]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AOD/AliAODEvent.cxx
updates JetSample to check cluster-track matching
[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),
5c1dc41f 102 fHeader(new AliAODHeader(*aod.fHeader)),
103 fTracks(new TClonesArray(*aod.fTracks)),
104 fVertices(new TClonesArray(*aod.fVertices)),
105 fV0s(new TClonesArray(*aod.fV0s)),
9a244178 106 fCascades(new TClonesArray(*aod.fCascades)),
5c1dc41f 107 fTracklets(new AliAODTracklets(*aod.fTracklets)),
108 fJets(new TClonesArray(*aod.fJets)),
109 fEmcalCells(new AliAODCaloCells(*aod.fEmcalCells)),
110 fPhosCells(new AliAODCaloCells(*aod.fPhosCells)),
111 fCaloClusters(new TClonesArray(*aod.fCaloClusters)),
720f7306 112 fEMCALTrigger(new AliAODCaloTrigger(*aod.fEMCALTrigger)),
113 fPHOSTrigger(new AliAODCaloTrigger(*aod.fPHOSTrigger)),
5c1dc41f 114 fFmdClusters(new TClonesArray(*aod.fFmdClusters)),
866d8d78 115 fPmdClusters(new TClonesArray(*aod.fPmdClusters)),
08b38f3f 116 fHMPIDrings(new TClonesArray(*aod.fHMPIDrings)),
ae2bccf1 117 fDimuons(new TClonesArray(*aod.fDimuons)),
a1f96974 118 fAODTZERO(new AliAODTZERO(*aod.fAODTZERO)),
16d867eb 119 fAODVZERO(new AliAODVZERO(*aod.fAODVZERO)),
68919bd9 120 fAODZDC(new AliAODZDC(*aod.fAODZDC)),
9aa7ebff 121 fTOFHeader(new AliTOFHeader(*aod.fTOFHeader)),
122 fTrdTracks(new TClonesArray(*aod.fTrdTracks))
5c1dc41f 123{
124 // Copy constructor
125 AddObject(fHeader);
126 AddObject(fTracks);
127 AddObject(fVertices);
128 AddObject(fV0s);
9a244178 129 AddObject(fCascades);
5c1dc41f 130 AddObject(fTracklets);
131 AddObject(fJets);
132 AddObject(fEmcalCells);
133 AddObject(fPhosCells);
134 AddObject(fCaloClusters);
720f7306 135 AddObject(fEMCALTrigger);
136 AddObject(fPHOSTrigger);
5c1dc41f 137 AddObject(fFmdClusters);
138 AddObject(fPmdClusters);
08b38f3f 139 AddObject(fHMPIDrings);
866d8d78 140 AddObject(fDimuons);
a1f96974 141 AddObject(fAODTZERO);
ae2bccf1 142 AddObject(fAODVZERO);
16d867eb 143 AddObject(fAODZDC);
68919bd9 144 AddObject(fTOFHeader);
9aa7ebff 145 AddObject(fTrdTracks);
dd389a30 146 fConnected = aod.fConnected;
d38034b8 147 ConnectTracks();
5c1dc41f 148 GetStdContent();
48f1c230 149 CreateStdFolders();
5c1dc41f 150}
151
152//______________________________________________________________________________
153AliAODEvent & AliAODEvent::operator=(const AliAODEvent& aod) {
154
155 // Assignment operator
156
48f1c230 157 if(&aod == this) return *this;
158 AliVEvent::operator=(aod);
5c1dc41f 159
48f1c230 160 // This assumes that the list is already created
161 // and that the virtual void Copy(Tobject&) function
162 // is correctly implemented in the derived class
163 // otherwise only TObject::Copy() will be used
164
165 if((fAODObjects->GetSize()==0)&&(aod.fAODObjects->GetSize()>=kAODListN)){
166 // We cover the case that we do not yet have the
167 // standard content but the source has it
168 CreateStdContent();
169 }
170
171 // Here we have the standard content without user additions, but the content is
172 // not matching the aod source.
173
174 // Iterate the list of source objects
175 TIter next(aod.GetList());
176 TObject *its = 0;
177 TString name;
178 while ((its = next())) {
179 name = its->GetName();
180 // Check if we have this object type in out list
181 TObject *mine = fAODObjects->FindObject(name);
182 if(!mine) {
183 // We have to create the same type of object.
184 TClass* pClass=TClass::GetClass(its->ClassName());
185 if (!pClass) {
186 AliWarning(Form("Can not find class description for entry %s (%s)\n",
187 its->ClassName(), name.Data()));
188 continue;
189 }
190 mine=(TObject*)pClass->New();
191 if(!mine){
192 // not in this: can be added to list
193 AliWarning(Form("%s:%d Could not find %s for copying \n",
194 (char*)__FILE__,__LINE__,name.Data()));
195 continue;
196 }
197 if(mine->InheritsFrom("TNamed")) {
198 ((TNamed*)mine)->SetName(name);
199 } else if(mine->InheritsFrom("TCollection")){
200 if(mine->InheritsFrom("TClonesArray")) {
201 TClonesArray *itscl = dynamic_cast<TClonesArray*>(its);
202 if (!itscl) {
203 AliWarning(Form("Class description for entry %s (%s) not TClonesArray\n",
204 its->ClassName(), name.Data()));
205 continue;
206
207 }
208 dynamic_cast<TClonesArray*>(mine)->SetClass(itscl->GetClass(), itscl->GetSize());
209 }
210 dynamic_cast<TCollection*>(mine)->SetName(name);
211 }
212 AliDebug(1, Form("adding object %s of type %s", mine->GetName(), mine->ClassName()));
213 AddObject(mine);
214 }
215 // Now we have an object of the same type and name, but different content.
216 if(!its->InheritsFrom("TCollection")){
217 // simple objects (do they have a Copy method that calls operator= ?)
218 its->Copy(*mine);
219 } else if (its->InheritsFrom("TClonesArray")) {
220 // Create or expand the tclonesarray pointers
221 // so we can directly copy to the object
222 TClonesArray *its_tca = (TClonesArray*)its;
223 TClonesArray *mine_tca = (TClonesArray*)mine;
224 // this leaves the capacity of the TClonesArray the same
225 // except for a factor of 2 increase when size > capacity
226 // does not release any memory occupied by the tca
227 Int_t its_entries = its_tca->GetEntriesFast();
228 mine_tca->ExpandCreate(its_entries);
229 for(int i=0; i<its_entries; i++){
230 // copy
231 TObject *mine_tca_obj = mine_tca->At(i);
232 TObject *its_tca_obj = its_tca->At(i);
233 // no need to delete first
234 // pointers within the class should be handled by Copy()...
235 // Can there be Empty slots?
236 its_tca_obj->Copy(*mine_tca_obj);
237 }
238 } else {
239 AliWarning(Form("%s:%d cannot copy TCollection \n",
240 (char*)__FILE__,__LINE__));
241 }
242 }
243 fConnected = aod.fConnected;
d38034b8 244 fTracksConnected = kFALSE;
245 ConnectTracks();
48f1c230 246 return *this;
5c1dc41f 247}
248
249
df9db588 250//______________________________________________________________________________
251AliAODEvent::~AliAODEvent()
252{
ec4af4c1 253// destructor
fc65507e 254 delete fAODFolder;
255 fAODFolder = 0;
483ad248 256 if(!fConnected) {
d51e155a 257// fAODObjects->Delete("slow");
483ad248 258 delete fAODObjects;
259 }
df9db588 260}
261
262//______________________________________________________________________________
263void AliAODEvent::AddObject(TObject* obj)
264{
4b3de353 265 // Add an object to the list of objects.
df9db588 266 // Please be aware that in order to increase performance you should
267 // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
268
d51e155a 269// if ( !fAODObjects ) {
270// fAODObjects = new TList();
271// fAODObjects->SetOwner();
272// }
14d6fad5 273 if ( !fAODObjects->FindObject(obj) )
274 {
275 fAODObjects->AddLast(obj);
276 }
df9db588 277}
278
d38034b8 279//______________________________________________________________________________
280Int_t AliAODEvent::AddTrack(const AliAODTrack* trk)
281{
282// Add new AOD track. Make sure to set the event if needed.
283 AliAODTrack *track = new((*fTracks)[fTracks->GetEntriesFast()]) AliAODTrack(*trk);
284 track->SetAODEvent(this);
285 return fTracks->GetEntriesFast()-1;
286}
287
4b3de353 288//______________________________________________________________________________
289void AliAODEvent::RemoveObject(TObject* obj)
290{
291 // Removes an object from the list of objects.
292
293 fAODObjects->Remove(obj);
294}
295
df9db588 296//______________________________________________________________________________
2811495d 297TObject *AliAODEvent::FindListObject(const char *objName) const
df9db588 298{
299 // Return the pointer to the object with the given name.
300
301 return fAODObjects->FindObject(objName);
302}
303
304//______________________________________________________________________________
305void AliAODEvent::CreateStdContent()
306{
307 // create the standard AOD content and set pointers
308
309 // create standard objects and add them to the TList of objects
310 AddObject(new AliAODHeader());
311 AddObject(new TClonesArray("AliAODTrack", 0));
312 AddObject(new TClonesArray("AliAODVertex", 0));
3dd9f9e3 313 AddObject(new TClonesArray("AliAODv0", 0));
9a244178 314 AddObject(new TClonesArray("AliAODcascade", 0));
821f8f1d 315 AddObject(new AliAODTracklets());
3dd9f9e3 316 AddObject(new TClonesArray("AliAODJet", 0));
317 AddObject(new AliAODCaloCells());
37792174 318 AddObject(new AliAODCaloCells());
3dd9f9e3 319 AddObject(new TClonesArray("AliAODCaloCluster", 0));
720f7306 320 AddObject(new AliAODCaloTrigger()); // EMCAL
321 AddObject(new AliAODCaloTrigger()); // PHOS
3dd9f9e3 322 AddObject(new TClonesArray("AliAODFmdCluster", 0));
323 AddObject(new TClonesArray("AliAODPmdCluster", 0));
08b38f3f 324 AddObject(new TClonesArray("AliAODHMPIDrings", 0));
866d8d78 325 AddObject(new TClonesArray("AliAODDimuon", 0));
a1f96974 326 AddObject(new AliAODTZERO());
ae2bccf1 327 AddObject(new AliAODVZERO());
16d867eb 328 AddObject(new AliAODZDC());
68919bd9 329 AddObject(new AliTOFHeader());
9aa7ebff 330 AddObject(new TClonesArray("AliAODTrdTrack", 0));
08e4c457 331 // set names
332 SetStdNames();
333
df9db588 334 // read back pointers
335 GetStdContent();
5c1dc41f 336 CreateStdFolders();
08e4c457 337 return;
df9db588 338}
339
c8e4f399 340void AliAODEvent::MakeEntriesReferencable()
341{
342 // Make all entries referencable in a subsequent process
343 //
344 TIter next(fAODObjects);
345 TObject* obj;
8ac4fa64 346 while ((obj = next()))
c8e4f399 347 {
348 if(obj->InheritsFrom("TCollection"))
349 {
350 AssignIDtoCollection((TCollection*)obj);
351 }
352 }
353}
354
08e4c457 355//______________________________________________________________________________
356void AliAODEvent::SetStdNames()
357{
358 // introduce the standard naming
359
360 if(fAODObjects->GetEntries()==kAODListN){
361 for(int i = 0;i < fAODObjects->GetEntries();i++){
362 TObject *fObj = fAODObjects->At(i);
363 if(fObj->InheritsFrom("TNamed")){
364 ((TNamed*)fObj)->SetName(fAODListName[i]);
365 }
366 else if(fObj->InheritsFrom("TClonesArray")){
367 ((TClonesArray*)fObj)->SetName(fAODListName[i]);
368 }
369 }
370 }
371 else{
372 printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
373 }
374}
375
d38034b8 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");
df9db588 423}
424
425//______________________________________________________________________________
3dd9f9e3 426void AliAODEvent::ResetStd(Int_t trkArrSize,
d38034b8 427 Int_t vtxArrSize,
428 Int_t v0ArrSize,
429 Int_t cascadeArrSize,
430 Int_t jetSize,
431 Int_t caloClusSize,
432 Int_t fmdClusSize,
433 Int_t pmdClusSize,
434 Int_t hmpidRingsSize,
435 Int_t dimuonArrSize,
436 Int_t nTrdTracks
9a244178 437 )
df9db588 438{
3dd9f9e3 439 // deletes content of standard arrays and resets size
d38034b8 440 fTracksConnected = kFALSE;
f8e407b9 441 if (fTracks) {
442 fTracks->Delete();
443 if (trkArrSize > fTracks->GetSize())
444 fTracks->Expand(trkArrSize);
445 }
446 if (fVertices) {
447 fVertices->Delete();
448 if (vtxArrSize > fVertices->GetSize())
449 fVertices->Expand(vtxArrSize);
450 }
451 if (fV0s) {
452 fV0s->Delete();
453 if (v0ArrSize > fV0s->GetSize())
454 fV0s->Expand(v0ArrSize);
455 }
456 if (fCascades) {
457 fCascades->Delete();
458 if (cascadeArrSize > fCascades->GetSize())
459 fCascades->Expand(cascadeArrSize);
460 }
461 if (fJets) {
462 fJets->Delete();
463 if (jetSize > fJets->GetSize())
464 fJets->Expand(jetSize);
465 }
466 if (fCaloClusters) {
467 fCaloClusters->Delete();
468 if (caloClusSize > fCaloClusters->GetSize())
469 fCaloClusters->Expand(caloClusSize);
470 }
471 if (fFmdClusters) {
472 fFmdClusters->Delete();
473 if (fmdClusSize > fFmdClusters->GetSize())
474 fFmdClusters->Expand(fmdClusSize);
475 }
476 if (fPmdClusters) {
477 fPmdClusters->Delete();
478 if (pmdClusSize > fPmdClusters->GetSize())
479 fPmdClusters->Expand(pmdClusSize);
480 }
08b38f3f 481 if (fHMPIDrings) {
fc05a533 482 fHMPIDrings->Delete();
08b38f3f 483 if (hmpidRingsSize > fHMPIDrings->GetSize())
484 fHMPIDrings->Expand(hmpidRingsSize);
485 }
f8e407b9 486 if (fDimuons) {
487 fDimuons->Delete();
488 if (dimuonArrSize > fDimuons->GetSize())
489 fDimuons->Expand(dimuonArrSize);
490 }
9aa7ebff 491 if (fTrdTracks) {
492 // no pointers in there, so cheaper Clear suffices
493 fTrdTracks->Clear("C");
494 if (nTrdTracks > fTrdTracks->GetSize())
495 fTrdTracks->Expand(nTrdTracks);
496 }
497
f8e407b9 498 if (fTracklets)
499 fTracklets->DeleteContainer();
500 if (fPhosCells)
501 fPhosCells->DeleteContainer();
502 if (fEmcalCells)
503 fEmcalCells->DeleteContainer();
720f7306 504
505 if (fEMCALTrigger)
506 fEMCALTrigger->DeAllocate();
507 if (fPHOSTrigger)
508 fPHOSTrigger->DeAllocate();
6d710f57 509
df9db588 510}
511
d38034b8 512//______________________________________________________________________________
ec4af4c1 513void AliAODEvent::ClearStd()
514{
515 // clears the standard arrays
f8e407b9 516 if (fHeader)
517 fHeader ->Clear();
d38034b8 518 fTracksConnected = kFALSE;
f8e407b9 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
f7cc8591 635//______________________________________________________________________________
636Int_t AliAODEvent::GetMuonGlobalTracks(TRefArray *muonGlobalTracks) const // AU
637{
638 // fills the provided TRefArray with all found muon global tracks
639
640 muonGlobalTracks->Clear();
641
642 AliAODTrack *track = 0;
643 for (Int_t iTrack = 0; iTrack < GetNTracks(); iTrack++) {
644 track = GetTrack(iTrack);
645 if (track->IsMuonGlobalTrack()) {
646 muonGlobalTracks->Add(track);
647 }
648 }
649
650 return muonGlobalTracks->GetEntriesFast();
651}
652
653
654//______________________________________________________________________________
655Int_t AliAODEvent::GetNumberOfMuonGlobalTracks() const // AU
656{
657 // get number of muon global tracks
658 Int_t nMuonGlobalTracks=0;
659 for (Int_t iTrack = 0; iTrack < GetNTracks(); iTrack++) {
660 if ((GetTrack(iTrack))->IsMuonGlobalTrack()) {
661 nMuonGlobalTracks++;
662 }
663 }
664
665 return nMuonGlobalTracks;
666}
667
788578f5 668//______________________________________________________________________________
3b93c32a 669void AliAODEvent::ReadFromTree(TTree *tree, Option_t* opt /*= ""*/)
8ff33247 670{
c8fe2783 671 // Connects aod event to tree
08e4c457 672
61cb38c7 673 if(!tree){
788578f5 674 AliWarning("Zero Pointer to Tree \n");
61cb38c7 675 return;
676 }
c8fe2783 677 // load the TTree
61cb38c7 678 if(!tree->GetTree())tree->LoadTree(0);
c8fe2783 679
680 // Try to find AliAODEvent
61cb38c7 681 AliAODEvent *aodEvent = 0;
682 aodEvent = (AliAODEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliAODEvent");
683 if(aodEvent){
788578f5 684 // This event is connected to the tree by definition, just say so
685 aodEvent->SetConnected();
c8fe2783 686 // Check if already connected to tree
61cb38c7 687 TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("AODObjectsConnectedToTree"));
5fdc7d49 688 if (connectedList && (!strcmp(opt, "reconnect"))) {
c8fe2783 689 // If connected use the connected list of objects
5fdc7d49 690 if (fAODObjects != connectedList) {
691 delete fAODObjects;
692 fAODObjects = connectedList;
693 }
694 GetStdContent();
695 fConnected = kTRUE;
696 return;
d8f5fda5 697 }
c8fe2783 698 // Connect to tree
699 // prevent a memory leak when reading back the TList
28a79204 700// if (!(strcmp(opt, "reconnect"))) fAODObjects->Delete();
c8fe2783 701
702 // create a new TList from the UserInfo TList...
703 // copy constructor does not work...
1ee5d9a3 704 // fAODObjects = (TList*)(aodEvent->GetList()->Clone());
705 fAODObjects = (TList*)aodEvent->GetList();
316cf4cc 706 fAODObjects->SetOwner(kTRUE);
14d6fad5 707 if(fAODObjects->GetEntries()<kAODListN)
708 {
709 AliWarning(Form("AliAODEvent::ReadFromTree() TList contains less than the standard contents %d < %d"
710 " That might be fine though (at least for filtered AODs)",fAODObjects->GetEntries(),kAODListN));
61cb38c7 711 }
c8fe2783 712 //
713 // Let's find out whether we have friends
ced57103 714 TList* friendL = tree->GetTree()->GetListOfFriends();
298d3d58 715 if (friendL)
716 {
c8fe2783 717 TIter next(friendL);
718 TFriendElement* fe;
719 while ((fe = (TFriendElement*)next())){
720 aodEvent = (AliAODEvent*)(fe->GetTree()->GetUserInfo()->FindObject("AliAODEvent"));
721 if (!aodEvent) {
722 printf("No UserInfo on tree \n");
723 } else {
724
1ee5d9a3 725 // TList* objL = (TList*)(aodEvent->GetList()->Clone());
08b38f3f 726 TList* objL = (TList*)aodEvent->GetList();
727 printf("Get list of object from tree %d !!\n", objL->GetEntries());
728 TIter nextobject(objL);
729 TObject* obj = 0;
730 while((obj = nextobject()))
c8fe2783 731 {
08b38f3f 732 printf("Adding object from friend %s !\n", obj->GetName());
733 fAODObjects->Add(obj);
c8fe2783 734 } // object "branch" loop
08b38f3f 735 } // has userinfo
c8fe2783 736 } // friend loop
298d3d58 737 } // has friends
c8fe2783 738 // set the branch addresses
61cb38c7 739 TIter next(fAODObjects);
740 TNamed *el;
741 while((el=(TNamed*)next())){
742 TString bname(el->GetName());
c8fe2783 743 // check if branch exists under this Name
ced57103 744 TBranch *br = tree->GetTree()->GetBranch(bname.Data());
61cb38c7 745 if(br){
c8fe2783 746 tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
ced57103 747 } else {
c8fe2783 748 br = tree->GetBranch(Form("%s.",bname.Data()));
749 if(br){
750 tree->SetBranchAddress(Form("%s.",bname.Data()),fAODObjects->GetObjectRef(el));
751 }
752 else{
753 printf("%s %d AliAODEvent::ReadFromTree() No Branch found with Name %s. \n",
754 (char*)__FILE__,__LINE__,bname.Data());
755 }
61cb38c7 756 }
757 }
61cb38c7 758 GetStdContent();
c8fe2783 759 // when reading back we are not owner of the list
760 // must not delete it
316cf4cc 761 fAODObjects->SetOwner(kTRUE);
61cb38c7 762 fAODObjects->SetName("AODObjectsConnectedToTree");
c8fe2783 763 // we are not owner of the list objects
764 // must not delete it
61cb38c7 765 tree->GetUserInfo()->Add(fAODObjects);
dd389a30 766 fConnected = kTRUE;
61cb38c7 767 }// no aodEvent
768 else {
c8fe2783 769 // we can't get the list from the user data, create standard content
770 // and set it by hand
61cb38c7 771 CreateStdContent();
772 TIter next(fAODObjects);
773 TNamed *el;
774 while((el=(TNamed*)next())){
775 TString bname(el->GetName());
776 tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
777 }
778 GetStdContent();
c8fe2783 779 // when reading back we are not owner of the list
780 // must not delete it
316cf4cc 781 fAODObjects->SetOwner(kTRUE);
08e4c457 782 }
8ff33247 783}
c8fe2783 784 //______________________________________________________________________________
a98c78e5 785Int_t AliAODEvent::GetNumberOfPileupVerticesSPD() const{
786 // count number of SPD pileup vertices
787 Int_t nVertices=GetNumberOfVertices();
788 Int_t nPileupVertices=0;
789 for(Int_t iVert=0; iVert<nVertices; iVert++){
790 AliAODVertex *v=GetVertex(iVert);
791 if(v->GetType()==AliAODVertex::kPileupSPD) nPileupVertices++;
792 }
793 return nPileupVertices;
794}
795//______________________________________________________________________________
796Int_t AliAODEvent::GetNumberOfPileupVerticesTracks() const{
797 // count number of track pileup vertices
798 Int_t nVertices=GetNumberOfVertices();
799 Int_t nPileupVertices=0;
800 for(Int_t iVert=0; iVert<nVertices; iVert++){
801 AliAODVertex *v=GetVertex(iVert);
802 if(v->GetType()==AliAODVertex::kPileupTracks) nPileupVertices++;
803 }
804 return nPileupVertices;
805}
806//______________________________________________________________________________
807AliAODVertex* AliAODEvent::GetPrimaryVertexSPD() const{
5e6a3170 808 // Get SPD primary vertex
a98c78e5 809 Int_t nVertices=GetNumberOfVertices();
810 for(Int_t iVert=0; iVert<nVertices; iVert++){
811 AliAODVertex *v=GetVertex(iVert);
812 if(v->GetType()==AliAODVertex::kMainSPD) return v;
813 }
814 return 0;
815}
816//______________________________________________________________________________
817AliAODVertex* AliAODEvent::GetPileupVertexSPD(Int_t iV) const{
5e6a3170 818 // Get pile-up vertex iV
a98c78e5 819 Int_t nVertices=GetNumberOfVertices();
820 Int_t counter=0;
821 for(Int_t iVert=0; iVert<nVertices; iVert++){
822 AliAODVertex *v=GetVertex(iVert);
823 if(v->GetType()==AliAODVertex::kPileupSPD){
824 if(counter==iV) return v;
825 ++counter;
826 }
827 }
828 return 0;
829}
830//______________________________________________________________________________
831AliAODVertex* AliAODEvent::GetPileupVertexTracks(Int_t iV) const{
5e6a3170 832 // Get pile-up vertex iV
a98c78e5 833 Int_t nVertices=GetNumberOfVertices();
834 Int_t counter=0;
835 for(Int_t iVert=0; iVert<nVertices; iVert++){
836 AliAODVertex *v=GetVertex(iVert);
837 if(v->GetType()==AliAODVertex::kPileupTracks){
838 if(counter==iV) return v;
839 ++counter;
840 }
841 }
842 return 0;
843}
844//______________________________________________________________________________
845Bool_t AliAODEvent::IsPileupFromSPD(Int_t minContributors,
846 Double_t minZdist,
847 Double_t nSigmaZdist,
848 Double_t nSigmaDiamXY,
849 Double_t nSigmaDiamZ) const{
850 //
851 // This function checks if there was a pile up
852 // reconstructed with SPD
853 //
854 AliAODVertex *mainV=GetPrimaryVertexSPD();
855 if(!mainV) return kFALSE;
856 Int_t nc1=mainV->GetNContributors();
857 if(nc1<1) return kFALSE;
858 Int_t nPileVert=GetNumberOfPileupVerticesSPD();
859 if(nPileVert==0) return kFALSE;
860 Int_t nVertices=GetNumberOfVertices();
861
862 for(Int_t iVert=0; iVert<nVertices; iVert++){
863 AliAODVertex *pv=GetVertex(iVert);
864 if(pv->GetType()!=AliAODVertex::kPileupSPD) continue;
865 Int_t nc2=pv->GetNContributors();
866 if(nc2>=minContributors){
867 Double_t z1=mainV->GetZ();
868 Double_t z2=pv->GetZ();
869 Double_t distZ=TMath::Abs(z2-z1);
870 Double_t distZdiam=TMath::Abs(z2-GetDiamondZ());
569d954c 871 Double_t cutZdiam=nSigmaDiamZ*TMath::Sqrt(GetSigma2DiamondZ());
a98c78e5 872 if(GetSigma2DiamondZ()<0.0001)cutZdiam=99999.; //protection for missing z diamond information
873 if(distZ>minZdist && distZdiam<cutZdiam){
874 Double_t x2=pv->GetX();
875 Double_t y2=pv->GetY();
876 Double_t distXdiam=TMath::Abs(x2-GetDiamondX());
877 Double_t distYdiam=TMath::Abs(y2-GetDiamondY());
878 Double_t cov1[6],cov2[6];
879 mainV->GetCovarianceMatrix(cov1);
880 pv->GetCovarianceMatrix(cov2);
881 Double_t errxDist=TMath::Sqrt(cov2[0]+GetSigma2DiamondX());
882 Double_t erryDist=TMath::Sqrt(cov2[2]+GetSigma2DiamondY());
883 Double_t errzDist=TMath::Sqrt(cov1[5]+cov2[5]);
884 Double_t cutXdiam=nSigmaDiamXY*errxDist;
885 if(GetSigma2DiamondX()<0.0001)cutXdiam=99999.; //protection for missing diamond information
886 Double_t cutYdiam=nSigmaDiamXY*erryDist;
887 if(GetSigma2DiamondY()<0.0001)cutYdiam=99999.; //protection for missing diamond information
888 if( (distXdiam<cutXdiam) && (distYdiam<cutYdiam) && (distZ>nSigmaZdist*errzDist) ){
889 return kTRUE;
890 }
891 }
892 }
893 }
894 return kFALSE;
895}
8ff33247 896
08e4c457 897//______________________________________________________________________________
898void AliAODEvent::Print(Option_t *) const
899{
4922c144 900 // Print the names of the all branches
901 TIter next(fAODObjects);
902 TNamed *el;
903 Printf(">>>>> AOD Content <<<<<");
904 while((el=(TNamed*)next())){
905 Printf(">> %s ",el->GetName());
906 }
907 Printf(">>>>> <<<<<");
08e4c457 908
909 return;
910}
c8e4f399 911
d38034b8 912//______________________________________________________________________________
5e6a3170 913void AliAODEvent::AssignIDtoCollection(const TCollection* col)
c8e4f399 914{
915 // Static method which assigns a ID to each object in a collection
916 // In this way the objects are marked as referenced and written with
917 // an ID. This has the advantage that TRefs to this objects can be
918 // written by a subsequent process.
919 TIter next(col);
920 TObject* obj;
8ac4fa64 921 while ((obj = next()))
c8e4f399 922 TProcessID::AssignID(obj);
923}
b46ff4b0 924
d38034b8 925//______________________________________________________________________________
b46ff4b0 926Bool_t AliAODEvent::IsPileupFromSPDInMultBins() const {
927 Int_t nTracklets=GetTracklets()->GetNumberOfTracklets();
928 if(nTracklets<20) return IsPileupFromSPD(3,0.8);
929 else if(nTracklets<50) return IsPileupFromSPD(4,0.8);
930 else return IsPileupFromSPD(5,0.8);
931}
932
d38034b8 933//______________________________________________________________________________
1da0e888 934void AliAODEvent::Reset()
935{
936 // Handle the cases
937 // Std content + Non std content
938
939 ClearStd();
1da0e888 940 if(fAODObjects->GetSize()>kAODListN){
941 // we have non std content
942 // this also covers aodfriends
943 for(int i = kAODListN;i < fAODObjects->GetSize();++i){
944 TObject *pObject = fAODObjects->At(i);
945 // TClonesArrays
946 if(pObject->InheritsFrom(TClonesArray::Class())){
947 ((TClonesArray*)pObject)->Delete();
948 }
949 else if(!pObject->InheritsFrom(TCollection::Class())){
950 TClass *pClass = TClass::GetClass(pObject->ClassName());
951 if (pClass && pClass->GetListOfMethods()->FindObject("Clear")) {
952 AliDebug(1, Form("Clear for object %s class %s", pObject->GetName(), pObject->ClassName()));
953 pObject->Clear();
954 }
955 else {
956 AliDebug(1, Form("ResetWithPlacementNew for object %s class %s", pObject->GetName(), pObject->ClassName()));
957 Long_t dtoronly = TObject::GetDtorOnly();
958 TObject::SetDtorOnly(pObject);
959 delete pObject;
960 pClass->New(pObject);
961 TObject::SetDtorOnly((void*)dtoronly);
962 }
963 }
964 else{
965 AliWarning(Form("No reset for %s \n",
966 pObject->ClassName()));
967 }
968 }
969 }
970}
971
5e14e698 972Float_t AliAODEvent::GetVZEROEqMultiplicity(Int_t i) const
973{
974 // Get VZERO Multiplicity for channel i
975 // Themethod uses the equalization factors
976 // stored in the ESD-run object in order to
977 // get equal multiplicities within a VZERO rins (1/8 of VZERO)
978 if (!fAODVZERO || !fHeader) return -1;
979
980 Int_t ring = i/8;
981 Float_t factorSum = 0;
982 for(Int_t j = 8*ring; j < (8*ring+8); ++j) {
983 factorSum += fHeader->GetVZEROEqFactors(j);
984 }
985 Float_t factor = fHeader->GetVZEROEqFactors(i)*8./factorSum;
986
987 return (fAODVZERO->GetMultiplicity(i)/factor);
988}
68919bd9 989
990//------------------------------------------------------------
991void AliAODEvent::SetTOFHeader(const AliTOFHeader *header)
992{
993 //
994 // Set the TOF event_time
995 //
996
997 if (fTOFHeader) {
998 *fTOFHeader=*header;
999 //fTOFHeader->SetName(fgkESDListName[kTOFHeader]);
1000 }
1001 else {
1002 // for analysis of reconstructed events
1003 // when this information is not avaliable
1004 fTOFHeader = new AliTOFHeader(*header);
1005 //AddObject(fTOFHeader);
1006 }
1007
1008}
08b38f3f 1009//------------------------------------------------------------
567624b5 1010AliAODHMPIDrings *AliAODEvent::GetHMPIDringForTrackID(Int_t trackID) const
08b38f3f 1011{
1012 //
1013 // Returns the HMPID object if any for a given track ID
1014 //
1015 if(GetHMPIDrings())
1016 {
1017 for(Int_t ien = 0 ; ien < GetNHMPIDrings(); ien++)
1018 {
824d3e1f 1019 if( GetHMPIDring(ien)->GetHmpTrkID() == trackID ) return GetHMPIDring(ien);
08b38f3f 1020 }//rings loop
1021 }
1022 return 0;
1023}
1024//------------------------------------------------------------
567624b5 1025Int_t AliAODEvent::GetNHMPIDrings() const
08b38f3f 1026{
1027 //
1028 // If there is a list of HMPID rings in the given AOD event, return their number
1029 //
1030 if ( fHMPIDrings) return fHMPIDrings->GetEntriesFast();
1031 else return -1;
1032}
1033//------------------------------------------------------------
567624b5 1034AliAODHMPIDrings *AliAODEvent::GetHMPIDring(Int_t nRings) const
08b38f3f 1035{
1036 //
1037 // If there is a list of HMPID rings in the given AOD event, return corresponding ring
1038 //
1039 if(fHMPIDrings) {
1040 if( (AliAODHMPIDrings*)fHMPIDrings->UncheckedAt(nRings) ) {
1041 return (AliAODHMPIDrings*)fHMPIDrings->UncheckedAt(nRings);
1042 }
1043 else return 0x0;
1044 }
1045 else return 0x0;
1046}
1047//------------------------------------------------------------
9aa7ebff 1048AliAODTrdTrack& AliAODEvent::AddTrdTrack(const AliVTrdTrack *track) {
1049 return *(new ((*fTrdTracks)[fTrdTracks->GetEntriesFast()]) AliAODTrdTrack(*track));
1050}
d38034b8 1051
1052//______________________________________________________________________________
1053void AliAODEvent::ConnectTracks() {
1054// Connect tracks to this event
1055 if (fTracksConnected || !fTracks || !fTracks->GetEntriesFast()) return;
541cfe93 1056 if(!GetTrack(0)->InheritsFrom("AliAODTrack")) { // FIXME: consider using a dynamic_cast instead of InheritsFrom
1057 AliWarning("Not an AliAODTrack, this is not a standard AOD");
1058 return;
1059 }
d38034b8 1060 AliAODTrack *track;
1061 TIter next(fTracks);
1062 while ((track=(AliAODTrack*)next())) track->SetAODEvent(this);
1063 fTracksConnected = kTRUE;
1064}
1065