1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //_________________________________________________________________________
19 // Class for trigger analysis.
20 // Digits are grouped in TRU's (Trigger Units). A TRU consist of 16x28
21 // crystals ordered fNTRUPhi x fNTRUZ. The algorithm searches all possible
22 // 4x4 crystal combinations per each TRU, adding the digits amplitude and
23 // finding the maximum. Maximums are transformed in ADC time samples.
24 // Each time bin is compared to the trigger threshold until it is larger
25 // and then, triggers are set. Thresholds need to be fixed.
28 // //Inside the event loop
29 // AliEMCALTrigger *tr = new AliEMCALTrigger();//Init Trigger
30 // tr->SetL0Threshold(100);
31 // tr->SetL1JetLowPtThreshold(1000);
32 // tr->SetL1JetHighPtThreshold(20000);
33 // tr->Trigger(); //Execute Trigger
34 // tr->Print(""); //Print result, with "deb" option all data members
37 //*-- Author: Gustavo Conesa & Yves Schutz (IFIC, CERN)
38 //////////////////////////////////////////////////////////////////////////////
41 // --- ROOT system ---
42 //#include "TMatrixD.h"
44 // --- ALIROOT system ---
46 #include "AliPHOSTrigger.h"
47 #include "AliPHOSGeometry.h"
48 #include "AliPHOSGetter.h"
49 #include "AliTriggerInput.h"
52 ClassImp(AliPHOSTrigger)
54 //______________________________________________________________________
55 AliPHOSTrigger::AliPHOSTrigger()
56 : AliTriggerDetector(),
57 f2x2MaxAmp(-1), f2x2CrystalPhi(-1), f2x2CrystalEta(-1),
58 f4x4MaxAmp(-1), f4x4CrystalPhi(-1), f4x4CrystalEta(-1),
59 fL0Threshold(50), fL1JetLowPtThreshold(200), fL1JetHighPtThreshold(500),
60 fNTRU(8), fNTRUZ(2), fNTRUPhi(4), fSimulation(kTRUE)
64 fADCValuesHigh4x4 = 0x0; //new Int_t[fTimeBins];
65 fADCValuesLow4x4 = 0x0; //new Int_t[fTimeBins];
66 fADCValuesHigh2x2 = 0x0; //new Int_t[fTimeBins];
67 fADCValuesLow2x2 = 0x0; //new Int_t[fTimeBins];
79 //____________________________________________________________________________
80 AliPHOSTrigger::AliPHOSTrigger(const AliPHOSTrigger & trig)
81 : AliTriggerDetector(trig)
86 f2x2MaxAmp = trig.f2x2MaxAmp ;
87 f4x4MaxAmp = trig.f4x4MaxAmp ;
88 f2x2CrystalPhi = trig.f2x2CrystalPhi ;
89 f4x4CrystalPhi = trig.f4x4CrystalPhi ;
90 f2x2CrystalEta = trig.f2x2CrystalEta ;
91 f4x4CrystalEta = trig.f4x4CrystalEta ;
92 fADCValuesHigh4x4 = trig.fADCValuesHigh4x4 ;
93 fADCValuesLow4x4 = trig.fADCValuesLow4x4 ;
94 fADCValuesHigh2x2 = trig.fADCValuesHigh2x2 ;
95 fADCValuesLow2x2 = trig.fADCValuesLow2x2 ;
96 fDigitsList = trig.fDigitsList ;
97 fL0Threshold = trig.fL0Threshold ;
98 fL1JetLowPtThreshold = trig.fL1JetLowPtThreshold ;
99 fL1JetHighPtThreshold = trig.fL1JetHighPtThreshold ;
101 fNTRUZ = trig.fNTRUZ ;
102 fNTRUPhi = trig.fNTRUPhi ;
103 fSimulation = trig.fSimulation ;
107 //_________________________________________________________________________
108 void AliPHOSTrigger::CreateInputs()
112 // Do not create inputs again!!
113 if( fInputs.GetEntriesFast() > 0 ) return;
115 fInputs.AddLast( new AliTriggerInput( "PHOS_L0", "PHOS L0", 0x02 ) );
116 fInputs.AddLast( new AliTriggerInput( "PHOS_JetHPt_L1","PHOS Jet High Pt L1", 0x04 ) );
117 fInputs.AddLast( new AliTriggerInput( "PHOS_JetLPt_L1","PHOS Jet Low Pt L1", 0x08 ) );
121 //____________________________________________________________________________
122 void AliPHOSTrigger::FillTRU(const TClonesArray * digits, const AliPHOSGeometry * geom, TClonesArray * ampmatrix, TClonesArray * timeRmatrix) const {
124 //Orders digits ampitudes list and times in fNTRU TRUs (28x16 crystals)
125 //per module. Each TRU is a TMatrixD, and they are kept in TClonesArrays.
126 //In a module, the number of TRU in phi is fNTRUPhi, and the number of
127 //TRU in eta is fNTRUZ.
131 if(fNTRUZ*fNTRUPhi != fNTRU)
132 Error("FillTRU"," Wrong number of TRUS per Z or Phi");
134 //Initilize and declare variables
135 Int_t nModules = geom->GetNModules();
136 Int_t nCrystalsPhi = geom->GetNPhi()/fNTRUPhi ;// 64/4=16
137 Int_t nCrystalsZ = geom->GetNZ()/fNTRUZ ;// 56/2=28
143 //List of TRU matrices initialized to 0.
144 for(Int_t k = 0; k < fNTRU*nModules ; k++){
145 TMatrixD * amptrus = new TMatrixD(nCrystalsPhi,nCrystalsZ) ;
146 TMatrixD * timeRtrus = new TMatrixD(nCrystalsPhi,nCrystalsZ) ;
147 for(Int_t i = 0; i < nCrystalsPhi; i++){
148 for(Int_t j = 0; j < nCrystalsZ; j++){
149 (*amptrus)(i,j) = 0.0;
150 (*timeRtrus)(i,j) = 0.0;
153 new((*ampmatrix)[k]) TMatrixD(*amptrus) ;
154 new((*timeRmatrix)[k]) TMatrixD(*timeRtrus) ;
159 //Digits loop to fill TRU matrices with amplitudes.
161 for(Int_t idig = 0 ; idig < digits->GetEntriesFast() ; idig++){
163 dig = static_cast<AliPHOSDigit *>(digits->At(idig)) ;
164 amp = dig->GetAmp() ; // Energy of the digit (arbitrary units)
165 id = dig->GetId() ; // Id label of the cell
166 timeR = dig->GetTimeR() ; // Earliest time of the digit
167 geom->AbsToRelNumbering(id, relid) ;
168 //Transform digit number into 4 numbers
170 //relid[1] = EMC (0) or CPV (-1)
171 //relid[2] = row <= 64 (fNPhi)
172 //relid[3] = column <= 56 (fNZ)
174 if(relid[1] == 0){//Not CPV, Only EMC digits
176 //Check to which TRU in the supermodule belongs the crystal.
177 //Supermodules are divided in a TRU matrix of dimension
179 //Each TRU is a crystal matrix of dimension (nCrystalsPhi,nCrystalsZ)
181 //First calculate the row and column in the supermodule
182 //of the TRU to which the crystal belongs.
183 Int_t col = (relid[3]-1)/nCrystalsZ+1;
184 Int_t row = (relid[2]-1)/nCrystalsPhi+1;
186 //Calculate label number of the TRU
187 Int_t itru = (row-1) + (col-1)*fNTRUPhi + (relid[0]-1)*fNTRU ;
189 //Fill TRU matrix with crystal values
190 TMatrixD * amptrus = dynamic_cast<TMatrixD *>(ampmatrix->At(itru)) ;
191 TMatrixD * timeRtrus = dynamic_cast<TMatrixD *>(timeRmatrix->At(itru)) ;
193 //Calculate row and column of the crystal inside the TRU with number itru
194 Int_t irow = (relid[2]-1) - (row-1) * nCrystalsPhi;
195 Int_t icol = (relid[3]-1) - (col-1) * nCrystalsZ;
197 (*amptrus)(irow,icol) = amp ;
198 (*timeRtrus)(irow,icol) = timeR ;
203 //______________________________________________________________________
204 void AliPHOSTrigger::GetCrystalPhiEtaIndexInModuleFromTRUIndex(const Int_t itru,const Int_t iphitru,const Int_t ietatru,Int_t &iphiMod,Int_t &ietaMod,const AliPHOSGeometry* geom) const
206 // This method transforms the (eta,phi) index of a crystals in a
207 // TRU matrix into Super Module (eta,phi) index.
209 // Calculate in which row and column in which the TRU are
211 Int_t col = itru/ fNTRUPhi + 1;
212 Int_t row = itru - (col-1)*fNTRUPhi + 1;
214 //Calculate the (eta,phi) index in SM
215 Int_t nCrystalsPhi = geom->GetNPhi()/fNTRUPhi;
216 Int_t nCrystalsZ = geom->GetNZ()/fNTRUZ;
218 iphiMod = nCrystalsPhi*(row-1) + iphitru + 1 ;
219 ietaMod = nCrystalsZ*(col-1) + ietatru + 1 ;
222 //____________________________________________________________________________
223 void AliPHOSTrigger::MakeSlidingCell(const TClonesArray * amptrus, const TClonesArray * timeRtrus, const Int_t imod, TMatrixD *ampmax2, TMatrixD *ampmax4, const AliPHOSGeometry *geom){
224 //Sums energy of all possible 2x2 (L0) and 4x4 (L1) crystals per each TRU.
225 //Fast signal in the experiment is given by 2x2 crystals,
226 //for this reason we loop inside the TRU crystals by 2.
228 //Declare and initialize varibles
229 Int_t nCrystalsPhi = geom->GetNPhi()/fNTRUPhi ;// 64/4=16
230 Int_t nCrystalsZ = geom->GetNZ()/fNTRUZ ;// 56/2=28
233 for(Int_t i = 0; i < 3; i++){
234 for(Int_t j = 0; j < fNTRU; j++){
235 (*ampmax2)(i,j) = -1;
236 (*ampmax4)(i,j) = -1;
240 //Create matrix that will contain 2x2 amplitude sums
241 //used to calculate the 4x4 sums
242 TMatrixD * tru2x2 = new TMatrixD(nCrystalsPhi/2,nCrystalsZ/2) ;
244 for(Int_t i = 0; i < nCrystalsPhi/2; i++)
245 for(Int_t j = 0; j < nCrystalsZ/2; j++)
246 (*tru2x2)(i,j) = 0.0;
248 //Loop over all TRUS in a module
249 for(Int_t itru = 0 + (imod - 1) * fNTRU ; itru < imod*fNTRU ; itru++){
250 TMatrixD * amptru = dynamic_cast<TMatrixD *>(amptrus->At(itru)) ;
251 TMatrixD * timeRtru = dynamic_cast<TMatrixD *>(timeRtrus->At(itru)) ;
252 Int_t mtru = itru-(imod-1)*fNTRU ; //Number of TRU in Module
254 //Sliding 2x2, add 2x2 amplitudes (NOT OVERLAP)
255 for(Int_t irow = 0 ; irow < nCrystalsPhi; irow += 2){
256 for(Int_t icol = 0 ; icol < nCrystalsZ ; icol += 2){
257 amp2 = (*amptru)(irow,icol)+(*amptru)(irow+1,icol)+
258 (*amptru)(irow,icol+1)+(*amptru)(irow+1,icol+1);
259 //Fill new matrix with added 2x2 crystals for use in 4x4 sums
260 (*tru2x2)(irow/2,icol/2) = amp2 ;
261 //Select 2x2 maximum sums to select L0
262 if(amp2 > (*ampmax2)(0,mtru)){
263 (*ampmax2)(0,mtru) = amp2 ;
264 (*ampmax2)(1,mtru) = irow;
265 (*ampmax2)(2,mtru) = icol;
270 //Find most recent time in the selected 2x2 cell
271 (*ampmax2)(3,mtru) = 1 ;
272 Int_t row2 = static_cast <Int_t> ((*ampmax2)(1,mtru));
273 Int_t col2 = static_cast <Int_t> ((*ampmax2)(2,mtru));
274 for(Int_t i = 0; i<2; i++){
275 for(Int_t j = 0; j<2; j++){
276 if((*amptru)(row2+i,col2+j) > 0 && (*timeRtru)(row2+i,col2+j)> 0){
277 if((*timeRtru)(row2+i,col2+j) < (*ampmax2)(3,mtru) )
278 (*ampmax2)(3,mtru) = (*timeRtru)(row2+i,col2+j);
283 //Sliding 4x4, add 4x4 amplitudes (OVERLAP)
284 for(Int_t irow = 0 ; irow < nCrystalsPhi/2; irow++){
285 for(Int_t icol = 0 ; icol < nCrystalsZ/2 ; icol++){
286 if( (irow+1) < nCrystalsPhi/2 && (icol+1) < nCrystalsZ/2){//Avoid exit the TRU
287 amp4 = (*tru2x2)(irow,icol)+(*tru2x2)(irow+1,icol)+
288 (*tru2x2)(irow,icol+1)+(*tru2x2)(irow+1,icol+1);
289 //Select 4x4 maximum sums to select L1
290 if(amp4 > (*ampmax4)(0,mtru)){
291 (*ampmax4)(0,mtru) = amp4 ;
292 (*ampmax4)(1,mtru) = irow*2;
293 (*ampmax4)(2,mtru) = icol*2;
299 //Find most recent time in selected 4x4 cell
300 (*ampmax4)(3,mtru) = 1 ;
301 Int_t row4 = static_cast <Int_t> ((*ampmax4)(1,mtru));
302 Int_t col4 = static_cast <Int_t> ((*ampmax4)(2,mtru));
303 for(Int_t i = 0; i<4; i++){
304 for(Int_t j = 0; j<4; j++){
305 if((*amptru)(row4+i,col4+j) > 0 && (*timeRtru)(row4+i,col4+j)> 0){
306 if((*timeRtru)(row4+i,col4+j) < (*ampmax4)(3,mtru) )
307 (*ampmax4)(3,mtru) = (*timeRtru)(row4+i,col4+j);
314 //____________________________________________________________________________
315 void AliPHOSTrigger::Print(const Option_t * opt) const
318 //Prints main parameters
322 AliTriggerInput* in = 0x0 ;
324 printf( " Maximum Amplitude after Sliding Crystal, \n") ;
325 printf( " -2x2 crystals sum (not overlapped): %10.2f, in Super Module %d\n",
327 printf( " -2x2 from row %d to row %d and from column %d to column %d\n", f2x2CrystalPhi, f2x2CrystalPhi+2, f2x2CrystalEta, f2x2CrystalEta+2) ;
328 printf( " -4x4 crystals sum (overlapped) : %10.2f, in Super Module %d\n",
330 printf( " -4x4 from row %d to row %d and from column %d to column %d\n", f4x4CrystalPhi, f4x4CrystalPhi+4, f4x4CrystalEta, f4x4CrystalEta+4) ;
331 printf( " Threshold for LO %10.1f\n",
334 printf( " Threshold for LO %10.2f\n", fL0Threshold) ;
335 in = (AliTriggerInput*)fInputs.FindObject( "PHOS_L0" );
337 printf( " *** PHOS LO is set ***\n") ;
339 printf( " Jet Low Pt Threshold for L1 %10.2f\n", fL1JetLowPtThreshold) ;
340 in = (AliTriggerInput*)fInputs.FindObject( "PHOS_JetLPt_L1" );
342 printf( " *** PHOS Jet Low Pt for L1 is set ***\n") ;
344 printf( " Jet High Pt Threshold for L1 %10.2f\n", fL1JetHighPtThreshold) ;
345 in = (AliTriggerInput*) fInputs.FindObject( "PHOS_JetHPt_L1" );
347 printf( " *** PHOS Jet High Pt for L1 is set ***\n") ;
351 //____________________________________________________________________________
352 void AliPHOSTrigger::SetTriggers(const Int_t iMod, const TMatrixD * ampmax2, const TMatrixD * ampmax4, const AliPHOSGeometry *geom)
354 //Checks the 2x2 and 4x4 maximum amplitude per each TRU and compares
355 //with the different L0 and L1 triggers thresholds
357 //Initialize variables
358 Float_t max2[] = {-1,-1,-1,-1} ;
359 Float_t max4[] = {-1,-1,-1,-1} ;
364 //Find maximum summed amplitude of all the TRU
366 for(Int_t i = 0 ; i < fNTRU ; i++){
367 if(max2[0] < (*ampmax2)(0,i) ){
368 max2[0] = (*ampmax2)(0,i) ; // 2x2 summed max amplitude
369 max2[1] = (*ampmax2)(1,i) ; // corresponding phi position in TRU
370 max2[2] = (*ampmax2)(2,i) ; // corresponding eta position in TRU
371 max2[3] = (*ampmax2)(3,i) ; // corresponding most recent time
372 itru2 = i ; // TRU number
374 if(max4[4] < (*ampmax4)(0,i) ){
375 max4[0] = (*ampmax4)(0,i) ; // 4x4 summed max amplitude
376 max4[1] = (*ampmax4)(1,i) ; // corresponding phi position in TRU
377 max4[2] = (*ampmax4)(2,i) ; // corresponding eta position in TRU
378 max4[3] = (*ampmax4)(3,i) ; // corresponding most recent time
379 itru4 = i ; // TRU number
383 //Set max amplitude if larger than in other Modules
384 Float_t maxtimeR2 = -1 ;
385 Float_t maxtimeR4 = -1 ;
386 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
387 AliPHOS * phos = gime->PHOS();
388 Int_t nTimeBins = phos->GetRawFormatTimeBins() ;
390 //Set max 2x2 amplitude and select L0 trigger
391 if(max2[0] > f2x2MaxAmp ){
392 f2x2MaxAmp = max2[0] ;
394 maxtimeR2 = max2[3] ;
395 GetCrystalPhiEtaIndexInModuleFromTRUIndex(itru2,static_cast<Int_t>(max2[1]),static_cast<Int_t>(max2[2]),f2x2CrystalPhi,f2x2CrystalEta,geom) ;
397 //Transform digit amplitude in Raw Samples
398 fADCValuesLow2x2 = new Int_t[nTimeBins];
399 fADCValuesHigh2x2 = new Int_t[nTimeBins];
401 phos->RawSampledResponse(maxtimeR2, f2x2MaxAmp, fADCValuesHigh2x2, fADCValuesLow2x2) ;
403 //Set Trigger Inputs, compare ADC time bins until threshold is attained
405 for(Int_t i = 0 ; i < nTimeBins ; i++){
406 if(fADCValuesHigh2x2[i] >= fL0Threshold || fADCValuesLow2x2[i] >= fL0Threshold){
407 SetInput("PHOS_L0") ;
411 // for(Int_t i = 0 ; i < 256 ; i++)
412 // if(fADCValuesLow2x2[i]!=0||fADCValuesHigh2x2[i]!=0)
413 // cout<< "2x2 Time Bin "<<i
414 // <<"; 2x2 Low Gain "<<fADCValuesLow2x2[i]
415 // <<"; 2x2 High Gain "<<fADCValuesHigh2x2[i]<<endl;
418 //Set max 4x4 amplitude and select L1 triggers
419 if(max4[0] > f4x4MaxAmp ){
420 f4x4MaxAmp = max4[0] ;
422 maxtimeR4 = max4[3] ;
423 GetCrystalPhiEtaIndexInModuleFromTRUIndex(itru4,static_cast<Int_t>(max4[1]),static_cast<Int_t>(max4[2]),f4x4CrystalPhi,f4x4CrystalEta,geom) ;
425 //Transform digit amplitude in Raw Samples
426 fADCValuesHigh4x4 = new Int_t[nTimeBins];
427 fADCValuesLow4x4 = new Int_t[nTimeBins];
428 phos->RawSampledResponse(maxtimeR4, f4x4MaxAmp, fADCValuesHigh4x4, fADCValuesLow4x4) ;
430 //Set Trigger Inputs, compare ADC time bins until threshold is attained
432 for(Int_t i = 0 ; i < nTimeBins ; i++){
433 if(fADCValuesHigh4x4[i] >= fL1JetLowPtThreshold || fADCValuesLow4x4[i] >= fL1JetLowPtThreshold){
434 SetInput("PHOS_JetLPt_L1") ;
439 for(Int_t i = 0 ; i < nTimeBins ; i++){
440 if(fADCValuesHigh4x4[i] >= fL1JetHighPtThreshold || fADCValuesLow4x4[i] >= fL1JetHighPtThreshold){
441 SetInput("PHOS_JetHPt_L1") ;
445 // for(Int_t i = 0 ; i < 256 ; i++)
446 // if(fADCValuesLow4x4[i]!=0||fADCValuesHigh4x4[i]!=0)
447 // cout<< "4x4 Time Bin "<<i
448 // <<"; 4x4 Low Gain "<<fADCValuesLow4x4[i]
449 // <<"; 4x4 High Gain "<<fADCValuesHigh4x4[i]<<endl;
453 //____________________________________________________________________________
454 void AliPHOSTrigger::Trigger()
457 //Main Method to select triggers.
458 AliRunLoader *rl = gAlice->GetRunLoader();
460 AliPHOSGetter * gime = AliPHOSGetter::Instance( rl->GetFileName() ) ;
461 //AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
464 const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
467 Int_t nModules = geom->GetNModules();
469 //Intialize data members each time the trigger is called in event loop
470 f2x2MaxAmp = -1; f2x2CrystalPhi = -1; f2x2CrystalEta = -1;
471 f4x4MaxAmp = -1; f4x4CrystalPhi = -1; f4x4CrystalEta = -1;
473 //Take the digits list if simulation
475 fDigitsList = gime->Digits() ;
478 AliFatal("Digits not found !") ;
481 TClonesArray * amptrus = new TClonesArray("TMatrixD",1000);
482 TClonesArray * timeRtrus = new TClonesArray("TMatrixD",1000);
483 FillTRU(fDigitsList,geom,amptrus, timeRtrus) ;
485 //Do Crystal Sliding and select Trigger
486 //Initialize varible that will contain maximum amplitudes and
487 //its corresponding cell position in eta and phi, and time.
488 TMatrixD * ampmax2 = new TMatrixD(4,fNTRU) ;
489 TMatrixD * ampmax4 = new TMatrixD(4,fNTRU) ;
491 for(Int_t imod = 1 ; imod <= nModules ; imod++) {
492 //Do 2x2 and 4x4 sums, select maximums.
493 MakeSlidingCell(amptrus, timeRtrus, imod, ampmax2, ampmax4, geom);
495 SetTriggers(imod,ampmax2,ampmax4, geom) ;