]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSTrigger.cxx
fixed bug in AliSTARTTrigger
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrigger.cxx
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$ */
16
17
18 //_________________________________________________________________________  
19 //
20 //  Class for trigger analysis.
21 //  Digits are grouped in TRU's (16x28 crystals ordered fNTRUPhi x fNTRUZ). 
22 //  The algorithm searches all possible 4x4 cell combinations per each TRU, 
23 //  adding the digits amplitude and finding the maximum. Maximums are compared 
24 //  to triggers threshold and they are set. Thresholds need to be fixed. 
25 //  Usage:
26 //
27 //  //Inside the event loop
28 //  AliEMCALTrigger *tr = new AliEMCALTrigger();//Init Trigger
29 //  tr->SetL0MBPbPbThreshold(500);
30 //  tr->SetL0MBppThreshold(100);
31 //  tr->SetL1JetLowPtThreshold(1000);
32 //  tr->SetL1JetMediumPtThreshold(10000);
33 //  tr->SetL1JetHighPtThreshold(20000);
34 //  tr->Trigger(); //Execute Trigger
35 //  tr->Print(""); //Print result, with "deb" option all data members 
36 //  //are printed
37 //
38 //*-- Author: Gustavo Conesa & Yves Schutz (IFIC, CERN) 
39 //////////////////////////////////////////////////////////////////////////////
40
41
42 // --- ROOT system ---
43 #include "TMatrixD.h"
44
45 // --- ALIROOT system ---
46 #include "AliPHOSTrigger.h" 
47 #include "AliPHOSGeometry.h"
48 #include "AliPHOSGetter.h" 
49 #include "AliTriggerInput.h"
50
51
52 ClassImp(AliPHOSTrigger)
53
54 //______________________________________________________________________
55 AliPHOSTrigger::AliPHOSTrigger()
56   : AliTriggerDetector(), fNTRU(8), fNTRUZ(2), fNTRUPhi(4), 
57     fL0MBPbPbThreshold(500), fL0MBppThreshold(50), 
58     fL1JetLowPtThreshold(1200), fL1JetHighPtThreshold(30000) 
59 {
60   //ctor
61
62    SetName("PHOS");
63    CreateInputs();
64    
65    //Print("all") ; 
66 }
67
68
69
70 //____________________________________________________________________________
71 AliPHOSTrigger::AliPHOSTrigger(const AliPHOSTrigger & trig) 
72   : AliTriggerDetector(trig) 
73 {
74
75   // cpy ctor
76   fNTRU                 = trig.fNTRU ; 
77   fNTRUZ                = trig.fNTRUZ ; 
78   fNTRUPhi              = trig.fNTRUPhi ; 
79   fL0MBPbPbThreshold    = trig.fL0MBPbPbThreshold ; 
80   fL0MBppThreshold      = trig.fL0MBppThreshold ; 
81   fL1JetLowPtThreshold  = trig.fL1JetLowPtThreshold ;
82   fL1JetHighPtThreshold = trig.fL1JetHighPtThreshold ;
83
84 }
85
86 //----------------------------------------------------------------------
87 void AliPHOSTrigger::CreateInputs()
88 {
89    // inputs 
90    
91    // Do not create inputs again!!
92    if( fInputs.GetEntriesFast() > 0 ) return;
93    
94    fInputs.AddLast( new AliTriggerInput( "PHOS_MB_PbPb_L0", "PHOS PbPb Minimum Bias L0",  0x01 ) );
95    fInputs.AddLast( new AliTriggerInput( "PHOS_MB_pp_L0", "PHOS pp Minimum Bias L0",  0x02 ) );
96    fInputs.AddLast( new AliTriggerInput( "PHOS_PbPb_JetHPt_L1", "PHOS PbPb Jet High Pt L1", 0x04 ) );
97    fInputs.AddLast( new AliTriggerInput( "PHOS_PbPb_JetLPt_L1", "PHOS PbPb Jet Low Pt L1", 0x08 ) );
98  
99 }
100
101 //____________________________________________________________________________
102 TClonesArray *  AliPHOSTrigger::FillTRU(const TClonesArray * digits,
103                                         const AliPHOSGeometry * geom,
104                                         const Int_t nModules, 
105                                         const Int_t nCrystalsPhi, 
106                                         const Int_t nCrystalsZ) const {
107
108   //Orders digits ampitudes list in fNTRU TRUs (28x16 crystals) per module. 
109   //Each TRU is a TMatrixD, and they are kept in TClonesArrays. The number of 
110   //TRU in phi is fNTRUPhi, and the number of TRU in eta is fNTRUZ. 
111
112   //Check data members
113   
114   if(fNTRUZ*fNTRUPhi != fNTRU)
115     Error("FillTRU"," Wrong number of TRUS per Z or Phi");
116
117   //Initilize variables
118   //List of TRU matrices initialized to 0.
119
120   TClonesArray * matrix = new TClonesArray("TMatrixD",1000);
121   for(Int_t k = 0; k < fNTRU*nModules ; k++){
122     TMatrixD  * trus = new TMatrixD(nCrystalsPhi,nCrystalsZ) ;
123     for(Int_t i = 0; i < nCrystalsPhi; i++)
124       for(Int_t j = 0; j < nCrystalsZ; j++)
125         (*trus)(i,j) = 0.0;
126     new((*matrix)[k]) TMatrixD(*trus) ;
127   }
128   
129   AliPHOSDigit * dig ;
130   
131   //Declare variables
132   Int_t relid[4] ; 
133   Float_t amp = 0;
134
135   //Digits loop to fill TRU matrices with amplitudes.
136
137   for(Int_t idig = 0 ; idig < digits->GetEntriesFast() ; idig++){
138     
139     dig = static_cast<AliPHOSDigit *>(digits->At(idig)) ;
140     amp = dig->GetAmp() ; //Energy of the digit (arbitrary units)           
141     geom->AbsToRelNumbering(dig->GetId(), relid) ;
142     //Transform digit number into 4 numbers
143     //relid[0] = module
144     //relid[1] = EMC (0) or CPV (-1)
145     //relid[2] = row <= 64 (fNPhi)
146     //relid[3] = column <= 56 (fNZ)
147     
148     if(relid[1] == 0){//Not CPV, Only EMC digits
149      
150       //Check to which TRU in the supermodule belongs the cell. 
151       //Supermodules are divided in a TRU matrix of dimension 
152       //(fNTRUPhi,fNTRUZ).
153       //Each TRU is a cell matrix of dimension (nCrystalsPhi,nCrystalsZ)
154       
155       //First calculate the row and column in the supermodule 
156       //of the TRU to which the cell belongs.
157
158       Int_t col   = (relid[3]-1)/nCrystalsZ+1; 
159       Int_t row   = (relid[2]-1)/nCrystalsPhi+1; 
160       Int_t itru  = col*row + (relid[0]-1)*fNTRU - 1;
161
162       //Fill TRU matrix with cell values
163
164       TMatrixD * trus = dynamic_cast<TMatrixD *>(matrix->At(itru)) ;
165
166     //Calculate row and column of the cell inside the TRU with number itru
167
168       Int_t nrow = (relid[2]-1) - (row-1) *  nCrystalsPhi;      
169       Int_t ncol = (relid[3]-1) - (col-1) *  nCrystalsZ;
170      
171       (*trus)(nrow,ncol) = amp ;
172     }
173   }
174   return matrix;
175 }
176
177 //____________________________________________________________________________
178 void AliPHOSTrigger::MakeSlidingCell(const TClonesArray * trus, 
179                                      const Int_t mod,  
180                                      const Int_t nCrystalsPhi,
181                                      const Int_t nCrystalsZ,
182                                      Float_t *ampmax){
183
184   //Sums energy of all possible 4x4 crystals per each TRU. Fast signal 
185   //in the experiment is given by 2x2 crystals, for this reason we loop 
186   //inside the TRU crystals by 2. 
187  
188   Float_t amp = 0 ;
189
190   for(Int_t i = 0 ; i < fNTRU ; i++)   
191     ampmax[i] = 0 ;
192
193   //Loop over all TRUS in a module
194   for(Int_t itru = 0 + (mod - 1) * fNTRU ; itru < mod*fNTRU ; itru++){
195     TMatrixD * tru = dynamic_cast<TMatrixD *>(trus->At(itru)) ;
196     //Sliding 2x2 cell
197     //ampmax[itru-(mod-1)*8]=0.0;       
198     for(Int_t irow = 0 ; irow <  nCrystalsPhi; irow += 2){ 
199       for(Int_t icol = 0 ; icol < nCrystalsZ ; icol += 2){
200         amp = 0;
201         if( (irow+3) < nCrystalsPhi && (icol+3) < nCrystalsZ){//Avoid exit the TRU
202           for(Int_t i = irow; i < irow + 4 ; i++){
203             for(Int_t j = icol; j < icol + 4 ; j++){
204               amp += (*tru)(i,j) ;
205             }
206           }
207         }
208         if(amp > ampmax[itru-(mod-1)*fNTRU])
209           ampmax[itru-(mod-1)*fNTRU] = amp ;
210       }
211     }
212   }
213 }
214
215 //____________________________________________________________________________
216 void AliPHOSTrigger::Trigger() 
217 {
218
219   //Main Method to select triggers.
220   //Getter
221   AliPHOSGetter * gime = AliPHOSGetter::Instance() ; 
222  
223   //Get Geometry
224   const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
225
226   //Define some useful parameters
227   Int_t nModules     = geom->GetNModules();
228   Int_t nCrystalsPhi = geom->GetNPhi()/fNTRUPhi ;// 64/4=16
229   Int_t nCrystalsZ   = geom->GetNZ()/fNTRUZ ;// 56/2=28
230
231   //Take the digits list and declare digits pointers
232   TClonesArray * digits = gime->Digits() ;
233
234   //Fill TRU Matrix  
235   TClonesArray * trus = FillTRU(digits,geom, nModules, nCrystalsPhi, 
236                                 nCrystalsZ) ;
237
238   //Do Cell Sliding and select Trigger
239   Float_t max [8] ;
240   for(Int_t imod = 1 ; imod <= nModules ; imod++) {
241     MakeSlidingCell(trus, imod, nCrystalsPhi, nCrystalsZ, max);
242 //     cout<<" Max Amplitude: mod " << imod <<" TRU0 " << max[0] 
243 //      <<" TRU1 " << max[1] <<" TRU2 " << max[2] <<" TRU3 " << max[3]
244 //      <<" TRU4 " << max[4] <<" TRU5 " << max[5] <<" TRU6 " << max[6]
245 //      <<" TRU7 " << max[7] <<endl;
246   
247     SetTriggers(max) ;
248   }
249   
250 }
251
252 //____________________________________________________________________________
253 void AliPHOSTrigger::Print(const Option_t * opt) const 
254 {
255
256   //Prints main parameters
257  
258   if(! opt)
259     return;
260   AliTriggerInput* in = 0x0 ;
261
262   AliInfo("PHOS trigger information:") ; 
263   printf( "             Threshold for pp MB LO %d\n", fL0MBppThreshold) ;  
264   in = (AliTriggerInput*)fInputs.FindObject( "PHOS_MB_pp_L0" );
265   if(in->GetValue())
266     printf( "             *** PHOS MB pp LO is set ***\n") ; 
267
268   printf( "             Threshold for PbPb MB LO %d\n", fL0MBPbPbThreshold) ;  
269   in = (AliTriggerInput*)fInputs.FindObject( "PHOS_MB_PbPb_L0" );
270   if(in->GetValue())
271     printf( "             *** PHOS MB PbPb LO is set ***\n") ; 
272   
273   printf( "             Jet Low Pt Threshold for PbPb L1 %d\n", fL1JetLowPtThreshold) ;
274   in = (AliTriggerInput*)fInputs.FindObject( "PHOS_PbPb_JetLPt_L1" );
275   if(in->GetValue())
276     printf( "             *** PHOS Jet Low Pt for PbPb L1 is set ***\n") ;
277
278   printf( "             Jet High Pt Threshold for L1 %d\n", fL1JetHighPtThreshold) ;  
279   in = (AliTriggerInput*) fInputs.FindObject( "PHOS_PbPb_JetHPt_L1" );
280   if(in->GetValue())
281     printf( "             *** PHOS Jet High Pt for PbPb L1 is set ***\n") ;
282
283   if(strstr(opt,"all")){
284     printf( "                         Number of TRUs %d\n", fNTRU) ;
285     printf( "                         Number of crystals in Z in TRUs %d\n", 
286             fNTRUZ) ;
287     printf( "                         Number of crystals in Phi in TRUs %d\n", 
288             fNTRUPhi) ;
289   }   
290 }
291
292 //____________________________________________________________________________
293 void AliPHOSTrigger::SetTriggers(const Float_t * amp)  
294 {
295
296   //Checks the maximum amplitude per each TRU and compares with the 
297   //different triggers thresholds
298
299   Float_t max = 0;
300   for(Int_t i = 0 ; i < 8 ; i++){
301     if(max < amp[i] )
302       max = amp[i] ;
303   }
304  
305   if(max >= fL0MBppThreshold)
306     SetInput("PHOS_MB_pp_L0");
307   if(max >= fL0MBPbPbThreshold)
308     SetInput("PHOS_MB_PbPb_L0");
309   if(max >= fL1JetLowPtThreshold)
310     SetInput("PHOS_PbPb_JetLPt_L1"); 
311   if(max >= fL1JetHighPtThreshold)
312     SetInput("PHOS_PbPb_JetHPt_L1");
313   
314 }