1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-------------------------------------------------------------------------
20 // Author: Markus Oldenburg, CERN
21 //-------------------------------------------------------------------------
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"
36 // definition of std AOD member names
37 const char* AliAODEvent::fAODListName[kAODListN] = {"header",
51 //______________________________________________________________________________
52 AliAODEvent::AliAODEvent() :
54 fAODObjects(new TList()),
70 // default constructor
73 //______________________________________________________________________________
74 AliAODEvent::AliAODEvent(const AliAODEvent& aod):
76 fAODObjects(new TList()),
77 fAODFolder(new TFolder()),
79 fHeader(new AliAODHeader(*aod.fHeader)),
80 fTracks(new TClonesArray(*aod.fTracks)),
81 fVertices(new TClonesArray(*aod.fVertices)),
82 fV0s(new TClonesArray(*aod.fV0s)),
83 fCascades(new TClonesArray(*aod.fCascades)),
84 fTracklets(new AliAODTracklets(*aod.fTracklets)),
85 fJets(new TClonesArray(*aod.fJets)),
86 fEmcalCells(new AliAODCaloCells(*aod.fEmcalCells)),
87 fPhosCells(new AliAODCaloCells(*aod.fPhosCells)),
88 fCaloClusters(new TClonesArray(*aod.fCaloClusters)),
89 fFmdClusters(new TClonesArray(*aod.fFmdClusters)),
90 fPmdClusters(new TClonesArray(*aod.fPmdClusters))
98 AddObject(fTracklets);
100 AddObject(fEmcalCells);
101 AddObject(fPhosCells);
102 AddObject(fCaloClusters);
103 AddObject(fFmdClusters);
104 AddObject(fPmdClusters);
105 fConnected = aod.fConnected;
109 //______________________________________________________________________________
110 AliAODEvent & AliAODEvent::operator=(const AliAODEvent& aod) {
112 // Assignment operator
114 if(&aod == this) return *this;
115 AliVEvent::operator=(aod);
117 fAODObjects = new TList();
118 fAODFolder = new TFolder();
119 fConnected = aod.fConnected;
120 fHeader = new AliAODHeader(*aod.fHeader);
121 fTracks = new TClonesArray(*aod.fTracks);
122 fVertices = new TClonesArray(*aod.fVertices);
123 fV0s = new TClonesArray(*aod.fV0s);
124 fCascades = new TClonesArray(*aod.fCascades);
125 fTracklets = new AliAODTracklets(*aod.fTracklets);
126 fJets = new TClonesArray(*aod.fJets);
127 fEmcalCells = new AliAODCaloCells(*aod.fEmcalCells);
128 fPhosCells = new AliAODCaloCells(*aod.fPhosCells);
129 fCaloClusters = new TClonesArray(*aod.fCaloClusters);
130 fFmdClusters = new TClonesArray(*aod.fFmdClusters);
131 fPmdClusters = new TClonesArray(*aod.fPmdClusters);
133 fAODObjects = new TList();
137 AddObject(fVertices);
139 AddObject(fCascades);
140 AddObject(fTracklets);
142 AddObject(fEmcalCells);
143 AddObject(fPhosCells);
144 AddObject(fCaloClusters);
145 AddObject(fFmdClusters);
146 AddObject(fPmdClusters);
152 //______________________________________________________________________________
153 AliAODEvent::~AliAODEvent()
156 if(fAODObjects&&!fConnected)
165 //______________________________________________________________________________
166 void AliAODEvent::AddObject(TObject* obj)
168 // Add an object to the list of objects.
169 // Please be aware that in order to increase performance you should
170 // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
172 fAODObjects->AddLast(obj);
175 //______________________________________________________________________________
176 void AliAODEvent::RemoveObject(TObject* obj)
178 // Removes an object from the list of objects.
180 fAODObjects->Remove(obj);
183 //______________________________________________________________________________
184 TObject *AliAODEvent::FindListObject(const char *objName)
186 // Return the pointer to the object with the given name.
188 return fAODObjects->FindObject(objName);
191 //______________________________________________________________________________
192 void AliAODEvent::CreateStdContent()
194 // create the standard AOD content and set pointers
196 // create standard objects and add them to the TList of objects
197 AddObject(new AliAODHeader());
198 AddObject(new TClonesArray("AliAODTrack", 0));
199 AddObject(new TClonesArray("AliAODVertex", 0));
200 AddObject(new TClonesArray("AliAODv0", 0));
201 AddObject(new TClonesArray("AliAODcascade", 0));
202 AddObject(new AliAODTracklets());
203 AddObject(new TClonesArray("AliAODJet", 0));
204 AddObject(new AliAODCaloCells());
205 AddObject(new AliAODCaloCells());
206 AddObject(new TClonesArray("AliAODCaloCluster", 0));
207 AddObject(new TClonesArray("AliAODFmdCluster", 0));
208 AddObject(new TClonesArray("AliAODPmdCluster", 0));
212 // read back pointers
218 void AliAODEvent::MakeEntriesReferencable()
220 // Make all entries referencable in a subsequent process
222 TIter next(fAODObjects);
224 while ((obj = next()))
226 if(obj->InheritsFrom("TCollection"))
228 AssignIDtoCollection((TCollection*)obj);
233 //______________________________________________________________________________
234 void AliAODEvent::SetStdNames()
236 // introduce the standard naming
238 if(fAODObjects->GetEntries()==kAODListN){
239 for(int i = 0;i < fAODObjects->GetEntries();i++){
240 TObject *fObj = fAODObjects->At(i);
241 if(fObj->InheritsFrom("TNamed")){
242 ((TNamed*)fObj)->SetName(fAODListName[i]);
244 else if(fObj->InheritsFrom("TClonesArray")){
245 ((TClonesArray*)fObj)->SetName(fAODListName[i]);
250 printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
254 void AliAODEvent::CreateStdFolders()
256 // Create the standard folder structure
257 fAODFolder = gROOT->GetRootFolder()->AddFolder("AOD", "AOD");
258 if(fAODObjects->GetEntries()==kAODListN){
259 for(int i = 0;i < fAODObjects->GetEntries();i++){
260 TObject *fObj = fAODObjects->At(i);
261 if(fObj->InheritsFrom("TClonesArray")){
262 fAODFolder->AddFolder(fAODListName[i], fAODListName[i], (TCollection*) fObj);
264 fAODFolder->AddFolder(fAODListName[i], fAODListName[i], 0);
269 printf("%s:%d CreateStdFolders() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
273 //______________________________________________________________________________
274 void AliAODEvent::GetStdContent()
276 // set pointers for standard content
278 fHeader = (AliAODHeader*)fAODObjects->FindObject("header");
279 fTracks = (TClonesArray*)fAODObjects->FindObject("tracks");
280 fVertices = (TClonesArray*)fAODObjects->FindObject("vertices");
281 fV0s = (TClonesArray*)fAODObjects->FindObject("v0s");
282 fCascades = (TClonesArray*)fAODObjects->FindObject("cascades");
283 fTracklets = (AliAODTracklets*)fAODObjects->FindObject("tracklets");
284 fJets = (TClonesArray*)fAODObjects->FindObject("jets");
285 fEmcalCells = (AliAODCaloCells*)fAODObjects->FindObject("emcalCells");
286 fPhosCells = (AliAODCaloCells*)fAODObjects->FindObject("phosCells");
287 fCaloClusters = (TClonesArray*)fAODObjects->FindObject("caloClusters");
288 fFmdClusters = (TClonesArray*)fAODObjects->FindObject("fmdClusters");
289 fPmdClusters = (TClonesArray*)fAODObjects->FindObject("pmdClusters");
292 //______________________________________________________________________________
293 void AliAODEvent::ResetStd(Int_t trkArrSize,
296 Int_t cascadeArrSize,
303 // deletes content of standard arrays and resets size
306 if (trkArrSize > fTracks->GetSize())
307 fTracks->Expand(trkArrSize);
310 if (vtxArrSize > fVertices->GetSize())
311 fVertices->Expand(vtxArrSize);
314 if (v0ArrSize > fV0s->GetSize())
315 fV0s->Expand(v0ArrSize);
318 if (cascadeArrSize > fCascades->GetSize())
319 fCascades->Expand(cascadeArrSize);
322 if (jetSize > fJets->GetSize())
323 fJets->Expand(jetSize);
325 fCaloClusters->Delete();
326 if (caloClusSize > fCaloClusters->GetSize())
327 fCaloClusters->Expand(caloClusSize);
329 fFmdClusters->Delete();
330 if (fmdClusSize > fFmdClusters->GetSize())
331 fFmdClusters->Expand(fmdClusSize);
333 fPmdClusters->Delete();
334 if (pmdClusSize > fPmdClusters->GetSize())
335 fPmdClusters->Expand(pmdClusSize);
337 // Reset the tracklets
338 fTracklets->DeleteContainer();
339 fPhosCells->DeleteContainer();
340 fEmcalCells->DeleteContainer();
344 void AliAODEvent::ClearStd()
346 // clears the standard arrays
347 fHeader ->RemoveQTheta();
349 fVertices ->Delete();
351 fCascades ->Delete();
352 fTracklets ->DeleteContainer();
354 fEmcalCells ->DeleteContainer();
355 fPhosCells ->DeleteContainer();
356 fCaloClusters ->Delete();
357 fFmdClusters ->Clear();
358 fPmdClusters ->Clear();
361 //_________________________________________________________________
362 Int_t AliAODEvent::GetPHOSClusters(TRefArray *clusters) const
364 // fills the provided TRefArray with all found phos clusters
368 AliAODCaloCluster *cl = 0;
369 Bool_t first = kTRUE;
370 for (Int_t i = 0; i < GetNCaloClusters() ; i++) {
371 if ( (cl = GetCaloCluster(i)) ) {
372 if (cl->IsPHOSCluster()){
374 new (clusters) TRefArray(TProcessID::GetProcessWithUID(cl));
378 //printf("IsPHOS cluster %d, E %2.3f Size: %d \n",i,cl->E(),clusters->GetEntriesFast());
382 return clusters->GetEntriesFast();
385 //_________________________________________________________________
386 Int_t AliAODEvent::GetEMCALClusters(TRefArray *clusters) const
388 // fills the provided TRefArray with all found emcal clusters
391 cout<<"AOD event 1: nclus "<<GetNCaloClusters()<<endl;
392 AliAODCaloCluster *cl = 0;
393 Bool_t first = kTRUE;
394 for (Int_t i = 0; i < GetNCaloClusters(); i++) {
395 if ( (cl = GetCaloCluster(i)) ) {
396 if (cl->IsEMCALCluster()){
398 new (clusters) TRefArray(TProcessID::GetProcessWithUID(cl));
402 //printf("IsEMCal cluster %d, E %2.3f Size: %d \n",i,cl->E(),clusters->GetEntriesFast());
406 return clusters->GetEntriesFast();
410 //______________________________________________________________________________
411 Int_t AliAODEvent::GetMuonTracks(TRefArray *muonTracks) const
413 // fills the provided TRefArray with all found muon tracks
417 AliAODTrack *track = 0;
418 for (Int_t iTrack = 0; iTrack < GetNTracks(); iTrack++) {
419 if ((track = GetTrack(iTrack))->IsMuonTrack()) {
420 muonTracks->Add(track);
424 return muonTracks->GetEntriesFast();
428 void AliAODEvent::ReadFromTree(TTree *tree, Option_t* opt /*= ""*/)
430 // Connects aod event to tree
433 Printf("%s %d AliAODEvent::ReadFromTree() Zero Pointer to Tree \n",(char*)__FILE__,__LINE__);
437 if(!tree->GetTree())tree->LoadTree(0);
439 // Try to find AliAODEvent
440 AliAODEvent *aodEvent = 0;
441 aodEvent = (AliAODEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliAODEvent");
443 // Check if already connected to tree
444 TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("AODObjectsConnectedToTree"));
445 if (connectedList && (strcmp(opt, "reconnect"))) {
446 // If connected use the connected list of objects
447 printf("Delete and reconnect \n");
449 fAODObjects->Delete();
450 fAODObjects = connectedList;
456 // prevent a memory leak when reading back the TList
457 if (!(strcmp(opt, "reconnect"))) fAODObjects->Delete();
460 // create a new TList from the UserInfo TList...
461 // copy constructor does not work...
462 fAODObjects = (TList*)(aodEvent->GetList()->Clone());
463 fAODObjects->SetOwner(kFALSE);
464 if(fAODObjects->GetEntries()<kAODListN){
465 printf("%s %d AliAODEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
466 (char*)__FILE__,__LINE__,fAODObjects->GetEntries(),kAODListN);
469 // Let's find out whether we have friends
470 TList* friendL = tree->GetTree()->GetListOfFriends();
475 while ((fe = (TFriendElement*)next())){
476 aodEvent = (AliAODEvent*)(fe->GetTree()->GetUserInfo()->FindObject("AliAODEvent"));
478 printf("No UserInfo on tree \n");
481 TList* objL = (TList*)(aodEvent->GetList()->Clone());
482 printf("Get list of object from tree %d !!\n", objL->GetEntries());
483 TIter nextobject(objL);
485 while((obj = nextobject()))
487 printf("Adding object from friend %s !\n", obj->GetName());
488 fAODObjects->Add(obj);
489 } // object "branch" loop
495 // set the branch addresses
496 TIter next(fAODObjects);
498 while((el=(TNamed*)next())){
499 TString bname(el->GetName());
500 // check if branch exists under this Name
501 TBranch *br = tree->GetTree()->GetBranch(bname.Data());
503 tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
505 br = tree->GetBranch(Form("%s.",bname.Data()));
507 tree->SetBranchAddress(Form("%s.",bname.Data()),fAODObjects->GetObjectRef(el));
510 printf("%s %d AliAODEvent::ReadFromTree() No Branch found with Name %s. \n",
511 (char*)__FILE__,__LINE__,bname.Data());
516 // when reading back we are not owner of the list
517 // must not delete it
518 fAODObjects->SetOwner(kFALSE);
519 fAODObjects->SetName("AODObjectsConnectedToTree");
520 // we are not owner of the list objects
521 // must not delete it
522 tree->GetUserInfo()->Add(fAODObjects);
526 // we can't get the list from the user data, create standard content
527 // and set it by hand
529 TIter next(fAODObjects);
531 while((el=(TNamed*)next())){
532 TString bname(el->GetName());
533 tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
536 // when reading back we are not owner of the list
537 // must not delete it
538 fAODObjects->SetOwner(kFALSE);
542 //______________________________________________________________________________
543 void AliAODEvent::Print(Option_t *) const
545 // Something meaningful should be implemented here.
550 void AliAODEvent::AssignIDtoCollection(TCollection* col)
552 // Static method which assigns a ID to each object in a collection
553 // In this way the objects are marked as referenced and written with
554 // an ID. This has the advantage that TRefs to this objects can be
555 // written by a subsequent process.
558 while ((obj = next()))
559 TProcessID::AssignID(obj);