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