Moving AliESDCosmicTrack from TPC to STEER/ESD (Marian)
[u/mrichter/AliRoot.git] / STEER / ESD / 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
6989bff3 20// This is the class to deal with during the physics analysis of data.
f56a9fa7 21// It also ensures the backward compatibility with the old ESD format.
6989bff3 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*/
7d44c466 30// The AliESDInputHandler does this automatically for you
f56a9fa7 31//
32// Origin: Christian Klein-Boesing, CERN, Christian.Klein-Boesing@cern.ch
af885e0f 33//-----------------------------------------------------------------
34
35#include "TList.h"
cd1d4ee0 36#include "TRefArray.h"
af885e0f 37#include <TNamed.h>
2a3dfb14 38#include <TROOT.h>
39#include <TInterpreter.h>
af885e0f 40
41#include "AliESDEvent.h"
42#include "AliESDfriend.h"
43#include "AliESDVZERO.h"
af885e0f 44#include "AliESDFMD.h"
45#include "AliESD.h"
f0106218 46#include "AliESDMuonTrack.h"
47#include "AliESDPmdTrack.h"
48#include "AliESDTrdTrack.h"
49#include "AliESDVertex.h"
50#include "AliESDcascade.h"
51#include "AliESDPmdTrack.h"
6c8e0967 52#include "AliESDTrdTrigger.h"
f0106218 53#include "AliESDTrdTrack.h"
52cd0cc0 54#include "AliESDTrdTracklet.h"
f0106218 55#include "AliESDVertex.h"
518573d7 56#include "AliVertexerTracks.h"
f0106218 57#include "AliESDcascade.h"
58#include "AliESDkink.h"
59#include "AliESDtrack.h"
60#include "AliESDHLTtrack.h"
61#include "AliESDCaloCluster.h"
e649177a 62#include "AliESDCaloCells.h"
f0106218 63#include "AliESDv0.h"
64#include "AliESDFMD.h"
65#include "AliESDVZERO.h"
66#include "AliMultiplicity.h"
67#include "AliRawDataErrorLog.h"
e649177a 68#include "AliLog.h"
bd95bae7 69#include "AliESDACORDE.h"
8b12d288 70#include "AliESDHLTDecision.h"
fba4b2e2 71#include "AliCentrality.h"
8e1324ab 72#include "AliESDCosmicTrack.h"
820b4d9e 73#ifdef MFT_UPGRADE
74#include "AliESDMFT.h"
75#endif
ce7adfe9 76#include "AliEventplane.h"
8b12d288 77
820b4d9e 78
af885e0f 79ClassImp(AliESDEvent)
80
60e8f114 81
82
83// here we define the names, some classes are no TNamed, therefore the classnames
84// are the Names
6989bff3 85 const char* AliESDEvent::fgkESDListName[kESDListN] = {"AliESDRun",
f858b00e 86 "AliESDHeader",
87 "AliESDZDC",
88 "AliESDFMD",
89 "AliESDVZERO",
90 "AliESDTZERO",
91 "TPCVertex",
92 "SPDVertex",
93 "PrimaryVertex",
94 "AliMultiplicity",
95 "PHOSTrigger",
96 "EMCALTrigger",
97 "SPDPileupVertices",
98 "TrkPileupVertices",
99 "Tracks",
100 "MuonTracks",
101 "PmdTracks",
6c8e0967 102 "AliESDTrdTrigger",
f858b00e 103 "TrdTracks",
52cd0cc0 104 "TrdTracklets",
f858b00e 105 "V0s",
106 "Cascades",
107 "Kinks",
108 "CaloClusters",
109 "EMCALCells",
110 "PHOSCells",
111 "AliRawDataErrorLogs",
112 "AliESDACORDE",
8e1324ab 113 "AliTOFHeader",
114 "CosmicTracks"
115 #ifdef MFT_UPGRADE
820b4d9e 116// , "AliESDMFT"
117 #endif
118 };
bd95bae7 119
af885e0f 120//______________________________________________________________________________
121AliESDEvent::AliESDEvent():
024c7734 122 AliVEvent(),
af885e0f 123 fESDObjects(new TList()),
124 fESDRun(0),
125 fHeader(0),
126 fESDZDC(0),
127 fESDFMD(0),
128 fESDVZERO(0),
129 fESDTZERO(0),
06cc9d95 130 fTPCVertex(0),
af885e0f 131 fSPDVertex(0),
132 fPrimaryVertex(0),
133 fSPDMult(0),
134 fPHOSTrigger(0),
135 fEMCALTrigger(0),
bd95bae7 136 fESDACORDE(0),
6c8e0967 137 fTrdTrigger(0),
04d01397 138 fSPDPileupVertices(0),
139 fTrkPileupVertices(0),
af885e0f 140 fTracks(0),
141 fMuonTracks(0),
142 fPmdTracks(0),
143 fTrdTracks(0),
52cd0cc0 144 fTrdTracklets(0),
af885e0f 145 fV0s(0),
146 fCascades(0),
147 fKinks(0),
148 fCaloClusters(0),
e649177a 149 fEMCALCells(0), fPHOSCells(0),
8e1324ab 150 fCosmicTracks(0),
af885e0f 151 fErrorLogs(0),
152 fESDOld(0),
1bd10080 153 fESDFriendOld(0),
60e8f114 154 fConnected(kFALSE),
f858b00e 155 fUseOwnList(kFALSE),
2eec2a33 156 fTOFHeader(0),
ce7adfe9 157 fCentrality(0),
a8f382ab 158 fEventplane(0),
159 fDetectorStatus(0xFFFFFFFF)
820b4d9e 160 #ifdef MFT_UPGRADE
161// , fESDMFT(0)
162 #endif
af885e0f 163{
164}
165//______________________________________________________________________________
166AliESDEvent::AliESDEvent(const AliESDEvent& esd):
024c7734 167 AliVEvent(esd),
af885e0f 168 fESDObjects(new TList()),
169 fESDRun(new AliESDRun(*esd.fESDRun)),
170 fHeader(new AliESDHeader(*esd.fHeader)),
171 fESDZDC(new AliESDZDC(*esd.fESDZDC)),
172 fESDFMD(new AliESDFMD(*esd.fESDFMD)),
173 fESDVZERO(new AliESDVZERO(*esd.fESDVZERO)),
174 fESDTZERO(new AliESDTZERO(*esd.fESDTZERO)),
06cc9d95 175 fTPCVertex(new AliESDVertex(*esd.fTPCVertex)),
af885e0f 176 fSPDVertex(new AliESDVertex(*esd.fSPDVertex)),
177 fPrimaryVertex(new AliESDVertex(*esd.fPrimaryVertex)),
178 fSPDMult(new AliMultiplicity(*esd.fSPDMult)),
179 fPHOSTrigger(new AliESDCaloTrigger(*esd.fPHOSTrigger)),
180 fEMCALTrigger(new AliESDCaloTrigger(*esd.fEMCALTrigger)),
bd95bae7 181 fESDACORDE(new AliESDACORDE(*esd.fESDACORDE)),
6c8e0967 182 fTrdTrigger(new AliESDTrdTrigger(*esd.fTrdTrigger)),
04d01397 183 fSPDPileupVertices(new TClonesArray(*esd.fSPDPileupVertices)),
184 fTrkPileupVertices(new TClonesArray(*esd.fTrkPileupVertices)),
af885e0f 185 fTracks(new TClonesArray(*esd.fTracks)),
186 fMuonTracks(new TClonesArray(*esd.fMuonTracks)),
187 fPmdTracks(new TClonesArray(*esd.fPmdTracks)),
188 fTrdTracks(new TClonesArray(*esd.fTrdTracks)),
52cd0cc0 189 fTrdTracklets(new TClonesArray(*esd.fTrdTracklets)),
af885e0f 190 fV0s(new TClonesArray(*esd.fV0s)),
191 fCascades(new TClonesArray(*esd.fCascades)),
192 fKinks(new TClonesArray(*esd.fKinks)),
193 fCaloClusters(new TClonesArray(*esd.fCaloClusters)),
e649177a 194 fEMCALCells(new AliESDCaloCells(*esd.fEMCALCells)),
195 fPHOSCells(new AliESDCaloCells(*esd.fPHOSCells)),
8e1324ab 196 fCosmicTracks(new TClonesArray(*esd.fCosmicTracks)),
af885e0f 197 fErrorLogs(new TClonesArray(*esd.fErrorLogs)),
7251b311 198 fESDOld(esd.fESDOld ? new AliESD(*esd.fESDOld) : 0),
199 fESDFriendOld(esd.fESDFriendOld ? new AliESDfriend(*esd.fESDFriendOld) : 0),
60e8f114 200 fConnected(esd.fConnected),
f858b00e 201 fUseOwnList(esd.fUseOwnList),
2eec2a33 202 fTOFHeader(new AliTOFHeader(*esd.fTOFHeader)),
ce7adfe9 203 fCentrality(new AliCentrality(*esd.fCentrality)),
a8f382ab 204 fEventplane(new AliEventplane(*esd.fEventplane)),
205 fDetectorStatus(esd.fDetectorStatus)
820b4d9e 206 #ifdef MFT_UPGRADE
207// , fESDMFT(new AliESDMFT(*esd.fESDMFT))
208 #endif
209
210
af885e0f 211{
820b4d9e 212 printf("copying ESD event...\n"); // AU
af885e0f 213 // CKB init in the constructor list and only add here ...
214 AddObject(fESDRun);
215 AddObject(fHeader);
216 AddObject(fESDZDC);
217 AddObject(fESDFMD);
218 AddObject(fESDVZERO);
219 AddObject(fESDTZERO);
06cc9d95 220 AddObject(fTPCVertex);
af885e0f 221 AddObject(fSPDVertex);
222 AddObject(fPrimaryVertex);
223 AddObject(fSPDMult);
224 AddObject(fPHOSTrigger);
225 AddObject(fEMCALTrigger);
6c8e0967 226 AddObject(fTrdTrigger);
04d01397 227 AddObject(fSPDPileupVertices);
228 AddObject(fTrkPileupVertices);
af885e0f 229 AddObject(fTracks);
230 AddObject(fMuonTracks);
231 AddObject(fPmdTracks);
232 AddObject(fTrdTracks);
52cd0cc0 233 AddObject(fTrdTracklets);
af885e0f 234 AddObject(fV0s);
235 AddObject(fCascades);
236 AddObject(fKinks);
237 AddObject(fCaloClusters);
e649177a 238 AddObject(fEMCALCells);
239 AddObject(fPHOSCells);
8e1324ab 240 AddObject(fCosmicTracks);
af885e0f 241 AddObject(fErrorLogs);
bd95bae7 242 AddObject(fESDACORDE);
f858b00e 243 AddObject(fTOFHeader);
820b4d9e 244 #ifdef MFT_UPGRADE
245// AddObject(fESDMFT);
246 #endif
af885e0f 247 GetStdContent();
248
249}
250
251//______________________________________________________________________________
252AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
253
254 // Assignment operator
255
256 if(&source == this) return *this;
024c7734 257 AliVEvent::operator=(source);
af885e0f 258
732a24fe 259 // This assumes that the list is already created
260 // and that the virtual void Copy(Tobject&) function
261 // is correctly implemented in the derived class
262 // otherwise only TObject::Copy() will be used
263
264
102c56c8 265
732a24fe 266 if((fESDObjects->GetSize()==0)&&(source.fESDObjects->GetSize()>=kESDListN)){
267 // We cover the case that we do not yet have the
268 // standard content but the source has it
269 CreateStdContent();
270 }
271
272 TIter next(source.GetList());
273 TObject *its = 0;
274 TString name;
275 while ((its = next())) {
276 name.Form("%s", its->GetName());
277 TObject *mine = fESDObjects->FindObject(name.Data());
278 if(!mine){
102c56c8 279 TClass* pClass=TClass::GetClass(its->ClassName());
280 if (!pClass) {
281 AliWarning(Form("Can not find class description for entry %s (%s)\n",
282 its->ClassName(), name.Data()));
283 continue;
284 }
732a24fe 285
102c56c8 286 mine=(TObject*)pClass->New();
287 if(!mine){
288 // not in this: can be added to list
289 AliWarning(Form("%s:%d Could not find %s for copying \n",
290 (char*)__FILE__,__LINE__,name.Data()));
291 continue;
292 }
293 if(mine->InheritsFrom("TNamed")){
294 ((TNamed*)mine)->SetName(name);
295 }
296 else if(mine->InheritsFrom("TCollection")){
11becff8 297 if(mine->InheritsFrom("TClonesArray")) {
298 TClonesArray* tcits = dynamic_cast<TClonesArray*>(its);
299 if (tcits)
300 dynamic_cast<TClonesArray*>(mine)->SetClass(tcits->GetClass());
301 }
102c56c8 302 dynamic_cast<TCollection*>(mine)->SetName(name);
303 }
304 AliDebug(1, Form("adding object %s of type %s", mine->GetName(), mine->ClassName()));
305 AddObject(mine);
306 }
307
732a24fe 308 if(!its->InheritsFrom("TCollection")){
309 // simple objects
310 its->Copy(*mine);
311 }
312 else if(its->InheritsFrom("TClonesArray")){
313 // Create or expand the tclonesarray pointers
314 // so we can directly copy to the object
315 TClonesArray *its_tca = (TClonesArray*)its;
316 TClonesArray *mine_tca = (TClonesArray*)mine;
317
318 // this leaves the capacity of the TClonesArray the same
319 // except for a factor of 2 increase when size > capacity
320 // does not release any memory occupied by the tca
321 mine_tca->ExpandCreate(its_tca->GetEntriesFast());
322 for(int i = 0;i < its_tca->GetEntriesFast();++i){
323 // copy
324 TObject *mine_tca_obj = mine_tca->At(i);
325 TObject *its_tca_obj = its_tca->At(i);
326 // no need to delete first
327 // pointers within the class should be handled by Copy()...
328 // Can there be Empty slots?
329 its_tca_obj->Copy(*mine_tca_obj);
330 }
331 }
332 else{
333 AliWarning(Form("%s:%d cannot copy TCollection \n",
334 (char*)__FILE__,__LINE__));
335 }
336 }
af885e0f 337
2eec2a33 338 fCentrality = source.fCentrality;
ce7adfe9 339 fEventplane = source.fEventplane;
2eec2a33 340
341 fConnected = source.fConnected;
a2fbb067 342 fUseOwnList = source.fUseOwnList;
a8f382ab 343
344 fDetectorStatus = source.fDetectorStatus;
af885e0f 345
af885e0f 346 return *this;
af885e0f 347}
348
349
350//______________________________________________________________________________
351AliESDEvent::~AliESDEvent()
352{
353 //
354 // Standard destructor
355 //
356
001b9beb 357 // everthing on the list gets deleted automatically
139f2194 358
359
60e8f114 360 if(fESDObjects&&!fConnected)
361 {
362 delete fESDObjects;
363 fESDObjects = 0;
364 }
cb62947d 365 if (fCentrality) delete fCentrality;
ce7adfe9 366 if (fEventplane) delete fEventplane;
60e8f114 367
af885e0f 368}
369
732a24fe 370void AliESDEvent::Copy(TObject &obj) const {
371
372 // interface to TOBject::Copy
373 // Copies the content of this into obj!
374 // bascially obj = *this
375
376 if(this==&obj)return;
377 AliESDEvent *robj = dynamic_cast<AliESDEvent*>(&obj);
378 if(!robj)return; // not an AliESEvent
379 *robj = *this;
380 return;
381}
382
af885e0f 383//______________________________________________________________________________
384void AliESDEvent::Reset()
385{
386
102c56c8 387 // Handle the cases
388 // Std content + Non std content
389
af885e0f 390 // Reset the standard contents
391 ResetStdContent();
102c56c8 392
393 // reset for the old data without AliESDEvent...
af885e0f 394 if(fESDOld)fESDOld->Reset();
d7749dec 395 if(fESDFriendOld){
396 fESDFriendOld->~AliESDfriend();
397 new (fESDFriendOld) AliESDfriend();
398 }
102c56c8 399 //
400
401 if(fESDObjects->GetSize()>kESDListN){
402 // we have non std content
403 // this also covers esdfriends
404 for(int i = kESDListN;i < fESDObjects->GetSize();++i){
405 TObject *pObject = fESDObjects->At(i);
406 // TClonesArrays
407 if(pObject->InheritsFrom(TClonesArray::Class())){
408 ((TClonesArray*)pObject)->Delete();
409 }
410 else if(!pObject->InheritsFrom(TCollection::Class())){
00b66af8 411 TClass *pClass = TClass::GetClass(pObject->ClassName());
412 if (pClass && pClass->GetListOfMethods()->FindObject("Clear")) {
413 AliDebug(1, Form("Clear for object %s class %s", pObject->GetName(), pObject->ClassName()));
414 pObject->Clear();
415 }
416 else {
417 AliDebug(1, Form("ResetWithPlacementNew for object %s class %s", pObject->GetName(), pObject->ClassName()));
418 ResetWithPlacementNew(pObject);
419 }
102c56c8 420 }
421 else{
65b25288 422 AliWarning(Form("No reset for %s \n",
102c56c8 423 pObject->ClassName()));
424 }
425 }
d7749dec 426 }
427
102c56c8 428}
429
430Bool_t AliESDEvent::ResetWithPlacementNew(TObject *pObject){
431 Long_t dtoronly = TObject::GetDtorOnly();
432 TClass *pClass = TClass::GetClass(pObject->ClassName());
433 TObject::SetDtorOnly(pObject);
434 delete pObject;
435 // Recreate with placement new
436 pClass->New(pObject);
437 // Restore the state.
438 TObject::SetDtorOnly((void*)dtoronly);
439 return kTRUE;
af885e0f 440}
441
442void AliESDEvent::ResetStdContent()
443{
444 // Reset the standard contents
445 if(fESDRun) fESDRun->Reset();
446 if(fHeader) fHeader->Reset();
93d96ff5 447 if(fCentrality) fCentrality->Reset();
448 if(fEventplane) fEventplane->Reset();
af885e0f 449 if(fESDZDC) fESDZDC->Reset();
0f0eb29c 450 if(fESDFMD) {
a2fbb067 451 fESDFMD->Clear();
0f0eb29c 452 }
6989bff3 453 if(fESDVZERO){
454 // reset by callin d'to /c'tor keep the pointer
455 fESDVZERO->~AliESDVZERO();
456 new (fESDVZERO) AliESDVZERO();
457 }
bd95bae7 458 if(fESDACORDE){
459 fESDACORDE->~AliESDACORDE();
460 new (fESDACORDE) AliESDACORDE();
461 }
af885e0f 462 if(fESDTZERO) fESDTZERO->Reset();
463 // CKB no clear/reset implemented
06cc9d95 464 if(fTPCVertex){
465 fTPCVertex->~AliESDVertex();
466 new (fTPCVertex) AliESDVertex();
467 fTPCVertex->SetName(fgkESDListName[kTPCVertex]);
468 }
af885e0f 469 if(fSPDVertex){
316c6cd9 470 fSPDVertex->~AliESDVertex();
af885e0f 471 new (fSPDVertex) AliESDVertex();
6989bff3 472 fSPDVertex->SetName(fgkESDListName[kSPDVertex]);
af885e0f 473 }
474 if(fPrimaryVertex){
316c6cd9 475 fPrimaryVertex->~AliESDVertex();
af885e0f 476 new (fPrimaryVertex) AliESDVertex();
6989bff3 477 fPrimaryVertex->SetName(fgkESDListName[kPrimaryVertex]);
af885e0f 478 }
316c6cd9 479 if(fSPDMult){
480 fSPDMult->~AliMultiplicity();
481 new (fSPDMult) AliMultiplicity();
482 }
f858b00e 483 if(fTOFHeader){
484 fTOFHeader->~AliTOFHeader();
485 new (fTOFHeader) AliTOFHeader();
486 //fTOFHeader->SetName(fgkESDListName[kTOFHeader]);
487 }
6c8e0967 488 if (fTrdTrigger) {
489 fTrdTrigger->~AliESDTrdTrigger();
490 new (fTrdTrigger) AliESDTrdTrigger();
491 }
820b4d9e 492 #ifdef MFT_UPGRADE
493 //if(fESDMFT){
494// fESDMFT->~AliESDMFT();
495// new (fESDMFT) AliESDMFT();
496 // }
497 #endif
498
042d5330 499 if(fPHOSTrigger)fPHOSTrigger->DeAllocate();
500 if(fEMCALTrigger)fEMCALTrigger->DeAllocate();
04d01397 501 if(fSPDPileupVertices)fSPDPileupVertices->Delete();
502 if(fTrkPileupVertices)fTrkPileupVertices->Delete();
ddfbc51a 503 if(fTracks)fTracks->Delete();
6989bff3 504 if(fMuonTracks)fMuonTracks->Delete();
505 if(fPmdTracks)fPmdTracks->Delete();
506 if(fTrdTracks)fTrdTracks->Delete();
52cd0cc0 507 if(fTrdTracklets)fTrdTracklets->Delete();
ddfbc51a 508 if(fV0s)fV0s->Delete();
509 if(fCascades)fCascades->Delete();
510 if(fKinks)fKinks->Delete();
bc9a7b42 511 if(fCaloClusters)fCaloClusters->Delete();
e649177a 512 if(fPHOSCells)fPHOSCells->DeleteContainer();
513 if(fEMCALCells)fEMCALCells->DeleteContainer();
8e1324ab 514 if(fCosmicTracks)fCosmicTracks->Delete();
16167d49 515 if(fErrorLogs) fErrorLogs->Delete();
af885e0f 516
d7749dec 517 // don't reset fconnected fConnected and the list
60e8f114 518
af885e0f 519}
520
521
522Int_t AliESDEvent::AddV0(const AliESDv0 *v) {
523 //
524 // Add V0
525 //
526 TClonesArray &fv = *fV0s;
527 Int_t idx=fV0s->GetEntriesFast();
528 new(fv[idx]) AliESDv0(*v);
529 return idx;
530}
531
532//______________________________________________________________________________
533void AliESDEvent::Print(Option_t *) const
534{
535 //
536 // Print header information of the event
537 //
538 printf("ESD run information\n");
539 printf("Event # in file %d Bunch crossing # %d Orbit # %d Period # %d Run # %d Trigger %lld Magnetic field %f \n",
540 GetEventNumberInFile(),
541 GetBunchCrossNumber(),
542 GetOrbitNumber(),
543 GetPeriodNumber(),
544 GetRunNumber(),
545 GetTriggerMask(),
546 GetMagneticField() );
c017f53f 547 if (fPrimaryVertex)
548 printf("Vertex: (%.4f +- %.4f, %.4f +- %.4f, %.4f +- %.4f) cm\n",
af885e0f 549 fPrimaryVertex->GetXv(), fPrimaryVertex->GetXRes(),
550 fPrimaryVertex->GetYv(), fPrimaryVertex->GetYRes(),
551 fPrimaryVertex->GetZv(), fPrimaryVertex->GetZRes());
1c7554f9 552 printf("Mean vertex in RUN: X=%.4f Y=%.4f Z=%.4f cm\n",
553 GetDiamondX(),GetDiamondY(),GetDiamondZ());
c017f53f 554 if(fSPDMult)
af885e0f 555 printf("SPD Multiplicity. Number of tracklets %d \n",
556 fSPDMult->GetNumberOfTracklets());
04d01397 557 printf("Number of pileup primary vertices reconstructed with SPD %d\n",
c017f53f 558 GetNumberOfPileupVerticesSPD());
04d01397 559 printf("Number of pileup primary vertices reconstructed using the tracks %d\n",
c017f53f 560 GetNumberOfPileupVerticesTracks());
af885e0f 561 printf("Number of tracks: \n");
562 printf(" charged %d\n", GetNumberOfTracks());
563 printf(" muon %d\n", GetNumberOfMuonTracks());
564 printf(" pmd %d\n", GetNumberOfPmdTracks());
565 printf(" trd %d\n", GetNumberOfTrdTracks());
52cd0cc0 566 printf(" trd trkl %d\n", GetNumberOfTrdTracklets());
af885e0f 567 printf(" v0 %d\n", GetNumberOfV0s());
568 printf(" cascades %d\n", GetNumberOfCascades());
569 printf(" kinks %d\n", GetNumberOfKinks());
38f940fb 570 if(fPHOSCells)printf(" PHOSCells %d\n", fPHOSCells->GetNumberOfCells());
571 else printf(" PHOSCells not in the Event\n");
572 if(fEMCALCells)printf(" EMCALCells %d\n", fEMCALCells->GetNumberOfCells());
573 else printf(" EMCALCells not in the Event\n");
af885e0f 574 printf(" CaloClusters %d\n", GetNumberOfCaloClusters());
af885e0f 575 printf(" FMD %s\n", (fESDFMD ? "yes" : "no"));
576 printf(" VZERO %s\n", (fESDVZERO ? "yes" : "no"));
8e1324ab 577 if (fCosmicTracks) printf(" Cosmics %d\n", GetNumberOfCosmicTracks());
820b4d9e 578 #ifdef MFT_UPGRADE
579 //printf(" MFT %s\n", (fESDMFT ? "yes" : "no"));
580 #endif
581
582
8b12d288 583 TObject* pHLTDecision=GetHLTTriggerDecision();
584 printf("HLT trigger decision: %s\n", pHLTDecision?pHLTDecision->GetOption():"not available");
585 if (pHLTDecision) pHLTDecision->Print("compact");
024c7734 586
587 return;
af885e0f 588}
589
7d44c466 590void AliESDEvent::SetESDfriend(const AliESDfriend *ev) const {
af885e0f 591 //
592 // Attaches the complementary info to the ESD
593 //
594 if (!ev) return;
595
5300bdab 596 // to be sure that we set the tracks also
597 // in case of old esds
60e8f114 598 // if(fESDOld)CopyFromOldESD();
5300bdab 599
af885e0f 600 Int_t ntrk=ev->GetNumberOfTracks();
601
602 for (Int_t i=0; i<ntrk; i++) {
603 const AliESDfriendTrack *f=ev->GetTrack(i);
604 GetTrack(i)->SetFriendTrack(f);
605 }
606}
607
7d44c466 608Bool_t AliESDEvent::RemoveKink(Int_t rm) const {
a023d8d8 609 // ---------------------------------------------------------
610 // Remove a kink candidate and references to it from ESD,
611 // if this candidate does not come from a reconstructed decay
612 // Not yet implemented...
613 // ---------------------------------------------------------
614 Int_t last=GetNumberOfKinks()-1;
615 if ((rm<0)||(rm>last)) return kFALSE;
616
617 return kTRUE;
618}
619
7d44c466 620Bool_t AliESDEvent::RemoveV0(Int_t rm) const {
a023d8d8 621 // ---------------------------------------------------------
622 // Remove a V0 candidate and references to it from ESD,
623 // if this candidate does not come from a reconstructed decay
624 // ---------------------------------------------------------
625 Int_t last=GetNumberOfV0s()-1;
626 if ((rm<0)||(rm>last)) return kFALSE;
627
628 AliESDv0 *v0=GetV0(rm);
629 Int_t idxP=v0->GetPindex(), idxN=v0->GetNindex();
630
631 v0=GetV0(last);
632 Int_t lastIdxP=v0->GetPindex(), lastIdxN=v0->GetNindex();
633
634 Int_t used=0;
635
636 // Check if this V0 comes from a reconstructed decay
637 Int_t ncs=GetNumberOfCascades();
638 for (Int_t n=0; n<ncs; n++) {
639 AliESDcascade *cs=GetCascade(n);
640
641 Int_t csIdxP=cs->GetPindex();
642 Int_t csIdxN=cs->GetNindex();
643
644 if (idxP==csIdxP)
645 if (idxN==csIdxN) return kFALSE;
646
647 if (csIdxP==lastIdxP)
648 if (csIdxN==lastIdxN) used++;
649 }
650
651 //Replace the removed V0 with the last V0
652 TClonesArray &a=*fV0s;
653 delete a.RemoveAt(rm);
654
655 if (rm==last) return kTRUE;
656
657 //v0 is pointing to the last V0 candidate...
658 new (a[rm]) AliESDv0(*v0);
659 delete a.RemoveAt(last);
660
661 if (!used) return kTRUE;
662
663
664 // Remap the indices of the daughters of reconstructed decays
665 for (Int_t n=0; n<ncs; n++) {
666 AliESDcascade *cs=GetCascade(n);
667
668
669 Int_t csIdxP=cs->GetPindex();
670 Int_t csIdxN=cs->GetNindex();
671
672 if (csIdxP==lastIdxP)
673 if (csIdxN==lastIdxN) {
674 cs->AliESDv0::SetIndex(1,idxP);
675 cs->AliESDv0::SetIndex(0,idxN);
676 used--;
677 if (!used) return kTRUE;
678 }
679 }
680
681 return kTRUE;
682}
683
7d44c466 684Bool_t AliESDEvent::RemoveTrack(Int_t rm) const {
d64bd07d 685 // ---------------------------------------------------------
7f68891d 686 // Remove a track and references to it from ESD,
687 // if this track does not come from a reconstructed decay
d64bd07d 688 // ---------------------------------------------------------
7f68891d 689 Int_t last=GetNumberOfTracks()-1;
690 if ((rm<0)||(rm>last)) return kFALSE;
691
692 Int_t used=0;
d64bd07d 693
6fca035d 694 // Check if this track comes from the reconstructed primary vertices
695 if (fTPCVertex && fTPCVertex->GetStatus()) {
696 UShort_t *primIdx=fTPCVertex->GetIndices();
697 Int_t n=fTPCVertex->GetNIndices();
698 while (n--) {
699 Int_t idx=Int_t(primIdx[n]);
700 if (rm==idx) return kFALSE;
701 if (idx==last) used++;
702 }
703 }
704 if (fPrimaryVertex && fPrimaryVertex->GetStatus()) {
705 UShort_t *primIdx=fPrimaryVertex->GetIndices();
706 Int_t n=fPrimaryVertex->GetNIndices();
707 while (n--) {
708 Int_t idx=Int_t(primIdx[n]);
709 if (rm==idx) return kFALSE;
710 if (idx==last) used++;
711 }
712 }
713
d64bd07d 714 // Check if this track comes from a reconstructed decay
7f68891d 715 Int_t nv0=GetNumberOfV0s();
716 for (Int_t n=0; n<nv0; n++) {
717 AliESDv0 *v0=GetV0(n);
718
719 Int_t idx=v0->GetNindex();
720 if (rm==idx) return kFALSE;
721 if (idx==last) used++;
722
723 idx=v0->GetPindex();
724 if (rm==idx) return kFALSE;
725 if (idx==last) used++;
726 }
727
728 Int_t ncs=GetNumberOfCascades();
729 for (Int_t n=0; n<ncs; n++) {
730 AliESDcascade *cs=GetCascade(n);
d64bd07d 731
7f68891d 732 Int_t idx=cs->GetIndex();
733 if (rm==idx) return kFALSE;
734 if (idx==last) used++;
fdbe4208 735
736 AliESDv0 *v0=cs;
737 idx=v0->GetNindex();
738 if (rm==idx) return kFALSE;
739 if (idx==last) used++;
740
741 idx=v0->GetPindex();
742 if (rm==idx) return kFALSE;
743 if (idx==last) used++;
7f68891d 744 }
745
746 Int_t nkn=GetNumberOfKinks();
747 for (Int_t n=0; n<nkn; n++) {
748 AliESDkink *kn=GetKink(n);
749
750 Int_t idx=kn->GetIndex(0);
751 if (rm==idx) return kFALSE;
752 if (idx==last) used++;
753
754 idx=kn->GetIndex(1);
755 if (rm==idx) return kFALSE;
756 if (idx==last) used++;
757 }
d64bd07d 758
8303b114 759 // Check if this track is associated with a CaloCluster
760 Int_t ncl=GetNumberOfCaloClusters();
761 for (Int_t n=0; n<ncl; n++) {
762 AliESDCaloCluster *cluster=GetCaloCluster(n);
763 TArrayI *arr=cluster->GetTracksMatched();
764 Int_t s=arr->GetSize();
765 while (s--) {
766 Int_t idx=arr->At(s);
767 if (rm==idx) return kFALSE;
768 if (idx==last) used++;
769 }
770 }
771
ddfbc51a 772
773
774 //Replace the removed track with the last track
7f68891d 775 TClonesArray &a=*fTracks;
776 delete a.RemoveAt(rm);
777
778 if (rm==last) return kTRUE;
779
780 AliESDtrack *t=GetTrack(last);
781 t->SetID(rm);
ddfbc51a 782 new (a[rm]) AliESDtrack(*t);
7f68891d 783 delete a.RemoveAt(last);
784
6fca035d 785
7f68891d 786 if (!used) return kTRUE;
787
788
6fca035d 789 // Remap the indices of the tracks used for the primary vertex reconstruction
790 if (fTPCVertex && fTPCVertex->GetStatus()) {
791 UShort_t *primIdx=fTPCVertex->GetIndices();
792 Int_t n=fTPCVertex->GetNIndices();
793 while (n--) {
794 Int_t idx=Int_t(primIdx[n]);
795 if (idx==last) {
796 primIdx[n]=Short_t(rm);
797 used--;
798 if (!used) return kTRUE;
799 }
800 }
801 }
802 if (fPrimaryVertex && fPrimaryVertex->GetStatus()) {
803 UShort_t *primIdx=fPrimaryVertex->GetIndices();
804 Int_t n=fPrimaryVertex->GetNIndices();
805 while (n--) {
806 Int_t idx=Int_t(primIdx[n]);
807 if (idx==last) {
808 primIdx[n]=Short_t(rm);
809 used--;
810 if (!used) return kTRUE;
811 }
812 }
813 }
814
7f68891d 815 // Remap the indices of the daughters of reconstructed decays
816 for (Int_t n=0; n<nv0; n++) {
817 AliESDv0 *v0=GetV0(n);
818 if (v0->GetIndex(0)==last) {
819 v0->SetIndex(0,rm);
820 used--;
821 if (!used) return kTRUE;
822 }
823 if (v0->GetIndex(1)==last) {
824 v0->SetIndex(1,rm);
825 used--;
826 if (!used) return kTRUE;
827 }
828 }
829
830 for (Int_t n=0; n<ncs; n++) {
831 AliESDcascade *cs=GetCascade(n);
832 if (cs->GetIndex()==last) {
833 cs->SetIndex(rm);
834 used--;
835 if (!used) return kTRUE;
836 }
fdbe4208 837 AliESDv0 *v0=cs;
838 if (v0->GetIndex(0)==last) {
839 v0->SetIndex(0,rm);
840 used--;
841 if (!used) return kTRUE;
842 }
843 if (v0->GetIndex(1)==last) {
844 v0->SetIndex(1,rm);
845 used--;
846 if (!used) return kTRUE;
847 }
7f68891d 848 }
849
850 for (Int_t n=0; n<nkn; n++) {
851 AliESDkink *kn=GetKink(n);
852 if (kn->GetIndex(0)==last) {
853 kn->SetIndex(rm,0);
854 used--;
855 if (!used) return kTRUE;
856 }
857 if (kn->GetIndex(1)==last) {
858 kn->SetIndex(rm,1);
859 used--;
860 if (!used) return kTRUE;
861 }
862 }
d64bd07d 863
8303b114 864 // Remap the indices of the tracks accosicated with CaloClusters
865 for (Int_t n=0; n<ncl; n++) {
866 AliESDCaloCluster *cluster=GetCaloCluster(n);
867 TArrayI *arr=cluster->GetTracksMatched();
868 Int_t s=arr->GetSize();
869 while (s--) {
870 Int_t idx=arr->At(s);
871 if (idx==last) {
872 arr->AddAt(rm,s);
873 used--;
874 if (!used) return kTRUE;
875 }
876 }
877 }
878
d64bd07d 879 return kTRUE;
880}
881
882
7f68891d 883Bool_t AliESDEvent::Clean(Float_t *cleanPars) {
884 //
885 // Remove the data which are not needed for the physics analysis.
886 //
a023d8d8 887 // 1) Cleaning the V0 candidates
888 // ---------------------------
889 // If the cosine of the V0 pointing angle "csp" and
890 // the DCA between the daughter tracks "dca" does not satisfy
891 // the conditions
892 //
893 // csp > cleanPars[1] + dca/cleanPars[0]*(1.- cleanPars[1])
894 //
895 // an attempt to remove this V0 candidate from ESD is made.
896 //
897 // The V0 candidate gets removed if it does not belong to any
898 // recosntructed cascade decay
899 //
900 // 12.11.2007, optimal values: cleanPars[0]=0.5, cleanPars[1]=0.999
901 //
902 // 2) Cleaning the tracks
903 // ----------------------
904 // If track's transverse parameter is larger than cleanPars[2]
7f68891d 905 // OR
a023d8d8 906 // track's longitudinal parameter is larger than cleanPars[3]
907 // an attempt to remove this track from ESD is made.
7f68891d 908 //
a023d8d8 909 // The track gets removed if it does not come
910 // from a reconstructed decay
7f68891d 911 //
a023d8d8 912 Bool_t rc=kFALSE;
913
914 Float_t dcaMax=cleanPars[0];
915 Float_t cspMin=cleanPars[1];
916
917 Int_t nV0s=GetNumberOfV0s();
918 for (Int_t i=nV0s-1; i>=0; i--) {
919 AliESDv0 *v0=GetV0(i);
920
921 Float_t dca=v0->GetDcaV0Daughters();
922 Float_t csp=v0->GetV0CosineOfPointingAngle();
923 Float_t cspcut=cspMin + dca/dcaMax*(1.-cspMin);
449e752b 924 if (csp > cspcut) continue;
925 if (RemoveV0(i)) rc=kTRUE;
a023d8d8 926 }
927
7f68891d 928
a023d8d8 929 Float_t dmax=cleanPars[2], zmax=cleanPars[3];
7f68891d 930
06cc9d95 931 const AliESDVertex *vertex=GetPrimaryVertexSPD();
a023d8d8 932 Bool_t vtxOK=vertex->GetStatus();
7f68891d 933
934 Int_t nTracks=GetNumberOfTracks();
935 for (Int_t i=nTracks-1; i>=0; i--) {
936 AliESDtrack *track=GetTrack(i);
937 Float_t xy,z; track->GetImpactParameters(xy,z);
938 if ((TMath::Abs(xy) > dmax) || (vtxOK && (TMath::Abs(z) > zmax))) {
939 if (RemoveTrack(i)) rc=kTRUE;
940 }
941 }
942
943 return rc;
944}
945
6dc21f57 946Char_t AliESDEvent::AddPileupVertexSPD(const AliESDVertex *vtx)
04d01397 947{
948 // Add a pileup primary vertex reconstructed with SPD
949 TClonesArray &ftr = *fSPDPileupVertices;
6dc21f57 950 Char_t n=Char_t(ftr.GetEntriesFast());
951 AliESDVertex *vertex = new(ftr[n]) AliESDVertex(*vtx);
952 vertex->SetID(n);
953 return n;
04d01397 954}
955
6dc21f57 956Char_t AliESDEvent::AddPileupVertexTracks(const AliESDVertex *vtx)
04d01397 957{
958 // Add a pileup primary vertex reconstructed with SPD
959 TClonesArray &ftr = *fTrkPileupVertices;
6dc21f57 960 Char_t n=Char_t(ftr.GetEntriesFast());
961 AliESDVertex *vertex = new(ftr[n]) AliESDVertex(*vtx);
962 vertex->SetID(n);
963 return n;
04d01397 964}
965
6989bff3 966Int_t AliESDEvent::AddTrack(const AliESDtrack *t)
967{
af885e0f 968 // Add track
969 TClonesArray &ftr = *fTracks;
970 AliESDtrack * track = new(ftr[fTracks->GetEntriesFast()])AliESDtrack(*t);
971 track->SetID(fTracks->GetEntriesFast()-1);
972 return track->GetID();
973}
974
65a0cf79 975AliESDtrack* AliESDEvent::NewTrack()
976{
977 // Add a new track
978 TClonesArray &ftr = *fTracks;
979 AliESDtrack * track = new(ftr[fTracks->GetEntriesFast()])AliESDtrack();
980 track->SetID(fTracks->GetEntriesFast()-1);
981 return track;
982}
983
6989bff3 984 void AliESDEvent::AddMuonTrack(const AliESDMuonTrack *t)
985{
f0106218 986 TClonesArray &fmu = *fMuonTracks;
987 new(fmu[fMuonTracks->GetEntriesFast()]) AliESDMuonTrack(*t);
988}
989
6989bff3 990void AliESDEvent::AddPmdTrack(const AliESDPmdTrack *t)
991{
f0106218 992 TClonesArray &fpmd = *fPmdTracks;
993 new(fpmd[fPmdTracks->GetEntriesFast()]) AliESDPmdTrack(*t);
994}
995
6c8e0967 996void AliESDEvent::SetTrdTrigger(const AliESDTrdTrigger *t)
997{
998 *fTrdTrigger = *t;
999}
1000
6989bff3 1001void AliESDEvent::AddTrdTrack(const AliESDTrdTrack *t)
1002{
f0106218 1003 TClonesArray &ftrd = *fTrdTracks;
1004 new(ftrd[fTrdTracks->GetEntriesFast()]) AliESDTrdTrack(*t);
1005}
1006
52cd0cc0 1007void AliESDEvent::AddTrdTracklet(const AliESDTrdTracklet *trkl)
1008{
1009 new ((*fTrdTracklets)[fTrdTracklets->GetEntriesFast()]) AliESDTrdTracklet(*trkl);
1010}
f0106218 1011
6989bff3 1012Int_t AliESDEvent::AddKink(const AliESDkink *c)
1013{
af885e0f 1014 // Add kink
1015 TClonesArray &fk = *fKinks;
1016 AliESDkink * kink = new(fk[fKinks->GetEntriesFast()]) AliESDkink(*c);
1017 kink->SetID(fKinks->GetEntriesFast()); // CKB different from the other imps..
1018 return fKinks->GetEntriesFast()-1;
1019}
1020
f0106218 1021
6989bff3 1022void AliESDEvent::AddCascade(const AliESDcascade *c)
1023{
f0106218 1024 TClonesArray &fc = *fCascades;
1025 new(fc[fCascades->GetEntriesFast()]) AliESDcascade(*c);
1026}
1027
8e1324ab 1028void AliESDEvent::AddCosmicTrack(const AliESDCosmicTrack *t)
1029{
1030 TClonesArray &ft = *fCosmicTracks;
1031 new(ft[fCosmicTracks->GetEntriesFast()]) AliESDCosmicTrack(*t);
1032}
1033
f0106218 1034
6989bff3 1035Int_t AliESDEvent::AddCaloCluster(const AliESDCaloCluster *c)
1036{
af885e0f 1037 // Add calocluster
1038 TClonesArray &fc = *fCaloClusters;
1039 AliESDCaloCluster *clus = new(fc[fCaloClusters->GetEntriesFast()]) AliESDCaloCluster(*c);
1040 clus->SetID(fCaloClusters->GetEntriesFast()-1);
1041 return fCaloClusters->GetEntriesFast()-1;
1042 }
1043
1044
7d44c466 1045void AliESDEvent::AddRawDataErrorLog(const AliRawDataErrorLog *log) const {
6989bff3 1046 TClonesArray &errlogs = *fErrorLogs;
1047 new(errlogs[errlogs.GetEntriesFast()]) AliRawDataErrorLog(*log);
1048}
f0106218 1049
af6f24c9 1050void AliESDEvent::SetZDCData(AliESDZDC * obj)
1051{
1052 // use already allocated space
1053 if(fESDZDC)
1054 *fESDZDC = *obj;
1055}
1056
06cc9d95 1057void AliESDEvent::SetPrimaryVertexTPC(const AliESDVertex *vertex)
1058{
1059 // Set the TPC vertex
1060 // use already allocated space
1061 if(fTPCVertex){
1062 *fTPCVertex = *vertex;
1063 fTPCVertex->SetName(fgkESDListName[kTPCVertex]);
1064 }
1065}
1066
1067void AliESDEvent::SetPrimaryVertexSPD(const AliESDVertex *vertex)
6989bff3 1068{
1069 // Set the SPD vertex
60e8f114 1070 // use already allocated space
1071 if(fSPDVertex){
316c6cd9 1072 *fSPDVertex = *vertex;
6989bff3 1073 fSPDVertex->SetName(fgkESDListName[kSPDVertex]);
60e8f114 1074 }
1075}
1076
c264b61b 1077void AliESDEvent::SetPrimaryVertexTracks(const AliESDVertex *vertex)
6989bff3 1078{
c264b61b 1079 // Set the primary vertex reconstructed using he ESD tracks.
6989bff3 1080 // use already allocated space
60e8f114 1081 if(fPrimaryVertex){
316c6cd9 1082 *fPrimaryVertex = *vertex;
6989bff3 1083 fPrimaryVertex->SetName(fgkESDListName[kPrimaryVertex]);
60e8f114 1084 }
1085}
1086
c264b61b 1087const AliESDVertex * AliESDEvent::GetPrimaryVertex() const
1088{
1089 //
1090 // Get the "best" available reconstructed primary vertex.
1091 //
1092 if(fPrimaryVertex){
1093 if (fPrimaryVertex->GetStatus()) return fPrimaryVertex;
1094 }
1095 if(fSPDVertex){
1096 if (fSPDVertex->GetStatus()) return fSPDVertex;
1097 }
1098 if(fTPCVertex) return fTPCVertex;
1099
1100 AliWarning("No primary vertex available. Returning the \"default\"...");
1101 return fSPDVertex;
1102}
1103
518573d7 1104AliESDVertex * AliESDEvent::PrimaryVertexTracksUnconstrained() const
1105{
1106 //
1107 // Removes diamond constraint from fPrimaryVertex (reconstructed with tracks)
1108 // Returns a AliESDVertex which has to be deleted by the user
1109 //
1110 if(!fPrimaryVertex) {
1111 AliWarning("No primary vertex from tracks available.");
1112 return 0;
1113 }
1114 if(!fPrimaryVertex->GetStatus()) {
1115 AliWarning("No primary vertex from tracks available.");
1116 return 0;
1117 }
1118
1119 AliVertexerTracks vertexer(GetMagneticField());
1120 Float_t diamondxyz[3]={(Float_t)GetDiamondX(),(Float_t)GetDiamondY(),0.};
1121 Float_t diamondcovxy[3]; GetDiamondCovXY(diamondcovxy);
1122 Float_t diamondcov[6]={diamondcovxy[0],diamondcovxy[1],diamondcovxy[2],0.,0.,7.};
1123 AliESDVertex *vertex =
1124 (AliESDVertex*)vertexer.RemoveConstraintFromVertex(fPrimaryVertex,diamondxyz,diamondcov);
1125
1126 return vertex;
1127}
1128
6989bff3 1129void AliESDEvent::SetMultiplicity(const AliMultiplicity *mul)
1130{
1131 // Set the SPD Multiplicity
f0106218 1132 if(fSPDMult){
316c6cd9 1133 *fSPDMult = *mul;
f0106218 1134 }
1135}
1136
1137
6989bff3 1138void AliESDEvent::SetFMDData(AliESDFMD * obj)
1139{
af885e0f 1140 // use already allocated space
1141 if(fESDFMD){
316c6cd9 1142 *fESDFMD = *obj;
af885e0f 1143 }
1144}
1145
6989bff3 1146void AliESDEvent::SetVZEROData(AliESDVZERO * obj)
1147{
af885e0f 1148 // use already allocated space
1149 if(fESDVZERO)
6989bff3 1150 *fESDVZERO = *obj;
af885e0f 1151}
1152
b0e13b29 1153void AliESDEvent::SetTZEROData(AliESDTZERO * obj)
1154{
1155 // use already allocated space
1156 if(fESDTZERO)
1157 *fESDTZERO = *obj;
1158}
1159
820b4d9e 1160#ifdef MFT_UPGRADE
1161//void AliESDEvent::SetMFTData(AliESDMFT * obj)
1162//{
1163// if(fESDMFT)
1164// *fESDMFT = *obj;
1165//}
1166#endif
1167
bd95bae7 1168void AliESDEvent::SetACORDEData(AliESDACORDE * obj)
1169{
1170 if(fESDACORDE)
1171 *fESDACORDE = *obj;
1172}
1173
1174
6989bff3 1175void AliESDEvent::GetESDfriend(AliESDfriend *ev) const
1176{
af885e0f 1177 //
1178 // Extracts the complementary info from the ESD
1179 //
1180 if (!ev) return;
1181
1182 Int_t ntrk=GetNumberOfTracks();
1183
1184 for (Int_t i=0; i<ntrk; i++) {
80799a5f 1185 AliESDtrack *t=GetTrack(i);
ddfbc51a 1186 const AliESDfriendTrack *f=t->GetFriendTrack();
1187 ev->AddTrack(f);
1188
1189 t->ReleaseESDfriendTrack();// Not to have two copies of "friendTrack"
1190
af885e0f 1191 }
af885e0f 1192
b090e6a3 1193 AliESDfriend *fr = (AliESDfriend*)(const_cast<AliESDEvent*>(this)->FindListObject("AliESDfriend"));
1194 if (fr) ev->SetVZEROfriend(fr->GetVZEROfriend());
1195}
af885e0f 1196
1197void AliESDEvent::AddObject(TObject* obj)
1198{
1199 // Add an object to the list of object.
1200 // Please be aware that in order to increase performance you should
1201 // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
1202 fESDObjects->SetOwner(kTRUE);
1203 fESDObjects->AddLast(obj);
1204}
1205
1206
1207void AliESDEvent::GetStdContent()
1208{
1209 // set pointers for standard content
60e8f114 1210 // get by name much safer and not a big overhead since not called very often
1211
6989bff3 1212 fESDRun = (AliESDRun*)fESDObjects->FindObject(fgkESDListName[kESDRun]);
1213 fHeader = (AliESDHeader*)fESDObjects->FindObject(fgkESDListName[kHeader]);
1214 fESDZDC = (AliESDZDC*)fESDObjects->FindObject(fgkESDListName[kESDZDC]);
1215 fESDFMD = (AliESDFMD*)fESDObjects->FindObject(fgkESDListName[kESDFMD]);
1216 fESDVZERO = (AliESDVZERO*)fESDObjects->FindObject(fgkESDListName[kESDVZERO]);
1217 fESDTZERO = (AliESDTZERO*)fESDObjects->FindObject(fgkESDListName[kESDTZERO]);
06cc9d95 1218 fTPCVertex = (AliESDVertex*)fESDObjects->FindObject(fgkESDListName[kTPCVertex]);
6989bff3 1219 fSPDVertex = (AliESDVertex*)fESDObjects->FindObject(fgkESDListName[kSPDVertex]);
1220 fPrimaryVertex = (AliESDVertex*)fESDObjects->FindObject(fgkESDListName[kPrimaryVertex]);
1221 fSPDMult = (AliMultiplicity*)fESDObjects->FindObject(fgkESDListName[kSPDMult]);
1222 fPHOSTrigger = (AliESDCaloTrigger*)fESDObjects->FindObject(fgkESDListName[kPHOSTrigger]);
1223 fEMCALTrigger = (AliESDCaloTrigger*)fESDObjects->FindObject(fgkESDListName[kEMCALTrigger]);
04d01397 1224 fSPDPileupVertices = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kSPDPileupVertices]);
1225 fTrkPileupVertices = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTrkPileupVertices]);
6989bff3 1226 fTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTracks]);
1227 fMuonTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kMuonTracks]);
1228 fPmdTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kPmdTracks]);
6c8e0967 1229 fTrdTrigger = (AliESDTrdTrigger*)fESDObjects->FindObject(fgkESDListName[kTrdTrigger]);
6989bff3 1230 fTrdTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTrdTracks]);
52cd0cc0 1231 fTrdTracklets = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTrdTracklets]);
6989bff3 1232 fV0s = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kV0s]);
1233 fCascades = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kCascades]);
1234 fKinks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kKinks]);
1235 fCaloClusters = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kCaloClusters]);
e649177a 1236 fEMCALCells = (AliESDCaloCells*)fESDObjects->FindObject(fgkESDListName[kEMCALCells]);
1237 fPHOSCells = (AliESDCaloCells*)fESDObjects->FindObject(fgkESDListName[kPHOSCells]);
6989bff3 1238 fErrorLogs = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kErrorLogs]);
bd95bae7 1239 fESDACORDE = (AliESDACORDE*)fESDObjects->FindObject(fgkESDListName[kESDACORDE]);
f858b00e 1240 fTOFHeader = (AliTOFHeader*)fESDObjects->FindObject(fgkESDListName[kTOFHeader]);
8e1324ab 1241 fCosmicTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kCosmicTracks]);
820b4d9e 1242 #ifdef MFT_UPGRADE
1243 // fESDMFT = (AliESDMFT*)fESDObjects->FindObject(fgkESDListName[kESDMFT]);
1244 #endif
af885e0f 1245}
1246
1247void AliESDEvent::SetStdNames(){
1248 // Set the names of the standard contents
60e8f114 1249 //
102c56c8 1250 if(fESDObjects->GetEntries()>=kESDListN){
1251 for(int i = 0;i < fESDObjects->GetEntries() && i<kESDListN;i++){
60e8f114 1252 TObject *fObj = fESDObjects->At(i);
1253 if(fObj->InheritsFrom("TNamed")){
6989bff3 1254 ((TNamed*)fObj)->SetName(fgkESDListName[i]);
60e8f114 1255 }
1256 else if(fObj->InheritsFrom("TClonesArray")){
6989bff3 1257 ((TClonesArray*)fObj)->SetName(fgkESDListName[i]);
60e8f114 1258 }
1259 }
1260 }
1261 else{
90e88950 1262 AliWarning("Std Entries missing");
60e8f114 1263 }
af885e0f 1264}
1265
a2fbb067 1266
1267void AliESDEvent::CreateStdContent(Bool_t bUseThisList){
1268 fUseOwnList = bUseThisList;
1269 CreateStdContent();
1270}
1271
af885e0f 1272void AliESDEvent::CreateStdContent()
1273{
1274 // create the standard AOD content and set pointers
1275
1276 // create standard objects and add them to the TList of objects
1277 AddObject(new AliESDRun());
1278 AddObject(new AliESDHeader());
1279 AddObject(new AliESDZDC());
1280 AddObject(new AliESDFMD());
1281 AddObject(new AliESDVZERO());
1282 AddObject(new AliESDTZERO());
1283 AddObject(new AliESDVertex());
1284 AddObject(new AliESDVertex());
06cc9d95 1285 AddObject(new AliESDVertex());
af885e0f 1286 AddObject(new AliMultiplicity());
1287 AddObject(new AliESDCaloTrigger());
1288 AddObject(new AliESDCaloTrigger());
04d01397 1289 AddObject(new TClonesArray("AliESDVertex",0));
1290 AddObject(new TClonesArray("AliESDVertex",0));
af885e0f 1291 AddObject(new TClonesArray("AliESDtrack",0));
1292 AddObject(new TClonesArray("AliESDMuonTrack",0));
1293 AddObject(new TClonesArray("AliESDPmdTrack",0));
6c8e0967 1294 AddObject(new AliESDTrdTrigger());
af885e0f 1295 AddObject(new TClonesArray("AliESDTrdTrack",0));
52cd0cc0 1296 AddObject(new TClonesArray("AliESDTrdTracklet",0));
af885e0f 1297 AddObject(new TClonesArray("AliESDv0",0));
1298 AddObject(new TClonesArray("AliESDcascade",0));
1299 AddObject(new TClonesArray("AliESDkink",0));
1300 AddObject(new TClonesArray("AliESDCaloCluster",0));
e649177a 1301 AddObject(new AliESDCaloCells());
1302 AddObject(new AliESDCaloCells());
af885e0f 1303 AddObject(new TClonesArray("AliRawDataErrorLog",0));
bd95bae7 1304 AddObject(new AliESDACORDE());
f858b00e 1305 AddObject(new AliTOFHeader());
8e1324ab 1306 AddObject(new TClonesArray("AliESDCosmicTrack",0));
820b4d9e 1307 #ifdef MFT_UPGRADE
1308 //AddObject(new AliESDMFT());
1309 #endif
1310
af885e0f 1311 // check the order of the indices against enum...
1312
af885e0f 1313 // set names
1314 SetStdNames();
60e8f114 1315 // read back pointers
1316 GetStdContent();
af885e0f 1317}
1318
2811495d 1319TObject* AliESDEvent::FindListObject(const char *name) const {
7d44c466 1320//
1321// Find object with name "name" in the list of branches
1322//
d7749dec 1323 if(fESDObjects){
1324 return fESDObjects->FindObject(name);
1325 }
001b9beb 1326 return 0;
1327}
1328
cd1d4ee0 1329Int_t AliESDEvent::GetPHOSClusters(TRefArray *clusters) const
1330{
1331 // fills the provided TRefArray with all found phos clusters
e649177a 1332
cd1d4ee0 1333 clusters->Clear();
e649177a 1334
cd1d4ee0 1335 AliESDCaloCluster *cl = 0;
1336 for (Int_t i = 0; i < GetNumberOfCaloClusters(); i++) {
e649177a 1337
1338 if ( (cl = GetCaloCluster(i)) ) {
cd1d4ee0 1339 if (cl->IsPHOS()){
1340 clusters->Add(cl);
e649177a 1341 AliDebug(1,Form("IsPHOS cluster %d Size: %d \n",i,clusters->GetEntriesFast()));
cd1d4ee0 1342 }
1343 }
1344 }
1345 return clusters->GetEntriesFast();
1346}
1347
1348Int_t AliESDEvent::GetEMCALClusters(TRefArray *clusters) const
1349{
e649177a 1350 // fills the provided TRefArray with all found emcal clusters
cd1d4ee0 1351
1352 clusters->Clear();
1353
1354 AliESDCaloCluster *cl = 0;
1355 for (Int_t i = 0; i < GetNumberOfCaloClusters(); i++) {
1356
e649177a 1357 if ( (cl = GetCaloCluster(i)) ) {
cd1d4ee0 1358 if (cl->IsEMCAL()){
1359 clusters->Add(cl);
e649177a 1360 AliDebug(1,Form("IsEMCAL cluster %d Size: %d \n",i,clusters->GetEntriesFast()));
cd1d4ee0 1361 }
1362 }
1363 }
1364 return clusters->GetEntriesFast();
1365}
1366
f12d42ce 1367void AliESDEvent::WriteToTree(TTree* tree) const {
38f940fb 1368 // Book the branches as in TTree::Branch(TCollection*)
1369 // but add a "." at the end of top level branches which are
1370 // not a TClonesArray
1371
1372
1373 TString branchname;
1374 TIter next(fESDObjects);
7d44c466 1375 const Int_t kSplitlevel = 99; // default value in TTree::Branch()
ddfbc51a 1376 const Int_t kBufsize = 32000; // default value in TTree::Branch()
38f940fb 1377 TObject *obj = 0;
1378
1379 while ((obj = next())) {
1380 branchname.Form("%s", obj->GetName());
32ba9c61 1381 if(branchname.CompareTo("AliESDfriend")==0)branchname = "ESDfriend.";
7d44c466 1382 if ((kSplitlevel > 1) && !obj->InheritsFrom(TClonesArray::Class())) {
732a24fe 1383 if(!branchname.EndsWith("."))branchname += ".";
38f940fb 1384 }
102c56c8 1385 if (!tree->FindBranch(branchname)) {
771c4f86 1386 // For the custom streamer to be called splitlevel
1387 // has to be negative, only needed for HLT
1388 Int_t splitLevel = (TString(obj->ClassName()) == "AliHLTGlobalTriggerDecision") ? -1 : kSplitlevel - 1;
1389 tree->Bronch(branchname, obj->ClassName(), fESDObjects->GetObjectRef(obj),kBufsize, splitLevel);
102c56c8 1390 }
38f940fb 1391 }
38f940fb 1392}
1393
cd1d4ee0 1394
f7ec3414 1395void AliESDEvent::ReadFromTree(TTree *tree, Option_t* opt){
7d44c466 1396//
1397// Connect the ESDEvent to a tree
1398//
6989bff3 1399 if(!tree){
90e88950 1400 AliWarning("AliESDEvent::ReadFromTree() Zero Pointer to Tree \n");
6989bff3 1401 return;
1402 }
024c7734 1403 // load the TTree
6989bff3 1404 if(!tree->GetTree())tree->LoadTree(0);
024c7734 1405
001b9beb 1406 // if we find the "ESD" branch on the tree we do have the old structure
1bd10080 1407 if(tree->GetBranch("ESD")) {
1408 char ** address = (char **)(tree->GetBranch("ESD")->GetAddress());
0eb6eb59 1409 // do we have the friend branch
1410 TBranch * esdFB = tree->GetBranch("ESDfriend.");
1411 char ** addressF = 0;
1412 if(esdFB)addressF = (char **)(esdFB->GetAddress());
6989bff3 1413 if (!address) {
90e88950 1414 AliInfo("AliESDEvent::ReadFromTree() Reading old Tree");
1bd10080 1415 tree->SetBranchAddress("ESD", &fESDOld);
0eb6eb59 1416 if(esdFB){
1417 tree->SetBranchAddress("ESDfriend.",&fESDFriendOld);
1418 }
6989bff3 1419 } else {
90e88950 1420 AliInfo("AliESDEvent::ReadFromTree() Reading old Tree");
1421 AliInfo("Branch already connected. Using existing branch address.");
1bd10080 1422 fESDOld = (AliESD*) (*address);
0eb6eb59 1423 // addressF can still be 0, since branch needs to switched on
1424 if(addressF)fESDFriendOld = (AliESDfriend*) (*addressF);
6989bff3 1425 }
0eb6eb59 1426
6989bff3 1427 // have already connected the old ESD structure... ?
1428 // reuse also the pointer of the AlliESDEvent
1429 // otherwise create new ones
6989bff3 1430 TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("ESDObjectsConnectedToTree"));
1431
1432 if(connectedList){
1433 // If connected use the connected list of objects
0eb6eb59 1434 if(fESDObjects!= connectedList){
1435 // protect when called twice
1436 fESDObjects->Delete();
1437 fESDObjects = connectedList;
1438 }
6989bff3 1439 GetStdContent();
0eb6eb59 1440
0eb6eb59 1441
d7749dec 1442 // The pointer to the friend changes when called twice via InitIO
1443 // since AliESDEvent is deleted
0eb6eb59 1444 TObject* oldf = FindListObject("AliESDfriend");
1445 TObject* newf = 0;
1446 if(addressF){
1447 newf = (TObject*)*addressF;
1448 }
1449 if(newf!=0&&oldf!=newf){
1450 // remove the old reference
1451 // Should we also delete it? Or is this handled in TTree I/O
1452 // since it is created by the first SetBranchAddress
1453 fESDObjects->Remove(oldf);
1454 // add the new one
1455 fESDObjects->Add(newf);
1456 }
1457
6989bff3 1458 fConnected = true;
b93c2026 1459 return;
6989bff3 1460 }
1461 // else...
1462 CreateStdContent(); // create for copy
0eb6eb59 1463 // if we have the esdfriend add it, so we always can access it via the userinfo
1464 if(fESDFriendOld)AddObject(fESDFriendOld);
6989bff3 1465 // we are not owner of the list objects
1466 // must not delete it
efea3f54 1467 fESDObjects->SetOwner(kTRUE);
6989bff3 1468 fESDObjects->SetName("ESDObjectsConnectedToTree");
1469 tree->GetUserInfo()->Add(fESDObjects);
1470 fConnected = true;
1471 return;
af885e0f 1472 }
0eb6eb59 1473
732a24fe 1474
1475 delete fESDOld;
1476 fESDOld = 0;
af885e0f 1477 // Try to find AliESDEvent
1478 AliESDEvent *esdEvent = 0;
1479 esdEvent = (AliESDEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliESDEvent");
001b9beb 1480 if(esdEvent){
941603c0 1481 // Check if already connected to tree
efea3f54 1482 esdEvent->Reset();
139f2194 1483 TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("ESDObjectsConnectedToTree"));
f7ec3414 1484
1485
1486 if (connectedList && (strcmp(opt, "reconnect"))) {
139f2194 1487 // If connected use the connected list if objects
1488 fESDObjects->Delete();
b5bc83df 1489 fESDObjects = connectedList;
1490 GetStdContent();
60e8f114 1491 fConnected = true;
139f2194 1492 return;
1493 }
732a24fe 1494
139f2194 1495 // Connect to tree
001b9beb 1496 // prevent a memory leak when reading back the TList
28a79204 1497 // if (!(strcmp(opt, "reconnect"))) fESDObjects->Delete();
f7ec3414 1498
a2fbb067 1499 if(!fUseOwnList){
a2fbb067 1500 // create a new TList from the UserInfo TList...
1501 // copy constructor does not work...
1502 fESDObjects = (TList*)(esdEvent->GetList()->Clone());
efea3f54 1503 fESDObjects->SetOwner(kTRUE);
a2fbb067 1504 }
1505 else if ( fESDObjects->GetEntries()==0){
1506 // at least create the std content if we want to read to our list
1507 CreateStdContent();
1508 }
732a24fe 1509
1510 // in principle
1511 // we only need new things in the list if we do no already have it..
1512 // TODO just add new entries
1513
af885e0f 1514 if(fESDObjects->GetEntries()<kESDListN){
90e88950 1515 AliWarning(Form("AliESDEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
1516 fESDObjects->GetEntries(),kESDListN));
af885e0f 1517 }
1518 // set the branch addresses
1519 TIter next(fESDObjects);
1520 TNamed *el;
1521 while((el=(TNamed*)next())){
1522 TString bname(el->GetName());
af885e0f 1523 if(bname.CompareTo("AliESDfriend")==0)
1524 {
1525 // AliESDfriend does not have a name ...
4453d900 1526 TBranch *br = tree->GetBranch("ESDfriend.");
588195ca 1527 if (br) tree->SetBranchAddress("ESDfriend.",fESDObjects->GetObjectRef(el));
af885e0f 1528 }
1529 else{
38f940fb 1530 // check if branch exists under this Name
1531 TBranch *br = tree->GetBranch(bname.Data());
1532 if(br){
1533 tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
1534 }
1535 else{
1536 br = tree->GetBranch(Form("%s.",bname.Data()));
1537 if(br){
1538 tree->SetBranchAddress(Form("%s.",bname.Data()),fESDObjects->GetObjectRef(el));
1539 }
1540 else{
90e88950 1541 AliWarning(Form("AliESDEvent::ReadFromTree() No Branch found with Name %s or %s.",bname.Data(),bname.Data()));
38f940fb 1542 }
1543
1544 }
af885e0f 1545 }
1546 }
1547 GetStdContent();
1548 // when reading back we are not owner of the list
1549 // must not delete it
efea3f54 1550 fESDObjects->SetOwner(kTRUE);
60e8f114 1551 fESDObjects->SetName("ESDObjectsConnectedToTree");
139f2194 1552 // we are not owner of the list objects
1553 // must not delete it
60e8f114 1554 tree->GetUserInfo()->Add(fESDObjects);
efea3f54 1555 tree->GetUserInfo()->SetOwner(kFALSE);
60e8f114 1556 fConnected = true;
efea3f54 1557 }// no esdEvent -->
af885e0f 1558 else {
001b9beb 1559 // we can't get the list from the user data, create standard content
1560 // and set it by hand (no ESDfriend at the moment
af885e0f 1561 CreateStdContent();
1562 TIter next(fESDObjects);
1563 TNamed *el;
1564 while((el=(TNamed*)next())){
1565 TString bname(el->GetName());
732a24fe 1566 TBranch *br = tree->GetBranch(bname.Data());
1567 if(br){
1568 tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
1569 }
1570 else{
1571 br = tree->GetBranch(Form("%s.",bname.Data()));
1572 if(br){
1573 tree->SetBranchAddress(Form("%s.",bname.Data()),fESDObjects->GetObjectRef(el));
1574 }
1575 }
af885e0f 1576 }
1577 GetStdContent();
1578 // when reading back we are not owner of the list
1579 // must not delete it
316cf4cc 1580 fESDObjects->SetOwner(kTRUE);
af885e0f 1581 }
af885e0f 1582}
1583
1584
1585void AliESDEvent::CopyFromOldESD()
1586{
1587 // Method which copies over everthing from the old esd structure to the
1588 // new
af885e0f 1589 if(fESDOld){
1590 ResetStdContent();
1591 // Run
1592 SetRunNumber(fESDOld->GetRunNumber());
1593 SetPeriodNumber(fESDOld->GetPeriodNumber());
6ca8842a 1594 SetMagneticField(fESDOld->GetMagneticField());
af885e0f 1595
1596 // leave out diamond ...
1597 // SetDiamond(const AliESDVertex *vertex) { fESDRun->SetDiamond(vertex);}
1598
1599 // header
1600 SetTriggerMask(fESDOld->GetTriggerMask());
1601 SetOrbitNumber(fESDOld->GetOrbitNumber());
1602 SetTimeStamp(fESDOld->GetTimeStamp());
1603 SetEventType(fESDOld->GetEventType());
1604 SetEventNumberInFile(fESDOld->GetEventNumberInFile());
1605 SetBunchCrossNumber(fESDOld->GetBunchCrossNumber());
1606 SetTriggerCluster(fESDOld->GetTriggerCluster());
1607
1608 // ZDC
1609
1610 SetZDC(fESDOld->GetZDCN1Energy(),
a85132e7 1611 fESDOld->GetZDCP1Energy(),
1612 fESDOld->GetZDCEMEnergy(),
1613 0,
1614 fESDOld->GetZDCN2Energy(),
1615 fESDOld->GetZDCP2Energy(),
2b6cdc43 1616 fESDOld->GetZDCParticipants(),
5f0ec064 1617 0,
1618 0,
1619 0,
1620 0,
1621 0,
2b6cdc43 1622 0);
af885e0f 1623
1624 // FMD
1625
cb6aa27f 1626 if(fESDOld->GetFMDData())SetFMDData(fESDOld->GetFMDData());
af885e0f 1627
1628 // T0
1629
1630 SetT0zVertex(fESDOld->GetT0zVertex());
1631 SetT0(fESDOld->GetT0());
1632 // leave amps out
1633
1634 // VZERO
c06eaba2 1635 if (fESDOld->GetVZEROData()) SetVZEROData(fESDOld->GetVZEROData());
af885e0f 1636
06cc9d95 1637 if(fESDOld->GetVertex())SetPrimaryVertexSPD(fESDOld->GetVertex());
af885e0f 1638
c264b61b 1639 if(fESDOld->GetPrimaryVertex())SetPrimaryVertexTracks(fESDOld->GetPrimaryVertex());
af885e0f 1640
cb6aa27f 1641 if(fESDOld->GetMultiplicity())SetMultiplicity(fESDOld->GetMultiplicity());
1bd10080 1642
af885e0f 1643 for(int i = 0;i<fESDOld->GetNumberOfTracks();i++){
1644 AddTrack(fESDOld->GetTrack(i));
1645 }
1646
1647 for(int i = 0;i<fESDOld->GetNumberOfMuonTracks();i++){
1648 AddMuonTrack(fESDOld->GetMuonTrack(i));
1649 }
1650
1651 for(int i = 0;i<fESDOld->GetNumberOfPmdTracks();i++){
1652 AddPmdTrack(fESDOld->GetPmdTrack(i));
1653 }
1654
1655 for(int i = 0;i<fESDOld->GetNumberOfTrdTracks();i++){
1656 AddTrdTrack(fESDOld->GetTrdTrack(i));
1657 }
1658
1659 for(int i = 0;i<fESDOld->GetNumberOfV0s();i++){
1660 AddV0(fESDOld->GetV0(i));
1661 }
1662
1663 for(int i = 0;i<fESDOld->GetNumberOfCascades();i++){
1664 AddCascade(fESDOld->GetCascade(i));
1665 }
1666
1667 for(int i = 0;i<fESDOld->GetNumberOfKinks();i++){
1668 AddKink(fESDOld->GetKink(i));
1669 }
1670
1671
1672 for(int i = 0;i<fESDOld->GetNumberOfCaloClusters();i++){
1673 AddCaloCluster(fESDOld->GetCaloCluster(i));
1674 }
820b4d9e 1675
1676 #ifdef MFT_UPGRADE
1677 // MFT
1678// if (fESDOld->GetMFTData()) SetMFTData(fESDOld->GetMFTData());
1679 #endif
1bd10080 1680
af885e0f 1681 }// if fesdold
1682}
1683
2a3dfb14 1684Bool_t AliESDEvent::IsEventSelected(const char *trigExpr) const
1685{
1686 // Check if the event satisfies the trigger
1687 // selection expression trigExpr.
1688 // trigExpr can be any logical expression
1689 // of the trigger classes defined in AliESDRun
1690 // In case of wrong syntax return kTRUE.
1691
1692 TString expr(trigExpr);
1693 if (expr.IsNull()) return kTRUE;
1694
1695 ULong64_t mask = GetTriggerMask();
1696 for(Int_t itrig = 0; itrig < AliESDRun::kNTriggerClasses; itrig++) {
1697 if (mask & (1ull << itrig)) {
1698 expr.ReplaceAll(GetESDRun()->GetTriggerClass(itrig),"1");
1699 }
1700 else {
1701 expr.ReplaceAll(GetESDRun()->GetTriggerClass(itrig),"0");
1702 }
1703 }
1704
1705 Int_t error;
1706 if ((gROOT->ProcessLineFast(expr.Data(),&error) == 0) &&
1707 (error == TInterpreter::kNoError)) {
1708 return kFALSE;
1709 }
1710
1711 return kTRUE;
1712
1713}
1714
3b286f80 1715TObject* AliESDEvent::GetHLTTriggerDecision() const
1716{
1717 // get the HLT trigger decission object
1718
1719 // cast away const'nes because the FindListObject method
1720 // is not const
1721 AliESDEvent* pNonConst=const_cast<AliESDEvent*>(this);
1722 return pNonConst->FindListObject("HLTGlobalTrigger");
1723}
1724
1725TString AliESDEvent::GetHLTTriggerDescription() const
1726{
1727 // get the HLT trigger decission description
1728 TString description;
1729 TObject* pDecision=GetHLTTriggerDecision();
1730 if (pDecision) {
1731 description=pDecision->GetTitle();
1732 }
1733
1734 return description;
1735}
1736
1737Bool_t AliESDEvent::IsHLTTriggerFired(const char* name) const
1738{
1739 // get the HLT trigger decission description
1740 TObject* pDecision=GetHLTTriggerDecision();
1741 if (!pDecision) return kFALSE;
1742
1743 Option_t* option=pDecision->GetOption();
1744 if (option==NULL || *option!='1') return kFALSE;
1745
1746 if (name) {
1747 TString description=GetHLTTriggerDescription();
1748 Int_t index=description.Index(name);
1749 if (index<0) return kFALSE;
1750 index+=strlen(name);
1751 if (index>=description.Length()) return kFALSE;
1752 if (description[index]!=0 && description[index]!=' ') return kFALSE;
1753 }
1754 return kTRUE;
1755}
af885e0f 1756
a98c78e5 1757//______________________________________________________________________________
1758Bool_t AliESDEvent::IsPileupFromSPD(Int_t minContributors,
1759 Double_t minZdist,
1760 Double_t nSigmaZdist,
1761 Double_t nSigmaDiamXY,
1762 Double_t nSigmaDiamZ) const{
e741cb7c 1763 //
1764 // This function checks if there was a pile up
1765 // reconstructed with SPD
1766 //
e741cb7c 1767 Int_t nc1=fSPDVertex->GetNContributors();
1768 if(nc1<1) return kFALSE;
1769 Int_t nPileVert=GetNumberOfPileupVerticesSPD();
1770 if(nPileVert==0) return kFALSE;
a98c78e5 1771
e741cb7c 1772 for(Int_t i=0; i<nPileVert;i++){
1773 const AliESDVertex* pv=GetPileupVertexSPD(i);
e741cb7c 1774 Int_t nc2=pv->GetNContributors();
a98c78e5 1775 if(nc2>=minContributors){
1776 Double_t z1=fSPDVertex->GetZ();
1777 Double_t z2=pv->GetZ();
1778 Double_t distZ=TMath::Abs(z2-z1);
1779 Double_t distZdiam=TMath::Abs(z2-GetDiamondZ());
569d954c 1780 Double_t cutZdiam=nSigmaDiamZ*TMath::Sqrt(GetSigma2DiamondZ());
a98c78e5 1781 if(GetSigma2DiamondZ()<0.0001)cutZdiam=99999.; //protection for missing z diamond information
1782 if(distZ>minZdist && distZdiam<cutZdiam){
1783 Double_t x2=pv->GetX();
1784 Double_t y2=pv->GetY();
1785 Double_t distXdiam=TMath::Abs(x2-GetDiamondX());
1786 Double_t distYdiam=TMath::Abs(y2-GetDiamondY());
1787 Double_t cov1[6],cov2[6];
1788 fSPDVertex->GetCovarianceMatrix(cov1);
1789 pv->GetCovarianceMatrix(cov2);
1790 Double_t errxDist=TMath::Sqrt(cov2[0]+GetSigma2DiamondX());
1791 Double_t erryDist=TMath::Sqrt(cov2[2]+GetSigma2DiamondY());
1792 Double_t errzDist=TMath::Sqrt(cov1[5]+cov2[5]);
1793 Double_t cutXdiam=nSigmaDiamXY*errxDist;
1794 if(GetSigma2DiamondX()<0.0001)cutXdiam=99999.; //protection for missing diamond information
1795 Double_t cutYdiam=nSigmaDiamXY*erryDist;
1796 if(GetSigma2DiamondY()<0.0001)cutYdiam=99999.; //protection for missing diamond information
1797 if( (distXdiam<cutXdiam) && (distYdiam<cutYdiam) && (distZ>nSigmaZdist*errzDist) ){
1798 return kTRUE;
1799 }
1800 }
e741cb7c 1801 }
e741cb7c 1802 }
a98c78e5 1803 return kFALSE;
1804}
e741cb7c 1805
4ace6760 1806//______________________________________________________________________________
1807void AliESDEvent::EstimateMultiplicity(Int_t &tracklets, Int_t &trITSTPC, Int_t &trITSSApure, Double_t eta, Bool_t useDCAFlag,Bool_t useV0Flag) const
1808{
1809 //
1810 // calculates 3 estimators for the multiplicity in the -eta:eta range
1811 // tracklets : using SPD tracklets only
1812 // trITSTPC : using TPC/ITS + complementary ITS SA tracks + tracklets from clusters not used by tracks
1813 // trITSSApure : using ITS standalone tracks + tracklets from clusters not used by tracks
1814 // if useDCAFlag is true: account for the ESDtrack flag marking the tracks with large DCA
1815 // if useV0Flag is true: account for the ESDtrack flag marking conversion and K0's V0s
1816 tracklets = trITSSApure = trITSTPC = 0;
1817 int ntr = fSPDMult ? fSPDMult->GetNumberOfTracklets() : 0;
1818 //
1819 // count tracklets
1820 for (int itr=ntr;itr--;) {
1821 if (TMath::Abs(fSPDMult->GetEta(itr))>eta) continue;
1822 tracklets++;
1823 if (fSPDMult->FreeClustersTracklet(itr,0)) trITSTPC++; // not used in ITS/TPC or ITS_SA track
1824 if (fSPDMult->FreeClustersTracklet(itr,1)) trITSSApure++; // not used in ITS_SA_Pure track
1825 }
1826 //
1827 // count real tracks
1828 ntr = GetNumberOfTracks();
1829 for (int itr=ntr;itr--;) {
1830 AliESDtrack *t = GetTrack(itr);
1831 if (TMath::Abs(t->Eta())>eta) continue;
1832 if (!t->IsOn(AliESDtrack::kITSin)) continue;
1833 if (useDCAFlag && t->IsOn(AliESDtrack::kMultSec)) continue;
1834 if (useV0Flag && t->IsOn(AliESDtrack::kMultInV0)) continue;
1835 if (t->IsOn(AliESDtrack::kITSpureSA)) trITSSApure++;
1836 else trITSTPC++;
1837 }
1838 //
1839}
b46ff4b0 1840
1841Bool_t AliESDEvent::IsPileupFromSPDInMultBins() const {
1842 Int_t nTracklets=GetMultiplicity()->GetNumberOfTracklets();
1843 if(nTracklets<20) return IsPileupFromSPD(3,0.8);
1844 else if(nTracklets<50) return IsPileupFromSPD(4,0.8);
1845 else return IsPileupFromSPD(5,0.8);
1846}
1847
f858b00e 1848void AliESDEvent::SetTOFHeader(const AliTOFHeader *header)
1849{
1850 //
1851 // Set the TOF event_time
1852 //
1853
1854 if (fTOFHeader) {
1855 *fTOFHeader=*header;
1856 //fTOFHeader->SetName(fgkESDListName[kTOFHeader]);
1857 }
1858 else {
1859 // for analysis of reconstructed events
1860 // when this information is not avaliable
1861 fTOFHeader = new AliTOFHeader(*header);
1862 //AddObject(fTOFHeader);
1863 }
1864
1865}
cb62947d 1866
fba4b2e2 1867AliCentrality* AliESDEvent::GetCentrality()
cb62947d 1868{
fba4b2e2 1869 if (!fCentrality) fCentrality = new AliCentrality();
cb62947d 1870 return fCentrality;
1871}
ce7adfe9 1872
1873AliEventplane* AliESDEvent::GetEventplane()
1874{
1875 if (!fEventplane) fEventplane = new AliEventplane();
1876 return fEventplane;
1877}
1dc767cf 1878
1879Float_t AliESDEvent::GetVZEROEqMultiplicity(Int_t i) const
1880{
1881 // Get VZERO Multiplicity for channel i
1882 // Themethod uses the equalization factors
1883 // stored in the ESD-run object in order to
1884 // get equal multiplicities within a VZERO rins (1/8 of VZERO)
1885 if (!fESDVZERO || !fESDRun) return -1;
1886
1887 Int_t ring = i/8;
1888 Float_t factorSum = 0;
1889 for(Int_t j = 8*ring; j < (8*ring+8); ++j) {
1890 factorSum += fESDRun->GetVZEROEqFactors(j);
1891 }
1892 Float_t factor = fESDRun->GetVZEROEqFactors(i)*8./factorSum;
1893
1894 return (fESDVZERO->GetMultiplicity(i)/factor);
1895}