1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------
19 // Implementation of the AliESDEvent class
20 // This is the class to deal with during the physics analysis of data.
21 // It also ensures the backward compatibility with the old ESD format.
23 AliESDEvent *ev= new AliESDEvent();
24 ev->ReadFromTree(esdTree);
26 for (Int_t i=0; i<nev; i++) {
28 if(ev->GetAliESDOld())ev->CopyFromOldESD();
30 // The AliESDInputHandler does this automatically for you
32 // Origin: Christian Klein-Boesing, CERN, Christian.Klein-Boesing@cern.ch
33 //-----------------------------------------------------------------
36 #include "TRefArray.h"
39 #include "AliESDEvent.h"
40 #include "AliESDfriend.h"
41 #include "AliESDVZERO.h"
42 #include "AliESDFMD.h"
44 #include "AliESDMuonTrack.h"
45 #include "AliESDPmdTrack.h"
46 #include "AliESDTrdTrack.h"
47 #include "AliESDVertex.h"
48 #include "AliESDcascade.h"
49 #include "AliESDPmdTrack.h"
50 #include "AliESDTrdTrack.h"
51 #include "AliESDVertex.h"
52 #include "AliESDcascade.h"
53 #include "AliESDkink.h"
54 #include "AliESDtrack.h"
55 #include "AliESDHLTtrack.h"
56 #include "AliESDCaloCluster.h"
57 #include "AliESDCaloCells.h"
59 #include "AliESDFMD.h"
60 #include "AliESDVZERO.h"
61 #include "AliMultiplicity.h"
62 #include "AliRawDataErrorLog.h"
64 #include "AliESDACORDE.h"
69 // here we define the names, some classes are no TNamed, therefore the classnames
71 const char* AliESDEvent::fgkESDListName[kESDListN] = {"AliESDRun",
93 "AliRawDataErrorLogs",
96 //______________________________________________________________________________
97 AliESDEvent::AliESDEvent():
99 fESDObjects(new TList()),
121 fEMCALCells(0), fPHOSCells(0),
127 fFirstEMCALCluster(-1),
129 fFirstPHOSCluster(-1)
132 //______________________________________________________________________________
133 AliESDEvent::AliESDEvent(const AliESDEvent& esd):
135 fESDObjects(new TList()),
136 fESDRun(new AliESDRun(*esd.fESDRun)),
137 fHeader(new AliESDHeader(*esd.fHeader)),
138 fESDZDC(new AliESDZDC(*esd.fESDZDC)),
139 fESDFMD(new AliESDFMD(*esd.fESDFMD)),
140 fESDVZERO(new AliESDVZERO(*esd.fESDVZERO)),
141 fESDTZERO(new AliESDTZERO(*esd.fESDTZERO)),
142 fTPCVertex(new AliESDVertex(*esd.fTPCVertex)),
143 fSPDVertex(new AliESDVertex(*esd.fSPDVertex)),
144 fPrimaryVertex(new AliESDVertex(*esd.fPrimaryVertex)),
145 fSPDMult(new AliMultiplicity(*esd.fSPDMult)),
146 fPHOSTrigger(new AliESDCaloTrigger(*esd.fPHOSTrigger)),
147 fEMCALTrigger(new AliESDCaloTrigger(*esd.fEMCALTrigger)),
148 fESDACORDE(new AliESDACORDE(*esd.fESDACORDE)),
149 fTracks(new TClonesArray(*esd.fTracks)),
150 fMuonTracks(new TClonesArray(*esd.fMuonTracks)),
151 fPmdTracks(new TClonesArray(*esd.fPmdTracks)),
152 fTrdTracks(new TClonesArray(*esd.fTrdTracks)),
153 fV0s(new TClonesArray(*esd.fV0s)),
154 fCascades(new TClonesArray(*esd.fCascades)),
155 fKinks(new TClonesArray(*esd.fKinks)),
156 fCaloClusters(new TClonesArray(*esd.fCaloClusters)),
157 fEMCALCells(new AliESDCaloCells(*esd.fEMCALCells)),
158 fPHOSCells(new AliESDCaloCells(*esd.fPHOSCells)),
159 fErrorLogs(new TClonesArray(*esd.fErrorLogs)),
160 fESDOld(new AliESD(*esd.fESDOld)),
161 fESDFriendOld(new AliESDfriend(*esd.fESDFriendOld)),
162 fConnected(esd.fConnected),
163 fEMCALClusters(esd.fEMCALClusters),
164 fFirstEMCALCluster(esd.fFirstEMCALCluster),
165 fPHOSClusters(esd.fPHOSClusters),
166 fFirstPHOSCluster(esd.fFirstPHOSCluster)
169 // CKB init in the constructor list and only add here ...
174 AddObject(fESDVZERO);
175 AddObject(fESDTZERO);
176 AddObject(fTPCVertex);
177 AddObject(fSPDVertex);
178 AddObject(fPrimaryVertex);
180 AddObject(fPHOSTrigger);
181 AddObject(fEMCALTrigger);
183 AddObject(fMuonTracks);
184 AddObject(fPmdTracks);
185 AddObject(fTrdTracks);
187 AddObject(fCascades);
189 AddObject(fCaloClusters);
190 AddObject(fEMCALCells);
191 AddObject(fPHOSCells);
192 AddObject(fErrorLogs);
193 AddObject(fESDACORDE);
199 //______________________________________________________________________________
200 AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
202 // Assignment operator
204 if(&source == this) return *this;
205 AliVEvent::operator=(source);
207 // This assumes that the list is already created
208 // and that the virtual void Copy(Tobject&) function
209 // is correctly implemented in the derived class
210 // otherwise only TObject::Copy() will be used
213 if((fESDObjects->GetSize()==0)&&(source.fESDObjects->GetSize()>=kESDListN)){
214 // We cover the case that we do not yet have the
215 // standard content but the source has it
219 TIter next(source.GetList());
222 while ((its = next())) {
223 name.Form("%s", its->GetName());
224 TObject *mine = fESDObjects->FindObject(name.Data());
226 // not in this: can be added to list (to be implemented)
227 AliWarning(Form("%s:%d Could not find %s for copying \n",
228 (char*)__FILE__,__LINE__,name.Data()));
232 if(!its->InheritsFrom("TCollection")){
236 else if(its->InheritsFrom("TClonesArray")){
237 // Create or expand the tclonesarray pointers
238 // so we can directly copy to the object
239 TClonesArray *its_tca = (TClonesArray*)its;
240 TClonesArray *mine_tca = (TClonesArray*)mine;
242 // this leaves the capacity of the TClonesArray the same
243 // except for a factor of 2 increase when size > capacity
244 // does not release any memory occupied by the tca
245 mine_tca->ExpandCreate(its_tca->GetEntriesFast());
246 for(int i = 0;i < its_tca->GetEntriesFast();++i){
248 TObject *mine_tca_obj = mine_tca->At(i);
249 TObject *its_tca_obj = its_tca->At(i);
250 // no need to delete first
251 // pointers within the class should be handled by Copy()...
252 // Can there be Empty slots?
253 its_tca_obj->Copy(*mine_tca_obj);
257 AliWarning(Form("%s:%d cannot copy TCollection \n",
258 (char*)__FILE__,__LINE__));
262 fConnected = source.fConnected;
263 fEMCALClusters = source.fEMCALClusters;
264 fFirstEMCALCluster = source.fFirstEMCALCluster;
265 fPHOSClusters = source.fPHOSClusters;
266 fFirstPHOSCluster = source.fFirstPHOSCluster;
274 //______________________________________________________________________________
275 AliESDEvent::~AliESDEvent()
278 // Standard destructor
281 // everthing on the list gets deleted automatically
284 if(fESDObjects&&!fConnected)
293 void AliESDEvent::Copy(TObject &obj) const {
295 // interface to TOBject::Copy
296 // Copies the content of this into obj!
297 // bascially obj = *this
299 if(this==&obj)return;
300 AliESDEvent *robj = dynamic_cast<AliESDEvent*>(&obj);
301 if(!robj)return; // not an AliESEvent
306 //______________________________________________________________________________
307 void AliESDEvent::Reset()
311 // Reset the standard contents
313 if(fESDOld)fESDOld->Reset();
314 // reset for the friends...
316 fESDFriendOld->~AliESDfriend();
317 new (fESDFriendOld) AliESDfriend();
319 // for new data we have to fetch the Pointer from the list
320 AliESDfriend *fr = (AliESDfriend*)FindListObject("AliESDfriend");
322 // delete the content
324 // make a new valid ESDfriend at the same place
325 new (fr) AliESDfriend();
328 // call reset for user supplied data?
331 void AliESDEvent::ResetStdContent()
333 // Reset the standard contents
334 if(fESDRun) fESDRun->Reset();
335 if(fHeader) fHeader->Reset();
336 if(fESDZDC) fESDZDC->Reset();
338 fESDFMD->~AliESDFMD();
339 new (fESDFMD) AliESDFMD();
342 // reset by callin d'to /c'tor keep the pointer
343 fESDVZERO->~AliESDVZERO();
344 new (fESDVZERO) AliESDVZERO();
347 fESDACORDE->~AliESDACORDE();
348 new (fESDACORDE) AliESDACORDE();
350 if(fESDTZERO) fESDTZERO->Reset();
351 // CKB no clear/reset implemented
353 fTPCVertex->~AliESDVertex();
354 new (fTPCVertex) AliESDVertex();
355 fTPCVertex->SetName(fgkESDListName[kTPCVertex]);
358 fSPDVertex->~AliESDVertex();
359 new (fSPDVertex) AliESDVertex();
360 fSPDVertex->SetName(fgkESDListName[kSPDVertex]);
363 fPrimaryVertex->~AliESDVertex();
364 new (fPrimaryVertex) AliESDVertex();
365 fPrimaryVertex->SetName(fgkESDListName[kPrimaryVertex]);
368 fSPDMult->~AliMultiplicity();
369 new (fSPDMult) AliMultiplicity();
371 if(fPHOSTrigger)fPHOSTrigger->Reset();
372 if(fEMCALTrigger)fEMCALTrigger->Reset();
373 if(fTracks)fTracks->Delete();
374 if(fMuonTracks)fMuonTracks->Delete();
375 if(fPmdTracks)fPmdTracks->Delete();
376 if(fTrdTracks)fTrdTracks->Delete();
377 if(fV0s)fV0s->Delete();
378 if(fCascades)fCascades->Delete();
379 if(fKinks)fKinks->Delete();
380 if(fCaloClusters)fCaloClusters->Delete();
381 if(fPHOSCells)fPHOSCells->DeleteContainer();
382 if(fEMCALCells)fEMCALCells->DeleteContainer();
383 if(fErrorLogs) fErrorLogs->Delete();
385 // don't reset fconnected fConnected and the list
388 fFirstEMCALCluster=-1;
390 fFirstPHOSCluster=-1;
394 Int_t AliESDEvent::AddV0(const AliESDv0 *v) {
398 TClonesArray &fv = *fV0s;
399 Int_t idx=fV0s->GetEntriesFast();
400 new(fv[idx]) AliESDv0(*v);
404 //______________________________________________________________________________
405 void AliESDEvent::Print(Option_t *) const
408 // Print header information of the event
410 printf("ESD run information\n");
411 printf("Event # in file %d Bunch crossing # %d Orbit # %d Period # %d Run # %d Trigger %lld Magnetic field %f \n",
412 GetEventNumberInFile(),
413 GetBunchCrossNumber(),
418 GetMagneticField() );
419 printf("Vertex: (%.4f +- %.4f, %.4f +- %.4f, %.4f +- %.4f) cm\n",
420 fPrimaryVertex->GetXv(), fPrimaryVertex->GetXRes(),
421 fPrimaryVertex->GetYv(), fPrimaryVertex->GetYRes(),
422 fPrimaryVertex->GetZv(), fPrimaryVertex->GetZRes());
423 printf("Mean vertex in RUN: X=%.4f Y=%.4f cm\n",
424 GetDiamondX(),GetDiamondY());
425 printf("SPD Multiplicity. Number of tracklets %d \n",
426 fSPDMult->GetNumberOfTracklets());
427 printf("Number of tracks: \n");
428 printf(" charged %d\n", GetNumberOfTracks());
429 printf(" muon %d\n", GetNumberOfMuonTracks());
430 printf(" pmd %d\n", GetNumberOfPmdTracks());
431 printf(" trd %d\n", GetNumberOfTrdTracks());
432 printf(" v0 %d\n", GetNumberOfV0s());
433 printf(" cascades %d\n", GetNumberOfCascades());
434 printf(" kinks %d\n", GetNumberOfKinks());
435 if(fPHOSCells)printf(" PHOSCells %d\n", fPHOSCells->GetNumberOfCells());
436 else printf(" PHOSCells not in the Event\n");
437 if(fEMCALCells)printf(" EMCALCells %d\n", fEMCALCells->GetNumberOfCells());
438 else printf(" EMCALCells not in the Event\n");
439 printf(" CaloClusters %d\n", GetNumberOfCaloClusters());
440 printf(" phos %d\n", GetNumberOfPHOSClusters());
441 printf(" emcal %d\n", GetNumberOfEMCALClusters());
442 printf(" FMD %s\n", (fESDFMD ? "yes" : "no"));
443 printf(" VZERO %s\n", (fESDVZERO ? "yes" : "no"));
448 void AliESDEvent::SetESDfriend(const AliESDfriend *ev) const {
450 // Attaches the complementary info to the ESD
454 // to be sure that we set the tracks also
455 // in case of old esds
456 // if(fESDOld)CopyFromOldESD();
458 Int_t ntrk=ev->GetNumberOfTracks();
460 for (Int_t i=0; i<ntrk; i++) {
461 const AliESDfriendTrack *f=ev->GetTrack(i);
462 GetTrack(i)->SetFriendTrack(f);
466 Bool_t AliESDEvent::RemoveKink(Int_t rm) const {
467 // ---------------------------------------------------------
468 // Remove a kink candidate and references to it from ESD,
469 // if this candidate does not come from a reconstructed decay
470 // Not yet implemented...
471 // ---------------------------------------------------------
472 Int_t last=GetNumberOfKinks()-1;
473 if ((rm<0)||(rm>last)) return kFALSE;
478 Bool_t AliESDEvent::RemoveV0(Int_t rm) const {
479 // ---------------------------------------------------------
480 // Remove a V0 candidate and references to it from ESD,
481 // if this candidate does not come from a reconstructed decay
482 // ---------------------------------------------------------
483 Int_t last=GetNumberOfV0s()-1;
484 if ((rm<0)||(rm>last)) return kFALSE;
486 AliESDv0 *v0=GetV0(rm);
487 Int_t idxP=v0->GetPindex(), idxN=v0->GetNindex();
490 Int_t lastIdxP=v0->GetPindex(), lastIdxN=v0->GetNindex();
494 // Check if this V0 comes from a reconstructed decay
495 Int_t ncs=GetNumberOfCascades();
496 for (Int_t n=0; n<ncs; n++) {
497 AliESDcascade *cs=GetCascade(n);
499 Int_t csIdxP=cs->GetPindex();
500 Int_t csIdxN=cs->GetNindex();
503 if (idxN==csIdxN) return kFALSE;
505 if (csIdxP==lastIdxP)
506 if (csIdxN==lastIdxN) used++;
509 //Replace the removed V0 with the last V0
510 TClonesArray &a=*fV0s;
511 delete a.RemoveAt(rm);
513 if (rm==last) return kTRUE;
515 //v0 is pointing to the last V0 candidate...
516 new (a[rm]) AliESDv0(*v0);
517 delete a.RemoveAt(last);
519 if (!used) return kTRUE;
522 // Remap the indices of the daughters of reconstructed decays
523 for (Int_t n=0; n<ncs; n++) {
524 AliESDcascade *cs=GetCascade(n);
527 Int_t csIdxP=cs->GetPindex();
528 Int_t csIdxN=cs->GetNindex();
530 if (csIdxP==lastIdxP)
531 if (csIdxN==lastIdxN) {
532 cs->AliESDv0::SetIndex(1,idxP);
533 cs->AliESDv0::SetIndex(0,idxN);
535 if (!used) return kTRUE;
542 Bool_t AliESDEvent::RemoveTrack(Int_t rm) const {
543 // ---------------------------------------------------------
544 // Remove a track and references to it from ESD,
545 // if this track does not come from a reconstructed decay
546 // ---------------------------------------------------------
547 Int_t last=GetNumberOfTracks()-1;
548 if ((rm<0)||(rm>last)) return kFALSE;
552 // Check if this track comes from the reconstructed primary vertices
553 if (fTPCVertex && fTPCVertex->GetStatus()) {
554 UShort_t *primIdx=fTPCVertex->GetIndices();
555 Int_t n=fTPCVertex->GetNIndices();
557 Int_t idx=Int_t(primIdx[n]);
558 if (rm==idx) return kFALSE;
559 if (idx==last) used++;
562 if (fPrimaryVertex && fPrimaryVertex->GetStatus()) {
563 UShort_t *primIdx=fPrimaryVertex->GetIndices();
564 Int_t n=fPrimaryVertex->GetNIndices();
566 Int_t idx=Int_t(primIdx[n]);
567 if (rm==idx) return kFALSE;
568 if (idx==last) used++;
572 // Check if this track comes from a reconstructed decay
573 Int_t nv0=GetNumberOfV0s();
574 for (Int_t n=0; n<nv0; n++) {
575 AliESDv0 *v0=GetV0(n);
577 Int_t idx=v0->GetNindex();
578 if (rm==idx) return kFALSE;
579 if (idx==last) used++;
582 if (rm==idx) return kFALSE;
583 if (idx==last) used++;
586 Int_t ncs=GetNumberOfCascades();
587 for (Int_t n=0; n<ncs; n++) {
588 AliESDcascade *cs=GetCascade(n);
590 Int_t idx=cs->GetIndex();
591 if (rm==idx) return kFALSE;
592 if (idx==last) used++;
595 Int_t nkn=GetNumberOfKinks();
596 for (Int_t n=0; n<nkn; n++) {
597 AliESDkink *kn=GetKink(n);
599 Int_t idx=kn->GetIndex(0);
600 if (rm==idx) return kFALSE;
601 if (idx==last) used++;
604 if (rm==idx) return kFALSE;
605 if (idx==last) used++;
609 //Replace the removed track with the last track
610 TClonesArray &a=*fTracks;
611 delete a.RemoveAt(rm);
613 if (rm==last) return kTRUE;
615 AliESDtrack *t=GetTrack(last);
617 new (a[rm]) AliESDtrack(*t);
618 delete a.RemoveAt(last);
621 if (!used) return kTRUE;
624 // Remap the indices of the tracks used for the primary vertex reconstruction
625 if (fTPCVertex && fTPCVertex->GetStatus()) {
626 UShort_t *primIdx=fTPCVertex->GetIndices();
627 Int_t n=fTPCVertex->GetNIndices();
629 Int_t idx=Int_t(primIdx[n]);
631 primIdx[n]=Short_t(rm);
633 if (!used) return kTRUE;
637 if (fPrimaryVertex && fPrimaryVertex->GetStatus()) {
638 UShort_t *primIdx=fPrimaryVertex->GetIndices();
639 Int_t n=fPrimaryVertex->GetNIndices();
641 Int_t idx=Int_t(primIdx[n]);
643 primIdx[n]=Short_t(rm);
645 if (!used) return kTRUE;
650 // Remap the indices of the daughters of reconstructed decays
651 for (Int_t n=0; n<nv0; n++) {
652 AliESDv0 *v0=GetV0(n);
653 if (v0->GetIndex(0)==last) {
656 if (!used) return kTRUE;
658 if (v0->GetIndex(1)==last) {
661 if (!used) return kTRUE;
665 for (Int_t n=0; n<ncs; n++) {
666 AliESDcascade *cs=GetCascade(n);
667 if (cs->GetIndex()==last) {
670 if (!used) return kTRUE;
674 for (Int_t n=0; n<nkn; n++) {
675 AliESDkink *kn=GetKink(n);
676 if (kn->GetIndex(0)==last) {
679 if (!used) return kTRUE;
681 if (kn->GetIndex(1)==last) {
684 if (!used) return kTRUE;
692 Bool_t AliESDEvent::Clean(Float_t *cleanPars) {
694 // Remove the data which are not needed for the physics analysis.
696 // 1) Cleaning the V0 candidates
697 // ---------------------------
698 // If the cosine of the V0 pointing angle "csp" and
699 // the DCA between the daughter tracks "dca" does not satisfy
702 // csp > cleanPars[1] + dca/cleanPars[0]*(1.- cleanPars[1])
704 // an attempt to remove this V0 candidate from ESD is made.
706 // The V0 candidate gets removed if it does not belong to any
707 // recosntructed cascade decay
709 // 12.11.2007, optimal values: cleanPars[0]=0.5, cleanPars[1]=0.999
711 // 2) Cleaning the tracks
712 // ----------------------
713 // If track's transverse parameter is larger than cleanPars[2]
715 // track's longitudinal parameter is larger than cleanPars[3]
716 // an attempt to remove this track from ESD is made.
718 // The track gets removed if it does not come
719 // from a reconstructed decay
723 Float_t dcaMax=cleanPars[0];
724 Float_t cspMin=cleanPars[1];
726 Int_t nV0s=GetNumberOfV0s();
727 for (Int_t i=nV0s-1; i>=0; i--) {
728 AliESDv0 *v0=GetV0(i);
730 Float_t dca=v0->GetDcaV0Daughters();
731 Float_t csp=v0->GetV0CosineOfPointingAngle();
732 Float_t cspcut=cspMin + dca/dcaMax*(1.-cspMin);
733 if (csp > cspcut) continue;
734 if (RemoveV0(i)) rc=kTRUE;
738 Float_t dmax=cleanPars[2], zmax=cleanPars[3];
740 const AliESDVertex *vertex=GetPrimaryVertexSPD();
741 Bool_t vtxOK=vertex->GetStatus();
743 Int_t nTracks=GetNumberOfTracks();
744 for (Int_t i=nTracks-1; i>=0; i--) {
745 AliESDtrack *track=GetTrack(i);
746 Float_t xy,z; track->GetImpactParameters(xy,z);
747 if ((TMath::Abs(xy) > dmax) || (vtxOK && (TMath::Abs(z) > zmax))) {
748 if (RemoveTrack(i)) rc=kTRUE;
755 Int_t AliESDEvent::AddTrack(const AliESDtrack *t)
758 TClonesArray &ftr = *fTracks;
759 AliESDtrack * track = new(ftr[fTracks->GetEntriesFast()])AliESDtrack(*t);
760 track->SetID(fTracks->GetEntriesFast()-1);
761 return track->GetID();
764 void AliESDEvent::AddMuonTrack(const AliESDMuonTrack *t)
766 TClonesArray &fmu = *fMuonTracks;
767 new(fmu[fMuonTracks->GetEntriesFast()]) AliESDMuonTrack(*t);
770 void AliESDEvent::AddPmdTrack(const AliESDPmdTrack *t)
772 TClonesArray &fpmd = *fPmdTracks;
773 new(fpmd[fPmdTracks->GetEntriesFast()]) AliESDPmdTrack(*t);
776 void AliESDEvent::AddTrdTrack(const AliESDTrdTrack *t)
778 TClonesArray &ftrd = *fTrdTracks;
779 new(ftrd[fTrdTracks->GetEntriesFast()]) AliESDTrdTrack(*t);
785 Int_t AliESDEvent::AddKink(const AliESDkink *c)
788 TClonesArray &fk = *fKinks;
789 AliESDkink * kink = new(fk[fKinks->GetEntriesFast()]) AliESDkink(*c);
790 kink->SetID(fKinks->GetEntriesFast()); // CKB different from the other imps..
791 return fKinks->GetEntriesFast()-1;
795 void AliESDEvent::AddCascade(const AliESDcascade *c)
797 TClonesArray &fc = *fCascades;
798 new(fc[fCascades->GetEntriesFast()]) AliESDcascade(*c);
802 Int_t AliESDEvent::AddCaloCluster(const AliESDCaloCluster *c)
805 TClonesArray &fc = *fCaloClusters;
806 AliESDCaloCluster *clus = new(fc[fCaloClusters->GetEntriesFast()]) AliESDCaloCluster(*c);
807 clus->SetID(fCaloClusters->GetEntriesFast()-1);
808 return fCaloClusters->GetEntriesFast()-1;
812 void AliESDEvent::AddRawDataErrorLog(const AliRawDataErrorLog *log) const {
813 TClonesArray &errlogs = *fErrorLogs;
814 new(errlogs[errlogs.GetEntriesFast()]) AliRawDataErrorLog(*log);
817 void AliESDEvent::SetPrimaryVertexTPC(const AliESDVertex *vertex)
819 // Set the TPC vertex
820 // use already allocated space
822 *fTPCVertex = *vertex;
823 fTPCVertex->SetName(fgkESDListName[kTPCVertex]);
827 void AliESDEvent::SetPrimaryVertexSPD(const AliESDVertex *vertex)
829 // Set the SPD vertex
830 // use already allocated space
832 *fSPDVertex = *vertex;
833 fSPDVertex->SetName(fgkESDListName[kSPDVertex]);
837 void AliESDEvent::SetPrimaryVertex(const AliESDVertex *vertex)
839 // Set the primary vertex
840 // use already allocated space
842 *fPrimaryVertex = *vertex;
843 fPrimaryVertex->SetName(fgkESDListName[kPrimaryVertex]);
847 void AliESDEvent::SetMultiplicity(const AliMultiplicity *mul)
849 // Set the SPD Multiplicity
856 void AliESDEvent::SetFMDData(AliESDFMD * obj)
858 // use already allocated space
864 void AliESDEvent::SetVZEROData(AliESDVZERO * obj)
866 // use already allocated space
871 void AliESDEvent::SetACORDEData(AliESDACORDE * obj)
878 void AliESDEvent::GetESDfriend(AliESDfriend *ev) const
881 // Extracts the complementary info from the ESD
885 Int_t ntrk=GetNumberOfTracks();
887 for (Int_t i=0; i<ntrk; i++) {
888 AliESDtrack *t=GetTrack(i);
889 const AliESDfriendTrack *f=t->GetFriendTrack();
892 t->ReleaseESDfriendTrack();// Not to have two copies of "friendTrack"
898 void AliESDEvent::AddObject(TObject* obj)
900 // Add an object to the list of object.
901 // Please be aware that in order to increase performance you should
902 // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
903 fESDObjects->SetOwner(kTRUE);
904 fESDObjects->AddLast(obj);
908 void AliESDEvent::GetStdContent()
910 // set pointers for standard content
911 // get by name much safer and not a big overhead since not called very often
913 fESDRun = (AliESDRun*)fESDObjects->FindObject(fgkESDListName[kESDRun]);
914 fHeader = (AliESDHeader*)fESDObjects->FindObject(fgkESDListName[kHeader]);
915 fESDZDC = (AliESDZDC*)fESDObjects->FindObject(fgkESDListName[kESDZDC]);
916 fESDFMD = (AliESDFMD*)fESDObjects->FindObject(fgkESDListName[kESDFMD]);
917 fESDVZERO = (AliESDVZERO*)fESDObjects->FindObject(fgkESDListName[kESDVZERO]);
918 fESDTZERO = (AliESDTZERO*)fESDObjects->FindObject(fgkESDListName[kESDTZERO]);
919 fTPCVertex = (AliESDVertex*)fESDObjects->FindObject(fgkESDListName[kTPCVertex]);
920 fSPDVertex = (AliESDVertex*)fESDObjects->FindObject(fgkESDListName[kSPDVertex]);
921 fPrimaryVertex = (AliESDVertex*)fESDObjects->FindObject(fgkESDListName[kPrimaryVertex]);
922 fSPDMult = (AliMultiplicity*)fESDObjects->FindObject(fgkESDListName[kSPDMult]);
923 fPHOSTrigger = (AliESDCaloTrigger*)fESDObjects->FindObject(fgkESDListName[kPHOSTrigger]);
924 fEMCALTrigger = (AliESDCaloTrigger*)fESDObjects->FindObject(fgkESDListName[kEMCALTrigger]);
925 fTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTracks]);
926 fMuonTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kMuonTracks]);
927 fPmdTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kPmdTracks]);
928 fTrdTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTrdTracks]);
929 fV0s = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kV0s]);
930 fCascades = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kCascades]);
931 fKinks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kKinks]);
932 fCaloClusters = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kCaloClusters]);
933 fEMCALCells = (AliESDCaloCells*)fESDObjects->FindObject(fgkESDListName[kEMCALCells]);
934 fPHOSCells = (AliESDCaloCells*)fESDObjects->FindObject(fgkESDListName[kPHOSCells]);
935 fErrorLogs = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kErrorLogs]);
936 fESDACORDE = (AliESDACORDE*)fESDObjects->FindObject(fgkESDListName[kESDACORDE]);
940 void AliESDEvent::SetStdNames(){
941 // Set the names of the standard contents
943 if(fESDObjects->GetEntries()==kESDListN){
944 for(int i = 0;i < fESDObjects->GetEntries();i++){
945 TObject *fObj = fESDObjects->At(i);
946 if(fObj->InheritsFrom("TNamed")){
947 ((TNamed*)fObj)->SetName(fgkESDListName[i]);
949 else if(fObj->InheritsFrom("TClonesArray")){
950 ((TClonesArray*)fObj)->SetName(fgkESDListName[i]);
955 printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
959 void AliESDEvent::CreateStdContent()
961 // create the standard AOD content and set pointers
963 // create standard objects and add them to the TList of objects
964 AddObject(new AliESDRun());
965 AddObject(new AliESDHeader());
966 AddObject(new AliESDZDC());
967 AddObject(new AliESDFMD());
968 AddObject(new AliESDVZERO());
969 AddObject(new AliESDTZERO());
970 AddObject(new AliESDVertex());
971 AddObject(new AliESDVertex());
972 AddObject(new AliESDVertex());
973 AddObject(new AliMultiplicity());
974 AddObject(new AliESDCaloTrigger());
975 AddObject(new AliESDCaloTrigger());
976 AddObject(new TClonesArray("AliESDtrack",0));
977 AddObject(new TClonesArray("AliESDMuonTrack",0));
978 AddObject(new TClonesArray("AliESDPmdTrack",0));
979 AddObject(new TClonesArray("AliESDTrdTrack",0));
980 AddObject(new TClonesArray("AliESDv0",0));
981 AddObject(new TClonesArray("AliESDcascade",0));
982 AddObject(new TClonesArray("AliESDkink",0));
983 AddObject(new TClonesArray("AliESDCaloCluster",0));
984 AddObject(new AliESDCaloCells());
985 AddObject(new AliESDCaloCells());
986 AddObject(new TClonesArray("AliRawDataErrorLog",0));
987 AddObject(new AliESDACORDE());
989 // check the order of the indices against enum...
993 // read back pointers
997 TObject* AliESDEvent::FindListObject(const char *name){
999 // Find object with name "name" in the list of branches
1002 return fESDObjects->FindObject(name);
1007 Int_t AliESDEvent::GetPHOSClusters(TRefArray *clusters) const
1009 // fills the provided TRefArray with all found phos clusters
1013 AliESDCaloCluster *cl = 0;
1014 for (Int_t i = 0; i < GetNumberOfCaloClusters(); i++) {
1016 if ( (cl = GetCaloCluster(i)) ) {
1019 AliDebug(1,Form("IsPHOS cluster %d Size: %d \n",i,clusters->GetEntriesFast()));
1023 return clusters->GetEntriesFast();
1026 Int_t AliESDEvent::GetEMCALClusters(TRefArray *clusters) const
1028 // fills the provided TRefArray with all found emcal clusters
1032 AliESDCaloCluster *cl = 0;
1033 for (Int_t i = 0; i < GetNumberOfCaloClusters(); i++) {
1035 if ( (cl = GetCaloCluster(i)) ) {
1038 AliDebug(1,Form("IsEMCAL cluster %d Size: %d \n",i,clusters->GetEntriesFast()));
1042 return clusters->GetEntriesFast();
1045 const void AliESDEvent::WriteToTree(TTree* tree) const {
1046 // Book the branches as in TTree::Branch(TCollection*)
1047 // but add a "." at the end of top level branches which are
1048 // not a TClonesArray
1052 TIter next(fESDObjects);
1053 const Int_t kSplitlevel = 99; // default value in TTree::Branch()
1054 const Int_t kBufsize = 32000; // default value in TTree::Branch()
1057 while ((obj = next())) {
1058 branchname.Form("%s", obj->GetName());
1059 if ((kSplitlevel > 1) && !obj->InheritsFrom(TClonesArray::Class())) {
1060 if(!branchname.EndsWith("."))branchname += ".";
1062 tree->Bronch(branchname, obj->ClassName(), fESDObjects->GetObjectRef(obj),
1063 kBufsize, kSplitlevel - 1);
1069 void AliESDEvent::ReadFromTree(TTree *tree){
1071 // Connect the ESDEvent to a tree
1074 Printf("%s %d AliESDEvent::ReadFromTree() Zero Pointer to Tree \n",(char*)__FILE__,__LINE__);
1078 if(!tree->GetTree())tree->LoadTree(0);
1080 // if we find the "ESD" branch on the tree we do have the old structure
1081 if(tree->GetBranch("ESD")) {
1082 char ** address = (char **)(tree->GetBranch("ESD")->GetAddress());
1083 // do we have the friend branch
1084 TBranch * esdFB = tree->GetBranch("ESDfriend.");
1085 char ** addressF = 0;
1086 if(esdFB)addressF = (char **)(esdFB->GetAddress());
1088 printf("%s %d AliESDEvent::ReadFromTree() Reading old Tree \n",(char*)__FILE__,__LINE__);
1089 tree->SetBranchAddress("ESD", &fESDOld);
1091 tree->SetBranchAddress("ESDfriend.",&fESDFriendOld);
1094 printf("%s %d AliESDEvent::ReadFromTree() Reading old Tree \n",(char*)__FILE__,__LINE__);
1095 printf("%s %d Branch already connected. Using existing branch address. \n",(char*)__FILE__,__LINE__);
1096 fESDOld = (AliESD*) (*address);
1097 // addressF can still be 0, since branch needs to switched on
1098 if(addressF)fESDFriendOld = (AliESDfriend*) (*addressF);
1101 // have already connected the old ESD structure... ?
1102 // reuse also the pointer of the AlliESDEvent
1103 // otherwise create new ones
1104 TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("ESDObjectsConnectedToTree"));
1107 // If connected use the connected list of objects
1108 if(fESDObjects!= connectedList){
1109 // protect when called twice
1110 fESDObjects->Delete();
1111 fESDObjects = connectedList;
1116 // The pointer to the friend changes when called twice via InitIO
1117 // since AliESDEvent is deleted
1118 TObject* oldf = FindListObject("AliESDfriend");
1121 newf = (TObject*)*addressF;
1123 if(newf!=0&&oldf!=newf){
1124 // remove the old reference
1125 // Should we also delete it? Or is this handled in TTree I/O
1126 // since it is created by the first SetBranchAddress
1127 fESDObjects->Remove(oldf);
1129 fESDObjects->Add(newf);
1136 CreateStdContent(); // create for copy
1137 // if we have the esdfriend add it, so we always can access it via the userinfo
1138 if(fESDFriendOld)AddObject(fESDFriendOld);
1139 // we are not owner of the list objects
1140 // must not delete it
1141 fESDObjects->SetOwner(kFALSE);
1142 fESDObjects->SetName("ESDObjectsConnectedToTree");
1143 tree->GetUserInfo()->Add(fESDObjects);
1151 // Try to find AliESDEvent
1152 AliESDEvent *esdEvent = 0;
1153 esdEvent = (AliESDEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliESDEvent");
1155 // Check if already connected to tree
1156 TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("ESDObjectsConnectedToTree"));
1157 if (connectedList) {
1158 // If connected use the connected list if objects
1159 fESDObjects->Delete();
1160 fESDObjects = connectedList;
1167 // prevent a memory leak when reading back the TList
1173 // create a new TList from the UserInfo TList...
1174 // copy constructor does not work...
1176 fESDObjects = (TList*)(esdEvent->GetList()->Clone());
1177 fESDObjects->SetOwner(kFALSE);
1180 // we only need new things in the list if we do no already have it..
1181 // TODO just add new entries
1183 if(fESDObjects->GetEntries()<kESDListN){
1184 printf("%s %d AliESDEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
1185 (char*)__FILE__,__LINE__,fESDObjects->GetEntries(),kESDListN);
1187 // set the branch addresses
1188 TIter next(fESDObjects);
1190 while((el=(TNamed*)next())){
1191 TString bname(el->GetName());
1192 if(bname.CompareTo("AliESDfriend")==0)
1194 // AliESDfriend does not have a name ...
1195 tree->SetBranchAddress("ESDfriend.",fESDObjects->GetObjectRef(el));
1198 // check if branch exists under this Name
1199 TBranch *br = tree->GetBranch(bname.Data());
1201 tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
1204 br = tree->GetBranch(Form("%s.",bname.Data()));
1206 tree->SetBranchAddress(Form("%s.",bname.Data()),fESDObjects->GetObjectRef(el));
1209 printf("%s %d AliESDEvent::ReadFromTree() No Branch found with Name %s or %s. \n",
1210 (char*)__FILE__,__LINE__,bname.Data(),bname.Data());
1217 // when reading back we are not owner of the list
1218 // must not delete it
1219 fESDObjects->SetOwner(kFALSE);
1220 fESDObjects->SetName("ESDObjectsConnectedToTree");
1221 // we are not owner of the list objects
1222 // must not delete it
1223 tree->GetUserInfo()->Add(fESDObjects);
1227 // we can't get the list from the user data, create standard content
1228 // and set it by hand (no ESDfriend at the moment
1230 TIter next(fESDObjects);
1232 while((el=(TNamed*)next())){
1233 TString bname(el->GetName());
1234 TBranch *br = tree->GetBranch(bname.Data());
1236 tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
1239 br = tree->GetBranch(Form("%s.",bname.Data()));
1241 tree->SetBranchAddress(Form("%s.",bname.Data()),fESDObjects->GetObjectRef(el));
1246 // when reading back we are not owner of the list
1247 // must not delete it
1248 fESDObjects->SetOwner(kFALSE);
1253 void AliESDEvent::CopyFromOldESD()
1255 // Method which copies over everthing from the old esd structure to the
1260 SetRunNumber(fESDOld->GetRunNumber());
1261 SetPeriodNumber(fESDOld->GetPeriodNumber());
1262 SetMagneticField(fESDOld->GetMagneticField());
1264 // leave out diamond ...
1265 // SetDiamond(const AliESDVertex *vertex) { fESDRun->SetDiamond(vertex);}
1268 SetTriggerMask(fESDOld->GetTriggerMask());
1269 SetOrbitNumber(fESDOld->GetOrbitNumber());
1270 SetTimeStamp(fESDOld->GetTimeStamp());
1271 SetEventType(fESDOld->GetEventType());
1272 SetEventNumberInFile(fESDOld->GetEventNumberInFile());
1273 SetBunchCrossNumber(fESDOld->GetBunchCrossNumber());
1274 SetTriggerCluster(fESDOld->GetTriggerCluster());
1278 SetZDC(fESDOld->GetZDCN1Energy(),
1279 fESDOld->GetZDCP1Energy(),
1280 fESDOld->GetZDCEMEnergy(),
1282 fESDOld->GetZDCN2Energy(),
1283 fESDOld->GetZDCP2Energy(),
1284 fESDOld->GetZDCParticipants());
1288 if(fESDOld->GetFMDData())SetFMDData(fESDOld->GetFMDData());
1292 SetT0zVertex(fESDOld->GetT0zVertex());
1293 SetT0(fESDOld->GetT0());
1297 if (fESDOld->GetVZEROData()) SetVZEROData(fESDOld->GetVZEROData());
1299 if(fESDOld->GetVertex())SetPrimaryVertexSPD(fESDOld->GetVertex());
1301 if(fESDOld->GetPrimaryVertex())SetPrimaryVertex(fESDOld->GetPrimaryVertex());
1303 if(fESDOld->GetMultiplicity())SetMultiplicity(fESDOld->GetMultiplicity());
1305 for(int i = 0;i<fESDOld->GetNumberOfTracks();i++){
1306 AddTrack(fESDOld->GetTrack(i));
1309 for(int i = 0;i<fESDOld->GetNumberOfMuonTracks();i++){
1310 AddMuonTrack(fESDOld->GetMuonTrack(i));
1313 for(int i = 0;i<fESDOld->GetNumberOfPmdTracks();i++){
1314 AddPmdTrack(fESDOld->GetPmdTrack(i));
1317 for(int i = 0;i<fESDOld->GetNumberOfTrdTracks();i++){
1318 AddTrdTrack(fESDOld->GetTrdTrack(i));
1321 for(int i = 0;i<fESDOld->GetNumberOfV0s();i++){
1322 AddV0(fESDOld->GetV0(i));
1325 for(int i = 0;i<fESDOld->GetNumberOfCascades();i++){
1326 AddCascade(fESDOld->GetCascade(i));
1329 for(int i = 0;i<fESDOld->GetNumberOfKinks();i++){
1330 AddKink(fESDOld->GetKink(i));
1334 for(int i = 0;i<fESDOld->GetNumberOfCaloClusters();i++){
1335 AddCaloCluster(fESDOld->GetCaloCluster(i));