]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliRecoParam.cxx
Introducing event specie in QA (Yves)
[u/mrichter/AliRoot.git] / STEER / AliRecoParam.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
16
17 ///////////////////////////////////////////////////////////////////////////////
18 //                                                                           //
19 // ALICE Reconstruction parameterization:                                    //
20 //                                                                           //
21 //                                                                           //
22 // Base Class for Detector reconstruction parameters                         //
23 // Revision: cvetan.cheshkov@cern.ch 12/06/2008                              //
24 // Its structure has been revised and it is interfaced to AliEventInfo.      //
25 //                                                                           //
26 ///////////////////////////////////////////////////////////////////////////////
27
28 #include "TObjArray.h"
29 #include "TMath.h"
30 #include "AliDetectorRecoParam.h"
31
32 #include "AliLog.h"
33 #include "AliRecoParam.h"
34 #include "AliRunInfo.h"
35 #include "AliEventInfo.h"
36
37 ClassImp(AliRecoParam)
38
39 TString AliRecoParam::fkgEventSpecieName[] = {"Default", "LowMultiplicity", "HighMultiplicity", "Cosmic", "Calibration", "Unknown"} ; 
40
41 AliRecoParam::AliRecoParam(): 
42   TObject(),
43   fEventSpecie(kDefault)
44 {
45   // Default constructor
46   // ...
47   for(Int_t iDet = 0; iDet < kNDetectors; iDet++)
48     fDetRecoParams[iDet] = NULL;
49   for(Int_t iSpecie = 0; iSpecie < kNSpecies; iSpecie++) {
50     for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
51       fDetRecoParamsIndex[iSpecie][iDet] = -1;
52     }
53   }
54 }
55
56 AliRecoParam::AliRecoParam(const AliRecoParam& par) :
57   TObject(),
58   fEventSpecie(par.fEventSpecie)
59 {
60   // copy constructor
61   for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
62     if (par.fDetRecoParams[iDet])
63       fDetRecoParams[iDet] = (TObjArray*)(par.fDetRecoParams[iDet]->Clone());
64     else
65       fDetRecoParams[iDet] = NULL;
66   }
67   for(Int_t iSpecie = 0; iSpecie < kNSpecies; iSpecie++) {
68     for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
69       fDetRecoParamsIndex[iSpecie][iDet] = par.fDetRecoParamsIndex[iSpecie][iDet];
70     }
71   }
72 }
73
74 //_____________________________________________________________________________
75 AliRecoParam& AliRecoParam::operator = (const AliRecoParam& par)
76 {
77   // assignment operator
78
79   if(&par == this) return *this;
80
81   this->~AliRecoParam();
82   new(this) AliRecoParam(par);
83   return *this;
84 }
85
86 AliRecoParam::~AliRecoParam(){
87   // Destructor
88   // ...
89   // Delete the array with the reco-param objects
90   for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
91     if (fDetRecoParams[iDet]){
92       fDetRecoParams[iDet]->Delete();
93       delete fDetRecoParams[iDet];
94     }
95   }
96 }
97
98 Int_t AliRecoParam::AConvert(EventSpecie_t es)
99 {
100   //Converts EventSpecie_t  into int
101   return static_cast<Int_t>(TMath::Log2(es)) ; 
102   
103 }
104
105 AliRecoParam::EventSpecie_t AliRecoParam::Convert(Int_t ies)
106 {
107   //Converts int into EventSpecie_t
108   AliRecoParam::EventSpecie_t es = AliRecoParam::kDefault ; 
109   
110   Int_t i = (Int_t)TMath::Power(2, ies) ; 
111   
112   if ( i == AliRecoParam::kLowMult) 
113     es = kLowMult ; 
114   else if ( i == AliRecoParam::kHighMult) 
115     es = kHighMult ;   
116   else if ( i == AliRecoParam::kCosmic) 
117     es = kCosmic ;   
118   else if ( i == AliRecoParam::kCalib) 
119     es = kCalib ;   
120   
121   return es ;   
122 }
123
124 void  AliRecoParam::Print(Option_t *option) const {
125   //
126   // Print reconstruction setup
127   //
128   for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
129     if (fDetRecoParams[iDet]){
130       printf("AliDetectorRecoParam objects for detector %d:\n",iDet); 
131       Int_t nparam = fDetRecoParams[iDet]->GetEntriesFast();
132       for (Int_t iparam=0; iparam<nparam; iparam++){
133         AliDetectorRecoParam * param = (AliDetectorRecoParam *)fDetRecoParams[iDet]->At(iparam);
134         if (!param) continue;
135         param->Print(option);
136       }
137     }
138     else {
139       printf("No AliDetectorRecoParam objects specified for detector %d\n",iDet); 
140     }
141   }
142 }
143
144 void AliRecoParam::SetEventSpecie(const AliRunInfo *runInfo, const AliEventInfo &evInfo)
145 {
146   // To be implemented
147   // Here we return always kDefault!!
148
149   fEventSpecie = kDefault;
150
151   if (strcmp(runInfo->GetRunType(),"PHYSICS")) {
152     // Not a physics run, the event specie is set to kCalib
153     fEventSpecie = kCalib;
154     return;
155   }
156
157   if (strcmp(runInfo->GetLHCState(),"STABLE_BEAMS") == 0) {
158     // In case of stable beams
159 //    if ((strcmp(runInfo->GetBeamType(),"A-A") == 0) ||
160 //      (strcmp(runInfo->GetBeamType(),"A-") == 0) ||
161 //      (strcmp(runInfo->GetBeamType(),"-A") == 0)) {
162       // Heavy ion run (any beam tha is not pp, the event specie is set to kHighMult
163       fEventSpecie = kHighMult;
164 //    }
165 //    else 
166     if ((strcmp(runInfo->GetBeamType(),"p-p") == 0) ||
167              (strcmp(runInfo->GetBeamType(),"p-") == 0) ||
168              (strcmp(runInfo->GetBeamType(),"-p") == 0) ||
169              (strcmp(runInfo->GetBeamType(),"P-P") == 0) ||
170              (strcmp(runInfo->GetBeamType(),"P-") == 0) ||
171              (strcmp(runInfo->GetBeamType(),"-P") == 0)) {
172       // Proton run, the event specie is set to kLowMult
173       fEventSpecie = kLowMult;
174     }
175     else if (strcmp(runInfo->GetBeamType(),"-") == 0) {
176       // No beams, we assume cosmic data
177       fEventSpecie = kCosmic;
178     }
179     else if (strcmp(runInfo->GetBeamType(),"UNKNOWN") == 0) {
180       // No LHC beam information is available, we the default
181       // event specie
182       fEventSpecie = kDefault;
183     }
184
185     // Now we look into the trigger type in order to decide
186     // on the remaining cases (cosmic event within LHC run,
187     // high-mult event based on high-mult SPD trigger
188     // within p-p run, laser triggers within physics run,
189     // special DAQ events considered as calibration etc...)
190     if (evInfo.GetEventType() != 7) {
191       // START_OF_*, END_OF_*, CALIBRATION etc events
192       fEventSpecie = kCalib;
193     }
194
195     TString triggerClasses = evInfo.GetTriggerClasses();
196     TObjArray* trClassArray = triggerClasses.Tokenize(" ");
197     Int_t nTrClasses = trClassArray->GetEntriesFast();
198     Bool_t cosmicTrigger = kFALSE,
199       laserTrigger = kFALSE,
200       highMultTrigger = kFALSE,
201       otherTrigger = kFALSE;
202     for( Int_t i=0; i<nTrClasses; ++i ) {
203       TString trClass = ((TObjString*)trClassArray->At(i))->String();
204       if (trClass.BeginsWith("C0A") ||
205           trClass.BeginsWith("C0SC") ||
206           trClass.BeginsWith("C0OC")) {
207       // ACORDE/SPD/TOF cosmic trigger, so we have cosmic event
208       // not always true, but we don't have a better idea...
209         cosmicTrigger = kTRUE;
210       }
211       else if (trClass.BeginsWith("C0LSR")) {
212         // Laser trigger
213         laserTrigger = kTRUE;
214       }
215       else if (trClass.BeginsWith("C0SH")) {
216         // High-multiplicity SPD trugger
217         // Have to add other high-mult triggers here...
218         highMultTrigger = kTRUE;
219       }
220       else {
221         otherTrigger = kTRUE;
222       }
223     }
224
225     if (laserTrigger) {
226       fEventSpecie = kCalib;
227       return;
228     }
229     if (cosmicTrigger && !highMultTrigger && !otherTrigger) {
230       fEventSpecie = kCosmic;
231       return;
232     }
233     if (highMultTrigger) {
234       fEventSpecie = kHighMult;
235       return;
236     }
237
238     // Here we have to add if we have other cases
239     // and also HLT info if any...
240   }
241 }
242
243 const AliDetectorRecoParam *AliRecoParam::GetDetRecoParam(Int_t iDet) const
244 {
245   // Return AliDetectorRecoParam object for a given detector
246   // according to the event specie provided as an argument
247   if ( iDet >= kNDetectors) return NULL;
248   if (!fDetRecoParams[iDet]) return NULL;
249   if (fDetRecoParams[iDet]->GetEntries() == 0) return NULL;
250
251   for(Int_t iBit = 0; iBit < kNSpecies; iBit++) {
252     if (fEventSpecie & (1 << iBit)) {
253       if (fDetRecoParamsIndex[iBit][iDet] >= 0)
254         return (AliDetectorRecoParam *)fDetRecoParams[iDet]->At(fDetRecoParamsIndex[iBit][iDet]);
255       else
256         return (AliDetectorRecoParam *)fDetRecoParams[iDet]->At(fDetRecoParamsIndex[0][iDet]);
257     }
258   }
259
260   // Default one
261   AliError(Form("Invalid event specie: %d!",fEventSpecie));
262   return (AliDetectorRecoParam *)fDetRecoParams[iDet]->At(fDetRecoParamsIndex[0][iDet]);
263 }
264
265 void  AliRecoParam::AddDetRecoParam(Int_t iDet, AliDetectorRecoParam* param)
266 {
267   // Add an instance of reco params object into
268   // the fDetRecoParams for detector iDet
269   // Updates the fDetRecoParams index
270   if (!fDetRecoParams[iDet]) fDetRecoParams[iDet] = new TObjArray;
271   fDetRecoParams[iDet]->AddLast(param);
272   Int_t index = fDetRecoParams[iDet]->GetLast();
273
274   // Index
275   Int_t specie = param->GetEventSpecie();
276   for(Int_t iBit = 0; iBit < kNSpecies; iBit++) {
277     if (specie & (1 << iBit)) {
278       fDetRecoParamsIndex[iBit][iDet] = index;
279     }
280   }
281 }
282
283 Bool_t AliRecoParam::AddDetRecoParamArray(Int_t iDet, TObjArray* parArray)
284 {
285   // Add an array of reconstruction parameter objects
286   // for a given detector
287   // Basic check on the consistency of the array
288   Bool_t defaultFound = kFALSE;
289   for(Int_t i = 0; i < parArray->GetEntriesFast(); i++) {
290     AliDetectorRecoParam *par = (AliDetectorRecoParam*)parArray->At(i);
291     if (!par) continue;
292     if (par->IsDefault()) defaultFound = kTRUE;
293
294     Int_t specie = par->GetEventSpecie();
295     for(Int_t iBit = 0; iBit < kNSpecies; iBit++) {
296       if (specie & (1 << iBit)) {
297         fDetRecoParamsIndex[iBit][iDet] = i;
298       }
299     }
300  }
301    
302   fDetRecoParams[iDet] = parArray;
303
304   return defaultFound;
305 }
306
307 const char*  AliRecoParam::PrintEventSpecie() const
308 {
309   // Print the current
310   // event specie
311   switch (fEventSpecie) {
312   case kDefault:
313     return fkgEventSpecieName[0].Data() ;
314     break;
315   case kLowMult:
316     return fkgEventSpecieName[1].Data() ;
317     break;
318   case kHighMult:
319     return fkgEventSpecieName[2].Data() ;
320     break;
321   case kCosmic:
322     return fkgEventSpecieName[3].Data() ;
323     break;
324   case kCalib:
325     return fkgEventSpecieName[4].Data() ;
326     break;
327   default:
328     return fkgEventSpecieName[5].Data() ;
329     break;
330   }
331 }
332
333 const char * AliRecoParam::GetEventSpecieName(EventSpecie_t es)
334 {
335   switch (es) {
336     case kDefault:
337       return fkgEventSpecieName[0].Data() ;
338       break;
339     case kLowMult:
340       return fkgEventSpecieName[1].Data() ;
341       break;
342     case kHighMult:
343       return fkgEventSpecieName[2].Data() ;
344       break;
345     case kCosmic:
346       return fkgEventSpecieName[3].Data() ;
347       break;
348     case kCalib:
349       return fkgEventSpecieName[4].Data() ;
350       break;
351     default:
352       return fkgEventSpecieName[5].Data() ;
353       break;
354   }
355 }
356
357 const char * AliRecoParam::GetEventSpecieName(Int_t esIndex)
358 {
359   if ( esIndex >= 0 && esIndex < kNSpecies) 
360     return fkgEventSpecieName[esIndex].Data() ;
361   else 
362     return fkgEventSpecieName[kNSpecies].Data() ;
363 }