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