Changes to compile with Root6 on macosx64
[u/mrichter/AliRoot.git] / STEER / STEER / AliDetector.cxx
CommitLineData
4c039060 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
acd84897 16/* $Id$ */
4c039060 17
fe4da5cc 18///////////////////////////////////////////////////////////////////////////////
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/*
1439f98e 30<img src="picts/AliDetectorClass.gif">
fe4da5cc 31*/
32//End_Html
33// //
34///////////////////////////////////////////////////////////////////////////////
65fb704d 35
2ab0c725 36#include <TBrowser.h>
7ca4655f 37#include <TClonesArray.h>
6644b9ca 38#include <TTree.h>
fe4da5cc 39
594d8990 40#include "AliLog.h"
9e1a0ddb 41#include "AliConfig.h"
94de3818 42#include "AliDetector.h"
94de3818 43#include "AliHit.h"
88cb7938 44#include "AliLoader.h"
6644b9ca 45#include "AliRun.h"
5d12ce38 46#include "AliMC.h"
aab9c8d5 47
9e1a0ddb 48
fe4da5cc 49ClassImp(AliDetector)
50
6644b9ca 51//_______________________________________________________________________
52AliDetector::AliDetector():
75c4b017 53 AliModule(),
6644b9ca 54 fTimeGate(200.e-9),
55 fIshunt(0),
56 fNhits(0),
57 fNdigits(0),
58 fBufferSize(1600),
90e48c0c 59 fMaxIterHit(0),
60 fCurIterHit(0),
6644b9ca 61 fHits(0),
62 fDigits(0),
88cb7938 63 fLoader(0x0)
fe4da5cc 64{
65 //
66 // Default constructor for the AliDetector class
67 //
fe4da5cc 68}
69
70//_____________________________________________________________________________
6644b9ca 71AliDetector::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),
90e48c0c 78 fMaxIterHit(0),
79 fCurIterHit(0),
6644b9ca 80 fHits(0),
81 fDigits(0),
88cb7938 82 fLoader(0x0)
fe4da5cc 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
fe4da5cc 90 fActive = kTRUE;
9e1a0ddb 91 AliConfig::Instance()->Add(this);
aab9c8d5 92
fe4da5cc 93}
94
6644b9ca 95//_______________________________________________________________________
fe4da5cc 96AliDetector::~AliDetector()
97{
98 //
99 // Destructor
100 //
6644b9ca 101
e460afec 102 // Delete digits structure
103 if (fDigits) {
104 fDigits->Delete();
105 delete fDigits;
106 fDigits = 0;
107 }
88cb7938 108
109 if (fLoader)
110 {
111 fLoader->GetModulesFolder()->Remove(this);
112 }
113
fe4da5cc 114}
9e1a0ddb 115
6644b9ca 116//_______________________________________________________________________
3a83c716 117void AliDetector::Publish(const char */*dir*/, void */*address*/, const char */*name*/) const
9e1a0ddb 118{
88cb7938 119//
120// Register pointer to detector objects.
121//
88cb7938 122 MayNotUse("Publish");
9e1a0ddb 123}
124
6644b9ca 125//_______________________________________________________________________
4787b401 126void AliDetector::AddAlignableVolumes() const
127{
128 //
129 AliWarning(Form("%s still has to implement the AddAlignableVolumes method!",GetName()));
130}
131
132//_______________________________________________________________________
6644b9ca 133TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
134 void* address, Int_t size,
135 const char *file)
9e1a0ddb 136{
d0f40f23 137 return(MakeBranchInTree(tree,name,0,address,size,99,file));
9e1a0ddb 138}
139
6644b9ca 140//_______________________________________________________________________
141TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
142 const char *classname,
143 void* address,Int_t size,
d1898505 144 Int_t splitlevel, const char */*file*/)
9e1a0ddb 145{
88cb7938 146//
147// Makes branch in given tree and diverts them to a separate file
148//
149//
150//
a96ab15b 151
594d8990 152 AliDebug(2,Form("Making Branch %s",name));
88cb7938 153 if (tree == 0x0)
154 {
594d8990 155 AliError(Form("Making Branch %s Tree is NULL",name));
88cb7938 156 return 0x0;
157 }
158 TBranch *branch = tree->GetBranch(name);
159 if (branch)
160 {
594d8990 161 AliDebug(2,Form("Branch %s is already in tree.",name));
9e1a0ddb 162 return branch;
88cb7938 163 }
164
165 if (classname)
166 {
167 branch = tree->Branch(name,classname,address,size,splitlevel);
168 }
169 else
170 {
a96ab15b 171 branch = tree->Bronch(name, "TClonesArray", address, size, splitlevel);
88cb7938 172 }
73bbf779 173 AliDebug(2,Form("Branch %s returning branch %p",name,branch));
88cb7938 174 return branch;
9e1a0ddb 175}
176
6644b9ca 177//_______________________________________________________________________
fe4da5cc 178void AliDetector::Browse(TBrowser *b)
179{
180 //
181 // Insert Detector objects in the list of objects to be browsed
182 //
338da9aa 183 char name[64]="";
fe4da5cc 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);
338da9aa 191 snprintf(name,63,"%s_%d",obj->GetName(),i);
fe4da5cc 192 b->Add(obj, &name[0]);
193 }
194}
195
6644b9ca 196//_______________________________________________________________________
fe4da5cc 197void AliDetector::FinishRun()
198{
199 //
200 // Procedure called at the end of a run.
201 //
202}
203
6644b9ca 204//_______________________________________________________________________
fe4da5cc 205AliHit* AliDetector::FirstHit(Int_t track)
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) {
3e2e3ece 215 gAlice->GetMCApp()->ResetHits(); //stupid = if N detector this method is called N times
cb5b8b21 216 fLoader->TreeH()->GetEvent(track); //skowron
fe4da5cc 217 }
218 //
3a83c716 219 fMaxIterHit=fHits->GetEntriesFast();
220 fCurIterHit=0;
221 if(fMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
fe4da5cc 222 else return 0;
223}
224
6644b9ca 225//_______________________________________________________________________
fe4da5cc 226AliHit* AliDetector::NextHit()
227{
228 //
229 // Return the next hit for the current track
230 //
3a83c716 231 if(fMaxIterHit) {
232 if(++fCurIterHit<fMaxIterHit)
233 return dynamic_cast<AliHit*>(fHits->UncheckedAt(fCurIterHit));
fe4da5cc 234 else
235 return 0;
236 } else {
594d8990 237 AliWarning("Hit Iterator called without calling FistHit before");
fe4da5cc 238 return 0;
239 }
240}
6644b9ca 241
6644b9ca 242//_______________________________________________________________________
88cb7938 243void AliDetector::MakeBranch(Option_t *option)
fe4da5cc 244{
245 //
88cb7938 246 // Create a new branch for this detector in its treeH
fe4da5cc 247 //
88cb7938 248
594d8990 249 AliDebug(2,Form(" for %s",GetName()));
5cf7bbad 250 const char *cH = strstr(option,"H");
2ab0c725 251
cb5b8b21 252 if (fHits && fLoader->TreeH() && cH)
88cb7938 253 {
cb5b8b21 254 MakeBranchInTree(fLoader->TreeH(), GetName(), &fHits, fBufferSize, 0);
88cb7938 255 }
aab9c8d5 256}
fe4da5cc 257
6644b9ca 258//_______________________________________________________________________
fe4da5cc 259void AliDetector::ResetDigits()
260{
261 //
262 // Reset number of digits and the digits array
263 //
264 fNdigits = 0;
88cb7938 265 if (fDigits) fDigits->Clear();
fe4da5cc 266}
267
6644b9ca 268//_______________________________________________________________________
fe4da5cc 269void AliDetector::ResetHits()
270{
271 //
272 // Reset number of hits and the hits array
273 //
274 fNhits = 0;
88cb7938 275 if (fHits) fHits->Clear();
fe4da5cc 276}
277
6644b9ca 278//_______________________________________________________________________
fe4da5cc 279void AliDetector::SetTreeAddress()
280{
281 //
282 // Set branch address for the Hits and Digits Trees
283 //
284 TBranch *branch;
fe4da5cc 285 //
286 // Branch address for hit tree
88cb7938 287
cb5b8b21 288 TTree* tree = fLoader->TreeH();
88cb7938 289 if (tree && fHits) {
290 branch = tree->GetBranch(GetName());
291 if (branch)
292 {
594d8990 293 AliDebug(2,Form("(%s) Setting for Hits",GetName()));
88cb7938 294 branch->SetAddress(&fHits);
295 }
296 else
f2a509af 297 { //can be invoked before branch creation
594d8990 298 AliDebug(2,Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
88cb7938 299 }
fe4da5cc 300 }
88cb7938 301
fe4da5cc 302 //
303 // Branch address for digit tree
88cb7938 304 TTree *treeD = fLoader->TreeD();
fe4da5cc 305 if (treeD && fDigits) {
88cb7938 306 branch = treeD->GetBranch(GetName());
fe4da5cc 307 if (branch) branch->SetAddress(&fDigits);
308 }
309}
310
88cb7938 311//_______________________________________________________________________
312void 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
fe4da5cc 319
88cb7938 320 AliLoader* loader = GetLoader();
321 if (loader == 0x0)
322 {
594d8990 323 AliError(Form("Can not get loader for %s",GetName()));
88cb7938 324 return;
325 }
326 loader->MakeTree(option); //delegate this job to getter
327 }
328
329//_______________________________________________________________________
330AliLoader* 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
594d8990 335 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
336 GetName(),topfoldername));
88cb7938 337
338 fLoader = new AliLoader(GetName(),topfoldername);
339 return fLoader;
88cb7938 340}
341
88cb7938 342