GammaWare  Head Version for release 0.9
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AgataEventContainer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004-2006 by Olivier Stezowski & Christian Finck *
3  * stezow(AT)ipnl.in2p3.fr, cfinck(AT)ires.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * FreAgataEventContainere Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
24 #ifndef ROOT_TBranch
25 #include "TBranch.h"
26 #endif
27 
28 #ifndef Gw_AgataEventContainer
29 #include "AgataEventContainer.h"
30 #endif
31 
32 using namespace Gw;
33 
34 //
38 
39 const Int_t AgataEventContainer::fgkMaxNofTypeName = 4;
40  TString AgataEventContainer::fgTypeName[fgkMaxNofTypeName] = {"Agata", "HeavyIons", "LightCP", "Neutron"};
41 const TString AgataEventContainer::fgkTypeNameExt[] = {"_Tracks", "_Hits"};
42 
43 //__________________________________________________________
46  fTrackList(new TClonesArray("Gw::TrackHit")),
47  fHitList(new TClonesArray("Gw::StdHit")),
48  fNofBracnhes(0)
49 {
50  // default constructor
51  fLog.GetProcessName() = "AgataEventContainer";
52 
53  // register at least Agata
55 }
56 
57 //__________________________________________________________
59 {
60  // default destructor
61  for (Int_t i = 0; i < fNofBracnhes; ++i) {
62  delete fCurrentTrackList[i];
63  delete fCurrentHitList[i];
64  }
65  delete fHitList;
66  delete fTrackList;
67 }
68 
69 //__________________________________________________________
70 const Char_t* AgataEventContainer::RegisterBranch(Option_t* type)
71 {
72  if (++fNofBracnhes >= fgkMaxNofTypeName) {
73  fLog.SetProcessMethod("RegisterBranch(Option_t* )");
74  fLog << error << "Too many branches registered" << dolog;
75  return "";
76  }
77 
78  TString name(type);
79  if (!name.IsNull())
80  fgTypeName[fNofBracnhes-1] = type;
81 
82  name = fgTypeName[fNofBracnhes-1].Data() + fgkTypeNameExt[0];
83  fCurrentTrackList[fNofBracnhes-1] = new TClonesArray("Gw::TrackHit");
84  fEventTree->Branch(name.Data(), &fCurrentTrackList[fNofBracnhes-1]);
85 
86  name = fgTypeName[fNofBracnhes-1].Data() + fgkTypeNameExt[1];
87  fCurrentHitList[fNofBracnhes-1] = new TClonesArray("Gw::StdHit");
88  fEventTree->Branch(name.Data(), &fCurrentHitList[fNofBracnhes-1]);
89 
90  return fgTypeName[fNofBracnhes-1].Data();
91 }
92 
93 //__________________________________________________________
95 {
96  for (Int_t i = 0; i < fNofBracnhes; ++i) {
97  fCurrentTrackList[i]->Clear();
98  fCurrentHitList[i]->Clear();
99  }
100  fEventTree->Clear();
101 }
102 
103 //__________________________________________________________
104 void AgataEventContainer::FillHits(Option_t* type)
105 {
106  Int_t idx = GetIndex(type);
107  if (idx == -1) {
108  fLog.SetProcessMethod("FillHits(Option_t* )");
109  fLog << error << "Unkown type" << dolog;
110  return;
111  }
112 
113  TString name = GetHitBranchName(type);
114  TBranch* b = fEventTree->GetBranch(name.Data());
115 
116  b->Fill();
117  if (b->GetEntries() > fNofEvents)
118  fNofEvents = b->GetEntries();
119 
120  for (Int_t i = 0; i < fNofBracnhes; ++i) {
121  fCurrentHitList[i]->Delete();
122  }
123 }
124 
125 //__________________________________________________________
126 void AgataEventContainer::FillTracks(Option_t* type)
127 {
128  Int_t idx = GetIndex(type);
129  if (idx == -1) {
130  fLog.SetProcessMethod("FillTracks(Option_t* )");
131  fLog << error << "Unkown type" << dolog;
132  return;
133  }
134 
135  TString name = GetTrackBranchName(type);
136  TBranch* b = fEventTree->GetBranch(name.Data());
137 
138  b->Fill();
139  if (b->GetEntries() > fNofEvents)
140  fNofEvents = b->GetEntries();
141 
142  for (Int_t i = 0; i < fNofBracnhes; ++i) {
143  fCurrentTrackList[i]->Delete();
144  }
145 }
146 
147 
148 //__________________________________________________________
150 {
151  fLog.SetProcessMethod("NewTrackHit(Option_t* )");
152 
153  Int_t idx = GetIndex(type);
154  if (idx == -1) {
155  fLog << error << "Unkown type" << dolog;
156  return 0x0;
157  }
158 
159  if (fCurrentTrackList[idx] == 0x0) {
160  fLog << error << "No current track list available" << dolog;
161  return 0x0;
162  }
163 
164  TClonesArray &hitArray = *fCurrentTrackList[idx];
165  TrackHit* hit = new(hitArray[hitArray.GetEntriesFast()]) TrackHit();
166 
167  fLog << dolog;
168  return hit;
169 }
170 
171 //__________________________________________________________
173 {
174  fLog.SetProcessMethod("NewHit(Option_t* )");
175 
176  Int_t idx = GetIndex(type);
177  if (idx == -1) {
178  fLog << error << "Unkown type" << dolog;
179  return 0x0;
180  }
181 
182  if (fCurrentHitList[idx] == 0x0) {
183  fLog << error << "No current hit list available" << dolog;
184  return 0x0;
185  }
186 
187  TClonesArray &hitArray = *fCurrentHitList[idx];
188  StdHit* hit = new(hitArray[hitArray.GetEntriesFast()]) StdHit();
189 
190  fLog << dolog;
191  return hit;
192 }
193 
194 //__________________________________________________________
195 Int_t AgataEventContainer::GetIndex(Option_t* type) const
196 {
197  TString tmp(type);
198 
199  for (Int_t i = 0; i < fNofBracnhes; ++i) {
200  if (tmp.CompareTo(fgTypeName[i]) == 0)
201  return i;
202  }
203 
204  return -1;
205 }
206 
207 //__________________________________________________________
208 TString AgataEventContainer::GetTrackBranchName(Option_t* type) const
209 {
210  Int_t idx = GetIndex(type);
211  if (idx == -1) {
212  fLog.SetProcessMethod("GetTrackBranchName(Option_t*)");
213  fLog << error << "Unkown type" << dolog;
214  return TString("");
215  }
216 
217  TString name = fgTypeName[idx].Data() + fgkTypeNameExt[0];
218 
219  return TString(name);
220 }
221 
222 //__________________________________________________________
223 TString AgataEventContainer::GetHitBranchName(Option_t* type) const
224 {
225  Int_t idx = GetIndex(type);
226  if (idx == -1) {
227  fLog.SetProcessMethod("GetHitBranchName(Option_t*)");
228  fLog << error << "Unkown type" << dolog;
229  return TString("");
230  }
231 
232  TString name = fgTypeName[idx].Data() + fgkTypeNameExt[1];
233 
234  return TString(name);
235 }
236 
237 //__________________________________________________________
238 TClonesArray* AgataEventContainer::GetTrackList(Int_t ievent, Option_t* type, Bool_t warn)
239 {
240  TString name = GetTrackBranchName(type);
241  if (name.IsNull())
242  return 0x0;
243 
244  TBranch* b = fEventTree->GetBranch(name.Data());
245 
246  if (ievent >= b->GetEntries()) {
247  if (warn) {
248  fLog.SetProcessMethod("GetTrackList(Int_t, Option_t* )");
249  fLog << "index too large" << dolog;
250  }
251  return 0x0;
252  }
253 
254  fTrackList->Delete();
255 
256  b->SetAddress(&fTrackList);
257  b->GetEntry(ievent);
258  return fTrackList;
259 }
260 
261 //__________________________________________________________
262 TClonesArray* AgataEventContainer::GetHitList(Int_t ievent, Option_t* type, Bool_t warn)
263 {
264  TString name = GetHitBranchName(type);
265  if (name.IsNull())
266  return 0x0;
267 
268  TBranch* b = fEventTree->GetBranch(name.Data());
269 
270  if (ievent >= b->GetEntries()) {
271  if (warn) {
272  fLog.SetProcessMethod("GetHitList(Int_t, Option_t* )");
273  fLog << "index too large" << dolog;
274  }
275  return 0x0;
276  }
277 
278  fHitList->Delete();
279 
280  b->SetAddress(&fHitList);
281  b->GetEntry(ievent);
282 
283  return fHitList;
284 }
285 
286 
287 //_________________________________________________________
288 
289 //__________________________________________________________
291  : TObject(),
292  fTrackList(new TClonesArray("Gw::StdHit"))
293 {
294  fTrackList->SetOwner(true);
295 }
296 
297 //__________________________________________________________
299 {
300  delete fTrackList;
301 }
302 
303 //__________________________________________________________
304 Int_t TrackHit::GetNbHits() const
305 {
306  return fTrackList->GetEntries();
307 }
308 
309 //__________________________________________________________
311 {
312  TClonesArray &hitArray = *fTrackList;
313  StdHit* hit = new(hitArray[hitArray.GetEntriesFast()]) StdHit();
314 
315  return hit;
316 }
317 
318 //__________________________________________________________
319 StdHit* TrackHit::GetHit(Int_t i) const
320 {
321  if (i >= fTrackList->GetEntries() && i >= 0)
322  return 0x0;
323 
324  return (StdHit*)fTrackList->At(i);
325 
326 }
AgataEventContainer class that contains agata event to be displayed.
TBrowser * b
const Char_t * RegisterBranch(Option_t *type="")
Register branch, return name of type.
Int_t GetIndex(Option_t *type) const
Get index from type.
LogMessage & error(LogMessage &)
StdHit * NewHit()
Add a new hit to the track (filling mode). The Stack is emptied by calling Reset. ...
void FillTracks(Option_t *type="Agata")
TClonesArray * GetHitList(Int_t ievent, Option_t *type="Agata", Bool_t warn=true)
get array
BaseEventContainer base class that contains event for display.
StdHit * GetHit(Int_t i=0) const
Get Hit number i of the track (already added with NewHit !!)
Int_t GetNbHits() const
It returns the number of hits for this tracked particle.
LogMessage & dolog(LogMessage &)
void ClearEvents()
clear list or delete when dynamical memory allocation
void FillHits(Option_t *type="Agata")
Fill Event.
TClonesArray * GetTrackList(Int_t ievent, Option_t *type="Agata", Bool_t warn=true)
get array
TrackHit * NewTrackHit(Option_t *type="Agata")
add current track hit (added to current track hit list)
StdHit * NewHit(Option_t *type="Agata")
add current hit (added to current hit list)
virtual std::string & GetProcessName()
To get the Process name.
Definition: GwLogMessage.h:224
ClassImp(BaseNucleus)
virtual void SetProcessMethod(const char *)
To set the current method.