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