]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSTrigger.cxx
Fixing Effective C++ warnings (Laurent)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrigger.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 //  Class for trigger analysis.
20 //  Digits are grouped in TRU's (Trigger Units). A TRU consist of 16x28 
21 //  crystals ordered fNTRUPhi x fNTRUZ. The algorithm searches all possible 
22 //  4x4 crystal combinations per each TRU, adding the digits amplitude and 
23 //  finding the maximum. Maximums are transformed in ADC time samples. 
24 //  Each time bin is compared to the trigger threshold until it is larger 
25 //  and then, triggers are set. Thresholds need to be fixed. 
26 //  Usage:
27 //
28 //  //Inside the event loop
29 //  AliEMCALTrigger *tr = new AliEMCALTrigger();//Init Trigger
30 //  tr->SetL0Threshold(100);
31 //  tr->SetL1JetLowPtThreshold(1000);
32 //  tr->SetL1JetHighPtThreshold(20000);
33 //  tr->Trigger(); //Execute Trigger
34 //  tr->Print(""); //Print result, with "deb" option all data members 
35 //  //are printed
36 //
37 //*-- Author: Gustavo Conesa & Yves Schutz (IFIC, CERN) 
38 //////////////////////////////////////////////////////////////////////////////
39
40
41 // --- ROOT system ---
42 //#include "TMatrixD.h"
43
44 // --- ALIROOT system ---
45 #include "AliPHOS.h"
46 #include "AliPHOSTrigger.h" 
47 #include "AliPHOSGeometry.h"
48 #include "AliPHOSGetter.h" 
49 #include "AliTriggerInput.h"
50 //#include "AliLog.h"
51
52 ClassImp(AliPHOSTrigger)
53
54 //______________________________________________________________________
55 AliPHOSTrigger::AliPHOSTrigger()
56   : AliTriggerDetector(),
57     f2x2MaxAmp(-1), f2x2CrystalPhi(-1),  f2x2CrystalEta(-1), f2x2SM(0),
58     f4x4MaxAmp(-1), f4x4CrystalPhi(-1),  f4x4CrystalEta(-1), f4x4SM(0),
59     fADCValuesHigh4x4(0), fADCValuesLow4x4(0),
60     fADCValuesHigh2x2(0), fADCValuesLow2x2(0), fDigitsList(0),
61     fL0Threshold(50), fL1JetLowPtThreshold(200), fL1JetHighPtThreshold(500),
62     fNTRU(8), fNTRUZ(2), fNTRUPhi(4), fSimulation(kTRUE)
63 {
64   //ctor
65   fADCValuesHigh4x4 = 0x0; //new Int_t[fTimeBins];
66   fADCValuesLow4x4  = 0x0; //new Int_t[fTimeBins];
67   fADCValuesHigh2x2 = 0x0; //new Int_t[fTimeBins];
68   fADCValuesLow2x2  = 0x0; //new Int_t[fTimeBins];
69
70   SetName("PHOS");
71   CreateInputs();
72   
73   //Print("") ; 
74 }
75
76 //____________________________________________________________________________
77 AliPHOSTrigger::AliPHOSTrigger(const AliPHOSTrigger & trig) : 
78   AliTriggerDetector(trig),
79   f2x2MaxAmp(trig.f2x2MaxAmp),
80   f2x2CrystalPhi(trig.f2x2CrystalPhi),
81   f2x2CrystalEta(trig.f2x2CrystalEta),
82   f2x2SM(trig.f2x2SM),
83   f4x4MaxAmp(trig.f4x4MaxAmp),
84   f4x4CrystalPhi(trig.f4x4CrystalPhi),
85   f4x4CrystalEta(trig.f4x4CrystalEta),
86   f4x4SM(trig.f4x4SM),
87   fADCValuesHigh4x4(trig.fADCValuesHigh4x4),
88   fADCValuesLow4x4(trig.fADCValuesLow4x4),
89   fADCValuesHigh2x2(trig.fADCValuesHigh2x2),
90   fADCValuesLow2x2(trig.fADCValuesLow2x2),
91   fDigitsList(trig.fDigitsList),
92   fL0Threshold(trig.fL0Threshold),
93   fL1JetLowPtThreshold(trig.fL1JetLowPtThreshold),
94   fL1JetHighPtThreshold(trig.fL1JetHighPtThreshold),
95   fNTRU(trig.fNTRU),
96   fNTRUZ(trig.fNTRUZ),
97   fNTRUPhi(trig.fNTRUPhi),
98   fSimulation(trig.fSimulation)
99 {
100   // cpy ctor
101 }
102
103 //_________________________________________________________________________
104 AliPHOSTrigger & AliPHOSTrigger::operator = (const AliPHOSTrigger &)
105 {
106   Fatal("operator =", "no implemented");
107   return *this;
108 }
109
110 void AliPHOSTrigger::CreateInputs()
111 {
112    // inputs 
113    
114    // Do not create inputs again!!
115    if( fInputs.GetEntriesFast() > 0 ) return;
116    
117    fInputs.AddLast( new AliTriggerInput( "PHOS_L0",       "PHOS L0", 0x02 ) );
118    fInputs.AddLast( new AliTriggerInput( "PHOS_JetHPt_L1","PHOS Jet High Pt L1", 0x04 ) );
119    fInputs.AddLast( new AliTriggerInput( "PHOS_JetLPt_L1","PHOS Jet Low Pt L1", 0x08 ) );
120  
121 }
122
123 //____________________________________________________________________________
124 void AliPHOSTrigger::FillTRU(const TClonesArray * digits, const AliPHOSGeometry * geom, TClonesArray * ampmatrix, TClonesArray * timeRmatrix) const {
125
126   //Orders digits ampitudes list and times in fNTRU TRUs (28x16 crystals) 
127   //per module. Each TRU is a TMatrixD, and they are kept in TClonesArrays. 
128   //In a module, the number of TRU in phi is fNTRUPhi, and the number of 
129   //TRU in eta is fNTRUZ. 
130
131   //Check data members
132   
133   if(fNTRUZ*fNTRUPhi != fNTRU)
134     Error("FillTRU"," Wrong number of TRUS per Z or Phi");
135
136   //Initilize and declare variables
137   Int_t nModules     = geom->GetNModules();
138   Int_t nCrystalsPhi = geom->GetNPhi()/fNTRUPhi ;// 64/4=16
139   Int_t nCrystalsZ   = geom->GetNZ()/fNTRUZ ;// 56/2=28
140   Int_t relid[4] ; 
141   Float_t amp   = -1;
142   Float_t timeR = -1;
143   Int_t id      = -1;
144
145   //List of TRU matrices initialized to 0.
146   for(Int_t k = 0; k < fNTRU*nModules ; k++){
147     TMatrixD  * amptrus   = new TMatrixD(nCrystalsPhi,nCrystalsZ) ;
148     TMatrixD  * timeRtrus = new TMatrixD(nCrystalsPhi,nCrystalsZ) ;
149     for(Int_t i = 0; i < nCrystalsPhi; i++){
150       for(Int_t j = 0; j < nCrystalsZ; j++){
151         (*amptrus)(i,j)   = 0.0;
152         (*timeRtrus)(i,j) = 0.0;
153       }
154     }
155     new((*ampmatrix)[k])   TMatrixD(*amptrus) ;
156     new((*timeRmatrix)[k]) TMatrixD(*timeRtrus) ; 
157   }
158   
159   AliPHOSDigit * dig ;
160  
161   //Digits loop to fill TRU matrices with amplitudes.
162
163   for(Int_t idig = 0 ; idig < digits->GetEntriesFast() ; idig++){
164     
165     dig    = static_cast<AliPHOSDigit *>(digits->At(idig)) ;
166     amp    = dig->GetAmp() ;   // Energy of the digit (arbitrary units)
167     id     = dig->GetId() ;    // Id label of the cell
168     timeR  = dig->GetTimeR() ; // Earliest time of the digit
169     geom->AbsToRelNumbering(id, relid) ;
170     //Transform digit number into 4 numbers
171     //relid[0] = module
172     //relid[1] = EMC (0) or CPV (-1)
173     //relid[2] = row <= 64 (fNPhi)
174     //relid[3] = column <= 56 (fNZ)
175     
176     if(relid[1] == 0){//Not CPV, Only EMC digits
177      
178       //Check to which TRU in the supermodule belongs the crystal. 
179       //Supermodules are divided in a TRU matrix of dimension 
180       //(fNTRUPhi,fNTRUZ).
181       //Each TRU is a crystal matrix of dimension (nCrystalsPhi,nCrystalsZ)
182       
183       //First calculate the row and column in the supermodule 
184       //of the TRU to which the crystal belongs.
185       Int_t col   = (relid[3]-1)/nCrystalsZ+1; 
186       Int_t row   = (relid[2]-1)/nCrystalsPhi+1;
187  
188       //Calculate label number of the TRU  
189       Int_t itru  = (row-1) + (col-1)*fNTRUPhi + (relid[0]-1)*fNTRU ;
190
191       //Fill TRU matrix with crystal values
192       TMatrixD * amptrus   = dynamic_cast<TMatrixD *>(ampmatrix->At(itru)) ;
193       TMatrixD * timeRtrus = dynamic_cast<TMatrixD *>(timeRmatrix->At(itru)) ;
194
195       //Calculate row and column of the crystal inside the TRU with number itru
196       Int_t irow = (relid[2]-1) - (row-1) *  nCrystalsPhi;      
197       Int_t icol = (relid[3]-1) - (col-1) *  nCrystalsZ;
198       
199       (*amptrus)(irow,icol)   = amp ;
200       (*timeRtrus)(irow,icol) = timeR ;
201     }
202   }
203 }
204
205 //______________________________________________________________________
206 void AliPHOSTrigger::GetCrystalPhiEtaIndexInModuleFromTRUIndex(const Int_t itru,const Int_t iphitru,const Int_t ietatru,Int_t &iphiMod,Int_t &ietaMod,const AliPHOSGeometry* geom) const 
207 {
208   // This method transforms the (eta,phi) index of a crystals in a 
209   // TRU matrix into Super Module (eta,phi) index.
210   
211   // Calculate in which row and column in which the TRU are 
212   // ordered in the SM
213   Int_t col = itru/ fNTRUPhi + 1;
214   Int_t row = itru - (col-1)*fNTRUPhi + 1;
215   
216   //Calculate the (eta,phi) index in SM
217   Int_t nCrystalsPhi = geom->GetNPhi()/fNTRUPhi;
218   Int_t nCrystalsZ   = geom->GetNZ()/fNTRUZ;
219   
220   iphiMod = nCrystalsPhi*(row-1) + iphitru + 1 ;
221   ietaMod = nCrystalsZ*(col-1) + ietatru + 1 ;
222
223 }
224 //____________________________________________________________________________
225 void AliPHOSTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClonesArray * timeRtrus, const Int_t imod, TMatrixD *ampmax2, TMatrixD *ampmax4, const AliPHOSGeometry *geom){
226   //Sums energy of all possible 2x2 (L0) and 4x4 (L1) crystals per each TRU. 
227   //Fast signal in the experiment is given by 2x2 crystals, 
228   //for this reason we loop inside the TRU crystals by 2. 
229  
230   //Declare and initialize varibles
231   Int_t nCrystalsPhi = geom->GetNPhi()/fNTRUPhi ;// 64/4=16
232   Int_t nCrystalsZ   = geom->GetNZ()/fNTRUZ ;// 56/2=28
233   Float_t amp2 = 0 ;
234   Float_t amp4 = 0 ; 
235   for(Int_t i = 0; i < 3; i++){
236     for(Int_t j = 0; j < fNTRU; j++){
237       (*ampmax2)(i,j) = -1;
238       (*ampmax4)(i,j) = -1;
239     }
240   }
241
242   //Create matrix that will contain 2x2 amplitude sums
243   //used to calculate the 4x4 sums
244   TMatrixD  * tru2x2 = new TMatrixD(nCrystalsPhi/2,nCrystalsZ/2) ;
245
246   for(Int_t i = 0; i < nCrystalsPhi/2; i++)
247     for(Int_t j = 0; j < nCrystalsZ/2; j++)
248       (*tru2x2)(i,j) = 0.0;
249     
250   //Loop over all TRUS in a module
251   for(Int_t itru = 0 + (imod - 1) * fNTRU ; itru < imod*fNTRU ; itru++){
252     TMatrixD * amptru   = dynamic_cast<TMatrixD *>(amptrus->At(itru)) ;
253     TMatrixD * timeRtru = dynamic_cast<TMatrixD *>(timeRtrus->At(itru)) ;
254     Int_t mtru = itru-(imod-1)*fNTRU ; //Number of TRU in Module
255     
256     //Sliding 2x2, add 2x2 amplitudes (NOT OVERLAP)
257     for(Int_t irow = 0 ; irow <  nCrystalsPhi; irow += 2){ 
258       for(Int_t icol = 0 ; icol < nCrystalsZ ; icol += 2){
259         amp2 = (*amptru)(irow,icol)+(*amptru)(irow+1,icol)+
260           (*amptru)(irow,icol+1)+(*amptru)(irow+1,icol+1);
261         //Fill new matrix with added 2x2 crystals for use in 4x4 sums
262         (*tru2x2)(irow/2,icol/2) = amp2 ;
263         //Select 2x2 maximum sums to select L0 
264         if(amp2 > (*ampmax2)(0,mtru)){
265           (*ampmax2)(0,mtru) = amp2 ; 
266           (*ampmax2)(1,mtru) = irow;
267           (*ampmax2)(2,mtru) = icol;
268         }
269       }
270     }
271
272     //Find most recent time in the selected 2x2 cell
273     (*ampmax2)(3,mtru) = 1 ;
274     Int_t row2 =  static_cast <Int_t> ((*ampmax2)(1,mtru));
275     Int_t col2 =  static_cast <Int_t> ((*ampmax2)(2,mtru));
276     for(Int_t i = 0; i<2; i++){
277       for(Int_t j = 0; j<2; j++){
278         if((*amptru)(row2+i,col2+j) > 0 &&  (*timeRtru)(row2+i,col2+j)> 0){       
279           if((*timeRtru)(row2+i,col2+j) <  (*ampmax2)(3,mtru)  )
280             (*ampmax2)(3,mtru) =  (*timeRtru)(row2+i,col2+j);
281         }
282       }
283     }
284
285     //Sliding 4x4, add 4x4 amplitudes (OVERLAP)
286     for(Int_t irow = 0 ; irow <  nCrystalsPhi/2; irow++){ 
287       for(Int_t icol = 0 ; icol < nCrystalsZ/2 ; icol++){
288         if( (irow+1) < nCrystalsPhi/2 && (icol+1) < nCrystalsZ/2){//Avoid exit the TRU
289           amp4 = (*tru2x2)(irow,icol)+(*tru2x2)(irow+1,icol)+
290             (*tru2x2)(irow,icol+1)+(*tru2x2)(irow+1,icol+1);
291           //Select 4x4 maximum sums to select L1 
292           if(amp4 > (*ampmax4)(0,mtru)){
293             (*ampmax4)(0,mtru) = amp4 ; 
294             (*ampmax4)(1,mtru) = irow*2;
295             (*ampmax4)(2,mtru) = icol*2;
296           }
297         }
298       }
299     }
300
301     //Find most recent time in selected 4x4 cell
302     (*ampmax4)(3,mtru) = 1 ;
303     Int_t row4 =  static_cast <Int_t> ((*ampmax4)(1,mtru));
304     Int_t col4 =  static_cast <Int_t> ((*ampmax4)(2,mtru));
305     for(Int_t i = 0; i<4; i++){
306       for(Int_t j = 0; j<4; j++){
307         if((*amptru)(row4+i,col4+j) > 0 &&  (*timeRtru)(row4+i,col4+j)> 0){
308           if((*timeRtru)(row4+i,col4+j) <  (*ampmax4)(3,mtru)  )
309             (*ampmax4)(3,mtru) =  (*timeRtru)(row4+i,col4+j);
310         }
311       }
312     }
313   }
314 }
315
316 //____________________________________________________________________________
317 void AliPHOSTrigger::Print(const Option_t * opt) const 
318 {
319
320   //Prints main parameters
321  
322   if(! opt)
323     return;
324   AliTriggerInput* in = 0x0 ;
325
326   printf( "             Maximum Amplitude after Sliding Crystal, \n") ; 
327   printf( "               -2x2 crystals sum (not overlapped): %10.2f, in Super Module %d\n",
328           f2x2MaxAmp,f2x2SM) ; 
329   printf( "               -2x2 from row %d to row %d and from column %d to column %d\n", f2x2CrystalPhi, f2x2CrystalPhi+2, f2x2CrystalEta, f2x2CrystalEta+2) ; 
330   printf( "               -4x4 crystals sum (overlapped)    : %10.2f, in Super Module %d\n",
331           f4x4MaxAmp,f4x4SM) ; 
332   printf( "               -4x4 from row %d to row %d and from column %d to column %d\n", f4x4CrystalPhi, f4x4CrystalPhi+4, f4x4CrystalEta, f4x4CrystalEta+4) ; 
333   printf( "             Threshold for LO %10.1f\n", 
334           fL0Threshold) ;  
335   
336   printf( "             Threshold for LO %10.2f\n", fL0Threshold) ;  
337   in = (AliTriggerInput*)fInputs.FindObject( "PHOS_L0" );
338   if(in->GetValue())
339     printf( "             *** PHOS LO is set ***\n") ; 
340   
341   printf( "             Jet Low Pt Threshold for L1 %10.2f\n", fL1JetLowPtThreshold) ;
342   in = (AliTriggerInput*)fInputs.FindObject( "PHOS_JetLPt_L1" );
343   if(in->GetValue())
344     printf( "             *** PHOS Jet Low Pt for L1 is set ***\n") ;
345   
346   printf( "             Jet High Pt Threshold for L1 %10.2f\n", fL1JetHighPtThreshold) ;  
347   in = (AliTriggerInput*) fInputs.FindObject( "PHOS_JetHPt_L1" );
348   if(in->GetValue())
349     printf( "              *** PHOS Jet High Pt for L1 is set ***\n") ;
350  
351 }
352
353 //____________________________________________________________________________
354 void AliPHOSTrigger::SetTriggers(const Int_t iMod, const TMatrixD * ampmax2, const TMatrixD * ampmax4, const AliPHOSGeometry *geom)  
355 {
356   //Checks the 2x2 and 4x4 maximum amplitude per each TRU and compares 
357   //with the different L0 and L1 triggers thresholds
358
359   //Initialize variables
360   Float_t max2[] = {-1,-1,-1,-1} ;
361   Float_t max4[] = {-1,-1,-1,-1} ;
362   Int_t   itru2  = -1 ;
363   Int_t   itru4  = -1 ;
364
365
366   //Find maximum summed amplitude of all the TRU 
367   //in a Module
368   for(Int_t i = 0 ; i < fNTRU ; i++){
369     if(max2[0] < (*ampmax2)(0,i) ){
370       max2[0] =  (*ampmax2)(0,i) ; // 2x2 summed max amplitude
371       max2[1] =  (*ampmax2)(1,i) ; // corresponding phi position in TRU
372       max2[2] =  (*ampmax2)(2,i) ; // corresponding eta position in TRU
373       max2[3] =  (*ampmax2)(3,i) ; // corresponding most recent time
374       itru2   = i ; // TRU number
375     }
376     if(max4[0] < (*ampmax4)(0,i) ){
377       max4[0] =  (*ampmax4)(0,i) ; // 4x4 summed max amplitude
378       max4[1] =  (*ampmax4)(1,i) ; // corresponding phi position in TRU
379       max4[2] =  (*ampmax4)(2,i) ; // corresponding eta position in TRU
380       max4[3] =  (*ampmax4)(3,i) ; // corresponding most recent time
381       itru4   = i ; // TRU number
382     }
383   }
384   
385   //Set max amplitude if larger than in other Modules
386   Float_t maxtimeR2 = -1 ;
387   Float_t maxtimeR4 = -1 ;
388   AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
389   AliPHOS * phos  = gime->PHOS();
390   Int_t nTimeBins = phos->GetRawFormatTimeBins() ;
391  
392   //Set max 2x2 amplitude and select L0 trigger
393   if(max2[0] > f2x2MaxAmp ){
394     f2x2MaxAmp  = max2[0] ;
395     f2x2SM      = iMod ;
396     maxtimeR2   = max2[3] ;
397     GetCrystalPhiEtaIndexInModuleFromTRUIndex(itru2,static_cast<Int_t>(max2[1]),static_cast<Int_t>(max2[2]),f2x2CrystalPhi,f2x2CrystalEta,geom) ;
398     
399     //Transform digit amplitude in Raw Samples
400     fADCValuesLow2x2  = new Int_t[nTimeBins];
401     fADCValuesHigh2x2 = new Int_t[nTimeBins];
402     
403     phos->RawSampledResponse(maxtimeR2, f2x2MaxAmp, fADCValuesHigh2x2, fADCValuesLow2x2) ; 
404     
405     //Set Trigger Inputs, compare ADC time bins until threshold is attained
406     //Set L0
407     for(Int_t i = 0 ; i < nTimeBins ; i++){
408       if(fADCValuesHigh2x2[i] >= fL0Threshold          || fADCValuesLow2x2[i] >= fL0Threshold){
409         SetInput("PHOS_L0") ;
410         break;
411       }
412     }
413 //     for(Int_t i = 0 ; i < 256 ; i++)
414 //       if(fADCValuesLow2x2[i]!=0||fADCValuesHigh2x2[i]!=0)
415 //      cout<< "2x2 Time Bin "<<i
416 //          <<"; 2x2 Low Gain  "<<fADCValuesLow2x2[i]
417 //          <<"; 2x2 High Gain "<<fADCValuesHigh2x2[i]<<endl;
418   }
419
420   //Set max 4x4 amplitude and select L1 triggers
421   if(max4[0] > f4x4MaxAmp ){
422     f4x4MaxAmp  = max4[0] ;
423     f4x4SM      = iMod ;
424     maxtimeR4   = max4[3] ;
425     GetCrystalPhiEtaIndexInModuleFromTRUIndex(itru4,static_cast<Int_t>(max4[1]),static_cast<Int_t>(max4[2]),f4x4CrystalPhi,f4x4CrystalEta,geom) ; 
426     
427     //Transform digit amplitude in Raw Samples
428     fADCValuesHigh4x4 = new Int_t[nTimeBins];
429     fADCValuesLow4x4  = new Int_t[nTimeBins];
430     phos->RawSampledResponse(maxtimeR4, f4x4MaxAmp, fADCValuesHigh4x4, fADCValuesLow4x4) ;
431     
432     //Set Trigger Inputs, compare ADC time bins until threshold is attained
433     //SetL1 Low
434     for(Int_t i = 0 ; i < nTimeBins ; i++){
435       if(fADCValuesHigh4x4[i] >= fL1JetLowPtThreshold  || fADCValuesLow4x4[i] >= fL1JetLowPtThreshold){
436         SetInput("PHOS_JetLPt_L1") ;
437         break; 
438       }
439     }
440     //SetL1 High
441     for(Int_t i = 0 ; i < nTimeBins ; i++){
442       if(fADCValuesHigh4x4[i] >= fL1JetHighPtThreshold || fADCValuesLow4x4[i] >= fL1JetHighPtThreshold){
443         SetInput("PHOS_JetHPt_L1") ;
444         break;
445       }
446     }
447 //     for(Int_t i = 0 ; i < 256 ; i++)
448 //       if(fADCValuesLow4x4[i]!=0||fADCValuesHigh4x4[i]!=0)
449 //      cout<< "4x4 Time Bin "<<i
450 //          <<"; 4x4 Low Gain  "<<fADCValuesLow4x4[i]
451 //          <<"; 4x4 High Gain "<<fADCValuesHigh4x4[i]<<endl;
452   }
453 }
454
455 //____________________________________________________________________________
456 void AliPHOSTrigger::Trigger() 
457 {
458
459   //Main Method to select triggers.
460   AliRunLoader *rl = gAlice->GetRunLoader();
461   //Getter
462   AliPHOSGetter * gime = AliPHOSGetter::Instance( rl->GetFileName() ) ;
463   //AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
464
465   //Get Geometry
466   const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
467    
468   //Define parameters
469   Int_t nModules     = geom->GetNModules();
470
471   //Intialize data members each time the trigger is called in event loop
472   f2x2MaxAmp = -1; f2x2CrystalPhi = -1;  f2x2CrystalEta = -1;
473   f4x4MaxAmp = -1; f4x4CrystalPhi = -1;  f4x4CrystalEta = -1;
474
475   //Take the digits list if simulation
476   if(fSimulation)
477     fDigitsList = gime->Digits() ;
478   
479   if(!fDigitsList)
480     AliFatal("Digits not found !") ;
481   
482   //Fill TRU Matrix  
483   TClonesArray * amptrus   = new TClonesArray("TMatrixD",1000);
484   TClonesArray * timeRtrus = new TClonesArray("TMatrixD",1000);
485   FillTRU(fDigitsList,geom,amptrus, timeRtrus) ;
486
487   //Do Crystal Sliding and select Trigger
488   //Initialize varible that will contain maximum amplitudes and 
489   //its corresponding cell position in eta and phi, and time.
490   TMatrixD  * ampmax2 = new TMatrixD(4,fNTRU) ;
491   TMatrixD  * ampmax4 = new TMatrixD(4,fNTRU) ;
492
493   for(Int_t imod = 1 ; imod <= nModules ; imod++) {
494     //Do 2x2 and 4x4 sums, select maximums. 
495     MakeSlidingCell(amptrus, timeRtrus, imod, ampmax2, ampmax4, geom);
496     //Set the trigger
497     SetTriggers(imod,ampmax2,ampmax4, geom) ;
498   }
499 }