Coverity 16571
[u/mrichter/AliRoot.git] / STEER / AliESDRun.cxx
CommitLineData
d5ebf00e 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 **************************************************************************/
f009b5c1 15#include <TNamed.h>
8d218603 16#include <TGeoMatrix.h>
33fe5eb1 17#include <TGeoGlobalMagField.h>
d5ebf00e 18
19#include "AliESDRun.h"
20#include "AliESDVertex.h"
f009b5c1 21#include "AliLog.h"
33fe5eb1 22#include "AliMagF.h"
d5ebf00e 23
24//-------------------------------------------------------------------------
25// Implementation Class AliESDRun
26// Run by run data
27// for the ESD
28// Origin: Christian Klein-Boesing, CERN, Christian.Klein-Boesing@cern.ch
29//-------------------------------------------------------------------------
30
31ClassImp(AliESDRun)
32
33//______________________________________________________________________________
34AliESDRun::AliESDRun() :
694aad0c 35 TObject(),
33fe5eb1 36 fCurrentL3(0),
37 fCurrentDip(0),
38 fBeamEnergy(0),
694aad0c 39 fMagneticField(0),
1c7554f9 40 fDiamondZ(0),
41 fDiamondSig2Z(0),
d5ebf00e 42 fPeriodNumber(0),
694aad0c 43 fRunNumber(0),
f009b5c1 44 fRecoVersion(0),
33fe5eb1 45 fBeamType(""),
7b649c02 46 fTriggerClasses(kNTriggerClasses),
47 fDetInDAQ(0),
48 fDetInReco(0)
d443e5e9 49
d5ebf00e 50{
51 for (Int_t i=0; i<2; i++) fDiamondXY[i]=0.;
a2dedd16 52 fDiamondCovXY[0]=fDiamondCovXY[2]=3.*3.;
53 fDiamondCovXY[1]=0.;
f009b5c1 54 fTriggerClasses.SetOwner(kTRUE);
b671618d 55 fMeanBeamInt[0][0]=fMeanBeamInt[0][1]=fMeanBeamInt[1][0]=fMeanBeamInt[1][1]=-1;
8d218603 56 for (Int_t m=0; m<kNPHOSMatrix; m++) fPHOSMatrix[m]=NULL;
428557af 57 for (Int_t sm=0; sm<kNEMCALMatrix; sm++) fEMCALMatrix[sm]=NULL;
d443e5e9 58 for (Int_t i=0; i<kT0spreadSize;i++) fT0spread[i]=0.;
e2456048 59 for (Int_t it=0; it<8; it++) fCaloTriggerType[it]=0;
d5ebf00e 60}
61
62//______________________________________________________________________________
63AliESDRun::AliESDRun(const AliESDRun &esd) :
64 TObject(esd),
33fe5eb1 65 fCurrentL3(0),
66 fCurrentDip(0),
67 fBeamEnergy(0),
694aad0c 68 fMagneticField(esd.fMagneticField),
1c7554f9 69 fDiamondZ(esd.fDiamondZ),
70 fDiamondSig2Z(esd.fDiamondSig2Z),
d5ebf00e 71 fPeriodNumber(esd.fPeriodNumber),
694aad0c 72 fRunNumber(esd.fRunNumber),
f009b5c1 73 fRecoVersion(esd.fRecoVersion),
33fe5eb1 74 fBeamType(""),
7b649c02 75 fTriggerClasses(TObjArray(kNTriggerClasses)),
76 fDetInDAQ(0),
77 fDetInReco(0)
d5ebf00e 78{
79 // Copy constructor
80 for (Int_t i=0; i<2; i++) fDiamondXY[i]=esd.fDiamondXY[i];
81 for (Int_t i=0; i<3; i++) fDiamondCovXY[i]=esd.fDiamondCovXY[i];
f009b5c1 82
83 for(Int_t i = 0; i < kNTriggerClasses; i++) {
84 TNamed *str = (TNamed *)((esd.fTriggerClasses).At(i));
85 if (str) fTriggerClasses.AddAt(new TNamed(*str),i);
86 }
8d218603 87
88 for(Int_t m=0; m<kNPHOSMatrix; m++){
89 if(esd.fPHOSMatrix[m])
90 fPHOSMatrix[m]=new TGeoHMatrix(*(esd.fPHOSMatrix[m])) ;
91 else
92 fPHOSMatrix[m]=NULL;
93 }
b671618d 94
95 for (int ib=2;ib--;) for (int it=2;it--;) fMeanBeamInt[ib][it] = esd.fMeanBeamInt[ib][it];
96
428557af 97 for(Int_t sm=0; sm<kNEMCALMatrix; sm++){
98 if(esd.fEMCALMatrix[sm])
99 fEMCALMatrix[sm]=new TGeoHMatrix(*(esd.fEMCALMatrix[sm])) ;
100 else
101 fEMCALMatrix[sm]=NULL;
102 }
d443e5e9 103 for (Int_t i=0; i<kT0spreadSize;i++) fT0spread[i]=esd.fT0spread[i];
e2456048 104 for (Int_t it=0; it<8; it++) fCaloTriggerType[it]=esd.fCaloTriggerType[it];
d443e5e9 105
d5ebf00e 106}
107
108//______________________________________________________________________________
109AliESDRun& AliESDRun::operator=(const AliESDRun &esd)
110{
111 // assigment operator
112 if(this!=&esd) {
113 TObject::operator=(esd);
114 fRunNumber=esd.fRunNumber;
8d218603 115 fPeriodNumber=esd.fPeriodNumber;
116 fRecoVersion=esd.fRecoVersion;
117 fMagneticField=esd.fMagneticField;
1c7554f9 118 fDiamondZ=esd.fDiamondZ;
119 fDiamondSig2Z=esd.fDiamondSig2Z;
33fe5eb1 120 fBeamType = esd.fBeamType;
121 fCurrentL3 = esd.fCurrentL3;
122 fCurrentDip = esd.fCurrentDip;
123 fBeamEnergy = esd.fBeamEnergy;
8d218603 124 for (Int_t i=0; i<2; i++) fDiamondXY[i]=esd.fDiamondXY[i];
125 for (Int_t i=0; i<3; i++) fDiamondCovXY[i]=esd.fDiamondCovXY[i];
126 fTriggerClasses.Clear();
127 for(Int_t i = 0; i < kNTriggerClasses; i++) {
128 TNamed *str = (TNamed *)((esd.fTriggerClasses).At(i));
129 if (str) fTriggerClasses.AddAt(new TNamed(*str),i);
130 }
131
7b649c02 132 fDetInDAQ = esd.fDetInDAQ;
133 fDetInReco = esd.fDetInReco;
134
b671618d 135 for (int ib=2;ib--;) for (int it=2;it--;) fMeanBeamInt[ib][it] = esd.fMeanBeamInt[ib][it];
136
8d218603 137 for(Int_t m=0; m<kNPHOSMatrix; m++){
138 if(esd.fPHOSMatrix[m])
139 fPHOSMatrix[m]=new TGeoHMatrix(*(esd.fPHOSMatrix[m])) ;
140 else
141 fPHOSMatrix[m]=0;
142 }
428557af 143
144 for(Int_t sm=0; sm<kNEMCALMatrix; sm++){
145 if(esd.fEMCALMatrix[sm])
146 fEMCALMatrix[sm]=new TGeoHMatrix(*(esd.fEMCALMatrix[sm])) ;
147 else
148 fEMCALMatrix[sm]=0;
149 }
d5ebf00e 150 }
d443e5e9 151 for (Int_t i=0; i<kT0spreadSize;i++) fT0spread[i]=esd.fT0spread[i];
e2456048 152 for (Int_t it=0; it<8; it++) fCaloTriggerType[it]=esd.fCaloTriggerType[it];
d5ebf00e 153 return *this;
154}
155
732a24fe 156void AliESDRun::Copy(TObject &obj) const{
157
158 // this overwrites the virtual TOBject::Copy()
159 // to allow run time copying without casting
160 // in AliESDEvent
161
162 if(this==&obj)return;
163 AliESDRun *robj = dynamic_cast<AliESDRun*>(&obj);
164 if(!robj)return; // not an aliesdrun
165 *robj = *this;
166
167}
168
8d218603 169//______________________________________________________________________________
170AliESDRun::~AliESDRun() {
171 // Destructor
172 // Delete PHOS position matrices
173 for(Int_t m=0; m<kNPHOSMatrix; m++) {
174 if(fPHOSMatrix[m]) delete fPHOSMatrix[m] ;
175 fPHOSMatrix[m] = NULL;
176 }
428557af 177 // Delete PHOS position matrices
178 for(Int_t sm=0; sm<kNEMCALMatrix; sm++) {
179 if(fEMCALMatrix[sm]) delete fEMCALMatrix[sm] ;
180 fEMCALMatrix[sm] = NULL;
181 }
8d218603 182}
183
d5ebf00e 184void AliESDRun::SetDiamond(const AliESDVertex *vertex) {
185 // set the interaction diamond
c7a22819 186 if (vertex) {
187 fDiamondXY[0]=vertex->GetXv();
188 fDiamondXY[1]=vertex->GetYv();
189 fDiamondZ=vertex->GetZv();
190 Double32_t cov[6];
191 vertex->GetCovMatrix(cov);
192 fDiamondCovXY[0]=cov[0];
193 fDiamondCovXY[1]=cov[1];
194 fDiamondCovXY[2]=cov[2];
195 fDiamondSig2Z=cov[5];
196 }
d5ebf00e 197}
198
199
200//______________________________________________________________________________
201void AliESDRun::Print(const Option_t *) const
202{
203 // Print some data members
1c7554f9 204 printf("Mean vertex in RUN %d: X=%.4f Y=%.4f Z=%.4f cm\n",
205 GetRunNumber(),GetDiamondX(),GetDiamondY(),GetDiamondZ());
33fe5eb1 206 printf("Beam Type: %s, Energy: %.1f GeV\n",fBeamType.IsNull() ? "N/A":fBeamType.Data(),fBeamEnergy);
207 printf("Magnetic field in IP= %f T | Currents: L3:%+.1f Dipole:%+.1f %s\n",
208 GetMagneticField(),fCurrentL3,fCurrentDip,TestBit(kUniformBMap) ? "(Uniform)":"");
d5ebf00e 209 printf("Event from reconstruction version %d \n",fRecoVersion);
f009b5c1 210
211 printf("List of active trigger classes: ");
212 for(Int_t i = 0; i < kNTriggerClasses; i++) {
213 TNamed *str = (TNamed *)((fTriggerClasses).At(i));
384e7a60 214 if (str) printf("%s ",str->GetName());
f009b5c1 215 }
b671618d 216 printf("Mean intenstity for interacting : beam1:%+.3e beam2:%+.3e\n",fMeanBeamInt[0][0],fMeanBeamInt[1][0]);
217 printf("Mean intenstity for non-intecting : beam1:%+.3e beam2:%+.3e\n",fMeanBeamInt[0][1],fMeanBeamInt[1][1]);
f009b5c1 218 printf("\n");
d5ebf00e 219}
220
221void AliESDRun::Reset()
222{
223 // reset data members
224 fRunNumber = 0;
225 fPeriodNumber = 0;
226 fRecoVersion = 0;
227 fMagneticField = 0;
11be4f1c 228 fCurrentL3 = 0;
229 fCurrentDip = 0;
230 fBeamEnergy = 0;
231 fBeamType = "";
5cf76849 232 ResetBit(kBInfoStored|kUniformBMap|kConvSqrtSHalfGeV);
d5ebf00e 233 for (Int_t i=0; i<2; i++) fDiamondXY[i]=0.;
a2dedd16 234 fDiamondCovXY[0]=fDiamondCovXY[2]=3.*3.;
235 fDiamondCovXY[1]=0.;
1c7554f9 236 fDiamondZ=0.;
237 fDiamondSig2Z=10.*10.;
f009b5c1 238 fTriggerClasses.Clear();
7b649c02 239 fDetInDAQ = 0;
240 fDetInReco = 0;
f009b5c1 241}
242
243//______________________________________________________________________________
244void AliESDRun::SetTriggerClass(const char*name, Int_t index)
245{
246 // Fill the trigger class name
247 // into the corresponding array
248 if (index >= kNTriggerClasses || index < 0) {
249 AliError(Form("Index (%d) is outside the allowed range (0,49)!",index));
250 return;
251 }
252
253 fTriggerClasses.AddAt(new TNamed(name,NULL),index);
254}
255
256//______________________________________________________________________________
257const char* AliESDRun::GetTriggerClass(Int_t index) const
258{
259 // Get the trigger class name at
260 // specified position in the trigger mask
261 TNamed *trclass = (TNamed *)fTriggerClasses.At(index);
262 if (trclass)
263 return trclass->GetName();
264 else
265 return "";
266}
267
268//______________________________________________________________________________
269TString AliESDRun::GetActiveTriggerClasses() const
270{
271 // Construct and return
272 // the list of trigger classes
273 // which are present in the run
274 TString trclasses;
275 for(Int_t i = 0; i < kNTriggerClasses; i++) {
276 TNamed *str = (TNamed *)((fTriggerClasses).At(i));
277 if (str) {
278 trclasses += " ";
279 trclasses += str->GetName();
280 trclasses += " ";
281 }
282 }
283
284 return trclasses;
285}
286
287//______________________________________________________________________________
288TString AliESDRun::GetFiredTriggerClasses(ULong64_t mask) const
289{
290 // Constructs and returns the
291 // list of trigger classes that
292 // have been fired. Uses the trigger
293 // class mask as an argument.
294 TString trclasses;
295 for(Int_t i = 0; i < kNTriggerClasses; i++) {
a62d86d6 296 if (mask & (1ull << i)) {
f009b5c1 297 TNamed *str = (TNamed *)((fTriggerClasses).At(i));
298 if (str) {
299 trclasses += " ";
300 trclasses += str->GetName();
301 trclasses += " ";
302 }
303 }
304 }
305
306 return trclasses;
d5ebf00e 307}
308
f009b5c1 309//______________________________________________________________________________
310Bool_t AliESDRun::IsTriggerClassFired(ULong64_t mask, const char *name) const
311{
312 // Checks if the trigger class
313 // identified by 'name' has been
314 // fired. Uses the trigger class mask.
315
316 TNamed *trclass = (TNamed *)fTriggerClasses.FindObject(name);
317 if (!trclass) return kFALSE;
318
319 Int_t iclass = fTriggerClasses.IndexOf(trclass);
320 if (iclass < 0) return kFALSE;
321
a62d86d6 322 if (mask & (1ull << iclass))
f009b5c1 323 return kTRUE;
324 else
325 return kFALSE;
326}
33fe5eb1 327
328//_____________________________________________________________________________
329Bool_t AliESDRun::InitMagneticField() const
330{
331 // Create mag field from stored information
332 //
333 if (!TestBit(kBInfoStored)) {
334 AliError("No information on currents, cannot create field from run header");
335 return kFALSE;
336 }
337 //
338 if ( TGeoGlobalMagField::Instance()->IsLocked() ) {
339 if (TGeoGlobalMagField::Instance()->GetField()->TestBit(AliMagF::kOverrideGRP)) {
340 AliInfo("ExpertMode!!! Information on magnet currents will be ignored !");
341 AliInfo("ExpertMode!!! Running with the externally locked B field !");
342 return kTRUE;
343 }
344 else {
345 AliInfo("Destroying existing B field instance!");
346 delete TGeoGlobalMagField::Instance();
347 }
348 }
349 //
350 AliMagF* fld = AliMagF::CreateFieldMap(fCurrentL3,fCurrentDip,AliMagF::kConvLHC,
5cf76849 351 TestBit(kUniformBMap), GetBeamEnergy(), GetBeamType());
33fe5eb1 352 if (fld) {
353 TGeoGlobalMagField::Instance()->SetField( fld );
354 TGeoGlobalMagField::Instance()->Lock();
355 AliInfo("Running with the B field constructed out of the Run Header !");
356 return kTRUE;
357 }
358 else {
359 AliError("Failed to create a B field map !");
360 return kFALSE;
361 }
362 //
363}
d443e5e9 364
365//_____________________________________________________________________________
366void AliESDRun::SetT0spread(Int_t i,Float_t t)
367{
368 //
369 // Setting the T0 spread value at index i
370 //
371
372 if ( (i>=0) && (i<kT0spreadSize)) {
373 fT0spread[i]=t;
374 } else {
375 AliError(Form("Index %d out of bound",i));
376 }
377 return;
378}
379
380//_____________________________________________________________________________
381void AliESDRun::SetT0spread(Float_t *t)
382{
383 //
384 // Setting the T0 spread values
385 //
386 if (t == 0x0){
387 AliError(Form("Null pointer passed"));
388 }
389 else{
390 for (Int_t i=0;i<kT0spreadSize;i++) fT0spread[i]=t[i];
391 }
392 return;
393}
394