LCOV - code coverage report
Current view: top level - TRD/TRDsim - AliTRDptrgTLMU.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 113 235 48.1 %
Date: 2016-06-14 17:26:59 Functions: 14 18 77.8 %

          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             : //                                                                        //
      20             : //  Pre-Trigger simulation                                                //
      21             : //                                                                        //
      22             : //  Authors: F. Reidt (Felix.Reidt@cern.ch)                               //
      23             : //                                                                        //
      24             : ////////////////////////////////////////////////////////////////////////////
      25             : 
      26             : #include "TFile.h"
      27             : #include "TROOT.h"
      28             : 
      29             : #include "TClonesArray.h"
      30             : 
      31             : #include "AliRun.h"
      32             : #include "AliRunLoader.h"
      33             : 
      34             : #include "AliTOFdigit.h"
      35             : #include "AliRawReader.h" // needed for AliTOFTrigger's raw digit support
      36             : #include "AliTOFTrigger.h"
      37             : 
      38             : #include "AliTRDptrgParam.h"
      39             : 
      40             : #include "AliTRDptrgTLMU.h"
      41             : #include "AliLog.h"
      42             : 
      43          12 : ClassImp(AliTRDptrgTLMU)
      44             : 
      45             : //______________________________________________________________________________
      46             : AliTRDptrgTLMU::AliTRDptrgTLMU(AliRunLoader *rl) 
      47           0 :   : TObject(),
      48           0 :   fRunLoader(rl),
      49           0 :   fParam(0x0),
      50           0 :   fOperatingMode(AliTRDptrgParam::kDigits),
      51           0 :   fInputMask(0x0),
      52           0 :   fCMatrices(0x0),
      53           0 :   fMultiplicity(0x0),
      54           0 :   fOutput(0x0) 
      55           0 : {
      56             :   // default ctor
      57             :  
      58           0 :   for (Int_t i = 0; i < 18; i++) {
      59           0 :     this->fTOFinputBits[i] = 0;
      60             :   }
      61             :   
      62           0 :   this->LoadParams();
      63           0 : }
      64             : 
      65             : //______________________________________________________________________________
      66             : AliTRDptrgTLMU::AliTRDptrgTLMU(AliRunLoader *rl,  AliTRDptrgParam *param,
      67             :                                AliTRDptrgParam::AliTRDptrgOperatingMode_t operatingMode)
      68           4 :   : TObject(),
      69           4 :   fRunLoader(rl),
      70           4 :   fParam(param),
      71           4 :   fOperatingMode(operatingMode),
      72           4 :   fInputMask(0x0),
      73           4 :   fCMatrices(0x0),
      74           4 :   fMultiplicity(0x0),
      75           4 :   fOutput(0x0) 
      76          20 : {
      77             :   // recommended ctor
      78             :   
      79         152 :   for (Int_t i = 0; i < 18; i++) {
      80          72 :     this->fTOFinputBits[i] = 0;
      81             :   }
      82             :  
      83           4 :   this->LoadParams();
      84           8 : }
      85             : 
      86             : //______________________________________________________________________________
      87             : AliTRDptrgTLMU::~AliTRDptrgTLMU() 
      88          24 : {
      89             :   // destructor
      90             :   
      91           4 :   this->fCMatrices = 0x0;
      92           4 :   this->fMultiplicity = 0x0;
      93           4 :   this->fOutput = 0x0;
      94          12 : }
      95             : 
      96             : //______________________________________________________________________________
      97             : Int_t* AliTRDptrgTLMU::Simulate() 
      98             : {
      99             :   // starts a simulation
     100             :         
     101           8 :   if (this->fOperatingMode == AliTRDptrgParam::kDigits) {
     102           4 :     this->LoadDigits();
     103           4 :   }     
     104           0 :   else if (this->fOperatingMode == AliTRDptrgParam::kHits) {
     105           0 :     return 0x0; // TODO
     106             :   }
     107             : 
     108             :   // which super modules are active? - needed for fast coincidence processing:  
     109             :   // M(sm | coincidence condition)>=2
     110             :   UInt_t temp = 0x1;
     111             :   UInt_t sm = 0x0; 
     112         152 :   for (Int_t iSM = 0; iSM < 18; iSM++) {
     113          72 :     if (this->Or(iSM)) {
     114          30 :       sm |= temp;
     115          30 :     }
     116          72 :     temp <<= 1;
     117             :   }
     118          12 :   AliDebug(4, Form("Active supermodules: 0x%x", sm));
     119             : 
     120             :   // get multiplicity
     121           4 :   UInt_t multiplicity = this->GetMultiplicitySum();
     122          12 :   AliDebug(4, Form("TOF/TLMU multiplicity: %d", multiplicity));       
     123             : 
     124           4 :   Int_t* result = new Int_t[9]; 
     125           4 :   result[0] = 8;
     126          72 :   for (Int_t iResult = 0; iResult < 8; iResult++) {
     127          32 :     result[iResult + 1] = 0;
     128             : 
     129             :     // coincidence matrix
     130          32 :     if (this->fOutput[iResult][0] != -1) {
     131          42 :       for (Int_t iLine = 0; iLine < 18; iLine++) {
     132          63 :         AliDebug(5, Form("Entry: %d, matrix: %d, line: %d, output: 0x%x", 
     133             :                          iResult, this->fOutput[iResult][0], iLine, sm & 
     134             :                          this->fCMatrices[this->fOutput[iResult][0]][iLine]));
     135          42 :         if (this->GetBitVectorMultiplicity(
     136          42 :              sm & this->fCMatrices[this->fOutput[iResult][0]][iLine]) > 1) {
     137          12 :           result[iResult + 1] = 1;
     138          12 :           break;
     139             :         }        
     140             :       }
     141          12 :     }
     142             :     
     143             :     // multiplicity conditions
     144          32 :     if (this->fOutput[iResult][1] != -1) {
     145          60 :       AliDebug(5, Form("Entry: %d, slice: %d", iResult, 
     146             :                        this->fOutput[iResult][1]));
     147          31 :       if ((this->fMultiplicity[this->fOutput[iResult][1]][0] < multiplicity) &&
     148          11 :           (this->fMultiplicity[this->fOutput[iResult][1]][1] >= multiplicity)) {
     149           8 :         result[iResult + 1] = 1;
     150           8 :       } 
     151             :     }
     152          96 :     AliDebug(4, Form("TLMU result[%d] = %d", iResult, result[iResult + 1]));
     153             :   }
     154             : 
     155             :   return result;
     156           4 : }
     157             : 
     158             : //______________________________________________________________________________
     159             : Int_t AliTRDptrgTLMU::LoadDigits()
     160             : {
     161             :   // loads Digits (for usage with aquired data)
     162           8 :   this->GetInputBits(); // get bits from AliTOFTrigger
     163           4 :   return 0;
     164             : }
     165             : 
     166             : 
     167             : //______________________________________________________________________________
     168             : Bool_t AliTRDptrgTLMU::LoadParams()
     169             : {
     170             :   // load AliTRDprtgParam content
     171             :         
     172           8 :   if (this->fParam == 0x0) {
     173             :     // no parameter object assigned
     174           0 :     AliWarning("no parameter object assigned - using default settings!");
     175             : 
     176             :     UInt_t* imask = 0x0;
     177           0 :     imask = new UInt_t[18];
     178           0 :     for (Int_t i = 0; i < 18; i++) {
     179           0 :       imask[i] = 0xFFFFFFFF;
     180             :     }
     181             : 
     182           0 :     this->fInputMask = imask;
     183             :     
     184             :     // TLMU Coincidence Matrices
     185           0 :     this->fCMatrices = new UInt_t*[3];
     186           0 :     this->fCMatrices[0] = new UInt_t[18];
     187           0 :     this->fCMatrices[1] = new UInt_t[18];
     188           0 :     this->fCMatrices[2] = new UInt_t[18];    
     189             : 
     190             :     // Matrix 0: Back-To-Back
     191             :     // Matrix 1: Back-To-Back +/-1
     192             :     // Matrix 2: Back-To-Back +/-2
     193           0 :     for (UInt_t iMatrix = 0; iMatrix < 3; iMatrix++) {
     194           0 :       for (UInt_t iSlice = 0; iSlice < 18; iSlice++) {
     195           0 :         if (iMatrix == 0) {
     196           0 :           if (iSlice < 9) {
     197           0 :             this->fCMatrices[iMatrix][iSlice] = 0x201 << iSlice; 
     198             :             // Back-To-Back 
     199           0 :             AliDebug(5, Form("fCMatrices[%d][%d]=0x%x",iMatrix,iSlice,
     200             :                              this->fCMatrices[iMatrix][iSlice]));
     201             :           }
     202             :           // because of symmetrie the other slices are not necessary
     203             :         } 
     204           0 :         else if (iMatrix == 1)  {
     205             :           // Back-To-Back +/- 1
     206           0 :           if (iSlice < 8) {
     207           0 :             this->fCMatrices[iMatrix][iSlice] = 0x381 << iSlice;
     208           0 :           }
     209           0 :           else if (iSlice == 8) {
     210           0 :             this->fCMatrices[iMatrix][iSlice] = 0x30101;
     211           0 :           }
     212           0 :           else if (iSlice == 9) {
     213           0 :             this->fCMatrices[iMatrix][iSlice] = 0x20203;
     214           0 :           }
     215             :           else {
     216           0 :             this->fCMatrices[iMatrix][iSlice] = 0x407 << (iSlice - 10);
     217             :           } 
     218           0 :           AliDebug(5, Form("fCMatrices[%d][%d]=0x%x",iMatrix,iSlice,
     219             :                            this->fCMatrices[iMatrix][iSlice])); 
     220             :         }
     221           0 :         else if (iMatrix == 2) {
     222             :           // Back-To-Back +/-2
     223           0 :           if (iSlice < 7 ) {
     224           0 :             this->fCMatrices[iMatrix][iSlice] = 0xF81 << iSlice;
     225           0 :           }
     226           0 :           else if (iSlice == 7) {
     227           0 :             this->fCMatrices[iMatrix][iSlice] = 0x3C081;
     228           0 :           }
     229           0 :           else if (iSlice == 8) {
     230           0 :             this->fCMatrices[iMatrix][iSlice] = 0x38103;
     231           0 :           }
     232           0 :           else if (iSlice == 9) {
     233           0 :             this->fCMatrices[iMatrix][iSlice] = 0x30207;
     234           0 :           }
     235           0 :           else if (iSlice == 10) {
     236           0 :             this->fCMatrices[iMatrix][iSlice] = 0x2040F;
     237           0 :           }
     238             :           else {
     239           0 :             this->fCMatrices[iMatrix][iSlice] = 0x81F << (iSlice - 11);
     240             :           } 
     241           0 :           AliDebug(5, Form("fCMatrices[%d][%d]=0x%x",iMatrix,iSlice,
     242             :                            this->fCMatrices[iMatrix][iSlice]));     
     243             :         }
     244             :       } 
     245             :     }
     246             :  
     247             :     // Mulitplicity
     248           0 :     this->fMultiplicity = new UInt_t*[9];
     249           0 :     for (Int_t i = 0; i < 9; i++) {
     250           0 :       this->fMultiplicity[i] = new UInt_t[2];
     251             :     }
     252           0 :     this->fMultiplicity[0][0] = 0;
     253           0 :     this->fMultiplicity[0][1] = 10;
     254           0 :     this->fMultiplicity[1][0] = 10;
     255           0 :     this->fMultiplicity[1][1] = 25;
     256           0 :     this->fMultiplicity[2][0] = 25;
     257           0 :     this->fMultiplicity[2][1] = 50;
     258           0 :     this->fMultiplicity[3][0] = 50;
     259           0 :     this->fMultiplicity[3][1] = 100;
     260           0 :     this->fMultiplicity[4][0] = 100;
     261           0 :     this->fMultiplicity[4][1] = 200;
     262           0 :     this->fMultiplicity[5][0] = 200;
     263           0 :     this->fMultiplicity[5][1] = 350;
     264           0 :     this->fMultiplicity[6][0] = 350;
     265           0 :     this->fMultiplicity[6][1] = 400;
     266           0 :     this->fMultiplicity[7][0] = 400;
     267           0 :     this->fMultiplicity[7][1] = 576;
     268           0 :     this->fMultiplicity[8][0] = 100;
     269           0 :     this->fMultiplicity[8][1] = 576;
     270             :  
     271             :     // TLMU output
     272           0 :     this->fOutput = new Int_t*[8];
     273           0 :     for (Int_t i = 0; i < 9; i++) {
     274           0 :       this->fOutput[i] = new Int_t[2];
     275           0 :       this->fOutput[i][0] = -1;
     276           0 :       this->fOutput[i][1] = -1;
     277             :     }
     278           0 :     this->fOutput[0][0] = 0;
     279           0 :     this->fOutput[1][0] = 1;
     280           0 :     this->fOutput[2][0] = 2;
     281           0 :     this->fOutput[3][1] = 0;
     282           0 :     this->fOutput[4][1] = 1;
     283           0 :     this->fOutput[5][1] = 2;
     284           0 :     this->fOutput[6][1] = 3;
     285           0 :     this->fOutput[7][1] = 8;
     286             : 
     287             : 
     288           0 :   }
     289             :   else {
     290             :     // parameter object assigned
     291             :     
     292           4 :     this->fInputMask = this->fParam->GetTLMUInputMask(); 
     293             :     // input mask for TOF-bits (18x32=576)
     294             :     
     295           4 :     this->fCMatrices = this->fParam->GetTLMUcmatrices();
     296             :     // get coincidence matrices
     297             :  
     298           4 :     this->fMultiplicity = this->fParam->GetTLMUmultiplicity();
     299             :     // get multiplicity slices
     300             :   
     301           4 :     this->fOutput = this->fParam->GetTLMUoutput();
     302             :     // get output signal assignment
     303             :   }
     304             : 
     305           4 :   return false;
     306             : }
     307             : 
     308             : //______________________________________________________________________________
     309             : void AliTRDptrgTLMU::GetInputBits() {
     310             :   // Gets TOF-to-TRD input bits from AliTOFTrigger as Bool_t array
     311             : 
     312           8 :   AliTOFTrigger *toftrig = new AliTOFTrigger(); // create AliTOFTrigger 
     313           4 :   toftrig->CreateLTMMatrix(); // Generate LTMMatrix from AliTOFdigits 
     314             :   
     315             :   // prepare map  
     316             :   Bool_t** map = 0x0;
     317           4 :   map = new Bool_t*[72];
     318         584 :   for (Int_t i=0; i < 72; i++) 
     319         288 :     map[i] = new Bool_t[8];
     320             :   
     321             :   // initialise map
     322         584 :   for (Int_t i=0; i < 72; i++)
     323        5184 :     for (Int_t j=0; j < 8; j++)
     324        2304 :       map[i][j] = kFALSE;
     325             : 
     326             :   // get 576 TOF-to-TRD bits
     327           4 :   toftrig->GetTRDmap(map);
     328             : 
     329             :   //* DEBUG output 
     330             :   // used to determine the correct bit assignment
     331          12 :   AliDebug(5, "AliTOFTrigger->GetTRDmap(map):");
     332         584 :   for (Int_t i=0; i < 72; i++) {
     333         864 :     AliDebug(5, Form("%d %d%d%d%d%d%d%d%d", i, map[i][0], map[i][1], map[i][2],
     334             :                       map[i][3], map[i][4], map[i][5], map[i][6], map[i][7]));
     335             :   }
     336             :   //*/ // end of DEBUG output
     337             : 
     338             :   // initialise fTOFinputBits
     339         152 :   for (Int_t i=0; i < 18; i++) {
     340          72 :     this->fTOFinputBits[i] = 0;
     341             :   }
     342             : 
     343             :  
     344             :   // transform Bool_t array to UInt_t bitvectors according to
     345             :   // http://www.physi.uni-heidelberg.de/~schicker/cbtof/cbtof_docu.pdf
     346             :   // chapter 1.4 and 2.1 to a supermodule based structured 
     347             :   // integer (bit) array
     348             :   Int_t supermodule = -1;
     349             :   UInt_t tempA = 0x00000001;
     350             :   UInt_t tempC = 0x00010000;
     351         296 :   for (Int_t iLTM = 0; iLTM < (kNLTM / 2); iLTM++) {
     352         144 :     if (!(iLTM % 2)) { // renew temp vectors, update supermodule
     353             :       tempA = 0x00000001;
     354             :       tempC = 0x00010000;
     355          72 :       supermodule++;
     356          72 :     }
     357             :     // AliDebug(5, Form("(%2d,0x%8x,0x%8x)", iLTM, tempA, tempC));
     358        2592 :     for (Int_t iLTMchan = 0; iLTMchan < 8; iLTMchan++) {
     359             :       // A-side
     360        1152 :       if (map[iLTM][iLTMchan]) {
     361          35 :         this->fTOFinputBits[supermodule] |= tempA;        
     362          35 :       }
     363             :       // C-side
     364        1152 :       if (map[iLTM + 36][iLTMchan]) {
     365          18 :         this->fTOFinputBits[supermodule] |= tempC;
     366          18 :       }
     367             :       // change temp vectors
     368        1152 :       tempA <<= 1;
     369        1152 :       tempC <<= 1;
     370             :     }
     371             :   }
     372             : 
     373           8 :   delete [] map;
     374             : 
     375             :   // handle input mask
     376         152 :   for (Int_t iSM = 0; iSM < 18; iSM++) {
     377         216 :     AliDebug(5, Form("fInputTOFinputBits[%d]=0x%x", iSM, 
     378             :              this->fTOFinputBits[iSM]));
     379          72 :     this->fTOFinputBits[iSM] &= this->fInputMask[iSM];
     380             :   }
     381           4 : }
     382             : 
     383             : 
     384             : //______________________________________________________________________________
     385             : Int_t AliTRDptrgTLMU::BackToBack(Int_t iSM, Int_t range) {
     386             :   // Check whether there is an back-to-back particle trace
     387             : 
     388             :   // get the counterpart of supermodule iSM
     389             :   Int_t counterPart = -1;
     390           0 :   if (iSM >= 9) { 
     391           0 :     counterPart = iSM - 9;
     392           0 :   }
     393             :   else  {
     394           0 :     counterPart = iSM + 9;
     395             :   }
     396             : 
     397           0 :   if (this->Or(iSM)) { // is there are active bits in supermodule iSM
     398             :     Int_t result = 0;
     399           0 :     for (Int_t i = counterPart - range; i <= counterPart + range; i++) {
     400             :       // check whether there are active bits in supermodule i (counterParts)
     401           0 :       if ((i >= 0) && (i < 18)) {
     402           0 :         if (Or(i)) {
     403           0 :           result++;
     404           0 :         }
     405             :       }
     406             :       else {
     407           0 :         if (i < 0) {
     408           0 :           if (Or(17 - i)) {
     409           0 :             result++;
     410           0 :           }
     411             :         }
     412           0 :         if (i > 17) {
     413           0 :           if (Or(i - 18)) {
     414           0 :             result++;
     415           0 :           }
     416             :         }
     417             :       }
     418             :     }
     419           0 :     AliDebug(5, Form("BackToBack of %d and %d+-%d\n: %d", iSM, counterPart, 
     420             :                      range, result));
     421             :     return result; // return whether there was a possible back-to-back trace
     422             :   }    
     423             :   else {
     424           0 :     AliDebug(5, Form("BackToBack unsuccessful, not hit in sm%d", iSM));
     425           0 :     return 0; // iSM did not recognize anything
     426             :   }
     427           0 : }
     428             : 
     429             : //______________________________________________________________________________
     430             : Int_t AliTRDptrgTLMU::Coincidence(Int_t iSM1, Int_t iSM2) {
     431             :   // checks whether there is an coincidence in iSM1 and iSM2
     432             : 
     433           0 :   if (this->Or(iSM1) && this->Or(iSM2)) {
     434           0 :     return 1;
     435             :   }
     436             :   else
     437           0 :     return 0;
     438           0 : }
     439             : 
     440             : //______________________________________________________________________________
     441             : inline Int_t AliTRDptrgTLMU::Or(Int_t  iSM) {
     442             :   // returns 1 if one or more bits are active in supermodule iSM
     443             :  
     444         144 :   if ((iSM >= 0) && (iSM < 18)) {
     445          72 :     if (this->fTOFinputBits[iSM] > 0)
     446          30 :       return 1;
     447             :     else
     448          42 :       return 0; 
     449             :   }
     450             :   else {
     451           0 :     return -1;
     452             :   }
     453          72 : }
     454             : 
     455             : //______________________________________________________________________________
     456             : Int_t AliTRDptrgTLMU::GetMultiplicity(Int_t iSM) {
     457             :   // counts how many bits equal one are in class member fTOFinputBits[iSM]
     458             :   // (32bits from TOF to TRD of supermodule iSM)
     459             : 
     460         144 :   UInt_t temp = this->fTOFinputBits[iSM];
     461             :   UInt_t mask = 0x01;
     462             :   Int_t multiplicity = 0;  
     463             :         
     464        4752 :   for (int iBit = 0; iBit < 32; iBit++) {
     465        2304 :     if ((mask & temp) != 0x0) { // is the bit equal one?
     466          53 :       multiplicity++;
     467          53 :     }
     468        2304 :     mask <<= 1; // rotate mask to the left after each iteration
     469             :   }
     470         216 :   AliDebug(5, Form("Multiplicity of supermodule %d: %d", iSM, multiplicity));
     471          72 :   return multiplicity;
     472             : }
     473             : 
     474             : //______________________________________________________________________________
     475             : Int_t AliTRDptrgTLMU::GetMultiplicitySum() {
     476             :   // returns the multiplicity of the whole detector (all 576bit TOF to TRD bits)
     477             :   Int_t sum = 0;
     478             :   
     479         156 :   for (Int_t i = 0; i < 18; i++) {
     480          72 :     sum += this->GetMultiplicity(i);
     481             :   }
     482          12 :   AliDebug(5, Form("Whole multiplicity: %d", sum));
     483           4 :   return sum;
     484             : }
     485             : 
     486             : //______________________________________________________________________________
     487             : UInt_t AliTRDptrgTLMU::GetBitVectorMultiplicity(UInt_t BitVector) {
     488             :   // returns the multiplicity of a given bit vector
     489             :   
     490             :   UInt_t result = 0;
     491             :   UInt_t temp = 0x01;
     492        1407 :   for (UInt_t iBit = 0; iBit < 32; iBit++) {
     493         672 :     if (BitVector & temp) {
     494          38 :       result++;
     495          38 :     }
     496         672 :     temp <<= 1;
     497             :   }
     498             : 
     499          21 :   return result;
     500             : }

Generated by: LCOV version 1.11