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