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