]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AOD/AliAODEvent.cxx
Fix in inline methods declarations
[u/mrichter/AliRoot.git] / STEER / AOD / AliAODEvent.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, 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 //     AOD base class
20 //     Author: Markus Oldenburg, CERN
21 //-------------------------------------------------------------------------
22
23 #include <TROOT.h>
24 #include <TTree.h>
25 #include <TFolder.h>
26 #include <TFriendElement.h>
27 #include <TProcessID.h>
28 #include <TCollection.h>
29 #include "Riostream.h"
30 #include "AliAODEvent.h"
31 #include "AliAODHeader.h"
32 #include "AliAODTrack.h"
33 #include "AliAODDimuon.h"
34
35 ClassImp(AliAODEvent)
36
37 // definition of std AOD member names
38   const char* AliAODEvent::fAODListName[kAODListN] = {"header",
39                                                       "tracks",
40                                                       "vertices",
41                                                       "v0s",
42                                                       "cascades",
43                                                       "tracklets",
44                                                       "jets",
45                                                       "emcalCells",
46                                                       "phosCells",
47                                                                         "caloClusters",
48                                                                         "emcalTrigger",
49                                                                         "phosTrigger",
50                                                       "fmdClusters",
51                                                       "pmdClusters",
52                                                       "hmpidRings",
53                                                       "dimuons",
54                                                       "AliAODTZERO",
55                                                       "AliAODVZERO",
56                                                       "AliAODZDC",
57                                                       "AliTOFHeader"
58 #ifdef MFT_UPGRADE        
59                                                       ,"AliAODMFT"
60 #endif                                                
61                                                       
62 };
63 //______________________________________________________________________________
64 AliAODEvent::AliAODEvent() :
65   AliVEvent(),
66   fAODObjects(0),
67   fAODFolder(0),
68   fConnected(kFALSE),
69   fHeader(0),
70   fTracks(0),
71   fVertices(0),
72   fV0s(0),
73   fCascades(0),
74   fTracklets(0),
75   fJets(0),
76   fEmcalCells(0),
77   fPhosCells(0),
78   fCaloClusters(0),
79   fEMCALTrigger(0),
80   fPHOSTrigger(0),
81   fFmdClusters(0),
82   fPmdClusters(0),
83   fHMPIDrings(0),
84   fDimuons(0),
85   fAODTZERO(0),
86   fAODVZERO(0),
87   fAODZDC(0),
88   fTOFHeader(0)
89 #ifdef MFT_UPGRADE
90   ,fAODMFT(0)
91 #endif
92 {
93   // default constructor
94   if (TClass::IsCallingNew() != TClass::kDummyNew) fAODObjects = new TList();
95 }
96
97 //______________________________________________________________________________
98 AliAODEvent::AliAODEvent(const AliAODEvent& aod):
99   AliVEvent(aod),
100   fAODObjects(new TList()),
101   fAODFolder(0),
102   fConnected(kFALSE),
103   fHeader(new AliAODHeader(*aod.fHeader)),
104   fTracks(new TClonesArray(*aod.fTracks)),
105   fVertices(new TClonesArray(*aod.fVertices)),
106   fV0s(new TClonesArray(*aod.fV0s)),
107   fCascades(new TClonesArray(*aod.fCascades)),
108   fTracklets(new AliAODTracklets(*aod.fTracklets)),
109   fJets(new TClonesArray(*aod.fJets)),
110   fEmcalCells(new AliAODCaloCells(*aod.fEmcalCells)),
111   fPhosCells(new AliAODCaloCells(*aod.fPhosCells)),
112   fCaloClusters(new TClonesArray(*aod.fCaloClusters)),
113   fEMCALTrigger(new AliAODCaloTrigger(*aod.fEMCALTrigger)),
114   fPHOSTrigger(new AliAODCaloTrigger(*aod.fPHOSTrigger)),
115   fFmdClusters(new TClonesArray(*aod.fFmdClusters)),
116   fPmdClusters(new TClonesArray(*aod.fPmdClusters)),
117   fHMPIDrings(new TClonesArray(*aod.fHMPIDrings)),
118   fDimuons(new TClonesArray(*aod.fDimuons)),
119   fAODTZERO(new AliAODTZERO(*aod.fAODTZERO)),
120   fAODVZERO(new AliAODVZERO(*aod.fAODVZERO)),
121   fAODZDC(new AliAODZDC(*aod.fAODZDC)),
122   fTOFHeader(new AliTOFHeader(*aod.fTOFHeader))
123 #ifdef MFT_UPGRADE
124   ,fAODMFT(new AliAODMFT(*aod.fAODMFT))
125 #endif
126 {
127   // Copy constructor
128   AddObject(fHeader);
129   AddObject(fTracks);
130   AddObject(fVertices);
131   AddObject(fV0s);
132   AddObject(fCascades);
133   AddObject(fTracklets);
134   AddObject(fJets);
135   AddObject(fEmcalCells);
136   AddObject(fPhosCells);
137   AddObject(fCaloClusters);
138   AddObject(fEMCALTrigger);
139   AddObject(fPHOSTrigger);
140   AddObject(fFmdClusters);
141   AddObject(fPmdClusters);
142   AddObject(fHMPIDrings);
143   AddObject(fDimuons);
144   AddObject(fAODTZERO);
145   AddObject(fAODVZERO);
146   AddObject(fAODZDC);
147   AddObject(fTOFHeader);
148 #ifdef MFT_UPGRADE      
149   AddObject(fAODVZERO);
150 #endif
151   fConnected = aod.fConnected;
152   GetStdContent();
153   CreateStdFolders();
154 }
155
156 //______________________________________________________________________________
157 AliAODEvent & AliAODEvent::operator=(const AliAODEvent& aod) {
158
159     // Assignment operator
160
161   if(&aod == this) return *this;
162   AliVEvent::operator=(aod);
163
164   // This assumes that the list is already created
165   // and that the virtual void Copy(Tobject&) function
166   // is correctly implemented in the derived class
167   // otherwise only TObject::Copy() will be used
168
169   if((fAODObjects->GetSize()==0)&&(aod.fAODObjects->GetSize()>=kAODListN)){
170     // We cover the case that we do not yet have the 
171     // standard content but the source has it
172     CreateStdContent();
173   }
174   
175   // Here we have the standard content without user additions, but the content is 
176   // not matching the aod source.
177   
178   // Iterate the list of source objects
179   TIter next(aod.GetList());
180   TObject *its = 0;
181   TString name;
182   while ((its = next())) {
183     name = its->GetName();
184     // Check if we have this object type in out list
185     TObject *mine = fAODObjects->FindObject(name);    
186     if(!mine) {
187       // We have to create the same type of object.
188       TClass* pClass=TClass::GetClass(its->ClassName());     
189       if (!pClass) {
190         AliWarning(Form("Can not find class description for entry %s (%s)\n",
191                    its->ClassName(), name.Data()));
192         continue;
193       }
194       mine=(TObject*)pClass->New();
195       if(!mine){
196         // not in this: can be added to list
197         AliWarning(Form("%s:%d Could not find %s for copying \n",
198                    (char*)__FILE__,__LINE__,name.Data()));
199         continue;
200       }  
201       if(mine->InheritsFrom("TNamed"))  {
202         ((TNamed*)mine)->SetName(name);
203       } else if(mine->InheritsFrom("TCollection")){
204         if(mine->InheritsFrom("TClonesArray")) {
205           TClonesArray *itscl = dynamic_cast<TClonesArray*>(its);
206           if (!itscl) {
207             AliWarning(Form("Class description for entry %s (%s) not TClonesArray\n",
208                    its->ClassName(), name.Data()));
209             continue;
210           
211           }
212                dynamic_cast<TClonesArray*>(mine)->SetClass(itscl->GetClass(), itscl->GetSize());
213         }
214         dynamic_cast<TCollection*>(mine)->SetName(name);
215       }
216       AliDebug(1, Form("adding object %s of type %s", mine->GetName(), mine->ClassName()));
217       AddObject(mine);
218     }
219     // Now we have an object of the same type and name, but different content.        
220     if(!its->InheritsFrom("TCollection")){
221       // simple objects (do they have a Copy method that calls operator= ?)
222       its->Copy(*mine);
223     } else if (its->InheritsFrom("TClonesArray")) {
224       // Create or expand the tclonesarray pointers
225       // so we can directly copy to the object
226       TClonesArray *its_tca = (TClonesArray*)its;
227       TClonesArray *mine_tca = (TClonesArray*)mine;
228       // this leaves the capacity of the TClonesArray the same
229       // except for a factor of 2 increase when size > capacity
230       // does not release any memory occupied by the tca
231       Int_t its_entries = its_tca->GetEntriesFast();
232       mine_tca->ExpandCreate(its_entries);
233       for(int i=0; i<its_entries; i++){
234         // copy 
235         TObject *mine_tca_obj = mine_tca->At(i);
236         TObject *its_tca_obj = its_tca->At(i);
237         // no need to delete first
238         // pointers within the class should be handled by Copy()...
239         // Can there be Empty slots?
240         its_tca_obj->Copy(*mine_tca_obj);
241       }
242     } else {
243       AliWarning(Form("%s:%d cannot copy TCollection \n",
244                       (char*)__FILE__,__LINE__));
245     }
246   }  
247   fConnected = aod.fConnected;
248   return *this;
249 }
250
251
252 //______________________________________________________________________________
253 AliAODEvent::~AliAODEvent() 
254 {
255 // destructor
256     delete fAODFolder;
257     fAODFolder = 0;
258     if(!fConnected) {
259 //       fAODObjects->Delete("slow");
260        delete fAODObjects;
261     }   
262 }
263
264 //______________________________________________________________________________
265 void AliAODEvent::AddObject(TObject* obj) 
266 {
267   // Add an object to the list of objects.
268   // Please be aware that in order to increase performance you should
269   // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
270   
271 //  if ( !fAODObjects ) {
272 //     fAODObjects = new TList();
273 //     fAODObjects->SetOwner();
274 //  }
275   if ( !fAODObjects->FindObject(obj) ) 
276   {
277     fAODObjects->AddLast(obj);
278   }
279 }
280
281 //______________________________________________________________________________
282 void AliAODEvent::RemoveObject(TObject* obj) 
283 {
284   // Removes an object from the list of objects.
285   
286   fAODObjects->Remove(obj);
287 }
288
289 //______________________________________________________________________________
290 TObject *AliAODEvent::FindListObject(const char *objName) const
291 {
292   // Return the pointer to the object with the given name.
293
294   return fAODObjects->FindObject(objName);
295 }
296
297 //______________________________________________________________________________
298 void AliAODEvent::CreateStdContent() 
299 {
300   // create the standard AOD content and set pointers
301
302   // create standard objects and add them to the TList of objects
303   AddObject(new AliAODHeader());
304   AddObject(new TClonesArray("AliAODTrack", 0));
305   AddObject(new TClonesArray("AliAODVertex", 0));
306   AddObject(new TClonesArray("AliAODv0", 0));
307   AddObject(new TClonesArray("AliAODcascade", 0));
308   AddObject(new AliAODTracklets());
309   AddObject(new TClonesArray("AliAODJet", 0));
310   AddObject(new AliAODCaloCells());
311   AddObject(new AliAODCaloCells());
312   AddObject(new TClonesArray("AliAODCaloCluster", 0));
313   AddObject(new AliAODCaloTrigger()); // EMCAL 
314   AddObject(new AliAODCaloTrigger()); // PHOS
315   AddObject(new TClonesArray("AliAODFmdCluster", 0));
316   AddObject(new TClonesArray("AliAODPmdCluster", 0));
317   AddObject(new TClonesArray("AliAODHMPIDrings", 0));
318   AddObject(new TClonesArray("AliAODDimuon", 0));
319   AddObject(new AliAODTZERO());
320   AddObject(new AliAODVZERO());
321   AddObject(new AliAODZDC());
322   AddObject(new AliTOFHeader());
323 #ifdef MFT_UPGRADE
324   AddObject(new AliAODMFT());
325 #endif
326   // set names
327   SetStdNames();
328
329   // read back pointers
330   GetStdContent();
331   CreateStdFolders();
332   return;
333 }
334
335 void  AliAODEvent::MakeEntriesReferencable()
336 {
337     // Make all entries referencable in a subsequent process
338     //
339     TIter next(fAODObjects);
340     TObject* obj;
341     while ((obj = next()))
342     {
343         if(obj->InheritsFrom("TCollection"))
344             {
345                 AssignIDtoCollection((TCollection*)obj);
346             }
347     }
348 }
349
350 //______________________________________________________________________________
351 void AliAODEvent::SetStdNames()
352 {
353   // introduce the standard naming
354
355   if(fAODObjects->GetEntries()==kAODListN){
356     for(int i = 0;i < fAODObjects->GetEntries();i++){
357       TObject *fObj = fAODObjects->At(i);
358       if(fObj->InheritsFrom("TNamed")){
359         ((TNamed*)fObj)->SetName(fAODListName[i]);
360       }
361       else if(fObj->InheritsFrom("TClonesArray")){
362         ((TClonesArray*)fObj)->SetName(fAODListName[i]);
363       }
364     }
365   }
366   else{
367     printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
368   }
369
370
371 void AliAODEvent::CreateStdFolders()
372 {
373     // Create the standard folder structure
374   if(fAODFolder)delete fAODFolder;
375     fAODFolder = gROOT->GetRootFolder()->AddFolder("AOD", "AOD");
376     if(fAODObjects->GetEntries()==kAODListN){
377         for(int i = 0;i < fAODObjects->GetEntries();i++){
378             TObject *fObj = fAODObjects->At(i);
379             if(fObj->InheritsFrom("TClonesArray")){
380                 fAODFolder->AddFolder(fAODListName[i], fAODListName[i], (TCollection*) fObj);
381             } else {
382                 fAODFolder->AddFolder(fAODListName[i], fAODListName[i], 0);
383             }
384         }
385     }
386     else{
387         printf("%s:%d CreateStdFolders() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
388     }
389
390
391 //______________________________________________________________________________
392 void AliAODEvent::GetStdContent()
393 {
394   // set pointers for standard content
395
396   fHeader        = (AliAODHeader*)fAODObjects->FindObject("header");
397   fTracks        = (TClonesArray*)fAODObjects->FindObject("tracks");
398   fVertices      = (TClonesArray*)fAODObjects->FindObject("vertices");
399   fV0s           = (TClonesArray*)fAODObjects->FindObject("v0s");
400   fCascades      = (TClonesArray*)fAODObjects->FindObject("cascades");
401   fTracklets     = (AliAODTracklets*)fAODObjects->FindObject("tracklets");
402   fJets          = (TClonesArray*)fAODObjects->FindObject("jets");
403   fEmcalCells    = (AliAODCaloCells*)fAODObjects->FindObject("emcalCells");
404   fPhosCells     = (AliAODCaloCells*)fAODObjects->FindObject("phosCells");
405   fCaloClusters  = (TClonesArray*)fAODObjects->FindObject("caloClusters");
406   fEMCALTrigger  = (AliAODCaloTrigger*)fAODObjects->FindObject("emcalTrigger");
407   fPHOSTrigger   = (AliAODCaloTrigger*)fAODObjects->FindObject("phosTrigger");
408   fFmdClusters   = (TClonesArray*)fAODObjects->FindObject("fmdClusters");
409   fPmdClusters   = (TClonesArray*)fAODObjects->FindObject("pmdClusters");
410   fHMPIDrings    = (TClonesArray*)fAODObjects->FindObject("hmpidRings");  
411   fDimuons       = (TClonesArray*)fAODObjects->FindObject("dimuons");
412   fAODTZERO      = (AliAODTZERO*)fAODObjects->FindObject("AliAODTZERO");
413   fAODVZERO      = (AliAODVZERO*)fAODObjects->FindObject("AliAODVZERO");
414   fAODZDC        = (AliAODZDC*)fAODObjects->FindObject("AliAODZDC");
415   fTOFHeader     = (AliTOFHeader*)fAODObjects->FindObject("AliTOFHeader");
416 #ifdef MFT_UPGRADE
417   fAODMFT        = (AliAODMFT*)fAODObjects->FindObject("AliAODMFT");
418 #endif
419 }
420
421 //______________________________________________________________________________
422 void AliAODEvent::ResetStd(Int_t trkArrSize, 
423                            Int_t vtxArrSize, 
424                            Int_t v0ArrSize,
425                            Int_t cascadeArrSize,
426                            Int_t jetSize, 
427                            Int_t caloClusSize, 
428                            Int_t fmdClusSize, 
429                            Int_t pmdClusSize,
430                            Int_t hmpidRingsSize,
431                            Int_t dimuonArrSize
432                            )
433 {
434   // deletes content of standard arrays and resets size 
435   if (fTracks) {
436     fTracks->Delete();
437     if (trkArrSize > fTracks->GetSize()) 
438       fTracks->Expand(trkArrSize);
439   }
440   if (fVertices) {
441     fVertices->Delete();
442     if (vtxArrSize > fVertices->GetSize()) 
443       fVertices->Expand(vtxArrSize);
444   }
445   if (fV0s) {
446     fV0s->Delete();
447     if (v0ArrSize > fV0s->GetSize()) 
448       fV0s->Expand(v0ArrSize);
449   }
450   if (fCascades) {
451     fCascades->Delete();
452     if (cascadeArrSize > fCascades->GetSize()) 
453       fCascades->Expand(cascadeArrSize);
454   }
455   if (fJets) {
456     fJets->Delete();
457     if (jetSize > fJets->GetSize())
458       fJets->Expand(jetSize);
459   }
460   if (fCaloClusters) {
461     fCaloClusters->Delete();
462     if (caloClusSize > fCaloClusters->GetSize()) 
463       fCaloClusters->Expand(caloClusSize);
464   }
465   if (fFmdClusters) {
466     fFmdClusters->Delete();
467     if (fmdClusSize > fFmdClusters->GetSize()) 
468       fFmdClusters->Expand(fmdClusSize);
469   }
470   if (fPmdClusters) {
471     fPmdClusters->Delete();
472     if (pmdClusSize > fPmdClusters->GetSize()) 
473       fPmdClusters->Expand(pmdClusSize);
474   }
475   if (fHMPIDrings) {
476      fHMPIDrings->Delete();
477     if (hmpidRingsSize > fHMPIDrings->GetSize()) 
478       fHMPIDrings->Expand(hmpidRingsSize);
479   }
480   if (fDimuons) {
481     fDimuons->Delete();
482     if (dimuonArrSize > fDimuons->GetSize()) 
483       fDimuons->Expand(dimuonArrSize);
484   }
485   if (fTracklets)
486     fTracklets->DeleteContainer();
487   if (fPhosCells)
488     fPhosCells->DeleteContainer();  
489   if (fEmcalCells)
490     fEmcalCells->DeleteContainer();
491   
492   if (fEMCALTrigger)
493         fEMCALTrigger->DeAllocate();
494   if (fPHOSTrigger)
495         fPHOSTrigger->DeAllocate();
496
497 }
498
499 void AliAODEvent::ClearStd()
500 {
501   // clears the standard arrays
502   if (fHeader)
503     fHeader        ->Clear();
504   if (fTracks)
505     fTracks        ->Delete();
506   if (fVertices)
507     fVertices      ->Delete();
508   if (fV0s)
509     fV0s           ->Delete();
510   if (fCascades)
511     fCascades      ->Delete();
512   if (fTracklets)
513     fTracklets     ->DeleteContainer();
514   if (fJets)
515     fJets          ->Delete();
516   if (fEmcalCells)
517     fEmcalCells    ->DeleteContainer();
518   if (fPhosCells)
519     fPhosCells     ->DeleteContainer();
520   if (fCaloClusters)
521     fCaloClusters  ->Delete();
522   if (fFmdClusters)
523     fFmdClusters   ->Clear();
524   if (fPmdClusters)
525     fPmdClusters   ->Clear();  
526   if (fHMPIDrings) 
527      fHMPIDrings   ->Clear();    
528   if (fDimuons)
529     fDimuons       ->Clear();
530         
531   if (fEMCALTrigger)
532         fEMCALTrigger->DeAllocate();
533   if (fPHOSTrigger)
534         fPHOSTrigger->DeAllocate();
535 }
536
537 //_________________________________________________________________
538 Int_t AliAODEvent::GetPHOSClusters(TRefArray *clusters) const
539 {
540   // fills the provided TRefArray with all found phos clusters
541   
542   clusters->Clear();
543   
544   AliAODCaloCluster *cl = 0;
545   Bool_t first = kTRUE;
546   for (Int_t i = 0; i < GetNumberOfCaloClusters() ; i++) {
547     if ( (cl = GetCaloCluster(i)) ) {
548       if (cl->IsPHOS()){
549         if(first) {
550           new (clusters) TRefArray(TProcessID::GetProcessWithUID(cl)); 
551           first=kFALSE;
552         }
553         clusters->Add(cl);
554         //printf("IsPHOS cluster %d, E %2.3f Size: %d \n",i,cl->E(),clusters->GetEntriesFast());
555       }
556     }
557   }
558   return clusters->GetEntriesFast();
559 }
560
561 //_________________________________________________________________
562 Int_t AliAODEvent::GetEMCALClusters(TRefArray *clusters) const
563 {
564   // fills the provided TRefArray with all found emcal clusters
565
566   clusters->Clear();
567   AliAODCaloCluster *cl = 0;
568   Bool_t first = kTRUE;
569   for (Int_t i = 0; i < GetNumberOfCaloClusters(); i++) {
570     if ( (cl = GetCaloCluster(i)) ) {
571       if (cl->IsEMCAL()){
572         if(first) {
573           new (clusters) TRefArray(TProcessID::GetProcessWithUID(cl)); 
574           first=kFALSE;
575         }
576         clusters->Add(cl);
577         //printf("IsEMCal cluster %d, E %2.3f Size: %d \n",i,cl->E(),clusters->GetEntriesFast());
578       }
579     }
580   }
581   return clusters->GetEntriesFast();
582 }
583
584
585 //______________________________________________________________________________
586 Int_t AliAODEvent::GetMuonTracks(TRefArray *muonTracks) const
587 {
588   // fills the provided TRefArray with all found muon tracks
589
590   muonTracks->Clear();
591
592   AliAODTrack *track = 0;
593   for (Int_t iTrack = 0; iTrack < GetNTracks(); iTrack++) {
594     track = GetTrack(iTrack);
595     if (track->IsMuonTrack()) {
596       muonTracks->Add(track);
597     }
598   }
599   
600   return muonTracks->GetEntriesFast();
601 }
602
603
604 //______________________________________________________________________________
605 Int_t AliAODEvent::GetNumberOfMuonTracks() const
606 {
607   // get number of muon tracks
608   Int_t nMuonTracks=0;
609   for (Int_t iTrack = 0; iTrack < GetNTracks(); iTrack++) {
610     if ((GetTrack(iTrack))->IsMuonTrack()) {
611        nMuonTracks++;
612     }
613   }
614   
615   return nMuonTracks;
616 }
617
618 //______________________________________________________________________________
619 void AliAODEvent::ReadFromTree(TTree *tree, Option_t* opt /*= ""*/)
620 {
621     // Connects aod event to tree
622   
623   if(!tree){
624     AliWarning("Zero Pointer to Tree \n");
625     return;
626   }
627     // load the TTree
628   if(!tree->GetTree())tree->LoadTree(0);
629   
630     // Try to find AliAODEvent
631   AliAODEvent *aodEvent = 0;
632   aodEvent = (AliAODEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliAODEvent");
633   if(aodEvent){
634     // This event is connected to the tree by definition, just say so
635     aodEvent->SetConnected();
636       // Check if already connected to tree
637     TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("AODObjectsConnectedToTree"));
638     if (connectedList && (!strcmp(opt, "reconnect"))) {
639         // If connected use the connected list of objects
640         if (fAODObjects != connectedList) {
641            delete fAODObjects;
642            fAODObjects = connectedList;
643         }   
644         GetStdContent(); 
645         fConnected = kTRUE;
646         return;
647     } 
648       // Connect to tree
649       // prevent a memory leak when reading back the TList
650 //      if (!(strcmp(opt, "reconnect"))) fAODObjects->Delete();
651     
652       // create a new TList from the UserInfo TList... 
653       // copy constructor does not work...
654     //    fAODObjects = (TList*)(aodEvent->GetList()->Clone());
655     fAODObjects = (TList*)aodEvent->GetList();
656     fAODObjects->SetOwner(kTRUE);
657     if(fAODObjects->GetEntries()<kAODListN)
658     {
659       AliWarning(Form("AliAODEvent::ReadFromTree() TList contains less than the standard contents %d < %d"
660                       " That might be fine though (at least for filtered AODs)",fAODObjects->GetEntries(),kAODListN));
661     }
662       //
663       // Let's find out whether we have friends
664     TList* friendL = tree->GetTree()->GetListOfFriends();
665     if (friendL) 
666     {
667       TIter next(friendL);
668       TFriendElement* fe;
669       while ((fe = (TFriendElement*)next())){
670         aodEvent = (AliAODEvent*)(fe->GetTree()->GetUserInfo()->FindObject("AliAODEvent"));
671         if (!aodEvent) {
672           printf("No UserInfo on tree \n");
673         } else {
674           
675           //          TList* objL = (TList*)(aodEvent->GetList()->Clone());
676           TList* objL = (TList*)aodEvent->GetList();
677           printf("Get list of object from tree %d !!\n", objL->GetEntries());
678           TIter nextobject(objL);
679           TObject* obj =  0;
680           while((obj = nextobject()))
681           {
682             printf("Adding object from friend %s !\n", obj->GetName());
683             fAODObjects->Add(obj);
684           } // object "branch" loop
685         } // has userinfo  
686       } // friend loop
687     } // has friends    
688       // set the branch addresses
689     TIter next(fAODObjects);
690     TNamed *el;
691     while((el=(TNamed*)next())){
692       TString bname(el->GetName());
693         // check if branch exists under this Name
694       TBranch *br = tree->GetTree()->GetBranch(bname.Data());
695       if(br){
696         tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
697       } else {
698         br = tree->GetBranch(Form("%s.",bname.Data()));
699         if(br){
700           tree->SetBranchAddress(Form("%s.",bname.Data()),fAODObjects->GetObjectRef(el));
701         }
702         else{
703           printf("%s %d AliAODEvent::ReadFromTree() No Branch found with Name %s. \n",
704                  (char*)__FILE__,__LINE__,bname.Data());
705         }       
706       }
707     }
708     GetStdContent();
709       // when reading back we are not owner of the list 
710       // must not delete it
711     fAODObjects->SetOwner(kTRUE);
712     fAODObjects->SetName("AODObjectsConnectedToTree");
713       // we are not owner of the list objects 
714       // must not delete it
715     tree->GetUserInfo()->Add(fAODObjects);
716     fConnected = kTRUE;
717   }// no aodEvent
718   else {
719       // we can't get the list from the user data, create standard content
720       // and set it by hand
721     CreateStdContent();
722     TIter next(fAODObjects);
723     TNamed *el;
724     while((el=(TNamed*)next())){
725       TString bname(el->GetName());    
726       tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
727     }
728     GetStdContent();
729       // when reading back we are not owner of the list 
730       // must not delete it
731     fAODObjects->SetOwner(kTRUE);
732   }
733 }
734   //______________________________________________________________________________
735 Int_t  AliAODEvent::GetNumberOfPileupVerticesSPD() const{
736   // count number of SPD pileup vertices
737   Int_t nVertices=GetNumberOfVertices();
738   Int_t nPileupVertices=0;
739   for(Int_t iVert=0; iVert<nVertices; iVert++){
740     AliAODVertex *v=GetVertex(iVert);
741     if(v->GetType()==AliAODVertex::kPileupSPD) nPileupVertices++;
742   }
743   return nPileupVertices;
744 }
745 //______________________________________________________________________________
746 Int_t  AliAODEvent::GetNumberOfPileupVerticesTracks() const{
747   // count number of track pileup vertices
748   Int_t nVertices=GetNumberOfVertices();
749   Int_t nPileupVertices=0;
750   for(Int_t iVert=0; iVert<nVertices; iVert++){
751     AliAODVertex *v=GetVertex(iVert);
752     if(v->GetType()==AliAODVertex::kPileupTracks) nPileupVertices++;
753   }
754   return nPileupVertices;
755 }
756 //______________________________________________________________________________
757 AliAODVertex* AliAODEvent::GetPrimaryVertexSPD() const{
758   // Get SPD primary vertex
759   Int_t nVertices=GetNumberOfVertices();
760   for(Int_t iVert=0; iVert<nVertices; iVert++){
761     AliAODVertex *v=GetVertex(iVert);
762     if(v->GetType()==AliAODVertex::kMainSPD) return v;
763   }
764   return 0;
765 }
766 //______________________________________________________________________________
767 AliAODVertex* AliAODEvent::GetPileupVertexSPD(Int_t iV) const{
768   // Get pile-up vertex iV
769   Int_t nVertices=GetNumberOfVertices();
770   Int_t counter=0;
771   for(Int_t iVert=0; iVert<nVertices; iVert++){
772     AliAODVertex *v=GetVertex(iVert);
773     if(v->GetType()==AliAODVertex::kPileupSPD){
774       if(counter==iV) return v;
775       ++counter;
776     }
777   }
778   return 0;
779 }
780 //______________________________________________________________________________
781 AliAODVertex* AliAODEvent::GetPileupVertexTracks(Int_t iV) const{
782   // Get pile-up vertex iV
783   Int_t nVertices=GetNumberOfVertices();
784   Int_t counter=0;
785   for(Int_t iVert=0; iVert<nVertices; iVert++){
786     AliAODVertex *v=GetVertex(iVert);
787     if(v->GetType()==AliAODVertex::kPileupTracks){
788       if(counter==iV) return v;
789       ++counter;
790     }
791   }
792   return 0;
793 }
794 //______________________________________________________________________________
795 Bool_t  AliAODEvent::IsPileupFromSPD(Int_t minContributors, 
796                                      Double_t minZdist, 
797                                      Double_t nSigmaZdist, 
798                                      Double_t nSigmaDiamXY, 
799                                      Double_t nSigmaDiamZ) const{
800   //
801   // This function checks if there was a pile up
802   // reconstructed with SPD
803   //
804   AliAODVertex *mainV=GetPrimaryVertexSPD();
805   if(!mainV) return kFALSE;
806   Int_t nc1=mainV->GetNContributors();
807   if(nc1<1) return kFALSE;
808   Int_t nPileVert=GetNumberOfPileupVerticesSPD();
809   if(nPileVert==0) return kFALSE;
810   Int_t nVertices=GetNumberOfVertices();
811   
812   for(Int_t iVert=0; iVert<nVertices; iVert++){
813     AliAODVertex *pv=GetVertex(iVert);
814     if(pv->GetType()!=AliAODVertex::kPileupSPD) continue;
815     Int_t nc2=pv->GetNContributors();
816     if(nc2>=minContributors){
817       Double_t z1=mainV->GetZ();
818       Double_t z2=pv->GetZ();
819       Double_t distZ=TMath::Abs(z2-z1);
820       Double_t distZdiam=TMath::Abs(z2-GetDiamondZ());
821       Double_t cutZdiam=nSigmaDiamZ*TMath::Sqrt(GetSigma2DiamondZ());
822       if(GetSigma2DiamondZ()<0.0001)cutZdiam=99999.; //protection for missing z diamond information
823       if(distZ>minZdist && distZdiam<cutZdiam){
824         Double_t x2=pv->GetX();
825         Double_t y2=pv->GetY();
826         Double_t distXdiam=TMath::Abs(x2-GetDiamondX());
827         Double_t distYdiam=TMath::Abs(y2-GetDiamondY());
828         Double_t cov1[6],cov2[6];       
829         mainV->GetCovarianceMatrix(cov1);
830         pv->GetCovarianceMatrix(cov2);
831         Double_t errxDist=TMath::Sqrt(cov2[0]+GetSigma2DiamondX());
832         Double_t erryDist=TMath::Sqrt(cov2[2]+GetSigma2DiamondY());
833         Double_t errzDist=TMath::Sqrt(cov1[5]+cov2[5]);
834         Double_t cutXdiam=nSigmaDiamXY*errxDist;
835         if(GetSigma2DiamondX()<0.0001)cutXdiam=99999.; //protection for missing diamond information
836         Double_t cutYdiam=nSigmaDiamXY*erryDist;
837         if(GetSigma2DiamondY()<0.0001)cutYdiam=99999.; //protection for missing diamond information
838         if( (distXdiam<cutXdiam) && (distYdiam<cutYdiam) && (distZ>nSigmaZdist*errzDist) ){
839           return kTRUE;
840         }
841       }
842     }
843   }
844   return kFALSE;
845 }
846
847 //______________________________________________________________________________
848 void AliAODEvent::Print(Option_t *) const
849 {
850   // Print the names of the all branches
851   TIter next(fAODObjects);
852   TNamed *el;
853   Printf(">>>>>  AOD  Content <<<<<");    
854   while((el=(TNamed*)next())){
855     Printf(">> %s ",el->GetName());      
856   }
857   Printf(">>>>>                <<<<<");    
858   
859   return;
860 }
861
862 void AliAODEvent::AssignIDtoCollection(const TCollection* col)
863 {
864     // Static method which assigns a ID to each object in a collection
865     // In this way the objects are marked as referenced and written with 
866     // an ID. This has the advantage that TRefs to this objects can be 
867     // written by a subsequent process.
868     TIter next(col);
869     TObject* obj;
870     while ((obj = next()))
871         TProcessID::AssignID(obj);
872 }
873
874 Bool_t AliAODEvent::IsPileupFromSPDInMultBins() const {
875     Int_t nTracklets=GetTracklets()->GetNumberOfTracklets();
876     if(nTracklets<20) return IsPileupFromSPD(3,0.8);
877     else if(nTracklets<50) return IsPileupFromSPD(4,0.8);
878     else return IsPileupFromSPD(5,0.8);
879 }
880
881 void AliAODEvent::Reset()
882 {
883   // Handle the cases
884   // Std content + Non std content
885
886   ClearStd();
887
888   if(fAODObjects->GetSize()>kAODListN){
889     // we have non std content
890     // this also covers aodfriends
891     for(int i = kAODListN;i < fAODObjects->GetSize();++i){
892       TObject *pObject = fAODObjects->At(i);
893       // TClonesArrays
894       if(pObject->InheritsFrom(TClonesArray::Class())){
895        ((TClonesArray*)pObject)->Delete();
896       }
897       else if(!pObject->InheritsFrom(TCollection::Class())){
898        TClass *pClass = TClass::GetClass(pObject->ClassName());
899        if (pClass && pClass->GetListOfMethods()->FindObject("Clear")) {
900          AliDebug(1, Form("Clear for object %s class %s", pObject->GetName(), pObject->ClassName()));
901          pObject->Clear();
902        }
903        else {
904          AliDebug(1, Form("ResetWithPlacementNew for object %s class %s", pObject->GetName(), pObject->ClassName()));
905           Long_t dtoronly = TObject::GetDtorOnly();
906           TObject::SetDtorOnly(pObject);
907           delete pObject;
908           pClass->New(pObject);
909           TObject::SetDtorOnly((void*)dtoronly);
910        }
911       }
912       else{
913        AliWarning(Form("No reset for %s \n",
914                        pObject->ClassName()));
915       }
916     }
917   }
918 }
919
920 Float_t AliAODEvent::GetVZEROEqMultiplicity(Int_t i) const
921 {
922   // Get VZERO Multiplicity for channel i
923   // Themethod uses the equalization factors
924   // stored in the ESD-run object in order to
925   // get equal multiplicities within a VZERO rins (1/8 of VZERO)
926   if (!fAODVZERO || !fHeader) return -1;
927
928   Int_t ring = i/8;
929   Float_t factorSum = 0;
930   for(Int_t j = 8*ring; j < (8*ring+8); ++j) {
931     factorSum += fHeader->GetVZEROEqFactors(j);
932   }
933   Float_t factor = fHeader->GetVZEROEqFactors(i)*8./factorSum;
934
935   return (fAODVZERO->GetMultiplicity(i)/factor);
936 }
937
938 //------------------------------------------------------------
939 void  AliAODEvent::SetTOFHeader(const AliTOFHeader *header)
940 {
941   //
942   // Set the TOF event_time
943   //
944
945   if (fTOFHeader) {
946     *fTOFHeader=*header;
947     //fTOFHeader->SetName(fgkESDListName[kTOFHeader]);
948   }
949   else {
950     // for analysis of reconstructed events
951     // when this information is not avaliable
952     fTOFHeader = new AliTOFHeader(*header);
953     //AddObject(fTOFHeader);
954   }
955
956 }
957 //------------------------------------------------------------
958 AliAODHMPIDrings *AliAODEvent::GetHMPIDringForTrackID(Int_t trackID)
959 {
960   //
961   // Returns the HMPID object if any for a given track ID
962   //
963   if(GetHMPIDrings())
964   {
965     for(Int_t ien = 0 ; ien < GetNHMPIDrings(); ien++)
966     {
967       if( ien == trackID ) return GetHMPIDring(ien);      
968     }//rings loop  
969   }
970   return 0;
971 }
972 //------------------------------------------------------------
973 Int_t AliAODEvent::GetNHMPIDrings()   
974
975   //
976   // If there is a list of HMPID rings in the given AOD event, return their number
977   //
978   if ( fHMPIDrings) return fHMPIDrings->GetEntriesFast(); 
979   else return -1;
980
981 //------------------------------------------------------------
982 AliAODHMPIDrings *AliAODEvent::GetHMPIDring(Int_t nRings)   
983
984   //
985   // If there is a list of HMPID rings in the given AOD event, return corresponding ring
986   //
987   if(fHMPIDrings) {
988     if(   (AliAODHMPIDrings*)fHMPIDrings->UncheckedAt(nRings) ) {
989       return (AliAODHMPIDrings*)fHMPIDrings->UncheckedAt(nRings);
990     }
991     else return 0x0;
992   }
993   else return 0x0;  
994 }
995 //------------------------------------------------------------