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