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