Make full use of newly introduced functionality:
[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 // definition of std AOD member names
32   const char* AliAODEvent::fAODListName[kAODListN] = {"header",
33                                                       "tracks",
34                                                       "vertices",
35                                                       "v0s",
36                                                       "tracklets",
37                                                       "jets",
38                                                       "caloCells",
39                                                       "caloClusters",
40                                                       "fmdClusters",
41                                                       "pmdClusters"
42 };
43 //______________________________________________________________________________
44 AliAODEvent::AliAODEvent() :
45   AliVEvent(),
46   fAODObjects(new TList()),
47   fHeader(0),
48   fTracks(0),
49   fVertices(0),
50   fV0s(0),
51   fTracklets(0),
52   fJets(0),
53   fCaloCells(0),
54   fCaloClusters(0),
55   fFmdClusters(0),
56   fPmdClusters(0)
57 {
58   // default constructor
59 }
60
61 //______________________________________________________________________________
62 AliAODEvent::~AliAODEvent() 
63 {
64 // destructor
65     delete fAODObjects;
66 }
67
68 //______________________________________________________________________________
69 void AliAODEvent::AddObject(TObject* obj) 
70 {
71   // Add an object to the list of object.
72   // Please be aware that in order to increase performance you should
73   // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
74   
75   fAODObjects->AddLast(obj);
76 }
77
78 //______________________________________________________________________________
79 TObject *AliAODEvent::FindListObject(const char *objName)
80 {
81   // Return the pointer to the object with the given name.
82
83   return fAODObjects->FindObject(objName);
84 }
85
86 //______________________________________________________________________________
87 void AliAODEvent::CreateStdContent() 
88 {
89   // create the standard AOD content and set pointers
90
91   // create standard objects and add them to the TList of objects
92   AddObject(new AliAODHeader());
93   AddObject(new TClonesArray("AliAODTrack", 0));
94   AddObject(new TClonesArray("AliAODVertex", 0));
95   AddObject(new TClonesArray("AliAODv0", 0));
96   AddObject(new AliAODTracklets());
97   AddObject(new TClonesArray("AliAODJet", 0));
98   AddObject(new AliAODCaloCells());
99   AddObject(new TClonesArray("AliAODCaloCluster", 0));
100   AddObject(new TClonesArray("AliAODFmdCluster", 0));
101   AddObject(new TClonesArray("AliAODPmdCluster", 0));
102   
103   // set names
104   SetStdNames();
105
106   // read back pointers
107   GetStdContent();
108
109   return;
110 }
111
112 //______________________________________________________________________________
113 void AliAODEvent::SetStdNames()
114 {
115   // introduce the standard naming
116
117   if(fAODObjects->GetEntries()==kAODListN){
118     for(int i = 0;i < fAODObjects->GetEntries();i++){
119       TObject *fObj = fAODObjects->At(i);
120       if(fObj->InheritsFrom("TNamed")){
121         ((TNamed*)fObj)->SetName(fAODListName[i]);
122       }
123       else if(fObj->InheritsFrom("TClonesArray")){
124         ((TClonesArray*)fObj)->SetName(fAODListName[i]);
125       }
126     }
127   }
128   else{
129     printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
130   }
131
132
133 //______________________________________________________________________________
134 void AliAODEvent::GetStdContent()
135 {
136   // set pointers for standard content
137
138   fHeader        = (AliAODHeader*)fAODObjects->FindObject("header");
139   fTracks        = (TClonesArray*)fAODObjects->FindObject("tracks");
140   fVertices      = (TClonesArray*)fAODObjects->FindObject("vertices");
141   fV0s           = (TClonesArray*)fAODObjects->FindObject("v0s");
142   fTracklets     = (AliAODTracklets*)fAODObjects->FindObject("tracklets");
143   fJets          = (TClonesArray*)fAODObjects->FindObject("jets");
144   fCaloCells     = (AliAODCaloCells*)fAODObjects->FindObject("caloCells");
145   fCaloClusters  = (TClonesArray*)fAODObjects->FindObject("caloClusters");
146   fFmdClusters   = (TClonesArray*)fAODObjects->FindObject("fmdClusters");
147   fPmdClusters   = (TClonesArray*)fAODObjects->FindObject("pmdClusters");
148 }
149
150 //______________________________________________________________________________
151 void AliAODEvent::ResetStd(Int_t trkArrSize, 
152                            Int_t vtxArrSize, 
153                            Int_t v0ArrSize, 
154                            Int_t jetSize, 
155                            Int_t caloClusSize, 
156                            Int_t fmdClusSize, 
157                            Int_t pmdClusSize)
158 {
159   // deletes content of standard arrays and resets size 
160
161   fTracks->Delete();
162   if (trkArrSize > fTracks->GetSize()) 
163     fTracks->Expand(trkArrSize);
164
165   fVertices->Delete();
166   if (vtxArrSize > fVertices->GetSize()) 
167     fVertices->Expand(vtxArrSize);
168  
169   fV0s->Delete();
170   if (v0ArrSize > fV0s->GetSize()) 
171     fV0s->Expand(v0ArrSize);
172
173   fJets->Delete();
174   if (jetSize > fJets->GetSize()) 
175     fJets->Expand(jetSize);
176
177   fCaloClusters->Delete();
178   if (caloClusSize > fCaloClusters->GetSize()) 
179     fCaloClusters->Expand(caloClusSize);
180
181   fFmdClusters->Delete();
182   if (fmdClusSize > fFmdClusters->GetSize()) 
183     fFmdClusters->Expand(fmdClusSize);
184
185   fPmdClusters->Delete();
186   if (pmdClusSize > fPmdClusters->GetSize()) 
187     fPmdClusters->Expand(pmdClusSize);
188 }
189
190 void AliAODEvent::ClearStd()
191 {
192   // clears the standard arrays
193   fTracks        ->Clear();
194   fVertices      ->Clear();
195   fV0s           ->Clear();
196   fTracklets     ->DeleteContainer();
197   fJets          ->Clear();
198   fCaloCells     ->DeleteContainer();
199   fCaloClusters ->Clear();
200   fFmdClusters  ->Clear();
201   fPmdClusters  ->Clear();
202 }
203
204 //______________________________________________________________________________
205 Int_t AliAODEvent::GetMuonTracks(TRefArray *muonTracks) const
206 {
207   // fills the provided TRefArray with all found muon tracks
208
209   muonTracks->Clear();
210
211   AliAODTrack *track = 0;
212   for (Int_t iTrack = 0; iTrack < GetNTracks(); iTrack++) {
213     if ((track = GetTrack(iTrack))->IsMuonTrack()) {
214       muonTracks->Add(track);
215     }
216   }
217   
218   return muonTracks->GetEntriesFast();
219 }
220
221
222 void AliAODEvent::ReadFromTree(TTree *tree)
223 {
224   // connects aod event to tree
225   
226   // load the TTree
227   tree->LoadTree(0);
228
229   fAODObjects = (TList*)((AliAODEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliAODEvent"))->GetList(); 
230   TIter next(fAODObjects);
231   TNamed *el;
232   while((el=(TNamed*)next())){
233     TString bname(el->GetName());
234     tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
235   }
236   GetStdContent();
237 }
238
239 //______________________________________________________________________________
240 void AliAODEvent::Print(Option_t *) const
241 {
242   // Something meaningful should be implemented here.
243   
244   return;
245 }