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