]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliDetector.cxx
Initialize arrays in constructor (Ivana)
[u/mrichter/AliRoot.git] / 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>
6644b9ca 37#include <TTree.h>
fe4da5cc 38
594d8990 39#include "AliLog.h"
9e1a0ddb 40#include "AliConfig.h"
94de3818 41#include "AliDetector.h"
94de3818 42#include "AliHit.h"
43#include "AliPoints.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),
59 fHits(0),
60 fDigits(0),
88cb7938 61 fPoints(0),
62 fLoader(0x0)
fe4da5cc 63{
64 //
65 // Default constructor for the AliDetector class
66 //
fe4da5cc 67}
68
e2afb3b6 69//_______________________________________________________________________
70AliDetector::AliDetector(const AliDetector &det):
71 AliModule(det),
72 fTimeGate(200.e-9),
73 fIshunt(0),
74 fNhits(0),
75 fNdigits(0),
76 fBufferSize(1600),
77 fHits(0),
78 fDigits(0),
88cb7938 79 fPoints(0),
80 fLoader(0x0)
e2afb3b6 81{
82 det.Copy(*this);
83}
84
fe4da5cc 85//_____________________________________________________________________________
6644b9ca 86AliDetector::AliDetector(const char* name,const char *title):
87 AliModule(name,title),
88 fTimeGate(200.e-9),
89 fIshunt(0),
90 fNhits(0),
91 fNdigits(0),
92 fBufferSize(1600),
93 fHits(0),
94 fDigits(0),
88cb7938 95 fPoints(0),
96 fLoader(0x0)
fe4da5cc 97{
98 //
99 // Normal constructor invoked by all Detectors.
100 // Create the list for detector specific histograms
101 // Add this Detector to the global list of Detectors in Run.
102 //
103
fe4da5cc 104 fActive = kTRUE;
9e1a0ddb 105 AliConfig::Instance()->Add(this);
aab9c8d5 106
fe4da5cc 107}
108
6644b9ca 109//_______________________________________________________________________
fe4da5cc 110AliDetector::~AliDetector()
111{
112 //
113 // Destructor
114 //
6644b9ca 115
fe4da5cc 116 // Delete space point structure
e460afec 117 if (fPoints) {
118 fPoints->Delete();
119 delete fPoints;
120 fPoints = 0;
121 }
122 // Delete digits structure
123 if (fDigits) {
124 fDigits->Delete();
125 delete fDigits;
126 fDigits = 0;
127 }
88cb7938 128
129 if (fLoader)
130 {
131 fLoader->GetModulesFolder()->Remove(this);
132 }
133
fe4da5cc 134}
9e1a0ddb 135
6644b9ca 136//_______________________________________________________________________
3a83c716 137void AliDetector::Publish(const char */*dir*/, void */*address*/, const char */*name*/) const
9e1a0ddb 138{
88cb7938 139//
140// Register pointer to detector objects.
141//
88cb7938 142 MayNotUse("Publish");
9e1a0ddb 143}
144
6644b9ca 145//_______________________________________________________________________
146TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
147 void* address, Int_t size,
148 const char *file)
9e1a0ddb 149{
d0f40f23 150 return(MakeBranchInTree(tree,name,0,address,size,99,file));
9e1a0ddb 151}
152
6644b9ca 153//_______________________________________________________________________
154TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
155 const char *classname,
156 void* address,Int_t size,
d1898505 157 Int_t splitlevel, const char */*file*/)
9e1a0ddb 158{
88cb7938 159//
160// Makes branch in given tree and diverts them to a separate file
161//
162//
163//
164// if (GetDebug()>1)
a96ab15b 165
594d8990 166 AliDebug(2,Form("Making Branch %s",name));
88cb7938 167 if (tree == 0x0)
168 {
594d8990 169 AliError(Form("Making Branch %s Tree is NULL",name));
88cb7938 170 return 0x0;
171 }
172 TBranch *branch = tree->GetBranch(name);
173 if (branch)
174 {
594d8990 175 AliDebug(2,Form("Branch %s is already in tree.",name));
9e1a0ddb 176 return branch;
88cb7938 177 }
178
179 if (classname)
180 {
181 branch = tree->Branch(name,classname,address,size,splitlevel);
182 }
183 else
184 {
a96ab15b 185 branch = tree->Bronch(name, "TClonesArray", address, size, splitlevel);
88cb7938 186 }
594d8990 187 AliDebug(2,Form("Branch %s returning branch %#x",name,branch));
88cb7938 188 return branch;
9e1a0ddb 189}
190
6644b9ca 191//_______________________________________________________________________
fe4da5cc 192void AliDetector::Browse(TBrowser *b)
193{
194 //
195 // Insert Detector objects in the list of objects to be browsed
196 //
197 char name[64];
198 if( fHits == 0) return;
199 TObject *obj;
200 Int_t i, nobjects;
201 //
202 nobjects = fHits->GetEntries();
203 for (i=0;i<nobjects;i++) {
204 obj = fHits->At(i);
205 sprintf(name,"%s_%d",obj->GetName(),i);
206 b->Add(obj, &name[0]);
207 }
208}
209
6644b9ca 210//_______________________________________________________________________
6c4904c2 211void AliDetector::Copy(TObject &) const
8918e700 212{
213 //
214 // Copy *this onto det -- not implemented
215 //
594d8990 216 AliFatal("Not implemented");
8918e700 217}
218
6644b9ca 219//_______________________________________________________________________
fe4da5cc 220void AliDetector::FinishRun()
221{
222 //
223 // Procedure called at the end of a run.
224 //
225}
226
6644b9ca 227//_______________________________________________________________________
fe4da5cc 228AliHit* AliDetector::FirstHit(Int_t track)
229{
230 //
231 // Initialise the hit iterator
232 // Return the address of the first hit for track
233 // If track>=0 the track is read from disk
234 // while if track<0 the first hit of the current
235 // track is returned
236 //
237 if(track>=0) {
88cb7938 238 gAlice->ResetHits(); //stupid = if N detector this method is called N times
239 TreeH()->GetEvent(track); //skowron
fe4da5cc 240 }
241 //
3a83c716 242 fMaxIterHit=fHits->GetEntriesFast();
243 fCurIterHit=0;
244 if(fMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
fe4da5cc 245 else return 0;
246}
247
6644b9ca 248//_______________________________________________________________________
fe4da5cc 249AliHit* AliDetector::NextHit()
250{
251 //
252 // Return the next hit for the current track
253 //
3a83c716 254 if(fMaxIterHit) {
255 if(++fCurIterHit<fMaxIterHit)
256 return dynamic_cast<AliHit*>(fHits->UncheckedAt(fCurIterHit));
fe4da5cc 257 else
258 return 0;
259 } else {
594d8990 260 AliWarning("Hit Iterator called without calling FistHit before");
fe4da5cc 261 return 0;
262 }
263}
6644b9ca 264
6644b9ca 265//_______________________________________________________________________
fe4da5cc 266void AliDetector::LoadPoints(Int_t)
267{
268 //
269 // Store x, y, z of all hits in memory
270 //
88cb7938 271 if (fHits == 0)
272 {
594d8990 273 AliError(Form("fHits == 0. Name is %s",GetName()));
88cb7938 274 return;
275 }
fe4da5cc 276 //
fe4da5cc 277 Int_t nhits = fHits->GetEntriesFast();
88cb7938 278 if (nhits == 0)
279 {
280// Error("LoadPoints","nhits == 0. Name is %s",GetName());
281 return;
282 }
5d12ce38 283 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
080a67a1 284 if (fPoints == 0) fPoints = new TObjArray(tracks);
fe4da5cc 285 AliHit *ahit;
286 //
080a67a1 287 Int_t *ntrk=new Int_t[tracks];
288 Int_t *limi=new Int_t[tracks];
289 Float_t **coor=new Float_t*[tracks];
290 for(Int_t i=0;i<tracks;i++) {
291 ntrk[i]=0;
292 coor[i]=0;
293 limi[i]=0;
294 }
295 //
fe4da5cc 296 AliPoints *points = 0;
080a67a1 297 Float_t *fp=0;
298 Int_t trk;
299 Int_t chunk=nhits/4+1;
fe4da5cc 300 //
301 // Loop over all the hits and store their position
302 for (Int_t hit=0;hit<nhits;hit++) {
e2afb3b6 303 ahit = dynamic_cast<AliHit*>(fHits->UncheckedAt(hit));
080a67a1 304 trk=ahit->GetTrack();
594d8990 305 if(trk>tracks) AliFatal(Form("Found track number %d, max track %d",trk, tracks));
88cb7938 306 if(ntrk[trk]==limi[trk])
307 {
fe4da5cc 308 //
309 // Initialise a new track
080a67a1 310 fp=new Float_t[3*(limi[trk]+chunk)];
88cb7938 311 if(coor[trk])
312 {
313 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
314 delete [] coor[trk];
315 }
080a67a1 316 limi[trk]+=chunk;
317 coor[trk] = fp;
88cb7938 318 }
319 else
320 {
080a67a1 321 fp = coor[trk];
88cb7938 322 }
94de3818 323 fp[3*ntrk[trk] ] = ahit->X();
324 fp[3*ntrk[trk]+1] = ahit->Y();
325 fp[3*ntrk[trk]+2] = ahit->Z();
080a67a1 326 ntrk[trk]++;
327 }
328 //
329 for(trk=0; trk<tracks; ++trk) {
330 if(ntrk[trk]) {
331 points = new AliPoints();
fe4da5cc 332 points->SetMarkerColor(GetMarkerColor());
fe4da5cc 333 points->SetMarkerSize(GetMarkerSize());
334 points->SetDetector(this);
335 points->SetParticle(trk);
080a67a1 336 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
337 fPoints->AddAt(points,trk);
338 delete [] coor[trk];
339 coor[trk]=0;
fe4da5cc 340 }
fe4da5cc 341 }
080a67a1 342 delete [] coor;
343 delete [] ntrk;
344 delete [] limi;
fe4da5cc 345}
346
6644b9ca 347//_______________________________________________________________________
88cb7938 348void AliDetector::MakeBranch(Option_t *option)
fe4da5cc 349{
350 //
88cb7938 351 // Create a new branch for this detector in its treeH
fe4da5cc 352 //
88cb7938 353
594d8990 354 AliDebug(2,Form(" for %s",GetName()));
5cf7bbad 355 const char *cH = strstr(option,"H");
2ab0c725 356
88cb7938 357 if (fHits && TreeH() && cH)
358 {
359 MakeBranchInTree(TreeH(), GetName(), &fHits, fBufferSize, 0);
360 }
aab9c8d5 361}
fe4da5cc 362
6644b9ca 363//_______________________________________________________________________
fe4da5cc 364void AliDetector::ResetDigits()
365{
366 //
367 // Reset number of digits and the digits array
368 //
369 fNdigits = 0;
88cb7938 370 if (fDigits) fDigits->Clear();
fe4da5cc 371}
372
6644b9ca 373//_______________________________________________________________________
fe4da5cc 374void AliDetector::ResetHits()
375{
376 //
377 // Reset number of hits and the hits array
378 //
379 fNhits = 0;
88cb7938 380 if (fHits) fHits->Clear();
fe4da5cc 381}
382
6644b9ca 383//_______________________________________________________________________
fe4da5cc 384void AliDetector::ResetPoints()
385{
386 //
387 // Reset array of points
388 //
389 if (fPoints) {
390 fPoints->Delete();
391 delete fPoints;
392 fPoints = 0;
393 }
394}
395
6644b9ca 396//_______________________________________________________________________
fe4da5cc 397void AliDetector::SetTreeAddress()
398{
399 //
400 // Set branch address for the Hits and Digits Trees
401 //
402 TBranch *branch;
fe4da5cc 403 //
404 // Branch address for hit tree
88cb7938 405
406 TTree *tree = TreeH();
407 if (tree && fHits) {
408 branch = tree->GetBranch(GetName());
409 if (branch)
410 {
594d8990 411 AliDebug(2,Form("(%s) Setting for Hits",GetName()));
88cb7938 412 branch->SetAddress(&fHits);
413 }
414 else
f2a509af 415 { //can be invoked before branch creation
594d8990 416 AliDebug(2,Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
88cb7938 417 }
fe4da5cc 418 }
88cb7938 419
fe4da5cc 420 //
421 // Branch address for digit tree
88cb7938 422 TTree *treeD = fLoader->TreeD();
fe4da5cc 423 if (treeD && fDigits) {
88cb7938 424 branch = treeD->GetBranch(GetName());
fe4da5cc 425 if (branch) branch->SetAddress(&fDigits);
426 }
2cad796f 427
428 AliModule::SetTreeAddress();
fe4da5cc 429}
430
88cb7938 431//_______________________________________________________________________
432void AliDetector::MakeTree(Option_t *option)
433 {
434 //makes a tree (container) for the data defined in option
435 //"H" - hits
436 //"D" - digits
437 //"S" - summable digits
438 //"R" - recontructed points and tracks
fe4da5cc 439
88cb7938 440 AliLoader* loader = GetLoader();
441 if (loader == 0x0)
442 {
594d8990 443 AliError(Form("Can not get loader for %s",GetName()));
88cb7938 444 return;
445 }
446 loader->MakeTree(option); //delegate this job to getter
447 }
448
449//_______________________________________________________________________
450AliLoader* AliDetector::MakeLoader(const char* topfoldername)
451{
452//builds standard getter (AliLoader type)
453//if detector wants to use castomized getter, it must overload this method
454
594d8990 455 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
456 GetName(),topfoldername));
88cb7938 457
458 fLoader = new AliLoader(GetName(),topfoldername);
459 return fLoader;
88cb7938 460}
461
462//_______________________________________________________________________
3a83c716 463TTree* AliDetector::TreeH() const
88cb7938 464{
465//Get the hits container from the folder
466 if (GetLoader() == 0x0)
467 {
468 //sunstitude this with make getter when we can obtain the event folder name
594d8990 469 AliError("Can not get the getter");
88cb7938 470 return 0x0;
471 }
472
473 TTree* tree = (TTree*)GetLoader()->TreeH();
474 return tree;
475}
476