]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESD.cxx
Bug fix: corrected file name (Levente)
[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 the reconstructed primary vertex
334   if (fPrimaryVertex.GetStatus()) {
335      UShort_t *primIdx=fPrimaryVertex.GetIndices();
336      Int_t n=fPrimaryVertex.GetNIndices();
337      while (n--) {
338        Int_t idx=Int_t(primIdx[n]);
339        if (rm==idx) return kFALSE;
340        if (idx==last) used++; 
341      }
342   }
343   
344   // Check if this track comes from a reconstructed decay
345   Int_t nv0=GetNumberOfV0s();
346   for (Int_t n=0; n<nv0; n++) {
347     AliESDv0 *v0=GetV0(n);
348
349     Int_t idx=v0->GetNindex();
350     if (rm==idx) return kFALSE;
351     if (idx==last) used++;
352
353     idx=v0->GetPindex();
354     if (rm==idx) return kFALSE;
355     if (idx==last) used++;
356   }
357
358   Int_t ncs=GetNumberOfCascades();
359   for (Int_t n=0; n<ncs; n++) {
360     AliESDcascade *cs=GetCascade(n);
361
362     Int_t idx=cs->GetIndex();
363     if (rm==idx) return kFALSE;
364     if (idx==last) used++;
365   }
366
367   Int_t nkn=GetNumberOfKinks();
368   for (Int_t n=0; n<nkn; n++) {
369     AliESDkink *kn=GetKink(n);
370
371     Int_t idx=kn->GetIndex(0);
372     if (rm==idx) return kFALSE;
373     if (idx==last) used++;
374
375     idx=kn->GetIndex(1);
376     if (rm==idx) return kFALSE;
377     if (idx==last) used++;
378   }
379
380
381   //Replace the removed track with the last track 
382   TClonesArray &a=fTracks;
383   delete a.RemoveAt(rm);
384
385   if (rm==last) return kTRUE;
386
387   AliESDtrack *t=GetTrack(last);
388   t->SetID(rm);
389   new (a[rm]) AliESDtrack(*t);
390   delete a.RemoveAt(last);
391
392
393   if (!used) return kTRUE;
394   
395
396   // Remap the indices of the tracks used for the primary vertex reconstruction
397   if (fPrimaryVertex.GetStatus()) {
398      UShort_t *primIdx=fPrimaryVertex.GetIndices();
399      Int_t n=fPrimaryVertex.GetNIndices();
400      while (n--) {
401        Int_t idx=Int_t(primIdx[n]);
402        if (idx==last) {
403           primIdx[n]=Short_t(rm); 
404           used--;
405           if (!used) return kTRUE;
406        }
407      }
408   }
409   
410   // Remap the indices of the daughters of reconstructed decays
411   for (Int_t n=0; n<nv0; n++) {
412     AliESDv0 *v0=GetV0(n);
413     if (v0->GetIndex(0)==last) {
414        v0->SetIndex(0,rm);
415        used--;
416        if (!used) return kTRUE;
417     }
418     if (v0->GetIndex(1)==last) {
419        v0->SetIndex(1,rm);
420        used--;
421        if (!used) return kTRUE;
422     }
423   }
424
425   for (Int_t n=0; n<ncs; n++) {
426     AliESDcascade *cs=GetCascade(n);
427     if (cs->GetIndex()==last) {
428        cs->SetIndex(rm);
429        used--;
430        if (!used) return kTRUE;
431     }
432   }
433
434   for (Int_t n=0; n<nkn; n++) {
435     AliESDkink *kn=GetKink(n);
436     if (kn->GetIndex(0)==last) {
437        kn->SetIndex(rm,0);
438        used--;
439        if (!used) return kTRUE;
440     }
441     if (kn->GetIndex(1)==last) {
442        kn->SetIndex(rm,1);
443        used--;
444        if (!used) return kTRUE;
445     }
446   }
447
448   return kTRUE;
449 }
450
451
452 Bool_t AliESD::Clean(Float_t *cleanPars) {
453   //
454   // Remove the data which are not needed for the physics analysis.
455   //
456   // 1) Cleaning the V0 candidates
457   //    ---------------------------
458   //    If the cosine of the V0 pointing angle "csp" and 
459   //    the DCA between the daughter tracks "dca" does not satisfy 
460   //    the conditions 
461   //
462   //     csp > cleanPars[1] + dca/cleanPars[0]*(1.- cleanPars[1])
463   //
464   //    an attempt to remove this V0 candidate from ESD is made.
465   //
466   //    The V0 candidate gets removed if it does not belong to any 
467   //    recosntructed cascade decay
468   //
469   //    12.11.2007, optimal values: cleanPars[0]=0.5, cleanPars[1]=0.999
470   //
471   // 2) Cleaning the tracks
472   //    ----------------------
473   //    If track's transverse parameter is larger than cleanPars[2]
474   //                       OR
475   //    track's longitudinal parameter is larger than cleanPars[3]
476   //    an attempt to remove this track from ESD is made.
477   //
478   //    The track gets removed if it does not come 
479   //    from a reconstructed decay
480   //
481   Bool_t rc=kFALSE;
482
483   Float_t dcaMax=cleanPars[0];
484   Float_t cspMin=cleanPars[1];
485
486   Int_t nV0s=GetNumberOfV0s();
487   for (Int_t i=nV0s-1; i>=0; i--) {
488     AliESDv0 *v0=GetV0(i);
489
490     Float_t dca=v0->GetDcaV0Daughters();
491     Float_t csp=v0->GetV0CosineOfPointingAngle();
492     Float_t cspcut=cspMin + dca/dcaMax*(1.-cspMin);
493     if (csp > cspcut) continue;
494
495     if (RemoveV0(i)) rc=kTRUE;
496   }
497
498
499   Float_t dmax=cleanPars[2], zmax=cleanPars[3];
500
501   const AliESDVertex *vertex=GetVertex();
502   Bool_t vtxOK=vertex->GetStatus();
503   
504   Int_t nTracks=GetNumberOfTracks();
505   for (Int_t i=nTracks-1; i>=0; i--) {
506     AliESDtrack *track=GetTrack(i);
507     Float_t xy,z; track->GetImpactParameters(xy,z);
508     if ((TMath::Abs(xy) > dmax) || (vtxOK && (TMath::Abs(z) > zmax))) {
509       if (RemoveTrack(i)) rc=kTRUE;
510     }
511   }
512
513   return rc;
514 }
515
516 Int_t AliESD::AddV0(const AliESDv0 *v) {
517   //
518   // Add V0
519   //
520     Int_t idx=fV0s.GetEntriesFast();
521     new(fV0s[idx]) AliESDv0(*v);
522     return idx;
523 }  
524
525 //______________________________________________________________________________
526 void AliESD::Print(Option_t *) const 
527 {
528   //
529   // Print header information of the event
530   //
531   printf("ESD run information\n");
532   printf("Event # in file %d Bunch crossing # %d Orbit # %d Period # %d Run # %d Trigger %lld Magnetic field %f \n",
533          GetEventNumberInFile(),
534          GetBunchCrossNumber(),
535          GetOrbitNumber(),
536          GetPeriodNumber(),
537          GetRunNumber(),
538          GetTriggerMask(),
539          GetMagneticField() );
540     printf("Vertex: (%.4f +- %.4f, %.4f +- %.4f, %.4f +- %.4f) cm\n",
541            fPrimaryVertex.GetXv(), fPrimaryVertex.GetXRes(),
542            fPrimaryVertex.GetYv(), fPrimaryVertex.GetYRes(),
543            fPrimaryVertex.GetZv(), fPrimaryVertex.GetZRes());
544     printf("Mean vertex in RUN: X=%.4f Y=%.4f cm\n",
545            GetDiamondX(),GetDiamondY());
546     printf("SPD Multiplicity. Number of tracklets %d \n",
547            fSPDMult.GetNumberOfTracklets());
548   printf("Event from reconstruction version %d \n",fRecoVersion);
549   printf("Number of tracks: \n");
550   printf("                 charged   %d\n", GetNumberOfTracks());
551   printf("                 hlt CF    %d\n", GetNumberOfHLTConfMapTracks());
552   printf("                 hlt HT    %d\n", GetNumberOfHLTHoughTracks());
553   printf("                 muon      %d\n", GetNumberOfMuonTracks());
554   printf("                 pmd       %d\n", GetNumberOfPmdTracks());
555   printf("                 trd       %d\n", GetNumberOfTrdTracks());
556   printf("                 v0        %d\n", GetNumberOfV0s());
557   printf("                 cascades  %d\n", GetNumberOfCascades());
558   printf("                 kinks     %d\n", GetNumberOfKinks());
559   printf("                 CaloClusters %d\n", GetNumberOfCaloClusters());
560   printf("                 phos      %d\n", GetNumberOfPHOSClusters());
561   printf("                 emcal     %d\n", GetNumberOfEMCALClusters());
562   printf("                 FMD       %s\n", (fESDFMD ? "yes" : "no"));
563   printf("                 VZERO     %s\n", (fESDVZERO ? "yes" : "no"));
564 }
565
566 void AliESD::SetESDfriend(const AliESDfriend *ev) {
567   //
568   // Attaches the complementary info to the ESD
569   //
570   if (!ev) return;
571
572   Int_t ntrk=ev->GetNumberOfTracks();
573
574   for (Int_t i=0; i<ntrk; i++) {
575     const AliESDfriendTrack *f=ev->GetTrack(i);
576     GetTrack(i)->SetFriendTrack(f);
577   }
578 }
579
580 void AliESD::GetESDfriend(AliESDfriend *ev) const {
581   //
582   // Extracts the complementary info from the ESD
583   //
584   if (!ev) return;
585
586   Int_t ntrk=GetNumberOfTracks();
587
588   for (Int_t i=0; i<ntrk; i++) {
589     AliESDtrack *t=GetTrack(i);
590     const AliESDfriendTrack *f=t->GetFriendTrack();
591     ev->AddTrack(f);
592
593     t->ReleaseESDfriendTrack();// Not to have two copies of "friendTrack"
594
595   }
596 }
597
598 void AliESD::SetDiamond(const AliESDVertex *vertex)
599 {
600   //
601   // Set the interaction diamond
602   //  
603     fDiamondXY[0]=vertex->GetXv();
604     fDiamondXY[1]=vertex->GetYv();
605     Double_t cov[6];
606     vertex->GetCovMatrix(cov);
607     fDiamondCovXY[0]=cov[0];
608     fDiamondCovXY[1]=cov[1];
609     fDiamondCovXY[2]=cov[2];
610   }