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