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