AliRoot Core  edcc906 (edcc906)
AliDetector.cxx
Go to the documentation of this file.
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 
19 // //
20 // Base class for ALICE modules. Both sensitive modules (detectors) and //
21 // non-sensitive ones are described by this base class. This class //
22 // supports the hit and digit trees produced by the simulation and also //
23 // the objects produced by the reconstruction. //
24 // //
25 // This class is also responsible for building the geometry of the //
26 // detectors. //
27 // //
28 //Begin_Html
29 /*
30 <img src="picts/AliDetectorClass.gif">
31 */
32 //End_Html
33 // //
35 
36 #include <TBrowser.h>
37 #include <TClonesArray.h>
38 #include <TTree.h>
39 
40 #include "AliLog.h"
41 #include "AliConfig.h"
42 #include "AliDetector.h"
43 #include "AliHit.h"
44 #include "AliLoader.h"
45 #include "AliRun.h"
46 #include "AliMC.h"
47 
48 
49 ClassImp(AliDetector)
50 
51 //_______________________________________________________________________
53  AliModule(),
54  fTimeGate(200.e-9),
55  fIshunt(0),
56  fNhits(0),
57  fNdigits(0),
58  fBufferSize(1600),
59  fMaxIterHit(0),
60  fCurIterHit(0),
61  fHits(0),
62  fDigits(0),
63  fLoader(0x0)
64 {
65  //
66  // Default constructor for the AliDetector class
67  //
68 }
69 
70 //_____________________________________________________________________________
71 AliDetector::AliDetector(const char* name,const char *title):
72  AliModule(name,title),
73  fTimeGate(200.e-9),
74  fIshunt(0),
75  fNhits(0),
76  fNdigits(0),
77  fBufferSize(1600),
78  fMaxIterHit(0),
79  fCurIterHit(0),
80  fHits(0),
81  fDigits(0),
82  fLoader(0x0)
83 {
84  //
85  // Normal constructor invoked by all Detectors.
86  // Create the list for detector specific histograms
87  // Add this Detector to the global list of Detectors in Run.
88  //
89 
90  fActive = kTRUE;
91  AliConfig::Instance()->Add(this);
92 
93 }
94 
95 //_______________________________________________________________________
97 {
98  //
99  // Destructor
100  //
101 
102  // Delete digits structure
103  if (fDigits) {
104  fDigits->Delete();
105  delete fDigits;
106  fDigits = 0;
107  }
108 
109  if (fLoader)
110  {
111  fLoader->GetModulesFolder()->Remove(this);
112  }
113 
114 }
115 
116 //_______________________________________________________________________
117 void AliDetector::Publish(const char */*dir*/, void */*address*/, const char */*name*/) const
118 {
119 //
120 // Register pointer to detector objects.
121 //
122  MayNotUse("Publish");
123 }
124 
125 //_______________________________________________________________________
127 {
128  //
129  AliWarning(Form("%s still has to implement the AddAlignableVolumes method!",GetName()));
130 }
131 
132 //_______________________________________________________________________
133 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
134  void* address, Int_t size,
135  const char *file)
136 {
137  return(MakeBranchInTree(tree,name,0,address,size,99,file));
138 }
139 
140 //_______________________________________________________________________
141 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
142  const char *classname,
143  void* address,Int_t size,
144  Int_t splitlevel, const char */*file*/)
145 {
146 //
147 // Makes branch in given tree and diverts them to a separate file
148 //
149 //
150 //
151 
152  AliDebug(2,Form("Making Branch %s",name));
153  if (tree == 0x0)
154  {
155  AliError(Form("Making Branch %s Tree is NULL",name));
156  return 0x0;
157  }
158  TBranch *branch = tree->GetBranch(name);
159  if (branch)
160  {
161  AliDebug(2,Form("Branch %s is already in tree.",name));
162  return branch;
163  }
164 
165  if (classname)
166  {
167  branch = tree->Branch(name,classname,address,size,splitlevel);
168  }
169  else
170  {
171  branch = tree->Bronch(name, "TClonesArray", address, size, splitlevel);
172  }
173  AliDebug(2,Form("Branch %s returning branch %p",name,branch));
174  return branch;
175 }
176 
177 //_______________________________________________________________________
178 void AliDetector::Browse(TBrowser *b)
179 {
180  //
181  // Insert Detector objects in the list of objects to be browsed
182  //
183  char name[64]="";
184  if( fHits == 0) return;
185  TObject *obj;
186  Int_t i, nobjects;
187  //
188  nobjects = fHits->GetEntries();
189  for (i=0;i<nobjects;i++) {
190  obj = fHits->At(i);
191  snprintf(name,63,"%s_%d",obj->GetName(),i);
192  b->Add(obj, &name[0]);
193  }
194 }
195 
196 //_______________________________________________________________________
198 {
199  //
200  // Procedure called at the end of a run.
201  //
202 }
203 
204 //_______________________________________________________________________
206 {
207  //
208  // Initialise the hit iterator
209  // Return the address of the first hit for track
210  // If track>=0 the track is read from disk
211  // while if track<0 the first hit of the current
212  // track is returned
213  //
214  if(track>=0) {
215  gAlice->GetMCApp()->ResetHits(); //stupid = if N detector this method is called N times
216  fLoader->TreeH()->GetEvent(track); //skowron
217  }
218  //
219  fMaxIterHit=fHits->GetEntriesFast();
220  fCurIterHit=0;
221  if(fMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
222  else return 0;
223 }
224 
225 //_______________________________________________________________________
227 {
228  //
229  // Return the next hit for the current track
230  //
231  if(fMaxIterHit) {
232  if(++fCurIterHit<fMaxIterHit)
233  return dynamic_cast<AliHit*>(fHits->UncheckedAt(fCurIterHit));
234  else
235  return 0;
236  } else {
237  AliWarning("Hit Iterator called without calling FistHit before");
238  return 0;
239  }
240 }
241 
242 //_______________________________________________________________________
243 void AliDetector::MakeBranch(Option_t *option)
244 {
245  //
246  // Create a new branch for this detector in its treeH
247  //
248 
249  AliDebug(2,Form(" for %s",GetName()));
250  const char *cH = strstr(option,"H");
251 
252  if (fHits && fLoader->TreeH() && cH)
253  {
254  MakeBranchInTree(fLoader->TreeH(), GetName(), &fHits, fBufferSize, 0);
255  }
256 }
257 
258 //_______________________________________________________________________
260 {
261  //
262  // Reset number of digits and the digits array
263  //
264  fNdigits = 0;
265  if (fDigits) fDigits->Clear();
266 }
267 
268 //_______________________________________________________________________
270 {
271  //
272  // Reset number of hits and the hits array
273  //
274  fNhits = 0;
275  if (fHits) fHits->Clear();
276 }
277 
278 //_______________________________________________________________________
280 {
281  //
282  // Set branch address for the Hits and Digits Trees
283  //
284  TBranch *branch;
285  //
286  // Branch address for hit tree
287 
288  TTree* tree = fLoader->TreeH();
289  if (tree && fHits) {
290  branch = tree->GetBranch(GetName());
291  if (branch)
292  {
293  AliDebug(2,Form("(%s) Setting for Hits",GetName()));
294  branch->SetAddress(&fHits);
295  }
296  else
297  { //can be invoked before branch creation
298  AliDebug(2,Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
299  }
300  }
301 
302  //
303  // Branch address for digit tree
304  TTree *treeD = fLoader->TreeD();
305  if (treeD && fDigits) {
306  branch = treeD->GetBranch(GetName());
307  if (branch) branch->SetAddress(&fDigits);
308  }
309 }
310 
311 //_______________________________________________________________________
312 void AliDetector::MakeTree(Option_t *option)
313  {
314  //makes a tree (container) for the data defined in option
315  //"H" - hits
316  //"D" - digits
317  //"S" - summable digits
318  //"R" - recontructed points and tracks
319 
320  AliLoader* loader = GetLoader();
321  if (loader == 0x0)
322  {
323  AliError(Form("Can not get loader for %s",GetName()));
324  return;
325  }
326  loader->MakeTree(option); //delegate this job to getter
327  }
328 
329 //_______________________________________________________________________
330 AliLoader* AliDetector::MakeLoader(const char* topfoldername)
331 {
332 //builds standard getter (AliLoader type)
333 //if detector wants to use castomized getter, it must overload this method
334 
335  AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
336  GetName(),topfoldername));
337 
338  fLoader = new AliLoader(GetName(),topfoldername);
339  return fLoader;
340 }
341 
342 
TBrowser b
Definition: RunAnaESD.C:12
TClonesArray * fHits
Counter for the hit iterator.
Definition: AliDetector.h:79
Int_t fBufferSize
Number of digits.
Definition: AliDetector.h:76
virtual ~AliDetector()
Definition: AliDetector.cxx:96
virtual void SetTreeAddress()
Int_t fCurIterHit
Limit for the hit iterator.
Definition: AliDetector.h:78
Definition: AliHit.h:14
virtual void MakeTree(Option_t *opt)
Definition: AliLoader.cxx:346
Int_t fNhits
Definition: AliDetector.h:74
TTree * TreeD() const
Definition: AliLoader.h:87
virtual AliHit * NextHit()
Int_t fMaxIterHit
buffer size for Tree detector branches
Definition: AliDetector.h:77
Int_t fNdigits
Number of hits.
Definition: AliDetector.h:75
AliTPCfastTrack * track
TTree * tree
#define AliWarning(message)
Definition: AliLog.h:541
virtual void ResetHits()
virtual void FinishRun()
void Add(TDatabasePDG *pdg)
Definition: AliConfig.cxx:180
virtual void Browse(TBrowser *b)
AliLoader * fLoader
List of digits for this detector.
Definition: AliDetector.h:82
virtual void MakeBranch(Option_t *opt=" ")
TClonesArray * fDigits
List of hits for one track only.
Definition: AliDetector.h:80
AliRun * gAlice
Definition: AliRun.cxx:62
virtual TBranch * MakeBranchInTree(TTree *tree, const char *cname, void *address, Int_t size=32000, const char *file=0)
virtual void Publish(const char *dir, void *c, const char *name=0) const
virtual AliLoader * MakeLoader(const char *topfoldername)
virtual AliHit * FirstHit(Int_t track)
Bool_t fActive
Maximum tracking medium ID for this Module.
Definition: AliModule.h:162
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
TTree * TreeH() const
Definition: AliLoader.h:83
AliLoader * GetLoader() const
Definition: AliDetector.h:67
void MakeTree(Option_t *option)
#define AliError(message)
Definition: AliLog.h:591
virtual void ResetHits()
Definition: AliMC.cxx:1432
virtual void AddAlignableVolumes() const
virtual void ResetDigits()
static AliConfig * Instance()
Definition: AliConfig.cxx:87
TFolder * GetModulesFolder()
Definition: AliLoader.cxx:255
AliMC * GetMCApp() const
Definition: AliRun.h:53