Dummy return
[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.
21// Digits are grouped in TRU's (384 cells? ordered fNTRUPhi x fNTRUEta).
22// The algorithm searches all possible 4x4 cell combinations per each TRU,
23// adding the digits amplitude and finding the maximum. Maximums are compared
24// to triggers threshold and they are set. Thresholds need to be fixed.
59264fa6 25// Last 2 modules are half size in Phi, I considered that the number of TRU
26// is maintained for the last modules but decision not taken. If different,
27// then this must be changed.
f0377b23 28// Usage:
29//
30// //Inside the event loop
31// AliEMCALTrigger *tr = new AliEMCALTrigger();//Init Trigger
59264fa6 32// tr->SetL0Threshold(100);
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),
64 f4x4MaxAmp(-1), f4x4CellPhi(-1), f4x4CellEta(-1),
65 f4x4SM(0),
66 fADCValuesHigh4x4(0x0),fADCValuesLow4x4(0x0),
67 fADCValuesHigh2x2(0x0),fADCValuesLow2x2(0x0),
68 fDigitsList(0x0),
69 fL0Threshold(100),fL1JetLowPtThreshold(200),
70 fL1JetMediumPtThreshold(500), fL1JetHighPtThreshold(1000),
59264fa6 71 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),
90 f4x4MaxAmp(trig.f4x4MaxAmp),
91 f4x4CellPhi(trig.f4x4CellPhi),
92 f4x4CellEta(trig.f4x4CellEta),
93 f4x4SM(trig.f4x4SM),
94 fADCValuesHigh4x4(trig.fADCValuesHigh4x4),
95 fADCValuesLow4x4(trig.fADCValuesLow4x4),
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),
103 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//____________________________________________________________________________
59264fa6 124void AliEMCALTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClonesArray * timeRtrus, const Int_t isupermod,TMatrixD *ampmax2, TMatrixD *ampmax4, AliEMCALGeometry *geom){
f0377b23 125
59264fa6 126 //Sums energy of all possible 2x2 (L0) and 4x4 (L1) cells per each TRU.
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 ;
140 Float_t amp4 = 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;
144 (*ampmax4)(i,j) = -1;
145 }
146 }
f0377b23 147
59264fa6 148 //Create matrix that will contain 2x2 amplitude sums
149 //used to calculate the 4x4 sums
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
59264fa6 167 //Fill matrix with added 2x2 crystals for use in 4x4 sums
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 }
190
191 //Sliding 4x4, add 4x4 amplitudes (OVERLAP)
192 for(Int_t irow = 0 ; irow < nCellsPhi/2; irow++){
193 for(Int_t icol = 0 ; icol < nCellsEta/2 ; icol++){
194 if( (irow+1) < nCellsPhi/2 && (icol+1) < nCellsEta/2){//Avoid exit the TRU
195 amp4 = (*tru2x2)(irow,icol)+(*tru2x2)(irow+1,icol)+
196 (*tru2x2)(irow,icol+1)+(*tru2x2)(irow+1,icol+1);
197 //Select 4x4 maximum sums to select L1
198 if(amp4 > (*ampmax4)(0,mtru)){
199 (*ampmax4)(0,mtru) = amp4 ;
200 (*ampmax4)(1,mtru) = irow*2;
201 (*ampmax4)(2,mtru) = icol*2;
202 }
203 }
204 }
205 }
206
207 //Find most recent time in selected 4x4 cell
208 (*ampmax4)(3,mtru) = 1 ;
209 Int_t row4 = static_cast <Int_t> ((*ampmax4)(1,mtru));
210 Int_t col4 = static_cast <Int_t> ((*ampmax4)(2,mtru));
211 for(Int_t i = 0; i<4; i++){
212 for(Int_t j = 0; j<4; j++){
213 if((*amptru)(row4+i,col4+j) > 0 && (*timeRtru)(row4+i,col4+j)> 0){
214 if((*timeRtru)(row4+i,col4+j) < (*ampmax4)(3,mtru) )
215 (*ampmax4)(3,mtru) = (*timeRtru)(row4+i,col4+j);
216 }
217 }
218 }
f0377b23 219 }
f0377b23 220}
221
222//____________________________________________________________________________
223void AliEMCALTrigger::Print(const Option_t * opt) const
224{
225
226 //Prints main parameters
227
228 if(! opt)
229 return;
230 AliTriggerInput* in = 0x0 ;
59264fa6 231
232 printf( " Maximum Amplitude after Sliding Cell, \n") ;
233 printf( " -2x2 cells sum (not overlapped): %10.2f, in Super Module %d\n",
234 f2x2MaxAmp,f2x2SM) ;
235 printf( " -2x2 from row %d to row %d and from column %d to column %d\n", f2x2CellPhi, f2x2CellPhi+2, f2x2CellEta, f2x2CellEta+2) ;
236 printf( " -4x4 cells sum (overlapped) : %10.2f, in Super Module %d\n",
237 f4x4MaxAmp,f4x4SM) ;
238 printf( " -4x4 from row %d to row %d and from column %d to column %d\n", f4x4CellPhi, f4x4CellPhi+4, f4x4CellEta, f4x4CellEta+4) ;
239 printf( " Threshold for LO %10.2f\n",
240 fL0Threshold) ;
241 in = (AliTriggerInput*)fInputs.FindObject( "EMCAL_L0" );
f0377b23 242 if(in->GetValue())
59264fa6 243 printf( " *** EMCAL LO is set ***\n") ;
f0377b23 244
59264fa6 245 printf( " Jet Low Pt Threshold for L1 %10.2f\n",
246 fL1JetLowPtThreshold) ;
247 in = (AliTriggerInput*)fInputs.FindObject( "EMCAL_JetLPt_L1" );
f0377b23 248 if(in->GetValue())
59264fa6 249 printf( " *** EMCAL Jet Low Pt for L1 is set ***\n") ;
f0377b23 250
59264fa6 251 printf( " Jet Medium Pt Threshold for L1 %10.2f\n",
252 fL1JetMediumPtThreshold) ;
253 in = (AliTriggerInput*) fInputs.FindObject( "EMCAL_JetMPt_L1" );
f0377b23 254 if(in->GetValue())
59264fa6 255 printf( " *** EMCAL Jet Medium Pt for L1 is set ***\n") ;
f0377b23 256
59264fa6 257 printf( " Jet High Pt Threshold for L1 %10.2f\n",
258 fL1JetHighPtThreshold) ;
259 in = (AliTriggerInput*) fInputs.FindObject( "EMCAL_JetHPt_L1" );
f0377b23 260 if(in->GetValue())
59264fa6 261 printf( " *** EMCAL Jet High Pt for L1 is set ***\n") ;
f0377b23 262
263}
264
265//____________________________________________________________________________
59264fa6 266void AliEMCALTrigger::SetTriggers(const Int_t iSM, const TMatrixD *ampmax2,
267 const TMatrixD *ampmax4, AliEMCALGeometry *geom)
f0377b23 268{
269
59264fa6 270 //Checks the 2x2 and 4x4 maximum amplitude per each TRU and
271 //compares with the different L0 and L1 triggers thresholds
272 Float_t max2[] = {-1,-1,-1,-1} ;
273 Float_t max4[] = {-1,-1,-1,-1} ;
274 Int_t itru2 = -1 ;
275 Int_t itru4 = -1 ;
f0377b23 276
59264fa6 277 //Find maximum summed amplitude of all the TRU
278 //in a Super Module
279 for(Int_t i = 0 ; i < geom->GetNTRU() ; i++){
280 if(max2[0] < (*ampmax2)(0,i) ){
281 max2[0] = (*ampmax2)(0,i) ; // 2x2 summed max amplitude
282 max2[1] = (*ampmax2)(1,i) ; // corresponding phi position in TRU
283 max2[2] = (*ampmax2)(2,i) ; // corresponding eta position in TRU
284 max2[3] = (*ampmax2)(3,i) ; // corresponding most recent time
285 itru2 = i ;
286 }
03ecfe88 287 if(max4[0] < (*ampmax4)(0,i) ){
59264fa6 288 max4[0] = (*ampmax4)(0,i) ; // 4x4 summed max amplitude
289 max4[1] = (*ampmax4)(1,i) ; // corresponding phi position in TRU
290 max4[2] = (*ampmax4)(2,i) ; // corresponding eta position in TRU
291 max4[3] = (*ampmax4)(3,i) ; // corresponding most recent time
292 itru4 = i ;
293 }
294 }
295
296 //--------Set max amplitude if larger than in other Super Modules------------
297 Float_t maxtimeR2 = -1 ;
298 Float_t maxtimeR4 = -1 ;
299 AliRunLoader *rl = AliRunLoader::GetRunLoader();
300 AliRun * gAlice = rl->GetAliRun();
301 AliEMCAL * emcal = (AliEMCAL*)gAlice->GetDetector("EMCAL");
302 Int_t nTimeBins = emcal->GetRawFormatTimeBins() ;
303
304 //Set max of 2x2 amplitudes and select L0 trigger
305 if(max2[0] > f2x2MaxAmp ){
306 f2x2MaxAmp = max2[0] ;
307 f2x2SM = iSM ;
308 maxtimeR2 = max2[3] ;
309 geom->GetCellPhiEtaIndexInSModuleFromTRUIndex(itru2,
310 static_cast<Int_t>(max2[1]),
311 static_cast<Int_t>(max2[2]),
312 f2x2CellPhi,f2x2CellEta) ;
313
314 //Transform digit amplitude in Raw Samples
315 fADCValuesLow2x2 = new Int_t[nTimeBins];
316 fADCValuesHigh2x2 = new Int_t[nTimeBins];
317 emcal->RawSampledResponse(maxtimeR2, f2x2MaxAmp, fADCValuesHigh2x2, fADCValuesLow2x2) ;
318
319 //Set Trigger Inputs, compare ADC time bins until threshold is attained
320 //Set L0
321 for(Int_t i = 0 ; i < nTimeBins ; i++){
322 if(fADCValuesHigh2x2[i] >= fL0Threshold || fADCValuesLow2x2[i] >= fL0Threshold){
323 SetInput("EMCAL_L0") ;
324 break;
325 }
326 }
f0377b23 327 }
59264fa6 328
329 //------------Set max of 4x4 amplitudes and select L1 trigger---------
330 if(max4[0] > f4x4MaxAmp ){
331 f4x4MaxAmp = max4[0] ;
332 f4x4SM = iSM ;
333 maxtimeR4 = max4[3] ;
334 geom->GetCellPhiEtaIndexInSModuleFromTRUIndex(itru4,
335 static_cast<Int_t>(max4[1]),
336 static_cast<Int_t>(max4[2]),
337 f4x4CellPhi,f4x4CellEta) ;
338 //Transform digit amplitude in Raw Samples
339 fADCValuesHigh4x4 = new Int_t[nTimeBins];
340 fADCValuesLow4x4 = new Int_t[nTimeBins];
341 emcal->RawSampledResponse(maxtimeR4, f4x4MaxAmp, fADCValuesHigh4x4, fADCValuesLow4x4) ;
342
343 //Set Trigger Inputs, compare ADC time bins until threshold is attained
344 //SetL1 Low
345 for(Int_t i = 0 ; i < nTimeBins ; i++){
346 if(fADCValuesHigh4x4[i] >= fL1JetLowPtThreshold || fADCValuesLow4x4[i] >= fL1JetLowPtThreshold){
347 SetInput("EMCAL_JetLPt_L1") ;
348 break;
349 }
350 }
351
352 //SetL1 Medium
353 for(Int_t i = 0 ; i < nTimeBins ; i++){
354 if(fADCValuesHigh4x4[i] >= fL1JetMediumPtThreshold || fADCValuesLow4x4[i] >= fL1JetMediumPtThreshold){
355 SetInput("EMCAL_JetMPt_L1") ;
356 break;
357 }
358 }
359
360 //SetL1 High
361 for(Int_t i = 0 ; i < nTimeBins ; i++){
362 if(fADCValuesHigh4x4[i] >= fL1JetHighPtThreshold || fADCValuesLow4x4[i] >= fL1JetHighPtThreshold){
363 SetInput("EMCAL_JetHPt_L1") ;
364 break;
365 }
366 }
59264fa6 367 }
368}
f0377b23 369
59264fa6 370//____________________________________________________________________________
371void AliEMCALTrigger::Trigger()
372{
373 //Main Method to select triggers.
374 AliRunLoader *rl = AliRunLoader::GetRunLoader();
375 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>
376 (rl->GetDetectorLoader("EMCAL"));
377
378 //Load EMCAL Geometry
379 rl->LoadgAlice();
380 AliRun * gAlice = rl->GetAliRun();
381 AliEMCAL * emcal = (AliEMCAL*)gAlice->GetDetector("EMCAL");
382 AliEMCALGeometry * geom = emcal->GetGeometry();
383
384 if (geom==0)
385 AliFatal("Did not get geometry from EMCALLoader");
386
387
388 //Define parameters
389 Int_t nSuperModules = geom->GetNumberOfSuperModules() ; //12 SM in EMCAL
390 Int_t nTRU = geom->GetNTRU();//3 TRU per super module
391
392 //Intialize data members each time the trigger is called in event loop
393 f2x2MaxAmp = -1; f2x2CellPhi = -1; f2x2CellEta = -1;
394 f4x4MaxAmp = -1; f4x4CellPhi = -1; f4x4CellEta = -1;
395
396 //Take the digits list if simulation
397 if(fSimulation){
398 rl->LoadDigits("EMCAL");
399 fDigitsList = emcalLoader->Digits() ;
400 }
59264fa6 401 if(!fDigitsList)
402 AliFatal("Digits not found !") ;
403
404 //Take the digits list
405
406 //Fill TRU Matrix
407 TClonesArray * amptrus = new TClonesArray("TMatrixD",1000);
408 TClonesArray * timeRtrus = new TClonesArray("TMatrixD",1000);
33d0b833 409
59264fa6 410 geom->FillTRU(fDigitsList, amptrus, timeRtrus) ;
411
412 //Do Cell Sliding and select Trigger
413 //Initialize varible that will contain maximum amplitudes and
414 //its corresponding cell position in eta and phi, and time.
415 TMatrixD * ampmax2 = new TMatrixD(4,nTRU) ;
416 TMatrixD * ampmax4 = new TMatrixD(4,nTRU) ;
417
33d0b833 418 for(Int_t iSM = 0 ; iSM < nSuperModules ; iSM++) {
59264fa6 419 //Do 2x2 and 4x4 sums, select maximums.
420 MakeSlidingCell(amptrus, timeRtrus, iSM, ampmax2, ampmax4, geom);
33d0b833 421
59264fa6 422 //Set the trigger
423 SetTriggers(iSM, ampmax2, ampmax4, geom) ;
424 }
f0377b23 425}