]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AOD/AliAODHeader.cxx
Made InitMagneticField a virtual method of the AliVEvent
[u/mrichter/AliRoot.git] / STEER / AOD / AliAODHeader.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, 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
16 /* $Id$ */
17
18 //-------------------------------------------------------------------------
19 //     AOD event base class
20 //     Author: Markus Oldenburg, CERN
21 //-------------------------------------------------------------------------
22
23 #include "AliAODHeader.h"
24 #include "AliCentrality.h"
25 #include "AliEventplane.h"
26 #include "AliMagF.h"
27 #include <TGeoGlobalMagField.h>
28 #include <TGeoMatrix.h>
29 #include <TObjString.h>
30
31 ClassImp(AliAODHeader)
32
33 //______________________________________________________________________________
34 AliAODHeader::AliAODHeader() : 
35   AliVHeader(),
36   fMagneticField(-999.),
37   fMuonMagFieldScale(-999.),
38   fCentrality(-999.),
39   fEventplane(-999.),
40   fEventplaneMag(-999.),
41   fEventplaneQx(-999.),
42   fEventplaneQy(-999.),
43   fZDCN1Energy(-999.),
44   fZDCP1Energy(-999.),
45   fZDCN2Energy(-999.),
46   fZDCP2Energy(-999.),
47   fNQTheta(0),
48   fQTheta(0x0),
49   fTriggerMask(0),
50   fFiredTriggers(),
51   fRunNumber(-999),  
52   fRefMult(-999),
53   fRefMultPos(-999),
54   fRefMultNeg(-999),
55   fNMuons(0),
56   fNDimuons(0),
57   fEventType(0),
58   fOrbitNumber(0),
59   fPeriodNumber(0),
60   fBunchCrossNumber(0),
61   fRefMultComb05(-999),
62   fRefMultComb08(-999),
63   fTriggerCluster(0), 
64   fDiamondZ(0.), 
65   fDiamondSig2Z(0.),
66   fOfflineTrigger(0),
67   fESDFileName(""),
68   fEventNumberESDFile(-1),
69   fNumberESDTracks(-1),
70   fL0TriggerInputs(0),
71   fL1TriggerInputs(0),
72   fL2TriggerInputs(0),
73   fTPConlyRefMult(-1), 
74   fCentralityP(0),
75   fEventplaneP(0),
76   fIRInt2InteractionsMap(0),
77   fIRInt1InteractionsMap(0)
78 {
79   // default constructor
80
81   SetName("header");
82   for(int j=0; j<2; j++) fZDCEMEnergy[j] = -999.;
83   for(Int_t i=0; i<2; i++) fDiamondXY[i]=0.;
84   fDiamondCovXY[0]=fDiamondCovXY[2]=3.*3.;
85   fDiamondCovXY[1]=0.;
86   for (Int_t m=0; m<kNPHOSMatrix; m++) fPHOSMatrix[m]=NULL;
87   for (Int_t sm=0; sm<kNEMCALMatrix; sm++) fEMCALMatrix[sm]=NULL;
88   for (Int_t i = 0; i < 6; i++)  fITSClusters[i] = 0;
89   for (Int_t j=0; j<64; ++j) fVZEROEqFactors[j]=-1;
90   for (Int_t i=0; i<kT0SpreadSize;i++) fT0spread[i]=0;
91 }
92
93 //______________________________________________________________________________
94 AliAODHeader::AliAODHeader(Int_t nRun, 
95                            UShort_t nBunchX,
96                            UInt_t nOrbit,
97                            UInt_t nPeriod,
98                            const Char_t *title) :
99   AliVHeader(),
100   fMagneticField(-999.),
101   fMuonMagFieldScale(-999.),
102   fCentrality(-999.),
103   fEventplane(-999.),
104   fEventplaneMag(-999.),
105   fEventplaneQx(-999.),
106   fEventplaneQy(-999.),
107   fZDCN1Energy(-999.),
108   fZDCP1Energy(-999.),
109   fZDCN2Energy(-999.),
110   fZDCP2Energy(-999.),
111   fNQTheta(0),
112   fQTheta(0x0),
113   fTriggerMask(0),
114   fFiredTriggers(),
115   fRunNumber(nRun),
116   fRefMult(-999),
117   fRefMultPos(-999),
118   fRefMultNeg(-999),
119   fNMuons(0),
120   fNDimuons(0),
121   fEventType(0),
122   fOrbitNumber(nOrbit),
123   fPeriodNumber(nPeriod),
124   fBunchCrossNumber(nBunchX),
125   fRefMultComb05(-999),
126   fRefMultComb08(-999),
127   fTriggerCluster(0), 
128   fDiamondZ(0.), 
129   fDiamondSig2Z(0.),
130   fOfflineTrigger(0),
131   fESDFileName(""),
132   fEventNumberESDFile(-1),
133   fNumberESDTracks(-1),
134   fL0TriggerInputs(0),
135   fL1TriggerInputs(0),
136   fL2TriggerInputs(0),
137   fTPConlyRefMult(-1), 
138   fCentralityP(0),
139   fEventplaneP(0),
140   fIRInt2InteractionsMap(0),
141   fIRInt1InteractionsMap(0)
142 {
143   // constructor
144
145   SetName("header");
146   SetTitle(title);
147   for(int j=0; j<2; j++) fZDCEMEnergy[j] = -999.;
148   for(Int_t i=0; i<2; i++) fDiamondXY[i]=0.;
149   fDiamondCovXY[0]=fDiamondCovXY[2]=3.*3.;
150   fDiamondCovXY[1]=0.;
151   for (Int_t m=0; m<kNPHOSMatrix; m++) fPHOSMatrix[m]=NULL;
152   for (Int_t sm=0; sm<kNEMCALMatrix; sm++) fEMCALMatrix[sm]=NULL;
153   for (Int_t j=0; j<64; ++j) fVZEROEqFactors[j]=-1;
154   for (Int_t i=0; i<kT0SpreadSize;i++) fT0spread[i]=0;
155 }
156
157 //______________________________________________________________________________
158 AliAODHeader::AliAODHeader(Int_t nRun, 
159                            UShort_t nBunchX,
160                            UInt_t nOrbit,
161                            UInt_t nPeriod,
162                            Int_t refMult,
163                            Int_t refMultPos,
164                            Int_t refMultNeg,
165                            Int_t refMultComb05,
166                            Int_t refMultComb08,
167                            Double_t magField,
168                            Double_t muonMagFieldScale,
169                            Double_t cent,
170                            Double_t eventplane,
171                            Double_t n1Energy,
172                            Double_t p1Energy,
173                            Double_t n2Energy,
174                            Double_t p2Energy,
175                            Double_t *emEnergy,
176                            ULong64_t trigMask,
177                            UChar_t trigClus,
178                            UInt_t evttype,
179                            const Float_t *vzeroEqFactors,
180                            const Char_t *title,
181                            Int_t nMuons,
182                            Int_t nDimuons) :
183   AliVHeader(),
184   fMagneticField(magField),
185   fMuonMagFieldScale(muonMagFieldScale),
186   fCentrality(cent),
187   fEventplane(eventplane),
188   fEventplaneMag(0),
189   fEventplaneQx(0),
190   fEventplaneQy(0),
191   fZDCN1Energy(n1Energy),
192   fZDCP1Energy(p1Energy),
193   fZDCN2Energy(n2Energy),
194   fZDCP2Energy(p2Energy),
195   fNQTheta(0),
196   fQTheta(0x0),
197   fTriggerMask(trigMask),
198   fFiredTriggers(),
199   fRunNumber(nRun),  
200   fRefMult(refMult),
201   fRefMultPos(refMultPos),
202   fRefMultNeg(refMultNeg),
203   fNMuons(nMuons),
204   fNDimuons(nDimuons),
205   fEventType(evttype),
206   fOrbitNumber(nOrbit),
207   fPeriodNumber(nPeriod),
208   fBunchCrossNumber(nBunchX),
209   fRefMultComb05(refMultComb05),
210   fRefMultComb08(refMultComb08),
211   fTriggerCluster(trigClus),
212   fDiamondZ(0.), 
213   fDiamondSig2Z(0.),
214   fOfflineTrigger(0),
215   fESDFileName(""),
216   fEventNumberESDFile(-1),
217   fNumberESDTracks(-1),
218   fL0TriggerInputs(0),
219   fL1TriggerInputs(0),
220   fL2TriggerInputs(0),
221   fTPConlyRefMult(-1), 
222   fCentralityP(0),
223   fEventplaneP(0),
224   fIRInt2InteractionsMap(0),
225   fIRInt1InteractionsMap(0)
226 {
227   // constructor
228
229   SetName("header");
230   SetTitle(title);
231   for(int j=0; j<2; j++) fZDCEMEnergy[j] = emEnergy[j];
232   for(Int_t i=0; i<2; i++) fDiamondXY[i]=0.;
233   fDiamondCovXY[0]=fDiamondCovXY[2]=3.*3.;
234   fDiamondCovXY[1]=0.;
235   for (Int_t m=0; m<kNPHOSMatrix; m++) fPHOSMatrix[m]=NULL;
236   for (Int_t sm=0; sm<kNEMCALMatrix; sm++) fEMCALMatrix[sm]=NULL;
237   for (Int_t i = 0; i < 6; i++)  fITSClusters[i] = 0;
238   if (vzeroEqFactors) for (Int_t j=0; j<64; ++j) fVZEROEqFactors[j] = vzeroEqFactors[j];
239   for (Int_t i=0; i<kT0SpreadSize;i++) fT0spread[i]=0;
240 }
241
242 //______________________________________________________________________________
243 AliAODHeader::~AliAODHeader() 
244 {
245   // destructor
246   delete fCentralityP;
247   delete fEventplaneP;
248   RemoveQTheta();
249 }
250
251 //______________________________________________________________________________
252 AliAODHeader::AliAODHeader(const AliAODHeader& hdr) :
253   AliVHeader(hdr),
254   fMagneticField(hdr.fMagneticField),
255   fMuonMagFieldScale(hdr.fMuonMagFieldScale),
256   fCentrality(hdr.fCentrality),
257   fEventplane(hdr.fEventplane),
258   fEventplaneMag(hdr.fEventplaneMag),
259   fEventplaneQx(hdr.fEventplaneQx),
260   fEventplaneQy(hdr.fEventplaneQy),
261   fZDCN1Energy(hdr.fZDCN1Energy),
262   fZDCP1Energy(hdr.fZDCP1Energy),
263   fZDCN2Energy(hdr.fZDCN2Energy),
264   fZDCP2Energy(hdr.fZDCP2Energy),
265   fNQTheta(0),
266   fQTheta(0x0),
267   fTriggerMask(hdr.fTriggerMask),
268   fFiredTriggers(hdr.fFiredTriggers),
269   fRunNumber(hdr.fRunNumber),  
270   fRefMult(hdr.fRefMult), 
271   fRefMultPos(hdr.fRefMultPos), 
272   fRefMultNeg(hdr.fRefMultNeg),
273   fNMuons(hdr.fNMuons),
274   fNDimuons(hdr.fNDimuons),
275   fEventType(hdr.fEventType),
276   fOrbitNumber(hdr.fOrbitNumber),
277   fPeriodNumber(hdr.fPeriodNumber),
278   fBunchCrossNumber(hdr.fBunchCrossNumber),
279   fRefMultComb05(hdr.fRefMultComb05), 
280   fRefMultComb08(hdr.fRefMultComb08), 
281   fTriggerCluster(hdr.fTriggerCluster), 
282   fDiamondZ(hdr.fDiamondZ), 
283   fDiamondSig2Z(hdr.fDiamondSig2Z),
284   fOfflineTrigger(hdr.fOfflineTrigger),
285   fESDFileName(hdr.fESDFileName),
286   fEventNumberESDFile(hdr.fEventNumberESDFile),
287   fNumberESDTracks(hdr.fNumberESDTracks),
288   fL0TriggerInputs(hdr.fL0TriggerInputs),
289   fL1TriggerInputs(hdr.fL1TriggerInputs),
290   fL2TriggerInputs(hdr.fL2TriggerInputs),
291   fTPConlyRefMult(hdr.fTPConlyRefMult), 
292   fCentralityP(new AliCentrality(*hdr.fCentralityP)),
293   fEventplaneP(new AliEventplane(*hdr.fEventplaneP)),
294   fIRInt2InteractionsMap(hdr.fIRInt2InteractionsMap),
295   fIRInt1InteractionsMap(hdr.fIRInt1InteractionsMap)
296 {
297   // Copy constructor.
298   
299   SetName(hdr.fName);
300   SetTitle(hdr.fTitle);
301   SetQTheta(hdr.fQTheta, hdr.fNQTheta);
302   SetZDCEMEnergy(hdr.fZDCEMEnergy[0], hdr.fZDCEMEnergy[1]);
303   for(Int_t i=0; i<2; i++) fDiamondXY[i]=hdr.fDiamondXY[i];
304   for(Int_t i=0; i<3; i++) fDiamondCovXY[i]=hdr.fDiamondCovXY[i];
305
306
307   for(Int_t m=0; m<kNPHOSMatrix; m++){
308       if(hdr.fPHOSMatrix[m])
309           fPHOSMatrix[m]=new TGeoHMatrix(*(hdr.fPHOSMatrix[m])) ;
310       else
311           fPHOSMatrix[m]=0;
312   }
313   
314   for(Int_t sm=0; sm<kNEMCALMatrix; sm++){
315       if(hdr.fEMCALMatrix[sm])
316           fEMCALMatrix[sm]=new TGeoHMatrix(*(hdr.fEMCALMatrix[sm])) ;
317       else
318           fEMCALMatrix[sm]=0;
319   }
320   for (Int_t i = 0; i < 6; i++)  fITSClusters[i] = hdr.fITSClusters[i];
321   for (Int_t j=0; j<64; ++j) fVZEROEqFactors[j]=hdr.fVZEROEqFactors[j];
322   for (Int_t i=0; i<kT0SpreadSize;i++) fT0spread[i]=hdr.fT0spread[i];
323
324 }
325
326 //______________________________________________________________________________
327 AliAODHeader& AliAODHeader::operator=(const AliAODHeader& hdr)
328 {
329   // Assignment operator
330   if(this!=&hdr) {
331     
332      AliVHeader::operator=(hdr);
333     
334     fMagneticField    = hdr.fMagneticField;
335     fMuonMagFieldScale= hdr.fMuonMagFieldScale;
336     fCentrality       = hdr.fCentrality;
337     fEventplane       = hdr.fEventplane;
338     fEventplaneMag    = hdr.fEventplaneMag;
339     fEventplaneQx     = hdr.fEventplaneQx;
340     fEventplaneQy     = hdr.fEventplaneQy;
341     fZDCN1Energy      = hdr.fZDCN1Energy;
342     fZDCP1Energy      = hdr.fZDCP1Energy;
343     fZDCN2Energy      = hdr.fZDCN2Energy;
344     fZDCP2Energy      = hdr.fZDCP2Energy;
345     fTriggerMask      = hdr.fTriggerMask;
346     fFiredTriggers    = hdr.fFiredTriggers;
347     fRunNumber        = hdr.fRunNumber;
348     fRefMult          = hdr.fRefMult;
349     fRefMultPos       = hdr.fRefMultPos;
350     fRefMultNeg       = hdr.fRefMultNeg;
351     fEventType        = hdr.fEventType;
352     fOrbitNumber      = hdr.fOrbitNumber;
353     fPeriodNumber     = hdr.fPeriodNumber;
354     fBunchCrossNumber = hdr.fBunchCrossNumber;
355     fRefMultComb05    = hdr.fRefMultComb05;
356     fRefMultComb08    = hdr.fRefMultComb08;
357
358     fTriggerCluster   = hdr.fTriggerCluster;
359     fNMuons           = hdr.fNMuons;
360     fNDimuons         = hdr.fNDimuons;
361     fDiamondZ         = hdr.fDiamondZ;
362     fDiamondSig2Z     = hdr.fDiamondSig2Z;
363     fOfflineTrigger   = hdr.fOfflineTrigger;
364     fESDFileName      = hdr.fESDFileName;
365     fEventNumberESDFile = hdr.fEventNumberESDFile;
366     fNumberESDTracks    = hdr.fNumberESDTracks;
367     fL0TriggerInputs    = hdr.fL0TriggerInputs;
368     fL1TriggerInputs    = hdr.fL1TriggerInputs;
369     fL2TriggerInputs    = hdr.fL2TriggerInputs;
370     fTPConlyRefMult     = hdr.fTPConlyRefMult;
371
372     fIRInt2InteractionsMap  = hdr.fIRInt2InteractionsMap;
373     fIRInt1InteractionsMap  = hdr.fIRInt1InteractionsMap;
374
375     if(hdr.fEventplaneP){
376       if(fEventplaneP)*fEventplaneP = *hdr.fEventplaneP;
377       else fEventplaneP = new AliEventplane(*hdr.fEventplaneP);
378     }
379
380     if(hdr.fCentralityP){
381       if(fCentralityP)*fCentralityP = *hdr.fCentralityP;
382       else fCentralityP = new AliCentrality(*hdr.fCentralityP);
383     }
384
385     SetName(hdr.fName);
386     SetTitle(hdr.fTitle);
387     SetQTheta(hdr.fQTheta, hdr.fNQTheta);
388     SetZDCEMEnergy(hdr.fZDCEMEnergy[0], hdr.fZDCEMEnergy[1]);
389     for(Int_t i=0; i<2; i++) fDiamondXY[i]=hdr.fDiamondXY[i];
390     for(Int_t i=0; i<3; i++) fDiamondCovXY[i]=hdr.fDiamondCovXY[i];
391
392     for(Int_t m=0; m<kNPHOSMatrix; m++){
393       if(hdr.fPHOSMatrix[m]){
394         if(fPHOSMatrix[m])delete fPHOSMatrix[m];
395         fPHOSMatrix[m]=new TGeoHMatrix(*(hdr.fPHOSMatrix[m])) ;
396       }
397       else
398         fPHOSMatrix[m]=0;
399     }
400     
401     for(Int_t sm=0; sm<kNEMCALMatrix; sm++){
402       if(hdr.fEMCALMatrix[sm]){
403         if(fEMCALMatrix[sm])delete fEMCALMatrix[sm];
404         fEMCALMatrix[sm]=new TGeoHMatrix(*(hdr.fEMCALMatrix[sm])) ;
405       }
406       else
407         fEMCALMatrix[sm]=0;
408     }
409     
410   }
411
412   for (Int_t i = 0; i < 6; i++)  fITSClusters[i] = hdr.fITSClusters[i];
413   for (Int_t j=0; j<64; ++j) fVZEROEqFactors[j] = hdr.fVZEROEqFactors[j];
414   for (Int_t i=0; i<kT0SpreadSize;i++) fT0spread[i]=hdr.fT0spread[i];
415
416   return *this;
417 }
418
419 //______________________________________________________________________________
420 void AliAODHeader::SetQTheta(Double_t *QTheta, UInt_t size) 
421 {
422   if (QTheta && size>0) {
423     if (size != (UInt_t)fNQTheta) {
424       RemoveQTheta();
425       fNQTheta = size;
426       fQTheta = new Double_t[fNQTheta];
427     }
428     
429     for (Int_t i = 0; i < fNQTheta; i++) {
430       fQTheta[i] = QTheta[i];
431     }
432   } else {
433     RemoveQTheta();
434   }
435
436   return;
437 }
438
439 //______________________________________________________________________________
440 Double_t AliAODHeader::GetQTheta(UInt_t i) const
441 {
442   if (fQTheta && i < (UInt_t)fNQTheta) {
443     return fQTheta[i];
444   } else {
445     return -999.;
446   }
447 }
448
449 //______________________________________________________________________________
450 void AliAODHeader::RemoveQTheta()
451 {
452   delete[] fQTheta;
453   fQTheta = 0x0;
454   fNQTheta = 0;
455
456   return;
457 }
458
459 void AliAODHeader::Clear(Option_t* /*opt*/)
460 {
461 // Clear memory
462   RemoveQTheta();
463   if (fCentralityP){
464     delete fCentralityP;
465     fCentralityP = 0;
466     fCentrality = -999;
467   }
468   if (fEventplaneP){
469     delete fEventplaneP;
470     fEventplaneP = 0;
471     fEventplane = -999;
472     fEventplaneMag = -999.;
473     fEventplaneQx = -999.;
474     fEventplaneQy = -999.;
475   }
476   return;
477 }
478
479 //______________________________________________________________________________
480 void AliAODHeader::Print(Option_t* /*option*/) const 
481 {
482   // prints event information
483
484   printf("Run #                   : %d\n", fRunNumber);
485   printf("Bunch Crossing  #       : %d\n", fBunchCrossNumber);
486   printf("Orbit Number #          : %d\n", fOrbitNumber);
487   printf("Period Number #         : %d\n", fPeriodNumber);
488   printf("Trigger mask            : %lld\n", fTriggerMask);
489   printf("Trigger cluster         : %d\n", fTriggerCluster);
490   printf("Event Type              : %d\n", fEventType);
491   printf("Magnetic field          : %f\n", fMagneticField);
492   printf("Muon mag. field scale   : %f\n", fMuonMagFieldScale);
493   
494   printf("Centrality              : %f\n", fCentrality);
495   printf("Event plane Ang         : %f\n", fEventplane);
496   printf("Event plane Mag         : %f\n", fEventplaneMag);
497   printf("Event plane Qx          : %f\n", fEventplaneQx);
498   printf("Event plane Qy          : %f\n", fEventplaneQy);
499   printf("ZDC N1 Energy           : %f\n", fZDCN1Energy);
500   printf("ZDC P1 Energy           : %f\n", fZDCP1Energy);
501   printf("ZDC N2 Energy           : %f\n", fZDCN2Energy);
502   printf("ZDC P2 Energy           : %f\n", fZDCP2Energy);
503   printf("ZDC EM1 Energy          : %f\n", fZDCEMEnergy[0]);
504   printf("ZDC EM2 Energy          : %f\n", fZDCEMEnergy[1]);
505   printf("ref. Multiplicity       : %d\n", fRefMult);
506   printf("ref. Multiplicity (pos) : %d\n", fRefMultPos);
507   printf("ref. Multiplicity (neg) : %d\n", fRefMultNeg);
508   printf("ref. Mult.Comb |eta|<.5 : %d\n", fRefMultComb05);
509   printf("ref. Mult.Comb |eta|<.8 : %d\n", fRefMultComb08);
510   printf("number of muons         : %d\n", fNMuons);
511   printf("number of dimuons       : %d\n", fNDimuons);
512   printf("offline trigger         : %u\n", fOfflineTrigger);
513
514   if (fQTheta) {
515     for (UInt_t i = 0; i<(UInt_t)fNQTheta; i++) {
516       printf("QTheta[%d]              : %13.3e\n", i, GetQTheta(i));
517     }
518   }
519   printf("V0 Eq factors: ");
520   for (Int_t j=0; j<64; ++j) printf(" %.3f",fVZEROEqFactors[j]);
521   printf("\n");
522
523   return;
524 }
525
526 //__________________________________________________________________________
527 Int_t AliAODHeader::FindIRIntInteractionsBXMap(Int_t difference) const
528 {
529   //
530   // The mapping is of 181 bits, from -90 to +90
531   //
532   Int_t bin=-1;
533
534   if(difference<-90 || difference>90) return bin;
535   else { bin = 90 + difference; }
536   
537   return bin;
538 }
539
540 //__________________________________________________________________________
541 Int_t AliAODHeader::GetIRInt2ClosestInteractionMap() const
542 {
543   //
544   // Calculation of the closest interaction
545   //
546   Int_t firstNegative=100;
547   for(Int_t item=-1; item>=-90; item--) {
548     Int_t bin = FindIRIntInteractionsBXMap(item);
549     Bool_t isFired = fIRInt2InteractionsMap.TestBitNumber(bin);
550     if(isFired) {
551       firstNegative = item;
552       break;
553     }
554   }
555   Int_t firstPositive=100;
556   for(Int_t item=1; item<=90; item++) {
557     Int_t bin = FindIRIntInteractionsBXMap(item);
558     Bool_t isFired = fIRInt2InteractionsMap.TestBitNumber(bin);
559     if(isFired) {
560       firstPositive = item;
561       break;
562     }
563   }
564
565   Int_t closest = firstPositive < TMath::Abs(firstNegative) ? firstPositive : TMath::Abs(firstNegative);
566   if(firstPositive==100 && firstNegative==100) closest=0;
567   return closest;
568 }
569
570 //__________________________________________________________________________
571 Int_t AliAODHeader::GetIRInt1ClosestInteractionMap(Int_t gap) const
572 {
573   //
574   // Calculation of the closest interaction
575   // In case of VZERO (Int1) one has to introduce a gap
576   // in order to avoid false positivies from after-pulses
577
578   Int_t firstNegative=100;
579   for(Int_t item=-1; item>=-90; item--) {
580     Int_t bin = FindIRIntInteractionsBXMap(item);
581     Bool_t isFired = fIRInt1InteractionsMap.TestBitNumber(bin);
582     if(isFired) {
583       firstNegative = item;
584       break;
585     }
586   }
587   Int_t firstPositive=100;
588   for(Int_t item=1+gap; item<=90; item++) {
589     Int_t bin = FindIRIntInteractionsBXMap(item);
590     Bool_t isFired = fIRInt1InteractionsMap.TestBitNumber(bin);
591     if(isFired) {
592       firstPositive = item;
593       break;
594     }
595   }
596
597   Int_t closest = firstPositive < TMath::Abs(firstNegative) ? firstPositive : TMath::Abs(firstNegative);
598   if(firstPositive==100 && firstNegative==100) closest=0;
599   return closest;
600 }
601
602 //__________________________________________________________________________
603 Int_t AliAODHeader::GetIRInt2LastInteractionMap() const
604 {
605   //
606   // Calculation of the last interaction
607   //
608   Int_t lastNegative=0;
609   for(Int_t item=-90; item<=-1; item++) {
610     Int_t bin = FindIRIntInteractionsBXMap(item);
611     Bool_t isFired = fIRInt2InteractionsMap.TestBitNumber(bin);
612     if(isFired) {
613       lastNegative = item;
614       break;
615     }
616   }
617   Int_t lastPositive=0;
618   for(Int_t item=90; item>=1; item--) {
619     Int_t bin = FindIRIntInteractionsBXMap(item);
620     Bool_t isFired = fIRInt2InteractionsMap.TestBitNumber(bin);
621     if(isFired) {
622       lastPositive = item;
623       break;
624     }
625   }
626
627   Int_t last = lastPositive > TMath::Abs(lastNegative) ? lastPositive : TMath::Abs(lastNegative);
628   return last;
629 }
630
631 //__________________________________________________________________________
632 Bool_t AliAODHeader::InitMagneticField() const
633 {
634   // Create mag field from stored information
635   //
636   const double def5kg = 5.00667905807495117e+00;
637   const double def2kg = 2.04487347602844238e+00;
638   //
639   AliMagF* fld = (AliMagF*) TGeoGlobalMagField::Instance()->GetField();
640   if (fld) {
641     if (TGeoGlobalMagField::Instance()->IsLocked()) {
642       if (fld->TestBit(AliMagF::kOverrideGRP)) {
643         AliInfo("ExpertMode!!! Information on magnet currents will be ignored !");
644         AliInfo("ExpertMode!!! Running with the externally locked B field !");
645         return kTRUE;
646       }
647     }
648     AliInfo("Destroying existing B field instance!");
649     delete TGeoGlobalMagField::Instance();
650   }
651   //
652   double fc5 = fMagneticField/def5kg;
653   double fc2 = fMagneticField/def2kg;
654   Bool_t use5 = TMath::Abs(TMath::Abs(fc5)-1.) < TMath::Abs(TMath::Abs(fc2)-1.);
655   //
656   fld = new AliMagF("mag","mag",use5 ? fc5 : fc2, fMuonMagFieldScale, use5 ? AliMagF::k5kG : AliMagF::k2kG);
657   //
658   if (fld) {
659     TGeoGlobalMagField::Instance()->SetField( fld );
660     TGeoGlobalMagField::Instance()->Lock();
661     AliInfo("Running with the B field constructed out of the AOD Header !");
662     return kTRUE;
663   }
664   else {
665     AliError("Failed to create a B field map !");
666     return kFALSE;
667   }
668   //
669 }