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