]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliESDEvent.cxx
The data members fEMCALClusterCluster and fPHOSCluster are removed from AliESDCaloClu...
[u/mrichter/AliRoot.git] / STEER / AliESDEvent.cxx
CommitLineData
af885e0f 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//-----------------------------------------------------------------
f56a9fa7 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
af885e0f 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"
f0106218 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"
af885e0f 53
54
55ClassImp(AliESDEvent)
56
60e8f114 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",
72da5d8c 77 "Cascades",
60e8f114 78 "Kinks",
79 "CaloClusters",
80 "AliRawDataErrorLogs"};
af885e0f 81//______________________________________________________________________________
82AliESDEvent::AliESDEvent():
024c7734 83 AliVEvent(),
af885e0f 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),
60e8f114 106 fConnected(kFALSE),
af885e0f 107 fEMCALClusters(0),
108 fFirstEMCALCluster(-1),
109 fPHOSClusters(0),
110 fFirstPHOSCluster(-1)
111{
112}
113//______________________________________________________________________________
114AliESDEvent::AliESDEvent(const AliESDEvent& esd):
024c7734 115 AliVEvent(esd),
af885e0f 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)),
60e8f114 138 fConnected(esd.fConnected),
af885e0f 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//______________________________________________________________________________
172AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
173
174 // Assignment operator
175
176 if(&source == this) return *this;
024c7734 177 AliVEvent::operator=(source);
af885e0f 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
60e8f114 225 fConnected = source.fConnected;
af885e0f 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//______________________________________________________________________________
239AliESDEvent::~AliESDEvent()
240{
241 //
242 // Standard destructor
243 //
244
001b9beb 245 // everthing on the list gets deleted automatically
139f2194 246
247
60e8f114 248 if(fESDObjects&&!fConnected)
249 {
250 delete fESDObjects;
251 fESDObjects = 0;
252 }
139f2194 253
60e8f114 254
af885e0f 255}
256
257//______________________________________________________________________________
258void AliESDEvent::Reset()
259{
260
261
262 // Reset the standard contents
263 ResetStdContent();
264
265 if(fESDOld)fESDOld->Reset();
001b9beb 266 // call reset for user supplied data?
af885e0f 267}
268
269void 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){
316c6cd9 281 fSPDVertex->~AliESDVertex();
af885e0f 282 new (fSPDVertex) AliESDVertex();
60e8f114 283 fSPDVertex->SetName(fESDListName[kSPDVertex]);
af885e0f 284 }
285 if(fPrimaryVertex){
316c6cd9 286 fPrimaryVertex->~AliESDVertex();
af885e0f 287 new (fPrimaryVertex) AliESDVertex();
60e8f114 288 fPrimaryVertex->SetName(fESDListName[kPrimaryVertex]);
af885e0f 289 }
316c6cd9 290 if(fSPDMult){
291 fSPDMult->~AliMultiplicity();
292 new (fSPDMult) AliMultiplicity();
293 }
af885e0f 294 if(fPHOSTrigger)fPHOSTrigger->Reset();
295 if(fEMCALTrigger)fEMCALTrigger->Reset();
bc9a7b42 296 if(fTracks)fTracks->Delete();
af885e0f 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();
bc9a7b42 303 if(fCaloClusters)fCaloClusters->Delete();
16167d49 304 if(fErrorLogs) fErrorLogs->Delete();
af885e0f 305
60e8f114 306 // don't reset fconnected fConnected ;
307
af885e0f 308 fEMCALClusters=0;
309 fFirstEMCALCluster=-1;
310 fPHOSClusters=0;
311 fFirstPHOSCluster=-1;
312}
313
314
315Int_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//______________________________________________________________________________
326void 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"));
024c7734 361
362 return;
af885e0f 363}
364
365void AliESDEvent::SetESDfriend(const AliESDfriend *ev) {
366 //
367 // Attaches the complementary info to the ESD
368 //
369 if (!ev) return;
370
5300bdab 371 // to be sure that we set the tracks also
372 // in case of old esds
60e8f114 373 // if(fESDOld)CopyFromOldESD();
5300bdab 374
af885e0f 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
7f68891d 383Bool_t AliESDEvent::RemoveTrack(Int_t rm) {
d64bd07d 384 // ---------------------------------------------------------
7f68891d 385 // Remove a track and references to it from ESD,
386 // if this track does not come from a reconstructed decay
d64bd07d 387 // ---------------------------------------------------------
7f68891d 388 Int_t last=GetNumberOfTracks()-1;
389 if ((rm<0)||(rm>last)) return kFALSE;
390
391 Int_t used=0;
d64bd07d 392
393 // Check if this track comes from a reconstructed decay
7f68891d 394 Int_t nv0=GetNumberOfV0s();
395 for (Int_t n=0; n<nv0; n++) {
396 AliESDv0 *v0=GetV0(n);
397
398 Int_t idx=v0->GetNindex();
399 if (rm==idx) return kFALSE;
400 if (idx==last) used++;
401
402 idx=v0->GetPindex();
403 if (rm==idx) return kFALSE;
404 if (idx==last) used++;
405 }
406
407 Int_t ncs=GetNumberOfCascades();
408 for (Int_t n=0; n<ncs; n++) {
409 AliESDcascade *cs=GetCascade(n);
d64bd07d 410
7f68891d 411 Int_t idx=cs->GetIndex();
412 if (rm==idx) return kFALSE;
413 if (idx==last) used++;
414 }
415
416 Int_t nkn=GetNumberOfKinks();
417 for (Int_t n=0; n<nkn; n++) {
418 AliESDkink *kn=GetKink(n);
419
420 Int_t idx=kn->GetIndex(0);
421 if (rm==idx) return kFALSE;
422 if (idx==last) used++;
423
424 idx=kn->GetIndex(1);
425 if (rm==idx) return kFALSE;
426 if (idx==last) used++;
427 }
d64bd07d 428
d64bd07d 429
7f68891d 430 //Replace the removed track with the last track
431 TClonesArray &a=*fTracks;
432 delete a.RemoveAt(rm);
433
434 if (rm==last) return kTRUE;
435
436 AliESDtrack *t=GetTrack(last);
437 t->SetID(rm);
438 new (a[rm]) AliESDtrack(*t);
439 delete a.RemoveAt(last);
440
441 if (!used) return kTRUE;
442
443
444 // Remap the indices of the daughters of reconstructed decays
445 for (Int_t n=0; n<nv0; n++) {
446 AliESDv0 *v0=GetV0(n);
447 if (v0->GetIndex(0)==last) {
448 v0->SetIndex(0,rm);
449 used--;
450 if (!used) return kTRUE;
451 }
452 if (v0->GetIndex(1)==last) {
453 v0->SetIndex(1,rm);
454 used--;
455 if (!used) return kTRUE;
456 }
457 }
458
459 for (Int_t n=0; n<ncs; n++) {
460 AliESDcascade *cs=GetCascade(n);
461 if (cs->GetIndex()==last) {
462 cs->SetIndex(rm);
463 used--;
464 if (!used) return kTRUE;
465 }
466 }
467
468 for (Int_t n=0; n<nkn; n++) {
469 AliESDkink *kn=GetKink(n);
470 if (kn->GetIndex(0)==last) {
471 kn->SetIndex(rm,0);
472 used--;
473 if (!used) return kTRUE;
474 }
475 if (kn->GetIndex(1)==last) {
476 kn->SetIndex(rm,1);
477 used--;
478 if (!used) return kTRUE;
479 }
480 }
d64bd07d 481
482 return kTRUE;
483}
484
485
7f68891d 486Bool_t AliESDEvent::Clean(Float_t *cleanPars) {
487 //
488 // Remove the data which are not needed for the physics analysis.
489 //
490 // If track's transverse parameter is larger than fDmax
491 // OR
492 // track's longitudinal parameter is larger than fZmax
493 // an attempt to remove this track from ESD is made.
494 //
495 // The track gets removed if it does not come
496 // from a reconstructed decay
497 //
498
499 Float_t dmax=cleanPars[0], zmax=cleanPars[1];
500
501 const AliESDVertex *vertex=GetVertex();
502 Bool_t vtxOK=vertex->GetStatus(), rc=kFALSE;
503
504 Int_t nTracks=GetNumberOfTracks();
505 for (Int_t i=nTracks-1; i>=0; i--) {
506 AliESDtrack *track=GetTrack(i);
507 Float_t xy,z; track->GetImpactParameters(xy,z);
508 if ((TMath::Abs(xy) > dmax) || (vtxOK && (TMath::Abs(z) > zmax))) {
509 if (RemoveTrack(i)) rc=kTRUE;
510 }
511 }
512
513 return rc;
514}
515
af885e0f 516Int_t AliESDEvent::AddTrack(const AliESDtrack *t) {
517 // Add track
518 TClonesArray &ftr = *fTracks;
519 AliESDtrack * track = new(ftr[fTracks->GetEntriesFast()])AliESDtrack(*t);
520 track->SetID(fTracks->GetEntriesFast()-1);
521 return track->GetID();
522}
523
f0106218 524 void AliESDEvent::AddMuonTrack(const AliESDMuonTrack *t) {
525 TClonesArray &fmu = *fMuonTracks;
526 new(fmu[fMuonTracks->GetEntriesFast()]) AliESDMuonTrack(*t);
527}
528
529void AliESDEvent::AddPmdTrack(const AliESDPmdTrack *t) {
530 TClonesArray &fpmd = *fPmdTracks;
531 new(fpmd[fPmdTracks->GetEntriesFast()]) AliESDPmdTrack(*t);
532}
533
534void AliESDEvent::AddTrdTrack(const AliESDTrdTrack *t) {
535 TClonesArray &ftrd = *fTrdTracks;
536 new(ftrd[fTrdTracks->GetEntriesFast()]) AliESDTrdTrack(*t);
537}
538
539
540
541
af885e0f 542Int_t AliESDEvent::AddKink(const AliESDkink *c) {
543 // Add kink
544 TClonesArray &fk = *fKinks;
545 AliESDkink * kink = new(fk[fKinks->GetEntriesFast()]) AliESDkink(*c);
546 kink->SetID(fKinks->GetEntriesFast()); // CKB different from the other imps..
547 return fKinks->GetEntriesFast()-1;
548}
549
f0106218 550
551void AliESDEvent::AddCascade(const AliESDcascade *c) {
552 TClonesArray &fc = *fCascades;
553 new(fc[fCascades->GetEntriesFast()]) AliESDcascade(*c);
554}
555
556
af885e0f 557Int_t AliESDEvent::AddCaloCluster(const AliESDCaloCluster *c) {
558 // Add calocluster
559 TClonesArray &fc = *fCaloClusters;
560 AliESDCaloCluster *clus = new(fc[fCaloClusters->GetEntriesFast()]) AliESDCaloCluster(*c);
561 clus->SetID(fCaloClusters->GetEntriesFast()-1);
562 return fCaloClusters->GetEntriesFast()-1;
563 }
564
565
f0106218 566 void AliESDEvent::AddRawDataErrorLog(const AliRawDataErrorLog *log) {
567 TClonesArray &errlogs = *fErrorLogs;
568 new(errlogs[errlogs.GetEntriesFast()]) AliRawDataErrorLog(*log);
569 }
570
60e8f114 571void AliESDEvent::SetVertex(const AliESDVertex *vertex) {
572 // use already allocated space
573 if(fSPDVertex){
316c6cd9 574 *fSPDVertex = *vertex;
60e8f114 575 fSPDVertex->SetName(fESDListName[kSPDVertex]);
576 }
577}
578
579void AliESDEvent::SetPrimaryVertex(const AliESDVertex *vertex) {
60e8f114 580 if(fPrimaryVertex){
316c6cd9 581 *fPrimaryVertex = *vertex;
60e8f114 582 fPrimaryVertex->SetName(fESDListName[kPrimaryVertex]);
583 }
584}
585
f0106218 586void AliESDEvent::SetMultiplicity(const AliMultiplicity *mul) {
587 if(fSPDMult){
316c6cd9 588 *fSPDMult = *mul;
f0106218 589 }
590}
591
592
af885e0f 593void AliESDEvent::SetFMDData(AliESDFMD * obj) {
594 // use already allocated space
595 if(fESDFMD){
316c6cd9 596 *fESDFMD = *obj;
af885e0f 597 }
598}
599
600void AliESDEvent::SetVZEROData(AliESDVZERO * obj){
601 // use already allocated space
602 if(fESDVZERO)
603 new(fESDVZERO) AliESDVZERO(*obj);
604}
605
606void AliESDEvent::GetESDfriend(AliESDfriend *ev) const {
607 //
608 // Extracts the complementary info from the ESD
609 //
610 if (!ev) return;
611
612 Int_t ntrk=GetNumberOfTracks();
613
614 for (Int_t i=0; i<ntrk; i++) {
80799a5f 615 AliESDtrack *t=GetTrack(i);
af885e0f 616 const AliESDfriendTrack *f=t->GetFriendTrack();
617 ev->AddTrack(f);
80799a5f 618
619 t->ReleaseESDfriendTrack();// Not to have two copies of "friendTrack"
620
af885e0f 621 }
622}
623
624
625void AliESDEvent::AddObject(TObject* obj)
626{
627 // Add an object to the list of object.
628 // Please be aware that in order to increase performance you should
629 // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
630 fESDObjects->SetOwner(kTRUE);
631 fESDObjects->AddLast(obj);
632}
633
634
635void AliESDEvent::GetStdContent()
636{
637 // set pointers for standard content
60e8f114 638 // get by name much safer and not a big overhead since not called very often
639
640 fESDRun = (AliESDRun*)fESDObjects->FindObject(fESDListName[kESDRun]);
641 fHeader = (AliESDHeader*)fESDObjects->FindObject(fESDListName[kHeader]);
642 fESDZDC = (AliESDZDC*)fESDObjects->FindObject(fESDListName[kESDZDC]);
643 fESDFMD = (AliESDFMD*)fESDObjects->FindObject(fESDListName[kESDFMD]);
644 fESDVZERO = (AliESDVZERO*)fESDObjects->FindObject(fESDListName[kESDVZERO]);
645 fESDTZERO = (AliESDTZERO*)fESDObjects->FindObject(fESDListName[kESDTZERO]);
646 fSPDVertex = (AliESDVertex*)fESDObjects->FindObject(fESDListName[kSPDVertex]);
647 fPrimaryVertex = (AliESDVertex*)fESDObjects->FindObject(fESDListName[kPrimaryVertex]);
648 fSPDMult = (AliMultiplicity*)fESDObjects->FindObject(fESDListName[kSPDMult]);
649 fPHOSTrigger = (AliESDCaloTrigger*)fESDObjects->FindObject(fESDListName[kPHOSTrigger]);
650 fEMCALTrigger = (AliESDCaloTrigger*)fESDObjects->FindObject(fESDListName[kEMCALTrigger]);
651 fTracks = (TClonesArray*)fESDObjects->FindObject(fESDListName[kTracks]);
652 fMuonTracks = (TClonesArray*)fESDObjects->FindObject(fESDListName[kMuonTracks]);
653 fPmdTracks = (TClonesArray*)fESDObjects->FindObject(fESDListName[kPmdTracks]);
654 fTrdTracks = (TClonesArray*)fESDObjects->FindObject(fESDListName[kTrdTracks]);
655 fV0s = (TClonesArray*)fESDObjects->FindObject(fESDListName[kV0s]);
656 fCascades = (TClonesArray*)fESDObjects->FindObject(fESDListName[kCascades]);
657 fKinks = (TClonesArray*)fESDObjects->FindObject(fESDListName[kKinks]);
658 fCaloClusters = (TClonesArray*)fESDObjects->FindObject(fESDListName[kCaloClusters]);
659 fErrorLogs = (TClonesArray*)fESDObjects->FindObject(fESDListName[kErrorLogs]);
af885e0f 660
661}
662
663void AliESDEvent::SetStdNames(){
664 // Set the names of the standard contents
60e8f114 665 //
666 if(fESDObjects->GetEntries()==kESDListN){
667 for(int i = 0;i < fESDObjects->GetEntries();i++){
668 TObject *fObj = fESDObjects->At(i);
669 if(fObj->InheritsFrom("TNamed")){
670 ((TNamed*)fObj)->SetName(fESDListName[i]);
671 }
672 else if(fObj->InheritsFrom("TClonesArray")){
673 ((TClonesArray*)fObj)->SetName(fESDListName[i]);
674 }
675 }
676 }
677 else{
678 printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
679 }
af885e0f 680}
681
682void AliESDEvent::CreateStdContent()
683{
684 // create the standard AOD content and set pointers
685
686 // create standard objects and add them to the TList of objects
687 AddObject(new AliESDRun());
688 AddObject(new AliESDHeader());
689 AddObject(new AliESDZDC());
690 AddObject(new AliESDFMD());
691 AddObject(new AliESDVZERO());
692 AddObject(new AliESDTZERO());
693 AddObject(new AliESDVertex());
694 AddObject(new AliESDVertex());
695 AddObject(new AliMultiplicity());
696 AddObject(new AliESDCaloTrigger());
697 AddObject(new AliESDCaloTrigger());
698 AddObject(new TClonesArray("AliESDtrack",0));
699 AddObject(new TClonesArray("AliESDMuonTrack",0));
700 AddObject(new TClonesArray("AliESDPmdTrack",0));
701 AddObject(new TClonesArray("AliESDTrdTrack",0));
702 AddObject(new TClonesArray("AliESDv0",0));
703 AddObject(new TClonesArray("AliESDcascade",0));
704 AddObject(new TClonesArray("AliESDkink",0));
705 AddObject(new TClonesArray("AliESDCaloCluster",0));
706 AddObject(new TClonesArray("AliRawDataErrorLog",0));
707
708 // check the order of the indices against enum...
709
af885e0f 710 // set names
711 SetStdNames();
60e8f114 712 // read back pointers
713 GetStdContent();
af885e0f 714}
715
001b9beb 716TObject* AliESDEvent::FindListObject(const char *name){
717 if(fESDObjects)return fESDObjects->FindObject(name);
718 return 0;
719}
720
af885e0f 721void AliESDEvent::ReadFromTree(TTree *tree){
024c7734 722
723 // load the TTree
724 tree->LoadTree(0);
725
001b9beb 726 // if we find the "ESD" branch on the tree we do have the old structure
af885e0f 727 if(tree->GetBranch("ESD")){
b93c2026 728 char ** address = (char **)(tree->GetBranch("ESD")->GetAddress());
729 if (!address) {
730 printf("%s %d AliESDEvent::ReadFromTree() Reading old Tree \n",(char*)__FILE__,__LINE__);
731 tree->SetBranchAddress("ESD",&fESDOld);
732 } else {
733 printf("%s %d AliESDEvent::ReadFromTree() Reading old Tree \n",(char*)__FILE__,__LINE__);
734 printf("%s %d Branch already connected. Using existing branch address. \n",(char*)__FILE__,__LINE__);
735 fESDOld = (AliESD*) (*address);
736 }
737
738
739 CreateStdContent(); // create for copy
740 // when reading back we are not owner of the list
741 // must not delete it
742 fESDObjects->SetOwner(kFALSE);
743 return;
af885e0f 744 }
745
746 fESDOld = 0;
747
748
749 // Try to find AliESDEvent
750 AliESDEvent *esdEvent = 0;
751 esdEvent = (AliESDEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliESDEvent");
bff64acf 752 //esdEvent = (AliESDEvent*)tree->GetUserInfo()->FindObject("AliESDEvent");
af885e0f 753
001b9beb 754 if(esdEvent){
941603c0 755 // Check if already connected to tree
139f2194 756 TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("ESDObjectsConnectedToTree"));
757 if (connectedList) {
758 // If connected use the connected list if objects
759 fESDObjects->Delete();
b5bc83df 760 fESDObjects = connectedList;
761 GetStdContent();
60e8f114 762 fConnected = true;
139f2194 763 return;
764 }
765 // Connect to tree
001b9beb 766 if(fESDObjects->GetEntries()!=0){
767 // this should not happen here put a warning?
768 }
769 // prevent a memory leak when reading back the TList
770 delete fESDObjects;
771 fESDObjects = 0;
af885e0f 772 // create a new TList from the UserInfo TList...
773 // copy constructor does not work...
774 fESDObjects = (TList*)(esdEvent->GetList()->Clone());
139f2194 775 fESDObjects->SetOwner(kFALSE);
af885e0f 776 if(fESDObjects->GetEntries()<kESDListN){
941603c0 777 printf("%s %d AliESDEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
778 (char*)__FILE__,__LINE__,fESDObjects->GetEntries(),kESDListN);
af885e0f 779 }
780 // set the branch addresses
781 TIter next(fESDObjects);
782 TNamed *el;
783 while((el=(TNamed*)next())){
784 TString bname(el->GetName());
785
786 if(bname.CompareTo("AliESDfriend")==0)
787 {
788 // AliESDfriend does not have a name ...
af885e0f 789 tree->SetBranchAddress("ESDfriend.",fESDObjects->GetObjectRef(el));
790 }
791 else{
792 tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
793 }
794 }
795 GetStdContent();
796 // when reading back we are not owner of the list
797 // must not delete it
798 fESDObjects->SetOwner(kFALSE);
60e8f114 799 fESDObjects->SetName("ESDObjectsConnectedToTree");
139f2194 800 // we are not owner of the list objects
801 // must not delete it
60e8f114 802 tree->GetUserInfo()->Add(fESDObjects);
803 fConnected = true;
af885e0f 804 }// no esdEvent
805 else {
001b9beb 806 // we can't get the list from the user data, create standard content
807 // and set it by hand (no ESDfriend at the moment
af885e0f 808 CreateStdContent();
809 TIter next(fESDObjects);
810 TNamed *el;
811 while((el=(TNamed*)next())){
812 TString bname(el->GetName());
813 tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
814 }
815 GetStdContent();
816 // when reading back we are not owner of the list
817 // must not delete it
818 fESDObjects->SetOwner(kFALSE);
819 }
820
821
822
823}
824
825
826void AliESDEvent::CopyFromOldESD()
827{
828 // Method which copies over everthing from the old esd structure to the
829 // new
830
831 if(fESDOld){
832 ResetStdContent();
833 // Run
834 SetRunNumber(fESDOld->GetRunNumber());
835 SetPeriodNumber(fESDOld->GetPeriodNumber());
836 SetMagneticField(fESDRun->GetMagneticField());
837
838 // leave out diamond ...
839 // SetDiamond(const AliESDVertex *vertex) { fESDRun->SetDiamond(vertex);}
840
841 // header
842 SetTriggerMask(fESDOld->GetTriggerMask());
843 SetOrbitNumber(fESDOld->GetOrbitNumber());
844 SetTimeStamp(fESDOld->GetTimeStamp());
845 SetEventType(fESDOld->GetEventType());
846 SetEventNumberInFile(fESDOld->GetEventNumberInFile());
847 SetBunchCrossNumber(fESDOld->GetBunchCrossNumber());
848 SetTriggerCluster(fESDOld->GetTriggerCluster());
849
850 // ZDC
851
852 SetZDC(fESDOld->GetZDCN1Energy(),
853 fESDOld->GetZDCP1Energy(),
854 fESDOld->GetZDCEMEnergy(),
855 fESDOld->GetZDCN2Energy(),
856 fESDOld->GetZDCP2Energy(),
857 fESDOld->GetZDCParticipants());
858
859 // FMD
860
cb6aa27f 861 if(fESDOld->GetFMDData())SetFMDData(fESDOld->GetFMDData());
af885e0f 862
863 // T0
864
865 SetT0zVertex(fESDOld->GetT0zVertex());
866 SetT0(fESDOld->GetT0());
867 // leave amps out
868
869 // VZERO
c06eaba2 870 if (fESDOld->GetVZEROData()) SetVZEROData(fESDOld->GetVZEROData());
af885e0f 871
cb6aa27f 872 if(fESDOld->GetVertex())SetVertex(fESDOld->GetVertex());
af885e0f 873
cb6aa27f 874 if(fESDOld->GetPrimaryVertex())SetPrimaryVertex(fESDOld->GetPrimaryVertex());
af885e0f 875
cb6aa27f 876 if(fESDOld->GetMultiplicity())SetMultiplicity(fESDOld->GetMultiplicity());
af885e0f 877
878 for(int i = 0;i<fESDOld->GetNumberOfTracks();i++){
879 AddTrack(fESDOld->GetTrack(i));
880 }
881
882 for(int i = 0;i<fESDOld->GetNumberOfMuonTracks();i++){
883 AddMuonTrack(fESDOld->GetMuonTrack(i));
884 }
885
886 for(int i = 0;i<fESDOld->GetNumberOfPmdTracks();i++){
887 AddPmdTrack(fESDOld->GetPmdTrack(i));
888 }
889
890 for(int i = 0;i<fESDOld->GetNumberOfTrdTracks();i++){
891 AddTrdTrack(fESDOld->GetTrdTrack(i));
892 }
893
894 for(int i = 0;i<fESDOld->GetNumberOfV0s();i++){
895 AddV0(fESDOld->GetV0(i));
896 }
897
898 for(int i = 0;i<fESDOld->GetNumberOfCascades();i++){
899 AddCascade(fESDOld->GetCascade(i));
900 }
901
902 for(int i = 0;i<fESDOld->GetNumberOfKinks();i++){
903 AddKink(fESDOld->GetKink(i));
904 }
905
906
907 for(int i = 0;i<fESDOld->GetNumberOfCaloClusters();i++){
908 AddCaloCluster(fESDOld->GetCaloCluster(i));
909 }
910 }// if fesdold
911}
912
913
914