LCOV - code coverage report
Current view: top level - MUON/MUONtrigger - AliMUONGlobalTriggerBoard.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 106 133 79.7 %
Date: 2016-06-14 17:26:59 Functions: 13 16 81.2 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : /* $Id$ */
      17             : 
      18             : //-----------------------------------------------------------------------------
      19             : /// \class AliMUONGlobalTriggerBoard
      20             : /// Global trigger implementation:
      21             : /// - inputs are regional responses
      22             : /// - output is a 12-bit word
      23             : /// - 4 bits per trigger level
      24             : ///
      25             : /// \author Rachid Guernane (LPCCFd), 
      26             : /// Corrected by Christian Finck (Subatech)
      27             : //-----------------------------------------------------------------------------
      28             : 
      29             : #include "AliMUONGlobalTriggerBoard.h"
      30             : #include "AliLog.h"
      31             : #include "TBits.h"
      32             : 
      33             : #include <Riostream.h>
      34             : 
      35             : /// \cond CLASSIMP
      36          18 : ClassImp(AliMUONGlobalTriggerBoard)
      37             : /// \endcond
      38             : 
      39             : //___________________________________________
      40           6 : AliMUONGlobalTriggerBoard::AliMUONGlobalTriggerBoard(): AliMUONTriggerBoard()
      41          30 : {
      42             : /// Default constructor
      43             : 
      44         204 :    for (Int_t i=0;i<16;i++) fRegionalResponse[i] = 0;
      45          60 :    for (Int_t i=0;i< 4;i++) fGlobalInput[i] = 0;
      46          60 :    for (Int_t i=0;i< 4;i++) fMask[i] = 0xffffffff;
      47          12 : }
      48             : 
      49             : //___________________________________________
      50           0 : AliMUONGlobalTriggerBoard::AliMUONGlobalTriggerBoard(const char *name, Int_t a) : AliMUONTriggerBoard(name, a)
      51           0 : {
      52             : /// Standard constructor
      53             : 
      54           0 :    for (Int_t i=0;i<16;i++) fRegionalResponse[i] = 0;
      55           0 :    for (Int_t i=0;i< 4;i++) fGlobalInput[i] = 0;
      56           0 :    for (Int_t i=0;i< 4;i++) fMask[i] = 0xffffffff;
      57           0 : }
      58             : 
      59             : //___________________________________________
      60             : AliMUONGlobalTriggerBoard::~AliMUONGlobalTriggerBoard()
      61          24 : {
      62             : /// Destructor
      63          24 : }
      64             : 
      65             : //___________________________________________
      66             : void AliMUONGlobalTriggerBoard::Mask(Int_t index, UInt_t mask)
      67             : {
      68             :   /// mask global trigger board input index with value mask
      69          48 :   if ( index >= 0 && index < 4 ) 
      70             :   {
      71          24 :     fMask[index]=mask;
      72          24 :   }
      73             :   else
      74             :   {
      75           0 :     AliError(Form("Index %d out of bounds (max %d)",index,3));
      76             :   }  
      77          24 : }
      78             : 
      79             : //___________________________________________
      80             : void AliMUONGlobalTriggerBoard::Response()
      81             : {
      82             :    /// compute the global trigger board
      83             :    /// response according to the algo() method
      84             : // output from global trigger algorithm
      85             : // [+, -, US, LS] * [Hpt, Lpt]
      86             : // transformed to [usHpt, usLpt, lsHpt, lsLpt, sHpt, sLpt] according
      87             : // to Global Trigger Unit user manual
      88             : 
      89        1418 :    Int_t t[16];
      90             : 
      91         709 :    BuildGlobalInput();
      92         709 :    MaskGlobalInput();
      93             : 
      94       24106 :    for (Int_t i = 0; i < 16; ++i) 
      95             :    {
      96       11344 :      t[i] = fRegionalResponse[i];
      97             :    }
      98             :    
      99             :    
     100             :    Int_t rank = 8;
     101             : 
     102        7090 :    for (Int_t i=0;i<4;i++)
     103             :    {
     104             :       Int_t ip = 0;
     105             :       
     106       26942 :       for (Int_t j=0;j<rank;j++)
     107             :       {
     108       10635 :          UShort_t lthres = Algo(t[2*j],t[2*j+1],"LPT");
     109             : 
     110       10635 :          UShort_t hthres = Algo(t[2*j],t[2*j+1],"HPT"); hthres <<= 4;
     111             : 
     112       10635 :          t[ip] = lthres | hthres;
     113             : 
     114       10635 :          ip++;
     115             :       }
     116             :       
     117        2836 :       rank /= 2; 
     118             :    }
     119             :    UChar_t sLpt, sHpt, lsLpt, lsHpt, usLpt, usHpt;
     120         709 :    sLpt  = ((t[0] & 0xC)  != 0);
     121         709 :    sHpt  = ((t[0] & 0xC0) != 0);
     122         709 :    lsLpt = ((t[0] & 0x1)  != 0);
     123         709 :    lsHpt = ((t[0] & 0x10) != 0);
     124         709 :    usLpt = ((t[0] & 0x2 ) != 0);
     125         709 :    usHpt = ((t[0] & 0x20) != 0);
     126             : 
     127             :    // LSB is zero (trigger choice to send to CTP: sLpt or sHpt)
     128             : 
     129         709 :    sLpt  <<= 1;
     130         709 :    sHpt  <<= 2;
     131         709 :    lsLpt <<= 3;
     132         709 :    lsHpt <<= 4;
     133         709 :    usLpt <<= 5;
     134         709 :    usHpt <<= 6;
     135             : 
     136         709 :    fResponse = sLpt | sHpt | lsLpt | lsHpt | usLpt |usHpt;
     137             :    
     138             : 
     139         709 : }
     140             : 
     141             : //___________________________________________
     142             : UShort_t AliMUONGlobalTriggerBoard::Algo(UShort_t i, UShort_t j, const char *thres)
     143             : {
     144             : /// global trigger algorithm
     145             : ///   a ,b = reg  response  =  Hpt (+|-|us|ls) |  Lpt (+|-|us|ls)  
     146             :                            
     147       63810 :    TBits a(8), b(8); a.Set(8,&i); b.Set(8,&j);
     148             : 
     149       63810 :    TBits trg1(2), trg2(2), trg(2);
     150             : 
     151       42540 :    if (!strcmp(thres,"LPT"))
     152             :    {
     153       74445 :       trg1[0] = a[2]; trg1[1] = a[3]; 
     154       74445 :       trg2[0] = b[2]; trg2[1] = b[3];
     155       10635 :    }
     156             :    else
     157             :    {
     158       74445 :       trg1[0] = a[6]; trg1[1] = a[7]; 
     159       74445 :       trg2[0] = b[6]; trg2[1] = b[7];         
     160             :    }
     161             :        
     162      127620 :    TBits trgLS1(1), trgUS1(1), trgLS2(1), trgUS2(1), trgLS(1), trgUS(1);
     163             : 
     164       42540 :    if (!strcmp(thres,"LPT"))
     165             :    {
     166       74445 :       trgLS1[0] = a[0]; trgUS1[0] = a[1]; 
     167       74445 :       trgLS2[0] = b[0]; trgUS2[0] = b[1];
     168       10635 :    }
     169             :    else
     170             :    {
     171       74445 :       trgLS1[0] = a[4]; trgUS1[0] = a[5]; 
     172       74445 :       trgLS2[0] = b[4]; trgUS2[0] = b[5];         
     173             :    }
     174             : 
     175      276510 :    trgLS[0] = ( trg1[0] & trg2[0] ) | ( trg1[1] & trg2[1] ) | trgLS1[0] | trgLS2[0];
     176      276510 :    trgUS[0] = ( trg1[0] & trg2[1] ) | ( trg1[1] & trg2[0] ) | trgUS1[0] | trgUS2[0];
     177             :    
     178      127620 :    trg[0] = trg1[0] | trg2[0];
     179      127620 :    trg[1] = trg1[1] | trg2[1];
     180             :    
     181       21270 :    TBits v(4);
     182             :    
     183       85080 :    v[0] = trgLS[0];
     184       85080 :    v[1] = trgUS[0];
     185       85080 :    v[2] = trg[0];
     186       85080 :    v[3] = trg[1];
     187             : 
     188       21270 :    UShort_t rv = 0;
     189       21270 :    v.Get(&rv);
     190             :    
     191       21270 :    return rv;
     192       21270 : }
     193             : 
     194             : //___________________________________________
     195             : void AliMUONGlobalTriggerBoard::BuildGlobalInput()
     196             : {
     197             :   /// build the 4 words (32bits) global input from the regional responses
     198             :   /// the order of regional responses is:
     199             :   /// 1R, 2R, 2-3R, 3R, 4R, 5R, 6R, 7R, 1L, 2L, 2-3L, 3L, 4L, 5L, 6L, 7L
     200             : 
     201        7799 :   for (Int_t i=0;i< 4;i++) fGlobalInput[i] = 0;
     202             : 
     203             :   UShort_t regRespInv;
     204       24106 :   for (Int_t iReg = 0; iReg < 16; iReg++) {
     205             : 
     206       11344 :     regRespInv = InvertPairBits(iReg);
     207             : 
     208       22688 :     if (iReg < 8) {    // right
     209             :       // Lpt word
     210       17016 :       fGlobalInput[0] |=  (regRespInv & 0x0F)       << (4*iReg);
     211             :       // Hpt word
     212        5672 :       fGlobalInput[2] |= ((regRespInv & 0xF0) >> 4) << (4*iReg);
     213        5672 :     } else {           // left
     214             :       // Lpt word
     215        5672 :       fGlobalInput[1] |=  (regRespInv & 0x0F)       << (4*(iReg-8));
     216             :       // Hpt word
     217        5672 :       fGlobalInput[3] |= ((regRespInv & 0xF0) >> 4) << (4*(iReg-8));
     218             :     }
     219             : 
     220             :   }
     221             : 
     222         709 : }
     223             : 
     224             : //___________________________________________
     225             : void AliMUONGlobalTriggerBoard::MaskGlobalInput()
     226             : {
     227             :   /// Apply masks to global input and recalculate regional inputs before
     228             :   /// applying the global response
     229             : 
     230        1418 :   UInt_t gitmp[4];
     231        7090 :   for (Int_t i = 0; i < 4; i++) {
     232        2836 :     fGlobalInput[i] &= fMask[i];
     233        2836 :     gitmp[i] = fGlobalInput[i];
     234             :   }
     235             : 
     236         709 :   RecomputeRegional(gitmp);
     237         709 : }
     238             : 
     239             : 
     240             : //___________________________________________
     241             : void AliMUONGlobalTriggerBoard::RecomputeRegional(UInt_t gitmp[4])
     242             : {
     243             :   //
     244             :   /// Recomput regional response from global input
     245             :   //
     246       24815 :   for (Int_t iReg = 0; iReg < 16; iReg++) {
     247       11344 :     fRegionalResponse[iReg] = 0;
     248       11344 :     if (iReg < 8) {    // right
     249             :       // Lpt
     250        5672 :       fRegionalResponse[iReg] |=  (gitmp[0] >> (4*iReg))     & 0xF;
     251             :       // Hpt
     252        5672 :       fRegionalResponse[iReg] |= ((gitmp[2] >> (4*iReg))     & 0xF) << 4;
     253        5672 :     } else {           // left
     254             :       // Lpt
     255        5672 :       fRegionalResponse[iReg] |=  (gitmp[1] >> (4*(iReg-8))) & 0xF;
     256             :       // Hpt
     257        5672 :       fRegionalResponse[iReg] |= ((gitmp[3] >> (4*(iReg-8))) & 0xF) << 4;
     258             :     }
     259             : 
     260       11344 :     fRegionalResponse[iReg] = InvertPairBits(iReg);
     261             :   }
     262         709 : }
     263             : 
     264             : //___________________________________________
     265             : void AliMUONGlobalTriggerBoard::Scan(Option_t*) const
     266             : {
     267             :   /// print global trigger output 
     268           0 :   TBits w(7); w.Set(7,&fResponse);
     269             : 
     270             : // TRG[1:0]
     271             : // 00 noth
     272             : // 01 negative track
     273             : // 10 positive track
     274             : // 11 undef
     275             : 
     276           0 :    Int_t iS[2] = {0,0};
     277             : 
     278           0 :    iS[0] = (Int_t)w.TestBitNumber(1);
     279           0 :    iS[1] = (Int_t)w.TestBitNumber(2);
     280             : 
     281           0 :    Int_t iPU[2] = {w[5],w[6]};
     282           0 :    Int_t iPL[2] = {w[3],w[4]};
     283             : 
     284           0 :    printf("============================================\n");
     285           0 :    printf(" Global Trigger output       Low pt  High pt\n");
     286           0 :    printf(" number of Single           :\t");
     287           0 :    for (Int_t i=0; i<2; i++) printf("%i\t",iS[i]);
     288           0 :    printf("\n");
     289           0 :    printf(" number of UnlikeSign pair  :\t"); 
     290           0 :    for (Int_t i=0; i<2; i++) printf("%i\t",iPU[i]);
     291           0 :    printf("\n");
     292           0 :    printf(" number of LikeSign pair    :\t");  
     293           0 :    for (Int_t i=0; i<2; i++) printf("%i\t",iPL[i]);
     294           0 :    printf("\n");
     295           0 :    printf("===================================================\n");
     296           0 :    printf("\n");
     297           0 : }
     298             : 
     299             : 
     300             : //___________________________________________
     301             : UShort_t AliMUONGlobalTriggerBoard::InvertPairBits(Int_t iReg)
     302             : {
     303             :   //
     304             :   /// invert "pair" bits in regional response
     305             :   /// [+, -, US, LS] becomes [+, -, LS, US]
     306             :   //
     307       45376 :   TBits rs(8), rsi(8);
     308       22688 :   rs.Set(8,&fRegionalResponse[iReg]);
     309      226880 :     for (Int_t i = 0; i < 4; i++) {
     310      181504 :       if (i%2 == 0) {
     311      272256 :         rsi[2*i]   = rs[2*i+1];
     312      181504 :         rsi[2*i+1] = rs[2*i];
     313       45376 :       } else {
     314      181504 :         rsi[2*i]   = rs[2*i];
     315      181504 :         rsi[2*i+1] = rs[2*i+1];
     316             :       }
     317             :     }
     318       22688 :     UShort_t regRespInv = 0;
     319       22688 :     rsi.Get(&regRespInv);
     320       22688 :     return regRespInv;
     321       22688 : }

Generated by: LCOV version 1.11