]>
Commit | Line | Data |
---|---|---|
df9db588 | 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 | ||
5c1dc41f | 23 | #include <TROOT.h> |
ec4af4c1 | 24 | #include <TTree.h> |
5c1dc41f | 25 | #include <TFolder.h> |
298d3d58 | 26 | #include <TFriendElement.h> |
c8e4f399 | 27 | #include <TProcessID.h> |
28 | #include <TCollection.h> | |
ec4af4c1 | 29 | |
df9db588 | 30 | #include "AliAODEvent.h" |
31 | #include "AliAODHeader.h" | |
32 | #include "AliAODTrack.h" | |
33 | ||
34 | ClassImp(AliAODEvent) | |
35 | ||
08e4c457 | 36 | // definition of std AOD member names |
37 | const char* AliAODEvent::fAODListName[kAODListN] = {"header", | |
38 | "tracks", | |
39 | "vertices", | |
3dd9f9e3 | 40 | "v0s", |
41 | "tracklets", | |
08e4c457 | 42 | "jets", |
37792174 | 43 | "emcalCells", |
44 | "phosCells", | |
3dd9f9e3 | 45 | "caloClusters", |
46 | "fmdClusters", | |
47 | "pmdClusters" | |
48 | }; | |
df9db588 | 49 | //______________________________________________________________________________ |
50 | AliAODEvent::AliAODEvent() : | |
08e4c457 | 51 | AliVEvent(), |
df9db588 | 52 | fAODObjects(new TList()), |
5c1dc41f | 53 | fAODFolder(0), |
ec4af4c1 | 54 | fHeader(0), |
55 | fTracks(0), | |
56 | fVertices(0), | |
3dd9f9e3 | 57 | fV0s(0), |
58 | fTracklets(0), | |
821f8f1d | 59 | fJets(0), |
37792174 | 60 | fEmcalCells(0), |
61 | fPhosCells(0), | |
3dd9f9e3 | 62 | fCaloClusters(0), |
63 | fFmdClusters(0), | |
64 | fPmdClusters(0) | |
df9db588 | 65 | { |
66 | // default constructor | |
67 | } | |
68 | ||
5c1dc41f | 69 | //______________________________________________________________________________ |
70 | AliAODEvent::AliAODEvent(const AliAODEvent& aod): | |
71 | AliVEvent(aod), | |
72 | fAODObjects(new TList()), | |
73 | fAODFolder(new TFolder()), | |
74 | fHeader(new AliAODHeader(*aod.fHeader)), | |
75 | fTracks(new TClonesArray(*aod.fTracks)), | |
76 | fVertices(new TClonesArray(*aod.fVertices)), | |
77 | fV0s(new TClonesArray(*aod.fV0s)), | |
78 | fTracklets(new AliAODTracklets(*aod.fTracklets)), | |
79 | fJets(new TClonesArray(*aod.fJets)), | |
80 | fEmcalCells(new AliAODCaloCells(*aod.fEmcalCells)), | |
81 | fPhosCells(new AliAODCaloCells(*aod.fPhosCells)), | |
82 | fCaloClusters(new TClonesArray(*aod.fCaloClusters)), | |
83 | fFmdClusters(new TClonesArray(*aod.fFmdClusters)), | |
84 | fPmdClusters(new TClonesArray(*aod.fPmdClusters)) | |
85 | { | |
86 | // Copy constructor | |
87 | AddObject(fHeader); | |
88 | AddObject(fTracks); | |
89 | AddObject(fVertices); | |
90 | AddObject(fV0s); | |
91 | AddObject(fTracklets); | |
92 | AddObject(fJets); | |
93 | AddObject(fEmcalCells); | |
94 | AddObject(fPhosCells); | |
95 | AddObject(fCaloClusters); | |
96 | AddObject(fFmdClusters); | |
97 | AddObject(fPmdClusters); | |
98 | ||
99 | GetStdContent(); | |
100 | } | |
101 | ||
102 | //______________________________________________________________________________ | |
103 | AliAODEvent & AliAODEvent::operator=(const AliAODEvent& aod) { | |
104 | ||
105 | // Assignment operator | |
106 | ||
107 | if(&aod == this) return *this; | |
108 | AliVEvent::operator=(aod); | |
109 | ||
110 | fAODObjects = new TList(); | |
111 | fAODFolder = new TFolder(); | |
112 | fHeader = new AliAODHeader(*aod.fHeader); | |
113 | fTracks = new TClonesArray(*aod.fTracks); | |
114 | fVertices = new TClonesArray(*aod.fVertices); | |
115 | fV0s = new TClonesArray(*aod.fV0s); | |
116 | fTracklets = new AliAODTracklets(*aod.fTracklets); | |
117 | fJets = new TClonesArray(*aod.fJets); | |
118 | fEmcalCells = new AliAODCaloCells(*aod.fEmcalCells); | |
119 | fPhosCells = new AliAODCaloCells(*aod.fPhosCells); | |
120 | fCaloClusters = new TClonesArray(*aod.fCaloClusters); | |
121 | fFmdClusters = new TClonesArray(*aod.fFmdClusters); | |
122 | fPmdClusters = new TClonesArray(*aod.fPmdClusters); | |
123 | ||
124 | fAODObjects = new TList(); | |
125 | ||
126 | AddObject(fHeader); | |
127 | AddObject(fTracks); | |
128 | AddObject(fVertices); | |
129 | AddObject(fV0s); | |
130 | AddObject(fTracklets); | |
131 | AddObject(fJets); | |
132 | AddObject(fEmcalCells); | |
133 | AddObject(fPhosCells); | |
134 | AddObject(fCaloClusters); | |
135 | AddObject(fFmdClusters); | |
136 | AddObject(fPmdClusters); | |
137 | GetStdContent(); | |
138 | return *this; | |
139 | } | |
140 | ||
141 | ||
df9db588 | 142 | //______________________________________________________________________________ |
143 | AliAODEvent::~AliAODEvent() | |
144 | { | |
ec4af4c1 | 145 | // destructor |
146 | delete fAODObjects; | |
5c1dc41f | 147 | delete fAODFolder; |
df9db588 | 148 | } |
149 | ||
150 | //______________________________________________________________________________ | |
151 | void AliAODEvent::AddObject(TObject* obj) | |
152 | { | |
4b3de353 | 153 | // Add an object to the list of objects. |
df9db588 | 154 | // Please be aware that in order to increase performance you should |
155 | // refrain from using TObjArrays (if possible). Use TClonesArrays, instead. | |
156 | ||
157 | fAODObjects->AddLast(obj); | |
158 | } | |
159 | ||
4b3de353 | 160 | //______________________________________________________________________________ |
161 | void AliAODEvent::RemoveObject(TObject* obj) | |
162 | { | |
163 | // Removes an object from the list of objects. | |
164 | ||
165 | fAODObjects->Remove(obj); | |
166 | } | |
167 | ||
df9db588 | 168 | //______________________________________________________________________________ |
08e4c457 | 169 | TObject *AliAODEvent::FindListObject(const char *objName) |
df9db588 | 170 | { |
171 | // Return the pointer to the object with the given name. | |
172 | ||
173 | return fAODObjects->FindObject(objName); | |
174 | } | |
175 | ||
176 | //______________________________________________________________________________ | |
177 | void AliAODEvent::CreateStdContent() | |
178 | { | |
179 | // create the standard AOD content and set pointers | |
180 | ||
181 | // create standard objects and add them to the TList of objects | |
182 | AddObject(new AliAODHeader()); | |
183 | AddObject(new TClonesArray("AliAODTrack", 0)); | |
184 | AddObject(new TClonesArray("AliAODVertex", 0)); | |
3dd9f9e3 | 185 | AddObject(new TClonesArray("AliAODv0", 0)); |
821f8f1d | 186 | AddObject(new AliAODTracklets()); |
3dd9f9e3 | 187 | AddObject(new TClonesArray("AliAODJet", 0)); |
188 | AddObject(new AliAODCaloCells()); | |
37792174 | 189 | AddObject(new AliAODCaloCells()); |
3dd9f9e3 | 190 | AddObject(new TClonesArray("AliAODCaloCluster", 0)); |
191 | AddObject(new TClonesArray("AliAODFmdCluster", 0)); | |
192 | AddObject(new TClonesArray("AliAODPmdCluster", 0)); | |
08e4c457 | 193 | // set names |
194 | SetStdNames(); | |
195 | ||
df9db588 | 196 | // read back pointers |
197 | GetStdContent(); | |
5c1dc41f | 198 | CreateStdFolders(); |
08e4c457 | 199 | return; |
df9db588 | 200 | } |
201 | ||
c8e4f399 | 202 | void AliAODEvent::MakeEntriesReferencable() |
203 | { | |
204 | // Make all entries referencable in a subsequent process | |
205 | // | |
206 | TIter next(fAODObjects); | |
207 | TObject* obj; | |
208 | while (obj = next()) | |
209 | { | |
210 | if(obj->InheritsFrom("TCollection")) | |
211 | { | |
212 | AssignIDtoCollection((TCollection*)obj); | |
213 | } | |
214 | } | |
215 | } | |
216 | ||
08e4c457 | 217 | //______________________________________________________________________________ |
218 | void AliAODEvent::SetStdNames() | |
219 | { | |
220 | // introduce the standard naming | |
221 | ||
222 | if(fAODObjects->GetEntries()==kAODListN){ | |
223 | for(int i = 0;i < fAODObjects->GetEntries();i++){ | |
224 | TObject *fObj = fAODObjects->At(i); | |
225 | if(fObj->InheritsFrom("TNamed")){ | |
226 | ((TNamed*)fObj)->SetName(fAODListName[i]); | |
227 | } | |
228 | else if(fObj->InheritsFrom("TClonesArray")){ | |
229 | ((TClonesArray*)fObj)->SetName(fAODListName[i]); | |
230 | } | |
231 | } | |
232 | } | |
233 | else{ | |
234 | printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__); | |
235 | } | |
236 | } | |
237 | ||
5c1dc41f | 238 | void AliAODEvent::CreateStdFolders() |
239 | { | |
240 | // Create the standard folder structure | |
241 | fAODFolder = gROOT->GetRootFolder()->AddFolder("AOD", "AOD"); | |
242 | if(fAODObjects->GetEntries()==kAODListN){ | |
243 | for(int i = 0;i < fAODObjects->GetEntries();i++){ | |
244 | TObject *fObj = fAODObjects->At(i); | |
245 | if(fObj->InheritsFrom("TClonesArray")){ | |
246 | fAODFolder->AddFolder(fAODListName[i], fAODListName[i], (TCollection*) fObj); | |
247 | } else { | |
248 | fAODFolder->AddFolder(fAODListName[i], fAODListName[i], 0); | |
249 | } | |
250 | } | |
251 | } | |
252 | else{ | |
253 | printf("%s:%d CreateStdFolders() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__); | |
254 | } | |
255 | } | |
256 | ||
df9db588 | 257 | //______________________________________________________________________________ |
ec4af4c1 | 258 | void AliAODEvent::GetStdContent() |
df9db588 | 259 | { |
260 | // set pointers for standard content | |
261 | ||
3dd9f9e3 | 262 | fHeader = (AliAODHeader*)fAODObjects->FindObject("header"); |
263 | fTracks = (TClonesArray*)fAODObjects->FindObject("tracks"); | |
264 | fVertices = (TClonesArray*)fAODObjects->FindObject("vertices"); | |
265 | fV0s = (TClonesArray*)fAODObjects->FindObject("v0s"); | |
266 | fTracklets = (AliAODTracklets*)fAODObjects->FindObject("tracklets"); | |
267 | fJets = (TClonesArray*)fAODObjects->FindObject("jets"); | |
37792174 | 268 | fEmcalCells = (AliAODCaloCells*)fAODObjects->FindObject("emcalCells"); |
269 | fPhosCells = (AliAODCaloCells*)fAODObjects->FindObject("phosCells"); | |
3dd9f9e3 | 270 | fCaloClusters = (TClonesArray*)fAODObjects->FindObject("caloClusters"); |
271 | fFmdClusters = (TClonesArray*)fAODObjects->FindObject("fmdClusters"); | |
272 | fPmdClusters = (TClonesArray*)fAODObjects->FindObject("pmdClusters"); | |
df9db588 | 273 | } |
274 | ||
275 | //______________________________________________________________________________ | |
3dd9f9e3 | 276 | void AliAODEvent::ResetStd(Int_t trkArrSize, |
277 | Int_t vtxArrSize, | |
278 | Int_t v0ArrSize, | |
279 | Int_t jetSize, | |
280 | Int_t caloClusSize, | |
281 | Int_t fmdClusSize, | |
282 | Int_t pmdClusSize) | |
df9db588 | 283 | { |
3dd9f9e3 | 284 | // deletes content of standard arrays and resets size |
df9db588 | 285 | fTracks->Delete(); |
286 | if (trkArrSize > fTracks->GetSize()) | |
287 | fTracks->Expand(trkArrSize); | |
288 | ||
289 | fVertices->Delete(); | |
290 | if (vtxArrSize > fVertices->GetSize()) | |
291 | fVertices->Expand(vtxArrSize); | |
3dd9f9e3 | 292 | |
293 | fV0s->Delete(); | |
294 | if (v0ArrSize > fV0s->GetSize()) | |
295 | fV0s->Expand(v0ArrSize); | |
296 | ||
297 | fJets->Delete(); | |
298 | if (jetSize > fJets->GetSize()) | |
299 | fJets->Expand(jetSize); | |
300 | ||
301 | fCaloClusters->Delete(); | |
302 | if (caloClusSize > fCaloClusters->GetSize()) | |
303 | fCaloClusters->Expand(caloClusSize); | |
304 | ||
305 | fFmdClusters->Delete(); | |
306 | if (fmdClusSize > fFmdClusters->GetSize()) | |
307 | fFmdClusters->Expand(fmdClusSize); | |
308 | ||
309 | fPmdClusters->Delete(); | |
310 | if (pmdClusSize > fPmdClusters->GetSize()) | |
311 | fPmdClusters->Expand(pmdClusSize); | |
6989bff3 | 312 | |
313 | // Reset the tracklets | |
314 | fTracklets->DeleteContainer(); | |
315 | fPhosCells->DeleteContainer(); | |
316 | fEmcalCells->DeleteContainer(); | |
317 | ||
df9db588 | 318 | } |
319 | ||
ec4af4c1 | 320 | void AliAODEvent::ClearStd() |
321 | { | |
322 | // clears the standard arrays | |
3dd9f9e3 | 323 | fTracks ->Clear(); |
324 | fVertices ->Clear(); | |
325 | fV0s ->Clear(); | |
326 | fTracklets ->DeleteContainer(); | |
1c37410a | 327 | fJets ->Delete(); |
37792174 | 328 | fEmcalCells ->DeleteContainer(); |
329 | fPhosCells ->DeleteContainer(); | |
330 | fCaloClusters ->Clear(); | |
331 | fFmdClusters ->Clear(); | |
332 | fPmdClusters ->Clear(); | |
ec4af4c1 | 333 | } |
334 | ||
78902954 | 335 | //_________________________________________________________________ |
336 | Int_t AliAODEvent::GetPHOSClusters(TRefArray *clusters) const | |
337 | { | |
338 | // fills the provided TRefArray with all found phos clusters | |
339 | ||
340 | clusters->Clear(); | |
341 | ||
342 | AliAODCaloCluster *cl = 0; | |
343 | for (Int_t i = 0; i < GetNCaloClusters() ; i++) { | |
344 | ||
345 | if ( (cl = GetCaloCluster(i)) ) { | |
346 | if (cl->IsPHOSCluster()){ | |
347 | clusters->Add(cl); | |
348 | //AliDebug(1,Form("IsPHOS cluster %d Size: %d \n",i,clusters->GetEntriesFast())); | |
349 | } | |
350 | } | |
351 | } | |
352 | return clusters->GetEntriesFast(); | |
353 | } | |
354 | ||
355 | //_________________________________________________________________ | |
356 | Int_t AliAODEvent::GetEMCALClusters(TRefArray *clusters) const | |
357 | { | |
358 | // fills the provided TRefArray with all found emcal clusters | |
359 | ||
360 | clusters->Clear(); | |
361 | ||
362 | AliAODCaloCluster *cl = 0; | |
363 | for (Int_t i = 0; i < GetNCaloClusters(); i++) { | |
364 | ||
365 | if ( (cl = GetCaloCluster(i)) ) { | |
366 | if (cl->IsEMCALCluster()){ | |
367 | clusters->Add(cl); | |
368 | //AliDebug(1,Form("IsEMCAL cluster %d Size: %d \n",i,clusters->GetEntriesFast())); | |
369 | } | |
370 | } | |
371 | } | |
372 | return clusters->GetEntriesFast(); | |
373 | } | |
374 | ||
375 | ||
fb41236c | 376 | //______________________________________________________________________________ |
377 | Int_t AliAODEvent::GetMuonTracks(TRefArray *muonTracks) const | |
378 | { | |
379 | // fills the provided TRefArray with all found muon tracks | |
df9db588 | 380 | |
fb41236c | 381 | muonTracks->Clear(); |
df9db588 | 382 | |
fb41236c | 383 | AliAODTrack *track = 0; |
384 | for (Int_t iTrack = 0; iTrack < GetNTracks(); iTrack++) { | |
08e4c457 | 385 | if ((track = GetTrack(iTrack))->IsMuonTrack()) { |
fb41236c | 386 | muonTracks->Add(track); |
387 | } | |
388 | } | |
389 | ||
3dd9f9e3 | 390 | return muonTracks->GetEntriesFast(); |
fb41236c | 391 | } |
ec4af4c1 | 392 | |
393 | ||
8ff33247 | 394 | void AliAODEvent::ReadFromTree(TTree *tree) |
395 | { | |
08e4c457 | 396 | // connects aod event to tree |
397 | ||
61cb38c7 | 398 | if(!tree){ |
399 | Printf("%s %d AliAODEvent::ReadFromTree() Zero Pointer to Tree \n",(char*)__FILE__,__LINE__); | |
400 | return; | |
401 | } | |
08e4c457 | 402 | // load the TTree |
61cb38c7 | 403 | if(!tree->GetTree())tree->LoadTree(0); |
404 | ||
405 | // Try to find AliAODEvent | |
406 | AliAODEvent *aodEvent = 0; | |
407 | aodEvent = (AliAODEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliAODEvent"); | |
408 | if(aodEvent){ | |
409 | // Check if already connected to tree | |
410 | TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("AODObjectsConnectedToTree")); | |
411 | if (connectedList) { | |
412 | // If connected use the connected list if objects | |
413 | fAODObjects->Delete(); | |
414 | fAODObjects = connectedList; | |
415 | GetStdContent(); | |
416 | return; | |
417 | } | |
418 | // Connect to tree | |
419 | // prevent a memory leak when reading back the TList | |
420 | delete fAODObjects; | |
421 | fAODObjects = 0; | |
422 | // create a new TList from the UserInfo TList... | |
423 | // copy constructor does not work... | |
424 | fAODObjects = (TList*)(aodEvent->GetList()->Clone()); | |
425 | fAODObjects->SetOwner(kFALSE); | |
426 | if(fAODObjects->GetEntries()<kAODListN){ | |
427 | printf("%s %d AliAODEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n", | |
428 | (char*)__FILE__,__LINE__,fAODObjects->GetEntries(),kAODListN); | |
429 | } | |
298d3d58 | 430 | // |
431 | // Let's find out whether we have friends | |
ced57103 | 432 | TList* friendL = tree->GetTree()->GetListOfFriends(); |
298d3d58 | 433 | if (friendL) |
434 | { | |
435 | TIter next(friendL); | |
436 | TFriendElement* fe; | |
437 | while ((fe = (TFriendElement*)next())){ | |
438 | aodEvent = (AliAODEvent*)(fe->GetTree()->GetUserInfo()->FindObject("AliAODEvent")); | |
439 | if (!aodEvent) { | |
440 | printf("No UserInfo on tree \n"); | |
441 | } else { | |
442 | ||
443 | TList* objL = (TList*)(aodEvent->GetList()->Clone()); | |
444 | printf("Get list of object from tree %d !!\n", objL->GetEntries()); | |
445 | TIter nextobject(objL); | |
446 | TObject* obj = 0; | |
447 | while(obj = nextobject()) | |
448 | { | |
449 | printf("Adding object from friend %s !\n", obj->GetName()); | |
450 | fAODObjects->Add(obj); | |
451 | } // object "branch" loop | |
452 | } // has userinfo | |
453 | } // friend loop | |
454 | } // has friends | |
455 | ||
456 | ||
457 | // set the branch addresses | |
61cb38c7 | 458 | TIter next(fAODObjects); |
459 | TNamed *el; | |
460 | while((el=(TNamed*)next())){ | |
461 | TString bname(el->GetName()); | |
462 | // check if branch exists under this Name | |
ced57103 | 463 | printf("Trying to connect branch %s\n", bname.Data()); |
464 | TBranch *br = tree->GetTree()->GetBranch(bname.Data()); | |
61cb38c7 | 465 | if(br){ |
466 | tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el)); | |
ced57103 | 467 | } else { |
298d3d58 | 468 | br = tree->GetBranch(Form("%s.",bname.Data())); |
469 | if(br){ | |
470 | tree->SetBranchAddress(Form("%s.",bname.Data()),fAODObjects->GetObjectRef(el)); | |
471 | } | |
472 | else{ | |
473 | printf("%s %d AliAODEvent::ReadFromTree() No Branch found with Name %s. \n", | |
474 | (char*)__FILE__,__LINE__,bname.Data()); | |
475 | } | |
61cb38c7 | 476 | } |
477 | } | |
61cb38c7 | 478 | GetStdContent(); |
479 | // when reading back we are not owner of the list | |
480 | // must not delete it | |
481 | fAODObjects->SetOwner(kFALSE); | |
482 | fAODObjects->SetName("AODObjectsConnectedToTree"); | |
483 | // we are not owner of the list objects | |
484 | // must not delete it | |
485 | tree->GetUserInfo()->Add(fAODObjects); | |
486 | }// no aodEvent | |
487 | else { | |
488 | // we can't get the list from the user data, create standard content | |
489 | // and set it by hand | |
490 | CreateStdContent(); | |
491 | TIter next(fAODObjects); | |
492 | TNamed *el; | |
493 | while((el=(TNamed*)next())){ | |
494 | TString bname(el->GetName()); | |
495 | tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el)); | |
496 | } | |
497 | GetStdContent(); | |
498 | // when reading back we are not owner of the list | |
499 | // must not delete it | |
500 | fAODObjects->SetOwner(kFALSE); | |
08e4c457 | 501 | } |
8ff33247 | 502 | } |
503 | ||
08e4c457 | 504 | //______________________________________________________________________________ |
505 | void AliAODEvent::Print(Option_t *) const | |
506 | { | |
507 | // Something meaningful should be implemented here. | |
508 | ||
509 | return; | |
510 | } | |
c8e4f399 | 511 | |
512 | void AliAODEvent::AssignIDtoCollection(TCollection* col) | |
513 | { | |
514 | // Static method which assigns a ID to each object in a collection | |
515 | // In this way the objects are marked as referenced and written with | |
516 | // an ID. This has the advantage that TRefs to this objects can be | |
517 | // written by a subsequent process. | |
518 | TIter next(col); | |
519 | TObject* obj; | |
520 | while (obj = next()) | |
521 | TProcessID::AssignID(obj); | |
522 | } |