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