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