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