]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALTrigger.cxx
PMD new raw data reader
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTrigger.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 /* $Id$ */
16 /* $Log $ */
17
18 //_________________________________________________________________________  
19 //
20 //  Class for trigger analysis.
21 //  Digits are grouped in TRU's (384 cells? ordered fNTRUPhi x fNTRUEta). 
22 //  The algorithm searches all possible 4x4 cell combinations per each TRU, 
23 //  adding the digits amplitude and finding the maximum. Maximums are compared 
24 //  to triggers threshold and they are set. Thresholds need to be fixed. 
25 //  Last 2 modules are half size in Phi, I considered that the number of TRU
26 //  is maintained for the last modules but decision not taken. If different, 
27 //  then this must be changed. 
28 //  Usage:
29 //
30 //  //Inside the event loop
31 //  AliEMCALTrigger *tr = new AliEMCALTrigger();//Init Trigger
32 //  tr->SetL0Threshold(100);
33 //  tr->SetL1JetLowPtThreshold(1000);
34 //  tr->SetL1JetMediumPtThreshold(10000);
35 //  tr->SetL1JetHighPtThreshold(20000);
36 //  tr->Trigger(); //Execute Trigger
37 //  tr->Print(""); //Print results
38 //
39 //*-- Author: Gustavo Conesa & Yves Schutz (IFIC, CERN) 
40 //////////////////////////////////////////////////////////////////////////////
41
42
43 // --- ROOT system ---
44 //#include "TMatrixD.h"
45
46 // --- ALIROOT system ---
47
48 #include "AliRun.h" 
49 #include "AliRunLoader.h" 
50 #include "AliTriggerInput.h"
51 #include "AliEMCAL.h" 
52 #include "AliEMCALLoader.h" 
53 #include "AliEMCALDigit.h"
54 #include "AliEMCALTrigger.h" 
55 #include "AliEMCALGeometry.h"
56
57 ClassImp(AliEMCALTrigger)
58
59 //______________________________________________________________________
60 AliEMCALTrigger::AliEMCALTrigger()
61   : AliTriggerDetector(),
62     f2x2MaxAmp(-1), f2x2CellPhi(-1),  f2x2CellEta(-1),
63     f4x4MaxAmp(-1), f4x4CellPhi(-1),  f4x4CellEta(-1), 
64     fL0Threshold(100),fL1JetLowPtThreshold(200), 
65     fL1JetMediumPtThreshold(500), fL1JetHighPtThreshold(1000), 
66     fSimulation(kTRUE)
67
68 {
69   //ctor 
70
71   fADCValuesHigh4x4 = 0x0; //new Int_t[fTimeBins];
72   fADCValuesLow4x4  = 0x0; //new Int_t[fTimeBins];
73   fADCValuesHigh2x2 = 0x0; //new Int_t[fTimeBins];
74   fADCValuesLow2x2  = 0x0; //new Int_t[fTimeBins];
75
76   fDigitsList = 0x0 ;
77
78
79   SetName("EMCAL");
80   CreateInputs();
81    
82    //Print("") ; 
83 }
84
85
86
87 //____________________________________________________________________________
88 AliEMCALTrigger::AliEMCALTrigger(const AliEMCALTrigger & trig) 
89   : AliTriggerDetector(trig) 
90 {
91
92   // cpy ctor
93
94   f2x2MaxAmp               = trig.f2x2MaxAmp ;
95   f4x4MaxAmp               = trig.f4x4MaxAmp ;
96   f2x2CellPhi              = trig.f2x2CellPhi ;
97   f4x4CellPhi              = trig.f4x4CellPhi ;
98   f2x2CellEta              = trig.f2x2CellEta ;
99   f4x4CellEta              = trig.f4x4CellEta ;
100   fADCValuesHigh4x4        = trig.fADCValuesHigh4x4 ; 
101   fADCValuesLow4x4         = trig.fADCValuesLow4x4  ; 
102   fADCValuesHigh2x2        = trig.fADCValuesHigh2x2 ; 
103   fADCValuesLow2x2         = trig.fADCValuesLow2x2  ;
104   fDigitsList              = trig.fDigitsList ;
105   fL0Threshold             = trig.fL0Threshold ; 
106   fL1JetLowPtThreshold     = trig.fL1JetLowPtThreshold ;
107   fL1JetMediumPtThreshold  = trig.fL1JetMediumPtThreshold ;
108   fL1JetHighPtThreshold    = trig.fL1JetHighPtThreshold ;
109   fSimulation              = trig.fSimulation ;
110
111
112
113 }
114
115 //----------------------------------------------------------------------
116 void AliEMCALTrigger::CreateInputs()
117 {
118    // inputs 
119    
120    // Do not create inputs again!!
121    if( fInputs.GetEntriesFast() > 0 ) return;
122    
123    fInputs.AddLast( new AliTriggerInput( "EMCAL_L0",       "EMCAL L0", 0x02 ) );
124    fInputs.AddLast( new AliTriggerInput( "EMCAL_JetHPt_L1","EMCAL Jet High Pt L1",   0x04 ) );
125    fInputs.AddLast( new AliTriggerInput( "EMCAL_JetMPt_L1","EMCAL Jet Medium Pt L1", 0x08 ) );
126    fInputs.AddLast( new AliTriggerInput( "EMCAL_JetLPt_L1","EMCAL Jet Low Pt L1",    0x016 ) );
127  
128 }
129
130 //____________________________________________________________________________
131 void AliEMCALTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClonesArray * timeRtrus, const Int_t isupermod,TMatrixD *ampmax2, TMatrixD *ampmax4, AliEMCALGeometry *geom){
132   
133   //Sums energy of all possible 2x2 (L0) and 4x4 (L1) cells per each TRU. 
134   //Fast signal in the experiment is given by 2x2 cells, 
135   //for this reason we loop inside the TRU cells by 2. 
136
137   //Declare and initialize variables
138   Int_t nCellsPhi  = geom->GetNPhi()*2/geom->GetNTRUPhi() ;
139   if(isupermod > 9)
140     nCellsPhi =  nCellsPhi / 2 ; //Half size SM. Not Final.
141   // 12(tow)*2(cell)/1 TRU, cells in Phi in one TRU
142   Int_t nCellsEta  = geom->GetNEta()*2/geom->GetNTRUEta() ;
143   // 24(mod)*2(tower)/3 TRU, cells in Eta in one TRU
144   Int_t nTRU          = geom->GetNTRU();//3 TRU per super module
145
146   Float_t amp2 = 0 ;
147   Float_t amp4 = 0 ; 
148   for(Int_t i = 0; i < 4; i++){
149     for(Int_t j = 0; j < nTRU; j++){
150       (*ampmax2)(i,j) = -1;
151       (*ampmax4)(i,j) = -1;
152     }
153   }
154
155   //Create matrix that will contain 2x2 amplitude sums
156   //used to calculate the 4x4 sums
157   TMatrixD  * tru2x2 = new TMatrixD(nCellsPhi/2,nCellsEta/2) ;
158   for(Int_t i = 0; i < nCellsPhi/2; i++)
159     for(Int_t j = 0; j < nCellsEta/2; j++)
160       (*tru2x2)(i,j) = -1;
161   
162   //Loop over all TRUS in a supermodule
163   for(Int_t itru = 0 + isupermod * nTRU ; itru < (isupermod+1)*nTRU ; itru++) {
164     TMatrixD * amptru   = dynamic_cast<TMatrixD *>(amptrus->At(itru)) ;
165     TMatrixD * timeRtru = dynamic_cast<TMatrixD *>(timeRtrus->At(itru)) ;
166     Int_t mtru = itru-isupermod*nTRU ; //Number of TRU in Supermodule
167    
168     //Sliding 2x2, add 2x2 amplitudes (NOT OVERLAP)
169     for(Int_t irow = 0 ; irow <  nCellsPhi; irow += 2){ 
170       for(Int_t icol = 0 ; icol < nCellsEta ; icol += 2){
171         amp2 = (*amptru)(irow,icol)+(*amptru)(irow+1,icol)+
172           (*amptru)(irow,icol+1)+(*amptru)(irow+1,icol+1);
173
174         //Fill matrix with added 2x2 crystals for use in 4x4 sums
175         (*tru2x2)(irow/2,icol/2) = amp2 ;
176         //Select 2x2 maximum sums to select L0 
177         if(amp2 > (*ampmax2)(0,mtru)){
178           (*ampmax2)(0,mtru) = amp2 ; 
179           (*ampmax2)(1,mtru) = irow;
180           (*ampmax2)(2,mtru) = icol;
181         }
182       }
183     }
184     
185     //Find most recent time in the selected 2x2 cell
186     (*ampmax2)(3,mtru) = 1 ;
187     Int_t row2 =  static_cast <Int_t> ((*ampmax2)(1,mtru));
188     Int_t col2 =  static_cast <Int_t> ((*ampmax2)(2,mtru));
189     for(Int_t i = 0; i<2; i++){
190       for(Int_t j = 0; j<2; j++){
191         if((*amptru)(row2+i,col2+j) > 0 &&  (*timeRtru)(row2+i,col2+j)> 0){       
192           if((*timeRtru)(row2+i,col2+j) <  (*ampmax2)(3,mtru)  )
193             (*ampmax2)(3,mtru) =  (*timeRtru)(row2+i,col2+j);
194         }
195       }
196     }
197     
198     //Sliding 4x4, add 4x4 amplitudes  (OVERLAP)
199     for(Int_t irow = 0 ; irow <  nCellsPhi/2; irow++){ 
200       for(Int_t icol = 0 ; icol < nCellsEta/2 ; icol++){
201         if( (irow+1) < nCellsPhi/2 && (icol+1) < nCellsEta/2){//Avoid exit the TRU
202           amp4 = (*tru2x2)(irow,icol)+(*tru2x2)(irow+1,icol)+
203             (*tru2x2)(irow,icol+1)+(*tru2x2)(irow+1,icol+1);
204           //Select 4x4 maximum sums to select L1 
205           if(amp4 > (*ampmax4)(0,mtru)){
206             (*ampmax4)(0,mtru) = amp4 ; 
207             (*ampmax4)(1,mtru) = irow*2;
208             (*ampmax4)(2,mtru) = icol*2;
209           }
210         }
211       }
212     }
213     
214     //Find most recent time in selected 4x4 cell
215     (*ampmax4)(3,mtru) = 1 ;
216     Int_t row4 =  static_cast <Int_t> ((*ampmax4)(1,mtru));
217     Int_t col4 =  static_cast <Int_t> ((*ampmax4)(2,mtru));
218     for(Int_t i = 0; i<4; i++){
219       for(Int_t j = 0; j<4; j++){
220         if((*amptru)(row4+i,col4+j) > 0 &&  (*timeRtru)(row4+i,col4+j)> 0){
221           if((*timeRtru)(row4+i,col4+j) <  (*ampmax4)(3,mtru)  )
222             (*ampmax4)(3,mtru) =  (*timeRtru)(row4+i,col4+j);
223         }
224       }
225     }
226   }
227 }
228
229 //____________________________________________________________________________
230 void AliEMCALTrigger::Print(const Option_t * opt) const 
231 {
232   
233   //Prints main parameters
234   
235   if(! opt)
236     return;
237   AliTriggerInput* in = 0x0 ;
238
239   printf( "             Maximum Amplitude after Sliding Cell, \n") ; 
240   printf( "               -2x2 cells sum (not overlapped): %10.2f, in Super Module %d\n",
241           f2x2MaxAmp,f2x2SM) ; 
242    printf( "               -2x2 from row %d to row %d and from column %d to column %d\n", f2x2CellPhi, f2x2CellPhi+2, f2x2CellEta, f2x2CellEta+2) ; 
243   printf( "               -4x4 cells sum (overlapped)    : %10.2f, in Super Module %d\n",
244           f4x4MaxAmp,f4x4SM) ; 
245   printf( "               -4x4 from row %d to row %d and from column %d to column %d\n", f4x4CellPhi, f4x4CellPhi+4, f4x4CellEta, f4x4CellEta+4) ; 
246   printf( "             Threshold for LO %10.2f\n", 
247           fL0Threshold) ;  
248   in = (AliTriggerInput*)fInputs.FindObject( "EMCAL_L0" );
249   if(in->GetValue())
250     printf( "             *** EMCAL LO is set ***\n") ; 
251   
252   printf( "             Jet Low Pt Threshold for L1 %10.2f\n", 
253           fL1JetLowPtThreshold) ;
254   in = (AliTriggerInput*)fInputs.FindObject( "EMCAL_JetLPt_L1" );
255   if(in->GetValue())
256     printf( "             *** EMCAL Jet Low Pt for L1 is set ***\n") ;
257
258   printf( "             Jet Medium Pt Threshold for L1 %10.2f\n", 
259           fL1JetMediumPtThreshold) ;  
260   in = (AliTriggerInput*) fInputs.FindObject( "EMCAL_JetMPt_L1" );
261   if(in->GetValue())
262     printf( "             *** EMCAL Jet Medium Pt for L1 is set ***\n") ;
263
264   printf( "             Jet High Pt Threshold for L1 %10.2f\n", 
265           fL1JetHighPtThreshold) ;  
266   in = (AliTriggerInput*) fInputs.FindObject( "EMCAL_JetHPt_L1" );
267   if(in->GetValue())
268     printf( "             *** EMCAL Jet High Pt for L1 is set ***\n") ;
269
270 }
271
272 //____________________________________________________________________________
273 void AliEMCALTrigger::SetTriggers(const Int_t iSM, const TMatrixD *ampmax2, 
274                                   const TMatrixD *ampmax4, AliEMCALGeometry *geom)  
275 {
276
277   //Checks the 2x2 and 4x4 maximum amplitude per each TRU and 
278   //compares with the different L0 and L1 triggers thresholds
279   Float_t max2[] = {-1,-1,-1,-1} ;
280   Float_t max4[] = {-1,-1,-1,-1} ;
281   Int_t   itru2  = -1 ;
282   Int_t   itru4  = -1 ;
283
284   //Find maximum summed amplitude of all the TRU 
285   //in a Super Module
286     for(Int_t i = 0 ; i < geom->GetNTRU() ; i++){
287       if(max2[0] < (*ampmax2)(0,i) ){
288         max2[0] =  (*ampmax2)(0,i) ; // 2x2 summed max amplitude
289         max2[1] =  (*ampmax2)(1,i) ; // corresponding phi position in TRU
290         max2[2] =  (*ampmax2)(2,i) ; // corresponding eta position in TRU
291         max2[3] =  (*ampmax2)(3,i) ; // corresponding most recent time
292         itru2   = i ;
293       }
294       if(max4[0] < (*ampmax4)(0,i) ){
295         max4[0] =  (*ampmax4)(0,i) ; // 4x4 summed max amplitude
296         max4[1] =  (*ampmax4)(1,i) ; // corresponding phi position in TRU
297         max4[2] =  (*ampmax4)(2,i) ; // corresponding eta position in TRU
298         max4[3] =  (*ampmax4)(3,i) ; // corresponding most recent time
299         itru4   = i ;
300       }
301     }
302
303   //--------Set max amplitude if larger than in other Super Modules------------
304   Float_t maxtimeR2 = -1 ;
305   Float_t maxtimeR4 = -1 ;
306   AliRunLoader *rl  = AliRunLoader::GetRunLoader();
307   AliRun * gAlice   = rl->GetAliRun(); 
308   AliEMCAL * emcal  = (AliEMCAL*)gAlice->GetDetector("EMCAL");
309   Int_t nTimeBins = emcal->GetRawFormatTimeBins() ;
310
311   //Set max of 2x2 amplitudes and select L0 trigger
312   if(max2[0] > f2x2MaxAmp ){
313     f2x2MaxAmp  = max2[0] ;
314     f2x2SM      = iSM ;
315     maxtimeR2   = max2[3] ;
316     geom->GetCellPhiEtaIndexInSModuleFromTRUIndex(itru2, 
317                                                   static_cast<Int_t>(max2[1]),
318                                                   static_cast<Int_t>(max2[2]),
319                                                   f2x2CellPhi,f2x2CellEta) ;
320     
321     //Transform digit amplitude in Raw Samples
322     fADCValuesLow2x2  = new Int_t[nTimeBins];
323     fADCValuesHigh2x2 = new Int_t[nTimeBins];
324     emcal->RawSampledResponse(maxtimeR2, f2x2MaxAmp, fADCValuesHigh2x2, fADCValuesLow2x2) ; 
325     
326     //Set Trigger Inputs, compare ADC time bins until threshold is attained
327     //Set L0
328     for(Int_t i = 0 ; i < nTimeBins ; i++){
329       if(fADCValuesHigh2x2[i] >= fL0Threshold          || fADCValuesLow2x2[i] >= fL0Threshold){
330         SetInput("EMCAL_L0") ;
331         break;
332       }
333     }
334   }
335   
336   //------------Set max of 4x4 amplitudes and select L1 trigger---------
337   if(max4[0] > f4x4MaxAmp ){
338     f4x4MaxAmp  = max4[0] ;
339     f4x4SM      = iSM ;
340     maxtimeR4   = max4[3] ;
341     geom->GetCellPhiEtaIndexInSModuleFromTRUIndex(itru4, 
342                                                   static_cast<Int_t>(max4[1]),
343                                                   static_cast<Int_t>(max4[2]),
344                                                   f4x4CellPhi,f4x4CellEta) ; 
345     //Transform digit amplitude in Raw Samples
346     fADCValuesHigh4x4 = new Int_t[nTimeBins];
347     fADCValuesLow4x4  = new Int_t[nTimeBins];
348     emcal->RawSampledResponse(maxtimeR4, f4x4MaxAmp, fADCValuesHigh4x4, fADCValuesLow4x4) ;
349     
350     //Set Trigger Inputs, compare ADC time bins until threshold is attained
351     //SetL1 Low
352     for(Int_t i = 0 ; i < nTimeBins ; i++){
353       if(fADCValuesHigh4x4[i] >= fL1JetLowPtThreshold  || fADCValuesLow4x4[i] >= fL1JetLowPtThreshold){
354         SetInput("EMCAL_JetLPt_L1") ;
355         break; 
356       }
357     }
358     
359     //SetL1 Medium
360     for(Int_t i = 0 ; i < nTimeBins ; i++){
361       if(fADCValuesHigh4x4[i] >= fL1JetMediumPtThreshold || fADCValuesLow4x4[i] >= fL1JetMediumPtThreshold){
362         SetInput("EMCAL_JetMPt_L1") ;
363         break;
364       }
365     }
366     
367     //SetL1 High
368     for(Int_t i = 0 ; i < nTimeBins ; i++){
369       if(fADCValuesHigh4x4[i] >= fL1JetHighPtThreshold || fADCValuesLow4x4[i] >= fL1JetHighPtThreshold){
370         SetInput("EMCAL_JetHPt_L1") ;
371         break;
372       }
373     }
374   } 
375 }
376
377 //____________________________________________________________________________
378 void AliEMCALTrigger::Trigger() 
379 {
380   //Main Method to select triggers.
381   AliRunLoader *rl = AliRunLoader::GetRunLoader();
382   AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>
383     (rl->GetDetectorLoader("EMCAL"));
384
385   //Load EMCAL Geometry
386   rl->LoadgAlice(); 
387   AliRun * gAlice = rl->GetAliRun(); 
388   AliEMCAL * emcal  = (AliEMCAL*)gAlice->GetDetector("EMCAL");
389   AliEMCALGeometry * geom = emcal->GetGeometry();
390   
391   if (geom==0)
392     AliFatal("Did not get geometry from EMCALLoader");
393
394
395   //Define parameters
396   Int_t nSuperModules = geom->GetNumberOfSuperModules() ; //12 SM in EMCAL
397   Int_t nTRU          = geom->GetNTRU();//3 TRU per super module
398
399   //Intialize data members each time the trigger is called in event loop
400   f2x2MaxAmp = -1; f2x2CellPhi = -1;  f2x2CellEta = -1;
401   f4x4MaxAmp = -1; f4x4CellPhi = -1;  f4x4CellEta = -1;
402
403   //Take the digits list if simulation
404   if(fSimulation){
405     rl->LoadDigits("EMCAL");
406     fDigitsList = emcalLoader->Digits() ;
407   }
408   if(!fDigitsList)
409     AliFatal("Digits not found !") ;
410   
411   //Take the digits list 
412   
413   //Fill TRU Matrix  
414   TClonesArray * amptrus   = new TClonesArray("TMatrixD",1000);
415   TClonesArray * timeRtrus = new TClonesArray("TMatrixD",1000);
416
417   geom->FillTRU(fDigitsList, amptrus, timeRtrus) ;
418
419   //Do Cell Sliding and select Trigger
420   //Initialize varible that will contain maximum amplitudes and 
421   //its corresponding cell position in eta and phi, and time.
422   TMatrixD  * ampmax2 = new TMatrixD(4,nTRU) ;
423   TMatrixD  * ampmax4 = new TMatrixD(4,nTRU) ;
424
425   for(Int_t iSM = 0 ; iSM < nSuperModules ; iSM++) {
426     //Do 2x2 and 4x4 sums, select maximums. 
427     MakeSlidingCell(amptrus, timeRtrus, iSM, ampmax2, ampmax4, geom);
428   
429     //Set the trigger
430     SetTriggers(iSM, ampmax2, ampmax4, geom) ;
431   }
432 }