Included new data member to change patch size in calorimeters trigger (Gustavo)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTrigger.cxx
CommitLineData
f0377b23 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 $ */
f0377b23 17
18//_________________________________________________________________________
19//
20// Class for trigger analysis.
0b2ec9f7 21// Digits are grouped in TRU's (384 cells ordered fNTRUPhi x fNTRUEta).
22// The algorithm searches all possible 2x2 and nxn (n is a multiple of 4) cell
23// combinations per each TRU, adding the digits amplitude and finding the
24// maximum. Maxima are compared to triggers threshold and they are set.
25// Thresholds need to be fixed. Last 2 modules are half size in Phi, I considered
26// that the number of TRU is maintained for the last modules but decision not taken.
27// If different, then this must be changed.
f0377b23 28// Usage:
29//
30// //Inside the event loop
31// AliEMCALTrigger *tr = new AliEMCALTrigger();//Init Trigger
0b2ec9f7 32// tr->SetL0Threshold(100); //Arbitrary threshold values
f0377b23 33// tr->SetL1JetLowPtThreshold(1000);
34// tr->SetL1JetMediumPtThreshold(10000);
35// tr->SetL1JetHighPtThreshold(20000);
36// tr->Trigger(); //Execute Trigger
37// tr->Print(""); //Print results
38//
39//*-- Author: Gustavo Conesa & Yves Schutz (IFIC, CERN)
40//////////////////////////////////////////////////////////////////////////////
41
42
43// --- ROOT system ---
59264fa6 44//#include "TMatrixD.h"
f0377b23 45
46// --- ALIROOT system ---
47
48#include "AliRun.h"
49#include "AliRunLoader.h"
50#include "AliTriggerInput.h"
51#include "AliEMCAL.h"
52#include "AliEMCALLoader.h"
53#include "AliEMCALDigit.h"
54#include "AliEMCALTrigger.h"
55#include "AliEMCALGeometry.h"
56
57ClassImp(AliEMCALTrigger)
58
59//______________________________________________________________________
60AliEMCALTrigger::AliEMCALTrigger()
61 : AliTriggerDetector(),
59264fa6 62 f2x2MaxAmp(-1), f2x2CellPhi(-1), f2x2CellEta(-1),
18a21c7c 63 f2x2SM(0),
0b2ec9f7 64 fnxnMaxAmp(-1), fnxnCellPhi(-1), fnxnCellEta(-1),
65 fnxnSM(0),
66 fADCValuesHighnxn(0x0),fADCValuesLownxn(0x0),
18a21c7c 67 fADCValuesHigh2x2(0x0),fADCValuesLow2x2(0x0),
68 fDigitsList(0x0),
69 fL0Threshold(100),fL1JetLowPtThreshold(200),
70 fL1JetMediumPtThreshold(500), fL1JetHighPtThreshold(1000),
0b2ec9f7 71 fPatchSize(1), fSimulation(kTRUE)
f0377b23 72{
59264fa6 73 //ctor
74
59264fa6 75 SetName("EMCAL");
76 CreateInputs();
f0377b23 77
59264fa6 78 //Print("") ;
f0377b23 79}
80
81
82
83//____________________________________________________________________________
84AliEMCALTrigger::AliEMCALTrigger(const AliEMCALTrigger & trig)
18a21c7c 85 : AliTriggerDetector(trig),
86 f2x2MaxAmp(trig.f2x2MaxAmp),
87 f2x2CellPhi(trig.f2x2CellPhi),
88 f2x2CellEta(trig.f2x2CellEta),
89 f2x2SM(trig.f2x2SM),
0b2ec9f7 90 fnxnMaxAmp(trig.fnxnMaxAmp),
91 fnxnCellPhi(trig.fnxnCellPhi),
92 fnxnCellEta(trig.fnxnCellEta),
93 fnxnSM(trig.fnxnSM),
94 fADCValuesHighnxn(trig.fADCValuesHighnxn),
95 fADCValuesLownxn(trig.fADCValuesLownxn),
18a21c7c 96 fADCValuesHigh2x2(trig.fADCValuesHigh2x2),
97 fADCValuesLow2x2(trig.fADCValuesLow2x2),
98 fDigitsList(trig.fDigitsList),
99 fL0Threshold(trig.fL0Threshold),
100 fL1JetLowPtThreshold(trig.fL1JetLowPtThreshold),
101 fL1JetMediumPtThreshold(trig.fL1JetMediumPtThreshold),
102 fL1JetHighPtThreshold(trig.fL1JetHighPtThreshold),
0b2ec9f7 103 fPatchSize(trig.fPatchSize), fSimulation(trig.fSimulation)
f0377b23 104{
f0377b23 105 // cpy ctor
f0377b23 106}
107
108//----------------------------------------------------------------------
109void AliEMCALTrigger::CreateInputs()
110{
111 // inputs
112
113 // Do not create inputs again!!
114 if( fInputs.GetEntriesFast() > 0 ) return;
115
59264fa6 116 fInputs.AddLast( new AliTriggerInput( "EMCAL_L0", "EMCAL L0", 0x02 ) );
117 fInputs.AddLast( new AliTriggerInput( "EMCAL_JetHPt_L1","EMCAL Jet High Pt L1", 0x04 ) );
118 fInputs.AddLast( new AliTriggerInput( "EMCAL_JetMPt_L1","EMCAL Jet Medium Pt L1", 0x08 ) );
119 fInputs.AddLast( new AliTriggerInput( "EMCAL_JetLPt_L1","EMCAL Jet Low Pt L1", 0x016 ) );
f0377b23 120
121}
122
123//____________________________________________________________________________
0b2ec9f7 124void AliEMCALTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClonesArray * timeRtrus, const Int_t isupermod,TMatrixD *ampmax2, TMatrixD *ampmaxn, AliEMCALGeometry *geom){
f0377b23 125
0b2ec9f7 126 //Sums energy of all possible 2x2 (L0) and nxn (L1) cells per each TRU.
59264fa6 127 //Fast signal in the experiment is given by 2x2 cells,
128 //for this reason we loop inside the TRU cells by 2.
33d0b833 129
59264fa6 130 //Declare and initialize variables
f0377b23 131 Int_t nCellsPhi = geom->GetNPhi()*2/geom->GetNTRUPhi() ;
33d0b833 132 if(isupermod > 9)
59264fa6 133 nCellsPhi = nCellsPhi / 2 ; //Half size SM. Not Final.
f0377b23 134 // 12(tow)*2(cell)/1 TRU, cells in Phi in one TRU
135 Int_t nCellsEta = geom->GetNEta()*2/geom->GetNTRUEta() ;
136 // 24(mod)*2(tower)/3 TRU, cells in Eta in one TRU
59264fa6 137 Int_t nTRU = geom->GetNTRU();//3 TRU per super module
f0377b23 138
59264fa6 139 Float_t amp2 = 0 ;
0b2ec9f7 140 Float_t ampn = 0 ;
33d0b833 141 for(Int_t i = 0; i < 4; i++){
59264fa6 142 for(Int_t j = 0; j < nTRU; j++){
143 (*ampmax2)(i,j) = -1;
0b2ec9f7 144 (*ampmaxn)(i,j) = -1;
59264fa6 145 }
146 }
f0377b23 147
59264fa6 148 //Create matrix that will contain 2x2 amplitude sums
0b2ec9f7 149 //used to calculate the nxn sums
59264fa6 150 TMatrixD * tru2x2 = new TMatrixD(nCellsPhi/2,nCellsEta/2) ;
151 for(Int_t i = 0; i < nCellsPhi/2; i++)
152 for(Int_t j = 0; j < nCellsEta/2; j++)
153 (*tru2x2)(i,j) = -1;
154
155 //Loop over all TRUS in a supermodule
33d0b833 156 for(Int_t itru = 0 + isupermod * nTRU ; itru < (isupermod+1)*nTRU ; itru++) {
59264fa6 157 TMatrixD * amptru = dynamic_cast<TMatrixD *>(amptrus->At(itru)) ;
158 TMatrixD * timeRtru = dynamic_cast<TMatrixD *>(timeRtrus->At(itru)) ;
33d0b833 159 Int_t mtru = itru-isupermod*nTRU ; //Number of TRU in Supermodule
160
59264fa6 161 //Sliding 2x2, add 2x2 amplitudes (NOT OVERLAP)
162 for(Int_t irow = 0 ; irow < nCellsPhi; irow += 2){
163 for(Int_t icol = 0 ; icol < nCellsEta ; icol += 2){
164 amp2 = (*amptru)(irow,icol)+(*amptru)(irow+1,icol)+
165 (*amptru)(irow,icol+1)+(*amptru)(irow+1,icol+1);
33d0b833 166
0b2ec9f7 167 //Fill matrix with added 2x2 crystals for use in nxn sums
59264fa6 168 (*tru2x2)(irow/2,icol/2) = amp2 ;
169 //Select 2x2 maximum sums to select L0
170 if(amp2 > (*ampmax2)(0,mtru)){
171 (*ampmax2)(0,mtru) = amp2 ;
172 (*ampmax2)(1,mtru) = irow;
173 (*ampmax2)(2,mtru) = icol;
174 }
175 }
176 }
177
178 //Find most recent time in the selected 2x2 cell
179 (*ampmax2)(3,mtru) = 1 ;
180 Int_t row2 = static_cast <Int_t> ((*ampmax2)(1,mtru));
181 Int_t col2 = static_cast <Int_t> ((*ampmax2)(2,mtru));
182 for(Int_t i = 0; i<2; i++){
183 for(Int_t j = 0; j<2; j++){
184 if((*amptru)(row2+i,col2+j) > 0 && (*timeRtru)(row2+i,col2+j)> 0){
185 if((*timeRtru)(row2+i,col2+j) < (*ampmax2)(3,mtru) )
186 (*ampmax2)(3,mtru) = (*timeRtru)(row2+i,col2+j);
187 }
188 }
189 }
0b2ec9f7 190
191 //Sliding nxn, add nxn amplitudes (OVERLAP)
192 if(fPatchSize > 0){
193 for(Int_t irow = 0 ; irow < nCellsPhi/2; irow++){
194 for(Int_t icol = 0 ; icol < nCellsEta/2 ; icol++){
195 ampn = 0;
196 if( (irow+fPatchSize) < nCellsPhi/2 && (icol+fPatchSize) < nCellsEta/2){//Avoid exit the TRU
197 for(Int_t i = 0 ; i <= fPatchSize ; i++)
198 for(Int_t j = 0 ; j <= fPatchSize ; j++)
199 ampn += (*tru2x2)(irow+i,icol+j);
200 //Select nxn maximum sums to select L1
201 if(ampn > (*ampmaxn)(0,mtru)){
202 (*ampmaxn)(0,mtru) = ampn ;
203 (*ampmaxn)(1,mtru) = irow*2;
204 (*ampmaxn)(2,mtru) = icol*2;
205 }
59264fa6 206 }
207 }
208 }
0b2ec9f7 209
210 //Find most recent time in selected nxn cell
211 (*ampmaxn)(3,mtru) = 1 ;
212 Int_t rown = static_cast <Int_t> ((*ampmaxn)(1,mtru));
213 Int_t coln = static_cast <Int_t> ((*ampmaxn)(2,mtru));
214 for(Int_t i = 0; i<4*fPatchSize; i++){
215 for(Int_t j = 0; j<4*fPatchSize; j++){
216 if( (rown+i) < nCellsPhi && (coln+j) < nCellsEta/2){//Avoid exit the TRU
217 if((*amptru)(rown+i,coln+j) > 0 && (*timeRtru)(rown+i,coln+j)> 0){
218 if((*timeRtru)(rown+i,coln+j) < (*ampmaxn)(3,mtru) )
219 (*ampmaxn)(3,mtru) = (*timeRtru)(rown+i,coln+j);
220 }
221 }
59264fa6 222 }
223 }
224 }
0b2ec9f7 225 else {
226 (*ampmaxn)(0,mtru) = (*ampmax2)(0,mtru);
227 (*ampmaxn)(1,mtru) = (*ampmax2)(1,mtru);
228 (*ampmaxn)(2,mtru) = (*ampmax2)(2,mtru);
229 (*ampmaxn)(3,mtru) = (*ampmax2)(3,mtru);
230 }
f0377b23 231 }
f0377b23 232}
233
234//____________________________________________________________________________
235void AliEMCALTrigger::Print(const Option_t * opt) const
236{
237
238 //Prints main parameters
239
240 if(! opt)
241 return;
242 AliTriggerInput* in = 0x0 ;
59264fa6 243
244 printf( " Maximum Amplitude after Sliding Cell, \n") ;
245 printf( " -2x2 cells sum (not overlapped): %10.2f, in Super Module %d\n",
246 f2x2MaxAmp,f2x2SM) ;
0b2ec9f7 247 printf( " -2x2 from row %d to row %d and from column %d to column %d\n", f2x2CellPhi, f2x2CellPhi+2, f2x2CellEta, f2x2CellEta+2) ;
248
249 if(fPatchSize > 0){
250 printf( " Patch Size, n x n: %d x %d cells\n",4*fPatchSize, 4*fPatchSize);
251 printf( " -nxn cells sum (overlapped) : %10.2f, in Super Module %d\n",
252 fnxnMaxAmp,fnxnSM) ;
253 printf( " -nxn from row %d to row %d and from column %d to column %d\n", fnxnCellPhi, fnxnCellPhi+4*fPatchSize, fnxnCellEta, fnxnCellEta+4*fPatchSize) ;
254 }
255
59264fa6 256 printf( " Threshold for LO %10.2f\n",
257 fL0Threshold) ;
258 in = (AliTriggerInput*)fInputs.FindObject( "EMCAL_L0" );
f0377b23 259 if(in->GetValue())
59264fa6 260 printf( " *** EMCAL LO is set ***\n") ;
f0377b23 261
59264fa6 262 printf( " Jet Low Pt Threshold for L1 %10.2f\n",
263 fL1JetLowPtThreshold) ;
264 in = (AliTriggerInput*)fInputs.FindObject( "EMCAL_JetLPt_L1" );
f0377b23 265 if(in->GetValue())
59264fa6 266 printf( " *** EMCAL Jet Low Pt for L1 is set ***\n") ;
f0377b23 267
59264fa6 268 printf( " Jet Medium Pt Threshold for L1 %10.2f\n",
269 fL1JetMediumPtThreshold) ;
270 in = (AliTriggerInput*) fInputs.FindObject( "EMCAL_JetMPt_L1" );
f0377b23 271 if(in->GetValue())
59264fa6 272 printf( " *** EMCAL Jet Medium Pt for L1 is set ***\n") ;
f0377b23 273
59264fa6 274 printf( " Jet High Pt Threshold for L1 %10.2f\n",
275 fL1JetHighPtThreshold) ;
276 in = (AliTriggerInput*) fInputs.FindObject( "EMCAL_JetHPt_L1" );
f0377b23 277 if(in->GetValue())
59264fa6 278 printf( " *** EMCAL Jet High Pt for L1 is set ***\n") ;
f0377b23 279
280}
281
282//____________________________________________________________________________
59264fa6 283void AliEMCALTrigger::SetTriggers(const Int_t iSM, const TMatrixD *ampmax2,
0b2ec9f7 284 const TMatrixD *ampmaxn, AliEMCALGeometry *geom)
f0377b23 285{
286
0b2ec9f7 287 //Checks the 2x2 and nxn maximum amplitude per each TRU and
59264fa6 288 //compares with the different L0 and L1 triggers thresholds
289 Float_t max2[] = {-1,-1,-1,-1} ;
0b2ec9f7 290 Float_t maxn[] = {-1,-1,-1,-1} ;
59264fa6 291 Int_t itru2 = -1 ;
0b2ec9f7 292 Int_t itrun = -1 ;
f0377b23 293
59264fa6 294 //Find maximum summed amplitude of all the TRU
295 //in a Super Module
296 for(Int_t i = 0 ; i < geom->GetNTRU() ; i++){
297 if(max2[0] < (*ampmax2)(0,i) ){
298 max2[0] = (*ampmax2)(0,i) ; // 2x2 summed max amplitude
299 max2[1] = (*ampmax2)(1,i) ; // corresponding phi position in TRU
300 max2[2] = (*ampmax2)(2,i) ; // corresponding eta position in TRU
301 max2[3] = (*ampmax2)(3,i) ; // corresponding most recent time
302 itru2 = i ;
303 }
0b2ec9f7 304 if(maxn[0] < (*ampmaxn)(0,i) ){
305 maxn[0] = (*ampmaxn)(0,i) ; // nxn summed max amplitude
306 maxn[1] = (*ampmaxn)(1,i) ; // corresponding phi position in TRU
307 maxn[2] = (*ampmaxn)(2,i) ; // corresponding eta position in TRU
308 maxn[3] = (*ampmaxn)(3,i) ; // corresponding most recent time
309 itrun = i ;
59264fa6 310 }
311 }
312
313 //--------Set max amplitude if larger than in other Super Modules------------
314 Float_t maxtimeR2 = -1 ;
0b2ec9f7 315 Float_t maxtimeRn = -1 ;
59264fa6 316 AliRunLoader *rl = AliRunLoader::GetRunLoader();
317 AliRun * gAlice = rl->GetAliRun();
318 AliEMCAL * emcal = (AliEMCAL*)gAlice->GetDetector("EMCAL");
319 Int_t nTimeBins = emcal->GetRawFormatTimeBins() ;
320
321 //Set max of 2x2 amplitudes and select L0 trigger
322 if(max2[0] > f2x2MaxAmp ){
323 f2x2MaxAmp = max2[0] ;
324 f2x2SM = iSM ;
325 maxtimeR2 = max2[3] ;
326 geom->GetCellPhiEtaIndexInSModuleFromTRUIndex(itru2,
327 static_cast<Int_t>(max2[1]),
328 static_cast<Int_t>(max2[2]),
329 f2x2CellPhi,f2x2CellEta) ;
330
331 //Transform digit amplitude in Raw Samples
332 fADCValuesLow2x2 = new Int_t[nTimeBins];
333 fADCValuesHigh2x2 = new Int_t[nTimeBins];
334 emcal->RawSampledResponse(maxtimeR2, f2x2MaxAmp, fADCValuesHigh2x2, fADCValuesLow2x2) ;
335
336 //Set Trigger Inputs, compare ADC time bins until threshold is attained
337 //Set L0
338 for(Int_t i = 0 ; i < nTimeBins ; i++){
339 if(fADCValuesHigh2x2[i] >= fL0Threshold || fADCValuesLow2x2[i] >= fL0Threshold){
340 SetInput("EMCAL_L0") ;
341 break;
342 }
343 }
f0377b23 344 }
59264fa6 345
0b2ec9f7 346 //------------Set max of nxn amplitudes and select L1 trigger---------
347 if(maxn[0] > fnxnMaxAmp ){
348 fnxnMaxAmp = maxn[0] ;
349 fnxnSM = iSM ;
350 maxtimeRn = maxn[3] ;
351 geom->GetCellPhiEtaIndexInSModuleFromTRUIndex(itrun,
352 static_cast<Int_t>(maxn[1]),
353 static_cast<Int_t>(maxn[2]),
354 fnxnCellPhi,fnxnCellEta) ;
59264fa6 355 //Transform digit amplitude in Raw Samples
0b2ec9f7 356 fADCValuesHighnxn = new Int_t[nTimeBins];
357 fADCValuesLownxn = new Int_t[nTimeBins];
358 emcal->RawSampledResponse(maxtimeRn, fnxnMaxAmp, fADCValuesHighnxn, fADCValuesLownxn) ;
59264fa6 359
360 //Set Trigger Inputs, compare ADC time bins until threshold is attained
361 //SetL1 Low
362 for(Int_t i = 0 ; i < nTimeBins ; i++){
0b2ec9f7 363 if(fADCValuesHighnxn[i] >= fL1JetLowPtThreshold || fADCValuesLownxn[i] >= fL1JetLowPtThreshold){
59264fa6 364 SetInput("EMCAL_JetLPt_L1") ;
365 break;
366 }
367 }
368
369 //SetL1 Medium
370 for(Int_t i = 0 ; i < nTimeBins ; i++){
0b2ec9f7 371 if(fADCValuesHighnxn[i] >= fL1JetMediumPtThreshold || fADCValuesLownxn[i] >= fL1JetMediumPtThreshold){
59264fa6 372 SetInput("EMCAL_JetMPt_L1") ;
373 break;
374 }
375 }
376
377 //SetL1 High
378 for(Int_t i = 0 ; i < nTimeBins ; i++){
0b2ec9f7 379 if(fADCValuesHighnxn[i] >= fL1JetHighPtThreshold || fADCValuesLownxn[i] >= fL1JetHighPtThreshold){
59264fa6 380 SetInput("EMCAL_JetHPt_L1") ;
381 break;
382 }
383 }
59264fa6 384 }
385}
f0377b23 386
59264fa6 387//____________________________________________________________________________
388void AliEMCALTrigger::Trigger()
389{
390 //Main Method to select triggers.
391 AliRunLoader *rl = AliRunLoader::GetRunLoader();
392 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>
393 (rl->GetDetectorLoader("EMCAL"));
394
395 //Load EMCAL Geometry
396 rl->LoadgAlice();
397 AliRun * gAlice = rl->GetAliRun();
398 AliEMCAL * emcal = (AliEMCAL*)gAlice->GetDetector("EMCAL");
399 AliEMCALGeometry * geom = emcal->GetGeometry();
400
401 if (geom==0)
402 AliFatal("Did not get geometry from EMCALLoader");
403
404
405 //Define parameters
406 Int_t nSuperModules = geom->GetNumberOfSuperModules() ; //12 SM in EMCAL
407 Int_t nTRU = geom->GetNTRU();//3 TRU per super module
408
409 //Intialize data members each time the trigger is called in event loop
410 f2x2MaxAmp = -1; f2x2CellPhi = -1; f2x2CellEta = -1;
0b2ec9f7 411 fnxnMaxAmp = -1; fnxnCellPhi = -1; fnxnCellEta = -1;
59264fa6 412
413 //Take the digits list if simulation
414 if(fSimulation){
415 rl->LoadDigits("EMCAL");
416 fDigitsList = emcalLoader->Digits() ;
417 }
59264fa6 418 if(!fDigitsList)
419 AliFatal("Digits not found !") ;
420
421 //Take the digits list
422
423 //Fill TRU Matrix
424 TClonesArray * amptrus = new TClonesArray("TMatrixD",1000);
425 TClonesArray * timeRtrus = new TClonesArray("TMatrixD",1000);
33d0b833 426
59264fa6 427 geom->FillTRU(fDigitsList, amptrus, timeRtrus) ;
428
429 //Do Cell Sliding and select Trigger
430 //Initialize varible that will contain maximum amplitudes and
431 //its corresponding cell position in eta and phi, and time.
432 TMatrixD * ampmax2 = new TMatrixD(4,nTRU) ;
0b2ec9f7 433 TMatrixD * ampmaxn = new TMatrixD(4,nTRU) ;
59264fa6 434
33d0b833 435 for(Int_t iSM = 0 ; iSM < nSuperModules ; iSM++) {
0b2ec9f7 436 //Do 2x2 and nxn sums, select maximums.
437 MakeSlidingCell(amptrus, timeRtrus, iSM, ampmax2, ampmaxn, geom);
33d0b833 438
59264fa6 439 //Set the trigger
0b2ec9f7 440 SetTriggers(iSM, ampmax2, ampmaxn, geom) ;
59264fa6 441 }
f0377b23 442}