]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESD.cxx
First V0 MC Analysis from H.Ricaud
[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   fSPDVertex.~AliESDVertex();
199   new (&fSPDVertex) AliESDVertex();
200   fPrimaryVertex.~AliESDVertex();
201   new (&fPrimaryVertex) AliESDVertex();
202   for (Int_t i=0; i<2; i++) fDiamondXY[i]=0.;
203   for (Int_t i=0; i<3; i++) fDiamondCovXY[i]=0.;
204   fSPDMult.~AliMultiplicity();
205   new (&fSPDMult) AliMultiplicity();
206   for (Int_t i=0; i<24; i++) {
207     fT0time[i] = 0;
208     fT0amplitude[i] = 0;
209   }
210   fT0timeStart = 0;
211   fTracks.Delete();
212   fHLTConfMapTracks.Delete();
213   fHLTHoughTracks.Delete();
214   fMuonTracks.Delete();
215   fPmdTracks.Delete();
216   fTrdTracks.Delete();
217   fV0s.Delete();
218   fCascades.Delete();
219   fCaloClusters.Delete();
220   fEMCALClusters=0; 
221   fFirstEMCALCluster=-1; 
222   fPHOSClusters=0; 
223   fFirstPHOSCluster=-1; 
224   if (fESDFMD) fESDFMD->Clear();
225   if (fESDVZERO){
226     fESDVZERO->~AliESDVZERO();
227     new (fESDVZERO) AliESDVZERO();
228   } 
229 //   fEMCALTriggerPosition->Clear();
230 //   fEMCALTriggerAmplitudes->Clear();
231 //   fPHOSTriggerPosition->Clear();
232 //   fPHOSTriggerAmplitudes->Clear();
233   fErrorLogs.Delete();
234 }
235
236
237 Bool_t  AliESD::RemoveKink(Int_t rm) {
238   // ---------------------------------------------------------
239   // Remove a kink candidate and references to it from ESD,
240   // if this candidate does not come from a reconstructed decay
241   // Not yet implemented...
242   // ---------------------------------------------------------
243   Int_t last=GetNumberOfKinks()-1;
244   if ((rm<0)||(rm>last)) return kFALSE;
245
246   return kTRUE;
247 }
248
249 Bool_t  AliESD::RemoveV0(Int_t rm) {
250   // ---------------------------------------------------------
251   // Remove a V0 candidate and references to it from ESD,
252   // if this candidate does not come from a reconstructed decay
253   // ---------------------------------------------------------
254   Int_t last=GetNumberOfV0s()-1;
255   if ((rm<0)||(rm>last)) return kFALSE;
256
257   AliESDv0 *v0=GetV0(rm);
258   Int_t idxP=v0->GetPindex(), idxN=v0->GetNindex();
259
260   v0=GetV0(last);
261   Int_t lastIdxP=v0->GetPindex(), lastIdxN=v0->GetNindex();
262
263   Int_t used=0;
264
265   // Check if this V0 comes from a reconstructed decay
266   Int_t ncs=GetNumberOfCascades();
267   for (Int_t n=0; n<ncs; n++) {
268     AliESDcascade *cs=GetCascade(n);
269
270     Int_t csIdxP=cs->GetPindex();
271     Int_t csIdxN=cs->GetNindex();
272
273     if (idxP==csIdxP)
274        if (idxN==csIdxN) return kFALSE;
275
276     if (csIdxP==lastIdxP)
277        if (csIdxN==lastIdxN) used++;
278   }
279
280   //Replace the removed V0 with the last V0 
281   TClonesArray &a=fV0s;
282   delete a.RemoveAt(rm);
283
284   if (rm==last) return kTRUE;
285
286   //v0 is pointing to the last V0 candidate... 
287   new (a[rm]) AliESDv0(*v0);
288   delete a.RemoveAt(last);
289
290   if (!used) return kTRUE;
291   
292
293   // Remap the indices of the daughters of reconstructed decays
294   for (Int_t n=0; n<ncs; n++) {
295     AliESDcascade *cs=GetCascade(n);
296
297
298     Int_t csIdxP=cs->GetPindex();
299     Int_t csIdxN=cs->GetNindex();
300
301     if (csIdxP==lastIdxP)
302       if (csIdxN==lastIdxN) {
303          cs->AliESDv0::SetIndex(1,idxP);
304          cs->AliESDv0::SetIndex(0,idxN);
305          used--;
306          if (!used) return kTRUE;
307       }
308   }
309
310   return kTRUE;
311 }
312
313 Bool_t  AliESD::RemoveTrack(Int_t rm) {
314   // ---------------------------------------------------------
315   // Remove a track and references to it from ESD,
316   // if this track does not come from a reconstructed decay
317   // ---------------------------------------------------------
318   Int_t last=GetNumberOfTracks()-1;
319   if ((rm<0)||(rm>last)) return kFALSE;
320
321   Int_t used=0;
322
323   // Check if this track comes from a reconstructed decay
324   Int_t nv0=GetNumberOfV0s();
325   for (Int_t n=0; n<nv0; n++) {
326     AliESDv0 *v0=GetV0(n);
327
328     Int_t idx=v0->GetNindex();
329     if (rm==idx) return kFALSE;
330     if (idx==last) used++;
331
332     idx=v0->GetPindex();
333     if (rm==idx) return kFALSE;
334     if (idx==last) used++;
335   }
336
337   Int_t ncs=GetNumberOfCascades();
338   for (Int_t n=0; n<ncs; n++) {
339     AliESDcascade *cs=GetCascade(n);
340
341     Int_t idx=cs->GetIndex();
342     if (rm==idx) return kFALSE;
343     if (idx==last) used++;
344   }
345
346   Int_t nkn=GetNumberOfKinks();
347   for (Int_t n=0; n<nkn; n++) {
348     AliESDkink *kn=GetKink(n);
349
350     Int_t idx=kn->GetIndex(0);
351     if (rm==idx) return kFALSE;
352     if (idx==last) used++;
353
354     idx=kn->GetIndex(1);
355     if (rm==idx) return kFALSE;
356     if (idx==last) used++;
357   }
358
359
360   //Replace the removed track with the last track 
361   TClonesArray &a=fTracks;
362   delete a.RemoveAt(rm);
363
364   if (rm==last) return kTRUE;
365
366   AliESDtrack *t=GetTrack(last);
367   t->SetID(rm);
368   new (a[rm]) AliESDtrack(*t);
369   delete a.RemoveAt(last);
370
371   if (!used) return kTRUE;
372   
373
374   // Remap the indices of the daughters of reconstructed decays
375   for (Int_t n=0; n<nv0; n++) {
376     AliESDv0 *v0=GetV0(n);
377     if (v0->GetIndex(0)==last) {
378        v0->SetIndex(0,rm);
379        used--;
380        if (!used) return kTRUE;
381     }
382     if (v0->GetIndex(1)==last) {
383        v0->SetIndex(1,rm);
384        used--;
385        if (!used) return kTRUE;
386     }
387   }
388
389   for (Int_t n=0; n<ncs; n++) {
390     AliESDcascade *cs=GetCascade(n);
391     if (cs->GetIndex()==last) {
392        cs->SetIndex(rm);
393        used--;
394        if (!used) return kTRUE;
395     }
396   }
397
398   for (Int_t n=0; n<nkn; n++) {
399     AliESDkink *kn=GetKink(n);
400     if (kn->GetIndex(0)==last) {
401        kn->SetIndex(rm,0);
402        used--;
403        if (!used) return kTRUE;
404     }
405     if (kn->GetIndex(1)==last) {
406        kn->SetIndex(rm,1);
407        used--;
408        if (!used) return kTRUE;
409     }
410   }
411
412   return kTRUE;
413 }
414
415
416 Bool_t AliESD::Clean(Float_t *cleanPars) {
417   //
418   // Remove the data which are not needed for the physics analysis.
419   //
420   // 1) Cleaning the V0 candidates
421   //    ---------------------------
422   //    If the cosine of the V0 pointing angle "csp" and 
423   //    the DCA between the daughter tracks "dca" does not satisfy 
424   //    the conditions 
425   //
426   //     csp > cleanPars[1] + dca/cleanPars[0]*(1.- cleanPars[1])
427   //
428   //    an attempt to remove this V0 candidate from ESD is made.
429   //
430   //    The V0 candidate gets removed if it does not belong to any 
431   //    recosntructed cascade decay
432   //
433   //    12.11.2007, optimal values: cleanPars[0]=0.5, cleanPars[1]=0.999
434   //
435   // 2) Cleaning the tracks
436   //    ----------------------
437   //    If track's transverse parameter is larger than cleanPars[2]
438   //                       OR
439   //    track's longitudinal parameter is larger than cleanPars[3]
440   //    an attempt to remove this track from ESD is made.
441   //
442   //    The track gets removed if it does not come 
443   //    from a reconstructed decay
444   //
445   Bool_t rc=kFALSE;
446
447   Float_t dcaMax=cleanPars[0];
448   Float_t cspMin=cleanPars[1];
449
450   Int_t nV0s=GetNumberOfV0s();
451   for (Int_t i=nV0s-1; i>=0; i--) {
452     AliESDv0 *v0=GetV0(i);
453
454     Float_t dca=v0->GetDcaV0Daughters();
455     Float_t csp=v0->GetV0CosineOfPointingAngle();
456     Float_t cspcut=cspMin + dca/dcaMax*(1.-cspMin);
457     if (csp > cspcut) continue;
458
459     if (RemoveV0(i)) rc=kTRUE;
460   }
461
462
463   Float_t dmax=cleanPars[2], zmax=cleanPars[3];
464
465   const AliESDVertex *vertex=GetVertex();
466   Bool_t vtxOK=vertex->GetStatus();
467   
468   Int_t nTracks=GetNumberOfTracks();
469   for (Int_t i=nTracks-1; i>=0; i--) {
470     AliESDtrack *track=GetTrack(i);
471     Float_t xy,z; track->GetImpactParameters(xy,z);
472     if ((TMath::Abs(xy) > dmax) || (vtxOK && (TMath::Abs(z) > zmax))) {
473       if (RemoveTrack(i)) rc=kTRUE;
474     }
475   }
476
477   return rc;
478 }
479
480 Int_t AliESD::AddV0(const AliESDv0 *v) {
481   //
482   // Add V0
483   //
484     Int_t idx=fV0s.GetEntriesFast();
485     new(fV0s[idx]) AliESDv0(*v);
486     return idx;
487 }  
488
489 //______________________________________________________________________________
490 void AliESD::Print(Option_t *) const 
491 {
492   //
493   // Print header information of the event
494   //
495   printf("ESD run information\n");
496   printf("Event # in file %d Bunch crossing # %d Orbit # %d Period # %d Run # %d Trigger %lld Magnetic field %f \n",
497          GetEventNumberInFile(),
498          GetBunchCrossNumber(),
499          GetOrbitNumber(),
500          GetPeriodNumber(),
501          GetRunNumber(),
502          GetTriggerMask(),
503          GetMagneticField() );
504     printf("Vertex: (%.4f +- %.4f, %.4f +- %.4f, %.4f +- %.4f) cm\n",
505            fPrimaryVertex.GetXv(), fPrimaryVertex.GetXRes(),
506            fPrimaryVertex.GetYv(), fPrimaryVertex.GetYRes(),
507            fPrimaryVertex.GetZv(), fPrimaryVertex.GetZRes());
508     printf("Mean vertex in RUN: X=%.4f Y=%.4f cm\n",
509            GetDiamondX(),GetDiamondY());
510     printf("SPD Multiplicity. Number of tracklets %d \n",
511            fSPDMult.GetNumberOfTracklets());
512   printf("Event from reconstruction version %d \n",fRecoVersion);
513   printf("Number of tracks: \n");
514   printf("                 charged   %d\n", GetNumberOfTracks());
515   printf("                 hlt CF    %d\n", GetNumberOfHLTConfMapTracks());
516   printf("                 hlt HT    %d\n", GetNumberOfHLTHoughTracks());
517   printf("                 muon      %d\n", GetNumberOfMuonTracks());
518   printf("                 pmd       %d\n", GetNumberOfPmdTracks());
519   printf("                 trd       %d\n", GetNumberOfTrdTracks());
520   printf("                 v0        %d\n", GetNumberOfV0s());
521   printf("                 cascades  %d\n", GetNumberOfCascades());
522   printf("                 kinks     %d\n", GetNumberOfKinks());
523   printf("                 CaloClusters %d\n", GetNumberOfCaloClusters());
524   printf("                 phos      %d\n", GetNumberOfPHOSClusters());
525   printf("                 emcal     %d\n", GetNumberOfEMCALClusters());
526   printf("                 FMD       %s\n", (fESDFMD ? "yes" : "no"));
527   printf("                 VZERO     %s\n", (fESDVZERO ? "yes" : "no"));
528 }
529
530 void AliESD::SetESDfriend(const AliESDfriend *ev) {
531   //
532   // Attaches the complementary info to the ESD
533   //
534   if (!ev) return;
535
536   Int_t ntrk=ev->GetNumberOfTracks();
537
538   for (Int_t i=0; i<ntrk; i++) {
539     const AliESDfriendTrack *f=ev->GetTrack(i);
540     GetTrack(i)->SetFriendTrack(f);
541   }
542 }
543
544 void AliESD::GetESDfriend(AliESDfriend *ev) const {
545   //
546   // Extracts the complementary info from the ESD
547   //
548   if (!ev) return;
549
550   Int_t ntrk=GetNumberOfTracks();
551
552   for (Int_t i=0; i<ntrk; i++) {
553     AliESDtrack *t=GetTrack(i);
554     const AliESDfriendTrack *f=t->GetFriendTrack();
555     ev->AddTrack(f);
556
557     t->ReleaseESDfriendTrack();// Not to have two copies of "friendTrack"
558
559   }
560 }
561
562 void AliESD::SetDiamond(const AliESDVertex *vertex)
563 {
564   //
565   // Set the interaction diamond
566   //  
567     fDiamondXY[0]=vertex->GetXv();
568     fDiamondXY[1]=vertex->GetYv();
569     Double_t cov[6];
570     vertex->GetCovMatrix(cov);
571     fDiamondCovXY[0]=cov[0];
572     fDiamondCovXY[1]=cov[1];
573     fDiamondCovXY[2]=cov[2];
574   }