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