]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSTrigger.cxx
Adding information from the PHOS trigger (Gustavo, Yves)
[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 //  2x2 and nxn (n multiple of 4) crystal combinations per each TRU, adding the 
23 //  digits amplitude and  finding the maximum. Iti is found is maximum 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 //  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 //  ....
34 //  tr->Trigger(); //Execute Trigger
35 //  tr->Print(""); //Print data members after calculation.
36 //  
37 //
38 //*-- Author: Gustavo Conesa & Yves Schutz (IFIC, CERN) 
39 //////////////////////////////////////////////////////////////////////////////
40
41
42 // --- ROOT system ---
43 //#include "TMatrixD.h"
44
45 // --- ALIROOT system ---
46 #include "AliPHOS.h"
47 #include "AliPHOSTrigger.h" 
48 #include "AliPHOSGeometry.h"
49 #include "AliPHOSGetter.h" 
50 #include "AliPHOSPulseGenerator.h" 
51 #include "AliTriggerInput.h"
52 //#include "AliLog.h"
53
54 ClassImp(AliPHOSTrigger)
55
56 //______________________________________________________________________
57 AliPHOSTrigger::AliPHOSTrigger()
58   : AliTriggerDetector(),
59     f2x2MaxAmp(-1), f2x2CrystalPhi(-1),  f2x2CrystalEta(-1), f2x2SM(0),
60     fnxnMaxAmp(-1), fnxnCrystalPhi(-1),  fnxnCrystalEta(-1), fnxnSM(0),
61     fADCValuesHighnxn(0), fADCValuesLownxn(0),
62     fADCValuesHigh2x2(0), fADCValuesLow2x2(0), fDigitsList(0),
63     fL0Threshold(50), fL1JetLowPtThreshold(200), fL1JetHighPtThreshold(500),
64     fNTRU(8), fNTRUZ(2), fNTRUPhi(4), 
65     fNCrystalsPhi(16),
66     fNCrystalsZ(28),
67     fPatchSize(1), fIsolPatchSize(1), 
68     f2x2AmpOutOfPatch(-1), fnxnAmpOutOfPatch(-1), 
69     f2x2AmpOutOfPatchThres(2),  fnxnAmpOutOfPatchThres(2), //2 GeV out of patch 
70     fIs2x2Isol(kFALSE), fIsnxnIsol(kFALSE),  
71     fSimulation(kTRUE)
72 {
73   //ctor
74   fADCValuesHighnxn = 0x0; //new Int_t[fTimeBins];
75   fADCValuesLownxn  = 0x0; //new Int_t[fTimeBins];
76   fADCValuesHigh2x2 = 0x0; //new Int_t[fTimeBins];
77   fADCValuesLow2x2  = 0x0; //new Int_t[fTimeBins];
78
79   SetName("PHOS");
80   CreateInputs();
81   
82   //Print("") ; 
83 }
84
85 //____________________________________________________________________________
86 AliPHOSTrigger::AliPHOSTrigger(const AliPHOSTrigger & trig) : 
87   AliTriggerDetector(trig),
88   f2x2MaxAmp(trig.f2x2MaxAmp),
89   f2x2CrystalPhi(trig.f2x2CrystalPhi),
90   f2x2CrystalEta(trig.f2x2CrystalEta),
91   f2x2SM(trig.f2x2SM),
92   fnxnMaxAmp(trig.fnxnMaxAmp),
93   fnxnCrystalPhi(trig.fnxnCrystalPhi),
94   fnxnCrystalEta(trig.fnxnCrystalEta),
95   fnxnSM(trig.fnxnSM),
96   fADCValuesHighnxn(trig.fADCValuesHighnxn),
97   fADCValuesLownxn(trig.fADCValuesLownxn),
98   fADCValuesHigh2x2(trig.fADCValuesHigh2x2),
99   fADCValuesLow2x2(trig.fADCValuesLow2x2),
100   fDigitsList(trig.fDigitsList),
101   fL0Threshold(trig.fL0Threshold),
102   fL1JetLowPtThreshold(trig.fL1JetLowPtThreshold),
103   fL1JetHighPtThreshold(trig.fL1JetHighPtThreshold),
104   fNTRU(trig.fNTRU),
105   fNTRUZ(trig.fNTRUZ),
106   fNTRUPhi(trig.fNTRUPhi),
107   fNCrystalsPhi(trig.fNCrystalsPhi),
108   fNCrystalsZ(trig. fNCrystalsZ),
109   fPatchSize(trig.fPatchSize),
110   fIsolPatchSize(trig.fIsolPatchSize), 
111   f2x2AmpOutOfPatch(trig.f2x2AmpOutOfPatch), 
112   fnxnAmpOutOfPatch(trig.fnxnAmpOutOfPatch), 
113   f2x2AmpOutOfPatchThres(trig.f2x2AmpOutOfPatchThres),  
114   fnxnAmpOutOfPatchThres(trig.fnxnAmpOutOfPatchThres), 
115   fIs2x2Isol(trig.fIs2x2Isol),
116   fIsnxnIsol(trig.fIsnxnIsol),  
117   fSimulation(trig.fSimulation)
118 {
119   // cpy ctor
120 }
121
122 //_________________________________________________________________________
123 AliPHOSTrigger & AliPHOSTrigger::operator = (const AliPHOSTrigger &)
124 {
125   Fatal("operator =", "no implemented");
126   return *this;
127 }
128
129 void AliPHOSTrigger::CreateInputs()
130 {
131    // inputs 
132    
133    // Do not create inputs again!!
134    if( fInputs.GetEntriesFast() > 0 ) return;
135    
136    fInputs.AddLast( new AliTriggerInput( "PHOS_L0",       "PHOS L0", 0x02 ) );
137    fInputs.AddLast( new AliTriggerInput( "PHOS_JetHPt_L1","PHOS Jet High Pt L1", 0x04 ) );
138    fInputs.AddLast( new AliTriggerInput( "PHOS_JetLPt_L1","PHOS Jet Low Pt L1", 0x08 ) );
139  
140 }
141
142 //____________________________________________________________________________
143 void AliPHOSTrigger::FillTRU(const TClonesArray * digits, const AliPHOSGeometry * geom, TClonesArray * ampmatrix, TClonesArray * timeRmatrix) const {
144
145   //Orders digits ampitudes list and times in fNTRU TRUs (28x16 crystals) 
146   //per module. Each TRU is a TMatrixD, and they are kept in TClonesArrays. 
147   //In a module, the number of TRU in phi is fNTRUPhi, and the number of 
148   //TRU in eta is fNTRUZ. 
149
150   //Check data members
151   
152   if(fNTRUZ*fNTRUPhi != fNTRU)
153     Error("FillTRU"," Wrong number of TRUS per Z or Phi");
154
155   //Initilize and declare variables
156   Int_t nModules     = geom->GetNModules();
157   Int_t relid[4] ; 
158   Float_t amp   = -1;
159   Float_t timeR = -1;
160   Int_t id      = -1;
161
162   //List of TRU matrices initialized to 0.
163   for(Int_t k = 0; k < fNTRU*nModules ; k++){
164     TMatrixD  * amptrus   = new TMatrixD(fNCrystalsPhi,fNCrystalsZ) ;
165     TMatrixD  * timeRtrus = new TMatrixD(fNCrystalsPhi,fNCrystalsZ) ;
166     for(Int_t i = 0; i < fNCrystalsPhi; i++){
167       for(Int_t j = 0; j < fNCrystalsZ; j++){
168         (*amptrus)(i,j)   = 0.0;
169         (*timeRtrus)(i,j) = 0.0;
170       }
171     }
172     new((*ampmatrix)[k])   TMatrixD(*amptrus) ;
173     new((*timeRmatrix)[k]) TMatrixD(*timeRtrus) ; 
174   }
175   
176   AliPHOSDigit * dig ;
177  
178   //Digits loop to fill TRU matrices with amplitudes.
179
180   for(Int_t idig = 0 ; idig < digits->GetEntriesFast() ; idig++){
181     
182     dig    = static_cast<AliPHOSDigit *>(digits->At(idig)) ;
183     amp    = dig->GetEnergy() ;   // Energy of the digit 
184     id     = dig->GetId() ;    // Id label of the cell
185     timeR  = dig->GetTimeR() ; // Earliest time of the digit
186     geom->AbsToRelNumbering(id, relid) ;
187     //Transform digit number into 4 numbers
188     //relid[0] = module
189     //relid[1] = EMC (0) or CPV (-1)
190     //relid[2] = row <= 64 (fNPhi)
191     //relid[3] = column <= 56 (fNZ)
192     
193     if(relid[1] == 0){//Not CPV, Only EMC digits
194      
195       //Check to which TRU in the supermodule belongs the crystal. 
196       //Supermodules are divided in a TRU matrix of dimension 
197       //(fNTRUPhi,fNTRUZ).
198       //Each TRU is a crystal matrix of dimension (fNCrystalsPhi,fNCrystalsZ)
199       
200       //First calculate the row and column in the supermodule 
201       //of the TRU to which the crystal belongs.
202       Int_t col   = (relid[3]-1)/fNCrystalsZ+1; 
203       Int_t row   = (relid[2]-1)/fNCrystalsPhi+1;
204  
205       //Calculate label number of the TRU  
206       Int_t itru  = (row-1) + (col-1)*fNTRUPhi + (relid[0]-1)*fNTRU ;
207
208       //Fill TRU matrix with crystal values
209       TMatrixD * amptrus   = dynamic_cast<TMatrixD *>(ampmatrix->At(itru)) ;
210       TMatrixD * timeRtrus = dynamic_cast<TMatrixD *>(timeRmatrix->At(itru)) ;
211
212       //Calculate row and column of the crystal inside the TRU with number itru
213       Int_t irow = (relid[2]-1) - (row-1) *  fNCrystalsPhi;     
214       Int_t icol = (relid[3]-1) - (col-1) *  fNCrystalsZ;
215       
216       (*amptrus)(irow,icol)   = amp ;
217       (*timeRtrus)(irow,icol) = timeR ;
218     }
219   }
220 }
221
222 //______________________________________________________________________
223 void AliPHOSTrigger::GetCrystalPhiEtaIndexInModuleFromTRUIndex(const Int_t itru,const Int_t iphitru,const Int_t ietatru,Int_t &iphiMod,Int_t &ietaMod) const 
224 {
225   // This method transforms the (eta,phi) index of a crystals in a 
226   // TRU matrix into Super Module (eta,phi) index.
227   
228   // Calculate in which row and column in which the TRU are 
229   // ordered in the SM
230   Int_t col = itru/ fNTRUPhi + 1;
231   Int_t row = itru - (col-1)*fNTRUPhi + 1;
232   
233   //Calculate the (eta,phi) index in SM
234   
235   iphiMod = fNCrystalsPhi*(row-1) + iphitru + 1 ;
236   ietaMod = fNCrystalsZ*(col-1) + ietatru + 1 ;
237
238 }
239
240 //____________________________________________________________________________
241 Bool_t AliPHOSTrigger::IsPatchIsolated(Int_t iPatchType, const TClonesArray * amptrus, const Int_t mtru, const Int_t imod, const Float_t *maxarray) {
242
243   //Calculate if the maximum patch found is isolated, find amplitude around maximum (2x2 or nxn) patch, 
244   //inside isolation patch . iPatchType = 0 means calculation for 2x2 patch, 
245   //iPatchType = 1 means calculation for nxn patch.
246   //In the next table there is an example of the different options of patch size and isolation patch size:
247   //                                                                                 Patch Size (fPatchSize)
248   //                                                             0                          1                                  2
249   //          fIsolPatchSize                 2x2 (not overlap)   4x4 (overlapped)        6x6(overlapped) ...
250   //                   1                                       4x4                      8x8                              10x10
251   //                   2                                       6x6                     12x12                           14x14    
252   //                   3                                       8x8                     16x16                           18x18
253                           
254   Bool_t b = kFALSE;
255   Float_t amp = 0;
256  
257  //Get matrix of TRU with maximum amplitude patch.
258   Int_t itru = mtru+imod*fNTRU ; //number of tru, min 0 max 8*5.
259   TMatrixD * amptru   = dynamic_cast<TMatrixD *>(amptrus->At(itru)) ;
260  
261   //Define patch cells
262   Int_t isolcells = fIsolPatchSize*(1+iPatchType);
263   Int_t ipatchcells = 2*(1+fPatchSize*iPatchType);
264   Int_t minrow =  static_cast<Int_t>(maxarray[1]) - isolcells;
265   Int_t mincol =  static_cast<Int_t>(maxarray[2]) - isolcells;
266   Int_t maxrow =  static_cast<Int_t>(maxarray[1]) + isolcells + ipatchcells;
267   Int_t maxcol =  static_cast<Int_t>(maxarray[2]) +  isolcells + ipatchcells;
268
269   AliDebug(2,Form("Number of added Isol Cells %d, Patch Size %d",isolcells, ipatchcells));
270   AliDebug(2,Form("Patch: minrow %d, maxrow %d, mincol %d, maxcol %d",minrow,maxrow,mincol,maxcol));
271
272   if(minrow < 0 || mincol < 0 || maxrow > fNCrystalsPhi || maxcol > fNCrystalsZ){
273     AliDebug(1,Form("Out of TRU range, cannot isolate patch"));
274     return kFALSE;
275   }
276
277   //Add amplitudes in all isolation patch
278   for(Int_t irow = minrow ; irow <  maxrow; irow ++)
279     for(Int_t icol = mincol ; icol < maxcol ; icol ++)
280       amp += (*amptru)(irow,icol);
281
282   AliDebug(2,Form("Type %d, Maximum amplitude %f, patch+isol square %f",iPatchType, maxarray[0], amp));
283
284   if(amp < maxarray[0]){
285     AliError(Form("Bad sum: Type %d, Maximum amplitude %f, patch+isol square %f",iPatchType, maxarray[0], amp));
286     return kFALSE;
287   }
288   else
289     amp-=maxarray[0]; //Calculate energy in isolation patch that do not comes from maximum patch.
290   
291   AliDebug(2, Form("Maximum amplitude %f, Out of patch %f",maxarray[0], amp));
292
293   //Fill isolation amplitude data member and say if patch is isolated.
294   if(iPatchType == 0){ //2x2 case
295     f2x2AmpOutOfPatch = amp;   
296     if(amp < f2x2AmpOutOfPatchThres)
297       b=kTRUE;
298   }
299   else  if(iPatchType == 1){ //nxn case
300     fnxnAmpOutOfPatch = amp;   
301     if(amp < fnxnAmpOutOfPatchThres)
302       b=kTRUE;
303   }
304
305   return b;
306
307 }
308
309
310 //____________________________________________________________________________
311 void AliPHOSTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClonesArray * timeRtrus, const Int_t imod, TMatrixD *ampmax2, TMatrixD *ampmaxn){
312   //Sums energy of all possible 2x2 (L0) and nxn (L1) crystals per each TRU. 
313   //Fast signal in the experiment is given by 2x2 crystals, 
314   //for this reason we loop inside the TRU crystals by 2. 
315  
316   //Declare and initialize varibles
317   Float_t amp2 = 0 ;
318   Float_t ampn = 0 ; 
319   for(Int_t i = 0; i < 4; i++){
320     for(Int_t j = 0; j < fNTRU; j++){
321       (*ampmax2)(i,j) = -1;
322       (*ampmaxn)(i,j) = -1;
323     }
324   }
325
326   //Create matrix that will contain 2x2 amplitude sums
327   //used to calculate the nxn sums
328   TMatrixD  * tru2x2 = new TMatrixD(fNCrystalsPhi/2,fNCrystalsZ/2) ;
329   for(Int_t i = 0; i < fNCrystalsPhi/2; i++)
330     for(Int_t j = 0; j < fNCrystalsZ/2; j++)
331       (*tru2x2)(i,j) = -1.;
332     
333   //Loop over all TRUS in a module
334   for(Int_t itru = 0 + imod  * fNTRU ; itru < (imod+1)*fNTRU ; itru++){
335     TMatrixD * amptru   = dynamic_cast<TMatrixD *>(amptrus->At(itru)) ;
336     TMatrixD * timeRtru = dynamic_cast<TMatrixD *>(timeRtrus->At(itru)) ;
337     Int_t mtru = itru-imod*fNTRU ; //Number of TRU in Module
338     
339     //Sliding 2x2, add 2x2 amplitudes (NOT OVERLAP)
340     for(Int_t irow = 0 ; irow <  fNCrystalsPhi; irow += 2){ 
341       for(Int_t icol = 0 ; icol < fNCrystalsZ ; icol += 2){
342         amp2 = (*amptru)(irow,icol)+(*amptru)(irow+1,icol)+
343           (*amptru)(irow,icol+1)+(*amptru)(irow+1,icol+1);
344         //Fill new matrix with added 2x2 crystals for use in nxn sums
345         (*tru2x2)(irow/2,icol/2) = amp2 ;
346         //Select 2x2 maximum sums to select L0 
347         if(amp2 > (*ampmax2)(0,mtru)){
348           (*ampmax2)(0,mtru) = amp2 ; 
349           (*ampmax2)(1,mtru) = irow;
350           (*ampmax2)(2,mtru) = icol;
351         }
352       }
353     }
354
355     //Find most recent time in the selected 2x2 cell
356     (*ampmax2)(3,mtru) = 1 ;
357     Int_t row2 =  static_cast <Int_t> ((*ampmax2)(1,mtru));
358     Int_t col2 =  static_cast <Int_t> ((*ampmax2)(2,mtru));
359     for(Int_t i = 0; i<2; i++){
360       for(Int_t j = 0; j<2; j++){
361         if((*amptru)(row2+i,col2+j) > 0 &&  (*timeRtru)(row2+i,col2+j)> 0){       
362           if((*timeRtru)(row2+i,col2+j) <  (*ampmax2)(3,mtru)  )
363             (*ampmax2)(3,mtru) =  (*timeRtru)(row2+i,col2+j);
364         }
365       }
366     }
367
368     //Sliding nxn, add nxn amplitudes (OVERLAP)
369     if(fPatchSize > 0){
370       for(Int_t irow = 0 ; irow <  fNCrystalsPhi/2; irow++){ 
371         for(Int_t icol = 0 ; icol < fNCrystalsZ/2 ; icol++){
372           ampn = 0;
373           if( (irow+fPatchSize) < fNCrystalsPhi/2 && (icol+fPatchSize) < fNCrystalsZ/2){//Avoid exit the TRU
374             for(Int_t i = 0 ; i <= fPatchSize ; i++)
375               for(Int_t j = 0 ; j <= fPatchSize ; j++)
376                 ampn += (*tru2x2)(irow+i,icol+j);
377             //Select nxn maximum sums to select L1 
378             if(ampn > (*ampmaxn)(0,mtru)){
379               (*ampmaxn)(0,mtru) = ampn ; 
380               (*ampmaxn)(1,mtru) = irow*2;
381               (*ampmaxn)(2,mtru) = icol*2;
382             }
383           }
384         }
385       }
386       
387       //Find most recent time in selected nxn cell
388       (*ampmaxn)(3,mtru) = 1 ;
389       Int_t rown =  static_cast <Int_t> ((*ampmaxn)(1,mtru));
390       Int_t coln =  static_cast <Int_t> ((*ampmaxn)(2,mtru));
391       for(Int_t i = 0; i<4*fPatchSize; i++){
392         for(Int_t j = 0; j<4*fPatchSize; j++){
393           if( (rown+i) < fNCrystalsPhi && (coln+j) < fNCrystalsZ/2){//Avoid exit the TRU
394             if((*amptru)(rown+i,coln+j) > 0 &&  (*timeRtru)(rown+i,coln+j)> 0){
395               if((*timeRtru)(rown+i,coln+j) <  (*ampmaxn)(3,mtru)  )
396                 (*ampmaxn)(3,mtru) =  (*timeRtru)(rown+i,coln+j);
397             }
398           }
399         }
400       }
401     }
402     else {  
403         (*ampmaxn)(0,mtru) =  (*ampmax2)(0,mtru); 
404         (*ampmaxn)(1,mtru) =  (*ampmax2)(1,mtru);
405         (*ampmaxn)(2,mtru) =  (*ampmax2)(2,mtru);
406         (*ampmaxn)(3,mtru) =  (*ampmax2)(3,mtru);
407       }
408   }
409 }
410
411
412 //____________________________________________________________________________
413 void AliPHOSTrigger::Print(const Option_t * opt) const 
414 {
415
416   //Prints main parameters
417  
418   if(! opt)
419     return;
420   AliTriggerInput* in = 0x0 ;
421
422   printf( "             Maximum Amplitude after Sliding Crystal, \n") ; 
423   printf( "               -2x2 crystals sum (not overlapped): %10.2f, in Super Module %d\n",
424           f2x2MaxAmp,f2x2SM) ; 
425   printf( "               -2x2 from row %d to row %d and from column %d to column %d\n", f2x2CrystalPhi, f2x2CrystalPhi+2, f2x2CrystalEta, f2x2CrystalEta+2) ; 
426   printf( "               -2x2 Isolation Patch %d x %d, Amplitude out of 2x2 patch is %f, threshold %f, Isolated? %d \n", 
427           2*fIsolPatchSize+2, 2*fIsolPatchSize+2,  f2x2AmpOutOfPatch,  f2x2AmpOutOfPatchThres,static_cast<Int_t> (fIs2x2Isol)) ; 
428   if(fPatchSize > 0){
429     printf( "             Patch Size, n x n: %d x %d cells\n",2*(fPatchSize+1), 2*(fPatchSize+1));
430     printf( "               -nxn crystals sum (overlapped)    : %10.2f, in Super Module %d\n",
431             fnxnMaxAmp,fnxnSM) ; 
432     printf( "               -nxn from row %d to row %d and from column %d to column %d\n", fnxnCrystalPhi, fnxnCrystalPhi+4, fnxnCrystalEta, fnxnCrystalEta+4) ; 
433     printf( "               -nxn Isolation Patch %d x %d, Amplitude out of nxn patch is %f, threshold %f, Isolated? %d \n", 
434             4*fIsolPatchSize+2*(fPatchSize+1),4*fIsolPatchSize+2*(fPatchSize+1) ,  fnxnAmpOutOfPatch,  fnxnAmpOutOfPatchThres,static_cast<Int_t> (fIsnxnIsol) ) ; 
435   }
436   printf( "             Threshold for LO %10.1f\n", 
437           fL0Threshold) ;  
438   
439   printf( "             Threshold for LO %10.2f\n", fL0Threshold) ;  
440   in = (AliTriggerInput*)fInputs.FindObject( "PHOS_L0" );
441   if(in->GetValue())
442     printf( "             *** PHOS LO is set ***\n") ; 
443   
444   printf( "             Jet Low Pt Threshold for L1 %10.2f\n", fL1JetLowPtThreshold) ;
445   in = (AliTriggerInput*)fInputs.FindObject( "PHOS_JetLPt_L1" );
446   if(in->GetValue())
447     printf( "             *** PHOS Jet Low Pt for L1 is set ***\n") ;
448   
449   printf( "             Jet High Pt Threshold for L1 %10.2f\n", fL1JetHighPtThreshold) ;  
450   in = (AliTriggerInput*) fInputs.FindObject( "PHOS_JetHPt_L1" );
451   if(in->GetValue())
452     printf( "              *** PHOS Jet High Pt for L1 is set ***\n") ;
453  
454 }
455
456 //____________________________________________________________________________
457 void AliPHOSTrigger::SetTriggers(const TClonesArray * amptrus, const Int_t iMod, const TMatrixD * ampmax2, const TMatrixD * ampmaxn)  
458 {
459   //Checks the 2x2 and nxn maximum amplitude per each TRU and compares 
460   //with the different L0 and L1 triggers thresholds. It finds if maximum amplitudes are isolated.
461
462   //Initialize variables
463   Float_t max2[] = {-1,-1,-1,-1} ;
464   Float_t maxn[] = {-1,-1,-1,-1} ;
465   Int_t   mtru2  = -1 ;
466   Int_t   mtrun  = -1 ;
467
468
469   //Find maximum summed amplitude of all the TRU 
470   //in a Module
471   for(Int_t i = 0 ; i < fNTRU ; i++){
472     if(max2[0] < (*ampmax2)(0,i) ){
473       max2[0] =  (*ampmax2)(0,i) ; // 2x2 summed max amplitude
474       max2[1] =  (*ampmax2)(1,i) ; // corresponding phi position in TRU
475       max2[2] =  (*ampmax2)(2,i) ; // corresponding eta position in TRU
476       max2[3] =  (*ampmax2)(3,i) ; // corresponding most recent time
477       mtru2   = i ; // TRU number in module
478     }
479     if(maxn[0] < (*ampmaxn)(0,i) ){
480       maxn[0] =  (*ampmaxn)(0,i) ; // nxn summed max amplitude
481       maxn[1] =  (*ampmaxn)(1,i) ; // corresponding phi position in TRU
482       maxn[2] =  (*ampmaxn)(2,i) ; // corresponding eta position in TRU
483       maxn[3] =  (*ampmaxn)(3,i) ; // corresponding most recent time
484       mtrun   = i ; // TRU number in module
485     }
486   }
487   
488   //Set max amplitude if larger than in other Modules
489   Float_t maxtimeR2 = -1 ;
490   Float_t maxtimeRn = -1 ;
491   // Create a shaper pulse object
492   AliPHOSPulseGenerator *pulse = new AliPHOSPulseGenerator();
493   Int_t nTimeBins = pulse->GetRawFormatTimeBins() ;
494  
495   //Set max 2x2 amplitude and select L0 trigger
496   if(max2[0] > f2x2MaxAmp ){
497     f2x2MaxAmp  = max2[0] ;
498     f2x2SM      = iMod ;
499     maxtimeR2   = max2[3] ;
500     GetCrystalPhiEtaIndexInModuleFromTRUIndex(mtru2,
501                                               static_cast<Int_t>(max2[1]),
502                                               static_cast<Int_t>(max2[2]),
503                                               f2x2CrystalPhi,f2x2CrystalEta) ;
504     
505     //Isolated patch?
506     fIs2x2Isol =  IsPatchIsolated(0, amptrus, mtru2, iMod, max2) ;
507
508     //Transform digit amplitude in Raw Samples
509     fADCValuesLow2x2  = new Int_t[nTimeBins];
510     fADCValuesHigh2x2 = new Int_t[nTimeBins];
511     
512     pulse->SetAmplitude(f2x2MaxAmp);
513     pulse->SetTZero(maxtimeR2);
514     pulse->MakeSamples();
515     pulse->GetSamples(fADCValuesHigh2x2, fADCValuesLow2x2) ; 
516     
517     //Set Trigger Inputs, compare ADC time bins until threshold is attained
518     //Set L0
519     for(Int_t i = 0 ; i < nTimeBins ; i++){
520       if(fADCValuesHigh2x2[i] >= fL0Threshold || fADCValuesLow2x2[i] >= fL0Threshold) {
521         SetInput("PHOS_L0") ;
522         break;
523       }
524     }
525   }
526
527   //Set max nxn amplitude and select L1 triggers
528   if(maxn[0] > fnxnMaxAmp  && fPatchSize > 0){
529     fnxnMaxAmp  = maxn[0] ;
530     fnxnSM      = iMod ;
531     maxtimeRn   = maxn[3] ;
532     GetCrystalPhiEtaIndexInModuleFromTRUIndex(mtrun,
533                                               static_cast<Int_t>(maxn[1]),
534                                               static_cast<Int_t>(maxn[2]),
535                                               fnxnCrystalPhi,fnxnCrystalEta) ; 
536     
537     //Isolated patch?
538     fIsnxnIsol =  IsPatchIsolated(1, amptrus, mtrun, iMod, maxn) ;
539
540     //Transform digit amplitude in Raw Samples
541     fADCValuesHighnxn = new Int_t[nTimeBins];
542     fADCValuesLownxn  = new Int_t[nTimeBins];
543
544     pulse->SetAmplitude(maxtimeRn);
545     pulse->SetTZero(fnxnMaxAmp);
546     pulse->MakeSamples();
547     pulse->GetSamples(fADCValuesHighnxn, fADCValuesLownxn) ;
548     
549     //Set Trigger Inputs, compare ADC time bins until threshold is attained
550     //SetL1 Low
551     for(Int_t i = 0 ; i < nTimeBins ; i++){
552       if(fADCValuesHighnxn[i] >= fL1JetLowPtThreshold  || fADCValuesLownxn[i] >= fL1JetLowPtThreshold){
553         SetInput("PHOS_JetLPt_L1") ;
554         break; 
555       }
556     }
557     //SetL1 High
558     for(Int_t i = 0 ; i < nTimeBins ; i++){
559       if(fADCValuesHighnxn[i] >= fL1JetHighPtThreshold || fADCValuesLownxn[i] >= fL1JetHighPtThreshold){
560         SetInput("PHOS_JetHPt_L1") ;
561         break;
562       }
563     }
564   }
565 }
566
567 //____________________________________________________________________________
568 void AliPHOSTrigger::Trigger() 
569 {
570
571   //Main Method to select triggers.
572   AliRunLoader *rl = gAlice->GetRunLoader();
573   //Getter
574   AliPHOSGetter * gime = AliPHOSGetter::Instance( rl->GetFileName() ) ;
575   //AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
576
577   //Get Geometry
578   const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
579    
580   //Define parameters
581   Int_t nModules     = geom->GetNModules();
582   fNCrystalsPhi = geom->GetNPhi()/fNTRUPhi ;// 64/4=16
583   fNCrystalsZ   = geom->GetNZ()/fNTRUZ ;// 56/2=28
584
585   //Intialize data members each time the trigger is called in event loop
586   f2x2MaxAmp = -1; f2x2CrystalPhi = -1;  f2x2CrystalEta = -1;
587   fnxnMaxAmp = -1; fnxnCrystalPhi = -1;  fnxnCrystalEta = -1;
588
589   //Take the digits list if simulation
590   if(fSimulation)
591     fDigitsList = gime->Digits() ;
592   
593   if(!fDigitsList)
594     AliFatal("Digits not found !") ;
595   
596   //Fill TRU Matrix  
597   TClonesArray * amptrus   = new TClonesArray("TMatrixD",1000);
598   TClonesArray * timeRtrus = new TClonesArray("TMatrixD",1000);
599   FillTRU(fDigitsList,geom,amptrus, timeRtrus) ;
600
601   //Do Crystal Sliding and select Trigger
602   //Initialize varible that will contain maximum amplitudes and 
603   //its corresponding cell position in eta and phi, and time.
604   TMatrixD  * ampmax2 = new TMatrixD(4,fNTRU) ;
605   TMatrixD  * ampmaxn = new TMatrixD(4,fNTRU) ;
606
607   for(Int_t imod = 0 ; imod < nModules ; imod++) {
608
609     //Do 2x2 and nxn sums, select maximums. 
610     MakeSlidingCell(amptrus, timeRtrus, imod, ampmax2, ampmaxn);
611     //Set the trigger
612     SetTriggers(amptrus,imod,ampmax2,ampmaxn) ;
613   }
614
615   //Print();
616
617 }