]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALTrigger.cxx
Added paths, uncommented MUONStatusMap.C (now compiles)
[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$ */
f0377b23 16
17//_________________________________________________________________________
18//
19// Class for trigger analysis.
0964c2e9 20// Digits are grouped in TRU's (Trigger Units). A TRU consists of 384
21// cells ordered fNTRUPhi x fNTRUEta. The algorithm searches all possible 2x2
22// and nxn (n is a multiple of 2) cell combinations per each TRU, adding the
23// digits amplitude and finding the maximum. If found, look if it 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.
0b2ec9f7 26// Thresholds need to be fixed. Last 2 modules are half size in Phi, I considered
27// that the number of TRU is maintained for the last modules but decision not taken.
28// If different, then this must be changed.
f0377b23 29// Usage:
30//
31// //Inside the event loop
32// AliEMCALTrigger *tr = new AliEMCALTrigger();//Init Trigger
0b2ec9f7 33// tr->SetL0Threshold(100); //Arbitrary threshold values
f0377b23 34// tr->SetL1JetLowPtThreshold(1000);
35// tr->SetL1JetMediumPtThreshold(10000);
36// tr->SetL1JetHighPtThreshold(20000);
0964c2e9 37// ...
f0377b23 38// tr->Trigger(); //Execute Trigger
39// tr->Print(""); //Print results
40//
41//*-- Author: Gustavo Conesa & Yves Schutz (IFIC, CERN)
42//////////////////////////////////////////////////////////////////////////////
43
44
45// --- ROOT system ---
f0377b23 46
47// --- ALIROOT system ---
f0377b23 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"
133abe1f 56#include "AliEMCALRawUtils.h"
f0377b23 57
58ClassImp(AliEMCALTrigger)
59
60//______________________________________________________________________
61AliEMCALTrigger::AliEMCALTrigger()
62 : AliTriggerDetector(),
59264fa6 63 f2x2MaxAmp(-1), f2x2CellPhi(-1), f2x2CellEta(-1),
18a21c7c 64 f2x2SM(0),
0b2ec9f7 65 fnxnMaxAmp(-1), fnxnCellPhi(-1), fnxnCellEta(-1),
66 fnxnSM(0),
0964c2e9 67 fADCValuesHighnxn(0),fADCValuesLownxn(0),
68 fADCValuesHigh2x2(0),fADCValuesLow2x2(0),
69 fDigitsList(0),
18a21c7c 70 fL0Threshold(100),fL1JetLowPtThreshold(200),
71 fL1JetMediumPtThreshold(500), fL1JetHighPtThreshold(1000),
0964c2e9 72 fNTRU(3), fNTRUEta(3), fNTRUPhi(1),
73 fNCellsPhi(24), fNCellsEta(16),
74 fPatchSize(1), fIsolPatchSize(1),
75 f2x2AmpOutOfPatch(-1), fnxnAmpOutOfPatch(-1),
76 f2x2AmpOutOfPatchThres(100000), fnxnAmpOutOfPatchThres(100000),
77 fIs2x2Isol(kFALSE), fIsnxnIsol(kFALSE),
78 fSimulation(kTRUE), fIsolateInSuperModule(kTRUE)
f0377b23 79{
59264fa6 80 //ctor
0964c2e9 81 fADCValuesHighnxn = 0x0; //new Int_t[fTimeBins];
82 fADCValuesLownxn = 0x0; //new Int_t[fTimeBins];
83 fADCValuesHigh2x2 = 0x0; //new Int_t[fTimeBins];
84 fADCValuesLow2x2 = 0x0; //new Int_t[fTimeBins];
59264fa6 85
59264fa6 86 SetName("EMCAL");
87 CreateInputs();
f0377b23 88
59264fa6 89 //Print("") ;
f0377b23 90}
91
92
93
94//____________________________________________________________________________
95AliEMCALTrigger::AliEMCALTrigger(const AliEMCALTrigger & trig)
18a21c7c 96 : AliTriggerDetector(trig),
97 f2x2MaxAmp(trig.f2x2MaxAmp),
98 f2x2CellPhi(trig.f2x2CellPhi),
99 f2x2CellEta(trig.f2x2CellEta),
100 f2x2SM(trig.f2x2SM),
0b2ec9f7 101 fnxnMaxAmp(trig.fnxnMaxAmp),
102 fnxnCellPhi(trig.fnxnCellPhi),
103 fnxnCellEta(trig.fnxnCellEta),
104 fnxnSM(trig.fnxnSM),
105 fADCValuesHighnxn(trig.fADCValuesHighnxn),
106 fADCValuesLownxn(trig.fADCValuesLownxn),
18a21c7c 107 fADCValuesHigh2x2(trig.fADCValuesHigh2x2),
108 fADCValuesLow2x2(trig.fADCValuesLow2x2),
109 fDigitsList(trig.fDigitsList),
110 fL0Threshold(trig.fL0Threshold),
111 fL1JetLowPtThreshold(trig.fL1JetLowPtThreshold),
112 fL1JetMediumPtThreshold(trig.fL1JetMediumPtThreshold),
113 fL1JetHighPtThreshold(trig.fL1JetHighPtThreshold),
0964c2e9 114 fNTRU(trig.fNTRU), fNTRUEta(trig.fNTRUEta), fNTRUPhi(trig.fNTRUPhi),
115 fNCellsPhi(trig.fNCellsPhi), fNCellsEta(trig.fNCellsEta),
116 fPatchSize(trig.fPatchSize),
117 fIsolPatchSize(trig.fIsolPatchSize),
118 f2x2AmpOutOfPatch(trig.f2x2AmpOutOfPatch),
119 fnxnAmpOutOfPatch(trig.fnxnAmpOutOfPatch),
120 f2x2AmpOutOfPatchThres(trig.f2x2AmpOutOfPatchThres),
121 fnxnAmpOutOfPatchThres(trig.fnxnAmpOutOfPatchThres),
122 fIs2x2Isol(trig.fIs2x2Isol),
123 fIsnxnIsol(trig.fIsnxnIsol),
124 fSimulation(trig.fSimulation),
125 fIsolateInSuperModule(trig.fIsolateInSuperModule)
f0377b23 126{
f0377b23 127 // cpy ctor
f0377b23 128}
129
c35bbfd4 130AliEMCALTrigger::~AliEMCALTrigger() {
131 delete [] fADCValuesHighnxn;
132 delete [] fADCValuesLownxn;
133 delete [] fADCValuesHigh2x2;
134 delete [] fADCValuesLow2x2;
135}
136
f0377b23 137//----------------------------------------------------------------------
138void AliEMCALTrigger::CreateInputs()
139{
140 // inputs
141
142 // Do not create inputs again!!
143 if( fInputs.GetEntriesFast() > 0 ) return;
144
59264fa6 145 fInputs.AddLast( new AliTriggerInput( "EMCAL_L0", "EMCAL L0", 0x02 ) );
146 fInputs.AddLast( new AliTriggerInput( "EMCAL_JetHPt_L1","EMCAL Jet High Pt L1", 0x04 ) );
147 fInputs.AddLast( new AliTriggerInput( "EMCAL_JetMPt_L1","EMCAL Jet Medium Pt L1", 0x08 ) );
148 fInputs.AddLast( new AliTriggerInput( "EMCAL_JetLPt_L1","EMCAL Jet Low Pt L1", 0x016 ) );
f0377b23 149
150}
151
152//____________________________________________________________________________
0964c2e9 153Bool_t AliEMCALTrigger::IsPatchIsolated(Int_t iPatchType, const TClonesArray * ampmatrixes, const Int_t iSM, const Int_t mtru, const Float_t maxamp, const Int_t maxphi, const Int_t maxeta) {
154
155 //Calculate if the maximum patch found is isolated, find amplitude around maximum (2x2 or nxn) patch,
156 //inside isolation patch . iPatchType = 0 means calculation for 2x2 patch,
157 //iPatchType = 1 means calculation for nxn patch.
158 //In the next table there is an example of the different options of patch size and isolation patch size:
159 // Patch Size (fPatchSize)
160 // 0 1 2
161 // fIsolPatchSize 2x2 (not overlap) 4x4 (overlapped) 6x6(overlapped) ...
162 // 1 4x4 8x8 10x10
163 // 2 6x6 12x12 14x14
164 // 3 8x8 16x16 18x18
165
166 Bool_t b = kFALSE;
167 Float_t amp = 0;
168
169 //Get matrix of TRU or Module with maximum amplitude patch.
170 Int_t itru = mtru+iSM*fNTRU ; //number of tru, min 0 max 8*5.
171 TMatrixD * ampmatrix = 0x0;
172 Int_t colborder = 0;
173 Int_t rowborder = 0;
174
175 if(fIsolateInSuperModule){
176 ampmatrix = dynamic_cast<TMatrixD *>(ampmatrixes->At(iSM)) ;
177 rowborder = fNCellsPhi*fNTRUPhi;
178 colborder = fNCellsEta*fNTRUEta;
179 AliDebug(2,"Isolate trigger in Module");
180 }
181 else{
182 ampmatrix = dynamic_cast<TMatrixD *>(ampmatrixes->At(itru)) ;
183 rowborder = fNCellsPhi;
184 colborder = fNCellsEta;
185 AliDebug(2,"Isolate trigger in TRU");
186 }
187
188 //Define patch cells
189 Int_t isolcells = fIsolPatchSize*(1+iPatchType);
190 Int_t ipatchcells = 2*(1+fPatchSize*iPatchType);
191 Int_t minrow = maxphi - isolcells;
192 Int_t mincol = maxeta - isolcells;
193 Int_t maxrow = maxphi + isolcells + ipatchcells;
194 Int_t maxcol = maxeta + isolcells + ipatchcells;
195
196 AliDebug(2,Form("Number of added Isol Cells %d, Patch Size %d",isolcells, ipatchcells));
197 AliDebug(2,Form("Patch: minrow %d, maxrow %d, mincol %d, maxcol %d",minrow,maxrow,mincol,maxcol));
198
199 if(minrow < 0 || mincol < 0 || maxrow > rowborder || maxcol > colborder){
200 AliDebug(1,Form("Out of Module/TRU range, cannot isolate patch"));
201 return kFALSE;
202 }
203
204 //Add amplitudes in all isolation patch
205 for(Int_t irow = minrow ; irow < maxrow; irow ++)
206 for(Int_t icol = mincol ; icol < maxcol ; icol ++)
207 amp += (*ampmatrix)(irow,icol);
208
209 AliDebug(2,Form("Type %d, Maximum amplitude %f, patch+isol square %f",iPatchType, maxamp, amp));
210
211 if(amp < maxamp){
212 AliError(Form("Bad sum: Type %d, Maximum amplitude %f, patch+isol square %f",iPatchType, maxamp, amp));
213 return kFALSE;
214 }
215 else
216 amp-=maxamp; //Calculate energy in isolation patch that do not comes from maximum patch.
217
218 AliDebug(2, Form("Maximum amplitude %f, Out of patch %f",maxamp, amp));
219
220 //Fill isolation amplitude data member and say if patch is isolated.
221 if(iPatchType == 0){ //2x2 case
222 f2x2AmpOutOfPatch = amp;
223 if(amp < f2x2AmpOutOfPatchThres)
224 b=kTRUE;
225 }
226 else if(iPatchType == 1){ //nxn case
227 fnxnAmpOutOfPatch = amp;
228 if(amp < fnxnAmpOutOfPatchThres)
229 b=kTRUE;
230 }
231
232 return b;
233
234}
235
236//____________________________________________________________________________
c35bbfd4 237void AliEMCALTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClonesArray * timeRtrus, const Int_t isupermod,TMatrixD &ampmax2, TMatrixD &ampmaxn){
f0377b23 238
0b2ec9f7 239 //Sums energy of all possible 2x2 (L0) and nxn (L1) cells per each TRU.
59264fa6 240 //Fast signal in the experiment is given by 2x2 cells,
241 //for this reason we loop inside the TRU cells by 2.
33d0b833 242
59264fa6 243 //Declare and initialize variables
0964c2e9 244 Int_t nCellsPhi = fNCellsPhi;//geom->GetNPhi()*2/geom->GetNTRUPhi() ;
33d0b833 245 if(isupermod > 9)
59264fa6 246 nCellsPhi = nCellsPhi / 2 ; //Half size SM. Not Final.
f0377b23 247 // 12(tow)*2(cell)/1 TRU, cells in Phi in one TRU
0964c2e9 248 Int_t nCellsEta = fNCellsEta ;//geom->GetNEta()*2/geom->GetNTRUEta() ;
f0377b23 249 // 24(mod)*2(tower)/3 TRU, cells in Eta in one TRU
0964c2e9 250 //Int_t nTRU = geom->GeNTRU();//3 TRU per super module
f0377b23 251
59264fa6 252 Float_t amp2 = 0 ;
0b2ec9f7 253 Float_t ampn = 0 ;
33d0b833 254 for(Int_t i = 0; i < 4; i++){
0964c2e9 255 for(Int_t j = 0; j < fNTRU; j++){
c35bbfd4 256 ampmax2(i,j) = -1;
257 ampmaxn(i,j) = -1;
59264fa6 258 }
259 }
f0377b23 260
59264fa6 261 //Create matrix that will contain 2x2 amplitude sums
0b2ec9f7 262 //used to calculate the nxn sums
c35bbfd4 263 TMatrixD tru2x2(nCellsPhi/2,nCellsEta/2) ;
59264fa6 264 for(Int_t i = 0; i < nCellsPhi/2; i++)
265 for(Int_t j = 0; j < nCellsEta/2; j++)
c35bbfd4 266 tru2x2(i,j) = -1;
59264fa6 267
268 //Loop over all TRUS in a supermodule
0964c2e9 269 for(Int_t itru = 0 + isupermod * fNTRU ; itru < (isupermod+1)*fNTRU ; itru++) {
59264fa6 270 TMatrixD * amptru = dynamic_cast<TMatrixD *>(amptrus->At(itru)) ;
271 TMatrixD * timeRtru = dynamic_cast<TMatrixD *>(timeRtrus->At(itru)) ;
0964c2e9 272 Int_t mtru = itru-isupermod*fNTRU ; //Number of TRU in Supermodule
33d0b833 273
59264fa6 274 //Sliding 2x2, add 2x2 amplitudes (NOT OVERLAP)
275 for(Int_t irow = 0 ; irow < nCellsPhi; irow += 2){
276 for(Int_t icol = 0 ; icol < nCellsEta ; icol += 2){
277 amp2 = (*amptru)(irow,icol)+(*amptru)(irow+1,icol)+
278 (*amptru)(irow,icol+1)+(*amptru)(irow+1,icol+1);
33d0b833 279
0964c2e9 280 //Fill matrix with added 2x2 cells for use in nxn sums
c35bbfd4 281 tru2x2(irow/2,icol/2) = amp2 ;
59264fa6 282 //Select 2x2 maximum sums to select L0
c35bbfd4 283 if(amp2 > ampmax2(0,mtru)){
284 ampmax2(0,mtru) = amp2 ;
285 ampmax2(1,mtru) = irow;
286 ampmax2(2,mtru) = icol;
59264fa6 287 }
288 }
289 }
290
291 //Find most recent time in the selected 2x2 cell
c35bbfd4 292 ampmax2(3,mtru) = 1 ;
293 Int_t row2 = static_cast <Int_t> (ampmax2(1,mtru));
294 Int_t col2 = static_cast <Int_t> (ampmax2(2,mtru));
59264fa6 295 for(Int_t i = 0; i<2; i++){
296 for(Int_t j = 0; j<2; j++){
297 if((*amptru)(row2+i,col2+j) > 0 && (*timeRtru)(row2+i,col2+j)> 0){
c35bbfd4 298 if((*timeRtru)(row2+i,col2+j) < ampmax2(3,mtru) )
299 ampmax2(3,mtru) = (*timeRtru)(row2+i,col2+j);
59264fa6 300 }
301 }
302 }
0b2ec9f7 303
304 //Sliding nxn, add nxn amplitudes (OVERLAP)
305 if(fPatchSize > 0){
306 for(Int_t irow = 0 ; irow < nCellsPhi/2; irow++){
307 for(Int_t icol = 0 ; icol < nCellsEta/2 ; icol++){
308 ampn = 0;
309 if( (irow+fPatchSize) < nCellsPhi/2 && (icol+fPatchSize) < nCellsEta/2){//Avoid exit the TRU
310 for(Int_t i = 0 ; i <= fPatchSize ; i++)
311 for(Int_t j = 0 ; j <= fPatchSize ; j++)
c35bbfd4 312 ampn += tru2x2(irow+i,icol+j);
0b2ec9f7 313 //Select nxn maximum sums to select L1
c35bbfd4 314 if(ampn > ampmaxn(0,mtru)){
315 ampmaxn(0,mtru) = ampn ;
316 ampmaxn(1,mtru) = irow*2;
317 ampmaxn(2,mtru) = icol*2;
0b2ec9f7 318 }
59264fa6 319 }
320 }
321 }
0b2ec9f7 322
323 //Find most recent time in selected nxn cell
c35bbfd4 324 ampmaxn(3,mtru) = 1 ;
325 Int_t rown = static_cast <Int_t> (ampmaxn(1,mtru));
326 Int_t coln = static_cast <Int_t> (ampmaxn(2,mtru));
0b2ec9f7 327 for(Int_t i = 0; i<4*fPatchSize; i++){
328 for(Int_t j = 0; j<4*fPatchSize; j++){
329 if( (rown+i) < nCellsPhi && (coln+j) < nCellsEta/2){//Avoid exit the TRU
330 if((*amptru)(rown+i,coln+j) > 0 && (*timeRtru)(rown+i,coln+j)> 0){
c35bbfd4 331 if((*timeRtru)(rown+i,coln+j) < ampmaxn(3,mtru) )
332 ampmaxn(3,mtru) = (*timeRtru)(rown+i,coln+j);
0b2ec9f7 333 }
334 }
59264fa6 335 }
336 }
337 }
0b2ec9f7 338 else {
c35bbfd4 339 ampmaxn(0,mtru) = ampmax2(0,mtru);
340 ampmaxn(1,mtru) = ampmax2(1,mtru);
341 ampmaxn(2,mtru) = ampmax2(2,mtru);
342 ampmaxn(3,mtru) = ampmax2(3,mtru);
0b2ec9f7 343 }
f0377b23 344 }
f0377b23 345}
346
347//____________________________________________________________________________
348void AliEMCALTrigger::Print(const Option_t * opt) const
349{
350
351 //Prints main parameters
352
353 if(! opt)
354 return;
355 AliTriggerInput* in = 0x0 ;
59264fa6 356
357 printf( " Maximum Amplitude after Sliding Cell, \n") ;
358 printf( " -2x2 cells sum (not overlapped): %10.2f, in Super Module %d\n",
359 f2x2MaxAmp,f2x2SM) ;
0b2ec9f7 360 printf( " -2x2 from row %d to row %d and from column %d to column %d\n", f2x2CellPhi, f2x2CellPhi+2, f2x2CellEta, f2x2CellEta+2) ;
0964c2e9 361 printf( " -2x2 Isolation Patch %d x %d, Amplitude out of 2x2 patch is %f, threshold %f, Isolated? %d \n",
362 2*fIsolPatchSize+2, 2*fIsolPatchSize+2, f2x2AmpOutOfPatch, f2x2AmpOutOfPatchThres,static_cast<Int_t> (fIs2x2Isol)) ;
0b2ec9f7 363 if(fPatchSize > 0){
0964c2e9 364 printf( " Patch Size, n x n: %d x %d cells\n",2*(fPatchSize+1), 2*(fPatchSize+1));
0b2ec9f7 365 printf( " -nxn cells sum (overlapped) : %10.2f, in Super Module %d\n",
366 fnxnMaxAmp,fnxnSM) ;
367 printf( " -nxn from row %d to row %d and from column %d to column %d\n", fnxnCellPhi, fnxnCellPhi+4*fPatchSize, fnxnCellEta, fnxnCellEta+4*fPatchSize) ;
0964c2e9 368 printf( " -nxn Isolation Patch %d x %d, Amplitude out of nxn patch is %f, threshold %f, Isolated? %d \n",
369 4*fIsolPatchSize+2*(fPatchSize+1),4*fIsolPatchSize+2*(fPatchSize+1) , fnxnAmpOutOfPatch, fnxnAmpOutOfPatchThres,static_cast<Int_t> (fIsnxnIsol) ) ;
0b2ec9f7 370 }
0964c2e9 371
372 printf( " Isolate in SuperModule? %d\n",
373 fIsolateInSuperModule) ;
374
59264fa6 375 printf( " Threshold for LO %10.2f\n",
376 fL0Threshold) ;
377 in = (AliTriggerInput*)fInputs.FindObject( "EMCAL_L0" );
f0377b23 378 if(in->GetValue())
59264fa6 379 printf( " *** EMCAL LO is set ***\n") ;
f0377b23 380
59264fa6 381 printf( " Jet Low Pt Threshold for L1 %10.2f\n",
382 fL1JetLowPtThreshold) ;
383 in = (AliTriggerInput*)fInputs.FindObject( "EMCAL_JetLPt_L1" );
f0377b23 384 if(in->GetValue())
59264fa6 385 printf( " *** EMCAL Jet Low Pt for L1 is set ***\n") ;
f0377b23 386
59264fa6 387 printf( " Jet Medium Pt Threshold for L1 %10.2f\n",
388 fL1JetMediumPtThreshold) ;
389 in = (AliTriggerInput*) fInputs.FindObject( "EMCAL_JetMPt_L1" );
f0377b23 390 if(in->GetValue())
59264fa6 391 printf( " *** EMCAL Jet Medium Pt for L1 is set ***\n") ;
f0377b23 392
59264fa6 393 printf( " Jet High Pt Threshold for L1 %10.2f\n",
394 fL1JetHighPtThreshold) ;
395 in = (AliTriggerInput*) fInputs.FindObject( "EMCAL_JetHPt_L1" );
f0377b23 396 if(in->GetValue())
59264fa6 397 printf( " *** EMCAL Jet High Pt for L1 is set ***\n") ;
f0377b23 398
399}
400
401//____________________________________________________________________________
0964c2e9 402void AliEMCALTrigger::SetTriggers(const TClonesArray * ampmatrix,const Int_t iSM,
c35bbfd4 403 const TMatrixD &ampmax2,
404 const TMatrixD &ampmaxn, const AliEMCALGeometry *geom)
f0377b23 405{
406
0b2ec9f7 407 //Checks the 2x2 and nxn maximum amplitude per each TRU and
59264fa6 408 //compares with the different L0 and L1 triggers thresholds
409 Float_t max2[] = {-1,-1,-1,-1} ;
0b2ec9f7 410 Float_t maxn[] = {-1,-1,-1,-1} ;
0964c2e9 411 Int_t mtru2 = -1 ;
412 Int_t mtrun = -1 ;
f0377b23 413
59264fa6 414 //Find maximum summed amplitude of all the TRU
415 //in a Super Module
0964c2e9 416 for(Int_t i = 0 ; i < fNTRU ; i++){
c35bbfd4 417 if(max2[0] < ampmax2(0,i) ){
418 max2[0] = ampmax2(0,i) ; // 2x2 summed max amplitude
419 max2[1] = ampmax2(1,i) ; // corresponding phi position in TRU
420 max2[2] = ampmax2(2,i) ; // corresponding eta position in TRU
421 max2[3] = ampmax2(3,i) ; // corresponding most recent time
0964c2e9 422 mtru2 = i ;
59264fa6 423 }
c35bbfd4 424 if(maxn[0] < ampmaxn(0,i) ){
425 maxn[0] = ampmaxn(0,i) ; // nxn summed max amplitude
426 maxn[1] = ampmaxn(1,i) ; // corresponding phi position in TRU
427 maxn[2] = ampmaxn(2,i) ; // corresponding eta position in TRU
428 maxn[3] = ampmaxn(3,i) ; // corresponding most recent time
0964c2e9 429 mtrun = i ;
59264fa6 430 }
431 }
432
433 //--------Set max amplitude if larger than in other Super Modules------------
434 Float_t maxtimeR2 = -1 ;
0b2ec9f7 435 Float_t maxtimeRn = -1 ;
133abe1f 436 static AliEMCALRawUtils rawUtil;
437 Int_t nTimeBins = rawUtil.GetRawFormatTimeBins() ;
59264fa6 438
439 //Set max of 2x2 amplitudes and select L0 trigger
440 if(max2[0] > f2x2MaxAmp ){
441 f2x2MaxAmp = max2[0] ;
442 f2x2SM = iSM ;
443 maxtimeR2 = max2[3] ;
0964c2e9 444 geom->GetCellPhiEtaIndexInSModuleFromTRUIndex(mtru2,
59264fa6 445 static_cast<Int_t>(max2[1]),
446 static_cast<Int_t>(max2[2]),
447 f2x2CellPhi,f2x2CellEta) ;
448
0964c2e9 449 //Isolated patch?
450 if(fIsolateInSuperModule)
451 fIs2x2Isol = IsPatchIsolated(0, ampmatrix, iSM, mtru2, f2x2MaxAmp, f2x2CellPhi,f2x2CellEta) ;
452 else
453 fIs2x2Isol = IsPatchIsolated(0, ampmatrix, iSM, mtru2, f2x2MaxAmp, static_cast<Int_t>(max2[1]), static_cast<Int_t>(max2[2])) ;
454
59264fa6 455 //Transform digit amplitude in Raw Samples
c35bbfd4 456 if (fADCValuesLow2x2 == 0) {
457 fADCValuesLow2x2 = new Int_t[nTimeBins];
458 fADCValuesHigh2x2 = new Int_t[nTimeBins];
459 }
133abe1f 460 rawUtil.RawSampledResponse(maxtimeR2, f2x2MaxAmp, fADCValuesHigh2x2, fADCValuesLow2x2) ;
59264fa6 461
462 //Set Trigger Inputs, compare ADC time bins until threshold is attained
463 //Set L0
464 for(Int_t i = 0 ; i < nTimeBins ; i++){
465 if(fADCValuesHigh2x2[i] >= fL0Threshold || fADCValuesLow2x2[i] >= fL0Threshold){
466 SetInput("EMCAL_L0") ;
467 break;
468 }
469 }
f0377b23 470 }
59264fa6 471
0b2ec9f7 472 //------------Set max of nxn amplitudes and select L1 trigger---------
473 if(maxn[0] > fnxnMaxAmp ){
474 fnxnMaxAmp = maxn[0] ;
475 fnxnSM = iSM ;
476 maxtimeRn = maxn[3] ;
0964c2e9 477 geom->GetCellPhiEtaIndexInSModuleFromTRUIndex(mtrun,
0b2ec9f7 478 static_cast<Int_t>(maxn[1]),
479 static_cast<Int_t>(maxn[2]),
480 fnxnCellPhi,fnxnCellEta) ;
0964c2e9 481
482 //Isolated patch?
483 if(fIsolateInSuperModule)
484 fIsnxnIsol = IsPatchIsolated(1, ampmatrix, iSM, mtrun, fnxnMaxAmp, fnxnCellPhi, fnxnCellEta) ;
485 else
486 fIsnxnIsol = IsPatchIsolated(1, ampmatrix, iSM, mtrun, fnxnMaxAmp, static_cast<Int_t>(maxn[1]), static_cast<Int_t>(maxn[2])) ;
487
59264fa6 488 //Transform digit amplitude in Raw Samples
c35bbfd4 489 if (fADCValuesLownxn == 0) {
490 fADCValuesHighnxn = new Int_t[nTimeBins];
491 fADCValuesLownxn = new Int_t[nTimeBins];
492 }
133abe1f 493 rawUtil.RawSampledResponse(maxtimeRn, fnxnMaxAmp, fADCValuesHighnxn, fADCValuesLownxn) ;
59264fa6 494
495 //Set Trigger Inputs, compare ADC time bins until threshold is attained
496 //SetL1 Low
497 for(Int_t i = 0 ; i < nTimeBins ; i++){
0b2ec9f7 498 if(fADCValuesHighnxn[i] >= fL1JetLowPtThreshold || fADCValuesLownxn[i] >= fL1JetLowPtThreshold){
59264fa6 499 SetInput("EMCAL_JetLPt_L1") ;
500 break;
501 }
502 }
503
504 //SetL1 Medium
505 for(Int_t i = 0 ; i < nTimeBins ; i++){
0b2ec9f7 506 if(fADCValuesHighnxn[i] >= fL1JetMediumPtThreshold || fADCValuesLownxn[i] >= fL1JetMediumPtThreshold){
59264fa6 507 SetInput("EMCAL_JetMPt_L1") ;
508 break;
509 }
510 }
511
512 //SetL1 High
513 for(Int_t i = 0 ; i < nTimeBins ; i++){
0b2ec9f7 514 if(fADCValuesHighnxn[i] >= fL1JetHighPtThreshold || fADCValuesLownxn[i] >= fL1JetHighPtThreshold){
59264fa6 515 SetInput("EMCAL_JetHPt_L1") ;
516 break;
517 }
518 }
59264fa6 519 }
520}
f0377b23 521
c35bbfd4 522//____________________________________________________________________________
523void AliEMCALTrigger::FillTRU(const AliEMCALGeometry *geom, const TClonesArray * digits, TClonesArray * ampmatrix, TClonesArray * ampmatrixsmod, TClonesArray * timeRmatrix) {
524
525// Orders digits ampitudes list in fNTRU TRUs (384 cells) per supermodule.
526// Each TRU is a TMatrixD, and they are kept in TClonesArrays. The number of
527// TRU in phi is fNTRUPhi, and the number of TRU in eta is fNTRUEta.
528// Last 2 modules are half size in Phi, I considered that the number of TRU
529// is maintained for the last modules but decision not taken. If different,
530// then this must be changed. Also fill a matrix with all amplitudes in supermodule for isolation studies.
531
532 //Check data members
533
534 if(fNTRUEta*fNTRUPhi != fNTRU)
535 Error("FillTRU"," Wrong number of TRUS per Eta or Phi");
536
537 //Initilize and declare variables
538 //List of TRU matrices initialized to 0.
539 Int_t nPhi = geom->GetNPhi();
540 Int_t nZ = geom->GetNZ();
541 Int_t nCellsPhi = nPhi*2/fNTRUPhi;
542 Int_t nCellsPhi2 = nPhi/fNTRUPhi; //HalfSize modules
543 Int_t nCellsEta = nZ*2/fNTRUEta;
544
545 Int_t id = -1;
546 Float_t amp = -1;
547 Float_t timeR = -1;
548 Int_t iSupMod = -1;
549 Int_t nModule = -1;
550 Int_t nIphi = -1;
551 Int_t nIeta = -1;
552 Int_t iphi = -1;
553 Int_t ieta = -1;
554
555 //List of TRU matrices initialized to 0.
556 Int_t nSup = geom->GetNumberOfSuperModules();
557 for(Int_t k = 0; k < fNTRU*nSup; k++){
558 TMatrixD amptrus(nCellsPhi,nCellsEta) ;
559 TMatrixD timeRtrus(nCellsPhi,nCellsEta) ;
560 // Do we need to initialise? I think TMatrixD does it by itself...
561 for(Int_t i = 0; i < nCellsPhi; i++){
562 for(Int_t j = 0; j < nCellsEta; j++){
563 amptrus(i,j) = 0.0;
564 timeRtrus(i,j) = 0.0;
565 }
566 }
567 new((*ampmatrix)[k]) TMatrixD(amptrus) ;
568 new((*timeRmatrix)[k]) TMatrixD(timeRtrus) ;
569 }
570
571 //List of Modules matrices initialized to 0.
572 for(Int_t k = 0; k < nSup ; k++){
573 TMatrixD ampsmods( nPhi*2, nZ*2) ;
574 for(Int_t i = 0; i < nPhi*2; i++){
575 for(Int_t j = 0; j < nZ*2; j++){
576 ampsmods(i,j) = 0.0;
577 }
578 }
579 new((*ampmatrixsmod)[k]) TMatrixD(ampsmods) ;
580 }
581
582 AliEMCALDigit * dig ;
583
584 //Digits loop to fill TRU matrices with amplitudes.
585 for(Int_t idig = 0 ; idig < digits->GetEntriesFast() ; idig++){
586
587 dig = dynamic_cast<AliEMCALDigit *>(digits->At(idig)) ;
588 amp = dig->GetAmp() ; // Energy of the digit (arbitrary units)
589 id = dig->GetId() ; // Id label of the cell
590 timeR = dig->GetTimeR() ; // Earliest time of the digit
591
592 //Get eta and phi cell position in supermodule
593 Bool_t bCell = geom->GetCellIndex(id, iSupMod, nModule, nIphi, nIeta) ;
594 if(!bCell)
595 Error("FillTRU","Wrong cell id number") ;
596
597 geom->GetCellPhiEtaIndexInSModule(iSupMod,nModule,nIphi, nIeta,iphi,ieta);
598
599 //Check to which TRU in the supermodule belongs the cell.
600 //Supermodules are divided in a TRU matrix of dimension
601 //(fNTRUPhi,fNTRUEta).
602 //Each TRU is a cell matrix of dimension (nCellsPhi,nCellsEta)
603
604 //First calculate the row and column in the supermodule
605 //of the TRU to which the cell belongs.
606 Int_t col = ieta/nCellsEta;
607 Int_t row = iphi/nCellsPhi;
608 if(iSupMod > 9)
609 row = iphi/nCellsPhi2;
610 //Calculate label number of the TRU
611 Int_t itru = row + col*fNTRUPhi + iSupMod*fNTRU ;
612
613 //Fill TRU matrix with cell values
614 TMatrixD * amptrus = dynamic_cast<TMatrixD *>(ampmatrix->At(itru)) ;
615 TMatrixD * timeRtrus = dynamic_cast<TMatrixD *>(timeRmatrix->At(itru)) ;
616
617 //Calculate row and column of the cell inside the TRU with number itru
618 Int_t irow = iphi - row * nCellsPhi;
619 if(iSupMod > 9)
620 irow = iphi - row * nCellsPhi2;
621 Int_t icol = ieta - col * nCellsEta;
622
623 (*amptrus)(irow,icol) = amp ;
624 (*timeRtrus)(irow,icol) = timeR ;
625
626 //####################SUPERMODULE MATRIX ##################
627 TMatrixD * ampsmods = dynamic_cast<TMatrixD *>(ampmatrixsmod->At(iSupMod)) ;
628 (*ampsmods)(iphi,ieta) = amp ;
629
630 }
631}
59264fa6 632//____________________________________________________________________________
633void AliEMCALTrigger::Trigger()
634{
635 //Main Method to select triggers.
c787fb51 636 AliRunLoader *runLoader = AliRunLoader::GetRunLoader();
59264fa6 637 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>
c787fb51 638 (runLoader->GetDetectorLoader("EMCAL"));
0964c2e9 639
59264fa6 640 //Load EMCAL Geometry
c787fb51 641 AliEMCALGeometry * geom = 0;
642 if (runLoader->GetAliRun() && runLoader->GetAliRun()->GetDetector("EMCAL"))
643 geom = dynamic_cast<AliEMCAL*>(runLoader->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
644 if (geom == 0)
645 geom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaulGeometryName());
0964c2e9 646
59264fa6 647 if (geom==0)
648 AliFatal("Did not get geometry from EMCALLoader");
0964c2e9 649
59264fa6 650 //Define parameters
651 Int_t nSuperModules = geom->GetNumberOfSuperModules() ; //12 SM in EMCAL
0964c2e9 652 fNTRU = geom->GetNTRU(); //3 TRU per super module
653 fNTRUEta = geom->GetNTRUEta(); //3 TRU in eta per super module
654 fNTRUPhi = geom->GetNTRUPhi(); //1 TRU in phi per super module
655 fNCellsPhi = geom->GetNPhi()*2/geom->GetNTRUPhi() ;
656 fNCellsEta = geom->GetNEta()*2/geom->GetNTRUEta() ;
59264fa6 657
658 //Intialize data members each time the trigger is called in event loop
659 f2x2MaxAmp = -1; f2x2CellPhi = -1; f2x2CellEta = -1;
0b2ec9f7 660 fnxnMaxAmp = -1; fnxnCellPhi = -1; fnxnCellEta = -1;
59264fa6 661
662 //Take the digits list if simulation
663 if(fSimulation){
c787fb51 664 runLoader->LoadDigits("EMCAL");
59264fa6 665 fDigitsList = emcalLoader->Digits() ;
666 }
59264fa6 667 if(!fDigitsList)
668 AliFatal("Digits not found !") ;
669
670 //Take the digits list
671
672 //Fill TRU Matrix
673 TClonesArray * amptrus = new TClonesArray("TMatrixD",1000);
0964c2e9 674 TClonesArray * ampsmods = new TClonesArray("TMatrixD",1000);
59264fa6 675 TClonesArray * timeRtrus = new TClonesArray("TMatrixD",1000);
0964c2e9 676
c35bbfd4 677 FillTRU(geom,fDigitsList, amptrus, ampsmods, timeRtrus) ;
59264fa6 678
679 //Do Cell Sliding and select Trigger
680 //Initialize varible that will contain maximum amplitudes and
681 //its corresponding cell position in eta and phi, and time.
c35bbfd4 682 TMatrixD ampmax2(4,fNTRU) ;
683 TMatrixD ampmaxn(4,fNTRU) ;
0964c2e9 684
33d0b833 685 for(Int_t iSM = 0 ; iSM < nSuperModules ; iSM++) {
0b2ec9f7 686 //Do 2x2 and nxn sums, select maximums.
0964c2e9 687 MakeSlidingCell(amptrus, timeRtrus, iSM, ampmax2, ampmaxn);
688
59264fa6 689 //Set the trigger
0964c2e9 690 if(fIsolateInSuperModule)
691 SetTriggers(ampsmods,iSM,ampmax2,ampmaxn,geom) ;
692 if(!fIsolateInSuperModule)
693 SetTriggers(amptrus,iSM,ampmax2,ampmaxn,geom) ;
59264fa6 694 }
0964c2e9 695
c35bbfd4 696 amptrus->Delete();
697 delete amptrus; amptrus = 0;
698 ampsmods->Delete();
699 delete ampsmods; ampsmods = 0;
700 timeRtrus->Delete();
701 delete timeRtrus; timeRtrus = 0;
0964c2e9 702 //Print();
703
f0377b23 704}