]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESD.cxx
Using AliPHOSLoader instead of AliPHOSGetter
[u/mrichter/AliRoot.git] / STEER / AliESD.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
16 /* $Id$ */
17
18 //-----------------------------------------------------------------
19 //           Implementation of the ESD class
20 //   This is the class to deal with during the phisical analysis of data
21 //   This class is generated directly by the reconstruction methods
22 //      Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
23 //-----------------------------------------------------------------
24
25 #include "AliESD.h"
26 #include "AliESDfriend.h"
27
28 ClassImp(AliESD)
29
30 //______________________________________________________________________________
31 AliESD::AliESD():
32   fEventNumberInFile(0),
33   fBunchCrossNumber(0),
34   fOrbitNumber(0),
35   fPeriodNumber(0),
36   fRunNumber(0),
37   fTimeStamp(0),
38   fEventType(0),
39   fTriggerMask(0),
40   fTriggerCluster(0),
41   fRecoVersion(0),
42   fMagneticField(0),
43   fZDCN1Energy(0),
44   fZDCP1Energy(0),
45   fZDCN2Energy(0),
46   fZDCP2Energy(0),
47   fZDCEMEnergy(0),
48   fZDCParticipants(0),
49   fT0zVertex(0),
50   fSPDVertex(),
51   fPrimaryVertex(),
52   fSPDMult(),
53   fT0timeStart(0),
54   fTracks("AliESDtrack",15000),
55   fHLTConfMapTracks("AliESDHLTtrack",25000),
56   fHLTHoughTracks("AliESDHLTtrack",15000),
57   fMuonTracks("AliESDMuonTrack",30),
58   fPmdTracks("AliESDPmdTrack",3000),
59   fTrdTracks("AliESDTrdTrack",300),
60   fV0s("AliESDv0",200),  
61   fCascades("AliESDcascade",20),
62   fKinks("AliESDkink",4000),
63   fCaloClusters("AliESDCaloCluster",10000),
64   fEMCALClusters(0), 
65   fFirstEMCALCluster(-1),
66   fEMCALTriggerPosition(0x0),
67   fEMCALTriggerAmplitudes(0x0),
68   fPHOSClusters(0), 
69   fFirstPHOSCluster(-1),
70   fPHOSTriggerPosition(0x0),
71   fPHOSTriggerAmplitudes(0x0),
72   fESDFMD(0x0),
73   fESDVZERO(0x0),
74   fErrorLogs("AliRawDataErrorLog",5)
75 {
76   // 
77   // Standar constructor
78   //
79
80   for (Int_t i=0; i<24; i++) {
81     fT0time[i] = 0;
82     fT0amplitude[i] = 0;
83   }
84   for (Int_t i=0; i<2; i++) fDiamondXY[i]=0.;
85   for (Int_t i=0; i<3; i++) fDiamondCovXY[i]=0.;
86 }
87
88 //______________________________________________________________________________
89 AliESD::AliESD(const AliESD& esd):
90   TObject(esd),
91   fEventNumberInFile(esd.fEventNumberInFile),
92   fBunchCrossNumber(esd.fBunchCrossNumber),
93   fOrbitNumber(esd.fOrbitNumber),
94   fPeriodNumber(esd.fPeriodNumber),
95   fRunNumber(esd.fRunNumber),
96   fTimeStamp(esd.fTimeStamp),
97   fEventType(esd.fEventType),
98   fTriggerMask(esd.fTriggerMask),
99   fTriggerCluster(esd.fTriggerCluster),
100   fRecoVersion(esd.fRecoVersion),
101   fMagneticField(esd.fMagneticField),
102   fZDCN1Energy(esd.fZDCN1Energy),
103   fZDCP1Energy(esd.fZDCP1Energy),
104   fZDCN2Energy(esd.fZDCN2Energy),
105   fZDCP2Energy(esd.fZDCP2Energy),
106   fZDCEMEnergy(esd.fZDCEMEnergy),
107   fZDCParticipants(esd.fZDCParticipants),
108   fT0zVertex(esd.fT0zVertex),
109   fSPDVertex(esd.fSPDVertex),
110   fPrimaryVertex(esd.fPrimaryVertex),
111   fSPDMult(esd.fSPDMult),
112   fT0timeStart(esd.fT0timeStart),
113   fTracks(*((TClonesArray*)esd.fTracks.Clone())),
114   fHLTConfMapTracks(*((TClonesArray*)esd.fHLTConfMapTracks.Clone())),
115   fHLTHoughTracks(*((TClonesArray*)esd.fHLTHoughTracks.Clone())),
116   fMuonTracks(*((TClonesArray*)esd.fMuonTracks.Clone())),
117   fPmdTracks(*((TClonesArray*)esd.fPmdTracks.Clone())),
118   fTrdTracks(*((TClonesArray*)esd.fTrdTracks.Clone())),
119   fV0s(*((TClonesArray*)esd.fV0s.Clone())),  
120   fCascades(*((TClonesArray*)esd.fCascades.Clone())),
121   fKinks(*((TClonesArray*)esd.fKinks.Clone())),
122   fCaloClusters(*((TClonesArray*)esd.fCaloClusters.Clone())),
123   fEMCALClusters(esd.fEMCALClusters), 
124   fFirstEMCALCluster(esd.fFirstEMCALCluster),
125   fEMCALTriggerPosition(esd. fEMCALTriggerPosition),
126   fEMCALTriggerAmplitudes(esd.fEMCALTriggerAmplitudes),
127   fPHOSClusters(esd.fPHOSClusters), 
128   fFirstPHOSCluster(esd.fFirstPHOSCluster),
129   fPHOSTriggerPosition(esd.fPHOSTriggerPosition),
130   fPHOSTriggerAmplitudes(esd.fPHOSTriggerAmplitudes),
131   fESDFMD(esd.fESDFMD),
132   fESDVZERO(esd.fESDVZERO),
133   fErrorLogs(*((TClonesArray*)esd.fErrorLogs.Clone()))
134 {
135   // 
136   // copy constructor
137   //
138   for (Int_t i=0; i<24; i++) {
139     fT0time[i] = esd.fT0time[i];
140     fT0amplitude[i] = esd.fT0amplitude[i];
141   }
142   for (Int_t i=0; i<2; i++) fDiamondXY[i]=esd.fDiamondXY[i];
143   for (Int_t i=0; i<3; i++) fDiamondCovXY[i]=esd.fDiamondCovXY[i];
144 }
145
146 //______________________________________________________________________________
147 AliESD::~AliESD()
148 {
149   //
150   // Standard destructor
151   //
152   fTracks.Delete();
153   fHLTConfMapTracks.Delete();
154   fHLTHoughTracks.Delete();
155   fMuonTracks.Delete();
156   fPmdTracks.Delete();
157   fTrdTracks.Delete();
158   fV0s.Delete();
159   fCascades.Delete();
160   fKinks.Delete();
161   fCaloClusters.Delete();
162   delete fESDFMD;
163   delete fESDVZERO;
164   delete fEMCALTriggerPosition;
165   delete fEMCALTriggerAmplitudes;
166   delete fPHOSTriggerPosition;
167   delete fPHOSTriggerAmplitudes;
168
169   fErrorLogs.Delete();
170
171 }
172
173 //______________________________________________________________________________
174 void AliESD::Reset()
175 {
176   // 
177   // Reset the contents and delete the entries in TClonesArrays
178   //
179
180   fEventNumberInFile=0;
181   fBunchCrossNumber=0;
182   fOrbitNumber=0;
183   fPeriodNumber=0;
184   fRunNumber=0;
185   fTimeStamp = 0;
186   fEventType = 0;
187   fTriggerMask=0;
188   fTriggerCluster=0;
189   fRecoVersion=0;
190   fMagneticField=0;
191   fZDCN1Energy=0;
192   fZDCP1Energy=0;
193   fZDCN2Energy=0;
194   fZDCP2Energy=0;
195   fZDCEMEnergy=0;
196   fZDCParticipants=0;
197   fT0zVertex=0;
198   
199   for (Int_t i=0; i<2; i++) fDiamondXY[i]=0.;
200   for (Int_t i=0; i<3; i++) fDiamondCovXY[i]=0.;
201
202   for (Int_t i=0; i<24; i++) {
203     fT0time[i] = 0;
204     fT0amplitude[i] = 0;
205   }
206   fT0timeStart = 0;
207 //
208   fSPDMult.~AliMultiplicity();
209   new (&fSPDMult) AliMultiplicity();
210   fSPDVertex.~AliESDVertex();
211   new (&fSPDVertex) AliESDVertex();
212   fPrimaryVertex.~AliESDVertex();
213   new (&fPrimaryVertex) AliESDVertex();
214 //
215   fTracks.Delete();
216   fHLTConfMapTracks.Delete();
217   fHLTHoughTracks.Delete();
218   fMuonTracks.Delete();
219   fPmdTracks.Delete();
220   fTrdTracks.Delete();
221   fV0s.Delete();
222   fCascades.Delete();
223   fKinks.Delete();
224   fCaloClusters.Delete();
225 //
226   fEMCALClusters=0; 
227   fFirstEMCALCluster=-1; 
228   fPHOSClusters=0; 
229   fFirstPHOSCluster=-1; 
230 //
231   if (fEMCALTriggerPosition)   fEMCALTriggerPosition  ->Reset();
232   if (fEMCALTriggerAmplitudes) fEMCALTriggerAmplitudes->Reset();
233   if (fPHOSTriggerPosition)    fPHOSTriggerPosition   ->Reset();
234   if (fPHOSTriggerAmplitudes)  fPHOSTriggerAmplitudes ->Reset();
235 //
236   if (fESDFMD) fESDFMD->Clear();
237 //
238   if (fESDVZERO){
239       fESDVZERO->~AliESDVZERO();
240       new (fESDVZERO) AliESDVZERO();
241   } 
242 //
243   fErrorLogs.Delete();
244 }
245
246
247 Bool_t  AliESD::RemoveKink(Int_t rm) {
248   // ---------------------------------------------------------
249   // Remove a kink candidate and references to it from ESD,
250   // if this candidate does not come from a reconstructed decay
251   // Not yet implemented...
252   // ---------------------------------------------------------
253   Int_t last=GetNumberOfKinks()-1;
254   if ((rm<0)||(rm>last)) return kFALSE;
255
256   return kTRUE;
257 }
258
259 Bool_t  AliESD::RemoveV0(Int_t rm) {
260   // ---------------------------------------------------------
261   // Remove a V0 candidate and references to it from ESD,
262   // if this candidate does not come from a reconstructed decay
263   // ---------------------------------------------------------
264   Int_t last=GetNumberOfV0s()-1;
265   if ((rm<0)||(rm>last)) return kFALSE;
266
267   AliESDv0 *v0=GetV0(rm);
268   Int_t idxP=v0->GetPindex(), idxN=v0->GetNindex();
269
270   v0=GetV0(last);
271   Int_t lastIdxP=v0->GetPindex(), lastIdxN=v0->GetNindex();
272
273   Int_t used=0;
274
275   // Check if this V0 comes from a reconstructed decay
276   Int_t ncs=GetNumberOfCascades();
277   for (Int_t n=0; n<ncs; n++) {
278     AliESDcascade *cs=GetCascade(n);
279
280     Int_t csIdxP=cs->GetPindex();
281     Int_t csIdxN=cs->GetNindex();
282
283     if (idxP==csIdxP)
284        if (idxN==csIdxN) return kFALSE;
285
286     if (csIdxP==lastIdxP)
287        if (csIdxN==lastIdxN) used++;
288   }
289
290   //Replace the removed V0 with the last V0 
291   TClonesArray &a=fV0s;
292   delete a.RemoveAt(rm);
293
294   if (rm==last) return kTRUE;
295
296   //v0 is pointing to the last V0 candidate... 
297   new (a[rm]) AliESDv0(*v0);
298   delete a.RemoveAt(last);
299
300   if (!used) return kTRUE;
301   
302
303   // Remap the indices of the daughters of reconstructed decays
304   for (Int_t n=0; n<ncs; n++) {
305     AliESDcascade *cs=GetCascade(n);
306
307
308     Int_t csIdxP=cs->GetPindex();
309     Int_t csIdxN=cs->GetNindex();
310
311     if (csIdxP==lastIdxP)
312       if (csIdxN==lastIdxN) {
313          cs->AliESDv0::SetIndex(1,idxP);
314          cs->AliESDv0::SetIndex(0,idxN);
315          used--;
316          if (!used) return kTRUE;
317       }
318   }
319
320   return kTRUE;
321 }
322
323 Bool_t  AliESD::RemoveTrack(Int_t rm) {
324   // ---------------------------------------------------------
325   // Remove a track and references to it from ESD,
326   // if this track does not come from a reconstructed decay
327   // ---------------------------------------------------------
328   Int_t last=GetNumberOfTracks()-1;
329   if ((rm<0)||(rm>last)) return kFALSE;
330
331   Int_t used=0;
332
333   // Check if this track comes from a reconstructed decay
334   Int_t nv0=GetNumberOfV0s();
335   for (Int_t n=0; n<nv0; n++) {
336     AliESDv0 *v0=GetV0(n);
337
338     Int_t idx=v0->GetNindex();
339     if (rm==idx) return kFALSE;
340     if (idx==last) used++;
341
342     idx=v0->GetPindex();
343     if (rm==idx) return kFALSE;
344     if (idx==last) used++;
345   }
346
347   Int_t ncs=GetNumberOfCascades();
348   for (Int_t n=0; n<ncs; n++) {
349     AliESDcascade *cs=GetCascade(n);
350
351     Int_t idx=cs->GetIndex();
352     if (rm==idx) return kFALSE;
353     if (idx==last) used++;
354   }
355
356   Int_t nkn=GetNumberOfKinks();
357   for (Int_t n=0; n<nkn; n++) {
358     AliESDkink *kn=GetKink(n);
359
360     Int_t idx=kn->GetIndex(0);
361     if (rm==idx) return kFALSE;
362     if (idx==last) used++;
363
364     idx=kn->GetIndex(1);
365     if (rm==idx) return kFALSE;
366     if (idx==last) used++;
367   }
368
369
370   //Replace the removed track with the last track 
371   TClonesArray &a=fTracks;
372   delete a.RemoveAt(rm);
373
374   if (rm==last) return kTRUE;
375
376   AliESDtrack *t=GetTrack(last);
377   t->SetID(rm);
378   new (a[rm]) AliESDtrack(*t);
379   delete a.RemoveAt(last);
380
381   if (!used) return kTRUE;
382   
383
384   // Remap the indices of the daughters of reconstructed decays
385   for (Int_t n=0; n<nv0; n++) {
386     AliESDv0 *v0=GetV0(n);
387     if (v0->GetIndex(0)==last) {
388        v0->SetIndex(0,rm);
389        used--;
390        if (!used) return kTRUE;
391     }
392     if (v0->GetIndex(1)==last) {
393        v0->SetIndex(1,rm);
394        used--;
395        if (!used) return kTRUE;
396     }
397   }
398
399   for (Int_t n=0; n<ncs; n++) {
400     AliESDcascade *cs=GetCascade(n);
401     if (cs->GetIndex()==last) {
402        cs->SetIndex(rm);
403        used--;
404        if (!used) return kTRUE;
405     }
406   }
407
408   for (Int_t n=0; n<nkn; n++) {
409     AliESDkink *kn=GetKink(n);
410     if (kn->GetIndex(0)==last) {
411        kn->SetIndex(rm,0);
412        used--;
413        if (!used) return kTRUE;
414     }
415     if (kn->GetIndex(1)==last) {
416        kn->SetIndex(rm,1);
417        used--;
418        if (!used) return kTRUE;
419     }
420   }
421
422   return kTRUE;
423 }
424
425
426 Bool_t AliESD::Clean(Float_t *cleanPars) {
427   //
428   // Remove the data which are not needed for the physics analysis.
429   //
430   // 1) Cleaning the V0 candidates
431   //    ---------------------------
432   //    If the cosine of the V0 pointing angle "csp" and 
433   //    the DCA between the daughter tracks "dca" does not satisfy 
434   //    the conditions 
435   //
436   //     csp > cleanPars[1] + dca/cleanPars[0]*(1.- cleanPars[1])
437   //
438   //    an attempt to remove this V0 candidate from ESD is made.
439   //
440   //    The V0 candidate gets removed if it does not belong to any 
441   //    recosntructed cascade decay
442   //
443   //    12.11.2007, optimal values: cleanPars[0]=0.5, cleanPars[1]=0.999
444   //
445   // 2) Cleaning the tracks
446   //    ----------------------
447   //    If track's transverse parameter is larger than cleanPars[2]
448   //                       OR
449   //    track's longitudinal parameter is larger than cleanPars[3]
450   //    an attempt to remove this track from ESD is made.
451   //
452   //    The track gets removed if it does not come 
453   //    from a reconstructed decay
454   //
455   Bool_t rc=kFALSE;
456
457   Float_t dcaMax=cleanPars[0];
458   Float_t cspMin=cleanPars[1];
459
460   Int_t nV0s=GetNumberOfV0s();
461   for (Int_t i=nV0s-1; i>=0; i--) {
462     AliESDv0 *v0=GetV0(i);
463
464     Float_t dca=v0->GetDcaV0Daughters();
465     Float_t csp=v0->GetV0CosineOfPointingAngle();
466     Float_t cspcut=cspMin + dca/dcaMax*(1.-cspMin);
467     if (csp > cspcut) continue;
468
469     if (RemoveV0(i)) rc=kTRUE;
470   }
471
472
473   Float_t dmax=cleanPars[2], zmax=cleanPars[3];
474
475   const AliESDVertex *vertex=GetVertex();
476   Bool_t vtxOK=vertex->GetStatus();
477   
478   Int_t nTracks=GetNumberOfTracks();
479   for (Int_t i=nTracks-1; i>=0; i--) {
480     AliESDtrack *track=GetTrack(i);
481     Float_t xy,z; track->GetImpactParameters(xy,z);
482     if ((TMath::Abs(xy) > dmax) || (vtxOK && (TMath::Abs(z) > zmax))) {
483       if (RemoveTrack(i)) rc=kTRUE;
484     }
485   }
486
487   return rc;
488 }
489
490 Int_t AliESD::AddV0(const AliESDv0 *v) {
491   //
492   // Add V0
493   //
494     Int_t idx=fV0s.GetEntriesFast();
495     new(fV0s[idx]) AliESDv0(*v);
496     return idx;
497 }  
498
499 //______________________________________________________________________________
500 void AliESD::Print(Option_t *) const 
501 {
502   //
503   // Print header information of the event
504   //
505   printf("ESD run information\n");
506   printf("Event # in file %d Bunch crossing # %d Orbit # %d Period # %d Run # %d Trigger %lld Magnetic field %f \n",
507          GetEventNumberInFile(),
508          GetBunchCrossNumber(),
509          GetOrbitNumber(),
510          GetPeriodNumber(),
511          GetRunNumber(),
512          GetTriggerMask(),
513          GetMagneticField() );
514     printf("Vertex: (%.4f +- %.4f, %.4f +- %.4f, %.4f +- %.4f) cm\n",
515            fPrimaryVertex.GetXv(), fPrimaryVertex.GetXRes(),
516            fPrimaryVertex.GetYv(), fPrimaryVertex.GetYRes(),
517            fPrimaryVertex.GetZv(), fPrimaryVertex.GetZRes());
518     printf("Mean vertex in RUN: X=%.4f Y=%.4f cm\n",
519            GetDiamondX(),GetDiamondY());
520     printf("SPD Multiplicity. Number of tracklets %d \n",
521            fSPDMult.GetNumberOfTracklets());
522   printf("Event from reconstruction version %d \n",fRecoVersion);
523   printf("Number of tracks: \n");
524   printf("                 charged   %d\n", GetNumberOfTracks());
525   printf("                 hlt CF    %d\n", GetNumberOfHLTConfMapTracks());
526   printf("                 hlt HT    %d\n", GetNumberOfHLTHoughTracks());
527   printf("                 muon      %d\n", GetNumberOfMuonTracks());
528   printf("                 pmd       %d\n", GetNumberOfPmdTracks());
529   printf("                 trd       %d\n", GetNumberOfTrdTracks());
530   printf("                 v0        %d\n", GetNumberOfV0s());
531   printf("                 cascades  %d\n", GetNumberOfCascades());
532   printf("                 kinks     %d\n", GetNumberOfKinks());
533   printf("                 CaloClusters %d\n", GetNumberOfCaloClusters());
534   printf("                 phos      %d\n", GetNumberOfPHOSClusters());
535   printf("                 emcal     %d\n", GetNumberOfEMCALClusters());
536   printf("                 FMD       %s\n", (fESDFMD ? "yes" : "no"));
537   printf("                 VZERO     %s\n", (fESDVZERO ? "yes" : "no"));
538 }
539
540 void AliESD::SetESDfriend(const AliESDfriend *ev) {
541   //
542   // Attaches the complementary info to the ESD
543   //
544   if (!ev) return;
545
546   Int_t ntrk=ev->GetNumberOfTracks();
547
548   for (Int_t i=0; i<ntrk; i++) {
549     const AliESDfriendTrack *f=ev->GetTrack(i);
550     GetTrack(i)->SetFriendTrack(f);
551   }
552 }
553
554 void AliESD::GetESDfriend(AliESDfriend *ev) const {
555   //
556   // Extracts the complementary info from the ESD
557   //
558   if (!ev) return;
559
560   Int_t ntrk=GetNumberOfTracks();
561
562   for (Int_t i=0; i<ntrk; i++) {
563     AliESDtrack *t=GetTrack(i);
564     const AliESDfriendTrack *f=t->GetFriendTrack();
565     ev->AddTrack(f);
566
567     t->ReleaseESDfriendTrack();// Not to have two copies of "friendTrack"
568
569   }
570 }
571
572 void AliESD::SetDiamond(const AliESDVertex *vertex)
573 {
574   //
575   // Set the interaction diamond
576   //  
577     fDiamondXY[0]=vertex->GetXv();
578     fDiamondXY[1]=vertex->GetYv();
579     Double_t cov[6];
580     vertex->GetCovMatrix(cov);
581     fDiamondCovXY[0]=cov[0];
582     fDiamondCovXY[1]=cov[1];
583     fDiamondCovXY[2]=cov[2];
584   }