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),
128 fFirstEMCALCluster(-1),
130 fFirstPHOSCluster(-1)
133 //______________________________________________________________________________
134 AliESDEvent::AliESDEvent(const AliESDEvent& esd):
136 fESDObjects(new TList()),
137 fESDRun(new AliESDRun(*esd.fESDRun)),
138 fHeader(new AliESDHeader(*esd.fHeader)),
139 fESDZDC(new AliESDZDC(*esd.fESDZDC)),
140 fESDFMD(new AliESDFMD(*esd.fESDFMD)),
141 fESDVZERO(new AliESDVZERO(*esd.fESDVZERO)),
142 fESDTZERO(new AliESDTZERO(*esd.fESDTZERO)),
143 fTPCVertex(new AliESDVertex(*esd.fTPCVertex)),
144 fSPDVertex(new AliESDVertex(*esd.fSPDVertex)),
145 fPrimaryVertex(new AliESDVertex(*esd.fPrimaryVertex)),
146 fSPDMult(new AliMultiplicity(*esd.fSPDMult)),
147 fPHOSTrigger(new AliESDCaloTrigger(*esd.fPHOSTrigger)),
148 fEMCALTrigger(new AliESDCaloTrigger(*esd.fEMCALTrigger)),
149 fESDACORDE(new AliESDACORDE(*esd.fESDACORDE)),
150 fTracks(new TClonesArray(*esd.fTracks)),
151 fMuonTracks(new TClonesArray(*esd.fMuonTracks)),
152 fPmdTracks(new TClonesArray(*esd.fPmdTracks)),
153 fTrdTracks(new TClonesArray(*esd.fTrdTracks)),
154 fV0s(new TClonesArray(*esd.fV0s)),
155 fCascades(new TClonesArray(*esd.fCascades)),
156 fKinks(new TClonesArray(*esd.fKinks)),
157 fCaloClusters(new TClonesArray(*esd.fCaloClusters)),
158 fEMCALCells(new AliESDCaloCells(*esd.fEMCALCells)),
159 fPHOSCells(new AliESDCaloCells(*esd.fPHOSCells)),
160 fErrorLogs(new TClonesArray(*esd.fErrorLogs)),
161 fESDOld(new AliESD(*esd.fESDOld)),
162 fESDFriendOld(new AliESDfriend(*esd.fESDFriendOld)),
163 fConnected(esd.fConnected),
164 fUseOwnList(esd.fUseOwnList),
165 fEMCALClusters(esd.fEMCALClusters),
166 fFirstEMCALCluster(esd.fFirstEMCALCluster),
167 fPHOSClusters(esd.fPHOSClusters),
168 fFirstPHOSCluster(esd.fFirstPHOSCluster)
171 // CKB init in the constructor list and only add here ...
176 AddObject(fESDVZERO);
177 AddObject(fESDTZERO);
178 AddObject(fTPCVertex);
179 AddObject(fSPDVertex);
180 AddObject(fPrimaryVertex);
182 AddObject(fPHOSTrigger);
183 AddObject(fEMCALTrigger);
185 AddObject(fMuonTracks);
186 AddObject(fPmdTracks);
187 AddObject(fTrdTracks);
189 AddObject(fCascades);
191 AddObject(fCaloClusters);
192 AddObject(fEMCALCells);
193 AddObject(fPHOSCells);
194 AddObject(fErrorLogs);
195 AddObject(fESDACORDE);
201 //______________________________________________________________________________
202 AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
204 // Assignment operator
206 if(&source == this) return *this;
207 AliVEvent::operator=(source);
209 // This assumes that the list is already created
210 // and that the virtual void Copy(Tobject&) function
211 // is correctly implemented in the derived class
212 // otherwise only TObject::Copy() will be used
216 if((fESDObjects->GetSize()==0)&&(source.fESDObjects->GetSize()>=kESDListN)){
217 // We cover the case that we do not yet have the
218 // standard content but the source has it
222 TIter next(source.GetList());
225 while ((its = next())) {
226 name.Form("%s", its->GetName());
227 TObject *mine = fESDObjects->FindObject(name.Data());
229 TClass* pClass=TClass::GetClass(its->ClassName());
231 AliWarning(Form("Can not find class description for entry %s (%s)\n",
232 its->ClassName(), name.Data()));
236 mine=(TObject*)pClass->New();
238 // not in this: can be added to list
239 AliWarning(Form("%s:%d Could not find %s for copying \n",
240 (char*)__FILE__,__LINE__,name.Data()));
243 if(mine->InheritsFrom("TNamed")){
244 ((TNamed*)mine)->SetName(name);
246 else if(mine->InheritsFrom("TCollection")){
247 if(mine->InheritsFrom("TClonesArray"))
248 dynamic_cast<TClonesArray*>(mine)->SetClass(dynamic_cast<TClonesArray*>(its)->GetClass());
249 dynamic_cast<TCollection*>(mine)->SetName(name);
251 AliDebug(1, Form("adding object %s of type %s", mine->GetName(), mine->ClassName()));
255 if(!its->InheritsFrom("TCollection")){
259 else if(its->InheritsFrom("TClonesArray")){
260 // Create or expand the tclonesarray pointers
261 // so we can directly copy to the object
262 TClonesArray *its_tca = (TClonesArray*)its;
263 TClonesArray *mine_tca = (TClonesArray*)mine;
265 // this leaves the capacity of the TClonesArray the same
266 // except for a factor of 2 increase when size > capacity
267 // does not release any memory occupied by the tca
268 mine_tca->ExpandCreate(its_tca->GetEntriesFast());
269 for(int i = 0;i < its_tca->GetEntriesFast();++i){
271 TObject *mine_tca_obj = mine_tca->At(i);
272 TObject *its_tca_obj = its_tca->At(i);
273 // no need to delete first
274 // pointers within the class should be handled by Copy()...
275 // Can there be Empty slots?
276 its_tca_obj->Copy(*mine_tca_obj);
280 AliWarning(Form("%s:%d cannot copy TCollection \n",
281 (char*)__FILE__,__LINE__));
285 fConnected = source.fConnected;
286 fUseOwnList = source.fUseOwnList;
287 fEMCALClusters = source.fEMCALClusters;
288 fFirstEMCALCluster = source.fFirstEMCALCluster;
289 fPHOSClusters = source.fPHOSClusters;
290 fFirstPHOSCluster = source.fFirstPHOSCluster;
298 //______________________________________________________________________________
299 AliESDEvent::~AliESDEvent()
302 // Standard destructor
305 // everthing on the list gets deleted automatically
308 if(fESDObjects&&!fConnected)
317 void AliESDEvent::Copy(TObject &obj) const {
319 // interface to TOBject::Copy
320 // Copies the content of this into obj!
321 // bascially obj = *this
323 if(this==&obj)return;
324 AliESDEvent *robj = dynamic_cast<AliESDEvent*>(&obj);
325 if(!robj)return; // not an AliESEvent
330 //______________________________________________________________________________
331 void AliESDEvent::Reset()
335 // Std content + Non std content
337 // Reset the standard contents
340 // reset for the old data without AliESDEvent...
341 if(fESDOld)fESDOld->Reset();
343 fESDFriendOld->~AliESDfriend();
344 new (fESDFriendOld) AliESDfriend();
348 if(fESDObjects->GetSize()>kESDListN){
349 // we have non std content
350 // this also covers esdfriends
351 for(int i = kESDListN;i < fESDObjects->GetSize();++i){
352 TObject *pObject = fESDObjects->At(i);
354 if(pObject->InheritsFrom(TClonesArray::Class())){
355 ((TClonesArray*)pObject)->Delete();
357 else if(!pObject->InheritsFrom(TCollection::Class())){
358 ResetWithPlacementNew(pObject);
361 AliWarning(Form("No reset for %s (%s)\n",
362 pObject->ClassName()));
369 Bool_t AliESDEvent::ResetWithPlacementNew(TObject *pObject){
370 Long_t dtoronly = TObject::GetDtorOnly();
371 TClass *pClass = TClass::GetClass(pObject->ClassName());
372 TObject::SetDtorOnly(pObject);
374 // Recreate with placement new
375 pClass->New(pObject);
376 // Restore the state.
377 TObject::SetDtorOnly((void*)dtoronly);
381 void AliESDEvent::ResetStdContent()
383 // Reset the standard contents
384 if(fESDRun) fESDRun->Reset();
385 if(fHeader) fHeader->Reset();
386 if(fESDZDC) fESDZDC->Reset();
391 // reset by callin d'to /c'tor keep the pointer
392 fESDVZERO->~AliESDVZERO();
393 new (fESDVZERO) AliESDVZERO();
396 fESDACORDE->~AliESDACORDE();
397 new (fESDACORDE) AliESDACORDE();
399 if(fESDTZERO) fESDTZERO->Reset();
400 // CKB no clear/reset implemented
402 fTPCVertex->~AliESDVertex();
403 new (fTPCVertex) AliESDVertex();
404 fTPCVertex->SetName(fgkESDListName[kTPCVertex]);
407 fSPDVertex->~AliESDVertex();
408 new (fSPDVertex) AliESDVertex();
409 fSPDVertex->SetName(fgkESDListName[kSPDVertex]);
412 fPrimaryVertex->~AliESDVertex();
413 new (fPrimaryVertex) AliESDVertex();
414 fPrimaryVertex->SetName(fgkESDListName[kPrimaryVertex]);
417 fSPDMult->~AliMultiplicity();
418 new (fSPDMult) AliMultiplicity();
420 if(fPHOSTrigger)fPHOSTrigger->Reset();
421 if(fEMCALTrigger)fEMCALTrigger->Reset();
422 if(fTracks)fTracks->Delete();
423 if(fMuonTracks)fMuonTracks->Delete();
424 if(fPmdTracks)fPmdTracks->Delete();
425 if(fTrdTracks)fTrdTracks->Delete();
426 if(fV0s)fV0s->Delete();
427 if(fCascades)fCascades->Delete();
428 if(fKinks)fKinks->Delete();
429 if(fCaloClusters)fCaloClusters->Delete();
430 if(fPHOSCells)fPHOSCells->DeleteContainer();
431 if(fEMCALCells)fEMCALCells->DeleteContainer();
432 if(fErrorLogs) fErrorLogs->Delete();
434 // don't reset fconnected fConnected and the list
437 fFirstEMCALCluster=-1;
439 fFirstPHOSCluster=-1;
443 Int_t AliESDEvent::AddV0(const AliESDv0 *v) {
447 TClonesArray &fv = *fV0s;
448 Int_t idx=fV0s->GetEntriesFast();
449 new(fv[idx]) AliESDv0(*v);
453 //______________________________________________________________________________
454 void AliESDEvent::Print(Option_t *) const
457 // Print header information of the event
459 printf("ESD run information\n");
460 printf("Event # in file %d Bunch crossing # %d Orbit # %d Period # %d Run # %d Trigger %lld Magnetic field %f \n",
461 GetEventNumberInFile(),
462 GetBunchCrossNumber(),
467 GetMagneticField() );
468 printf("Vertex: (%.4f +- %.4f, %.4f +- %.4f, %.4f +- %.4f) cm\n",
469 fPrimaryVertex->GetXv(), fPrimaryVertex->GetXRes(),
470 fPrimaryVertex->GetYv(), fPrimaryVertex->GetYRes(),
471 fPrimaryVertex->GetZv(), fPrimaryVertex->GetZRes());
472 printf("Mean vertex in RUN: X=%.4f Y=%.4f cm\n",
473 GetDiamondX(),GetDiamondY());
474 printf("SPD Multiplicity. Number of tracklets %d \n",
475 fSPDMult->GetNumberOfTracklets());
476 printf("Number of tracks: \n");
477 printf(" charged %d\n", GetNumberOfTracks());
478 printf(" muon %d\n", GetNumberOfMuonTracks());
479 printf(" pmd %d\n", GetNumberOfPmdTracks());
480 printf(" trd %d\n", GetNumberOfTrdTracks());
481 printf(" v0 %d\n", GetNumberOfV0s());
482 printf(" cascades %d\n", GetNumberOfCascades());
483 printf(" kinks %d\n", GetNumberOfKinks());
484 if(fPHOSCells)printf(" PHOSCells %d\n", fPHOSCells->GetNumberOfCells());
485 else printf(" PHOSCells not in the Event\n");
486 if(fEMCALCells)printf(" EMCALCells %d\n", fEMCALCells->GetNumberOfCells());
487 else printf(" EMCALCells not in the Event\n");
488 printf(" CaloClusters %d\n", GetNumberOfCaloClusters());
489 printf(" phos %d\n", GetNumberOfPHOSClusters());
490 printf(" emcal %d\n", GetNumberOfEMCALClusters());
491 printf(" FMD %s\n", (fESDFMD ? "yes" : "no"));
492 printf(" VZERO %s\n", (fESDVZERO ? "yes" : "no"));
497 void AliESDEvent::SetESDfriend(const AliESDfriend *ev) const {
499 // Attaches the complementary info to the ESD
503 // to be sure that we set the tracks also
504 // in case of old esds
505 // if(fESDOld)CopyFromOldESD();
507 Int_t ntrk=ev->GetNumberOfTracks();
509 for (Int_t i=0; i<ntrk; i++) {
510 const AliESDfriendTrack *f=ev->GetTrack(i);
511 GetTrack(i)->SetFriendTrack(f);
515 Bool_t AliESDEvent::RemoveKink(Int_t rm) const {
516 // ---------------------------------------------------------
517 // Remove a kink candidate and references to it from ESD,
518 // if this candidate does not come from a reconstructed decay
519 // Not yet implemented...
520 // ---------------------------------------------------------
521 Int_t last=GetNumberOfKinks()-1;
522 if ((rm<0)||(rm>last)) return kFALSE;
527 Bool_t AliESDEvent::RemoveV0(Int_t rm) const {
528 // ---------------------------------------------------------
529 // Remove a V0 candidate and references to it from ESD,
530 // if this candidate does not come from a reconstructed decay
531 // ---------------------------------------------------------
532 Int_t last=GetNumberOfV0s()-1;
533 if ((rm<0)||(rm>last)) return kFALSE;
535 AliESDv0 *v0=GetV0(rm);
536 Int_t idxP=v0->GetPindex(), idxN=v0->GetNindex();
539 Int_t lastIdxP=v0->GetPindex(), lastIdxN=v0->GetNindex();
543 // Check if this V0 comes from a reconstructed decay
544 Int_t ncs=GetNumberOfCascades();
545 for (Int_t n=0; n<ncs; n++) {
546 AliESDcascade *cs=GetCascade(n);
548 Int_t csIdxP=cs->GetPindex();
549 Int_t csIdxN=cs->GetNindex();
552 if (idxN==csIdxN) return kFALSE;
554 if (csIdxP==lastIdxP)
555 if (csIdxN==lastIdxN) used++;
558 //Replace the removed V0 with the last V0
559 TClonesArray &a=*fV0s;
560 delete a.RemoveAt(rm);
562 if (rm==last) return kTRUE;
564 //v0 is pointing to the last V0 candidate...
565 new (a[rm]) AliESDv0(*v0);
566 delete a.RemoveAt(last);
568 if (!used) return kTRUE;
571 // Remap the indices of the daughters of reconstructed decays
572 for (Int_t n=0; n<ncs; n++) {
573 AliESDcascade *cs=GetCascade(n);
576 Int_t csIdxP=cs->GetPindex();
577 Int_t csIdxN=cs->GetNindex();
579 if (csIdxP==lastIdxP)
580 if (csIdxN==lastIdxN) {
581 cs->AliESDv0::SetIndex(1,idxP);
582 cs->AliESDv0::SetIndex(0,idxN);
584 if (!used) return kTRUE;
591 Bool_t AliESDEvent::RemoveTrack(Int_t rm) const {
592 // ---------------------------------------------------------
593 // Remove a track and references to it from ESD,
594 // if this track does not come from a reconstructed decay
595 // ---------------------------------------------------------
596 Int_t last=GetNumberOfTracks()-1;
597 if ((rm<0)||(rm>last)) return kFALSE;
601 // Check if this track comes from the reconstructed primary vertices
602 if (fTPCVertex && fTPCVertex->GetStatus()) {
603 UShort_t *primIdx=fTPCVertex->GetIndices();
604 Int_t n=fTPCVertex->GetNIndices();
606 Int_t idx=Int_t(primIdx[n]);
607 if (rm==idx) return kFALSE;
608 if (idx==last) used++;
611 if (fPrimaryVertex && fPrimaryVertex->GetStatus()) {
612 UShort_t *primIdx=fPrimaryVertex->GetIndices();
613 Int_t n=fPrimaryVertex->GetNIndices();
615 Int_t idx=Int_t(primIdx[n]);
616 if (rm==idx) return kFALSE;
617 if (idx==last) used++;
621 // Check if this track comes from a reconstructed decay
622 Int_t nv0=GetNumberOfV0s();
623 for (Int_t n=0; n<nv0; n++) {
624 AliESDv0 *v0=GetV0(n);
626 Int_t idx=v0->GetNindex();
627 if (rm==idx) return kFALSE;
628 if (idx==last) used++;
631 if (rm==idx) return kFALSE;
632 if (idx==last) used++;
635 Int_t ncs=GetNumberOfCascades();
636 for (Int_t n=0; n<ncs; n++) {
637 AliESDcascade *cs=GetCascade(n);
639 Int_t idx=cs->GetIndex();
640 if (rm==idx) return kFALSE;
641 if (idx==last) used++;
644 Int_t nkn=GetNumberOfKinks();
645 for (Int_t n=0; n<nkn; n++) {
646 AliESDkink *kn=GetKink(n);
648 Int_t idx=kn->GetIndex(0);
649 if (rm==idx) return kFALSE;
650 if (idx==last) used++;
653 if (rm==idx) return kFALSE;
654 if (idx==last) used++;
658 //Replace the removed track with the last track
659 TClonesArray &a=*fTracks;
660 delete a.RemoveAt(rm);
662 if (rm==last) return kTRUE;
664 AliESDtrack *t=GetTrack(last);
666 new (a[rm]) AliESDtrack(*t);
667 delete a.RemoveAt(last);
670 if (!used) return kTRUE;
673 // Remap the indices of the tracks used for the primary vertex reconstruction
674 if (fTPCVertex && fTPCVertex->GetStatus()) {
675 UShort_t *primIdx=fTPCVertex->GetIndices();
676 Int_t n=fTPCVertex->GetNIndices();
678 Int_t idx=Int_t(primIdx[n]);
680 primIdx[n]=Short_t(rm);
682 if (!used) return kTRUE;
686 if (fPrimaryVertex && fPrimaryVertex->GetStatus()) {
687 UShort_t *primIdx=fPrimaryVertex->GetIndices();
688 Int_t n=fPrimaryVertex->GetNIndices();
690 Int_t idx=Int_t(primIdx[n]);
692 primIdx[n]=Short_t(rm);
694 if (!used) return kTRUE;
699 // Remap the indices of the daughters of reconstructed decays
700 for (Int_t n=0; n<nv0; n++) {
701 AliESDv0 *v0=GetV0(n);
702 if (v0->GetIndex(0)==last) {
705 if (!used) return kTRUE;
707 if (v0->GetIndex(1)==last) {
710 if (!used) return kTRUE;
714 for (Int_t n=0; n<ncs; n++) {
715 AliESDcascade *cs=GetCascade(n);
716 if (cs->GetIndex()==last) {
719 if (!used) return kTRUE;
723 for (Int_t n=0; n<nkn; n++) {
724 AliESDkink *kn=GetKink(n);
725 if (kn->GetIndex(0)==last) {
728 if (!used) return kTRUE;
730 if (kn->GetIndex(1)==last) {
733 if (!used) return kTRUE;
741 Bool_t AliESDEvent::Clean(Float_t *cleanPars) {
743 // Remove the data which are not needed for the physics analysis.
745 // 1) Cleaning the V0 candidates
746 // ---------------------------
747 // If the cosine of the V0 pointing angle "csp" and
748 // the DCA between the daughter tracks "dca" does not satisfy
751 // csp > cleanPars[1] + dca/cleanPars[0]*(1.- cleanPars[1])
753 // an attempt to remove this V0 candidate from ESD is made.
755 // The V0 candidate gets removed if it does not belong to any
756 // recosntructed cascade decay
758 // 12.11.2007, optimal values: cleanPars[0]=0.5, cleanPars[1]=0.999
760 // 2) Cleaning the tracks
761 // ----------------------
762 // If track's transverse parameter is larger than cleanPars[2]
764 // track's longitudinal parameter is larger than cleanPars[3]
765 // an attempt to remove this track from ESD is made.
767 // The track gets removed if it does not come
768 // from a reconstructed decay
772 Float_t dcaMax=cleanPars[0];
773 Float_t cspMin=cleanPars[1];
775 Int_t nV0s=GetNumberOfV0s();
776 for (Int_t i=nV0s-1; i>=0; i--) {
777 AliESDv0 *v0=GetV0(i);
779 Float_t dca=v0->GetDcaV0Daughters();
780 Float_t csp=v0->GetV0CosineOfPointingAngle();
781 Float_t cspcut=cspMin + dca/dcaMax*(1.-cspMin);
782 if (csp > cspcut) continue;
783 if (RemoveV0(i)) rc=kTRUE;
787 Float_t dmax=cleanPars[2], zmax=cleanPars[3];
789 const AliESDVertex *vertex=GetPrimaryVertexSPD();
790 Bool_t vtxOK=vertex->GetStatus();
792 Int_t nTracks=GetNumberOfTracks();
793 for (Int_t i=nTracks-1; i>=0; i--) {
794 AliESDtrack *track=GetTrack(i);
795 Float_t xy,z; track->GetImpactParameters(xy,z);
796 if ((TMath::Abs(xy) > dmax) || (vtxOK && (TMath::Abs(z) > zmax))) {
797 if (RemoveTrack(i)) rc=kTRUE;
804 Int_t AliESDEvent::AddTrack(const AliESDtrack *t)
807 TClonesArray &ftr = *fTracks;
808 AliESDtrack * track = new(ftr[fTracks->GetEntriesFast()])AliESDtrack(*t);
809 track->SetID(fTracks->GetEntriesFast()-1);
810 return track->GetID();
813 void AliESDEvent::AddMuonTrack(const AliESDMuonTrack *t)
815 TClonesArray &fmu = *fMuonTracks;
816 new(fmu[fMuonTracks->GetEntriesFast()]) AliESDMuonTrack(*t);
819 void AliESDEvent::AddPmdTrack(const AliESDPmdTrack *t)
821 TClonesArray &fpmd = *fPmdTracks;
822 new(fpmd[fPmdTracks->GetEntriesFast()]) AliESDPmdTrack(*t);
825 void AliESDEvent::AddTrdTrack(const AliESDTrdTrack *t)
827 TClonesArray &ftrd = *fTrdTracks;
828 new(ftrd[fTrdTracks->GetEntriesFast()]) AliESDTrdTrack(*t);
834 Int_t AliESDEvent::AddKink(const AliESDkink *c)
837 TClonesArray &fk = *fKinks;
838 AliESDkink * kink = new(fk[fKinks->GetEntriesFast()]) AliESDkink(*c);
839 kink->SetID(fKinks->GetEntriesFast()); // CKB different from the other imps..
840 return fKinks->GetEntriesFast()-1;
844 void AliESDEvent::AddCascade(const AliESDcascade *c)
846 TClonesArray &fc = *fCascades;
847 new(fc[fCascades->GetEntriesFast()]) AliESDcascade(*c);
851 Int_t AliESDEvent::AddCaloCluster(const AliESDCaloCluster *c)
854 TClonesArray &fc = *fCaloClusters;
855 AliESDCaloCluster *clus = new(fc[fCaloClusters->GetEntriesFast()]) AliESDCaloCluster(*c);
856 clus->SetID(fCaloClusters->GetEntriesFast()-1);
857 return fCaloClusters->GetEntriesFast()-1;
861 void AliESDEvent::AddRawDataErrorLog(const AliRawDataErrorLog *log) const {
862 TClonesArray &errlogs = *fErrorLogs;
863 new(errlogs[errlogs.GetEntriesFast()]) AliRawDataErrorLog(*log);
866 void AliESDEvent::SetPrimaryVertexTPC(const AliESDVertex *vertex)
868 // Set the TPC vertex
869 // use already allocated space
871 *fTPCVertex = *vertex;
872 fTPCVertex->SetName(fgkESDListName[kTPCVertex]);
876 void AliESDEvent::SetPrimaryVertexSPD(const AliESDVertex *vertex)
878 // Set the SPD vertex
879 // use already allocated space
881 *fSPDVertex = *vertex;
882 fSPDVertex->SetName(fgkESDListName[kSPDVertex]);
886 void AliESDEvent::SetPrimaryVertexTracks(const AliESDVertex *vertex)
888 // Set the primary vertex reconstructed using he ESD tracks.
889 // use already allocated space
891 *fPrimaryVertex = *vertex;
892 fPrimaryVertex->SetName(fgkESDListName[kPrimaryVertex]);
896 const AliESDVertex * AliESDEvent::GetPrimaryVertex() const
899 // Get the "best" available reconstructed primary vertex.
902 if (fPrimaryVertex->GetStatus()) return fPrimaryVertex;
905 if (fSPDVertex->GetStatus()) return fSPDVertex;
907 if(fTPCVertex) return fTPCVertex;
909 AliWarning("No primary vertex available. Returning the \"default\"...");
913 void AliESDEvent::SetMultiplicity(const AliMultiplicity *mul)
915 // Set the SPD Multiplicity
922 void AliESDEvent::SetFMDData(AliESDFMD * obj)
924 // use already allocated space
930 void AliESDEvent::SetVZEROData(AliESDVZERO * obj)
932 // use already allocated space
937 void AliESDEvent::SetACORDEData(AliESDACORDE * obj)
944 void AliESDEvent::GetESDfriend(AliESDfriend *ev) const
947 // Extracts the complementary info from the ESD
951 Int_t ntrk=GetNumberOfTracks();
953 for (Int_t i=0; i<ntrk; i++) {
954 AliESDtrack *t=GetTrack(i);
955 const AliESDfriendTrack *f=t->GetFriendTrack();
958 t->ReleaseESDfriendTrack();// Not to have two copies of "friendTrack"
962 AliESDfriend *fr = (AliESDfriend*)(const_cast<AliESDEvent*>(this)->FindListObject("AliESDfriend"));
963 if (fr) ev->SetVZEROfriend(fr->GetVZEROfriend());
966 void AliESDEvent::AddObject(TObject* obj)
968 // Add an object to the list of object.
969 // Please be aware that in order to increase performance you should
970 // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
971 fESDObjects->SetOwner(kTRUE);
972 fESDObjects->AddLast(obj);
976 void AliESDEvent::GetStdContent()
978 // set pointers for standard content
979 // get by name much safer and not a big overhead since not called very often
981 fESDRun = (AliESDRun*)fESDObjects->FindObject(fgkESDListName[kESDRun]);
982 fHeader = (AliESDHeader*)fESDObjects->FindObject(fgkESDListName[kHeader]);
983 fESDZDC = (AliESDZDC*)fESDObjects->FindObject(fgkESDListName[kESDZDC]);
984 fESDFMD = (AliESDFMD*)fESDObjects->FindObject(fgkESDListName[kESDFMD]);
985 fESDVZERO = (AliESDVZERO*)fESDObjects->FindObject(fgkESDListName[kESDVZERO]);
986 fESDTZERO = (AliESDTZERO*)fESDObjects->FindObject(fgkESDListName[kESDTZERO]);
987 fTPCVertex = (AliESDVertex*)fESDObjects->FindObject(fgkESDListName[kTPCVertex]);
988 fSPDVertex = (AliESDVertex*)fESDObjects->FindObject(fgkESDListName[kSPDVertex]);
989 fPrimaryVertex = (AliESDVertex*)fESDObjects->FindObject(fgkESDListName[kPrimaryVertex]);
990 fSPDMult = (AliMultiplicity*)fESDObjects->FindObject(fgkESDListName[kSPDMult]);
991 fPHOSTrigger = (AliESDCaloTrigger*)fESDObjects->FindObject(fgkESDListName[kPHOSTrigger]);
992 fEMCALTrigger = (AliESDCaloTrigger*)fESDObjects->FindObject(fgkESDListName[kEMCALTrigger]);
993 fTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTracks]);
994 fMuonTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kMuonTracks]);
995 fPmdTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kPmdTracks]);
996 fTrdTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTrdTracks]);
997 fV0s = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kV0s]);
998 fCascades = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kCascades]);
999 fKinks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kKinks]);
1000 fCaloClusters = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kCaloClusters]);
1001 fEMCALCells = (AliESDCaloCells*)fESDObjects->FindObject(fgkESDListName[kEMCALCells]);
1002 fPHOSCells = (AliESDCaloCells*)fESDObjects->FindObject(fgkESDListName[kPHOSCells]);
1003 fErrorLogs = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kErrorLogs]);
1004 fESDACORDE = (AliESDACORDE*)fESDObjects->FindObject(fgkESDListName[kESDACORDE]);
1008 void AliESDEvent::SetStdNames(){
1009 // Set the names of the standard contents
1011 if(fESDObjects->GetEntries()>=kESDListN){
1012 for(int i = 0;i < fESDObjects->GetEntries() && i<kESDListN;i++){
1013 TObject *fObj = fESDObjects->At(i);
1014 if(fObj->InheritsFrom("TNamed")){
1015 ((TNamed*)fObj)->SetName(fgkESDListName[i]);
1017 else if(fObj->InheritsFrom("TClonesArray")){
1018 ((TClonesArray*)fObj)->SetName(fgkESDListName[i]);
1023 AliWarning("Std Entries missing");
1028 void AliESDEvent::CreateStdContent(Bool_t bUseThisList){
1029 fUseOwnList = bUseThisList;
1033 void AliESDEvent::CreateStdContent()
1035 // create the standard AOD content and set pointers
1037 // create standard objects and add them to the TList of objects
1038 AddObject(new AliESDRun());
1039 AddObject(new AliESDHeader());
1040 AddObject(new AliESDZDC());
1041 AddObject(new AliESDFMD());
1042 AddObject(new AliESDVZERO());
1043 AddObject(new AliESDTZERO());
1044 AddObject(new AliESDVertex());
1045 AddObject(new AliESDVertex());
1046 AddObject(new AliESDVertex());
1047 AddObject(new AliMultiplicity());
1048 AddObject(new AliESDCaloTrigger());
1049 AddObject(new AliESDCaloTrigger());
1050 AddObject(new TClonesArray("AliESDtrack",0));
1051 AddObject(new TClonesArray("AliESDMuonTrack",0));
1052 AddObject(new TClonesArray("AliESDPmdTrack",0));
1053 AddObject(new TClonesArray("AliESDTrdTrack",0));
1054 AddObject(new TClonesArray("AliESDv0",0));
1055 AddObject(new TClonesArray("AliESDcascade",0));
1056 AddObject(new TClonesArray("AliESDkink",0));
1057 AddObject(new TClonesArray("AliESDCaloCluster",0));
1058 AddObject(new AliESDCaloCells());
1059 AddObject(new AliESDCaloCells());
1060 AddObject(new TClonesArray("AliRawDataErrorLog",0));
1061 AddObject(new AliESDACORDE());
1063 // check the order of the indices against enum...
1067 // read back pointers
1071 TObject* AliESDEvent::FindListObject(const char *name){
1073 // Find object with name "name" in the list of branches
1076 return fESDObjects->FindObject(name);
1081 Int_t AliESDEvent::GetPHOSClusters(TRefArray *clusters) const
1083 // fills the provided TRefArray with all found phos clusters
1087 AliESDCaloCluster *cl = 0;
1088 for (Int_t i = 0; i < GetNumberOfCaloClusters(); i++) {
1090 if ( (cl = GetCaloCluster(i)) ) {
1093 AliDebug(1,Form("IsPHOS cluster %d Size: %d \n",i,clusters->GetEntriesFast()));
1097 return clusters->GetEntriesFast();
1100 Int_t AliESDEvent::GetEMCALClusters(TRefArray *clusters) const
1102 // fills the provided TRefArray with all found emcal clusters
1106 AliESDCaloCluster *cl = 0;
1107 for (Int_t i = 0; i < GetNumberOfCaloClusters(); i++) {
1109 if ( (cl = GetCaloCluster(i)) ) {
1112 AliDebug(1,Form("IsEMCAL cluster %d Size: %d \n",i,clusters->GetEntriesFast()));
1116 return clusters->GetEntriesFast();
1119 void AliESDEvent::WriteToTree(TTree* tree) const {
1120 // Book the branches as in TTree::Branch(TCollection*)
1121 // but add a "." at the end of top level branches which are
1122 // not a TClonesArray
1126 TIter next(fESDObjects);
1127 const Int_t kSplitlevel = 99; // default value in TTree::Branch()
1128 const Int_t kBufsize = 32000; // default value in TTree::Branch()
1131 while ((obj = next())) {
1132 branchname.Form("%s", obj->GetName());
1133 if(branchname.CompareTo("AliESDfriend")==0)branchname = "ESDfriend.";
1134 if ((kSplitlevel > 1) && !obj->InheritsFrom(TClonesArray::Class())) {
1135 if(!branchname.EndsWith("."))branchname += ".";
1137 if (!tree->FindBranch(branchname)) {
1138 tree->Bronch(branchname, obj->ClassName(), fESDObjects->GetObjectRef(obj),
1139 kBufsize, kSplitlevel - 1);
1145 void AliESDEvent::ReadFromTree(TTree *tree, Option_t* /*opt*/){
1147 // Connect the ESDEvent to a tree
1150 AliWarning("AliESDEvent::ReadFromTree() Zero Pointer to Tree \n");
1154 if(!tree->GetTree())tree->LoadTree(0);
1156 // if we find the "ESD" branch on the tree we do have the old structure
1157 if(tree->GetBranch("ESD")) {
1158 char ** address = (char **)(tree->GetBranch("ESD")->GetAddress());
1159 // do we have the friend branch
1160 TBranch * esdFB = tree->GetBranch("ESDfriend.");
1161 char ** addressF = 0;
1162 if(esdFB)addressF = (char **)(esdFB->GetAddress());
1164 AliInfo("AliESDEvent::ReadFromTree() Reading old Tree");
1165 tree->SetBranchAddress("ESD", &fESDOld);
1167 tree->SetBranchAddress("ESDfriend.",&fESDFriendOld);
1170 AliInfo("AliESDEvent::ReadFromTree() Reading old Tree");
1171 AliInfo("Branch already connected. Using existing branch address.");
1172 fESDOld = (AliESD*) (*address);
1173 // addressF can still be 0, since branch needs to switched on
1174 if(addressF)fESDFriendOld = (AliESDfriend*) (*addressF);
1177 // have already connected the old ESD structure... ?
1178 // reuse also the pointer of the AlliESDEvent
1179 // otherwise create new ones
1180 TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("ESDObjectsConnectedToTree"));
1183 // If connected use the connected list of objects
1184 if(fESDObjects!= connectedList){
1185 // protect when called twice
1186 fESDObjects->Delete();
1187 fESDObjects = connectedList;
1192 // The pointer to the friend changes when called twice via InitIO
1193 // since AliESDEvent is deleted
1194 TObject* oldf = FindListObject("AliESDfriend");
1197 newf = (TObject*)*addressF;
1199 if(newf!=0&&oldf!=newf){
1200 // remove the old reference
1201 // Should we also delete it? Or is this handled in TTree I/O
1202 // since it is created by the first SetBranchAddress
1203 fESDObjects->Remove(oldf);
1205 fESDObjects->Add(newf);
1212 CreateStdContent(); // create for copy
1213 // if we have the esdfriend add it, so we always can access it via the userinfo
1214 if(fESDFriendOld)AddObject(fESDFriendOld);
1215 // we are not owner of the list objects
1216 // must not delete it
1217 fESDObjects->SetOwner(kFALSE);
1218 fESDObjects->SetName("ESDObjectsConnectedToTree");
1219 tree->GetUserInfo()->Add(fESDObjects);
1227 // Try to find AliESDEvent
1228 AliESDEvent *esdEvent = 0;
1229 esdEvent = (AliESDEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliESDEvent");
1231 // Check if already connected to tree
1232 TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("ESDObjectsConnectedToTree"));
1233 if (connectedList) {
1234 // If connected use the connected list if objects
1235 fESDObjects->Delete();
1236 fESDObjects = connectedList;
1243 // prevent a memory leak when reading back the TList
1248 // create a new TList from the UserInfo TList...
1249 // copy constructor does not work...
1250 fESDObjects = (TList*)(esdEvent->GetList()->Clone());
1251 fESDObjects->SetOwner(kFALSE);
1253 else if ( fESDObjects->GetEntries()==0){
1254 // at least create the std content if we want to read to our list
1259 // we only need new things in the list if we do no already have it..
1260 // TODO just add new entries
1262 if(fESDObjects->GetEntries()<kESDListN){
1263 AliWarning(Form("AliESDEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
1264 fESDObjects->GetEntries(),kESDListN));
1266 // set the branch addresses
1267 TIter next(fESDObjects);
1269 while((el=(TNamed*)next())){
1270 TString bname(el->GetName());
1271 if(bname.CompareTo("AliESDfriend")==0)
1273 // AliESDfriend does not have a name ...
1274 tree->SetBranchAddress("ESDfriend.",fESDObjects->GetObjectRef(el));
1277 // check if branch exists under this Name
1278 TBranch *br = tree->GetBranch(bname.Data());
1280 tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
1283 br = tree->GetBranch(Form("%s.",bname.Data()));
1285 tree->SetBranchAddress(Form("%s.",bname.Data()),fESDObjects->GetObjectRef(el));
1288 AliWarning(Form("AliESDEvent::ReadFromTree() No Branch found with Name %s or %s.",bname.Data(),bname.Data()));
1295 // when reading back we are not owner of the list
1296 // must not delete it
1297 fESDObjects->SetOwner(kFALSE);
1298 fESDObjects->SetName("ESDObjectsConnectedToTree");
1299 // we are not owner of the list objects
1300 // must not delete it
1301 tree->GetUserInfo()->Add(fESDObjects);
1305 // we can't get the list from the user data, create standard content
1306 // and set it by hand (no ESDfriend at the moment
1308 TIter next(fESDObjects);
1310 while((el=(TNamed*)next())){
1311 TString bname(el->GetName());
1312 TBranch *br = tree->GetBranch(bname.Data());
1314 tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
1317 br = tree->GetBranch(Form("%s.",bname.Data()));
1319 tree->SetBranchAddress(Form("%s.",bname.Data()),fESDObjects->GetObjectRef(el));
1324 // when reading back we are not owner of the list
1325 // must not delete it
1326 fESDObjects->SetOwner(kFALSE);
1331 void AliESDEvent::CopyFromOldESD()
1333 // Method which copies over everthing from the old esd structure to the
1338 SetRunNumber(fESDOld->GetRunNumber());
1339 SetPeriodNumber(fESDOld->GetPeriodNumber());
1340 SetMagneticField(fESDOld->GetMagneticField());
1342 // leave out diamond ...
1343 // SetDiamond(const AliESDVertex *vertex) { fESDRun->SetDiamond(vertex);}
1346 SetTriggerMask(fESDOld->GetTriggerMask());
1347 SetOrbitNumber(fESDOld->GetOrbitNumber());
1348 SetTimeStamp(fESDOld->GetTimeStamp());
1349 SetEventType(fESDOld->GetEventType());
1350 SetEventNumberInFile(fESDOld->GetEventNumberInFile());
1351 SetBunchCrossNumber(fESDOld->GetBunchCrossNumber());
1352 SetTriggerCluster(fESDOld->GetTriggerCluster());
1356 SetZDC(fESDOld->GetZDCN1Energy(),
1357 fESDOld->GetZDCP1Energy(),
1358 fESDOld->GetZDCEMEnergy(),
1360 fESDOld->GetZDCN2Energy(),
1361 fESDOld->GetZDCP2Energy(),
1362 fESDOld->GetZDCParticipants(),
1367 if(fESDOld->GetFMDData())SetFMDData(fESDOld->GetFMDData());
1371 SetT0zVertex(fESDOld->GetT0zVertex());
1372 SetT0(fESDOld->GetT0());
1376 if (fESDOld->GetVZEROData()) SetVZEROData(fESDOld->GetVZEROData());
1378 if(fESDOld->GetVertex())SetPrimaryVertexSPD(fESDOld->GetVertex());
1380 if(fESDOld->GetPrimaryVertex())SetPrimaryVertexTracks(fESDOld->GetPrimaryVertex());
1382 if(fESDOld->GetMultiplicity())SetMultiplicity(fESDOld->GetMultiplicity());
1384 for(int i = 0;i<fESDOld->GetNumberOfTracks();i++){
1385 AddTrack(fESDOld->GetTrack(i));
1388 for(int i = 0;i<fESDOld->GetNumberOfMuonTracks();i++){
1389 AddMuonTrack(fESDOld->GetMuonTrack(i));
1392 for(int i = 0;i<fESDOld->GetNumberOfPmdTracks();i++){
1393 AddPmdTrack(fESDOld->GetPmdTrack(i));
1396 for(int i = 0;i<fESDOld->GetNumberOfTrdTracks();i++){
1397 AddTrdTrack(fESDOld->GetTrdTrack(i));
1400 for(int i = 0;i<fESDOld->GetNumberOfV0s();i++){
1401 AddV0(fESDOld->GetV0(i));
1404 for(int i = 0;i<fESDOld->GetNumberOfCascades();i++){
1405 AddCascade(fESDOld->GetCascade(i));
1408 for(int i = 0;i<fESDOld->GetNumberOfKinks();i++){
1409 AddKink(fESDOld->GetKink(i));
1413 for(int i = 0;i<fESDOld->GetNumberOfCaloClusters();i++){
1414 AddCaloCluster(fESDOld->GetCaloCluster(i));