]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliRecoParam.cxx
Update of the event-specie selection routine according to the discussions with trigge...
[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 "TClass.h"
29 #include "TObjArray.h"
30 #include "TMath.h"
31 #include "AliDetectorRecoParam.h"
32
33 #include "AliLog.h"
34 #include "AliRecoParam.h"
35 #include "AliRunInfo.h"
36 #include "AliEventInfo.h"
37 #include "AliLog.h"
38
39 ClassImp(AliRecoParam)
40
41 TString AliRecoParam::fkgEventSpecieName[] = {"Default", "LowMultiplicity", "HighMultiplicity", "Cosmic", "Calibration", "Unknown"} ; 
42
43 AliRecoParam::AliRecoParam(): 
44   TObject(),
45   fEventSpecie(kDefault)
46 {
47   // Default constructor
48   // ...
49   for(Int_t iDet = 0; iDet < kNDetectors; iDet++)
50     fDetRecoParams[iDet] = NULL;
51   for(Int_t iSpecie = 0; iSpecie < kNSpecies; iSpecie++) {
52     for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
53       fDetRecoParamsIndex[iSpecie][iDet] = -1;
54     }
55   }
56 }
57
58 AliRecoParam::AliRecoParam(const AliRecoParam& par) :
59   TObject(),
60   fEventSpecie(par.fEventSpecie)
61 {
62   // copy constructor
63   for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
64     if (par.fDetRecoParams[iDet])
65       fDetRecoParams[iDet] = (TObjArray*)(par.fDetRecoParams[iDet]->Clone());
66     else
67       fDetRecoParams[iDet] = NULL;
68   }
69   for(Int_t iSpecie = 0; iSpecie < kNSpecies; iSpecie++) {
70     for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
71       fDetRecoParamsIndex[iSpecie][iDet] = par.fDetRecoParamsIndex[iSpecie][iDet];
72     }
73   }
74 }
75
76 //_____________________________________________________________________________
77 AliRecoParam& AliRecoParam::operator = (const AliRecoParam& par)
78 {
79   // assignment operator
80
81   if(&par == this) return *this;
82
83   this->~AliRecoParam();
84   new(this) AliRecoParam(par);
85   return *this;
86 }
87
88 AliRecoParam::~AliRecoParam(){
89   // Destructor
90   // ...
91   // Delete the array with the reco-param objects
92   for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
93     if (fDetRecoParams[iDet]){
94       fDetRecoParams[iDet]->Delete();
95       delete fDetRecoParams[iDet];
96     }
97   }
98 }
99
100 Int_t AliRecoParam::AConvert(EventSpecie_t es)
101 {
102   //Converts EventSpecie_t  into int
103   Int_t rv = -1 ; 
104   switch (es) {
105     case kDefault:
106       rv = 0 ; 
107       break;
108     case kLowMult:
109       rv = 1 ; 
110       break;
111     case kHighMult:
112       rv = 2 ; 
113       break;
114     case kCosmic:
115       rv = 3 ; 
116       break;
117     case kCalib:
118       rv = 4 ; 
119       break;
120     default:
121       break;
122   }
123
124   if (rv < 0) 
125     AliFatalClass(Form("Wrong event specie conversion %d", es)) ; 
126
127   return rv ;
128 }
129
130 AliRecoParam::EventSpecie_t AliRecoParam::Convert(Int_t ies)
131 {
132   //Converts int into EventSpecie_t
133   AliRecoParam::EventSpecie_t es = kDefault ; 
134   if ( ies >> 1) 
135     es = kLowMult ; 
136   if ( ies >> 2) 
137     es = kHighMult ;   
138   if ( ies >> 3) 
139     es = kCosmic ;   
140   if ( ies >> 4) 
141     es = kCalib ;
142
143   return es ;   
144 }
145
146 AliRecoParam::EventSpecie_t AliRecoParam::ConvertIndex(Int_t index)
147 {
148   //Converts index of lists into eventspecie
149   EventSpecie_t es = kDefault ; 
150   switch (index) {
151     case 0:
152       es = kDefault ; 
153       break;
154     case 1:
155       es = kLowMult ; 
156       break;
157     case 2:
158       es = kHighMult ;   
159       break;
160     case 3:
161       es = kCosmic ;   
162       break;
163     case 4:
164       es = kCalib ;
165       break;
166     default:
167       break;
168   }
169   return es ;
170 }
171
172 void  AliRecoParam::Print(Option_t *option) const {
173   //
174   // Print reconstruction setup
175   //
176   for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
177     if (fDetRecoParams[iDet]){
178       printf("AliDetectorRecoParam objects for detector %d:\n",iDet); 
179       Int_t nparam = fDetRecoParams[iDet]->GetEntriesFast();
180       for (Int_t iparam=0; iparam<nparam; iparam++){
181         AliDetectorRecoParam * param = (AliDetectorRecoParam *)fDetRecoParams[iDet]->At(iparam);
182         if (!param) continue;
183         param->Print(option);
184       }
185     }
186     else {
187       printf("No AliDetectorRecoParam objects specified for detector %d\n",iDet); 
188     }
189   }
190 }
191
192 void AliRecoParam::SetEventSpecie(const AliRunInfo *runInfo, const AliEventInfo &evInfo)
193 {
194   // To be implemented
195   // Here we return always kDefault!!
196
197   fEventSpecie = kDefault;
198
199   if (strcmp(runInfo->GetRunType(),"PHYSICS")) {
200     // Not a physics run, the event specie is set to kCalib
201     fEventSpecie = kCalib;
202     return;
203   }
204
205   if (strcmp(runInfo->GetLHCState(),"STABLE_BEAMS") == 0) {
206     // In case of stable beams
207     if ((strcmp(runInfo->GetBeamType(),"A-A") == 0) ||
208         (strcmp(runInfo->GetBeamType(),"A-") == 0) ||
209         (strcmp(runInfo->GetBeamType(),"-A") == 0)) {
210       // Heavy ion run (any beam tha is not pp, the event specie is set to kHighMult
211       fEventSpecie = kHighMult;
212     }
213     else if ((strcmp(runInfo->GetBeamType(),"p-p") == 0) ||
214              (strcmp(runInfo->GetBeamType(),"p-") == 0) ||
215              (strcmp(runInfo->GetBeamType(),"-p") == 0) ||
216              (strcmp(runInfo->GetBeamType(),"P-P") == 0) ||
217              (strcmp(runInfo->GetBeamType(),"P-") == 0) ||
218              (strcmp(runInfo->GetBeamType(),"-P") == 0)) {
219       // Proton run, the event specie is set to kLowMult
220       fEventSpecie = kLowMult;
221     }
222     else if (strcmp(runInfo->GetBeamType(),"-") == 0) {
223       // No beams, we assume cosmic data
224       fEventSpecie = kCosmic;
225     }
226     else if (strcmp(runInfo->GetBeamType(),"UNKNOWN") == 0) {
227       // No LHC beam information is available, we the default
228       // event specie
229       fEventSpecie = kDefault;
230     }
231
232     // Now we look into the trigger type in order to decide
233     // on the remaining cases (cosmic event within LHC run,
234     // calibration, for example TPC laser, triggers within physics run,
235     // special DAQ events considered as calibration etc...)
236     if (evInfo.GetEventType() != 7) {
237       // START_OF_*, END_OF_*, CALIBRATION etc events
238       fEventSpecie = kCalib;
239       return;
240     }
241
242     TString triggerClasses = evInfo.GetTriggerClasses();
243     TObjArray* trClassArray = triggerClasses.Tokenize(" ");
244     Int_t nTrClasses = trClassArray->GetEntriesFast();
245     Bool_t cosmicTrigger = kFALSE,
246       calibTrigger = kFALSE,
247       otherTrigger = kFALSE;
248     for( Int_t i=0; i<nTrClasses; ++i ) {
249       TString trClass = ((TObjString*)trClassArray->At(i))->String();
250
251       if (trClass.BeginsWith("C0L")) {
252         // Calibration triggers always start with C0L
253         calibTrigger = kTRUE;
254         continue;
255       }
256
257       TObjArray* tmp = trClass.Tokenize("-");
258       TObjString* bcName = (TObjString*)tmp->At(1);
259       if (bcName) {
260         if ((bcName->String().CompareTo("ABCE") == 0) ||
261             (bcName->String().CompareTo("E")    == 0) ||
262             (bcName->String().CompareTo("NONE") == 0)) {
263           // Cosmic triggers are identified by empty bunch-crossing mask
264           // The naming comvention is:
265           // A  filled bunch from A side, empty from C side
266           // B  filled bunch from both sides
267           // C  filled bunch from C side, empty from A side
268           // E  empty bunch from both sides
269           cosmicTrigger = kTRUE;
270           delete tmp;
271           continue;
272         }
273       }
274       else {
275         AliWarning(Form("Trigger class %s doesn't comply with the naming convention!",trClass.Data()));
276       }
277       delete tmp;
278
279       otherTrigger = kTRUE;
280     }
281
282     if (calibTrigger) {
283       fEventSpecie = kCalib;
284       return;
285     }
286     if (cosmicTrigger && !otherTrigger) {
287       fEventSpecie = kCosmic;
288       return;
289     }
290
291     // Here we have to add if we have other cases
292     // and also HLT info if any...
293   }
294 }
295
296 const AliDetectorRecoParam *AliRecoParam::GetDetRecoParam(Int_t iDet) const
297 {
298   // Return AliDetectorRecoParam object for a given detector
299   // according to the event specie provided as an argument
300   if ( iDet >= kNDetectors) return NULL;
301   if (!fDetRecoParams[iDet]) return NULL;
302   if (fDetRecoParams[iDet]->GetEntries() == 0) return NULL;
303
304   for(Int_t iBit = 0; iBit < kNSpecies; iBit++) {
305     if (fEventSpecie & (1 << iBit)) {
306       if (fDetRecoParamsIndex[iBit][iDet] >= 0)
307         return (AliDetectorRecoParam *)fDetRecoParams[iDet]->At(fDetRecoParamsIndex[iBit][iDet]);
308       else
309         return (AliDetectorRecoParam *)fDetRecoParams[iDet]->At(fDetRecoParamsIndex[0][iDet]);
310     }
311   }
312
313   // Default one
314   AliError(Form("Invalid event specie: %d!",fEventSpecie));
315   return (AliDetectorRecoParam *)fDetRecoParams[iDet]->At(fDetRecoParamsIndex[0][iDet]);
316 }
317
318 void  AliRecoParam::AddDetRecoParam(Int_t iDet, AliDetectorRecoParam* param)
319 {
320   // Add an instance of reco params object into
321   // the fDetRecoParams for detector iDet
322   // Updates the fDetRecoParams index
323   if (!fDetRecoParams[iDet]) fDetRecoParams[iDet] = new TObjArray;
324   fDetRecoParams[iDet]->AddLast(param);
325   Int_t index = fDetRecoParams[iDet]->GetLast();
326
327   // Index
328   Int_t specie = param->GetEventSpecie();
329   for(Int_t iBit = 0; iBit < kNSpecies; iBit++) {
330     if (specie & (1 << iBit)) {
331       fDetRecoParamsIndex[iBit][iDet] = index;
332     }
333   }
334 }
335
336 Bool_t AliRecoParam::AddDetRecoParamArray(Int_t iDet, TObjArray* parArray)
337 {
338   // Add an array of reconstruction parameter objects
339   // for a given detector
340   // Basic check on the consistency of the array
341   Bool_t defaultFound = kFALSE;
342   for(Int_t i = 0; i < parArray->GetEntriesFast(); i++) {
343     AliDetectorRecoParam *par = (AliDetectorRecoParam*)parArray->At(i);
344     if (!par) continue;
345     if (par->IsDefault()) defaultFound = kTRUE;
346
347     Int_t specie = par->GetEventSpecie();
348     for(Int_t iBit = 0; iBit < kNSpecies; iBit++) {
349       if (specie & (1 << iBit)) {
350         fDetRecoParamsIndex[iBit][iDet] = i;
351       }
352     }
353  }
354    
355   fDetRecoParams[iDet] = parArray;
356
357   return defaultFound;
358 }
359
360 const char*  AliRecoParam::PrintEventSpecie() const
361 {
362   // Print the current
363   // event specie
364   switch (fEventSpecie) {
365   case kDefault:
366     return fkgEventSpecieName[0].Data() ;
367     break;
368   case kLowMult:
369     return fkgEventSpecieName[1].Data() ;
370     break;
371   case kHighMult:
372     return fkgEventSpecieName[2].Data() ;
373     break;
374   case kCosmic:
375     return fkgEventSpecieName[3].Data() ;
376     break;
377   case kCalib:
378     return fkgEventSpecieName[4].Data() ;
379     break;
380   default:
381     return fkgEventSpecieName[5].Data() ;
382     break;
383   }
384 }
385
386 const char * AliRecoParam::GetEventSpecieName(EventSpecie_t es)
387 {
388   switch (es) {
389     case kDefault:
390       return fkgEventSpecieName[0].Data() ;
391       break;
392     case kLowMult:
393       return fkgEventSpecieName[1].Data() ;
394       break;
395     case kHighMult:
396       return fkgEventSpecieName[2].Data() ;
397       break;
398     case kCosmic:
399       return fkgEventSpecieName[3].Data() ;
400       break;
401     case kCalib:
402       return fkgEventSpecieName[4].Data() ;
403       break;
404     default:
405       return fkgEventSpecieName[5].Data() ;
406       break;
407   }
408 }
409
410 const char * AliRecoParam::GetEventSpecieName(Int_t esIndex)
411 {
412   if ( esIndex >= 0 && esIndex < kNSpecies) 
413     return fkgEventSpecieName[esIndex].Data() ;
414   else 
415     return fkgEventSpecieName[kNSpecies].Data() ;
416 }