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