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