]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDEvent.cxx
Implemented Copy() function for all esd objects to allow for assignment of AliESDEven...
[u/mrichter/AliRoot.git] / STEER / AliESDEvent.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 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.
22 /*
23    AliESDEvent *ev= new AliESDEvent();
24    ev->ReadFromTree(esdTree);
25    ...
26     for (Int_t i=0; i<nev; i++) {
27       esdTree->GetEntry(i);
28       if(ev->GetAliESDOld())ev->CopyFromOldESD();
29 */
30 //   The AliESDInputHandler does this automatically for you
31 //
32 // Origin: Christian Klein-Boesing, CERN, Christian.Klein-Boesing@cern.ch
33 //-----------------------------------------------------------------
34
35 #include "TList.h"
36 #include "TRefArray.h"
37 #include <TNamed.h>
38
39 #include "AliESDEvent.h"
40 #include "AliESDfriend.h"
41 #include "AliESDVZERO.h"
42 #include "AliESDFMD.h"
43 #include "AliESD.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"
58 #include "AliESDv0.h"
59 #include "AliESDFMD.h"
60 #include "AliESDVZERO.h"
61 #include "AliMultiplicity.h"
62 #include "AliRawDataErrorLog.h"
63 #include "AliLog.h"
64 #include "AliESDACORDE.h"
65 ClassImp(AliESDEvent)
66
67
68
69 // here we define the names, some classes are no TNamed, therefore the classnames 
70 // are the Names
71   const char* AliESDEvent::fgkESDListName[kESDListN] = {"AliESDRun",
72                                                        "AliESDHeader",
73                                                        "AliESDZDC",
74                                                        "AliESDFMD",
75                                                        "AliESDVZERO",
76                                                        "AliESDTZERO",
77                                                        "TPCVertex",
78                                                        "SPDVertex",
79                                                        "PrimaryVertex",
80                                                        "AliMultiplicity",
81                                                        "PHOSTrigger",
82                                                        "EMCALTrigger",
83                                                        "Tracks",
84                                                        "MuonTracks",
85                                                        "PmdTracks",
86                                                        "TrdTracks",
87                                                        "V0s",
88                                                        "Cascades",
89                                                        "Kinks",
90                                                        "CaloClusters",
91                                                       "EMCALCells",
92                                                       "PHOSCells",
93                                                        "AliRawDataErrorLogs",
94                                                        "AliESDACORDE"};
95
96 //______________________________________________________________________________
97 AliESDEvent::AliESDEvent():
98   AliVEvent(),
99   fESDObjects(new TList()),
100   fESDRun(0),
101   fHeader(0),
102   fESDZDC(0),
103   fESDFMD(0),
104   fESDVZERO(0),
105   fESDTZERO(0),
106   fTPCVertex(0),
107   fSPDVertex(0),
108   fPrimaryVertex(0),
109   fSPDMult(0),
110   fPHOSTrigger(0),
111   fEMCALTrigger(0),
112   fESDACORDE(0),
113   fTracks(0),
114   fMuonTracks(0),
115   fPmdTracks(0),
116   fTrdTracks(0),
117   fV0s(0),  
118   fCascades(0),
119   fKinks(0),
120   fCaloClusters(0),
121   fEMCALCells(0), fPHOSCells(0),
122   fErrorLogs(0),
123   fESDOld(0),
124   fESDFriendOld(0),
125   fConnected(kFALSE),
126   fEMCALClusters(0), 
127   fFirstEMCALCluster(-1),
128   fPHOSClusters(0), 
129   fFirstPHOSCluster(-1)
130 {
131 }
132 //______________________________________________________________________________
133 AliESDEvent::AliESDEvent(const AliESDEvent& esd):
134   AliVEvent(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)
167
168 {
169   // CKB init in the constructor list and only add here ...
170   AddObject(fESDRun);
171   AddObject(fHeader);
172   AddObject(fESDZDC);
173   AddObject(fESDFMD);
174   AddObject(fESDVZERO);
175   AddObject(fESDTZERO);
176   AddObject(fTPCVertex);
177   AddObject(fSPDVertex);
178   AddObject(fPrimaryVertex);
179   AddObject(fSPDMult);
180   AddObject(fPHOSTrigger);
181   AddObject(fEMCALTrigger);
182   AddObject(fTracks);
183   AddObject(fMuonTracks);
184   AddObject(fPmdTracks);
185   AddObject(fTrdTracks);
186   AddObject(fV0s);
187   AddObject(fCascades);
188   AddObject(fKinks);
189   AddObject(fCaloClusters);
190   AddObject(fEMCALCells);
191   AddObject(fPHOSCells);
192   AddObject(fErrorLogs);
193   AddObject(fESDACORDE);
194
195   GetStdContent();
196
197 }
198
199 //______________________________________________________________________________
200 AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
201
202   // Assignment operator
203
204   if(&source == this) return *this;
205   AliVEvent::operator=(source);
206
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
211
212
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
216     CreateStdContent();
217   }
218
219   TIter next(source.GetList());
220   TObject *its = 0;
221   TString name;
222   while ((its = next())) {
223     name.Form("%s", its->GetName());
224     TObject *mine = fESDObjects->FindObject(name.Data());
225     if(!mine){
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()));
229       continue;
230     }
231
232     if(!its->InheritsFrom("TCollection")){
233       // simple objects
234       its->Copy(*mine);
235     }
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;
241
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){
247         // copy 
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);
254       }
255     }
256     else{
257       AliWarning(Form("%s:%d cannot copy TCollection \n",
258                       (char*)__FILE__,__LINE__));
259     }
260   }
261
262   fConnected = source.fConnected;
263   fEMCALClusters = source.fEMCALClusters;
264   fFirstEMCALCluster = source.fFirstEMCALCluster;
265   fPHOSClusters = source.fPHOSClusters;
266   fFirstPHOSCluster = source.fFirstPHOSCluster;
267
268
269   return *this;
270
271 }
272
273
274 //______________________________________________________________________________
275 AliESDEvent::~AliESDEvent()
276 {
277   //
278   // Standard destructor
279   //
280
281   // everthing on the list gets deleted automatically
282
283   
284   if(fESDObjects&&!fConnected)
285     {
286       delete fESDObjects;
287       fESDObjects = 0;
288     }
289
290   
291 }
292
293 void AliESDEvent::Copy(TObject &obj) const {
294
295   // interface to TOBject::Copy
296   // Copies the content of this into obj!
297   // bascially obj = *this
298
299   if(this==&obj)return;
300   AliESDEvent *robj = dynamic_cast<AliESDEvent*>(&obj);
301   if(!robj)return; // not an AliESEvent
302   *robj = *this;
303   return;
304 }
305
306 //______________________________________________________________________________
307 void AliESDEvent::Reset()
308 {
309
310   
311   // Reset the standard contents
312   ResetStdContent(); 
313   if(fESDOld)fESDOld->Reset();
314   //  reset for the friends...
315   if(fESDFriendOld){
316     fESDFriendOld->~AliESDfriend();
317     new (fESDFriendOld) AliESDfriend();
318   }
319   // for new data we have to fetch the Pointer from the list 
320   AliESDfriend *fr = (AliESDfriend*)FindListObject("AliESDfriend");
321   if(fr){
322     // delete the content
323     fr->~AliESDfriend();
324     // make a new valid ESDfriend at the same place
325     new (fr) AliESDfriend();
326   }
327
328   // call reset for user supplied data?
329 }
330
331 void AliESDEvent::ResetStdContent()
332 {
333   // Reset the standard contents
334   if(fESDRun) fESDRun->Reset();
335   if(fHeader) fHeader->Reset();
336   if(fESDZDC) fESDZDC->Reset();
337   if(fESDFMD) {
338       fESDFMD->~AliESDFMD(); 
339       new (fESDFMD) AliESDFMD();
340   }
341   if(fESDVZERO){
342     // reset by callin d'to /c'tor keep the pointer
343     fESDVZERO->~AliESDVZERO();
344     new (fESDVZERO) AliESDVZERO();
345   }  
346   if(fESDACORDE){
347     fESDACORDE->~AliESDACORDE();
348     new (fESDACORDE) AliESDACORDE();    
349   } 
350   if(fESDTZERO) fESDTZERO->Reset(); 
351   // CKB no clear/reset implemented
352   if(fTPCVertex){
353     fTPCVertex->~AliESDVertex();
354     new (fTPCVertex) AliESDVertex();
355     fTPCVertex->SetName(fgkESDListName[kTPCVertex]);
356   }
357   if(fSPDVertex){
358     fSPDVertex->~AliESDVertex();
359     new (fSPDVertex) AliESDVertex();
360     fSPDVertex->SetName(fgkESDListName[kSPDVertex]);
361   }
362   if(fPrimaryVertex){
363     fPrimaryVertex->~AliESDVertex();
364     new (fPrimaryVertex) AliESDVertex();
365     fPrimaryVertex->SetName(fgkESDListName[kPrimaryVertex]);
366   }
367   if(fSPDMult){
368     fSPDMult->~AliMultiplicity();
369     new (fSPDMult) AliMultiplicity();
370   }
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();
384
385   // don't reset fconnected fConnected and the list
386
387   fEMCALClusters=0; 
388   fFirstEMCALCluster=-1; 
389   fPHOSClusters=0; 
390   fFirstPHOSCluster=-1; 
391 }
392
393
394 Int_t AliESDEvent::AddV0(const AliESDv0 *v) {
395   //
396   // Add V0
397   //
398   TClonesArray &fv = *fV0s;
399   Int_t idx=fV0s->GetEntriesFast();
400   new(fv[idx]) AliESDv0(*v);
401   return idx;
402 }  
403
404 //______________________________________________________________________________
405 void AliESDEvent::Print(Option_t *) const 
406 {
407   //
408   // Print header information of the event
409   //
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(),
414          GetOrbitNumber(),
415          GetPeriodNumber(),
416          GetRunNumber(),
417          GetTriggerMask(),
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"));
444
445   return;
446 }
447
448 void AliESDEvent::SetESDfriend(const AliESDfriend *ev) const {
449   //
450   // Attaches the complementary info to the ESD
451   //
452   if (!ev) return;
453
454   // to be sure that we set the tracks also
455   // in case of old esds 
456   // if(fESDOld)CopyFromOldESD();
457
458   Int_t ntrk=ev->GetNumberOfTracks();
459  
460   for (Int_t i=0; i<ntrk; i++) {
461     const AliESDfriendTrack *f=ev->GetTrack(i);
462     GetTrack(i)->SetFriendTrack(f);
463   }
464 }
465
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;
474
475   return kTRUE;
476 }
477
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;
485
486   AliESDv0 *v0=GetV0(rm);
487   Int_t idxP=v0->GetPindex(), idxN=v0->GetNindex();
488
489   v0=GetV0(last);
490   Int_t lastIdxP=v0->GetPindex(), lastIdxN=v0->GetNindex();
491
492   Int_t used=0;
493
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);
498
499     Int_t csIdxP=cs->GetPindex();
500     Int_t csIdxN=cs->GetNindex();
501
502     if (idxP==csIdxP)
503        if (idxN==csIdxN) return kFALSE;
504
505     if (csIdxP==lastIdxP)
506        if (csIdxN==lastIdxN) used++;
507   }
508
509   //Replace the removed V0 with the last V0 
510   TClonesArray &a=*fV0s;
511   delete a.RemoveAt(rm);
512
513   if (rm==last) return kTRUE;
514
515   //v0 is pointing to the last V0 candidate... 
516   new (a[rm]) AliESDv0(*v0);
517   delete a.RemoveAt(last);
518
519   if (!used) return kTRUE;
520   
521
522   // Remap the indices of the daughters of reconstructed decays
523   for (Int_t n=0; n<ncs; n++) {
524     AliESDcascade *cs=GetCascade(n);
525
526
527     Int_t csIdxP=cs->GetPindex();
528     Int_t csIdxN=cs->GetNindex();
529
530     if (csIdxP==lastIdxP)
531       if (csIdxN==lastIdxN) {
532          cs->AliESDv0::SetIndex(1,idxP);
533          cs->AliESDv0::SetIndex(0,idxN);
534          used--;
535          if (!used) return kTRUE;
536       }
537   }
538
539   return kTRUE;
540 }
541
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;
549
550   Int_t used=0;
551
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();
556      while (n--) {
557        Int_t idx=Int_t(primIdx[n]);
558        if (rm==idx) return kFALSE;
559        if (idx==last) used++; 
560      }
561   }
562   if (fPrimaryVertex && fPrimaryVertex->GetStatus()) {
563      UShort_t *primIdx=fPrimaryVertex->GetIndices();
564      Int_t n=fPrimaryVertex->GetNIndices();
565      while (n--) {
566        Int_t idx=Int_t(primIdx[n]);
567        if (rm==idx) return kFALSE;
568        if (idx==last) used++; 
569      }
570   }
571   
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);
576
577     Int_t idx=v0->GetNindex();
578     if (rm==idx) return kFALSE;
579     if (idx==last) used++;
580
581     idx=v0->GetPindex();
582     if (rm==idx) return kFALSE;
583     if (idx==last) used++;
584   }
585
586   Int_t ncs=GetNumberOfCascades();
587   for (Int_t n=0; n<ncs; n++) {
588     AliESDcascade *cs=GetCascade(n);
589
590     Int_t idx=cs->GetIndex();
591     if (rm==idx) return kFALSE;
592     if (idx==last) used++;
593   }
594
595   Int_t nkn=GetNumberOfKinks();
596   for (Int_t n=0; n<nkn; n++) {
597     AliESDkink *kn=GetKink(n);
598
599     Int_t idx=kn->GetIndex(0);
600     if (rm==idx) return kFALSE;
601     if (idx==last) used++;
602
603     idx=kn->GetIndex(1);
604     if (rm==idx) return kFALSE;
605     if (idx==last) used++;
606   }
607
608
609   //Replace the removed track with the last track 
610   TClonesArray &a=*fTracks;
611   delete a.RemoveAt(rm);
612
613   if (rm==last) return kTRUE;
614
615   AliESDtrack *t=GetTrack(last);
616   t->SetID(rm);
617   new (a[rm]) AliESDtrack(*t);
618   delete a.RemoveAt(last);
619
620
621   if (!used) return kTRUE;
622   
623
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();
628      while (n--) {
629        Int_t idx=Int_t(primIdx[n]);
630        if (idx==last) {
631           primIdx[n]=Short_t(rm); 
632           used--;
633           if (!used) return kTRUE;
634        }
635      }
636   }  
637   if (fPrimaryVertex && fPrimaryVertex->GetStatus()) {
638      UShort_t *primIdx=fPrimaryVertex->GetIndices();
639      Int_t n=fPrimaryVertex->GetNIndices();
640      while (n--) {
641        Int_t idx=Int_t(primIdx[n]);
642        if (idx==last) {
643           primIdx[n]=Short_t(rm); 
644           used--;
645           if (!used) return kTRUE;
646        }
647      }
648   }  
649
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) {
654        v0->SetIndex(0,rm);
655        used--;
656        if (!used) return kTRUE;
657     }
658     if (v0->GetIndex(1)==last) {
659        v0->SetIndex(1,rm);
660        used--;
661        if (!used) return kTRUE;
662     }
663   }
664
665   for (Int_t n=0; n<ncs; n++) {
666     AliESDcascade *cs=GetCascade(n);
667     if (cs->GetIndex()==last) {
668        cs->SetIndex(rm);
669        used--;
670        if (!used) return kTRUE;
671     }
672   }
673
674   for (Int_t n=0; n<nkn; n++) {
675     AliESDkink *kn=GetKink(n);
676     if (kn->GetIndex(0)==last) {
677        kn->SetIndex(rm,0);
678        used--;
679        if (!used) return kTRUE;
680     }
681     if (kn->GetIndex(1)==last) {
682        kn->SetIndex(rm,1);
683        used--;
684        if (!used) return kTRUE;
685     }
686   }
687
688   return kTRUE;
689 }
690
691
692 Bool_t AliESDEvent::Clean(Float_t *cleanPars) {
693   //
694   // Remove the data which are not needed for the physics analysis.
695   //
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 
700   //    the conditions 
701   //
702   //     csp > cleanPars[1] + dca/cleanPars[0]*(1.- cleanPars[1])
703   //
704   //    an attempt to remove this V0 candidate from ESD is made.
705   //
706   //    The V0 candidate gets removed if it does not belong to any 
707   //    recosntructed cascade decay
708   //
709   //    12.11.2007, optimal values: cleanPars[0]=0.5, cleanPars[1]=0.999
710   //
711   // 2) Cleaning the tracks
712   //    ----------------------
713   //    If track's transverse parameter is larger than cleanPars[2]
714   //                       OR
715   //    track's longitudinal parameter is larger than cleanPars[3]
716   //    an attempt to remove this track from ESD is made.
717   //
718   //    The track gets removed if it does not come 
719   //    from a reconstructed decay
720   //
721   Bool_t rc=kFALSE;
722
723   Float_t dcaMax=cleanPars[0];
724   Float_t cspMin=cleanPars[1];
725
726   Int_t nV0s=GetNumberOfV0s();
727   for (Int_t i=nV0s-1; i>=0; i--) {
728     AliESDv0 *v0=GetV0(i);
729
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;
735   }
736
737
738   Float_t dmax=cleanPars[2], zmax=cleanPars[3];
739
740   const AliESDVertex *vertex=GetPrimaryVertexSPD();
741   Bool_t vtxOK=vertex->GetStatus();
742   
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;
749     }
750   }
751
752   return rc;
753 }
754
755 Int_t  AliESDEvent::AddTrack(const AliESDtrack *t) 
756 {
757     // Add track
758     TClonesArray &ftr = *fTracks;
759     AliESDtrack * track = new(ftr[fTracks->GetEntriesFast()])AliESDtrack(*t);
760     track->SetID(fTracks->GetEntriesFast()-1);
761     return  track->GetID();    
762 }
763
764  void AliESDEvent::AddMuonTrack(const AliESDMuonTrack *t) 
765 {
766     TClonesArray &fmu = *fMuonTracks;
767     new(fmu[fMuonTracks->GetEntriesFast()]) AliESDMuonTrack(*t);
768 }
769
770 void AliESDEvent::AddPmdTrack(const AliESDPmdTrack *t) 
771 {
772   TClonesArray &fpmd = *fPmdTracks;
773   new(fpmd[fPmdTracks->GetEntriesFast()]) AliESDPmdTrack(*t);
774 }
775
776 void AliESDEvent::AddTrdTrack(const AliESDTrdTrack *t) 
777 {
778   TClonesArray &ftrd = *fTrdTracks;
779   new(ftrd[fTrdTracks->GetEntriesFast()]) AliESDTrdTrack(*t);
780 }
781
782
783
784
785 Int_t AliESDEvent::AddKink(const AliESDkink *c) 
786 {
787     // Add kink
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;
792 }
793
794
795 void AliESDEvent::AddCascade(const AliESDcascade *c) 
796 {
797   TClonesArray &fc = *fCascades;
798   new(fc[fCascades->GetEntriesFast()]) AliESDcascade(*c);
799 }
800
801
802 Int_t AliESDEvent::AddCaloCluster(const AliESDCaloCluster *c) 
803 {
804     // Add calocluster
805     TClonesArray &fc = *fCaloClusters;
806     AliESDCaloCluster *clus = new(fc[fCaloClusters->GetEntriesFast()]) AliESDCaloCluster(*c);
807     clus->SetID(fCaloClusters->GetEntriesFast()-1);
808     return fCaloClusters->GetEntriesFast()-1;
809   }
810
811
812 void  AliESDEvent::AddRawDataErrorLog(const AliRawDataErrorLog *log) const {
813   TClonesArray &errlogs = *fErrorLogs;
814   new(errlogs[errlogs.GetEntriesFast()])  AliRawDataErrorLog(*log);
815 }
816
817 void  AliESDEvent::SetPrimaryVertexTPC(const AliESDVertex *vertex) 
818 {
819   // Set the TPC vertex
820   // use already allocated space
821   if(fTPCVertex){
822     *fTPCVertex = *vertex;
823     fTPCVertex->SetName(fgkESDListName[kTPCVertex]);
824   }
825 }
826
827 void  AliESDEvent::SetPrimaryVertexSPD(const AliESDVertex *vertex) 
828 {
829   // Set the SPD vertex
830   // use already allocated space
831   if(fSPDVertex){
832     *fSPDVertex = *vertex;
833     fSPDVertex->SetName(fgkESDListName[kSPDVertex]);
834   }
835 }
836
837 void  AliESDEvent::SetPrimaryVertex(const AliESDVertex *vertex) 
838 {
839   // Set the primary vertex
840   // use already allocated space
841   if(fPrimaryVertex){
842     *fPrimaryVertex = *vertex;
843     fPrimaryVertex->SetName(fgkESDListName[kPrimaryVertex]);
844   }
845 }
846
847 void AliESDEvent::SetMultiplicity(const AliMultiplicity *mul) 
848 {
849   // Set the SPD Multiplicity
850   if(fSPDMult){
851     *fSPDMult = *mul;
852   }
853 }
854
855
856 void AliESDEvent::SetFMDData(AliESDFMD * obj) 
857
858   // use already allocated space
859   if(fESDFMD){
860     *fESDFMD = *obj;
861   }
862 }
863
864 void AliESDEvent::SetVZEROData(AliESDVZERO * obj)
865
866   // use already allocated space
867   if(fESDVZERO)
868     *fESDVZERO = *obj;
869 }
870
871 void AliESDEvent::SetACORDEData(AliESDACORDE * obj)
872 {
873   if(fESDACORDE)
874     *fESDACORDE = *obj;
875 }
876
877
878 void AliESDEvent::GetESDfriend(AliESDfriend *ev) const 
879 {
880   //
881   // Extracts the complementary info from the ESD
882   //
883   if (!ev) return;
884
885   Int_t ntrk=GetNumberOfTracks();
886
887   for (Int_t i=0; i<ntrk; i++) {
888     AliESDtrack *t=GetTrack(i);
889     const AliESDfriendTrack *f=t->GetFriendTrack();
890     ev->AddTrack(f);
891
892     t->ReleaseESDfriendTrack();// Not to have two copies of "friendTrack"
893
894   }
895 }
896
897
898 void AliESDEvent::AddObject(TObject* obj) 
899 {
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);
905 }
906
907
908 void AliESDEvent::GetStdContent() 
909 {
910   // set pointers for standard content
911   // get by name much safer and not a big overhead since not called very often
912  
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]);
937
938 }
939
940 void AliESDEvent::SetStdNames(){
941   // Set the names of the standard contents
942   // 
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]);
948       }
949       else if(fObj->InheritsFrom("TClonesArray")){
950         ((TClonesArray*)fObj)->SetName(fgkESDListName[i]);
951       }
952     }
953   }
954   else{
955     printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
956   }
957
958
959 void AliESDEvent::CreateStdContent() 
960 {
961   // create the standard AOD content and set pointers
962
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()); 
988
989   // check the order of the indices against enum...
990
991   // set names
992   SetStdNames();
993   // read back pointers
994   GetStdContent();
995 }
996
997 TObject* AliESDEvent::FindListObject(const char *name){
998 //
999 // Find object with name "name" in the list of branches
1000 //
1001   if(fESDObjects){
1002     return fESDObjects->FindObject(name);
1003   }
1004   return 0;
1005
1006
1007 Int_t AliESDEvent::GetPHOSClusters(TRefArray *clusters) const
1008 {
1009   // fills the provided TRefArray with all found phos clusters
1010   
1011   clusters->Clear();
1012   
1013   AliESDCaloCluster *cl = 0;
1014   for (Int_t i = 0; i < GetNumberOfCaloClusters(); i++) {
1015     
1016     if ( (cl = GetCaloCluster(i)) ) {
1017       if (cl->IsPHOS()){
1018         clusters->Add(cl);
1019         AliDebug(1,Form("IsPHOS cluster %d Size: %d \n",i,clusters->GetEntriesFast()));
1020       }
1021     }
1022   }
1023   return clusters->GetEntriesFast();
1024 }
1025
1026 Int_t AliESDEvent::GetEMCALClusters(TRefArray *clusters) const
1027 {
1028   // fills the provided TRefArray with all found emcal clusters
1029
1030   clusters->Clear();
1031
1032   AliESDCaloCluster *cl = 0;
1033   for (Int_t i = 0; i < GetNumberOfCaloClusters(); i++) {
1034
1035     if ( (cl = GetCaloCluster(i)) ) {
1036       if (cl->IsEMCAL()){
1037         clusters->Add(cl);
1038         AliDebug(1,Form("IsEMCAL cluster %d Size: %d \n",i,clusters->GetEntriesFast()));
1039       }
1040     }
1041   }
1042   return clusters->GetEntriesFast();
1043 }
1044
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
1049
1050
1051   TString branchname;
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()
1055   TObject *obj = 0;
1056
1057   while ((obj = next())) {
1058     branchname.Form("%s", obj->GetName());
1059     if ((kSplitlevel > 1) &&  !obj->InheritsFrom(TClonesArray::Class())) {
1060       if(!branchname.EndsWith("."))branchname += ".";
1061     }
1062     tree->Bronch(branchname, obj->ClassName(), fESDObjects->GetObjectRef(obj),
1063                  kBufsize, kSplitlevel - 1);
1064   }
1065
1066 }
1067
1068
1069 void AliESDEvent::ReadFromTree(TTree *tree){
1070 //
1071 // Connect the ESDEvent to a tree
1072 //
1073   if(!tree){
1074     Printf("%s %d AliESDEvent::ReadFromTree() Zero Pointer to Tree \n",(char*)__FILE__,__LINE__);
1075     return;
1076   }
1077   // load the TTree
1078   if(!tree->GetTree())tree->LoadTree(0);
1079
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());
1087     if (!address) {
1088       printf("%s %d AliESDEvent::ReadFromTree() Reading old Tree \n",(char*)__FILE__,__LINE__);
1089       tree->SetBranchAddress("ESD",       &fESDOld);
1090       if(esdFB){
1091         tree->SetBranchAddress("ESDfriend.",&fESDFriendOld);
1092       }
1093     } else {
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);
1099     }
1100                                        
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"));
1105   
1106     if(connectedList){
1107       // If connected use the connected list of objects
1108       if(fESDObjects!= connectedList){
1109         // protect when called twice 
1110         fESDObjects->Delete();
1111         fESDObjects = connectedList;
1112       }
1113       GetStdContent(); 
1114
1115       
1116       // The pointer to the friend changes when called twice via InitIO
1117       // since AliESDEvent is deleted
1118       TObject* oldf = FindListObject("AliESDfriend");
1119       TObject* newf = 0;
1120       if(addressF){
1121         newf = (TObject*)*addressF;
1122       }
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);
1128         // add the new one 
1129         fESDObjects->Add(newf);
1130       }
1131       
1132       fConnected = true;
1133       return;
1134     }
1135     // else...    
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);
1144     fConnected = true;
1145     return;
1146   }
1147   
1148
1149     delete fESDOld;
1150     fESDOld = 0;
1151   // Try to find AliESDEvent
1152   AliESDEvent *esdEvent = 0;
1153   esdEvent = (AliESDEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliESDEvent");
1154   if(esdEvent){   
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;
1161       GetStdContent(); 
1162       fConnected = true;
1163       return;
1164     }
1165
1166     // Connect to tree
1167     // prevent a memory leak when reading back the TList
1168     delete fESDObjects;
1169     fESDObjects = 0;
1170
1171
1172
1173     // create a new TList from the UserInfo TList... 
1174     // copy constructor does not work...
1175
1176     fESDObjects = (TList*)(esdEvent->GetList()->Clone());
1177     fESDObjects->SetOwner(kFALSE);
1178
1179     // in principle
1180     // we only need new things in the list if we do no already have it..
1181     // TODO just add new entries
1182
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);
1186     }
1187     // set the branch addresses
1188     TIter next(fESDObjects);
1189     TNamed *el;
1190     while((el=(TNamed*)next())){
1191       TString bname(el->GetName());
1192       if(bname.CompareTo("AliESDfriend")==0)
1193         {
1194           // AliESDfriend does not have a name ...
1195           tree->SetBranchAddress("ESDfriend.",fESDObjects->GetObjectRef(el));
1196         }
1197       else{
1198         // check if branch exists under this Name
1199         TBranch *br = tree->GetBranch(bname.Data());
1200         if(br){
1201           tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
1202         }
1203         else{
1204           br = tree->GetBranch(Form("%s.",bname.Data()));
1205           if(br){
1206             tree->SetBranchAddress(Form("%s.",bname.Data()),fESDObjects->GetObjectRef(el));
1207           }
1208           else{
1209             printf("%s %d AliESDEvent::ReadFromTree() No Branch found with Name %s or %s. \n",
1210                    (char*)__FILE__,__LINE__,bname.Data(),bname.Data());
1211           }
1212
1213         }
1214       }
1215     }
1216     GetStdContent();
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);
1224     fConnected = true;
1225   }// no esdEvent
1226   else {
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
1229     CreateStdContent();
1230     TIter next(fESDObjects);
1231     TNamed *el;
1232     while((el=(TNamed*)next())){
1233       TString bname(el->GetName());    
1234       TBranch *br = tree->GetBranch(bname.Data());
1235       if(br){
1236         tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
1237       }
1238       else{
1239         br = tree->GetBranch(Form("%s.",bname.Data()));
1240         if(br){
1241           tree->SetBranchAddress(Form("%s.",bname.Data()),fESDObjects->GetObjectRef(el));
1242         }
1243       }
1244     }
1245     GetStdContent();
1246     // when reading back we are not owner of the list 
1247     // must not delete it
1248     fESDObjects->SetOwner(kFALSE);
1249   }
1250 }
1251
1252
1253 void AliESDEvent::CopyFromOldESD()
1254 {
1255   // Method which copies over everthing from the old esd structure to the 
1256   // new  
1257   if(fESDOld){
1258     ResetStdContent();
1259      // Run
1260     SetRunNumber(fESDOld->GetRunNumber());
1261     SetPeriodNumber(fESDOld->GetPeriodNumber());
1262     SetMagneticField(fESDOld->GetMagneticField());
1263   
1264     // leave out diamond ...
1265     // SetDiamond(const AliESDVertex *vertex) { fESDRun->SetDiamond(vertex);}
1266
1267     // header
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());
1275
1276     // ZDC
1277
1278     SetZDC(fESDOld->GetZDCN1Energy(),
1279            fESDOld->GetZDCP1Energy(),
1280            fESDOld->GetZDCEMEnergy(),
1281            0,
1282            fESDOld->GetZDCN2Energy(),
1283            fESDOld->GetZDCP2Energy(),
1284            fESDOld->GetZDCParticipants());
1285
1286     // FMD
1287     
1288     if(fESDOld->GetFMDData())SetFMDData(fESDOld->GetFMDData());
1289
1290     // T0
1291
1292     SetT0zVertex(fESDOld->GetT0zVertex());
1293     SetT0(fESDOld->GetT0());
1294     //  leave amps out
1295
1296     // VZERO
1297     if (fESDOld->GetVZEROData()) SetVZEROData(fESDOld->GetVZEROData());
1298
1299     if(fESDOld->GetVertex())SetPrimaryVertexSPD(fESDOld->GetVertex());
1300
1301     if(fESDOld->GetPrimaryVertex())SetPrimaryVertex(fESDOld->GetPrimaryVertex());
1302
1303     if(fESDOld->GetMultiplicity())SetMultiplicity(fESDOld->GetMultiplicity());
1304
1305     for(int i = 0;i<fESDOld->GetNumberOfTracks();i++){
1306       AddTrack(fESDOld->GetTrack(i));
1307     }
1308
1309     for(int i = 0;i<fESDOld->GetNumberOfMuonTracks();i++){
1310       AddMuonTrack(fESDOld->GetMuonTrack(i));
1311     }
1312
1313     for(int i = 0;i<fESDOld->GetNumberOfPmdTracks();i++){
1314       AddPmdTrack(fESDOld->GetPmdTrack(i));
1315     }
1316
1317     for(int i = 0;i<fESDOld->GetNumberOfTrdTracks();i++){
1318       AddTrdTrack(fESDOld->GetTrdTrack(i));
1319     }
1320
1321     for(int i = 0;i<fESDOld->GetNumberOfV0s();i++){
1322       AddV0(fESDOld->GetV0(i));
1323     }
1324
1325     for(int i = 0;i<fESDOld->GetNumberOfCascades();i++){
1326       AddCascade(fESDOld->GetCascade(i));
1327     }
1328
1329     for(int i = 0;i<fESDOld->GetNumberOfKinks();i++){
1330       AddKink(fESDOld->GetKink(i));
1331     }
1332
1333
1334     for(int i = 0;i<fESDOld->GetNumberOfCaloClusters();i++){
1335       AddCaloCluster(fESDOld->GetCaloCluster(i));
1336     }
1337
1338   }// if fesdold
1339 }
1340
1341
1342