]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONMCDataInterface.cxx
Utility class to easy access to MC information (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONMCDataInterface.cxx
CommitLineData
1df4a03e 1/**************************************************************************
2* Copyright(c) 1998-1999, 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/// \class AliMUONMCDataInterface
19///
20/// Easy to use MC data accessor
21///
22/// \author Laurent Aphecetche, Subatech
23///
24
25#include "AliMUONMCDataInterface.h"
26
27#include "AliLog.h"
28#include "AliMUONDataManager.h"
29#include "AliMUONVStore.h"
30#include "AliMUONVHitStore.h"
31#include "AliRunLoader.h"
32#include "AliStack.h"
33#include <Riostream.h>
34#include <TClonesArray.h>
35#include <TParticle.h>
36
37/// \cond CLASSIMP
38ClassImp(AliMUONMCDataInterface)
39/// \endcond
40
41//_____________________________________________________________________________
42AliMUONMCDataInterface::AliMUONMCDataInterface(const char* filename) :
43TObject(),
44fDataManager(new AliMUONDataManager(filename))
45{
46 /// ctor
47 if (!IsValid())
48 {
49 AliError(Form("Could not access %s filename. Object is unuseable",filename));
50 }
51}
52
53//_____________________________________________________________________________
54AliMUONMCDataInterface::~AliMUONMCDataInterface()
55{
56 /// dtor
57 delete fDataManager;
58}
59
60//_____________________________________________________________________________
61void
62AliMUONMCDataInterface::DumpHits(Int_t event) const
63{
64 /// Dump all the hits for one event
65
66 Int_t ntracks = NumberOfTracks(event);
67
68 for ( Int_t i = 0; i < ntracks; ++i )
69 {
70 cout << ">> Track " << i << endl;
71 AliMUONVHitStore* hitStore = HitStore(event,i);
72 hitStore->Print("","full");
73 delete hitStore;
74 }
75}
76
77//_____________________________________________________________________________
78void
79AliMUONMCDataInterface::DumpKine(Int_t event) const
80{
81 /// Dump all generated particles for one event
82 AliStack* stack = Stack(event);
83
84 if ( stack )
85 {
86 Int_t nparticles = (Int_t) stack->GetNtrack();
87
88 for (Int_t iparticle=0; iparticle<nparticles; ++iparticle)
89 {
90 stack->Particle(iparticle)->Print("");
91 }
92 }
93 else
94 {
95 AliError("Could not get stack");
96 }
97}
98
99//_____________________________________________________________________________
100void
101AliMUONMCDataInterface::DumpTrackRefs(Int_t event) const
102{
103 /// Dump track references for one event
104 Int_t ntrackrefs = NumberOfTrackRefs(event);
105
106 for ( Int_t i = 0; i < ntrackrefs; ++i )
107 {
108 TClonesArray* trackRefs = TrackRefs(event,i);
109 trackRefs->Print("","*");
110 delete trackRefs;
111 }
112}
113
114//_____________________________________________________________________________
115AliMUONVHitStore*
116AliMUONMCDataInterface::HitStore(Int_t event, Int_t track) const
117{
118 /// Return the hitStore for a given track of one event
119 if ( !IsValid() ) return 0x0;
120
121 fDataManager->Load("H");
122
123 if ( fDataManager->Load(event) ) return 0x0;
124
125 TTree* treeH = fDataManager->Tree("H");
126
127 AliMUONVHitStore* hitStore(0x0);
128
129 if (treeH)
130 {
131 hitStore = AliMUONVHitStore::Create(*treeH);
132 if ( hitStore )
133 {
134 hitStore->Connect(*treeH);
135 if ( treeH->GetEvent(track) == 0 )
136 {
137 hitStore = 0x0;
138 }
139 }
140 }
141 else
142 {
143 AliError("Could not get TreeH");
144 }
145
146 fDataManager->Unload("H");
147
148 return hitStore;
149}
150
151//_____________________________________________________________________________
152Bool_t
153AliMUONMCDataInterface::IsValid() const
154{
155 /// Whether we were initialized properly or not
156 return fDataManager->IsValid();
157}
158
159//_____________________________________________________________________________
160Int_t
161AliMUONMCDataInterface::NumberOfEvents() const
162{
163 /// Number of events in the file we're connected to
164 if (!IsValid()) return 0;
165 return fDataManager->NumberOfEvents();
166}
167
168//_____________________________________________________________________________
169Int_t
170AliMUONMCDataInterface::NumberOfTracks(Int_t event) const
171{
172 /// Number of tracks in the event
173 if (!IsValid()) return 0;
174
175 fDataManager->Load("H");
176
177 if ( fDataManager->Load(event) ) return 0;
178
179 Int_t rv(0);
180
181 TTree* treeH = fDataManager->Tree("H");
182 if (treeH)
183 {
184 rv=static_cast<Int_t>(fDataManager->Tree("H")->GetEntries());
185 }
186 else
187 {
188 AliError("Could not get TreeH");
189 }
190
191 fDataManager->Unload("H");
192
193 return rv;
194}
195
196//_____________________________________________________________________________
197Int_t
198AliMUONMCDataInterface::NumberOfTrackRefs(Int_t event) const
199{
200 /// Number of track references in the event
201 if (!IsValid()) return 0;
202
203 fDataManager->Load("TR");
204
205 if ( fDataManager->Load(event) ) return 0;
206
207 Int_t rv(0);
208
209 TTree* treeH = fDataManager->Tree("TR");
210 if (treeH)
211 {
212 rv=static_cast<Int_t>(fDataManager->Tree("TR")->GetEntries());
213 }
214 else
215 {
216 AliError("Could not get TreeTR");
217 }
218
219 fDataManager->Unload("TR");
220
221 return rv;
222}
223
224//_____________________________________________________________________________
225AliStack*
226AliMUONMCDataInterface::Stack(Int_t event) const
227{
228 /// Get the Stack (list of generated particles) for one event
229 if (!IsValid()) return 0x0;
230
231 fDataManager->Load("K");
232
233 if ( fDataManager->Load(event) ) return 0x0;
234
235 AliRunLoader* runLoader = AliRunLoader::GetRunLoader();
236 AliDebug(1,Form("RunLoader=%p",runLoader));
237 return runLoader->Stack();
238}
239
240//_____________________________________________________________________________
241TClonesArray*
242AliMUONMCDataInterface::TrackRefs(Int_t event, Int_t track) const
243{
244 /// Get the track references for a given (generated) track of one event
245 if ( !IsValid() ) return 0x0;
246
247 fDataManager->Load("TR");
248
249 if ( fDataManager->Load(event) ) return 0x0;
250
251 TTree* treeTR = fDataManager->Tree("TR");
252
253 TClonesArray* rv = 0;
254
255 if (treeTR)
256 {
257 if ( treeTR->GetEvent(track) > 0 )
258 {
259 TBranch* branch = treeTR->GetBranch("MUON");
260 branch->SetAddress(&rv);
261 branch->GetEvent(track);
262 }
263 }
264 else
265 {
266 AliError("Could not get TreeTR");
267 }
268
269 fDataManager->Unload("TR");
270
271 return rv;
272}