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