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