]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALTrigger.cxx
Removing some warnings
[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
17 //_________________________________________________________________________  
18 //
19 //  Class for trigger analysis.
20 //  Digits are grouped in TRU's  (Trigger Units). A TRU consists of 384 
21 //  cells ordered fNTRUPhi x fNTRUEta. The algorithm searches all possible 2x2 
22 //  and nxn (n is a multiple of 2) cell combinations per each TRU,  adding the 
23 //  digits amplitude and finding the maximum. If found, look if it is isolated.
24 //  Maxima are transformed in ADC time samples. Each time bin is compared to the trigger 
25 //  threshold until it is larger and then, triggers are set. Thresholds need to be fixed.  
26 //  Thresholds need to be fixed. Last 2 modules are half size in Phi, I considered 
27 //  that the number of TRU is maintained for the last modules but decision not taken. 
28 //  If different, then this must be changed. 
29 //  Usage:
30 //
31 //  //Inside the event loop
32 //  AliEMCALTrigger *tr = new AliEMCALTrigger();//Init Trigger
33 //  tr->SetL0Threshold(100); //Arbitrary threshold values
34 //  tr->SetL1JetLowPtThreshold(1000);
35 //  tr->SetL1JetMediumPtThreshold(10000);
36 //  tr->SetL1JetHighPtThreshold(20000);
37 //  ...
38 //  tr->Trigger(); //Execute Trigger
39 //  tr->Print(""); //Print results
40 //
41 //*-- Author: Gustavo Conesa & Yves Schutz (IFIC, CERN) 
42 //////////////////////////////////////////////////////////////////////////////
43
44
45 // --- ROOT system ---
46
47 // --- ALIROOT system ---
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     f2x2SM(0),
64     fnxnMaxAmp(-1), fnxnCellPhi(-1),  fnxnCellEta(-1),
65     fnxnSM(0),
66     fADCValuesHighnxn(0),fADCValuesLownxn(0),
67     fADCValuesHigh2x2(0),fADCValuesLow2x2(0),
68     fDigitsList(0),
69     fL0Threshold(100),fL1JetLowPtThreshold(200),
70     fL1JetMediumPtThreshold(500), fL1JetHighPtThreshold(1000),
71     fNTRU(3), fNTRUEta(3), fNTRUPhi(1), 
72     fNCellsPhi(24), fNCellsEta(16), 
73     fPatchSize(1),  fIsolPatchSize(1), 
74     f2x2AmpOutOfPatch(-1), fnxnAmpOutOfPatch(-1), 
75     f2x2AmpOutOfPatchThres(100000),  fnxnAmpOutOfPatchThres(100000), 
76     fIs2x2Isol(kFALSE), fIsnxnIsol(kFALSE),  
77     fSimulation(kTRUE), fIsolateInSuperModule(kTRUE)
78 {
79   //ctor 
80   fADCValuesHighnxn = 0x0; //new Int_t[fTimeBins];
81   fADCValuesLownxn  = 0x0; //new Int_t[fTimeBins];
82   fADCValuesHigh2x2 = 0x0; //new Int_t[fTimeBins];
83   fADCValuesLow2x2  = 0x0; //new Int_t[fTimeBins];
84
85   SetName("EMCAL");
86   CreateInputs();
87    
88    //Print("") ; 
89 }
90
91
92
93 //____________________________________________________________________________
94 AliEMCALTrigger::AliEMCALTrigger(const AliEMCALTrigger & trig) 
95   : AliTriggerDetector(trig),
96     f2x2MaxAmp(trig.f2x2MaxAmp), 
97     f2x2CellPhi(trig.f2x2CellPhi),  
98     f2x2CellEta(trig.f2x2CellEta),
99     f2x2SM(trig.f2x2SM),
100     fnxnMaxAmp(trig.fnxnMaxAmp), 
101     fnxnCellPhi(trig.fnxnCellPhi),  
102     fnxnCellEta(trig.fnxnCellEta),
103     fnxnSM(trig.fnxnSM),
104     fADCValuesHighnxn(trig.fADCValuesHighnxn),
105     fADCValuesLownxn(trig.fADCValuesLownxn),
106     fADCValuesHigh2x2(trig.fADCValuesHigh2x2),
107     fADCValuesLow2x2(trig.fADCValuesLow2x2),
108     fDigitsList(trig.fDigitsList),
109     fL0Threshold(trig.fL0Threshold),
110     fL1JetLowPtThreshold(trig.fL1JetLowPtThreshold),
111     fL1JetMediumPtThreshold(trig.fL1JetMediumPtThreshold), 
112     fL1JetHighPtThreshold(trig.fL1JetHighPtThreshold),
113     fNTRU(trig.fNTRU), fNTRUEta(trig.fNTRUEta), fNTRUPhi(trig.fNTRUPhi), 
114     fNCellsPhi(trig.fNCellsPhi), fNCellsEta(trig.fNCellsEta), 
115     fPatchSize(trig.fPatchSize),
116     fIsolPatchSize(trig.fIsolPatchSize), 
117     f2x2AmpOutOfPatch(trig.f2x2AmpOutOfPatch), 
118     fnxnAmpOutOfPatch(trig.fnxnAmpOutOfPatch), 
119     f2x2AmpOutOfPatchThres(trig.f2x2AmpOutOfPatchThres),  
120     fnxnAmpOutOfPatchThres(trig.fnxnAmpOutOfPatchThres), 
121     fIs2x2Isol(trig.fIs2x2Isol),
122     fIsnxnIsol(trig.fIsnxnIsol),  
123     fSimulation(trig.fSimulation),
124     fIsolateInSuperModule(trig.fIsolateInSuperModule)
125 {
126   // cpy ctor
127 }
128
129 //----------------------------------------------------------------------
130 void AliEMCALTrigger::CreateInputs()
131 {
132    // inputs 
133    
134    // Do not create inputs again!!
135    if( fInputs.GetEntriesFast() > 0 ) return;
136    
137    fInputs.AddLast( new AliTriggerInput( "EMCAL_L0",       "EMCAL L0", 0x02 ) );
138    fInputs.AddLast( new AliTriggerInput( "EMCAL_JetHPt_L1","EMCAL Jet High Pt L1",   0x04 ) );
139    fInputs.AddLast( new AliTriggerInput( "EMCAL_JetMPt_L1","EMCAL Jet Medium Pt L1", 0x08 ) );
140    fInputs.AddLast( new AliTriggerInput( "EMCAL_JetLPt_L1","EMCAL Jet Low Pt L1",    0x016 ) );
141  
142 }
143
144 //____________________________________________________________________________
145 Bool_t AliEMCALTrigger::IsPatchIsolated(Int_t iPatchType, const TClonesArray * ampmatrixes, const Int_t iSM, const Int_t mtru, const Float_t maxamp, const Int_t maxphi, const Int_t maxeta) {
146
147   //Calculate if the maximum patch found is isolated, find amplitude around maximum (2x2 or nxn) patch, 
148   //inside isolation patch . iPatchType = 0 means calculation for 2x2 patch, 
149   //iPatchType = 1 means calculation for nxn patch.
150   //In the next table there is an example of the different options of patch size and isolation patch size:
151   //                                                                                 Patch Size (fPatchSize)
152   //                                                             0                          1                                  2
153   //          fIsolPatchSize                 2x2 (not overlap)   4x4 (overlapped)        6x6(overlapped) ...
154   //                   1                                       4x4                      8x8                              10x10
155   //                   2                                       6x6                     12x12                           14x14    
156   //                   3                                       8x8                     16x16                           18x18
157                           
158   Bool_t b = kFALSE;
159   Float_t amp = 0;
160  
161   //Get matrix of TRU or Module with maximum amplitude patch.
162   Int_t itru = mtru+iSM*fNTRU ; //number of tru, min 0 max 8*5.
163   TMatrixD * ampmatrix   = 0x0;
164   Int_t colborder = 0;
165   Int_t rowborder = 0;
166   
167   if(fIsolateInSuperModule){
168     ampmatrix = dynamic_cast<TMatrixD *>(ampmatrixes->At(iSM)) ;
169     rowborder = fNCellsPhi*fNTRUPhi;
170     colborder = fNCellsEta*fNTRUEta;
171     AliDebug(2,"Isolate trigger in Module");
172   }
173   else{
174     ampmatrix = dynamic_cast<TMatrixD *>(ampmatrixes->At(itru)) ;
175     rowborder = fNCellsPhi;
176     colborder = fNCellsEta;
177     AliDebug(2,"Isolate trigger in TRU");
178   }
179   
180   //Define patch cells
181   Int_t isolcells   = fIsolPatchSize*(1+iPatchType);
182   Int_t ipatchcells = 2*(1+fPatchSize*iPatchType);
183   Int_t minrow      = maxphi - isolcells;
184   Int_t mincol      = maxeta - isolcells;
185   Int_t maxrow      = maxphi + isolcells + ipatchcells;
186   Int_t maxcol      = maxeta + isolcells + ipatchcells;
187
188   AliDebug(2,Form("Number of added Isol Cells %d, Patch Size %d",isolcells, ipatchcells));
189   AliDebug(2,Form("Patch: minrow %d, maxrow %d, mincol %d, maxcol %d",minrow,maxrow,mincol,maxcol));
190   
191   if(minrow < 0 || mincol < 0 || maxrow > rowborder || maxcol > colborder){
192     AliDebug(1,Form("Out of Module/TRU range, cannot isolate patch"));
193     return kFALSE;
194   }
195   
196   //Add amplitudes in all isolation patch
197   for(Int_t irow = minrow ; irow <  maxrow; irow ++)
198     for(Int_t icol = mincol ; icol < maxcol ; icol ++)
199       amp += (*ampmatrix)(irow,icol);
200   
201   AliDebug(2,Form("Type %d, Maximum amplitude %f, patch+isol square %f",iPatchType, maxamp, amp));
202
203   if(amp < maxamp){
204     AliError(Form("Bad sum: Type %d, Maximum amplitude %f, patch+isol square %f",iPatchType, maxamp, amp));
205     return kFALSE;
206   }
207   else
208     amp-=maxamp; //Calculate energy in isolation patch that do not comes from maximum patch.
209   
210   AliDebug(2, Form("Maximum amplitude %f, Out of patch %f",maxamp, amp));
211
212   //Fill isolation amplitude data member and say if patch is isolated.
213   if(iPatchType == 0){ //2x2 case
214     f2x2AmpOutOfPatch = amp;   
215     if(amp < f2x2AmpOutOfPatchThres)
216       b=kTRUE;
217   }
218   else  if(iPatchType == 1){ //nxn case
219     fnxnAmpOutOfPatch = amp;   
220     if(amp < fnxnAmpOutOfPatchThres)
221       b=kTRUE;
222   }
223
224   return b;
225
226 }
227
228 //____________________________________________________________________________
229 void AliEMCALTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClonesArray * timeRtrus, const Int_t isupermod,TMatrixD *ampmax2, TMatrixD *ampmaxn){
230   
231   //Sums energy of all possible 2x2 (L0) and nxn (L1) cells per each TRU. 
232   //Fast signal in the experiment is given by 2x2 cells, 
233   //for this reason we loop inside the TRU cells by 2. 
234
235   //Declare and initialize variables
236   Int_t nCellsPhi  = fNCellsPhi;//geom->GetNPhi()*2/geom->GetNTRUPhi() ;
237   if(isupermod > 9)
238     nCellsPhi =  nCellsPhi / 2 ; //Half size SM. Not Final.
239   // 12(tow)*2(cell)/1 TRU, cells in Phi in one TRU
240   Int_t nCellsEta  = fNCellsEta ;//geom->GetNEta()*2/geom->GetNTRUEta() ;
241   // 24(mod)*2(tower)/3 TRU, cells in Eta in one TRU
242   //Int_t nTRU          = geom->GeNTRU();//3 TRU per super module
243
244   Float_t amp2 = 0 ;
245   Float_t ampn = 0 ; 
246   for(Int_t i = 0; i < 4; i++){
247     for(Int_t j = 0; j < fNTRU; j++){
248       (*ampmax2)(i,j) = -1;
249       (*ampmaxn)(i,j) = -1;
250     }
251   }
252
253   //Create matrix that will contain 2x2 amplitude sums
254   //used to calculate the nxn sums
255   TMatrixD  * tru2x2 = new TMatrixD(nCellsPhi/2,nCellsEta/2) ;
256   for(Int_t i = 0; i < nCellsPhi/2; i++)
257     for(Int_t j = 0; j < nCellsEta/2; j++)
258       (*tru2x2)(i,j) = -1;
259   
260   //Loop over all TRUS in a supermodule
261   for(Int_t itru = 0 + isupermod * fNTRU ; itru < (isupermod+1)*fNTRU ; itru++) {
262     TMatrixD * amptru   = dynamic_cast<TMatrixD *>(amptrus->At(itru)) ;
263     TMatrixD * timeRtru = dynamic_cast<TMatrixD *>(timeRtrus->At(itru)) ;
264     Int_t mtru = itru-isupermod*fNTRU ; //Number of TRU in Supermodule
265    
266     //Sliding 2x2, add 2x2 amplitudes (NOT OVERLAP)
267     for(Int_t irow = 0 ; irow <  nCellsPhi; irow += 2){ 
268       for(Int_t icol = 0 ; icol < nCellsEta ; icol += 2){
269         amp2 = (*amptru)(irow,icol)+(*amptru)(irow+1,icol)+
270           (*amptru)(irow,icol+1)+(*amptru)(irow+1,icol+1);
271
272         //Fill matrix with added 2x2 cells for use in nxn sums
273         (*tru2x2)(irow/2,icol/2) = amp2 ;
274         //Select 2x2 maximum sums to select L0 
275         if(amp2 > (*ampmax2)(0,mtru)){
276           (*ampmax2)(0,mtru) = amp2 ; 
277           (*ampmax2)(1,mtru) = irow;
278           (*ampmax2)(2,mtru) = icol;
279         }
280       }
281     }
282     
283     //Find most recent time in the selected 2x2 cell
284     (*ampmax2)(3,mtru) = 1 ;
285     Int_t row2 =  static_cast <Int_t> ((*ampmax2)(1,mtru));
286     Int_t col2 =  static_cast <Int_t> ((*ampmax2)(2,mtru));
287     for(Int_t i = 0; i<2; i++){
288       for(Int_t j = 0; j<2; j++){
289         if((*amptru)(row2+i,col2+j) > 0 &&  (*timeRtru)(row2+i,col2+j)> 0){       
290           if((*timeRtru)(row2+i,col2+j) <  (*ampmax2)(3,mtru)  )
291             (*ampmax2)(3,mtru) =  (*timeRtru)(row2+i,col2+j);
292         }
293       }
294     }
295
296     //Sliding nxn, add nxn amplitudes  (OVERLAP)
297     if(fPatchSize > 0){
298       for(Int_t irow = 0 ; irow <  nCellsPhi/2; irow++){ 
299         for(Int_t icol = 0 ; icol < nCellsEta/2 ; icol++){
300           ampn = 0;
301           if( (irow+fPatchSize) < nCellsPhi/2 && (icol+fPatchSize) < nCellsEta/2){//Avoid exit the TRU
302             for(Int_t i = 0 ; i <= fPatchSize ; i++)
303               for(Int_t j = 0 ; j <= fPatchSize ; j++)
304                 ampn += (*tru2x2)(irow+i,icol+j);
305             //Select nxn maximum sums to select L1 
306             if(ampn > (*ampmaxn)(0,mtru)){
307               (*ampmaxn)(0,mtru) = ampn ; 
308               (*ampmaxn)(1,mtru) = irow*2;
309               (*ampmaxn)(2,mtru) = icol*2;
310             }
311           }
312         }
313       }
314       
315       //Find most recent time in selected nxn cell
316       (*ampmaxn)(3,mtru) = 1 ;
317       Int_t rown =  static_cast <Int_t> ((*ampmaxn)(1,mtru));
318       Int_t coln =  static_cast <Int_t> ((*ampmaxn)(2,mtru));
319       for(Int_t i = 0; i<4*fPatchSize; i++){
320         for(Int_t j = 0; j<4*fPatchSize; j++){
321           if( (rown+i) < nCellsPhi && (coln+j) < nCellsEta/2){//Avoid exit the TRU
322             if((*amptru)(rown+i,coln+j) > 0 &&  (*timeRtru)(rown+i,coln+j)> 0){
323               if((*timeRtru)(rown+i,coln+j) <  (*ampmaxn)(3,mtru)  )
324                 (*ampmaxn)(3,mtru) =  (*timeRtru)(rown+i,coln+j);
325             }
326           }
327         }
328       }
329     }
330     else {  
331         (*ampmaxn)(0,mtru) =  (*ampmax2)(0,mtru); 
332         (*ampmaxn)(1,mtru) =  (*ampmax2)(1,mtru);
333         (*ampmaxn)(2,mtru) =  (*ampmax2)(2,mtru);
334         (*ampmaxn)(3,mtru) =  (*ampmax2)(3,mtru);
335       }
336   }
337 }
338
339 //____________________________________________________________________________
340 void AliEMCALTrigger::Print(const Option_t * opt) const 
341 {
342   
343   //Prints main parameters
344   
345   if(! opt)
346     return;
347   AliTriggerInput* in = 0x0 ;
348
349   printf( "             Maximum Amplitude after Sliding Cell, \n") ; 
350   printf( "               -2x2 cells sum (not overlapped): %10.2f, in Super Module %d\n",
351           f2x2MaxAmp,f2x2SM) ; 
352   printf( "               -2x2 from row %d to row %d and from column %d to column %d\n", f2x2CellPhi, f2x2CellPhi+2, f2x2CellEta, f2x2CellEta+2) ; 
353   printf( "               -2x2 Isolation Patch %d x %d, Amplitude out of 2x2 patch is %f, threshold %f, Isolated? %d \n", 
354           2*fIsolPatchSize+2, 2*fIsolPatchSize+2,  f2x2AmpOutOfPatch,  f2x2AmpOutOfPatchThres,static_cast<Int_t> (fIs2x2Isol)) ; 
355   if(fPatchSize > 0){
356     printf( "             Patch Size, n x n: %d x %d cells\n",2*(fPatchSize+1), 2*(fPatchSize+1));
357     printf( "               -nxn cells sum (overlapped)    : %10.2f, in Super Module %d\n",
358             fnxnMaxAmp,fnxnSM) ; 
359     printf( "               -nxn from row %d to row %d and from column %d to column %d\n", fnxnCellPhi, fnxnCellPhi+4*fPatchSize, fnxnCellEta, fnxnCellEta+4*fPatchSize) ; 
360     printf( "               -nxn Isolation Patch %d x %d, Amplitude out of nxn patch is %f, threshold %f, Isolated? %d \n", 
361             4*fIsolPatchSize+2*(fPatchSize+1),4*fIsolPatchSize+2*(fPatchSize+1) ,  fnxnAmpOutOfPatch,  fnxnAmpOutOfPatchThres,static_cast<Int_t> (fIsnxnIsol) ) ; 
362   }
363   
364   printf( "             Isolate in SuperModule? %d\n",  
365           fIsolateInSuperModule) ;  
366
367   printf( "             Threshold for LO %10.2f\n", 
368           fL0Threshold) ;  
369   in = (AliTriggerInput*)fInputs.FindObject( "EMCAL_L0" );
370   if(in->GetValue())
371     printf( "             *** EMCAL LO is set ***\n") ; 
372   
373   printf( "             Jet Low Pt Threshold for L1 %10.2f\n", 
374           fL1JetLowPtThreshold) ;
375   in = (AliTriggerInput*)fInputs.FindObject( "EMCAL_JetLPt_L1" );
376   if(in->GetValue())
377     printf( "             *** EMCAL Jet Low Pt for L1 is set ***\n") ;
378
379   printf( "             Jet Medium Pt Threshold for L1 %10.2f\n", 
380           fL1JetMediumPtThreshold) ;  
381   in = (AliTriggerInput*) fInputs.FindObject( "EMCAL_JetMPt_L1" );
382   if(in->GetValue())
383     printf( "             *** EMCAL Jet Medium Pt for L1 is set ***\n") ;
384
385   printf( "             Jet High Pt Threshold for L1 %10.2f\n", 
386           fL1JetHighPtThreshold) ;  
387   in = (AliTriggerInput*) fInputs.FindObject( "EMCAL_JetHPt_L1" );
388   if(in->GetValue())
389     printf( "             *** EMCAL Jet High Pt for L1 is set ***\n") ;
390
391 }
392
393 //____________________________________________________________________________
394 void AliEMCALTrigger::SetTriggers(const TClonesArray * ampmatrix,const Int_t iSM, 
395                                   const TMatrixD *ampmax2, 
396                                   const TMatrixD *ampmaxn, const AliEMCALGeometry *geom)  
397 {
398
399   //Checks the 2x2 and nxn maximum amplitude per each TRU and 
400   //compares with the different L0 and L1 triggers thresholds
401   Float_t max2[] = {-1,-1,-1,-1} ;
402   Float_t maxn[] = {-1,-1,-1,-1} ;
403   Int_t   mtru2  = -1 ;
404   Int_t   mtrun  = -1 ;
405
406   //Find maximum summed amplitude of all the TRU 
407   //in a Super Module
408     for(Int_t i = 0 ; i < fNTRU ; i++){
409       if(max2[0] < (*ampmax2)(0,i) ){
410         max2[0] =  (*ampmax2)(0,i) ; // 2x2 summed max amplitude
411         max2[1] =  (*ampmax2)(1,i) ; // corresponding phi position in TRU
412         max2[2] =  (*ampmax2)(2,i) ; // corresponding eta position in TRU
413         max2[3] =  (*ampmax2)(3,i) ; // corresponding most recent time
414         mtru2   = i ;
415       }
416       if(maxn[0] < (*ampmaxn)(0,i) ){
417         maxn[0] =  (*ampmaxn)(0,i) ; // nxn summed max amplitude
418         maxn[1] =  (*ampmaxn)(1,i) ; // corresponding phi position in TRU
419         maxn[2] =  (*ampmaxn)(2,i) ; // corresponding eta position in TRU
420         maxn[3] =  (*ampmaxn)(3,i) ; // corresponding most recent time
421         mtrun   = i ;
422       }
423     }
424
425   //--------Set max amplitude if larger than in other Super Modules------------
426   Float_t maxtimeR2 = -1 ;
427   Float_t maxtimeRn = -1 ;
428   AliRunLoader *rl  = AliRunLoader::GetRunLoader();
429   AliRun * gAlice   = rl->GetAliRun(); 
430   AliEMCAL * emcal  = (AliEMCAL*)gAlice->GetDetector("EMCAL");
431   Int_t nTimeBins = emcal->GetRawFormatTimeBins() ;
432
433   //Set max of 2x2 amplitudes and select L0 trigger
434   if(max2[0] > f2x2MaxAmp ){
435     f2x2MaxAmp  = max2[0] ;
436     f2x2SM      = iSM ;
437     maxtimeR2   = max2[3] ;
438     geom->GetCellPhiEtaIndexInSModuleFromTRUIndex(mtru2, 
439                                                   static_cast<Int_t>(max2[1]),
440                                                   static_cast<Int_t>(max2[2]),
441                                                   f2x2CellPhi,f2x2CellEta) ;
442     
443     //Isolated patch?
444     if(fIsolateInSuperModule)
445       fIs2x2Isol =  IsPatchIsolated(0, ampmatrix, iSM, mtru2,  f2x2MaxAmp, f2x2CellPhi,f2x2CellEta) ;
446     else
447       fIs2x2Isol =  IsPatchIsolated(0, ampmatrix, iSM, mtru2,  f2x2MaxAmp,  static_cast<Int_t>(max2[1]), static_cast<Int_t>(max2[2])) ;
448
449     //Transform digit amplitude in Raw Samples
450     fADCValuesLow2x2  = new Int_t[nTimeBins];
451     fADCValuesHigh2x2 = new Int_t[nTimeBins];
452     emcal->RawSampledResponse(maxtimeR2, f2x2MaxAmp, fADCValuesHigh2x2, fADCValuesLow2x2) ; 
453     
454     //Set Trigger Inputs, compare ADC time bins until threshold is attained
455     //Set L0
456     for(Int_t i = 0 ; i < nTimeBins ; i++){
457       if(fADCValuesHigh2x2[i] >= fL0Threshold          || fADCValuesLow2x2[i] >= fL0Threshold){
458         SetInput("EMCAL_L0") ;
459         break;
460       }
461     }
462   }
463   
464   //------------Set max of nxn amplitudes and select L1 trigger---------
465   if(maxn[0] > fnxnMaxAmp ){
466     fnxnMaxAmp  = maxn[0] ;
467     fnxnSM      = iSM ;
468     maxtimeRn   = maxn[3] ;
469     geom->GetCellPhiEtaIndexInSModuleFromTRUIndex(mtrun, 
470                                                   static_cast<Int_t>(maxn[1]),
471                                                   static_cast<Int_t>(maxn[2]),
472                                                   fnxnCellPhi,fnxnCellEta) ; 
473     
474     //Isolated patch?
475     if(fIsolateInSuperModule)
476       fIsnxnIsol =  IsPatchIsolated(1, ampmatrix, iSM, mtrun,  fnxnMaxAmp, fnxnCellPhi, fnxnCellEta) ;
477     else
478       fIsnxnIsol =  IsPatchIsolated(1, ampmatrix, iSM, mtrun,  fnxnMaxAmp,  static_cast<Int_t>(maxn[1]), static_cast<Int_t>(maxn[2])) ;
479     
480     //Transform digit amplitude in Raw Samples
481     fADCValuesHighnxn = new Int_t[nTimeBins];
482     fADCValuesLownxn  = new Int_t[nTimeBins];
483     emcal->RawSampledResponse(maxtimeRn, fnxnMaxAmp, fADCValuesHighnxn, fADCValuesLownxn) ;
484     
485     //Set Trigger Inputs, compare ADC time bins until threshold is attained
486     //SetL1 Low
487     for(Int_t i = 0 ; i < nTimeBins ; i++){
488       if(fADCValuesHighnxn[i] >= fL1JetLowPtThreshold  || fADCValuesLownxn[i] >= fL1JetLowPtThreshold){
489         SetInput("EMCAL_JetLPt_L1") ;
490         break; 
491       }
492     }
493     
494     //SetL1 Medium
495     for(Int_t i = 0 ; i < nTimeBins ; i++){
496       if(fADCValuesHighnxn[i] >= fL1JetMediumPtThreshold || fADCValuesLownxn[i] >= fL1JetMediumPtThreshold){
497         SetInput("EMCAL_JetMPt_L1") ;
498         break;
499       }
500     }
501     
502     //SetL1 High
503     for(Int_t i = 0 ; i < nTimeBins ; i++){
504       if(fADCValuesHighnxn[i] >= fL1JetHighPtThreshold || fADCValuesLownxn[i] >= fL1JetHighPtThreshold){
505         SetInput("EMCAL_JetHPt_L1") ;
506         break;
507       }
508     }
509   } 
510 }
511
512 //____________________________________________________________________________
513 void AliEMCALTrigger::Trigger() 
514 {
515   //Main Method to select triggers.
516   AliRunLoader *rl = AliRunLoader::GetRunLoader();
517   AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>
518     (rl->GetDetectorLoader("EMCAL"));
519   rl->LoadgAlice();  //Neede by calls to AliRun in SetTriggers
520  
521   //Load EMCAL Geometry
522   AliEMCALGeometry * geom =AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaulGeometryName());
523
524   if (geom==0)
525     AliFatal("Did not get geometry from EMCALLoader");
526   
527   //Define parameters
528   Int_t nSuperModules = geom->GetNumberOfSuperModules() ; //12 SM in EMCAL
529   fNTRU       = geom->GetNTRU();    //3 TRU per super module
530   fNTRUEta    = geom->GetNTRUEta(); //3 TRU in eta per super module
531   fNTRUPhi    = geom->GetNTRUPhi(); //1 TRU  in phi per super module
532   fNCellsPhi  = geom->GetNPhi()*2/geom->GetNTRUPhi() ;
533   fNCellsEta  = geom->GetNEta()*2/geom->GetNTRUEta() ;
534
535   //Intialize data members each time the trigger is called in event loop
536   f2x2MaxAmp = -1; f2x2CellPhi = -1;  f2x2CellEta = -1;
537   fnxnMaxAmp = -1; fnxnCellPhi = -1;  fnxnCellEta = -1;
538
539   //Take the digits list if simulation
540   if(fSimulation){
541     rl->LoadDigits("EMCAL");
542     fDigitsList = emcalLoader->Digits() ;
543   }
544   if(!fDigitsList)
545     AliFatal("Digits not found !") ;
546   
547   //Take the digits list 
548   
549   //Fill TRU Matrix  
550   TClonesArray * amptrus   = new TClonesArray("TMatrixD",1000);
551   TClonesArray * ampsmods  = new TClonesArray("TMatrixD",1000);
552   TClonesArray * timeRtrus = new TClonesArray("TMatrixD",1000);
553   
554   geom->FillTRU(fDigitsList, amptrus, ampsmods, timeRtrus) ;
555
556   //Do Cell Sliding and select Trigger
557   //Initialize varible that will contain maximum amplitudes and 
558   //its corresponding cell position in eta and phi, and time.
559   TMatrixD  * ampmax2 = new TMatrixD(4,fNTRU) ;
560   TMatrixD  * ampmaxn = new TMatrixD(4,fNTRU) ;
561   
562   for(Int_t iSM = 0 ; iSM < nSuperModules ; iSM++) {
563     //Do 2x2 and nxn sums, select maximums. 
564     MakeSlidingCell(amptrus, timeRtrus, iSM, ampmax2, ampmaxn);
565     
566     //Set the trigger
567     if(fIsolateInSuperModule)
568       SetTriggers(ampsmods,iSM,ampmax2,ampmaxn,geom) ;
569     if(!fIsolateInSuperModule)
570       SetTriggers(amptrus,iSM,ampmax2,ampmaxn,geom) ;
571   }
572   
573   //Print();
574
575 }