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