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