Bug fixes
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrigger.cxx
CommitLineData
25354ff4 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$ */
59264fa6 16/* $Log $ */
25354ff4 17
18//_________________________________________________________________________
25354ff4 19// Class for trigger analysis.
59264fa6 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
0b2ec9f7 22// 2x2 and nxn (n multiple of 4) crystal combinations per each TRU, adding the
23// digits amplitude and finding the maximum. Maxima are transformed in ADC
24// time samples. Each time bin is compared to the trigger threshold until it is larger
59264fa6 25// and then, triggers are set. Thresholds need to be fixed.
bb38a8fc 26// Usage:
27//
28// //Inside the event loop
29// AliEMCALTrigger *tr = new AliEMCALTrigger();//Init Trigger
59264fa6 30// tr->SetL0Threshold(100);
bb38a8fc 31// tr->SetL1JetLowPtThreshold(1000);
bb38a8fc 32// tr->SetL1JetHighPtThreshold(20000);
33// tr->Trigger(); //Execute Trigger
34// tr->Print(""); //Print result, with "deb" option all data members
35// //are printed
36//
25354ff4 37//*-- Author: Gustavo Conesa & Yves Schutz (IFIC, CERN)
38//////////////////////////////////////////////////////////////////////////////
39
40
41// --- ROOT system ---
59264fa6 42//#include "TMatrixD.h"
25354ff4 43
44// --- ALIROOT system ---
59264fa6 45#include "AliPHOS.h"
25354ff4 46#include "AliPHOSTrigger.h"
47#include "AliPHOSGeometry.h"
48#include "AliPHOSGetter.h"
b165f59d 49#include "AliTriggerInput.h"
59264fa6 50//#include "AliLog.h"
25354ff4 51
52ClassImp(AliPHOSTrigger)
53
b165f59d 54//______________________________________________________________________
55AliPHOSTrigger::AliPHOSTrigger()
59264fa6 56 : AliTriggerDetector(),
3663622c 57 f2x2MaxAmp(-1), f2x2CrystalPhi(-1), f2x2CrystalEta(-1), f2x2SM(0),
0b2ec9f7 58 fnxnMaxAmp(-1), fnxnCrystalPhi(-1), fnxnCrystalEta(-1), fnxnSM(0),
59 fADCValuesHighnxn(0), fADCValuesLownxn(0),
3663622c 60 fADCValuesHigh2x2(0), fADCValuesLow2x2(0), fDigitsList(0),
59264fa6 61 fL0Threshold(50), fL1JetLowPtThreshold(200), fL1JetHighPtThreshold(500),
0b2ec9f7 62 fNTRU(8), fNTRUZ(2), fNTRUPhi(4), fPatchSize(1), fSimulation(kTRUE)
25354ff4 63{
b165f59d 64 //ctor
0b2ec9f7 65 fADCValuesHighnxn = 0x0; //new Int_t[fTimeBins];
66 fADCValuesLownxn = 0x0; //new Int_t[fTimeBins];
59264fa6 67 fADCValuesHigh2x2 = 0x0; //new Int_t[fTimeBins];
68 fADCValuesLow2x2 = 0x0; //new Int_t[fTimeBins];
69
59264fa6 70 SetName("PHOS");
71 CreateInputs();
72
73 //Print("") ;
25354ff4 74}
75
76//____________________________________________________________________________
3663622c 77AliPHOSTrigger::AliPHOSTrigger(const AliPHOSTrigger & trig) :
78 AliTriggerDetector(trig),
79 f2x2MaxAmp(trig.f2x2MaxAmp),
80 f2x2CrystalPhi(trig.f2x2CrystalPhi),
81 f2x2CrystalEta(trig.f2x2CrystalEta),
82 f2x2SM(trig.f2x2SM),
0b2ec9f7 83 fnxnMaxAmp(trig.fnxnMaxAmp),
84 fnxnCrystalPhi(trig.fnxnCrystalPhi),
85 fnxnCrystalEta(trig.fnxnCrystalEta),
86 fnxnSM(trig.fnxnSM),
87 fADCValuesHighnxn(trig.fADCValuesHighnxn),
88 fADCValuesLownxn(trig.fADCValuesLownxn),
3663622c 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),
0b2ec9f7 98 fPatchSize(trig.fPatchSize), fSimulation(trig.fSimulation)
25354ff4 99{
25354ff4 100 // cpy ctor
25354ff4 101}
102
59264fa6 103//_________________________________________________________________________
3663622c 104AliPHOSTrigger & AliPHOSTrigger::operator = (const AliPHOSTrigger &)
105{
106 Fatal("operator =", "no implemented");
107 return *this;
108}
109
b165f59d 110void AliPHOSTrigger::CreateInputs()
111{
112 // inputs
113
114 // Do not create inputs again!!
115 if( fInputs.GetEntriesFast() > 0 ) return;
116
59264fa6 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 ) );
b165f59d 120
121}
122
25354ff4 123//____________________________________________________________________________
59264fa6 124void AliPHOSTrigger::FillTRU(const TClonesArray * digits, const AliPHOSGeometry * geom, TClonesArray * ampmatrix, TClonesArray * timeRmatrix) const {
25354ff4 125
59264fa6 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.
25354ff4 130
bb38a8fc 131 //Check data members
132
133 if(fNTRUZ*fNTRUPhi != fNTRU)
134 Error("FillTRU"," Wrong number of TRUS per Z or Phi");
25354ff4 135
59264fa6 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;
25354ff4 144
59264fa6 145 //List of TRU matrices initialized to 0.
2ff6837e 146 for(Int_t k = 0; k < fNTRU*nModules ; k++){
59264fa6 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) ;
25354ff4 157 }
158
159 AliPHOSDigit * dig ;
59264fa6 160
bb38a8fc 161 //Digits loop to fill TRU matrices with amplitudes.
162
25354ff4 163 for(Int_t idig = 0 ; idig < digits->GetEntriesFast() ; idig++){
164
59264fa6 165 dig = static_cast<AliPHOSDigit *>(digits->At(idig)) ;
0b2ec9f7 166 amp = dig->GetEnergy() ; // Energy of the digit
59264fa6 167 id = dig->GetId() ; // Id label of the cell
168 timeR = dig->GetTimeR() ; // Earliest time of the digit
169 geom->AbsToRelNumbering(id, relid) ;
bb38a8fc 170 //Transform digit number into 4 numbers
25354ff4 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
bb38a8fc 176 if(relid[1] == 0){//Not CPV, Only EMC digits
177
59264fa6 178 //Check to which TRU in the supermodule belongs the crystal.
bb38a8fc 179 //Supermodules are divided in a TRU matrix of dimension
180 //(fNTRUPhi,fNTRUZ).
59264fa6 181 //Each TRU is a crystal matrix of dimension (nCrystalsPhi,nCrystalsZ)
25354ff4 182
bb38a8fc 183 //First calculate the row and column in the supermodule
59264fa6 184 //of the TRU to which the crystal belongs.
bb38a8fc 185 Int_t col = (relid[3]-1)/nCrystalsZ+1;
59264fa6 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 ;
2ff6837e 190
59264fa6 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)) ;
2ff6837e 194
59264fa6 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 ;
25354ff4 201 }
202 }
25354ff4 203}
204
59264fa6 205//______________________________________________________________________
206void 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}
25354ff4 224//____________________________________________________________________________
0b2ec9f7 225void AliPHOSTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClonesArray * timeRtrus, const Int_t imod, TMatrixD *ampmax2, TMatrixD *ampmaxn, const AliPHOSGeometry *geom){
226 //Sums energy of all possible 2x2 (L0) and nxn (L1) crystals per each TRU.
59264fa6 227 //Fast signal in the experiment is given by 2x2 crystals,
228 //for this reason we loop inside the TRU crystals by 2.
25354ff4 229
59264fa6 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 ;
0b2ec9f7 234 Float_t ampn = 0 ;
235 for(Int_t i = 0; i < 4; i++){
59264fa6 236 for(Int_t j = 0; j < fNTRU; j++){
237 (*ampmax2)(i,j) = -1;
0b2ec9f7 238 (*ampmaxn)(i,j) = -1;
59264fa6 239 }
240 }
25354ff4 241
59264fa6 242 //Create matrix that will contain 2x2 amplitude sums
0b2ec9f7 243 //used to calculate the nxn sums
59264fa6 244 TMatrixD * tru2x2 = new TMatrixD(nCrystalsPhi/2,nCrystalsZ/2) ;
59264fa6 245 for(Int_t i = 0; i < nCrystalsPhi/2; i++)
246 for(Int_t j = 0; j < nCrystalsZ/2; j++)
247 (*tru2x2)(i,j) = 0.0;
248
25354ff4 249 //Loop over all TRUS in a module
59264fa6 250 for(Int_t itru = 0 + (imod - 1) * fNTRU ; itru < imod*fNTRU ; itru++){
251 TMatrixD * amptru = dynamic_cast<TMatrixD *>(amptrus->At(itru)) ;
252 TMatrixD * timeRtru = dynamic_cast<TMatrixD *>(timeRtrus->At(itru)) ;
253 Int_t mtru = itru-(imod-1)*fNTRU ; //Number of TRU in Module
254
255 //Sliding 2x2, add 2x2 amplitudes (NOT OVERLAP)
2ff6837e 256 for(Int_t irow = 0 ; irow < nCrystalsPhi; irow += 2){
257 for(Int_t icol = 0 ; icol < nCrystalsZ ; icol += 2){
59264fa6 258 amp2 = (*amptru)(irow,icol)+(*amptru)(irow+1,icol)+
259 (*amptru)(irow,icol+1)+(*amptru)(irow+1,icol+1);
0b2ec9f7 260
261 //Fill new matrix with added 2x2 crystals for use in nxn sums
59264fa6 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;
25354ff4 268 }
25354ff4 269 }
270 }
2ff6837e 271
59264fa6 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 }
2ff6837e 284
0b2ec9f7 285 //Sliding nxn, add nxn amplitudes (OVERLAP)
286 if(fPatchSize > 0){
287 for(Int_t irow = 0 ; irow < nCrystalsPhi/2; irow++){
288 for(Int_t icol = 0 ; icol < nCrystalsZ/2 ; icol++){
289 ampn = 0;
290 if( (irow+fPatchSize) < nCrystalsPhi/2 && (icol+fPatchSize) < nCrystalsZ/2){//Avoid exit the TRU
291 for(Int_t i = 0 ; i <= fPatchSize ; i++)
292 for(Int_t j = 0 ; j <= fPatchSize ; j++)
293 ampn += (*tru2x2)(irow+i,icol+j);
294 //Select nxn maximum sums to select L1
295 if(ampn > (*ampmaxn)(0,mtru)){
296 (*ampmaxn)(0,mtru) = ampn ;
297 (*ampmaxn)(1,mtru) = irow*2;
298 (*ampmaxn)(2,mtru) = icol*2;
299 }
59264fa6 300 }
301 }
302 }
0b2ec9f7 303
304 //Find most recent time in selected nxn cell
305 (*ampmaxn)(3,mtru) = 1 ;
306 Int_t rown = static_cast <Int_t> ((*ampmaxn)(1,mtru));
307 Int_t coln = static_cast <Int_t> ((*ampmaxn)(2,mtru));
308 for(Int_t i = 0; i<4*fPatchSize; i++){
309 for(Int_t j = 0; j<4*fPatchSize; j++){
310 if( (rown+i) < nCrystalsPhi && (coln+j) < nCrystalsZ/2){//Avoid exit the TRU
311 if((*amptru)(rown+i,coln+j) > 0 && (*timeRtru)(rown+i,coln+j)> 0){
312 if((*timeRtru)(rown+i,coln+j) < (*ampmaxn)(3,mtru) )
313 (*ampmaxn)(3,mtru) = (*timeRtru)(rown+i,coln+j);
314 }
315 }
59264fa6 316 }
317 }
318 }
0b2ec9f7 319 else {
320 (*ampmaxn)(0,mtru) = (*ampmax2)(0,mtru);
321 (*ampmaxn)(1,mtru) = (*ampmax2)(1,mtru);
322 (*ampmaxn)(2,mtru) = (*ampmax2)(2,mtru);
323 (*ampmaxn)(3,mtru) = (*ampmax2)(3,mtru);
324 }
25354ff4 325 }
25354ff4 326}
25354ff4 327//____________________________________________________________________________
328void AliPHOSTrigger::Print(const Option_t * opt) const
329{
330
331 //Prints main parameters
332
333 if(! opt)
334 return;
b165f59d 335 AliTriggerInput* in = 0x0 ;
25354ff4 336
59264fa6 337 printf( " Maximum Amplitude after Sliding Crystal, \n") ;
338 printf( " -2x2 crystals sum (not overlapped): %10.2f, in Super Module %d\n",
339 f2x2MaxAmp,f2x2SM) ;
340 printf( " -2x2 from row %d to row %d and from column %d to column %d\n", f2x2CrystalPhi, f2x2CrystalPhi+2, f2x2CrystalEta, f2x2CrystalEta+2) ;
0b2ec9f7 341
342 if(fPatchSize > 0){
343 printf( " Patch Size, n x n: %d x %d cells\n",4*fPatchSize, 4*fPatchSize);
344 printf( " -nxn crystals sum (overlapped) : %10.2f, in Super Module %d\n",
345 fnxnMaxAmp,fnxnSM) ;
346 printf( " -nxn from row %d to row %d and from column %d to column %d\n", fnxnCrystalPhi, fnxnCrystalPhi+4, fnxnCrystalEta, fnxnCrystalEta+4) ;
347 }
59264fa6 348 printf( " Threshold for LO %10.1f\n",
349 fL0Threshold) ;
350
351 printf( " Threshold for LO %10.2f\n", fL0Threshold) ;
352 in = (AliTriggerInput*)fInputs.FindObject( "PHOS_L0" );
b165f59d 353 if(in->GetValue())
59264fa6 354 printf( " *** PHOS LO is set ***\n") ;
355
356 printf( " Jet Low Pt Threshold for L1 %10.2f\n", fL1JetLowPtThreshold) ;
357 in = (AliTriggerInput*)fInputs.FindObject( "PHOS_JetLPt_L1" );
66f9b73c 358 if(in->GetValue())
59264fa6 359 printf( " *** PHOS Jet Low Pt for L1 is set ***\n") ;
66f9b73c 360
59264fa6 361 printf( " Jet High Pt Threshold for L1 %10.2f\n", fL1JetHighPtThreshold) ;
362 in = (AliTriggerInput*) fInputs.FindObject( "PHOS_JetHPt_L1" );
b165f59d 363 if(in->GetValue())
59264fa6 364 printf( " *** PHOS Jet High Pt for L1 is set ***\n") ;
365
366}
b165f59d 367
59264fa6 368//____________________________________________________________________________
0b2ec9f7 369void AliPHOSTrigger::SetTriggers(const Int_t iMod, const TMatrixD * ampmax2, const TMatrixD * ampmaxn, const AliPHOSGeometry *geom)
59264fa6 370{
0b2ec9f7 371 //Checks the 2x2 and nxn maximum amplitude per each TRU and compares
59264fa6 372 //with the different L0 and L1 triggers thresholds
373
374 //Initialize variables
375 Float_t max2[] = {-1,-1,-1,-1} ;
0b2ec9f7 376 Float_t maxn[] = {-1,-1,-1,-1} ;
59264fa6 377 Int_t itru2 = -1 ;
0b2ec9f7 378 Int_t itrun = -1 ;
59264fa6 379
380
381 //Find maximum summed amplitude of all the TRU
382 //in a Module
383 for(Int_t i = 0 ; i < fNTRU ; i++){
384 if(max2[0] < (*ampmax2)(0,i) ){
385 max2[0] = (*ampmax2)(0,i) ; // 2x2 summed max amplitude
386 max2[1] = (*ampmax2)(1,i) ; // corresponding phi position in TRU
387 max2[2] = (*ampmax2)(2,i) ; // corresponding eta position in TRU
388 max2[3] = (*ampmax2)(3,i) ; // corresponding most recent time
389 itru2 = i ; // TRU number
390 }
0b2ec9f7 391 if(maxn[0] < (*ampmaxn)(0,i) ){
392 maxn[0] = (*ampmaxn)(0,i) ; // nxn summed max amplitude
393 maxn[1] = (*ampmaxn)(1,i) ; // corresponding phi position in TRU
394 maxn[2] = (*ampmaxn)(2,i) ; // corresponding eta position in TRU
395 maxn[3] = (*ampmaxn)(3,i) ; // corresponding most recent time
396 itrun = i ; // TRU number
59264fa6 397 }
398 }
399
400 //Set max amplitude if larger than in other Modules
401 Float_t maxtimeR2 = -1 ;
0b2ec9f7 402 Float_t maxtimeRn = -1 ;
59264fa6 403 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
404 AliPHOS * phos = gime->PHOS();
405 Int_t nTimeBins = phos->GetRawFormatTimeBins() ;
406
407 //Set max 2x2 amplitude and select L0 trigger
408 if(max2[0] > f2x2MaxAmp ){
409 f2x2MaxAmp = max2[0] ;
410 f2x2SM = iMod ;
411 maxtimeR2 = max2[3] ;
412 GetCrystalPhiEtaIndexInModuleFromTRUIndex(itru2,static_cast<Int_t>(max2[1]),static_cast<Int_t>(max2[2]),f2x2CrystalPhi,f2x2CrystalEta,geom) ;
413
414 //Transform digit amplitude in Raw Samples
415 fADCValuesLow2x2 = new Int_t[nTimeBins];
416 fADCValuesHigh2x2 = new Int_t[nTimeBins];
417
418 phos->RawSampledResponse(maxtimeR2, f2x2MaxAmp, fADCValuesHigh2x2, fADCValuesLow2x2) ;
419
420 //Set Trigger Inputs, compare ADC time bins until threshold is attained
421 //Set L0
422 for(Int_t i = 0 ; i < nTimeBins ; i++){
423 if(fADCValuesHigh2x2[i] >= fL0Threshold || fADCValuesLow2x2[i] >= fL0Threshold){
424 SetInput("PHOS_L0") ;
425 break;
426 }
427 }
428// for(Int_t i = 0 ; i < 256 ; i++)
429// if(fADCValuesLow2x2[i]!=0||fADCValuesHigh2x2[i]!=0)
430// cout<< "2x2 Time Bin "<<i
431// <<"; 2x2 Low Gain "<<fADCValuesLow2x2[i]
432// <<"; 2x2 High Gain "<<fADCValuesHigh2x2[i]<<endl;
433 }
434
0b2ec9f7 435 //Set max nxn amplitude and select L1 triggers
436 if(maxn[0] > fnxnMaxAmp ){
437 fnxnMaxAmp = maxn[0] ;
438 fnxnSM = iMod ;
439 maxtimeRn = maxn[3] ;
440 GetCrystalPhiEtaIndexInModuleFromTRUIndex(itrun,static_cast<Int_t>(maxn[1]),static_cast<Int_t>(maxn[2]),fnxnCrystalPhi,fnxnCrystalEta,geom) ;
59264fa6 441
442 //Transform digit amplitude in Raw Samples
0b2ec9f7 443 fADCValuesHighnxn = new Int_t[nTimeBins];
444 fADCValuesLownxn = new Int_t[nTimeBins];
445 phos->RawSampledResponse(maxtimeRn, fnxnMaxAmp, fADCValuesHighnxn, fADCValuesLownxn) ;
59264fa6 446
447 //Set Trigger Inputs, compare ADC time bins until threshold is attained
448 //SetL1 Low
449 for(Int_t i = 0 ; i < nTimeBins ; i++){
0b2ec9f7 450 if(fADCValuesHighnxn[i] >= fL1JetLowPtThreshold || fADCValuesLownxn[i] >= fL1JetLowPtThreshold){
59264fa6 451 SetInput("PHOS_JetLPt_L1") ;
452 break;
453 }
454 }
455 //SetL1 High
456 for(Int_t i = 0 ; i < nTimeBins ; i++){
0b2ec9f7 457 if(fADCValuesHighnxn[i] >= fL1JetHighPtThreshold || fADCValuesLownxn[i] >= fL1JetHighPtThreshold){
59264fa6 458 SetInput("PHOS_JetHPt_L1") ;
459 break;
460 }
461 }
462// for(Int_t i = 0 ; i < 256 ; i++)
0b2ec9f7 463// if(fADCValuesLownxn[i]!=0||fADCValuesHighnxn[i]!=0)
464// cout<< "nxn Time Bin "<<i
465// <<"; nxn Low Gain "<<fADCValuesLownxn[i]
466// <<"; nxn High Gain "<<fADCValuesHighnxn[i]<<endl;
59264fa6 467 }
25354ff4 468}
469
470//____________________________________________________________________________
59264fa6 471void AliPHOSTrigger::Trigger()
25354ff4 472{
473
59264fa6 474 //Main Method to select triggers.
475 AliRunLoader *rl = gAlice->GetRunLoader();
476 //Getter
477 AliPHOSGetter * gime = AliPHOSGetter::Instance( rl->GetFileName() ) ;
478 //AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
25354ff4 479
59264fa6 480 //Get Geometry
481 const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
482
483 //Define parameters
484 Int_t nModules = geom->GetNModules();
485
486 //Intialize data members each time the trigger is called in event loop
487 f2x2MaxAmp = -1; f2x2CrystalPhi = -1; f2x2CrystalEta = -1;
0b2ec9f7 488 fnxnMaxAmp = -1; fnxnCrystalPhi = -1; fnxnCrystalEta = -1;
59264fa6 489
490 //Take the digits list if simulation
491 if(fSimulation)
492 fDigitsList = gime->Digits() ;
493
494 if(!fDigitsList)
495 AliFatal("Digits not found !") ;
66f9b73c 496
59264fa6 497 //Fill TRU Matrix
498 TClonesArray * amptrus = new TClonesArray("TMatrixD",1000);
499 TClonesArray * timeRtrus = new TClonesArray("TMatrixD",1000);
500 FillTRU(fDigitsList,geom,amptrus, timeRtrus) ;
501
502 //Do Crystal Sliding and select Trigger
503 //Initialize varible that will contain maximum amplitudes and
504 //its corresponding cell position in eta and phi, and time.
505 TMatrixD * ampmax2 = new TMatrixD(4,fNTRU) ;
0b2ec9f7 506 TMatrixD * ampmaxn = new TMatrixD(4,fNTRU) ;
59264fa6 507
508 for(Int_t imod = 1 ; imod <= nModules ; imod++) {
0b2ec9f7 509 //Do 2x2 and nxn sums, select maximums.
510 MakeSlidingCell(amptrus, timeRtrus, imod, ampmax2, ampmaxn, geom);
59264fa6 511 //Set the trigger
0b2ec9f7 512 SetTriggers(imod,ampmax2,ampmaxn, geom) ;
59264fa6 513 }
25354ff4 514}