remove exec
[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
85c25c2e 21// modules ordered fNTRUPhi x fNTRUEta. The algorithm searches all possible 2x2
0964c2e9 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
85c25c2e 34// tr->SetL1GammaLowPtThreshold(1000);
35// tr->SetL1GammaMediumPtThreshold(10000);
36// tr->SetL1GammaHighPtThreshold(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
d1f9a8ab 44#include <cassert>
f0377b23 45
46// --- ROOT system ---
85c25c2e 47#include <TTree.h>
48#include <TBranch.h>
49#include <TBrowser.h>
50#include <TH2F.h>
f0377b23 51
52// --- ALIROOT system ---
f0377b23 53#include "AliRun.h"
54#include "AliRunLoader.h"
55#include "AliTriggerInput.h"
56#include "AliEMCAL.h"
57#include "AliEMCALLoader.h"
58#include "AliEMCALDigit.h"
59#include "AliEMCALTrigger.h"
60#include "AliEMCALGeometry.h"
133abe1f 61#include "AliEMCALRawUtils.h"
0293e426 62#include "AliLog.h"
92d9f317 63#include "AliCaloConstants.h"
1f847d9f 64#include "AliEMCALRawResponse.h"
92d9f317 65
66using namespace CALO;
f0377b23 67
68ClassImp(AliEMCALTrigger)
69
85c25c2e 70TString AliEMCALTrigger::fgNameOfJetTriggers("EMCALJetTriggerL1");
71
f0377b23 72//______________________________________________________________________
73AliEMCALTrigger::AliEMCALTrigger()
9946f2fe 74 : AliTriggerDetector(), fGeom(0),
85c25c2e 75 f2x2MaxAmp(-1), f2x2ModulePhi(-1), f2x2ModuleEta(-1),
18a21c7c 76 f2x2SM(0),
85c25c2e 77 fnxnMaxAmp(-1), fnxnModulePhi(-1), fnxnModuleEta(-1),
0b2ec9f7 78 fnxnSM(0),
0964c2e9 79 fADCValuesHighnxn(0),fADCValuesLownxn(0),
80 fADCValuesHigh2x2(0),fADCValuesLow2x2(0),
81 fDigitsList(0),
85c25c2e 82 fL0Threshold(100),fL1GammaLowPtThreshold(200),
83 fL1GammaMediumPtThreshold(500), fL1GammaHighPtThreshold(1000),
0964c2e9 84 fPatchSize(1), fIsolPatchSize(1),
85 f2x2AmpOutOfPatch(-1), fnxnAmpOutOfPatch(-1),
86 f2x2AmpOutOfPatchThres(100000), fnxnAmpOutOfPatchThres(100000),
87 fIs2x2Isol(kFALSE), fIsnxnIsol(kFALSE),
85c25c2e 88 fSimulation(kTRUE), fIsolateInSuperModule(kTRUE), fTimeKey(kFALSE),
89 fAmpTrus(0),fTimeRtrus(0),fAmpSMods(0),
90 fTriggerPosition(6), fTriggerAmplitudes(4),
91 fNJetPatchPhi(3), fNJetPatchEta(3), fNJetThreshold(3), fL1JetThreshold(0), fJetMaxAmp(0),
92 fAmpJetMatrix(0), fJetMatrixE(0), fAmpJetMax(6,1), fVZER0Mult(0.)
f0377b23 93{
59264fa6 94 //ctor
0964c2e9 95 fADCValuesHighnxn = 0x0; //new Int_t[fTimeBins];
96 fADCValuesLownxn = 0x0; //new Int_t[fTimeBins];
97 fADCValuesHigh2x2 = 0x0; //new Int_t[fTimeBins];
98 fADCValuesLow2x2 = 0x0; //new Int_t[fTimeBins];
59264fa6 99
59264fa6 100 SetName("EMCAL");
85c25c2e 101 // Define jet threshold - can not change from outside now
102 // fNJetThreshold = 7; // For MB Pythia suppression
103 fNJetThreshold = 10; // Hijing
104 fL1JetThreshold = new Double_t[fNJetThreshold];
105 if(fNJetThreshold == 7) {
106 fL1JetThreshold[0] = 5./0.0153;
107 fL1JetThreshold[1] = 8./0.0153;
108 fL1JetThreshold[2] = 10./0.0153;
109 fL1JetThreshold[3] = 12./0.0153;
110 fL1JetThreshold[4] = 13./0.0153;
111 fL1JetThreshold[5] = 14./0.0153;
112 fL1JetThreshold[6] = 15./0.0153;
113 } else if(fNJetThreshold == 10) {
114 Double_t thGev[10]={5.,8.,10., 12., 13.,14.,15., 17., 20., 25.};
115 for(Int_t i=0; i<fNJetThreshold; i++) fL1JetThreshold[i] = thGev[i]/0.0153;
116 } else {
117 fL1JetThreshold[0] = 5./0.0153;
118 fL1JetThreshold[1] = 10./0.0153;
119 fL1JetThreshold[2] = 15./0.0153;
120 fL1JetThreshold[3] = 20./0.0153;
121 fL1JetThreshold[4] = 25./0.0153;
122 }
123 //
59264fa6 124 CreateInputs();
85c25c2e 125
126 fInputs.SetName("TriggersInputs");
59264fa6 127 //Print("") ;
f0377b23 128}
129
0293e426 130//____________________________________________________________________________
c35bbfd4 131AliEMCALTrigger::~AliEMCALTrigger() {
581ee158 132
133 //dtor
134
85c25c2e 135 if(GetTimeKey()) {
136 delete [] fADCValuesHighnxn;
137 delete [] fADCValuesLownxn;
138 delete [] fADCValuesHigh2x2;
139 delete [] fADCValuesLow2x2;
140 }
141 if(fAmpTrus) {fAmpTrus->Delete(); delete fAmpTrus;}
142 if(fTimeRtrus) {fTimeRtrus->Delete(); delete fTimeRtrus;}
143 if(fAmpSMods) {fAmpSMods->Delete(); delete fAmpSMods;}
144 if(fAmpJetMatrix) delete fAmpJetMatrix;
145 if(fJetMatrixE) delete fJetMatrixE;
146 if(fL1JetThreshold) delete [] fL1JetThreshold;
c35bbfd4 147}
148
f0377b23 149//----------------------------------------------------------------------
150void AliEMCALTrigger::CreateInputs()
151{
152 // inputs
153
154 // Do not create inputs again!!
155 if( fInputs.GetEntriesFast() > 0 ) return;
85c25c2e 156
157 // Second parameter should be detector name = "EMCAL"
158 TString det("EMCAL"); // Apr 29, 2008
159 fInputs.AddLast( new AliTriggerInput( det+"_L0", det, 0x02) );
160 fInputs.AddLast( new AliTriggerInput( det+"_GammaHPt_L1", det, 0x04 ) );
161 fInputs.AddLast( new AliTriggerInput( det+"_GammaMPt_L1", det, 0x08 ) );
162 fInputs.AddLast( new AliTriggerInput( det+"_GammaLPt_L1", det, 0x016 ) );
ad534ff6 163 fInputs.AddLast( new AliTriggerInput( det+"_JetHPt_L1", det, 0x032 ) );
2994ff3b 164 fInputs.AddLast( new AliTriggerInput( det+"_JetMPt_L1", det, 0x048 ) );
165 fInputs.AddLast( new AliTriggerInput( det+"_JetLPt_L1", det, 0x064 ) );
85c25c2e 166
167 if(fNJetThreshold<=0) return;
168 // Jet Trigger(s)
169 UInt_t level = 0x032;
170 for(Int_t i=0; i<fNJetThreshold; i++ ) {
7e42cd80 171 TString name(GetNameOfJetTrigger(i));
85c25c2e 172 TString title("EMCAL Jet triger L1 :"); // unused now
173 // 0.0153 - hard coded now
174 title += Form("Th %i(%5.1f GeV) :", (Int_t)fL1JetThreshold[i], fL1JetThreshold[i] * 0.0153);
175 title += Form("patch %ix%i~(%3.2f(#phi)x%3.2f(#eta)) ",
176 fNJetPatchPhi, fNJetPatchEta, 0.11*(fNJetPatchPhi), 0.11*(fNJetPatchEta));
177 fInputs.AddLast( new AliTriggerInput(name, det, UChar_t(level)) );
178 level *= 2;
179 }
f0377b23 180
181}
182
183//____________________________________________________________________________
0964c2e9 184Bool_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) {
185
85c25c2e 186 // Nov 8, 2007
187 // EMCAL RTU size is 4modules(phi) x 24modules (eta)
188 // So maximum size of patch is 4modules x 4modules (EMCAL L0 trigger).
189 // Calculate if the maximum patch found is isolated, find amplitude around maximum (2x2 or nxn) patch,
190 // inside isolation patch . iPatchType = 0 means calculation for 2x2 patch,
191 // iPatchType = 1 means calculation for nxn patch.
192 // In the next table there is an example of the different options of patch size and isolation patch size:
193 // Patch Size (fPatchSize)
194 // 0 1
195 // fIsolPatchSize 0 2x2 (not overlap) 4x4 (overlapped)
196 // 1 4x4 8x8
0964c2e9 197
198 Bool_t b = kFALSE;
622e10be 199 if(!ampmatrixes) return kFALSE;
200
85c25c2e 201 // Get matrix of TRU or Module with maximum amplitude patch.
202 Int_t itru = mtru + iSM * fGeom->GetNTRU(); //number of tru, min 0 max 3*12=36.
0964c2e9 203 TMatrixD * ampmatrix = 0x0;
204 Int_t colborder = 0;
205 Int_t rowborder = 0;
85c25c2e 206 static int keyPrint = 0;
0293e426 207 if(keyPrint) AliDebug(2,Form(" IsPatchIsolated : iSM %i mtru %i itru %i maxphi %i maxeta %i \n", iSM, mtru, itru, maxphi, maxeta));
0964c2e9 208
85c25c2e 209 if(fIsolateInSuperModule){ // ?
0964c2e9 210 ampmatrix = dynamic_cast<TMatrixD *>(ampmatrixes->At(iSM)) ;
85c25c2e 211 rowborder = fGeom->GetNPhi();
212 colborder = fGeom->GetNZ();
0964c2e9 213 AliDebug(2,"Isolate trigger in Module");
85c25c2e 214 } else{
0964c2e9 215 ampmatrix = dynamic_cast<TMatrixD *>(ampmatrixes->At(itru)) ;
85c25c2e 216 rowborder = fGeom->GetNModulesInTRUPhi();
217 colborder = fGeom->GetNModulesInTRUEta();
0964c2e9 218 AliDebug(2,"Isolate trigger in TRU");
219 }
85c25c2e 220 if(iSM>9) rowborder /= 2; // half size in phi
0964c2e9 221
6ce4e2ed 222 if(!ampmatrixes || !ampmatrix){
a51e676d 223 AliError("Could not recover the matrix with the amplitudes");
224 return kFALSE;
225 }
226
85c25c2e 227 //Define patch modules - what is this ??
228 Int_t isolmodules = fIsolPatchSize*(1+iPatchType);
229 Int_t ipatchmodules = 2*(1+fPatchSize*iPatchType);
230 Int_t minrow = maxphi - isolmodules;
231 Int_t mincol = maxeta - isolmodules;
232 Int_t maxrow = maxphi + isolmodules + ipatchmodules;
233 Int_t maxcol = maxeta + isolmodules + ipatchmodules;
234
235 minrow = minrow<0?0 :minrow;
236 mincol = mincol<0?0 :mincol;
237
238 maxrow = maxrow>rowborder?rowborder :maxrow;
239 maxcol = maxcol>colborder?colborder :maxcol;
9946f2fe 240
85c25c2e 241 //printf("%s\n",Form("Number of added Isol Modules %d, Patch Size %d",isolmodules, ipatchmodules));
242 //printf("%s\n",Form("Patch: minrow %d, maxrow %d, mincol %d, maxcol %d",minrow,maxrow,mincol,maxcol));
243 // AliDebug(2,Form("Number of added Isol Modules %d, Patch Size %d",isolmodules, ipatchmodules));
244 //AliDebug(2,Form("Patch: minrow %d, maxrow %d, mincol %d, maxcol %d",minrow,maxrow,mincol,maxcol));
0964c2e9 245
0964c2e9 246 //Add amplitudes in all isolation patch
85c25c2e 247 Float_t amp = 0.;
0964c2e9 248 for(Int_t irow = minrow ; irow < maxrow; irow ++)
249 for(Int_t icol = mincol ; icol < maxcol ; icol ++)
250 amp += (*ampmatrix)(irow,icol);
251
252 AliDebug(2,Form("Type %d, Maximum amplitude %f, patch+isol square %f",iPatchType, maxamp, amp));
253
254 if(amp < maxamp){
85c25c2e 255 // AliError(Form("Bad sum: Type %d, Maximum amplitude %f, patch+isol square %f",iPatchType, maxamp, amp));
256 // ampmatrix->Print();
0964c2e9 257 return kFALSE;
85c25c2e 258 } else {
0964c2e9 259 amp-=maxamp; //Calculate energy in isolation patch that do not comes from maximum patch.
85c25c2e 260 }
0964c2e9 261
262 AliDebug(2, Form("Maximum amplitude %f, Out of patch %f",maxamp, amp));
263
264 //Fill isolation amplitude data member and say if patch is isolated.
265 if(iPatchType == 0){ //2x2 case
266 f2x2AmpOutOfPatch = amp;
85c25c2e 267 if(amp < f2x2AmpOutOfPatchThres) b=kTRUE;
268 } else if(iPatchType == 1){ //nxn case
0964c2e9 269 fnxnAmpOutOfPatch = amp;
85c25c2e 270 if(amp < fnxnAmpOutOfPatchThres) b=kTRUE;
0964c2e9 271 }
272
0293e426 273 if(keyPrint) AliDebug(2,Form(" IsPatchIsolated - OUT \n"));
85c25c2e 274
0964c2e9 275 return b;
276
277}
278
85c25c2e 279/*
0964c2e9 280//____________________________________________________________________________
c35bbfd4 281void AliEMCALTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClonesArray * timeRtrus, const Int_t isupermod,TMatrixD &ampmax2, TMatrixD &ampmaxn){
f0377b23 282
85c25c2e 283 //Sums energy of all possible 2x2 (L0) and nxn (L1) modules per each TRU.
284 //Fast signal in the experiment is given by 2x2 modules,
285 //for this reason we loop inside the TRU modules by 2.
33d0b833 286
59264fa6 287 //Declare and initialize variables
9946f2fe 288 Int_t nCellsPhi = fGeom->GetNCellsInTRUPhi();
33d0b833 289 if(isupermod > 9)
59264fa6 290 nCellsPhi = nCellsPhi / 2 ; //Half size SM. Not Final.
f0377b23 291 // 12(tow)*2(cell)/1 TRU, cells in Phi in one TRU
9946f2fe 292 Int_t nCellsEta = fGeom->GetNCellsInTRUEta();
293 Int_t nTRU = fGeom->GetNTRU();
f0377b23 294 // 24(mod)*2(tower)/3 TRU, cells in Eta in one TRU
0964c2e9 295 //Int_t nTRU = geom->GeNTRU();//3 TRU per super module
f0377b23 296
59264fa6 297 Float_t amp2 = 0 ;
0b2ec9f7 298 Float_t ampn = 0 ;
33d0b833 299 for(Int_t i = 0; i < 4; i++){
9946f2fe 300 for(Int_t j = 0; j < nTRU; j++){
c35bbfd4 301 ampmax2(i,j) = -1;
302 ampmaxn(i,j) = -1;
59264fa6 303 }
304 }
f0377b23 305
59264fa6 306 //Create matrix that will contain 2x2 amplitude sums
0b2ec9f7 307 //used to calculate the nxn sums
c35bbfd4 308 TMatrixD tru2x2(nCellsPhi/2,nCellsEta/2) ;
59264fa6 309 for(Int_t i = 0; i < nCellsPhi/2; i++)
310 for(Int_t j = 0; j < nCellsEta/2; j++)
c35bbfd4 311 tru2x2(i,j) = -1;
59264fa6 312
313 //Loop over all TRUS in a supermodule
9946f2fe 314 for(Int_t itru = 0 + isupermod * nTRU ; itru < (isupermod+1)*nTRU ; itru++) {
59264fa6 315 TMatrixD * amptru = dynamic_cast<TMatrixD *>(amptrus->At(itru)) ;
316 TMatrixD * timeRtru = dynamic_cast<TMatrixD *>(timeRtrus->At(itru)) ;
9946f2fe 317 Int_t mtru = itru-isupermod*nTRU ; //Number of TRU in Supermodule
33d0b833 318
59264fa6 319 //Sliding 2x2, add 2x2 amplitudes (NOT OVERLAP)
320 for(Int_t irow = 0 ; irow < nCellsPhi; irow += 2){
321 for(Int_t icol = 0 ; icol < nCellsEta ; icol += 2){
322 amp2 = (*amptru)(irow,icol)+(*amptru)(irow+1,icol)+
323 (*amptru)(irow,icol+1)+(*amptru)(irow+1,icol+1);
33d0b833 324
0964c2e9 325 //Fill matrix with added 2x2 cells for use in nxn sums
c35bbfd4 326 tru2x2(irow/2,icol/2) = amp2 ;
59264fa6 327 //Select 2x2 maximum sums to select L0
c35bbfd4 328 if(amp2 > ampmax2(0,mtru)){
329 ampmax2(0,mtru) = amp2 ;
330 ampmax2(1,mtru) = irow;
331 ampmax2(2,mtru) = icol;
59264fa6 332 }
333 }
334 }
335
336 //Find most recent time in the selected 2x2 cell
c35bbfd4 337 ampmax2(3,mtru) = 1 ;
338 Int_t row2 = static_cast <Int_t> (ampmax2(1,mtru));
339 Int_t col2 = static_cast <Int_t> (ampmax2(2,mtru));
59264fa6 340 for(Int_t i = 0; i<2; i++){
341 for(Int_t j = 0; j<2; j++){
342 if((*amptru)(row2+i,col2+j) > 0 && (*timeRtru)(row2+i,col2+j)> 0){
c35bbfd4 343 if((*timeRtru)(row2+i,col2+j) < ampmax2(3,mtru) )
344 ampmax2(3,mtru) = (*timeRtru)(row2+i,col2+j);
59264fa6 345 }
346 }
347 }
0b2ec9f7 348
349 //Sliding nxn, add nxn amplitudes (OVERLAP)
350 if(fPatchSize > 0){
351 for(Int_t irow = 0 ; irow < nCellsPhi/2; irow++){
352 for(Int_t icol = 0 ; icol < nCellsEta/2 ; icol++){
353 ampn = 0;
354 if( (irow+fPatchSize) < nCellsPhi/2 && (icol+fPatchSize) < nCellsEta/2){//Avoid exit the TRU
355 for(Int_t i = 0 ; i <= fPatchSize ; i++)
356 for(Int_t j = 0 ; j <= fPatchSize ; j++)
c35bbfd4 357 ampn += tru2x2(irow+i,icol+j);
0b2ec9f7 358 //Select nxn maximum sums to select L1
c35bbfd4 359 if(ampn > ampmaxn(0,mtru)){
360 ampmaxn(0,mtru) = ampn ;
361 ampmaxn(1,mtru) = irow*2;
362 ampmaxn(2,mtru) = icol*2;
0b2ec9f7 363 }
59264fa6 364 }
365 }
366 }
0b2ec9f7 367
368 //Find most recent time in selected nxn cell
c35bbfd4 369 ampmaxn(3,mtru) = 1 ;
370 Int_t rown = static_cast <Int_t> (ampmaxn(1,mtru));
371 Int_t coln = static_cast <Int_t> (ampmaxn(2,mtru));
0b2ec9f7 372 for(Int_t i = 0; i<4*fPatchSize; i++){
373 for(Int_t j = 0; j<4*fPatchSize; j++){
9946f2fe 374 if( (rown+i) < nCellsPhi && (coln+j) < nCellsEta){//Avoid exit the TRU
0b2ec9f7 375 if((*amptru)(rown+i,coln+j) > 0 && (*timeRtru)(rown+i,coln+j)> 0){
c35bbfd4 376 if((*timeRtru)(rown+i,coln+j) < ampmaxn(3,mtru) )
377 ampmaxn(3,mtru) = (*timeRtru)(rown+i,coln+j);
0b2ec9f7 378 }
379 }
59264fa6 380 }
381 }
382 }
0b2ec9f7 383 else {
c35bbfd4 384 ampmaxn(0,mtru) = ampmax2(0,mtru);
385 ampmaxn(1,mtru) = ampmax2(1,mtru);
386 ampmaxn(2,mtru) = ampmax2(2,mtru);
387 ampmaxn(3,mtru) = ampmax2(3,mtru);
0b2ec9f7 388 }
f0377b23 389 }
f0377b23 390}
85c25c2e 391*/
392//____________________________________________________________________________
393void AliEMCALTrigger::MakeSlidingTowers(const TClonesArray * amptrus, const TClonesArray * timeRtrus,
a51e676d 394 const Int_t isupermod,TMatrixD &ampmax2, TMatrixD &ampmaxn){
85c25c2e 395
396 // Output from module (2x2 cells from one module)
397 Int_t nModulesPhi = fGeom->GetNModulesInTRUPhi(); // now 4 modules (3 div in phi)
398 if(isupermod > 9)
399 nModulesPhi = nModulesPhi / 2 ; // Half size SM. Not Final.
400 //
401 Int_t nModulesEta = fGeom->GetNModulesInTRUEta(); // now 24 modules (no division in eta)
402 Int_t nTRU = fGeom->GetNTRU();
403 static int keyPrint = 0;
0293e426 404 if(keyPrint) AliDebug(2,Form("MakeSlidingTowers : nTRU %i nModulesPhi %i nModulesEta %i ",
a51e676d 405 nTRU, nModulesPhi, nModulesEta ));
406
85c25c2e 407 Float_t amp2 = 0 ;
408 Float_t ampn = 0 ;
409 for(Int_t i = 0; i < 4; i++){
410 for(Int_t j = 0; j < nTRU; j++){
411 ampmax2(i,j) = ampmaxn(i,j) = -1;
412 }
413 }
a51e676d 414
85c25c2e 415 // Create matrix that will contain 2x2 amplitude sums
416 // used to calculate the nxn sums
417 TMatrixD tru2x2(nModulesPhi/2,nModulesEta/2);
a51e676d 418
85c25c2e 419 // Loop over all TRUS in a supermodule
420 for(Int_t itru = 0 + isupermod * nTRU ; itru < (isupermod+1)*nTRU ; itru++) {
421 TMatrixD * amptru = dynamic_cast<TMatrixD *>(amptrus->At(itru)) ;
422 TMatrixD * timeRtru = dynamic_cast<TMatrixD *>(timeRtrus->At(itru)) ;
423 Int_t mtru = itru - isupermod*nTRU ; // Number of TRU in Supermodule !!
a51e676d 424
425 if(!amptru || !timeRtru){
13242232 426 AliError("Amplitude or Time TRU matrix not available");
a51e676d 427 return;
428 }
429
85c25c2e 430 // Sliding 2x2, add 2x2 amplitudes (NOT OVERLAP)
431 for(Int_t irow = 0 ; irow < nModulesPhi; irow +=2){
432 for(Int_t icol = 0 ; icol < nModulesEta ; icol +=2){
a51e676d 433 amp2 = (*amptru)(irow,icol) +(*amptru)(irow+1,icol)+
434 (*amptru)(irow,icol+1)+(*amptru)(irow+1,icol+1);
435
436 //Fill matrix with added 2x2 towers for use in nxn sums
437 tru2x2(irow/2,icol/2) = amp2 ;
438 //Select 2x2 maximum sums to select L0
439 if(amp2 > ampmax2(0,mtru)){
440 ampmax2(0,mtru) = amp2 ;
441 ampmax2(1,mtru) = irow;
442 ampmax2(2,mtru) = icol;
443 }
85c25c2e 444 }
445 }
446
447 ampmax2(3,mtru) = 0.;
448 if(GetTimeKey()) {
a51e676d 449 // Find most recent time in the selected 2x2 towers
85c25c2e 450 Int_t row2 = static_cast <Int_t> (ampmax2(1,mtru));
451 Int_t col2 = static_cast <Int_t> (ampmax2(2,mtru));
452 for(Int_t i = 0; i<2; i++){
453 for(Int_t j = 0; j<2; j++){
a51e676d 454 if((*amptru)(row2+i,col2+j) > 0 && (*timeRtru)(row2+i,col2+j)> 0){
455 if((*timeRtru)(row2+i,col2+j) > ampmax2(3,mtru) )
456 ampmax2(3,mtru) = (*timeRtru)(row2+i,col2+j); // max time
457 }
85c25c2e 458 }
459 }
460 }
a51e676d 461
85c25c2e 462 //Sliding nxn, add nxn amplitudes (OVERLAP)
463 if(fPatchSize > 0){
464 for(Int_t irow = 0 ; irow < nModulesPhi/2; irow++){
a51e676d 465 for(Int_t icol = 0 ; icol < nModulesEta/2; icol++){
466 ampn = 0;
467 if( (irow+fPatchSize) < nModulesPhi/2 && (icol+fPatchSize) < nModulesEta/2){ //Avoid exit the TRU
468 for(Int_t i = 0 ; i <= fPatchSize ; i++)
469 for(Int_t j = 0 ; j <= fPatchSize ; j++)
470 ampn += tru2x2(irow+i,icol+j);
471 //Select nxn maximum sums to select L1
472 if(ampn > ampmaxn(0,mtru)){
473 ampmaxn(0,mtru) = ampn ;
474 ampmaxn(1,mtru) = irow;
475 ampmaxn(2,mtru) = icol;
476 }
477 }
478 }
85c25c2e 479 }
480
481 ampmaxn(3,mtru) = 0.; // Was 1 , I don't know why
482 if(GetTimeKey()) {
a51e676d 483 //Find most recent time in selected nxn cell
85c25c2e 484 Int_t rown = static_cast <Int_t> (ampmaxn(1,mtru));
485 Int_t coln = static_cast <Int_t> (ampmaxn(2,mtru));
486 for(Int_t i = 0; i<4*fPatchSize; i++){
a51e676d 487 for(Int_t j = 0; j<4*fPatchSize; j++){
488 if( (rown+i) < nModulesPhi && (coln+j) < nModulesEta){//Avoid exit the TRU
489 if((*amptru)(rown+i,coln+j) > 0 && (*timeRtru)(rown+i,coln+j)> 0){
490 if((*timeRtru)(rown+i,coln+j) > ampmaxn(3,mtru) )
491 ampmaxn(3,mtru) = (*timeRtru)(rown+i,coln+j); // max time
492 }
493 }
494 }
85c25c2e 495 }
496 }
497 } else { // copy 2x2 to nxn
a51e676d 498 ampmaxn(0,mtru) = ampmax2(0,mtru);
499 ampmaxn(1,mtru) = ampmax2(1,mtru);
500 ampmaxn(2,mtru) = ampmax2(2,mtru);
501 ampmaxn(3,mtru) = ampmax2(3,mtru);
85c25c2e 502 }
503 }
0293e426 504 if(keyPrint) AliDebug(2,Form(" : MakeSlidingTowers -OUt \n"));
85c25c2e 505}
f0377b23 506
507//____________________________________________________________________________
508void AliEMCALTrigger::Print(const Option_t * opt) const
509{
510
511 //Prints main parameters
512
513 if(! opt)
514 return;
515 AliTriggerInput* in = 0x0 ;
0293e426 516 AliInfo(Form(" fSimulation %i (input option) : #digits %i\n", fSimulation, fDigitsList->GetEntries()));
517 AliInfo(Form(" fTimeKey %i \n ", fTimeKey));
518
519 AliInfo(Form("\t Maximum Amplitude after Sliding Cell, \n")) ;
520 AliInfo(Form("\t -2x2 cells sum (not overlapped): %10.2f, in Super Module %d\n",
521 f2x2MaxAmp,f2x2SM)) ;
522 AliInfo(Form("\t -2x2 from row %d to row %d and from column %d to column %d\n", f2x2ModulePhi, f2x2ModulePhi+2, f2x2ModuleEta, f2x2ModuleEta+2));
523 AliInfo(Form("\t -2x2 Isolation Patch %d x %d, Amplitude out of 2x2 patch is %f, threshold %f, Isolated? %d \n", 2*fIsolPatchSize+2, 2*fIsolPatchSize+2, f2x2AmpOutOfPatch, f2x2AmpOutOfPatchThres,static_cast<Int_t> (fIs2x2Isol)));
0b2ec9f7 524 if(fPatchSize > 0){
0293e426 525 AliInfo(Form("\t Patch Size, n x n: %d x %d cells\n",2*(fPatchSize+1), 2*(fPatchSize+1)));
526 AliInfo(Form("\t -nxn cells sum (overlapped) : %10.2f, in Super Module %d\n", fnxnMaxAmp,fnxnSM));
527 AliInfo(Form("\t -nxn from row %d to row %d and from column %d to column %d\n", fnxnModulePhi, fnxnModulePhi+4*fPatchSize, fnxnModuleEta, fnxnModuleEta+4*fPatchSize)) ;
528 AliInfo(Form("\t -nxn Isolation Patch %d x %d, Amplitude out of nxn patch is %f, threshold %f, Isolated? %d \n", 4*fIsolPatchSize+2*(fPatchSize+1),4*fIsolPatchSize+2*(fPatchSize+1) , fnxnAmpOutOfPatch, fnxnAmpOutOfPatchThres,static_cast<Int_t> (fIsnxnIsol) ));
0b2ec9f7 529 }
0964c2e9 530
0293e426 531 AliInfo(Form("\t Isolate in SuperModule? %d\n", fIsolateInSuperModule)) ;
532 AliInfo(Form("\t Threshold for LO %10.2f\n", fL0Threshold));
0964c2e9 533
59264fa6 534 in = (AliTriggerInput*)fInputs.FindObject( "EMCAL_L0" );
f0377b23 535 if(in->GetValue())
0293e426 536 AliInfo(Form("\t *** EMCAL LO is set ***\n"));
f0377b23 537
0293e426 538 AliInfo(Form("\t Gamma Low Pt Threshold for L1 %10.2f\n", fL1GammaLowPtThreshold));
85c25c2e 539 in = (AliTriggerInput*)fInputs.FindObject( "EMCAL_GammaLPt_L1" );
f0377b23 540 if(in->GetValue())
0293e426 541 AliInfo(Form("\t *** EMCAL Gamma Low Pt for L1 is set ***\n"));
f0377b23 542
0293e426 543 AliInfo(Form("\t Gamma Medium Pt Threshold for L1 %10.2f\n", fL1GammaMediumPtThreshold));
85c25c2e 544 in = (AliTriggerInput*) fInputs.FindObject( "EMCAL_GammaMPt_L1" );
f0377b23 545 if(in->GetValue())
0293e426 546 AliInfo(Form("\t *** EMCAL Gamma Medium Pt for L1 is set ***\n"));
f0377b23 547
0293e426 548 AliInfo(Form("\t Gamma High Pt Threshold for L1 %10.2f\n", fL1GammaHighPtThreshold));
85c25c2e 549 in = (AliTriggerInput*) fInputs.FindObject( "EMCAL_GammaHPt_L1" );
f0377b23 550 if(in->GetValue())
0293e426 551 AliInfo(Form("\t *** EMCAL Gamma High Pt for L1 is set ***\n")) ;
f0377b23 552
553}
554
555//____________________________________________________________________________
0964c2e9 556void AliEMCALTrigger::SetTriggers(const TClonesArray * ampmatrix,const Int_t iSM,
c35bbfd4 557 const TMatrixD &ampmax2,
9946f2fe 558 const TMatrixD &ampmaxn)
f0377b23 559{
0b2ec9f7 560 //Checks the 2x2 and nxn maximum amplitude per each TRU and
59264fa6 561 //compares with the different L0 and L1 triggers thresholds
562 Float_t max2[] = {-1,-1,-1,-1} ;
0b2ec9f7 563 Float_t maxn[] = {-1,-1,-1,-1} ;
0964c2e9 564 Int_t mtru2 = -1 ;
565 Int_t mtrun = -1 ;
f0377b23 566
9946f2fe 567 Int_t nTRU = fGeom->GetNTRU();
568
59264fa6 569 //Find maximum summed amplitude of all the TRU
570 //in a Super Module
9946f2fe 571 for(Int_t i = 0 ; i < nTRU ; i++){
c35bbfd4 572 if(max2[0] < ampmax2(0,i) ){
573 max2[0] = ampmax2(0,i) ; // 2x2 summed max amplitude
574 max2[1] = ampmax2(1,i) ; // corresponding phi position in TRU
575 max2[2] = ampmax2(2,i) ; // corresponding eta position in TRU
576 max2[3] = ampmax2(3,i) ; // corresponding most recent time
0964c2e9 577 mtru2 = i ;
59264fa6 578 }
c35bbfd4 579 if(maxn[0] < ampmaxn(0,i) ){
580 maxn[0] = ampmaxn(0,i) ; // nxn summed max amplitude
581 maxn[1] = ampmaxn(1,i) ; // corresponding phi position in TRU
582 maxn[2] = ampmaxn(2,i) ; // corresponding eta position in TRU
583 maxn[3] = ampmaxn(3,i) ; // corresponding most recent time
0964c2e9 584 mtrun = i ;
59264fa6 585 }
586 }
587
588 //--------Set max amplitude if larger than in other Super Modules------------
589 Float_t maxtimeR2 = -1 ;
0b2ec9f7 590 Float_t maxtimeRn = -1 ;
133abe1f 591 static AliEMCALRawUtils rawUtil;
92d9f317 592 // Int_t nTimeBins = rawUtil.GetRawFormatTimeBins() ;
593 Int_t nTimeBins = TIMEBINS; //changed by PTH
59264fa6 594
595 //Set max of 2x2 amplitudes and select L0 trigger
596 if(max2[0] > f2x2MaxAmp ){
85c25c2e 597 // if(max2[0] > 5) printf(" L0 : iSM %i: max2[0] %5.0f : max2[3] %5.0f (maxtimeR2) \n",
598 // iSM, max2[0], max2[3]);
59264fa6 599 f2x2MaxAmp = max2[0] ;
600 f2x2SM = iSM ;
601 maxtimeR2 = max2[3] ;
85c25c2e 602 fGeom->GetModulePhiEtaIndexInSModuleFromTRUIndex(mtru2,
59264fa6 603 static_cast<Int_t>(max2[1]),
604 static_cast<Int_t>(max2[2]),
85c25c2e 605 f2x2ModulePhi,f2x2ModuleEta);
59264fa6 606
0964c2e9 607 //Isolated patch?
608 if(fIsolateInSuperModule)
85c25c2e 609 fIs2x2Isol = IsPatchIsolated(0, ampmatrix, iSM, mtru2, f2x2MaxAmp, f2x2ModulePhi,f2x2ModuleEta) ;
0964c2e9 610 else
611 fIs2x2Isol = IsPatchIsolated(0, ampmatrix, iSM, mtru2, f2x2MaxAmp, static_cast<Int_t>(max2[1]), static_cast<Int_t>(max2[2])) ;
612
85c25c2e 613 if(GetTimeKey()) {
59264fa6 614 //Transform digit amplitude in Raw Samples
85c25c2e 615 if (fADCValuesLow2x2 == 0) {
616 fADCValuesLow2x2 = new Int_t[nTimeBins];
617 fADCValuesHigh2x2 = new Int_t[nTimeBins];
618 }
619 //printf(" maxtimeR2 %12.5e (1)\n", maxtimeR2);
92d9f317 620 // rawUtil.RawSampledResponse(maxtimeR2 * AliEMCALRawUtils::GetRawFormatTimeBin(),
621 // f2x2MaxAmp, fADCValuesHigh2x2, fADCValuesLow2x2) ;
622
1f847d9f 623 // rawUtil.RawSampledResponse(maxtimeR2*TIMEBINMAX/TIMEBINS,
624 // f2x2MaxAmp, fADCValuesHigh2x2, fADCValuesLow2x2) ;
92d9f317 625
1f847d9f 626 AliEMCALRawResponse::RawSampledResponse( maxtimeR2*TIMEBINMAX/TIMEBINS,
627 f2x2MaxAmp, fADCValuesHigh2x2, fADCValuesLow2x2) ;
628
85c25c2e 629 // Set Trigger Inputs, compare ADC time bins until threshold is attained
630 // Set L0
631 for(Int_t i = 0 ; i < nTimeBins ; i++){
632 // printf(" fADCValuesHigh2x2[%i] %i : %i \n", i, fADCValuesHigh2x2[i], fADCValuesLow2x2[i]);
633 if(fADCValuesHigh2x2[i] >= fL0Threshold || fADCValuesLow2x2[i] >= fL0Threshold){
634 SetInput("EMCAL_L0") ;
635 break;
636 }
637 }
638 } else {
639 // Nov 5 - no analysis of time information
640 if(f2x2MaxAmp >= fL0Threshold) { // should add the low amp too
641 SetInput("EMCAL_L0");
59264fa6 642 }
643 }
f0377b23 644 }
59264fa6 645
0b2ec9f7 646 //------------Set max of nxn amplitudes and select L1 trigger---------
647 if(maxn[0] > fnxnMaxAmp ){
648 fnxnMaxAmp = maxn[0] ;
649 fnxnSM = iSM ;
650 maxtimeRn = maxn[3] ;
85c25c2e 651 fGeom->GetModulePhiEtaIndexInSModuleFromTRUIndex(mtrun,
0b2ec9f7 652 static_cast<Int_t>(maxn[1]),
653 static_cast<Int_t>(maxn[2]),
85c25c2e 654 fnxnModulePhi,fnxnModuleEta) ;
0964c2e9 655
656 //Isolated patch?
657 if(fIsolateInSuperModule)
85c25c2e 658 fIsnxnIsol = IsPatchIsolated(1, ampmatrix, iSM, mtrun, fnxnMaxAmp, fnxnModulePhi, fnxnModuleEta) ;
0964c2e9 659 else
660 fIsnxnIsol = IsPatchIsolated(1, ampmatrix, iSM, mtrun, fnxnMaxAmp, static_cast<Int_t>(maxn[1]), static_cast<Int_t>(maxn[2])) ;
661
85c25c2e 662 if(GetTimeKey()) {
59264fa6 663 //Transform digit amplitude in Raw Samples
85c25c2e 664 if (fADCValuesLownxn == 0) {
665 fADCValuesHighnxn = new Int_t[nTimeBins];
666 fADCValuesLownxn = new Int_t[nTimeBins];
667 }
92d9f317 668 // rawUtil.RawSampledResponse(maxtimeRn * AliEMCALRawUtils::GetRawFormatTimeBin(),
669 // fnxnMaxAmp, fADCValuesHighnxn, fADCValuesLownxn) ;
92d9f317 670
1f847d9f 671 //rawUtil.RawSampledResponse(maxtimeRn*TIMEBINMAX/TIMEBINS,
672 // fnxnMaxAmp, fADCValuesHighnxn, fADCValuesLownxn) ;
92d9f317 673
1f847d9f 674 AliEMCALRawResponse::RawSampledResponse (maxtimeRn*TIMEBINMAX/TIMEBINS,
675 fnxnMaxAmp, fADCValuesHighnxn, fADCValuesLownxn) ;
676
59264fa6 677 //Set Trigger Inputs, compare ADC time bins until threshold is attained
678 //SetL1 Low
85c25c2e 679 for(Int_t i = 0 ; i < nTimeBins ; i++){
680 if(fADCValuesHighnxn[i] >= fL1GammaLowPtThreshold || fADCValuesLownxn[i] >= fL1GammaLowPtThreshold){
681 SetInput("EMCAL_GammaLPt_L1") ;
682 break;
683 }
59264fa6 684 }
59264fa6 685
686 //SetL1 Medium
85c25c2e 687 for(Int_t i = 0 ; i < nTimeBins ; i++){
688 if(fADCValuesHighnxn[i] >= fL1GammaMediumPtThreshold || fADCValuesLownxn[i] >= fL1GammaMediumPtThreshold){
689 SetInput("EMCAL_GammaMPt_L1") ;
690 break;
691 }
59264fa6 692 }
59264fa6 693
694 //SetL1 High
85c25c2e 695 for(Int_t i = 0 ; i < nTimeBins ; i++){
696 if(fADCValuesHighnxn[i] >= fL1GammaHighPtThreshold || fADCValuesLownxn[i] >= fL1GammaHighPtThreshold){
697 SetInput("EMCAL_GammaHPt_L1") ;
698 break;
699 }
700 }
701 } else {
702 // Nov 5 - no analysis of time information
703 if(fnxnMaxAmp >= fL1GammaLowPtThreshold) { // should add the low amp too
704 SetInput("EMCAL_GammaLPt_L1") ; //SetL1 Low
705 }
706 if(fnxnMaxAmp >= fL1GammaMediumPtThreshold) { // should add the low amp too
707 SetInput("EMCAL_GammaMPt_L1") ; //SetL1 Medium
708 }
709 if(fnxnMaxAmp >= fL1GammaHighPtThreshold) { // should add the low amp too
710 SetInput("EMCAL_GammaHPt_L1") ; //SetL1 High
59264fa6 711 }
712 }
85c25c2e 713 }
59264fa6 714}
f0377b23 715
59264fa6 716//____________________________________________________________________________
9946f2fe 717void AliEMCALTrigger::FillTRU(const TClonesArray * digits, TClonesArray * ampmatrix, TClonesArray * ampmatrixsmod, TClonesArray * timeRmatrix) {
c35bbfd4 718
719// Orders digits ampitudes list in fNTRU TRUs (384 cells) per supermodule.
720// Each TRU is a TMatrixD, and they are kept in TClonesArrays. The number of
721// TRU in phi is fNTRUPhi, and the number of TRU in eta is fNTRUEta.
722// Last 2 modules are half size in Phi, I considered that the number of TRU
723// is maintained for the last modules but decision not taken. If different,
724// then this must be changed. Also fill a matrix with all amplitudes in supermodule for isolation studies.
725
85c25c2e 726// Initilize and declare variables
727// List of TRU matrices initialized to 0.
728// printf("<I> AliEMCALTrigger::FillTRU() started : # digits %i\n", digits->GetEntriesFast());
729
730// Nov 2, 2007.
731// One input per EMCAL module so size of matrix is reduced by 4 (2x2 division case)
732
733 Int_t nPhi = fGeom->GetNPhi();
734 Int_t nZ = fGeom->GetNZ();
735 Int_t nTRU = fGeom->GetNTRU();
736 // Int_t nTRUPhi = fGeom->GetNTRUPhi();
737 Int_t nModulesPhi = fGeom->GetNModulesInTRUPhi();
738 Int_t nModulesPhi2 = fGeom->GetNModulesInTRUPhi();
739 Int_t nModulesEta = fGeom->GetNModulesInTRUEta();
740 // printf("<I> AliEMCALTrigger::FillTRU() nTRU %i nTRUPhi %i : nModulesPhi %i nModulesEta %i \n",
741 // nTRU, nTRUPhi, nModulesPhi, nModulesEta);
c35bbfd4 742
743 Int_t id = -1;
744 Float_t amp = -1;
745 Float_t timeR = -1;
746 Int_t iSupMod = -1;
747 Int_t nModule = -1;
748 Int_t nIphi = -1;
749 Int_t nIeta = -1;
750 Int_t iphi = -1;
751 Int_t ieta = -1;
85c25c2e 752 // iphim, ietam - module indexes in SM
753 Int_t iphim = -1;
754 Int_t ietam = -1;
c35bbfd4 755
756 //List of TRU matrices initialized to 0.
9946f2fe 757 Int_t nSup = fGeom->GetNumberOfSuperModules();
758 for(Int_t k = 0; k < nTRU*nSup; k++){
85c25c2e 759 TMatrixD amptrus(nModulesPhi,nModulesEta) ;
760 TMatrixD timeRtrus(nModulesPhi,nModulesEta) ;
c35bbfd4 761 // Do we need to initialise? I think TMatrixD does it by itself...
85c25c2e 762 for(Int_t i = 0; i < nModulesPhi; i++){
763 for(Int_t j = 0; j < nModulesEta; j++){
c35bbfd4 764 amptrus(i,j) = 0.0;
765 timeRtrus(i,j) = 0.0;
766 }
767 }
768 new((*ampmatrix)[k]) TMatrixD(amptrus) ;
769 new((*timeRmatrix)[k]) TMatrixD(timeRtrus) ;
770 }
771
85c25c2e 772 // List of Modules matrices initialized to 0.
c35bbfd4 773 for(Int_t k = 0; k < nSup ; k++){
85c25c2e 774 int mphi = nPhi;
775 // if(nSup>9) mphi = nPhi/2; // the same size
776 TMatrixD ampsmods( mphi, nZ);
777 for(Int_t i = 0; i < mphi; i++){
778 for(Int_t j = 0; j < nZ; j++){
c35bbfd4 779 ampsmods(i,j) = 0.0;
780 }
781 }
85c25c2e 782 new((*ampmatrixsmod)[k]) TMatrixD(ampsmods) ;
c35bbfd4 783 }
784
785 AliEMCALDigit * dig ;
786
787 //Digits loop to fill TRU matrices with amplitudes.
788 for(Int_t idig = 0 ; idig < digits->GetEntriesFast() ; idig++){
789
790 dig = dynamic_cast<AliEMCALDigit *>(digits->At(idig)) ;
a51e676d 791 if(dig){
792 amp = Float_t(dig->GetAmplitude()); // Energy of the digit (arbitrary units)
793 id = dig->GetId() ; // Id label of the cell
794 timeR = dig->GetTimeR() ; // Earliest time of the digit
795 if(amp<=0.0) AliDebug(1,Form(" id %i amp %f \n", id, amp));
796 // printf(" FILLTRU : timeR %10.5e time %10.5e : amp %10.5e \n", timeR, dig->GetTime(), amp);
797 // Get eta and phi cell position in supermodule
798 Bool_t bCell = fGeom->GetCellIndex(id, iSupMod, nModule, nIphi, nIeta) ;
799 if(!bCell)
800 AliError(Form("%i Wrong cell id number %i ", idig, id)) ;
801
802 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,nModule,nIphi, nIeta,iphi,ieta);
803 // iphim, ietam - module indexes in SM
804 fGeom->GetModuleIndexesFromCellIndexesInSModule(iSupMod,iphi,ieta, iphim, ietam, nModule);
805 //if(iSupMod >9)
806 //printf("iSupMod %i nModule %i iphi %i ieta %i iphim %i ietam %i \n",
807 //iSupMod,nModule, iphi, ieta, iphim, ietam);
808
809 // Check to which TRU in the supermodule belongs the cell.
810 // Supermodules are divided in a TRU matrix of dimension
811 // (fNTRUPhi,fNTRUEta).
812 // Each TRU is a cell matrix of dimension (nModulesPhi,nModulesEta)
813
814 // First calculate the row and column in the supermodule
815 // of the TRU to which the cell belongs.
816 Int_t row = iphim / nModulesPhi;
817 Int_t col = ietam / nModulesEta;
818 //Calculate label number of the TRU
819 Int_t itru = fGeom->GetAbsTRUNumberFromNumberInSm(row, col, iSupMod);
820
821 //Fill TRU matrix with cell values
822 TMatrixD * amptrus = dynamic_cast<TMatrixD *>(ampmatrix->At(itru)) ;
823 TMatrixD * timeRtrus = dynamic_cast<TMatrixD *>(timeRmatrix->At(itru)) ;
824
6ce4e2ed 825 if(!amptrus || !timeRtrus){
a51e676d 826 AliError("Could not recover the TRU matrix with amplitudes or times");
a51e676d 827 }
622e10be 828 else{
829 //Calculate row and column of the module inside the TRU with number itru
830 Int_t irow = iphim - row * nModulesPhi;
831 if(iSupMod > 9)
832 irow = iphim - row * nModulesPhi2; // size of matrix the same
833 Int_t icol = ietam - col * nModulesEta;
a51e676d 834
622e10be 835 (*amptrus)(irow,icol) += amp ;
836 if((*timeRtrus)(irow,icol) <0.0 || (*timeRtrus)(irow,icol) <= timeR){ // ??
837 (*timeRtrus)(irow,icol) = timeR ;
838 }
a51e676d 839 }
840 //printf(" ieta %i iphi %i iSM %i || col %i row %i : itru %i -> amp %f\n",
841 // ieta, iphi, iSupMod, col, row, itru, amp);
842 //####################SUPERMODULE MATRIX ##################
843 TMatrixD * ampsmods = dynamic_cast<TMatrixD *>(ampmatrixsmod->At(iSupMod)) ;
844 if(!ampsmods){
845 AliError("Could not recover the matrix per SM");
846 continue;
847 }
848 (*ampsmods)(iphim,ietam) += amp ;
849 // printf(" id %i iphim %i ietam %i SM %i : irow %i icol %i itru %i : amp %6.0f\n",
850 //id, iphim, ietam, iSupMod, irow, icol, itru, amp);
85c25c2e 851 }
a51e676d 852 else AliError("Could not recover the digit");
c35bbfd4 853 }
85c25c2e 854 //assert(0);
855 //printf("<I> AliEMCALTrigger::FillTRU() is ended \n");
c35bbfd4 856}
0293e426 857
c35bbfd4 858//____________________________________________________________________________
59264fa6 859void AliEMCALTrigger::Trigger()
860{
861 //Main Method to select triggers.
581ee158 862 TH1::AddDirectory(0);
863
33c3c91a 864 AliRunLoader *runLoader = AliRunLoader::Instance();
85c25c2e 865 AliEMCALLoader *emcalLoader = 0;
866 if(runLoader) {
867 emcalLoader = dynamic_cast<AliEMCALLoader*>(runLoader->GetDetectorLoader("EMCAL"));
868 }
0964c2e9 869
59264fa6 870 //Load EMCAL Geometry
a51e676d 871 if (runLoader && runLoader->GetAliRun()){
872 AliEMCAL* emcal = dynamic_cast<AliEMCAL*>(runLoader->GetAliRun()->GetDetector("EMCAL"));
873 if(emcal)fGeom = emcal->GetGeometry();
874 }
875
876 if (!fGeom)
384c0bba 877 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
878
a51e676d 879 if (!fGeom)
59264fa6 880 AliFatal("Did not get geometry from EMCALLoader");
0964c2e9 881
59264fa6 882 //Define parameters
9946f2fe 883 Int_t nSuperModules = fGeom->GetNumberOfSuperModules() ; //12 SM in EMCAL
85c25c2e 884 Int_t nTRU = fGeom->GetNTRU(); // 3 TRU per super module
59264fa6 885
886 //Intialize data members each time the trigger is called in event loop
85c25c2e 887 f2x2MaxAmp = -1; f2x2ModulePhi = -1; f2x2ModuleEta = -1;
888 fnxnMaxAmp = -1; fnxnModulePhi = -1; fnxnModuleEta = -1;
59264fa6 889
85c25c2e 890 // Take the digits list if simulation
891 if(fSimulation && runLoader && emcalLoader){ // works than run seperate macros
c787fb51 892 runLoader->LoadDigits("EMCAL");
59264fa6 893 fDigitsList = emcalLoader->Digits() ;
85c25c2e 894 runLoader->LoadSDigits("EMCAL");
59264fa6 895 }
85c25c2e 896 // Digits list should be set by method SetDigitsList(TClonesArray * digits)
59264fa6 897 if(!fDigitsList)
898 AliFatal("Digits not found !") ;
899
900 //Take the digits list
901
85c25c2e 902 // Delete old if unzero
903 if(fAmpTrus) {fAmpTrus->Delete(); delete fAmpTrus;}
904 if(fTimeRtrus) {fTimeRtrus->Delete(); delete fTimeRtrus;}
905 if(fAmpSMods) {fAmpSMods->Delete(); delete fAmpSMods;}
906 // Fill TRU and SM matrix
907 fAmpTrus = new TClonesArray("TMatrixD",nTRU);
908 fAmpTrus->SetName("AmpTrus");
909 fTimeRtrus = new TClonesArray("TMatrixD",nTRU);
910 fTimeRtrus->SetName("TimeRtrus");
911 fAmpSMods = new TClonesArray("TMatrixD",nSuperModules);
912 fAmpSMods->SetName("AmpSMods");
0964c2e9 913
85c25c2e 914 FillTRU(fDigitsList, fAmpTrus, fAmpSMods, fTimeRtrus);
915
0293e426 916 // Jet stuff - only one case, no freedom here
85c25c2e 917 if(fGeom->GetNEtaSubOfTRU() == 6) {
918 if(fAmpJetMatrix) {delete fAmpJetMatrix; fAmpJetMatrix=0;}
919 if(fJetMatrixE) {delete fJetMatrixE; fJetMatrixE=0;}
920
921 fAmpJetMatrix = new TMatrixD(17,12); // 17-phi(row), 12-eta(col)
922 fJetMatrixE = new TH2F("fJetMatrixE"," E of max patch in (#phi,#eta)",
923 17, 80.*TMath::DegToRad(), (180.+20.*2/3.)*TMath::DegToRad(), 12, -0.7, 0.7);
924 for(Int_t row=0; row<fAmpJetMatrix->GetNrows(); row++) {
925 for(Int_t col=0; col<fAmpJetMatrix->GetNcols(); col++) {
926 (*fAmpJetMatrix)(row,col) = 0.;
927 }
928 }
929 FillJetMatrixFromSMs(fAmpSMods, fAmpJetMatrix, fGeom);
930 }
931 if(!CheckConsistentOfMatrixes()) assert(0);
59264fa6 932
85c25c2e 933 // Do Tower Sliding and select Trigger
934 // Initialize varible that will contain maximum amplitudes and
935 // its corresponding tower position in eta and phi, and time.
936 TMatrixD ampmax2(4,nTRU) ; // 0-max amp, 1-irow, 2-icol, 3-timeR
9946f2fe 937 TMatrixD ampmaxn(4,nTRU) ;
0964c2e9 938
33d0b833 939 for(Int_t iSM = 0 ; iSM < nSuperModules ; iSM++) {
0b2ec9f7 940 //Do 2x2 and nxn sums, select maximums.
85c25c2e 941
942 MakeSlidingTowers(fAmpTrus, fTimeRtrus, iSM, ampmax2, ampmaxn);
0964c2e9 943
85c25c2e 944 // Set the trigger
945 if(fIsolateInSuperModule) // here some discripency between tru and SM
946 SetTriggers(fAmpSMods,iSM,ampmax2,ampmaxn) ;
0964c2e9 947 if(!fIsolateInSuperModule)
85c25c2e 948 SetTriggers(fAmpTrus,iSM,ampmax2,ampmaxn) ;
59264fa6 949 }
0964c2e9 950
85c25c2e 951 // Do patch sliding and select Jet Trigger
952 // 0-max amp-meanFromVZERO(if), 1-irow, 2-icol, 3-timeR,
953 // 4-max amp , 5-meanFromVZERO (Nov 25, 2007)
954 // fAmpJetMax(6,1)
955 MakeSlidingPatch((*fAmpJetMatrix), fNJetPatchPhi, fAmpJetMax); // no timing information here
956
0964c2e9 957 //Print();
85c25c2e 958 // fDigitsList = 0;
959}
960
0293e426 961//____________________________________________________________________________
581ee158 962void AliEMCALTrigger::GetTriggerInfo(TArrayF &triggerPosition, TArrayF &triggerAmplitudes) const
85c25c2e 963{
964 // Template - should be defined; Nov 5, 2007
965 triggerPosition[0] = 0.;
966 triggerAmplitudes[0] = 0.;
967}
968
0293e426 969//____________________________________________________________________________
85c25c2e 970void AliEMCALTrigger::FillJetMatrixFromSMs(TClonesArray *ampmatrixsmod, TMatrixD* jetMat, AliEMCALGeometry *g)
971{
972 // Nov 5, 2007
973 // Fill matrix for jet trigger from SM matrixes of modules
974 //
975 static int keyPrint = 0;
976
977 if(ampmatrixsmod==0 || jetMat==0 || g==0) return;
978 Double_t amp = 0.0, ampSum=0.0;
0964c2e9 979
85c25c2e 980 Int_t nEtaModSum = g->GetNZ() / g->GetNEtaSubOfTRU(); // should be 4
981 Int_t nPhiModSum = g->GetNPhi() / g->GetNTRUPhi(); // should be 4
982
0293e426 983 if(keyPrint) AliDebug(2,Form("%s",Form(" AliEMCALTrigger::FillJetMatrixFromSMs | nEtaModSum %i : nPhiModSum %i \n", nEtaModSum, nPhiModSum)));
85c25c2e 984 Int_t jrow=0, jcol=0; // indexes of jet matrix
985 Int_t nEtaSM=0, nPhiSM=0;
986 for(Int_t iSM=0; iSM<ampmatrixsmod->GetEntries(); iSM++) {
987 TMatrixD * ampsmods = dynamic_cast<TMatrixD *>(ampmatrixsmod->At(iSM));
a51e676d 988
989 if(!ampsmods) return;
990
85c25c2e 991 Int_t nrow = ampsmods->GetNrows();
992 Int_t ncol = ampsmods->GetNcols();
993 //printf("%s",Form(" ######## SM %i : nrow %i : ncol %i ##### \n", iSM, nrow, ncol));
994 for(Int_t row=0; row<nrow; row++) {
995 for(Int_t col=0; col<ncol; col++) {
996 amp = (*ampsmods)(row,col);
997 nPhiSM = iSM / 2;
998 nEtaSM = iSM % 2;
999 if (amp>0.0) {
0293e426 1000 if(keyPrint) AliDebug(2,Form("%s",Form(" ** nPhiSm %i : nEtaSM %i : row %2.2i : col %2.2i -> ", nPhiSM, nEtaSM, row, col)));
85c25c2e 1001 if(nEtaSM == 0) { // positive Z
1002 jrow = 3*nPhiSM + row/nPhiModSum;
1003 jcol = 6 + col / nEtaModSum;
1004 } else { // negative Z
1005 if(iSM<=9) jrow = 3*nPhiSM + 2 - row/nPhiModSum;
1006 else jrow = 3*nPhiSM + 1 - row/nPhiModSum; // half size
1007 jcol = 5 - col / nEtaModSum;
1008 }
0293e426 1009 if(keyPrint) AliDebug(2,Form("%s",Form(" jrow %2.2i : jcol %2.2i : amp %f (jetMat) \n", jrow, jcol, amp)));
85c25c2e 1010
1011 (*jetMat)(jrow,jcol) += amp;
1012 ampSum += amp; // For controling
1013 } else if(amp<0.0) {
8b518399 1014 AliDebug(1,Form(" jrow %2.2i : jcol %2.2i : amp %f (jetMat: amp<0) \n", jrow, jcol, amp));
85c25c2e 1015 assert(0);
1016 }
1017 }
1018 }
1019 } // cycle on SM
29b7e56e 1020 if(ampSum <= 0.0) AliDebug(1,Form("ampSum %f (<=0.0) ", ampSum));
85c25c2e 1021}
1022
0293e426 1023//____________________________________________________________________________
85c25c2e 1024void AliEMCALTrigger::MakeSlidingPatch(const TMatrixD &jm, const Int_t nPatchSize, TMatrixD &ampJetMax)
1025{
1026 // Sliding patch : nPatchSize x nPatchSize (OVERLAP)
1027 static int keyPrint = 0;
0293e426 1028 if(keyPrint) AliDebug(2,Form(" AliEMCALTrigger::MakeSlidingPatch() was started \n"));
85c25c2e 1029 Double_t ampCur = 0.0, e=0.0;
1030 ampJetMax(0,0) = 0.0;
1031 ampJetMax(3,0) = 0.0; // unused now
1032 ampJetMax(4,0) = ampJetMax(5,0) = 0.0;
1033 for(Int_t row=0; row<fAmpJetMatrix->GetNrows(); row ++) {
1034 for(Int_t col=0; col<fAmpJetMatrix->GetNcols(); col++) {
1035 ampCur = 0.;
1036 // check on patch size
1037 if( (row+nPatchSize-1) < fAmpJetMatrix->GetNrows() && (col+nPatchSize-1) < fAmpJetMatrix->GetNcols()){
1038 for(Int_t i = 0 ; i < nPatchSize ; i++) {
1039 for(Int_t j = 0 ; j < nPatchSize ; j++) {
1040 ampCur += jm(row+i, col+j);
1041 }
1042 } // end cycle on patch
1043 if(ampCur > ampJetMax(0,0)){
1044 ampJetMax(0,0) = ampCur;
1045 ampJetMax(1,0) = row;
1046 ampJetMax(2,0) = col;
1047 }
1048 } // check on patch size
1049 }
1050 }
0293e426 1051 if(keyPrint) AliDebug(2,Form(" ampJetMax %i row %2i->%2i col %2i->%2i \n", Int_t(ampJetMax(0,0)), Int_t(ampJetMax(1,0)), Int_t(ampJetMax(1,0))+nPatchSize-1, Int_t(ampJetMax(2,0)), Int_t(ampJetMax(2,0))+nPatchSize-1));
85c25c2e 1052
1053 Double_t eCorrJetMatrix=0.0;
1054 if(fVZER0Mult > 0.0) {
1055 // Correct patch energy (adc) and jet patch matrix energy
1056 Double_t meanAmpBG = GetMeanEmcalPatchEnergy(Int_t(fVZER0Mult), nPatchSize)/0.0153;
1057 ampJetMax(4,0) = ampJetMax(0,0);
1058 ampJetMax(5,0) = meanAmpBG;
1059
1060 Double_t eCorr = ampJetMax(0,0) - meanAmpBG;
0293e426 1061 AliDebug(2,Form(" ampJetMax(0,0) %f meanAmpBG %f eCorr %f : ampJetMax(4,0) %f \n",
1062 ampJetMax(0,0), meanAmpBG, eCorr, ampJetMax(5,0)));
85c25c2e 1063 ampJetMax(0,0) = eCorr;
1064 // --
1065 eCorrJetMatrix = GetMeanEmcalEnergy(Int_t(fVZER0Mult)) / 208.;
1066 }
1067 // Fill patch energy matrix
1068 for(int row=Int_t(ampJetMax(1,0)); row<Int_t(ampJetMax(1,0))+nPatchSize; row++) {
1069 for(int col=Int_t(ampJetMax(2,0)); col<Int_t(ampJetMax(2,0))+nPatchSize; col++) {
1070 e = Double_t(jm(row,col)*0.0153); // 0.0153 - hard coded now
1071 if(eCorrJetMatrix > 0.0) { // BG subtraction case
1072 e -= eCorrJetMatrix;
1073 fJetMatrixE->SetBinContent(row+1, col+1, e);
1074 } else if(e > 0.0) {
1075 fJetMatrixE->SetBinContent(row+1, col+1, e);
1076 }
1077 }
1078 }
1079 // PrintJetMatrix();
1080 // Set the jet trigger(s), multiple threshold now, Nov 19,2007
1081 for(Int_t i=0; i<fNJetThreshold; i++ ) {
1082 if(ampJetMax(0,0) >= fL1JetThreshold[i]) {
7e42cd80 1083 SetInput(GetNameOfJetTrigger(i));
85c25c2e 1084 }
1085 }
1086}
1087
0293e426 1088//____________________________________________________________________________
85c25c2e 1089Double_t AliEMCALTrigger::GetEmcalSumAmp() const
1090{
1091 // Return sum of amplidutes from EMCal
1092 // Used calibration coefficeint for transition to energy
1093 return fAmpJetMatrix >0 ?fAmpJetMatrix->Sum() :0.0;
1094}
1095
0293e426 1096//____________________________________________________________________________
85c25c2e 1097void AliEMCALTrigger::PrintJetMatrix() const
1098{
1099 // fAmpJetMatrix : (17,12); // 17-phi(row), 12-eta(col)
1100 if(fAmpJetMatrix == 0) return;
1101
0293e426 1102 AliInfo(Form("\n #### jetMatrix : (%i,%i) ##### \n ",
1103 fAmpJetMatrix->GetNrows(), fAmpJetMatrix->GetNcols()));
85c25c2e 1104 PrintMatrix(*fAmpJetMatrix);
1105}
1106
0293e426 1107//____________________________________________________________________________
85c25c2e 1108void AliEMCALTrigger::PrintAmpTruMatrix(Int_t ind) const
1109{
581ee158 1110 // Print matrix with TRU patches
85c25c2e 1111 TMatrixD * tru = dynamic_cast<TMatrixD *>(fAmpTrus->At(ind));
1112 if(tru == 0) return;
0293e426 1113 AliInfo(Form("\n #### Amp TRU matrix(%i) : (%i,%i) ##### \n ",
1114 ind, tru->GetNrows(), tru->GetNcols()));
85c25c2e 1115 PrintMatrix(*tru);
1116}
1117
0293e426 1118//____________________________________________________________________________
85c25c2e 1119void AliEMCALTrigger::PrintAmpSmMatrix(Int_t ind) const
1120{
581ee158 1121 // Print matrix with SM amplitudes
1122 TMatrixD * sm = dynamic_cast<TMatrixD *>(fAmpSMods->At(ind));
85c25c2e 1123 if(sm == 0) return;
0293e426 1124 AliInfo(Form("\n #### Amp SM matrix(%i) : (%i,%i) ##### \n ",
1125 ind, sm->GetNrows(), sm->GetNcols()));
85c25c2e 1126 PrintMatrix(*sm);
1127}
1128
0293e426 1129//____________________________________________________________________________
85c25c2e 1130void AliEMCALTrigger::PrintMatrix(const TMatrixD &mat) const
1131{
581ee158 1132 //Print matrix object
0293e426 1133 for(Int_t col=0; col<mat.GetNcols(); col++) AliInfo(Form(" %3i ", col));
1134 AliInfo(Form("\n -- \n"));
85c25c2e 1135 for(Int_t row=0; row<mat.GetNrows(); row++) {
0293e426 1136 AliInfo(Form(" row:%2i ", row));
85c25c2e 1137 for(Int_t col=0; col<mat.GetNcols(); col++) {
0293e426 1138 AliInfo(Form(" %4i", (Int_t)mat(row,col)));
85c25c2e 1139 }
0293e426 1140 AliInfo("\n");
85c25c2e 1141 }
1142}
1143
0293e426 1144//____________________________________________________________________________
85c25c2e 1145Bool_t AliEMCALTrigger::CheckConsistentOfMatrixes(const Int_t pri)
1146{
581ee158 1147 // Check consitency of matrices
85c25c2e 1148 Double_t sumSM = 0.0, smCur=0.0;
1149 Double_t sumTru=0.0, sumTruInSM = 0.0, truSum=0.0;
1150 // Bool_t key = kTRUE;
1151
1152 for(Int_t i=0; i<fAmpSMods->GetEntries(); i++) {
1153 TMatrixD * sm = dynamic_cast<TMatrixD *>(fAmpSMods->At(i));
1154 if(sm) {
1155 smCur = sm->Sum();
1156 sumSM += smCur;
1157
1158 sumTruInSM = 0.0;
1159 for(Int_t itru=0; itru<3; itru++) { // Cycle on tru inside SM
1160 Int_t ind = 3*i + itru;
1161 TMatrixD *tru = dynamic_cast<TMatrixD *>(fAmpTrus->At(ind));
1162 if(tru) {
1163 truSum = tru->Sum();
1164 sumTruInSM += truSum;
1165 }
1166 }
1167 sumTru += sumTruInSM;
1168
1169 if(sumTruInSM != smCur) {
8b518399 1170 AliDebug(1,Form(" sm %i : smCur %f -> sumTruInSM %f \n", i, smCur, sumTruInSM));
85c25c2e 1171 return kFALSE;
1172 }
1173 }
1174 }
1175 Double_t sumJetMat = fAmpJetMatrix->Sum();
581ee158 1176 if(pri || TMath::Abs(sumSM-sumTru)>0.0001 || TMath::Abs(sumSM-sumJetMat) > 0.0001)
8b518399 1177 AliDebug(1,Form(" sumSM %f : sumTru %f : sumJetMat %f \n", sumSM, sumTru, sumJetMat));
581ee158 1178 if(TMath::Abs(sumSM - sumTru)>0.0001 || TMath::Abs(sumSM-sumJetMat) > 0.0001) return kFALSE;
85c25c2e 1179 else return kTRUE;
1180}
1181
0293e426 1182//____________________________________________________________________________
85c25c2e 1183void AliEMCALTrigger::Browse(TBrowser* b)
1184{
581ee158 1185 //Browse.
85c25c2e 1186 if(&fInputs) b->Add(&fInputs);
1187 if(fAmpTrus) b->Add(fAmpTrus);
1188 if(fTimeRtrus) b->Add(fTimeRtrus);
1189 if(fAmpSMods) b->Add(fAmpSMods);
1190 if(fAmpJetMatrix) b->Add(fAmpJetMatrix);
1191 if(fJetMatrixE) b->Add(fJetMatrixE);
1192 // if(c) b->Add(c);
f0377b23 1193}