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