Update master to aliroot
[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
95//______________________________________________________________________________
5c1dc41f 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
252//______________________________________________________________________________
df9db588 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
281//______________________________________________________________________________
d38034b8 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
290//______________________________________________________________________________
4b3de353 291void AliAODEvent::RemoveObject(TObject* obj)
292{
293 // Removes an object from the list of objects.
294
295 fAODObjects->Remove(obj);
296}
297
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
df9db588 357//______________________________________________________________________________
08e4c457 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
08e4c457 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++) {
4cd87297 624 track = dynamic_cast<AliAODTrack*>(GetTrack(iTrack));
625 if(!track) AliFatal("Not a standard AOD");
11becff8 626 if (track->IsMuonTrack()) {
fb41236c 627 muonTracks->Add(track);
628 }
629 }
630
3dd9f9e3 631 return muonTracks->GetEntriesFast();
fb41236c 632}
ec4af4c1 633
634
fa8b0e56 635//______________________________________________________________________________
636Int_t AliAODEvent::GetNumberOfMuonTracks() const
637{
638 // get number of muon tracks
2534dbc7 639 int ntr = GetNumberOfTracks();
640 if (!ntr) return 0;
fa8b0e56 641 Int_t nMuonTracks=0;
4cd87297 642 if(!dynamic_cast<AliAODTrack*>(GetTrack(0))) {
643 AliError("Not a standard AOD");
644 return 0;
645 }
646
2534dbc7 647 for (Int_t iTrack=ntr; iTrack--;) {
4cd87297 648 if (((AliAODTrack*)GetTrack(iTrack))->IsMuonTrack()) {
fa8b0e56 649 nMuonTracks++;
650 }
651 }
652
653 return nMuonTracks;
654}
655
788578f5 656//______________________________________________________________________________
f7cc8591 657Int_t AliAODEvent::GetMuonGlobalTracks(TRefArray *muonGlobalTracks) const // AU
658{
659 // fills the provided TRefArray with all found muon global tracks
660
661 muonGlobalTracks->Clear();
662
663 AliAODTrack *track = 0;
4640c275 664 for (Int_t iTrack = 0; iTrack < GetNumberOfTracks(); iTrack++) {
4cd87297 665 track = dynamic_cast<AliAODTrack*>(GetTrack(iTrack));
666 if(!track) AliFatal("Not a standard AOD");
f7cc8591 667 if (track->IsMuonGlobalTrack()) {
668 muonGlobalTracks->Add(track);
669 }
670 }
671
672 return muonGlobalTracks->GetEntriesFast();
673}
674
675
676//______________________________________________________________________________
677Int_t AliAODEvent::GetNumberOfMuonGlobalTracks() const // AU
678{
679 // get number of muon global tracks
2534dbc7 680 int ntr = GetNumberOfTracks();
681 if (!ntr) return 0;
f7cc8591 682 Int_t nMuonGlobalTracks=0;
4cd87297 683 if(!dynamic_cast<AliAODTrack*>(GetTrack(0))) {
684 AliError("Not a standard AOD");
685 return 0;
686 }
2534dbc7 687 for (Int_t iTrack=ntr; iTrack--;) {
4cd87297 688 if (((AliAODTrack*)GetTrack(iTrack))->IsMuonGlobalTrack()) {
f7cc8591 689 nMuonGlobalTracks++;
690 }
691 }
692
693 return nMuonGlobalTracks;
694}
695
696//______________________________________________________________________________
3b93c32a 697void AliAODEvent::ReadFromTree(TTree *tree, Option_t* opt /*= ""*/)
8ff33247 698{
c8fe2783 699 // Connects aod event to tree
08e4c457 700
61cb38c7 701 if(!tree){
788578f5 702 AliWarning("Zero Pointer to Tree \n");
61cb38c7 703 return;
704 }
c8fe2783 705 // load the TTree
61cb38c7 706 if(!tree->GetTree())tree->LoadTree(0);
c8fe2783 707
708 // Try to find AliAODEvent
61cb38c7 709 AliAODEvent *aodEvent = 0;
710 aodEvent = (AliAODEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliAODEvent");
711 if(aodEvent){
788578f5 712 // This event is connected to the tree by definition, just say so
713 aodEvent->SetConnected();
c8fe2783 714 // Check if already connected to tree
61cb38c7 715 TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("AODObjectsConnectedToTree"));
5fdc7d49 716 if (connectedList && (!strcmp(opt, "reconnect"))) {
c8fe2783 717 // If connected use the connected list of objects
5fdc7d49 718 if (fAODObjects != connectedList) {
719 delete fAODObjects;
720 fAODObjects = connectedList;
721 }
722 GetStdContent();
723 fConnected = kTRUE;
724 return;
d8f5fda5 725 }
c8fe2783 726 // Connect to tree
727 // prevent a memory leak when reading back the TList
28a79204 728// if (!(strcmp(opt, "reconnect"))) fAODObjects->Delete();
c8fe2783 729
730 // create a new TList from the UserInfo TList...
731 // copy constructor does not work...
1ee5d9a3 732 // fAODObjects = (TList*)(aodEvent->GetList()->Clone());
733 fAODObjects = (TList*)aodEvent->GetList();
316cf4cc 734 fAODObjects->SetOwner(kTRUE);
14d6fad5 735 if(fAODObjects->GetEntries()<kAODListN)
736 {
737 AliWarning(Form("AliAODEvent::ReadFromTree() TList contains less than the standard contents %d < %d"
738 " That might be fine though (at least for filtered AODs)",fAODObjects->GetEntries(),kAODListN));
61cb38c7 739 }
c8fe2783 740 //
741 // Let's find out whether we have friends
ced57103 742 TList* friendL = tree->GetTree()->GetListOfFriends();
298d3d58 743 if (friendL)
744 {
c8fe2783 745 TIter next(friendL);
746 TFriendElement* fe;
747 while ((fe = (TFriendElement*)next())){
748 aodEvent = (AliAODEvent*)(fe->GetTree()->GetUserInfo()->FindObject("AliAODEvent"));
749 if (!aodEvent) {
750 printf("No UserInfo on tree \n");
751 } else {
752
1ee5d9a3 753 // TList* objL = (TList*)(aodEvent->GetList()->Clone());
08b38f3f 754 TList* objL = (TList*)aodEvent->GetList();
755 printf("Get list of object from tree %d !!\n", objL->GetEntries());
756 TIter nextobject(objL);
757 TObject* obj = 0;
758 while((obj = nextobject()))
c8fe2783 759 {
08b38f3f 760 printf("Adding object from friend %s !\n", obj->GetName());
761 fAODObjects->Add(obj);
c8fe2783 762 } // object "branch" loop
08b38f3f 763 } // has userinfo
c8fe2783 764 } // friend loop
298d3d58 765 } // has friends
c8fe2783 766 // set the branch addresses
61cb38c7 767 TIter next(fAODObjects);
768 TNamed *el;
769 while((el=(TNamed*)next())){
770 TString bname(el->GetName());
c8fe2783 771 // check if branch exists under this Name
ced57103 772 TBranch *br = tree->GetTree()->GetBranch(bname.Data());
61cb38c7 773 if(br){
c8fe2783 774 tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
ced57103 775 } else {
c8fe2783 776 br = tree->GetBranch(Form("%s.",bname.Data()));
777 if(br){
778 tree->SetBranchAddress(Form("%s.",bname.Data()),fAODObjects->GetObjectRef(el));
779 }
780 else{
781 printf("%s %d AliAODEvent::ReadFromTree() No Branch found with Name %s. \n",
782 (char*)__FILE__,__LINE__,bname.Data());
783 }
61cb38c7 784 }
785 }
61cb38c7 786 GetStdContent();
c8fe2783 787 // when reading back we are not owner of the list
788 // must not delete it
316cf4cc 789 fAODObjects->SetOwner(kTRUE);
61cb38c7 790 fAODObjects->SetName("AODObjectsConnectedToTree");
c8fe2783 791 // we are not owner of the list objects
792 // must not delete it
61cb38c7 793 tree->GetUserInfo()->Add(fAODObjects);
dd389a30 794 fConnected = kTRUE;
61cb38c7 795 }// no aodEvent
796 else {
c8fe2783 797 // we can't get the list from the user data, create standard content
798 // and set it by hand
61cb38c7 799 CreateStdContent();
800 TIter next(fAODObjects);
801 TNamed *el;
802 while((el=(TNamed*)next())){
803 TString bname(el->GetName());
804 tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
805 }
806 GetStdContent();
c8fe2783 807 // when reading back we are not owner of the list
808 // must not delete it
316cf4cc 809 fAODObjects->SetOwner(kTRUE);
08e4c457 810 }
8ff33247 811}
c8fe2783 812 //______________________________________________________________________________
a98c78e5 813Int_t AliAODEvent::GetNumberOfPileupVerticesSPD() const{
814 // count number of SPD pileup vertices
815 Int_t nVertices=GetNumberOfVertices();
816 Int_t nPileupVertices=0;
817 for(Int_t iVert=0; iVert<nVertices; iVert++){
818 AliAODVertex *v=GetVertex(iVert);
819 if(v->GetType()==AliAODVertex::kPileupSPD) nPileupVertices++;
820 }
821 return nPileupVertices;
822}
823//______________________________________________________________________________
824Int_t AliAODEvent::GetNumberOfPileupVerticesTracks() const{
825 // count number of track pileup vertices
826 Int_t nVertices=GetNumberOfVertices();
827 Int_t nPileupVertices=0;
828 for(Int_t iVert=0; iVert<nVertices; iVert++){
829 AliAODVertex *v=GetVertex(iVert);
830 if(v->GetType()==AliAODVertex::kPileupTracks) nPileupVertices++;
831 }
832 return nPileupVertices;
833}
834//______________________________________________________________________________
835AliAODVertex* AliAODEvent::GetPrimaryVertexSPD() const{
5e6a3170 836 // Get SPD primary vertex
a98c78e5 837 Int_t nVertices=GetNumberOfVertices();
838 for(Int_t iVert=0; iVert<nVertices; iVert++){
839 AliAODVertex *v=GetVertex(iVert);
840 if(v->GetType()==AliAODVertex::kMainSPD) return v;
841 }
842 return 0;
843}
844//______________________________________________________________________________
c4d9b22d 845AliAODVertex* AliAODEvent::GetPrimaryVertexTPC() const{
846 // Get SPD primary vertex
847 Int_t nVertices=GetNumberOfVertices();
848 for(Int_t iVert=0; iVert<nVertices; iVert++){
849 AliAODVertex *v=GetVertex(iVert);
850 if(v->GetType()==AliAODVertex::kMainTPC) return v;
851 }
852 return 0;
853}
854//______________________________________________________________________________
a98c78e5 855AliAODVertex* AliAODEvent::GetPileupVertexSPD(Int_t iV) const{
5e6a3170 856 // Get pile-up vertex iV
a98c78e5 857 Int_t nVertices=GetNumberOfVertices();
858 Int_t counter=0;
859 for(Int_t iVert=0; iVert<nVertices; iVert++){
860 AliAODVertex *v=GetVertex(iVert);
861 if(v->GetType()==AliAODVertex::kPileupSPD){
862 if(counter==iV) return v;
863 ++counter;
864 }
865 }
866 return 0;
867}
868//______________________________________________________________________________
869AliAODVertex* AliAODEvent::GetPileupVertexTracks(Int_t iV) const{
5e6a3170 870 // Get pile-up vertex iV
a98c78e5 871 Int_t nVertices=GetNumberOfVertices();
872 Int_t counter=0;
873 for(Int_t iVert=0; iVert<nVertices; iVert++){
874 AliAODVertex *v=GetVertex(iVert);
875 if(v->GetType()==AliAODVertex::kPileupTracks){
876 if(counter==iV) return v;
877 ++counter;
878 }
879 }
880 return 0;
881}
882//______________________________________________________________________________
883Bool_t AliAODEvent::IsPileupFromSPD(Int_t minContributors,
884 Double_t minZdist,
885 Double_t nSigmaZdist,
886 Double_t nSigmaDiamXY,
887 Double_t nSigmaDiamZ) const{
888 //
889 // This function checks if there was a pile up
890 // reconstructed with SPD
891 //
892 AliAODVertex *mainV=GetPrimaryVertexSPD();
893 if(!mainV) return kFALSE;
894 Int_t nc1=mainV->GetNContributors();
895 if(nc1<1) return kFALSE;
896 Int_t nPileVert=GetNumberOfPileupVerticesSPD();
897 if(nPileVert==0) return kFALSE;
898 Int_t nVertices=GetNumberOfVertices();
899
900 for(Int_t iVert=0; iVert<nVertices; iVert++){
901 AliAODVertex *pv=GetVertex(iVert);
902 if(pv->GetType()!=AliAODVertex::kPileupSPD) continue;
903 Int_t nc2=pv->GetNContributors();
904 if(nc2>=minContributors){
905 Double_t z1=mainV->GetZ();
906 Double_t z2=pv->GetZ();
907 Double_t distZ=TMath::Abs(z2-z1);
908 Double_t distZdiam=TMath::Abs(z2-GetDiamondZ());
569d954c 909 Double_t cutZdiam=nSigmaDiamZ*TMath::Sqrt(GetSigma2DiamondZ());
a98c78e5 910 if(GetSigma2DiamondZ()<0.0001)cutZdiam=99999.; //protection for missing z diamond information
911 if(distZ>minZdist && distZdiam<cutZdiam){
912 Double_t x2=pv->GetX();
913 Double_t y2=pv->GetY();
914 Double_t distXdiam=TMath::Abs(x2-GetDiamondX());
915 Double_t distYdiam=TMath::Abs(y2-GetDiamondY());
916 Double_t cov1[6],cov2[6];
917 mainV->GetCovarianceMatrix(cov1);
918 pv->GetCovarianceMatrix(cov2);
919 Double_t errxDist=TMath::Sqrt(cov2[0]+GetSigma2DiamondX());
920 Double_t erryDist=TMath::Sqrt(cov2[2]+GetSigma2DiamondY());
921 Double_t errzDist=TMath::Sqrt(cov1[5]+cov2[5]);
922 Double_t cutXdiam=nSigmaDiamXY*errxDist;
923 if(GetSigma2DiamondX()<0.0001)cutXdiam=99999.; //protection for missing diamond information
924 Double_t cutYdiam=nSigmaDiamXY*erryDist;
925 if(GetSigma2DiamondY()<0.0001)cutYdiam=99999.; //protection for missing diamond information
926 if( (distXdiam<cutXdiam) && (distYdiam<cutYdiam) && (distZ>nSigmaZdist*errzDist) ){
927 return kTRUE;
928 }
929 }
930 }
931 }
932 return kFALSE;
933}
8ff33247 934
08e4c457 935//______________________________________________________________________________
936void AliAODEvent::Print(Option_t *) const
937{
4922c144 938 // Print the names of the all branches
939 TIter next(fAODObjects);
940 TNamed *el;
941 Printf(">>>>> AOD Content <<<<<");
942 while((el=(TNamed*)next())){
943 Printf(">> %s ",el->GetName());
944 }
945 Printf(">>>>> <<<<<");
08e4c457 946
947 return;
948}
c8e4f399 949
d38034b8 950//______________________________________________________________________________
5e6a3170 951void AliAODEvent::AssignIDtoCollection(const TCollection* col)
c8e4f399 952{
953 // Static method which assigns a ID to each object in a collection
954 // In this way the objects are marked as referenced and written with
955 // an ID. This has the advantage that TRefs to this objects can be
956 // written by a subsequent process.
957 TIter next(col);
958 TObject* obj;
8ac4fa64 959 while ((obj = next()))
c8e4f399 960 TProcessID::AssignID(obj);
961}
b46ff4b0 962
d38034b8 963//______________________________________________________________________________
b46ff4b0 964Bool_t AliAODEvent::IsPileupFromSPDInMultBins() const {
965 Int_t nTracklets=GetTracklets()->GetNumberOfTracklets();
966 if(nTracklets<20) return IsPileupFromSPD(3,0.8);
967 else if(nTracklets<50) return IsPileupFromSPD(4,0.8);
968 else return IsPileupFromSPD(5,0.8);
969}
970
d38034b8 971//______________________________________________________________________________
1da0e888 972void AliAODEvent::Reset()
973{
974 // Handle the cases
975 // Std content + Non std content
976
977 ClearStd();
1da0e888 978 if(fAODObjects->GetSize()>kAODListN){
979 // we have non std content
980 // this also covers aodfriends
981 for(int i = kAODListN;i < fAODObjects->GetSize();++i){
982 TObject *pObject = fAODObjects->At(i);
983 // TClonesArrays
984 if(pObject->InheritsFrom(TClonesArray::Class())){
985 ((TClonesArray*)pObject)->Delete();
986 }
987 else if(!pObject->InheritsFrom(TCollection::Class())){
988 TClass *pClass = TClass::GetClass(pObject->ClassName());
989 if (pClass && pClass->GetListOfMethods()->FindObject("Clear")) {
990 AliDebug(1, Form("Clear for object %s class %s", pObject->GetName(), pObject->ClassName()));
991 pObject->Clear();
992 }
993 else {
994 AliDebug(1, Form("ResetWithPlacementNew for object %s class %s", pObject->GetName(), pObject->ClassName()));
995 Long_t dtoronly = TObject::GetDtorOnly();
996 TObject::SetDtorOnly(pObject);
997 delete pObject;
998 pClass->New(pObject);
999 TObject::SetDtorOnly((void*)dtoronly);
1000 }
1001 }
1002 else{
1003 AliWarning(Form("No reset for %s \n",
1004 pObject->ClassName()));
1005 }
1006 }
1007 }
1008}
1009
f8faa5ab 1010// FIXME: Why is this in event and not in header?
5e14e698 1011Float_t AliAODEvent::GetVZEROEqMultiplicity(Int_t i) const
1012{
1013 // Get VZERO Multiplicity for channel i
1014 // Themethod uses the equalization factors
1015 // stored in the ESD-run object in order to
1016 // get equal multiplicities within a VZERO rins (1/8 of VZERO)
1017 if (!fAODVZERO || !fHeader) return -1;
1018
1019 Int_t ring = i/8;
1020 Float_t factorSum = 0;
1021 for(Int_t j = 8*ring; j < (8*ring+8); ++j) {
1022 factorSum += fHeader->GetVZEROEqFactors(j);
1023 }
1024 Float_t factor = fHeader->GetVZEROEqFactors(i)*8./factorSum;
1025
1026 return (fAODVZERO->GetMultiplicity(i)/factor);
1027}
68919bd9 1028
1029//------------------------------------------------------------
1030void AliAODEvent::SetTOFHeader(const AliTOFHeader *header)
1031{
1032 //
1033 // Set the TOF event_time
1034 //
1035
1036 if (fTOFHeader) {
1037 *fTOFHeader=*header;
1038 //fTOFHeader->SetName(fgkESDListName[kTOFHeader]);
1039 }
1040 else {
1041 // for analysis of reconstructed events
1042 // when this information is not avaliable
1043 fTOFHeader = new AliTOFHeader(*header);
1044 //AddObject(fTOFHeader);
1045 }
1046
1047}
08b38f3f 1048//------------------------------------------------------------
567624b5 1049AliAODHMPIDrings *AliAODEvent::GetHMPIDringForTrackID(Int_t trackID) const
08b38f3f 1050{
1051 //
1052 // Returns the HMPID object if any for a given track ID
1053 //
1054 if(GetHMPIDrings())
1055 {
1056 for(Int_t ien = 0 ; ien < GetNHMPIDrings(); ien++)
1057 {
824d3e1f 1058 if( GetHMPIDring(ien)->GetHmpTrkID() == trackID ) return GetHMPIDring(ien);
08b38f3f 1059 }//rings loop
1060 }
1061 return 0;
1062}
1063//------------------------------------------------------------
567624b5 1064Int_t AliAODEvent::GetNHMPIDrings() const
08b38f3f 1065{
1066 //
1067 // If there is a list of HMPID rings in the given AOD event, return their number
1068 //
1069 if ( fHMPIDrings) return fHMPIDrings->GetEntriesFast();
1070 else return -1;
1071}
1072//------------------------------------------------------------
567624b5 1073AliAODHMPIDrings *AliAODEvent::GetHMPIDring(Int_t nRings) const
08b38f3f 1074{
1075 //
1076 // If there is a list of HMPID rings in the given AOD event, return corresponding ring
1077 //
1078 if(fHMPIDrings) {
1079 if( (AliAODHMPIDrings*)fHMPIDrings->UncheckedAt(nRings) ) {
1080 return (AliAODHMPIDrings*)fHMPIDrings->UncheckedAt(nRings);
1081 }
1082 else return 0x0;
1083 }
1084 else return 0x0;
1085}
1086//------------------------------------------------------------
9aa7ebff 1087AliAODTrdTrack& AliAODEvent::AddTrdTrack(const AliVTrdTrack *track) {
1088 return *(new ((*fTrdTracks)[fTrdTracks->GetEntriesFast()]) AliAODTrdTrack(*track));
1089}
d38034b8 1090
1091//______________________________________________________________________________
1092void AliAODEvent::ConnectTracks() {
1093// Connect tracks to this event
1094 if (fTracksConnected || !fTracks || !fTracks->GetEntriesFast()) return;
4cd87297 1095 AliAODTrack *track = 0;
1096 track = dynamic_cast<AliAODTrack*>(GetTrack(0));
1097 if(!track) {
541cfe93 1098 AliWarning("Not an AliAODTrack, this is not a standard AOD");
1099 return;
1100 }
4cd87297 1101
d38034b8 1102 TIter next(fTracks);
1103 while ((track=(AliAODTrack*)next())) track->SetAODEvent(this);
1104 fTracksConnected = kTRUE;
1105}
1106
15da855d 1107AliVEvent::EDataLayoutType AliAODEvent::GetDataLayoutType() const {return AliVEvent::kAOD;}
1108