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