increased precision for stored momenta
[u/mrichter/AliRoot.git] / STEER / AliRecoParam.cxx
CommitLineData
242b332c 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// //
6769d914 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. //
242b332c 25// //
26///////////////////////////////////////////////////////////////////////////////
27
5e232cd6 28#include "TClass.h"
242b332c 29#include "TObjArray.h"
57acd2d2 30#include "TMath.h"
242b332c 31#include "AliDetectorRecoParam.h"
32
6bcbb25b 33#include "AliLog.h"
242b332c 34#include "AliRecoParam.h"
48f5e52d 35#include "AliRunInfo.h"
36#include "AliEventInfo.h"
5e232cd6 37#include "AliLog.h"
242b332c 38
242b332c 39ClassImp(AliRecoParam)
40
57acd2d2 41TString AliRecoParam::fkgEventSpecieName[] = {"Default", "LowMultiplicity", "HighMultiplicity", "Cosmic", "Calibration", "Unknown"} ;
42
6769d914 43AliRecoParam::AliRecoParam():
7e88424f 44 TObject(),
45 fEventSpecie(kDefault)
242b332c 46{
6769d914 47 // Default constructor
48 // ...
7e88424f 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 }
242b332c 56}
57
54e51010 58AliRecoParam::AliRecoParam(const AliRecoParam& par) :
59 TObject(),
60 fEventSpecie(par.fEventSpecie)
61{
62 // copy constructor
63 for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
54e51010 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
49ad11d0 76//_____________________________________________________________________________
77AliRecoParam& 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
242b332c 88AliRecoParam::~AliRecoParam(){
6769d914 89 // Destructor
90 // ...
91 // Delete the array with the reco-param objects
7e88424f 92 for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
93 if (fDetRecoParams[iDet]){
94 fDetRecoParams[iDet]->Delete();
95 delete fDetRecoParams[iDet];
96 }
242b332c 97 }
98}
99
57acd2d2 100Int_t AliRecoParam::AConvert(EventSpecie_t es)
101{
102 //Converts EventSpecie_t into int
5e232cd6 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 }
9d556894 123
124 if (rv < 0)
5e232cd6 125 AliFatalClass(Form("Wrong event specie conversion %d", es)) ;
9d556894 126
127 return rv ;
57acd2d2 128}
129
130AliRecoParam::EventSpecie_t AliRecoParam::Convert(Int_t ies)
131{
132 //Converts int into EventSpecie_t
5e232cd6 133 AliRecoParam::EventSpecie_t es = kDefault ;
134 if ( ies >> 1)
57acd2d2 135 es = kLowMult ;
5e232cd6 136 if ( ies >> 2)
57acd2d2 137 es = kHighMult ;
5e232cd6 138 if ( ies >> 3)
57acd2d2 139 es = kCosmic ;
5e232cd6 140 if ( ies >> 4)
141 es = kCalib ;
142
57acd2d2 143 return es ;
144}
145
5e232cd6 146AliRecoParam::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
6769d914 172void AliRecoParam::Print(Option_t *option) const {
242b332c 173 //
174 // Print reconstruction setup
175 //
7e88424f 176 for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
177 if (fDetRecoParams[iDet]){
ac232c75 178 printf("AliDetectorRecoParam objects for detector %d:\n",iDet);
7e88424f 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 }
242b332c 189 }
190}
191
48f5e52d 192void AliRecoParam::SetEventSpecie(const AliRunInfo *runInfo, const AliEventInfo &evInfo)
7e88424f 193{
194 // To be implemented
195 // Here we return always kDefault!!
48f5e52d 196
7e88424f 197 fEventSpecie = kDefault;
48f5e52d 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
57acd2d2 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
48f5e52d 211 fEventSpecie = kHighMult;
57acd2d2 212// }
213// else
214 if ((strcmp(runInfo->GetBeamType(),"p-p") == 0) ||
48f5e52d 215 (strcmp(runInfo->GetBeamType(),"p-") == 0) ||
216 (strcmp(runInfo->GetBeamType(),"-p") == 0) ||
217 (strcmp(runInfo->GetBeamType(),"P-P") == 0) ||
218 (strcmp(runInfo->GetBeamType(),"P-") == 0) ||
219 (strcmp(runInfo->GetBeamType(),"-P") == 0)) {
220 // Proton run, the event specie is set to kLowMult
221 fEventSpecie = kLowMult;
222 }
223 else if (strcmp(runInfo->GetBeamType(),"-") == 0) {
224 // No beams, we assume cosmic data
225 fEventSpecie = kCosmic;
226 }
227 else if (strcmp(runInfo->GetBeamType(),"UNKNOWN") == 0) {
228 // No LHC beam information is available, we the default
229 // event specie
230 fEventSpecie = kDefault;
231 }
232
233 // Now we look into the trigger type in order to decide
234 // on the remaining cases (cosmic event within LHC run,
235 // high-mult event based on high-mult SPD trigger
236 // within p-p run, laser triggers within physics run,
237 // special DAQ events considered as calibration etc...)
238 if (evInfo.GetEventType() != 7) {
239 // START_OF_*, END_OF_*, CALIBRATION etc events
240 fEventSpecie = kCalib;
241 }
242
243 TString triggerClasses = evInfo.GetTriggerClasses();
244 TObjArray* trClassArray = triggerClasses.Tokenize(" ");
245 Int_t nTrClasses = trClassArray->GetEntriesFast();
246 Bool_t cosmicTrigger = kFALSE,
247 laserTrigger = kFALSE,
248 highMultTrigger = kFALSE,
249 otherTrigger = kFALSE;
250 for( Int_t i=0; i<nTrClasses; ++i ) {
251 TString trClass = ((TObjString*)trClassArray->At(i))->String();
252 if (trClass.BeginsWith("C0A") ||
253 trClass.BeginsWith("C0SC") ||
254 trClass.BeginsWith("C0OC")) {
255 // ACORDE/SPD/TOF cosmic trigger, so we have cosmic event
256 // not always true, but we don't have a better idea...
257 cosmicTrigger = kTRUE;
258 }
259 else if (trClass.BeginsWith("C0LSR")) {
260 // Laser trigger
261 laserTrigger = kTRUE;
262 }
263 else if (trClass.BeginsWith("C0SH")) {
264 // High-multiplicity SPD trugger
265 // Have to add other high-mult triggers here...
266 highMultTrigger = kTRUE;
267 }
268 else {
269 otherTrigger = kTRUE;
270 }
271 }
272
273 if (laserTrigger) {
274 fEventSpecie = kCalib;
275 return;
276 }
277 if (cosmicTrigger && !highMultTrigger && !otherTrigger) {
278 fEventSpecie = kCosmic;
279 return;
280 }
281 if (highMultTrigger) {
282 fEventSpecie = kHighMult;
283 return;
284 }
285
286 // Here we have to add if we have other cases
287 // and also HLT info if any...
288 }
7e88424f 289}
290
291const AliDetectorRecoParam *AliRecoParam::GetDetRecoParam(Int_t iDet) const
292{
293 // Return AliDetectorRecoParam object for a given detector
294 // according to the event specie provided as an argument
a00021a7 295 if ( iDet >= kNDetectors) return NULL;
7e88424f 296 if (!fDetRecoParams[iDet]) return NULL;
297 if (fDetRecoParams[iDet]->GetEntries() == 0) return NULL;
298
299 for(Int_t iBit = 0; iBit < kNSpecies; iBit++) {
300 if (fEventSpecie & (1 << iBit)) {
301 if (fDetRecoParamsIndex[iBit][iDet] >= 0)
302 return (AliDetectorRecoParam *)fDetRecoParams[iDet]->At(fDetRecoParamsIndex[iBit][iDet]);
303 else
304 return (AliDetectorRecoParam *)fDetRecoParams[iDet]->At(fDetRecoParamsIndex[0][iDet]);
305 }
306 }
6bcbb25b 307
7e88424f 308 // Default one
309 AliError(Form("Invalid event specie: %d!",fEventSpecie));
310 return (AliDetectorRecoParam *)fDetRecoParams[iDet]->At(fDetRecoParamsIndex[0][iDet]);
6bcbb25b 311}
312
7e88424f 313void AliRecoParam::AddDetRecoParam(Int_t iDet, AliDetectorRecoParam* param)
314{
6769d914 315 // Add an instance of reco params object into
7e88424f 316 // the fDetRecoParams for detector iDet
317 // Updates the fDetRecoParams index
318 if (!fDetRecoParams[iDet]) fDetRecoParams[iDet] = new TObjArray;
319 fDetRecoParams[iDet]->AddLast(param);
320 Int_t index = fDetRecoParams[iDet]->GetLast();
321
322 // Index
323 Int_t specie = param->GetEventSpecie();
324 for(Int_t iBit = 0; iBit < kNSpecies; iBit++) {
325 if (specie & (1 << iBit)) {
326 fDetRecoParamsIndex[iBit][iDet] = index;
327 }
328 }
329}
330
331Bool_t AliRecoParam::AddDetRecoParamArray(Int_t iDet, TObjArray* parArray)
332{
333 // Add an array of reconstruction parameter objects
334 // for a given detector
335 // Basic check on the consistency of the array
336 Bool_t defaultFound = kFALSE;
337 for(Int_t i = 0; i < parArray->GetEntriesFast(); i++) {
338 AliDetectorRecoParam *par = (AliDetectorRecoParam*)parArray->At(i);
339 if (!par) continue;
340 if (par->IsDefault()) defaultFound = kTRUE;
3d0847a7 341
342 Int_t specie = par->GetEventSpecie();
343 for(Int_t iBit = 0; iBit < kNSpecies; iBit++) {
344 if (specie & (1 << iBit)) {
345 fDetRecoParamsIndex[iBit][iDet] = i;
346 }
347 }
348 }
7e88424f 349
350 fDetRecoParams[iDet] = parArray;
351
352 return defaultFound;
242b332c 353}
48f5e52d 354
355const char* AliRecoParam::PrintEventSpecie() const
356{
357 // Print the current
358 // event specie
359 switch (fEventSpecie) {
360 case kDefault:
57acd2d2 361 return fkgEventSpecieName[0].Data() ;
48f5e52d 362 break;
363 case kLowMult:
57acd2d2 364 return fkgEventSpecieName[1].Data() ;
48f5e52d 365 break;
366 case kHighMult:
57acd2d2 367 return fkgEventSpecieName[2].Data() ;
48f5e52d 368 break;
369 case kCosmic:
57acd2d2 370 return fkgEventSpecieName[3].Data() ;
48f5e52d 371 break;
372 case kCalib:
57acd2d2 373 return fkgEventSpecieName[4].Data() ;
48f5e52d 374 break;
375 default:
57acd2d2 376 return fkgEventSpecieName[5].Data() ;
48f5e52d 377 break;
378 }
379}
57acd2d2 380
381const char * AliRecoParam::GetEventSpecieName(EventSpecie_t es)
382{
383 switch (es) {
384 case kDefault:
385 return fkgEventSpecieName[0].Data() ;
386 break;
387 case kLowMult:
388 return fkgEventSpecieName[1].Data() ;
389 break;
390 case kHighMult:
391 return fkgEventSpecieName[2].Data() ;
392 break;
393 case kCosmic:
394 return fkgEventSpecieName[3].Data() ;
395 break;
396 case kCalib:
397 return fkgEventSpecieName[4].Data() ;
398 break;
399 default:
400 return fkgEventSpecieName[5].Data() ;
401 break;
402 }
403}
404
405const char * AliRecoParam::GetEventSpecieName(Int_t esIndex)
406{
407 if ( esIndex >= 0 && esIndex < kNSpecies)
408 return fkgEventSpecieName[esIndex].Data() ;
409 else
410 return fkgEventSpecieName[kNSpecies].Data() ;
411}