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