]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDEvent.cxx
Modifications in AliESDMuonTrack:
[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 phisical analysis of data.
21 //   It also ensures the backward compatibility with the old ESD format.
22 //
23 // Origin: Christian Klein-Boesing, CERN, Christian.Klein-Boesing@cern.ch
24 //-----------------------------------------------------------------
25
26 #include "TList.h"
27 #include <TNamed.h>
28
29 #include "AliESDEvent.h"
30 #include "AliESDfriend.h"
31 #include "AliESDVZERO.h"
32 #include "AliESDHLTtrack.h"
33 #include "AliESDFMD.h"
34 #include "AliESD.h"
35 #include "AliESDMuonTrack.h"
36 #include "AliESDPmdTrack.h"
37 #include "AliESDTrdTrack.h"
38 #include "AliESDVertex.h"
39 #include "AliESDcascade.h"
40 #include "AliESDPmdTrack.h"
41 #include "AliESDTrdTrack.h"
42 #include "AliESDVertex.h"
43 #include "AliESDcascade.h"
44 #include "AliESDkink.h"
45 #include "AliESDtrack.h"
46 #include "AliESDHLTtrack.h"
47 #include "AliESDCaloCluster.h"
48 #include "AliESDv0.h"
49 #include "AliESDFMD.h"
50 #include "AliESDVZERO.h"
51 #include "AliMultiplicity.h"
52 #include "AliRawDataErrorLog.h"
53
54
55 ClassImp(AliESDEvent)
56
57
58
59 // here we define the names, some classes are no TNamed, therefore the classnames 
60 // are the Names
61   const char* AliESDEvent::fESDListName[kESDListN] = {"AliESDRun",
62                                                        "AliESDHeader",
63                                                        "AliESDZDC",
64                                                        "AliESDFMD",
65                                                        "AliESDVZERO",
66                                                        "AliESDTZERO",
67                                                        "SPDVertex",
68                                                        "PrimaryVertex",
69                                                        "AliMultiplicity",
70                                                        "PHOSTrigger",
71                                                        "EMCALTrigger",
72                                                        "Tracks",
73                                                        "MuonTracks",
74                                                        "PmdTracks",
75                                                        "TrdTracks",
76                                                        "V0s",
77                                                        "Cascades",
78                                                        "Kinks",
79                                                        "CaloClusters",
80                                                        "AliRawDataErrorLogs"};
81 //______________________________________________________________________________
82 AliESDEvent::AliESDEvent():
83   AliVEvent(),
84   fESDObjects(new TList()),
85   fESDRun(0),
86   fHeader(0),
87   fESDZDC(0),
88   fESDFMD(0),
89   fESDVZERO(0),
90   fESDTZERO(0),
91   fSPDVertex(0),
92   fPrimaryVertex(0),
93   fSPDMult(0),
94   fPHOSTrigger(0),
95   fEMCALTrigger(0),
96   fTracks(0),
97   fMuonTracks(0),
98   fPmdTracks(0),
99   fTrdTracks(0),
100   fV0s(0),  
101   fCascades(0),
102   fKinks(0),
103   fCaloClusters(0),
104   fErrorLogs(0),
105   fESDOld(0),
106   fConnected(kFALSE),
107   fEMCALClusters(0), 
108   fFirstEMCALCluster(-1),
109   fPHOSClusters(0), 
110   fFirstPHOSCluster(-1)
111 {
112 }
113 //______________________________________________________________________________
114 AliESDEvent::AliESDEvent(const AliESDEvent& esd):
115   AliVEvent(esd),
116   fESDObjects(new TList()),
117   fESDRun(new AliESDRun(*esd.fESDRun)),
118   fHeader(new AliESDHeader(*esd.fHeader)),
119   fESDZDC(new AliESDZDC(*esd.fESDZDC)),
120   fESDFMD(new AliESDFMD(*esd.fESDFMD)),
121   fESDVZERO(new AliESDVZERO(*esd.fESDVZERO)),
122   fESDTZERO(new AliESDTZERO(*esd.fESDTZERO)),
123   fSPDVertex(new AliESDVertex(*esd.fSPDVertex)),
124   fPrimaryVertex(new AliESDVertex(*esd.fPrimaryVertex)),
125   fSPDMult(new AliMultiplicity(*esd.fSPDMult)),
126   fPHOSTrigger(new AliESDCaloTrigger(*esd.fPHOSTrigger)),
127   fEMCALTrigger(new AliESDCaloTrigger(*esd.fEMCALTrigger)),
128   fTracks(new TClonesArray(*esd.fTracks)),
129   fMuonTracks(new TClonesArray(*esd.fMuonTracks)),
130   fPmdTracks(new TClonesArray(*esd.fPmdTracks)),
131   fTrdTracks(new TClonesArray(*esd.fTrdTracks)),
132   fV0s(new TClonesArray(*esd.fV0s)),  
133   fCascades(new TClonesArray(*esd.fCascades)),
134   fKinks(new TClonesArray(*esd.fKinks)),
135   fCaloClusters(new TClonesArray(*esd.fCaloClusters)),
136   fErrorLogs(new TClonesArray(*esd.fErrorLogs)),
137   fESDOld(new AliESD(*esd.fESDOld)),
138   fConnected(esd.fConnected),
139   fEMCALClusters(esd.fEMCALClusters), 
140   fFirstEMCALCluster(esd.fFirstEMCALCluster),
141   fPHOSClusters(esd.fPHOSClusters), 
142   fFirstPHOSCluster(esd.fFirstPHOSCluster)
143
144 {
145   // CKB init in the constructor list and only add here ...
146   AddObject(fESDRun);
147   AddObject(fHeader);
148   AddObject(fESDZDC);
149   AddObject(fESDFMD);
150   AddObject(fESDVZERO);
151   AddObject(fESDTZERO);
152   AddObject(fSPDVertex);
153   AddObject(fPrimaryVertex);
154   AddObject(fSPDMult);
155   AddObject(fPHOSTrigger);
156   AddObject(fEMCALTrigger);
157   AddObject(fTracks);
158   AddObject(fMuonTracks);
159   AddObject(fPmdTracks);
160   AddObject(fTrdTracks);
161   AddObject(fV0s);
162   AddObject(fCascades);
163   AddObject(fKinks);
164   AddObject(fCaloClusters);
165   AddObject(fErrorLogs);
166
167   GetStdContent();
168
169 }
170
171 //______________________________________________________________________________
172 AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
173
174   // Assignment operator
175
176   if(&source == this) return *this;
177   AliVEvent::operator=(source);
178
179   fESDRun = new AliESDRun(*source.fESDRun);
180   fHeader = new AliESDHeader(*source.fHeader);
181   fESDZDC = new AliESDZDC(*source.fESDZDC);
182   fESDFMD = new AliESDFMD(*source.fESDFMD);
183   fESDVZERO = new AliESDVZERO(*source.fESDVZERO);
184   fESDTZERO = new AliESDTZERO(*source.fESDTZERO);
185   fSPDVertex = new AliESDVertex(*source.fSPDVertex);
186   fPrimaryVertex = new AliESDVertex(*source.fPrimaryVertex);
187   fSPDMult = new AliMultiplicity(*source.fSPDMult);
188   fPHOSTrigger = new AliESDCaloTrigger(*source.fPHOSTrigger);
189   fEMCALTrigger = new AliESDCaloTrigger(*source.fEMCALTrigger);
190   fTracks = new TClonesArray(*source.fTracks);
191   fMuonTracks = new TClonesArray(*source.fMuonTracks);
192   fPmdTracks = new TClonesArray(*source.fPmdTracks);
193   fTrdTracks = new TClonesArray(*source.fTrdTracks);
194   fV0s = new TClonesArray(*source.fV0s);
195   fCascades = new TClonesArray(*source.fCascades);
196   fKinks = new TClonesArray(*source.fKinks);
197   fCaloClusters = new TClonesArray(*source.fCaloClusters);
198   fErrorLogs = new TClonesArray(*source.fErrorLogs);
199   fESDOld = new AliESD(*source.fESDOld);
200   // CKB this way?? or 
201   // or AddObject(  fESDZDC = new AliESDZDC(*source.fESDZDC));
202
203   fESDObjects = new TList();
204   AddObject(fESDRun);
205   AddObject(fHeader);
206   AddObject(fESDZDC);
207   AddObject(fESDFMD);
208   AddObject(fESDVZERO);
209   AddObject(fESDTZERO);
210   AddObject(fSPDVertex);
211   AddObject(fPrimaryVertex);
212   AddObject(fSPDMult);
213   AddObject(fPHOSTrigger);
214   AddObject(fEMCALTrigger);
215   AddObject(fTracks);
216   AddObject(fMuonTracks);
217   AddObject(fPmdTracks);
218   AddObject(fTrdTracks);
219   AddObject(fV0s);
220   AddObject(fCascades);
221   AddObject(fKinks);
222   AddObject(fCaloClusters);
223   AddObject(fErrorLogs);
224
225   fConnected = source.fConnected;
226   fEMCALClusters = source.fEMCALClusters;
227   fFirstEMCALCluster = source.fFirstEMCALCluster;
228   fPHOSClusters = source.fPHOSClusters;
229   fFirstPHOSCluster = source.fFirstPHOSCluster;
230
231
232
233   return *this;
234
235 }
236
237
238 //______________________________________________________________________________
239 AliESDEvent::~AliESDEvent()
240 {
241   //
242   // Standard destructor
243   //
244
245   // everthing on the list gets deleted automatically
246
247   
248   if(fESDObjects&&!fConnected)
249     {
250       delete fESDObjects;
251       fESDObjects = 0;
252     }
253
254   
255 }
256
257 //______________________________________________________________________________
258 void AliESDEvent::Reset()
259 {
260
261   
262   // Reset the standard contents
263   ResetStdContent(); 
264
265   if(fESDOld)fESDOld->Reset();
266   // call reset for user supplied data?
267 }
268
269 void AliESDEvent::ResetStdContent()
270 {
271   // Reset the standard contents
272   if(fESDRun) fESDRun->Reset();
273   if(fHeader) fHeader->Reset();
274   if(fESDZDC) fESDZDC->Reset();
275   if(fESDFMD) fESDFMD->Clear(); // why clear.... need consistend names
276   // if(fESDVZERO) fESDVZERO->; // NOT IMPLEMENTED 
277   //  if(fESDVZERO) new (fESDVZERO) AliESDVZERO();
278   if(fESDTZERO) fESDTZERO->Reset(); 
279   // CKB no clear/reset implemented
280   if(fSPDVertex){
281     fSPDVertex->~AliESDVertex();
282     new (fSPDVertex) AliESDVertex();
283     fSPDVertex->SetName(fESDListName[kSPDVertex]);
284   }
285   if(fPrimaryVertex){
286     fPrimaryVertex->~AliESDVertex();
287     new (fPrimaryVertex) AliESDVertex();
288     fPrimaryVertex->SetName(fESDListName[kPrimaryVertex]);
289   }
290   if(fSPDMult){
291     fSPDMult->~AliMultiplicity();
292     new (fSPDMult) AliMultiplicity();
293   }
294   if(fPHOSTrigger)fPHOSTrigger->Reset(); 
295   if(fEMCALTrigger)fEMCALTrigger->Reset(); 
296   if(fTracks)fTracks->Delete();
297   if(fMuonTracks)fMuonTracks->Clear();
298   if(fPmdTracks)fPmdTracks->Clear();
299   if(fTrdTracks)fTrdTracks->Clear();
300   if(fV0s)fV0s->Clear();
301   if(fCascades)fCascades->Clear();
302   if(fKinks)fKinks->Clear();
303   if(fCaloClusters)fCaloClusters->Delete();
304   if(fErrorLogs) fErrorLogs->Delete();
305
306   // don't reset fconnected fConnected ;
307
308   fEMCALClusters=0; 
309   fFirstEMCALCluster=-1; 
310   fPHOSClusters=0; 
311   fFirstPHOSCluster=-1; 
312 }
313
314
315 Int_t AliESDEvent::AddV0(const AliESDv0 *v) {
316   //
317   // Add V0
318   //
319   TClonesArray &fv = *fV0s;
320   Int_t idx=fV0s->GetEntriesFast();
321   new(fv[idx]) AliESDv0(*v);
322   return idx;
323 }  
324
325 //______________________________________________________________________________
326 void AliESDEvent::Print(Option_t *) const 
327 {
328   //
329   // Print header information of the event
330   //
331   printf("ESD run information\n");
332   printf("Event # in file %d Bunch crossing # %d Orbit # %d Period # %d Run # %d Trigger %lld Magnetic field %f \n",
333          GetEventNumberInFile(),
334          GetBunchCrossNumber(),
335          GetOrbitNumber(),
336          GetPeriodNumber(),
337          GetRunNumber(),
338          GetTriggerMask(),
339          GetMagneticField() );
340   printf("Vertex: (%.4f +- %.4f, %.4f +- %.4f, %.4f +- %.4f) cm\n",
341            fPrimaryVertex->GetXv(), fPrimaryVertex->GetXRes(),
342            fPrimaryVertex->GetYv(), fPrimaryVertex->GetYRes(),
343            fPrimaryVertex->GetZv(), fPrimaryVertex->GetZRes());
344     printf("Mean vertex in RUN: X=%.4f Y=%.4f cm\n",
345            GetDiamondX(),GetDiamondY());
346     printf("SPD Multiplicity. Number of tracklets %d \n",
347            fSPDMult->GetNumberOfTracklets());
348   printf("Number of tracks: \n");
349   printf("                 charged   %d\n", GetNumberOfTracks());
350   printf("                 muon      %d\n", GetNumberOfMuonTracks());
351   printf("                 pmd       %d\n", GetNumberOfPmdTracks());
352   printf("                 trd       %d\n", GetNumberOfTrdTracks());
353   printf("                 v0        %d\n", GetNumberOfV0s());
354   printf("                 cascades  %d\n", GetNumberOfCascades());
355   printf("                 kinks     %d\n", GetNumberOfKinks());
356   printf("                 CaloClusters %d\n", GetNumberOfCaloClusters());
357   printf("                 phos      %d\n", GetNumberOfPHOSClusters());
358   printf("                 emcal     %d\n", GetNumberOfEMCALClusters());
359   printf("                 FMD       %s\n", (fESDFMD ? "yes" : "no"));
360   printf("                 VZERO     %s\n", (fESDVZERO ? "yes" : "no"));
361
362   return;
363 }
364
365 void AliESDEvent::SetESDfriend(const AliESDfriend *ev) {
366   //
367   // Attaches the complementary info to the ESD
368   //
369   if (!ev) return;
370
371   // to be sure that we set the tracks also
372   // in case of old esds 
373   // if(fESDOld)CopyFromOldESD();
374
375   Int_t ntrk=ev->GetNumberOfTracks();
376  
377   for (Int_t i=0; i<ntrk; i++) {
378     const AliESDfriendTrack *f=ev->GetTrack(i);
379     GetTrack(i)->SetFriendTrack(f);
380   }
381 }
382
383 Bool_t  AliESDEvent::RemoveTrack(Int_t /*i*/) {
384   // ---------------------------------------------------------
385   // Remove track
386   // ---------------------------------------------------------
387
388   // Check if this track comes from a reconstructed decay
389   // if (yes) return kFALSE
390
391   // Remap the indices of the daughters of recosntructed decays
392
393   // Remove the track
394   // delete fTracks->RemoveAt(i);
395
396   // Compress the array with tracks
397   // fTracks->Compress();
398
399   return kTRUE;
400 }
401
402
403 Int_t  AliESDEvent::AddTrack(const AliESDtrack *t) {
404     // Add track
405     TClonesArray &ftr = *fTracks;
406     AliESDtrack * track = new(ftr[fTracks->GetEntriesFast()])AliESDtrack(*t);
407     track->SetID(fTracks->GetEntriesFast()-1);
408     return  track->GetID();    
409 }
410
411  void AliESDEvent::AddMuonTrack(const AliESDMuonTrack *t) {
412     TClonesArray &fmu = *fMuonTracks;
413     new(fmu[fMuonTracks->GetEntriesFast()]) AliESDMuonTrack(*t);
414 }
415
416 void AliESDEvent::AddPmdTrack(const AliESDPmdTrack *t) {
417   TClonesArray &fpmd = *fPmdTracks;
418   new(fpmd[fPmdTracks->GetEntriesFast()]) AliESDPmdTrack(*t);
419 }
420
421 void AliESDEvent::AddTrdTrack(const AliESDTrdTrack *t) {
422   TClonesArray &ftrd = *fTrdTracks;
423   new(ftrd[fTrdTracks->GetEntriesFast()]) AliESDTrdTrack(*t);
424 }
425
426
427
428
429 Int_t AliESDEvent::AddKink(const AliESDkink *c) {
430     // Add kink
431     TClonesArray &fk = *fKinks;
432     AliESDkink * kink = new(fk[fKinks->GetEntriesFast()]) AliESDkink(*c);
433     kink->SetID(fKinks->GetEntriesFast()); // CKB different from the other imps..
434     return fKinks->GetEntriesFast()-1;
435 }
436
437
438 void AliESDEvent::AddCascade(const AliESDcascade *c) {
439   TClonesArray &fc = *fCascades;
440   new(fc[fCascades->GetEntriesFast()]) AliESDcascade(*c);
441 }
442
443
444 Int_t AliESDEvent::AddCaloCluster(const AliESDCaloCluster *c) {
445     // Add calocluster
446     TClonesArray &fc = *fCaloClusters;
447     AliESDCaloCluster *clus = new(fc[fCaloClusters->GetEntriesFast()]) AliESDCaloCluster(*c);
448     clus->SetID(fCaloClusters->GetEntriesFast()-1);
449     return fCaloClusters->GetEntriesFast()-1;
450   }
451
452
453   void  AliESDEvent::AddRawDataErrorLog(const AliRawDataErrorLog *log) {
454     TClonesArray &errlogs = *fErrorLogs;
455     new(errlogs[errlogs.GetEntriesFast()])  AliRawDataErrorLog(*log);
456   }
457
458 void  AliESDEvent::SetVertex(const AliESDVertex *vertex) {
459   // use already allocated space
460   if(fSPDVertex){
461     *fSPDVertex = *vertex;
462     fSPDVertex->SetName(fESDListName[kSPDVertex]);
463   }
464 }
465
466 void  AliESDEvent::SetPrimaryVertex(const AliESDVertex *vertex) {
467   if(fPrimaryVertex){
468     *fPrimaryVertex = *vertex;
469     fPrimaryVertex->SetName(fESDListName[kPrimaryVertex]);
470   }
471 }
472
473 void AliESDEvent::SetMultiplicity(const AliMultiplicity *mul) {
474   if(fSPDMult){
475     *fSPDMult = *mul;
476   }
477 }
478
479
480 void AliESDEvent::SetFMDData(AliESDFMD * obj) { 
481   // use already allocated space
482   if(fESDFMD){
483     *fESDFMD = *obj;
484   }
485 }
486
487 void AliESDEvent::SetVZEROData(AliESDVZERO * obj){ 
488   // use already allocated space
489   if(fESDVZERO)
490     new(fESDVZERO) AliESDVZERO(*obj);
491 }
492
493 void AliESDEvent::GetESDfriend(AliESDfriend *ev) const {
494   //
495   // Extracts the complementary info from the ESD
496   //
497   if (!ev) return;
498
499   Int_t ntrk=GetNumberOfTracks();
500
501   for (Int_t i=0; i<ntrk; i++) {
502     AliESDtrack *t=GetTrack(i);
503     const AliESDfriendTrack *f=t->GetFriendTrack();
504     ev->AddTrack(f);
505
506     t->ReleaseESDfriendTrack();// Not to have two copies of "friendTrack"
507
508   }
509 }
510
511
512 void AliESDEvent::AddObject(TObject* obj) 
513 {
514   // Add an object to the list of object.
515   // Please be aware that in order to increase performance you should
516   // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
517   fESDObjects->SetOwner(kTRUE);
518   fESDObjects->AddLast(obj);
519 }
520
521
522 void AliESDEvent::GetStdContent() 
523 {
524   // set pointers for standard content
525   // get by name much safer and not a big overhead since not called very often
526  
527   fESDRun = (AliESDRun*)fESDObjects->FindObject(fESDListName[kESDRun]);
528   fHeader = (AliESDHeader*)fESDObjects->FindObject(fESDListName[kHeader]);
529   fESDZDC = (AliESDZDC*)fESDObjects->FindObject(fESDListName[kESDZDC]);
530   fESDFMD = (AliESDFMD*)fESDObjects->FindObject(fESDListName[kESDFMD]);
531   fESDVZERO = (AliESDVZERO*)fESDObjects->FindObject(fESDListName[kESDVZERO]);
532   fESDTZERO = (AliESDTZERO*)fESDObjects->FindObject(fESDListName[kESDTZERO]);
533   fSPDVertex = (AliESDVertex*)fESDObjects->FindObject(fESDListName[kSPDVertex]);
534   fPrimaryVertex = (AliESDVertex*)fESDObjects->FindObject(fESDListName[kPrimaryVertex]);
535   fSPDMult =       (AliMultiplicity*)fESDObjects->FindObject(fESDListName[kSPDMult]);
536   fPHOSTrigger = (AliESDCaloTrigger*)fESDObjects->FindObject(fESDListName[kPHOSTrigger]);
537   fEMCALTrigger = (AliESDCaloTrigger*)fESDObjects->FindObject(fESDListName[kEMCALTrigger]);
538   fTracks = (TClonesArray*)fESDObjects->FindObject(fESDListName[kTracks]);
539   fMuonTracks = (TClonesArray*)fESDObjects->FindObject(fESDListName[kMuonTracks]);
540   fPmdTracks = (TClonesArray*)fESDObjects->FindObject(fESDListName[kPmdTracks]);
541   fTrdTracks = (TClonesArray*)fESDObjects->FindObject(fESDListName[kTrdTracks]);
542   fV0s = (TClonesArray*)fESDObjects->FindObject(fESDListName[kV0s]);
543   fCascades = (TClonesArray*)fESDObjects->FindObject(fESDListName[kCascades]);
544   fKinks = (TClonesArray*)fESDObjects->FindObject(fESDListName[kKinks]);
545   fCaloClusters = (TClonesArray*)fESDObjects->FindObject(fESDListName[kCaloClusters]);
546   fErrorLogs = (TClonesArray*)fESDObjects->FindObject(fESDListName[kErrorLogs]);
547
548 }
549
550 void AliESDEvent::SetStdNames(){
551   // Set the names of the standard contents
552   // 
553   if(fESDObjects->GetEntries()==kESDListN){
554     for(int i = 0;i < fESDObjects->GetEntries();i++){
555       TObject *fObj = fESDObjects->At(i);
556       if(fObj->InheritsFrom("TNamed")){
557         ((TNamed*)fObj)->SetName(fESDListName[i]);
558       }
559       else if(fObj->InheritsFrom("TClonesArray")){
560         ((TClonesArray*)fObj)->SetName(fESDListName[i]);
561       }
562     }
563   }
564   else{
565     printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
566   }
567
568
569 void AliESDEvent::CreateStdContent() 
570 {
571   // create the standard AOD content and set pointers
572
573   // create standard objects and add them to the TList of objects
574   AddObject(new AliESDRun());
575   AddObject(new AliESDHeader());
576   AddObject(new AliESDZDC());
577   AddObject(new AliESDFMD());
578   AddObject(new AliESDVZERO());
579   AddObject(new AliESDTZERO());
580   AddObject(new AliESDVertex());
581   AddObject(new AliESDVertex());
582   AddObject(new AliMultiplicity());
583   AddObject(new AliESDCaloTrigger());
584   AddObject(new AliESDCaloTrigger());
585   AddObject(new TClonesArray("AliESDtrack",0));
586   AddObject(new TClonesArray("AliESDMuonTrack",0));
587   AddObject(new TClonesArray("AliESDPmdTrack",0));
588   AddObject(new TClonesArray("AliESDTrdTrack",0));
589   AddObject(new TClonesArray("AliESDv0",0));
590   AddObject(new TClonesArray("AliESDcascade",0));
591   AddObject(new TClonesArray("AliESDkink",0));
592   AddObject(new TClonesArray("AliESDCaloCluster",0));
593   AddObject(new TClonesArray("AliRawDataErrorLog",0));
594
595   // check the order of the indices against enum...
596
597   // set names
598   SetStdNames();
599   // read back pointers
600   GetStdContent();
601 }
602
603 TObject* AliESDEvent::FindListObject(const char *name){
604   if(fESDObjects)return fESDObjects->FindObject(name);
605   return 0;
606
607
608 void AliESDEvent::ReadFromTree(TTree *tree){
609
610   // load the TTree
611   tree->LoadTree(0);
612
613   // if we find the "ESD" branch on the tree we do have the old structure
614   if(tree->GetBranch("ESD")){
615       char ** address = (char **)(tree->GetBranch("ESD")->GetAddress());
616       if (!address) {
617           printf("%s %d AliESDEvent::ReadFromTree() Reading old Tree \n",(char*)__FILE__,__LINE__);
618           tree->SetBranchAddress("ESD",&fESDOld);
619       } else {
620           printf("%s %d AliESDEvent::ReadFromTree() Reading old Tree \n",(char*)__FILE__,__LINE__);
621           printf("%s %d Branch already connected. Using existing branch address. \n",(char*)__FILE__,__LINE__);
622           fESDOld = (AliESD*) (*address);
623       }
624       
625       
626       CreateStdContent(); // create for copy
627       // when reading back we are not owner of the list 
628       // must not delete it
629       fESDObjects->SetOwner(kFALSE);
630       return;
631   }
632
633   fESDOld = 0;
634
635
636   // Try to find AliESDEvent
637   AliESDEvent *esdEvent = 0;
638   esdEvent = (AliESDEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliESDEvent");
639   //esdEvent = (AliESDEvent*)tree->GetUserInfo()->FindObject("AliESDEvent");
640
641   if(esdEvent){   
642       // Check if already connected to tree
643     TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("ESDObjectsConnectedToTree"));
644     if (connectedList) {
645       // If connected use the connected list if objects
646       fESDObjects->Delete();
647       fESDObjects = connectedList;
648       GetStdContent(); 
649       fConnected = true;
650       return;
651     }
652     // Connect to tree
653     if(fESDObjects->GetEntries()!=0){
654       // this should not happen here put a warning?
655     }
656     // prevent a memory leak when reading back the TList
657     delete fESDObjects;
658     fESDObjects = 0;
659     // create a new TList from the UserInfo TList... 
660     // copy constructor does not work...
661     fESDObjects = (TList*)(esdEvent->GetList()->Clone());
662     fESDObjects->SetOwner(kFALSE);
663     if(fESDObjects->GetEntries()<kESDListN){
664       printf("%s %d AliESDEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
665              (char*)__FILE__,__LINE__,fESDObjects->GetEntries(),kESDListN);
666     }
667     // set the branch addresses
668     TIter next(fESDObjects);
669     TNamed *el;
670     while((el=(TNamed*)next())){
671       TString bname(el->GetName());
672       
673       if(bname.CompareTo("AliESDfriend")==0)
674         {
675           // AliESDfriend does not have a name ...
676           tree->SetBranchAddress("ESDfriend.",fESDObjects->GetObjectRef(el));
677         }
678       else{
679         tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
680       }
681     }
682     GetStdContent();
683     // when reading back we are not owner of the list 
684     // must not delete it
685     fESDObjects->SetOwner(kFALSE);
686     fESDObjects->SetName("ESDObjectsConnectedToTree");
687     // we are not owner of the list objects 
688     // must not delete it
689     tree->GetUserInfo()->Add(fESDObjects);
690     fConnected = true;
691   }// no esdEvent
692   else {
693     // we can't get the list from the user data, create standard content
694     // and set it by hand (no ESDfriend at the moment
695     CreateStdContent();
696     TIter next(fESDObjects);
697     TNamed *el;
698     while((el=(TNamed*)next())){
699       TString bname(el->GetName());    
700       tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
701     }
702     GetStdContent();
703     // when reading back we are not owner of the list 
704     // must not delete it
705     fESDObjects->SetOwner(kFALSE);
706   }
707
708
709
710 }
711
712
713 void AliESDEvent::CopyFromOldESD()
714 {
715   // Method which copies over everthing from the old esd structure to the 
716   // new  
717
718   if(fESDOld){
719     ResetStdContent();
720      // Run
721     SetRunNumber(fESDOld->GetRunNumber());
722     SetPeriodNumber(fESDOld->GetPeriodNumber());
723     SetMagneticField(fESDRun->GetMagneticField());
724   
725     // leave out diamond ...
726     // SetDiamond(const AliESDVertex *vertex) { fESDRun->SetDiamond(vertex);}
727
728     // header
729     SetTriggerMask(fESDOld->GetTriggerMask());
730     SetOrbitNumber(fESDOld->GetOrbitNumber());
731     SetTimeStamp(fESDOld->GetTimeStamp());
732     SetEventType(fESDOld->GetEventType());
733     SetEventNumberInFile(fESDOld->GetEventNumberInFile());
734     SetBunchCrossNumber(fESDOld->GetBunchCrossNumber());
735     SetTriggerCluster(fESDOld->GetTriggerCluster());
736
737     // ZDC
738
739     SetZDC(fESDOld->GetZDCN1Energy(),
740            fESDOld->GetZDCP1Energy(),
741            fESDOld->GetZDCEMEnergy(),
742            fESDOld->GetZDCN2Energy(),
743            fESDOld->GetZDCP2Energy(),
744            fESDOld->GetZDCParticipants());
745
746     // FMD
747     
748     SetFMDData(fESDOld->GetFMDData());
749
750     // T0
751
752     SetT0zVertex(fESDOld->GetT0zVertex());
753     SetT0(fESDOld->GetT0());
754     //  leave amps out
755
756     // VZERO
757     if (fESDOld->GetVZEROData()) SetVZEROData(fESDOld->GetVZEROData());
758
759     SetVertex(fESDOld->GetVertex());
760
761     SetPrimaryVertex(fESDOld->GetPrimaryVertex());
762
763     SetMultiplicity(fESDOld->GetMultiplicity());
764     
765     for(int i = 0;i<fESDOld->GetNumberOfTracks();i++){
766       AddTrack(fESDOld->GetTrack(i));
767     }
768
769     for(int i = 0;i<fESDOld->GetNumberOfMuonTracks();i++){
770       AddMuonTrack(fESDOld->GetMuonTrack(i));
771     }
772
773     for(int i = 0;i<fESDOld->GetNumberOfPmdTracks();i++){
774       AddPmdTrack(fESDOld->GetPmdTrack(i));
775     }
776
777     for(int i = 0;i<fESDOld->GetNumberOfTrdTracks();i++){
778       AddTrdTrack(fESDOld->GetTrdTrack(i));
779     }
780
781     for(int i = 0;i<fESDOld->GetNumberOfV0s();i++){
782       AddV0(fESDOld->GetV0(i));
783     }
784
785     for(int i = 0;i<fESDOld->GetNumberOfCascades();i++){
786       AddCascade(fESDOld->GetCascade(i));
787     }
788
789     for(int i = 0;i<fESDOld->GetNumberOfKinks();i++){
790       AddKink(fESDOld->GetKink(i));
791     }
792
793
794     for(int i = 0;i<fESDOld->GetNumberOfCaloClusters();i++){
795       AddCaloCluster(fESDOld->GetCaloCluster(i));
796     }
797   }// if fesdold
798 }
799
800
801