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