fixing mem leak in operator=
[u/mrichter/AliRoot.git] / STEER / 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 <TGeoMatrix.h>
27 #include <TObjString.h>
28
29 ClassImp(AliAODHeader)
30
31 //______________________________________________________________________________
32 AliAODHeader::AliAODHeader() : 
33   AliVHeader(),
34   fMagneticField(-999.),
35   fMuonMagFieldScale(-999.),
36   fCentrality(-999.),
37   fEventplane(-999.),
38   fZDCN1Energy(-999.),
39   fZDCP1Energy(-999.),
40   fZDCN2Energy(-999.),
41   fZDCP2Energy(-999.),
42   fNQTheta(0),
43   fQTheta(0x0),
44   fTriggerMask(0),
45   fFiredTriggers(),
46   fRunNumber(-999),  
47   fRefMult(-999),
48   fRefMultPos(-999),
49   fRefMultNeg(-999),
50   fNMuons(0),
51   fNDimuons(0),
52   fEventType(0),
53   fOrbitNumber(0),
54   fPeriodNumber(0),
55   fBunchCrossNumber(0),
56   fTriggerCluster(0), 
57   fDiamondZ(0.), 
58   fDiamondSig2Z(0.),
59   fOfflineTrigger(0),
60   fESDFileName(""),
61   fEventNumberESDFile(-1),
62   fL0TriggerInputs(0),
63   fL1TriggerInputs(0),
64   fL2TriggerInputs(0),
65   fCentralityP(0),
66   fEventplaneP(0)
67 {
68   // default constructor
69
70   SetName("header");
71   for(int j=0; j<2; j++) fZDCEMEnergy[j] = -999.;
72   for(Int_t i=0; i<2; i++) fDiamondXY[i]=0.;
73   fDiamondCovXY[0]=fDiamondCovXY[2]=3.*3.;
74   fDiamondCovXY[1]=0.;
75   for (Int_t m=0; m<kNPHOSMatrix; m++) fPHOSMatrix[m]=NULL;
76   for (Int_t sm=0; sm<kNEMCALMatrix; sm++) fEMCALMatrix[sm]=NULL;
77 }
78
79 //______________________________________________________________________________
80 AliAODHeader::AliAODHeader(Int_t nRun, 
81                            UShort_t nBunchX,
82                            UInt_t nOrbit,
83                            UInt_t nPeriod,
84                            const Char_t *title) :
85   AliVHeader(),
86   fMagneticField(-999.),
87   fMuonMagFieldScale(-999.),
88   fCentrality(-999.),
89   fEventplane(-999.),
90   fZDCN1Energy(-999.),
91   fZDCP1Energy(-999.),
92   fZDCN2Energy(-999.),
93   fZDCP2Energy(-999.),
94   fNQTheta(0),
95   fQTheta(0x0),
96   fTriggerMask(0),
97   fFiredTriggers(),
98   fRunNumber(nRun),
99   fRefMult(-999),
100   fRefMultPos(-999),
101   fRefMultNeg(-999),
102   fNMuons(0),
103   fNDimuons(0),
104   fEventType(0),
105   fOrbitNumber(nOrbit),
106   fPeriodNumber(nPeriod),
107   fBunchCrossNumber(nBunchX),
108   fTriggerCluster(0), 
109   fDiamondZ(0.), 
110   fDiamondSig2Z(0.),
111   fOfflineTrigger(0),
112   fESDFileName(""),
113   fEventNumberESDFile(-1),
114   fL0TriggerInputs(0),
115   fL1TriggerInputs(0),
116   fL2TriggerInputs(0),
117   fCentralityP(0),
118   fEventplaneP(0)
119 {
120   // constructor
121
122   SetName("header");
123   SetTitle(title);
124   for(int j=0; j<2; j++) fZDCEMEnergy[j] = -999.;
125   for(Int_t i=0; i<2; i++) fDiamondXY[i]=0.;
126   fDiamondCovXY[0]=fDiamondCovXY[2]=3.*3.;
127   fDiamondCovXY[1]=0.;
128   for (Int_t m=0; m<kNPHOSMatrix; m++) fPHOSMatrix[m]=NULL;
129   for (Int_t sm=0; sm<kNEMCALMatrix; sm++) fEMCALMatrix[sm]=NULL;
130 }
131
132 //______________________________________________________________________________
133 AliAODHeader::AliAODHeader(Int_t nRun, 
134                            UShort_t nBunchX,
135                            UInt_t nOrbit,
136                            UInt_t nPeriod,
137                            Int_t refMult,
138                            Int_t refMultPos,
139                            Int_t refMultNeg,
140                            Double_t magField,
141                            Double_t muonMagFieldScale,
142                            Double_t cent,
143                            Double_t eventplane,
144                            Double_t n1Energy,
145                            Double_t p1Energy,
146                            Double_t n2Energy,
147                            Double_t p2Energy,
148                            Double_t *emEnergy,
149                            ULong64_t trigMask,
150                            UChar_t trigClus,
151                            UInt_t evttype,
152                            const Char_t *title,
153                            Int_t nMuons,
154                            Int_t nDimuons) :
155   AliVHeader(),
156   fMagneticField(magField),
157   fMuonMagFieldScale(muonMagFieldScale),
158   fCentrality(cent),
159   fEventplane(eventplane),
160   fZDCN1Energy(n1Energy),
161   fZDCP1Energy(p1Energy),
162   fZDCN2Energy(n2Energy),
163   fZDCP2Energy(p2Energy),
164   fNQTheta(0),
165   fQTheta(0x0),
166   fTriggerMask(trigMask),
167   fFiredTriggers(),
168   fRunNumber(nRun),  
169   fRefMult(refMult),
170   fRefMultPos(refMultPos),
171   fRefMultNeg(refMultNeg),
172   fNMuons(nMuons),
173   fNDimuons(nDimuons),
174   fEventType(evttype),
175   fOrbitNumber(nOrbit),
176   fPeriodNumber(nPeriod),
177   fBunchCrossNumber(nBunchX),
178   fTriggerCluster(trigClus),
179   fDiamondZ(0.), 
180   fDiamondSig2Z(0.),
181   fOfflineTrigger(0),
182   fESDFileName(""),
183   fEventNumberESDFile(-1),
184   fL0TriggerInputs(0),
185   fL1TriggerInputs(0),
186   fL2TriggerInputs(0),
187   fCentralityP(0),
188   fEventplaneP(0)
189 {
190   // constructor
191
192   SetName("header");
193   SetTitle(title);
194   for(int j=0; j<2; j++) fZDCEMEnergy[j] = emEnergy[j];
195   for(Int_t i=0; i<2; i++) fDiamondXY[i]=0.;
196   fDiamondCovXY[0]=fDiamondCovXY[2]=3.*3.;
197   fDiamondCovXY[1]=0.;
198   for (Int_t m=0; m<kNPHOSMatrix; m++) fPHOSMatrix[m]=NULL;
199   for (Int_t sm=0; sm<kNEMCALMatrix; sm++) fEMCALMatrix[sm]=NULL;
200 }
201
202 //______________________________________________________________________________
203 AliAODHeader::~AliAODHeader() 
204 {
205   // destructor
206   delete fCentralityP;
207   delete fEventplaneP;
208   RemoveQTheta();
209 }
210
211 //______________________________________________________________________________
212 AliAODHeader::AliAODHeader(const AliAODHeader& hdr) :
213   AliVHeader(hdr),
214   fMagneticField(hdr.fMagneticField),
215   fMuonMagFieldScale(hdr.fMuonMagFieldScale),
216   fCentrality(hdr.fCentrality),
217   fEventplane(hdr.fEventplane),
218   fZDCN1Energy(hdr.fZDCN1Energy),
219   fZDCP1Energy(hdr.fZDCP1Energy),
220   fZDCN2Energy(hdr.fZDCN2Energy),
221   fZDCP2Energy(hdr.fZDCP2Energy),
222   fNQTheta(0),
223   fQTheta(0x0),
224   fTriggerMask(hdr.fTriggerMask),
225   fFiredTriggers(hdr.fFiredTriggers),
226   fRunNumber(hdr.fRunNumber),  
227   fRefMult(hdr.fRefMult), 
228   fRefMultPos(hdr.fRefMultPos), 
229   fRefMultNeg(hdr.fRefMultNeg),
230   fNMuons(hdr.fNMuons),
231   fNDimuons(hdr.fNDimuons),
232   fEventType(hdr.fEventType),
233   fOrbitNumber(hdr.fOrbitNumber),
234   fPeriodNumber(hdr.fPeriodNumber),
235   fBunchCrossNumber(hdr.fBunchCrossNumber),
236   fTriggerCluster(hdr.fTriggerCluster), 
237   fDiamondZ(hdr.fDiamondZ), 
238   fDiamondSig2Z(hdr.fDiamondSig2Z),
239   fOfflineTrigger(hdr.fOfflineTrigger),
240   fESDFileName(hdr.fESDFileName),
241   fEventNumberESDFile(hdr.fEventNumberESDFile),
242   fL0TriggerInputs(hdr.fL0TriggerInputs),
243   fL1TriggerInputs(hdr.fL1TriggerInputs),
244   fL2TriggerInputs(hdr.fL2TriggerInputs),
245   fCentralityP(new AliCentrality(*hdr.fCentralityP)),
246   fEventplaneP(new AliEventplane(*hdr.fEventplaneP))
247 {
248   // Copy constructor.
249   
250   SetName(hdr.fName);
251   SetTitle(hdr.fTitle);
252   SetQTheta(hdr.fQTheta, hdr.fNQTheta);
253   SetZDCEMEnergy(hdr.fZDCEMEnergy[0], hdr.fZDCEMEnergy[1]);
254   for(Int_t i=0; i<2; i++) fDiamondXY[i]=hdr.fDiamondXY[i];
255   for(Int_t i=0; i<3; i++) fDiamondCovXY[i]=hdr.fDiamondCovXY[i];
256
257
258   for(Int_t m=0; m<kNPHOSMatrix; m++){
259       if(hdr.fPHOSMatrix[m])
260           fPHOSMatrix[m]=new TGeoHMatrix(*(hdr.fPHOSMatrix[m])) ;
261       else
262           fPHOSMatrix[m]=0;
263   }
264   
265   for(Int_t sm=0; sm<kNEMCALMatrix; sm++){
266       if(hdr.fEMCALMatrix[sm])
267           fEMCALMatrix[sm]=new TGeoHMatrix(*(hdr.fEMCALMatrix[sm])) ;
268       else
269           fEMCALMatrix[sm]=0;
270   }
271
272 }
273
274 //______________________________________________________________________________
275 AliAODHeader& AliAODHeader::operator=(const AliAODHeader& hdr)
276 {
277   // Assignment operator
278   if(this!=&hdr) {
279     
280      AliVHeader::operator=(hdr);
281     
282     fMagneticField    = hdr.fMagneticField;
283     fMuonMagFieldScale= hdr.fMuonMagFieldScale;
284     fCentrality       = hdr.fCentrality;
285     fEventplane       = hdr.fEventplane;
286     fZDCN1Energy      = hdr.fZDCN1Energy;
287     fZDCP1Energy      = hdr.fZDCP1Energy;
288     fZDCN2Energy      = hdr.fZDCN2Energy;
289     fZDCP2Energy      = hdr.fZDCP2Energy;
290     fTriggerMask      = hdr.fTriggerMask;
291     fFiredTriggers    = hdr.fFiredTriggers;
292     fRunNumber        = hdr.fRunNumber;
293     fRefMult          = hdr.fRefMult;
294     fRefMultPos       = hdr.fRefMultPos;
295     fRefMultNeg       = hdr.fRefMultNeg;
296     fEventType        = hdr.fEventType;
297     fOrbitNumber      = hdr.fOrbitNumber;
298     fPeriodNumber     = hdr.fPeriodNumber;
299     fBunchCrossNumber = hdr.fBunchCrossNumber;
300     fTriggerCluster   = hdr.fTriggerCluster;
301     fNMuons           = hdr.fNMuons;
302     fNDimuons         = hdr.fNDimuons;
303     fDiamondZ         = hdr.fDiamondZ;
304     fDiamondSig2Z     = hdr.fDiamondSig2Z;
305     fOfflineTrigger   = hdr.fOfflineTrigger;
306     fESDFileName      = hdr.fESDFileName;
307     fEventNumberESDFile = hdr.fEventNumberESDFile;
308     fL0TriggerInputs    = hdr.fL0TriggerInputs;
309     fL1TriggerInputs    = hdr.fL1TriggerInputs;
310     fL2TriggerInputs    = hdr.fL2TriggerInputs;
311     fEventplaneP        = new AliEventplane(*hdr.fEventplaneP);
312
313     if(hdr.fCentralityP){
314       if(fCentralityP)*fCentralityP = *hdr.fCentralityP;
315       else fCentralityP = new AliCentrality(*hdr.fCentralityP);
316     }
317
318     SetName(hdr.fName);
319     SetTitle(hdr.fTitle);
320     SetQTheta(hdr.fQTheta, hdr.fNQTheta);
321     SetZDCEMEnergy(hdr.fZDCEMEnergy[0], hdr.fZDCEMEnergy[1]);
322     for(Int_t i=0; i<2; i++) fDiamondXY[i]=hdr.fDiamondXY[i];
323     for(Int_t i=0; i<3; i++) fDiamondCovXY[i]=hdr.fDiamondCovXY[i];
324
325     for(Int_t m=0; m<kNPHOSMatrix; m++){
326       if(hdr.fPHOSMatrix[m]){
327         if(fPHOSMatrix[m])delete fPHOSMatrix[m];
328         fPHOSMatrix[m]=new TGeoHMatrix(*(hdr.fPHOSMatrix[m])) ;
329       }
330       else
331         fPHOSMatrix[m]=0;
332     }
333     
334     for(Int_t sm=0; sm<kNEMCALMatrix; sm++){
335       if(hdr.fEMCALMatrix[sm]){
336         if(fEMCALMatrix[sm])delete fEMCALMatrix[sm];
337         fEMCALMatrix[sm]=new TGeoHMatrix(*(hdr.fEMCALMatrix[sm])) ;
338       }
339       else
340         fEMCALMatrix[sm]=0;
341     }
342     
343   }
344
345
346   return *this;
347 }
348
349 //______________________________________________________________________________
350 void AliAODHeader::SetQTheta(Double_t *QTheta, UInt_t size) 
351 {
352   if (QTheta && size>0) {
353     if (size != (UInt_t)fNQTheta) {
354       RemoveQTheta();
355       fNQTheta = size;
356       fQTheta = new Double_t[fNQTheta];
357     }
358     
359     for (Int_t i = 0; i < fNQTheta; i++) {
360       fQTheta[i] = QTheta[i];
361     }
362   } else {
363     RemoveQTheta();
364   }
365
366   return;
367 }
368
369 //______________________________________________________________________________
370 Double_t AliAODHeader::GetQTheta(UInt_t i) const
371 {
372   if (fQTheta && i < (UInt_t)fNQTheta) {
373     return fQTheta[i];
374   } else {
375     return -999.;
376   }
377 }
378
379 //______________________________________________________________________________
380 void AliAODHeader::RemoveQTheta()
381 {
382   delete[] fQTheta;
383   fQTheta = 0x0;
384   fNQTheta = 0;
385
386   return;
387 }
388
389 void AliAODHeader::Clear(Option_t* /*opt*/)
390 {
391 // Clear memory
392   RemoveQTheta();
393   if (fCentralityP){
394     delete fCentralityP;
395     fCentralityP = 0;
396     fCentrality = -999;
397   }
398   if (fEventplaneP){
399     delete fEventplaneP;
400     fEventplaneP = 0;
401     fEventplane = -999;
402   }
403   return;
404 }
405
406 //______________________________________________________________________________
407 void AliAODHeader::Print(Option_t* /*option*/) const 
408 {
409   // prints event information
410
411   printf("Run #                   : %d\n", fRunNumber);
412   printf("Bunch Crossing  #       : %d\n", fBunchCrossNumber);
413   printf("Orbit Number #          : %d\n", fOrbitNumber);
414   printf("Period Number #         : %d\n", fPeriodNumber);
415   printf("Trigger mask            : %lld\n", fTriggerMask);
416   printf("Trigger cluster         : %d\n", fTriggerCluster);
417   printf("Event Type              : %d\n", fEventType);
418   printf("Magnetic field          : %f\n", fMagneticField);
419   printf("Muon mag. field scale   : %f\n", fMuonMagFieldScale);
420   
421   printf("Centrality              : %f\n", fCentrality);
422   printf("Event plane             : %f\n", fEventplane);
423   printf("ZDC N1 Energy           : %f\n", fZDCN1Energy);
424   printf("ZDC P1 Energy           : %f\n", fZDCP1Energy);
425   printf("ZDC N2 Energy           : %f\n", fZDCN2Energy);
426   printf("ZDC P2 Energy           : %f\n", fZDCP2Energy);
427   printf("ZDC EM1 Energy          : %f\n", fZDCEMEnergy[0]);
428   printf("ZDC EM2 Energy          : %f\n", fZDCEMEnergy[1]);
429   printf("ref. Multiplicity       : %d\n", fRefMult);
430   printf("ref. Multiplicity (pos) : %d\n", fRefMultPos);
431   printf("ref. Multiplicity (neg) : %d\n", fRefMultNeg);
432   printf("number of muons         : %d\n", fNMuons);
433   printf("number of dimuons       : %d\n", fNDimuons);
434   printf("offline trigger         : %u\n", fOfflineTrigger);
435
436   if (fQTheta) {
437     for (UInt_t i = 0; i<(UInt_t)fNQTheta; i++) {
438       printf("QTheta[%d]              : %13.3e\n", i, GetQTheta(i));
439     }
440   }
441
442   return;
443 }