]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALTrigger.cxx
Minor fixes in the event tag to take into account the new way of storing the trigger...
[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 > 10)
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 < 3; 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 - 1) * nTRU ; itru < isupermod*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-1)*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         //Fill matrix with added 2x2 crystals for use in 4x4 sums
174         (*tru2x2)(irow/2,icol/2) = amp2 ;
175         //Select 2x2 maximum sums to select L0 
176         if(amp2 > (*ampmax2)(0,mtru)){
177           (*ampmax2)(0,mtru) = amp2 ; 
178           (*ampmax2)(1,mtru) = irow;
179           (*ampmax2)(2,mtru) = icol;
180         }
181       }
182     }
183     
184     //Find most recent time in the selected 2x2 cell
185     (*ampmax2)(3,mtru) = 1 ;
186     Int_t row2 =  static_cast <Int_t> ((*ampmax2)(1,mtru));
187     Int_t col2 =  static_cast <Int_t> ((*ampmax2)(2,mtru));
188     for(Int_t i = 0; i<2; i++){
189       for(Int_t j = 0; j<2; j++){
190         if((*amptru)(row2+i,col2+j) > 0 &&  (*timeRtru)(row2+i,col2+j)> 0){       
191           if((*timeRtru)(row2+i,col2+j) <  (*ampmax2)(3,mtru)  )
192             (*ampmax2)(3,mtru) =  (*timeRtru)(row2+i,col2+j);
193         }
194       }
195     }
196     
197     //Sliding 4x4, add 4x4 amplitudes  (OVERLAP)
198     for(Int_t irow = 0 ; irow <  nCellsPhi/2; irow++){ 
199       for(Int_t icol = 0 ; icol < nCellsEta/2 ; icol++){
200         if( (irow+1) < nCellsPhi/2 && (icol+1) < nCellsEta/2){//Avoid exit the TRU
201           amp4 = (*tru2x2)(irow,icol)+(*tru2x2)(irow+1,icol)+
202             (*tru2x2)(irow,icol+1)+(*tru2x2)(irow+1,icol+1);
203           //Select 4x4 maximum sums to select L1 
204           if(amp4 > (*ampmax4)(0,mtru)){
205             (*ampmax4)(0,mtru) = amp4 ; 
206             (*ampmax4)(1,mtru) = irow*2;
207             (*ampmax4)(2,mtru) = icol*2;
208           }
209         }
210       }
211     }
212     
213     //Find most recent time in selected 4x4 cell
214     (*ampmax4)(3,mtru) = 1 ;
215     Int_t row4 =  static_cast <Int_t> ((*ampmax4)(1,mtru));
216     Int_t col4 =  static_cast <Int_t> ((*ampmax4)(2,mtru));
217     for(Int_t i = 0; i<4; i++){
218       for(Int_t j = 0; j<4; j++){
219         if((*amptru)(row4+i,col4+j) > 0 &&  (*timeRtru)(row4+i,col4+j)> 0){
220           if((*timeRtru)(row4+i,col4+j) <  (*ampmax4)(3,mtru)  )
221             (*ampmax4)(3,mtru) =  (*timeRtru)(row4+i,col4+j);
222         }
223       }
224     }
225   }
226 }
227
228 //____________________________________________________________________________
229 void AliEMCALTrigger::Print(const Option_t * opt) const 
230 {
231   
232   //Prints main parameters
233   
234   if(! opt)
235     return;
236   AliTriggerInput* in = 0x0 ;
237
238   printf( "             Maximum Amplitude after Sliding Cell, \n") ; 
239   printf( "               -2x2 cells sum (not overlapped): %10.2f, in Super Module %d\n",
240           f2x2MaxAmp,f2x2SM) ; 
241    printf( "               -2x2 from row %d to row %d and from column %d to column %d\n", f2x2CellPhi, f2x2CellPhi+2, f2x2CellEta, f2x2CellEta+2) ; 
242   printf( "               -4x4 cells sum (overlapped)    : %10.2f, in Super Module %d\n",
243           f4x4MaxAmp,f4x4SM) ; 
244   printf( "               -4x4 from row %d to row %d and from column %d to column %d\n", f4x4CellPhi, f4x4CellPhi+4, f4x4CellEta, f4x4CellEta+4) ; 
245   printf( "             Threshold for LO %10.2f\n", 
246           fL0Threshold) ;  
247   in = (AliTriggerInput*)fInputs.FindObject( "EMCAL_L0" );
248   if(in->GetValue())
249     printf( "             *** EMCAL LO is set ***\n") ; 
250   
251   printf( "             Jet Low Pt Threshold for L1 %10.2f\n", 
252           fL1JetLowPtThreshold) ;
253   in = (AliTriggerInput*)fInputs.FindObject( "EMCAL_JetLPt_L1" );
254   if(in->GetValue())
255     printf( "             *** EMCAL Jet Low Pt for L1 is set ***\n") ;
256
257   printf( "             Jet Medium Pt Threshold for L1 %10.2f\n", 
258           fL1JetMediumPtThreshold) ;  
259   in = (AliTriggerInput*) fInputs.FindObject( "EMCAL_JetMPt_L1" );
260   if(in->GetValue())
261     printf( "             *** EMCAL Jet Medium Pt for L1 is set ***\n") ;
262
263   printf( "             Jet High Pt Threshold for L1 %10.2f\n", 
264           fL1JetHighPtThreshold) ;  
265   in = (AliTriggerInput*) fInputs.FindObject( "EMCAL_JetHPt_L1" );
266   if(in->GetValue())
267     printf( "             *** EMCAL Jet High Pt for L1 is set ***\n") ;
268
269 }
270
271 //____________________________________________________________________________
272 void AliEMCALTrigger::SetTriggers(const Int_t iSM, const TMatrixD *ampmax2, 
273                                   const TMatrixD *ampmax4, AliEMCALGeometry *geom)  
274 {
275
276   //Checks the 2x2 and 4x4 maximum amplitude per each TRU and 
277   //compares with the different L0 and L1 triggers thresholds
278   Float_t max2[] = {-1,-1,-1,-1} ;
279   Float_t max4[] = {-1,-1,-1,-1} ;
280   Int_t   itru2  = -1 ;
281   Int_t   itru4  = -1 ;
282
283   //Find maximum summed amplitude of all the TRU 
284   //in a Super Module
285     for(Int_t i = 0 ; i < geom->GetNTRU() ; i++){
286       if(max2[0] < (*ampmax2)(0,i) ){
287         max2[0] =  (*ampmax2)(0,i) ; // 2x2 summed max amplitude
288         max2[1] =  (*ampmax2)(1,i) ; // corresponding phi position in TRU
289         max2[2] =  (*ampmax2)(2,i) ; // corresponding eta position in TRU
290         max2[3] =  (*ampmax2)(3,i) ; // corresponding most recent time
291         itru2   = i ;
292       }
293       if(max4[4] < (*ampmax4)(0,i) ){
294         max4[0] =  (*ampmax4)(0,i) ; // 4x4 summed max amplitude
295         max4[1] =  (*ampmax4)(1,i) ; // corresponding phi position in TRU
296         max4[2] =  (*ampmax4)(2,i) ; // corresponding eta position in TRU
297         max4[3] =  (*ampmax4)(3,i) ; // corresponding most recent time
298         itru4   = i ;
299       }
300     }
301
302   //--------Set max amplitude if larger than in other Super Modules------------
303   Float_t maxtimeR2 = -1 ;
304   Float_t maxtimeR4 = -1 ;
305   AliRunLoader *rl  = AliRunLoader::GetRunLoader();
306   AliRun * gAlice   = rl->GetAliRun(); 
307   AliEMCAL * emcal  = (AliEMCAL*)gAlice->GetDetector("EMCAL");
308   Int_t nTimeBins = emcal->GetRawFormatTimeBins() ;
309
310   //Set max of 2x2 amplitudes and select L0 trigger
311   if(max2[0] > f2x2MaxAmp ){
312     f2x2MaxAmp  = max2[0] ;
313     f2x2SM      = iSM ;
314     maxtimeR2   = max2[3] ;
315     geom->GetCellPhiEtaIndexInSModuleFromTRUIndex(itru2, 
316                                                   static_cast<Int_t>(max2[1]),
317                                                   static_cast<Int_t>(max2[2]),
318                                                   f2x2CellPhi,f2x2CellEta) ;
319     
320     //Transform digit amplitude in Raw Samples
321     fADCValuesLow2x2  = new Int_t[nTimeBins];
322     fADCValuesHigh2x2 = new Int_t[nTimeBins];
323     emcal->RawSampledResponse(maxtimeR2, f2x2MaxAmp, fADCValuesHigh2x2, fADCValuesLow2x2) ; 
324     
325     //Set Trigger Inputs, compare ADC time bins until threshold is attained
326     //Set L0
327     for(Int_t i = 0 ; i < nTimeBins ; i++){
328       if(fADCValuesHigh2x2[i] >= fL0Threshold          || fADCValuesLow2x2[i] >= fL0Threshold){
329         SetInput("EMCAL_L0") ;
330         break;
331       }
332     }
333     //    for(Int_t i = 0 ; i < nTimeBins ; i++)
334     //       if(fADCValuesLow2x2[i]!=0||fADCValuesHigh2x2[i]!=0)
335     //  cout<< "2x2 Time Bin "<<i
336     //      <<"; 2x2 Low Gain  "<<fADCValuesLow2x2[i]
337     //    <<"; 2x2 High Gain "<<fADCValuesHigh2x2[i]<<endl;
338   }
339   
340   //------------Set max of 4x4 amplitudes and select L1 trigger---------
341   if(max4[0] > f4x4MaxAmp ){
342     f4x4MaxAmp  = max4[0] ;
343     f4x4SM      = iSM ;
344     maxtimeR4   = max4[3] ;
345     geom->GetCellPhiEtaIndexInSModuleFromTRUIndex(itru4, 
346                                                   static_cast<Int_t>(max4[1]),
347                                                   static_cast<Int_t>(max4[2]),
348                                                   f4x4CellPhi,f4x4CellEta) ; 
349     //Transform digit amplitude in Raw Samples
350     fADCValuesHigh4x4 = new Int_t[nTimeBins];
351     fADCValuesLow4x4  = new Int_t[nTimeBins];
352     emcal->RawSampledResponse(maxtimeR4, f4x4MaxAmp, fADCValuesHigh4x4, fADCValuesLow4x4) ;
353     
354     //Set Trigger Inputs, compare ADC time bins until threshold is attained
355     //SetL1 Low
356     for(Int_t i = 0 ; i < nTimeBins ; i++){
357       if(fADCValuesHigh4x4[i] >= fL1JetLowPtThreshold  || fADCValuesLow4x4[i] >= fL1JetLowPtThreshold){
358         SetInput("EMCAL_JetLPt_L1") ;
359         break; 
360       }
361     }
362     
363     //SetL1 Medium
364     for(Int_t i = 0 ; i < nTimeBins ; i++){
365       if(fADCValuesHigh4x4[i] >= fL1JetMediumPtThreshold || fADCValuesLow4x4[i] >= fL1JetMediumPtThreshold){
366         SetInput("EMCAL_JetMPt_L1") ;
367         break;
368       }
369     }
370     
371     //SetL1 High
372     for(Int_t i = 0 ; i < nTimeBins ; i++){
373       if(fADCValuesHigh4x4[i] >= fL1JetHighPtThreshold || fADCValuesLow4x4[i] >= fL1JetHighPtThreshold){
374         SetInput("EMCAL_JetHPt_L1") ;
375         break;
376       }
377     }
378  //    for(Int_t i = 0 ; i < nTimeBins ; i++)
379 //       if(fADCValuesLow4x4[i]!= 100||fADCValuesHigh4x4[i] != 100)
380 //      cout<< "4x4 Time Bin "<<i
381 //          <<"; 4x4 Low Gain  "<<fADCValuesLow4x4[i]
382 //          <<"; 4x4 High Gain "<<fADCValuesHigh4x4[i]<<endl;
383   } 
384 }
385
386 //____________________________________________________________________________
387 void AliEMCALTrigger::Trigger() 
388 {
389   //Main Method to select triggers.
390   AliRunLoader *rl = AliRunLoader::GetRunLoader();
391   AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>
392     (rl->GetDetectorLoader("EMCAL"));
393
394   //Load EMCAL Geometry
395   rl->LoadgAlice(); 
396   AliRun * gAlice = rl->GetAliRun(); 
397   AliEMCAL * emcal  = (AliEMCAL*)gAlice->GetDetector("EMCAL");
398   AliEMCALGeometry * geom = emcal->GetGeometry();
399   
400   if (geom==0)
401     AliFatal("Did not get geometry from EMCALLoader");
402
403
404   //Define parameters
405   Int_t nSuperModules = geom->GetNumberOfSuperModules() ; //12 SM in EMCAL
406   Int_t nTRU          = geom->GetNTRU();//3 TRU per super module
407
408   //Intialize data members each time the trigger is called in event loop
409   f2x2MaxAmp = -1; f2x2CellPhi = -1;  f2x2CellEta = -1;
410   f4x4MaxAmp = -1; f4x4CellPhi = -1;  f4x4CellEta = -1;
411
412   //Take the digits list if simulation
413   if(fSimulation){
414     rl->LoadDigits("EMCAL");
415     fDigitsList = emcalLoader->Digits() ;
416   }
417   cout<<"Simulation "<<fSimulation<<endl;
418   if(!fDigitsList)
419     AliFatal("Digits not found !") ;
420   
421   //Take the digits list 
422   
423   //Fill TRU Matrix  
424   TClonesArray * amptrus   = new TClonesArray("TMatrixD",1000);
425   TClonesArray * timeRtrus = new TClonesArray("TMatrixD",1000);
426   geom->FillTRU(fDigitsList, amptrus, timeRtrus) ;
427
428   //Do Cell Sliding and select Trigger
429   //Initialize varible that will contain maximum amplitudes and 
430   //its corresponding cell position in eta and phi, and time.
431   TMatrixD  * ampmax2 = new TMatrixD(4,nTRU) ;
432   TMatrixD  * ampmax4 = new TMatrixD(4,nTRU) ;
433
434   for(Int_t iSM = 1 ; iSM <= nSuperModules ; iSM++) {
435     //Do 2x2 and 4x4 sums, select maximums. 
436     MakeSlidingCell(amptrus, timeRtrus, iSM, ampmax2, ampmax4, geom);
437     //Set the trigger
438     SetTriggers(iSM, ampmax2, ampmax4, geom) ;
439   }
440 }