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