]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODEvent.cxx
corrected bug in GetValue(UInt_t timeSec) (Haavard)
[u/mrichter/AliRoot.git] / STEER / AliAODEvent.cxx
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
23 #include <TTree.h>
24
25 #include "AliAODEvent.h"
26 #include "AliAODHeader.h"
27 #include "AliAODTrack.h"
28
29 ClassImp(AliAODEvent)
30
31 //______________________________________________________________________________
32 AliAODEvent::AliAODEvent() :
33   fAODObjects(new TList()),
34   fHeader(0),
35   fTracks(0),
36   fVertices(0),
37   fClusters(0),
38   fJets(0)
39 {
40   // default constructor
41 }
42
43 //______________________________________________________________________________
44 AliAODEvent::~AliAODEvent() 
45 {
46 // destructor
47     delete fAODObjects;
48 }
49
50 //______________________________________________________________________________
51 void AliAODEvent::AddObject(TObject* obj) 
52 {
53   // Add an object to the list of object.
54   // Please be aware that in order to increase performance you should
55   // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
56   
57   fAODObjects->AddLast(obj);
58 }
59
60 //______________________________________________________________________________
61 TObject *AliAODEvent::GetObject(const char *objName) const 
62 {
63   // Return the pointer to the object with the given name.
64
65   return fAODObjects->FindObject(objName);
66 }
67
68 //______________________________________________________________________________
69 void AliAODEvent::CreateStdContent() 
70 {
71   // create the standard AOD content and set pointers
72
73   // create standard objects and add them to the TList of objects
74   AddObject(new AliAODHeader());
75   AddObject(new TClonesArray("AliAODTrack", 0));
76   AddObject(new TClonesArray("AliAODVertex", 0));
77   AddObject(new TClonesArray("AliAODCluster", 0));
78   AddObject(new TClonesArray("AliAODJet", 0));
79
80   // read back pointers
81   GetStdContent();
82
83   // set names
84   fTracks->SetName("tracks");
85   fVertices->SetName("vertices");
86   fClusters->SetName("clusters");
87   fJets->SetName("jets");
88
89 }
90
91 //______________________________________________________________________________
92 void AliAODEvent::GetStdContent()
93 {
94   // set pointers for standard content
95
96   fHeader   = (AliAODHeader*)fAODObjects->At(0);
97   fTracks   = (TClonesArray*)fAODObjects->At(1);
98   fVertices = (TClonesArray*)fAODObjects->At(2);
99   fClusters = (TClonesArray*)fAODObjects->At(3);
100   fJets     = (TClonesArray*)fAODObjects->At(4);
101 }
102
103 //______________________________________________________________________________
104 void AliAODEvent::ResetStd(Int_t trkArrSize, Int_t vtxArrSize)
105 {
106   // deletes content of standard arrays and resets size
107   fTracks->Delete();
108   if (trkArrSize > fTracks->GetSize()) 
109     fTracks->Expand(trkArrSize);
110
111   fVertices->Delete();
112   if (vtxArrSize > fVertices->GetSize()) 
113     fVertices->Expand(vtxArrSize);
114 }
115
116 void AliAODEvent::ClearStd()
117 {
118   // clears the standard arrays
119     fTracks   ->Clear();
120     fVertices ->Clear();
121     fClusters ->Clear();
122     fJets     ->Clear();
123 }
124
125 //______________________________________________________________________________
126 Int_t AliAODEvent::GetMuonTracks(TRefArray *muonTracks) const
127 {
128   // fills the provided TRefArray with all found muon tracks
129
130   muonTracks->Clear();
131
132   AliAODTrack *track = 0;
133   for (Int_t iTrack = 0; iTrack < GetNTracks(); iTrack++) {
134     if ((track = GetTrack(iTrack))->GetMostProbablePID() == AliAODTrack::kMuon) {
135       muonTracks->Add(track);
136     }
137   }
138   
139   return muonTracks->GetSize();
140 }
141
142
143
144 void AliAODEvent::ReadFromTree(TTree *tree)
145 {
146     // connects aod event to tree
147
148     fAODObjects = (TList*)((AliAODEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliAODEvent"))->GetList(); 
149     TIter next(fAODObjects);
150     TNamed *el;
151     while((el=(TNamed*)next())){
152         TString bname(el->GetName());
153         tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
154     }
155     GetStdContent();
156 }
157