]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliDetector.cxx
STAGE_POOL and STAGE_HOST defined
[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
16/*
17$Log$
2ab0c725 18Revision 1.10 2001/01/17 10:50:50 hristov
19Corrections to destructors
20
e460afec 21Revision 1.9 2000/12/12 18:19:06 alibrary
22Introduce consistency check when loading points
23
27d40e08 24Revision 1.8 2000/11/30 07:12:48 alibrary
25Introducing new Rndm and QA classes
26
65fb704d 27Revision 1.7 2000/10/02 21:28:14 fca
28Removal of useless dependecies via forward declarations
29
94de3818 30Revision 1.6 2000/07/12 08:56:25 fca
31Coding convention correction and warning removal
32
8918e700 33Revision 1.5 1999/09/29 09:24:29 fca
34Introduction of the Copyright and cvs Log
35
4c039060 36*/
37
fe4da5cc 38///////////////////////////////////////////////////////////////////////////////
39// //
40// Base class for ALICE modules. Both sensitive modules (detectors) and //
41// non-sensitive ones are described by this base class. This class //
42// supports the hit and digit trees produced by the simulation and also //
43// the objects produced by the reconstruction. //
44// //
45// This class is also responsible for building the geometry of the //
46// detectors. //
47// //
48//Begin_Html
49/*
1439f98e 50<img src="picts/AliDetectorClass.gif">
fe4da5cc 51*/
52//End_Html
53// //
54///////////////////////////////////////////////////////////////////////////////
65fb704d 55
27d40e08 56#include <assert.h>
57
94de3818 58#include <TTree.h>
2ab0c725 59#include <TBrowser.h>
60#include <TFile.h>
fe4da5cc 61
94de3818 62#include "AliDetector.h"
63#include "AliRun.h"
64#include "AliHit.h"
65#include "AliPoints.h"
fe4da5cc 66// Static variables for the hit iterator routines
67static Int_t sMaxIterHit=0;
68static Int_t sCurIterHit=0;
69
70ClassImp(AliDetector)
71
72//_____________________________________________________________________________
73AliDetector::AliDetector()
74{
75 //
76 // Default constructor for the AliDetector class
77 //
78 fNhits = 0;
79 fNdigits = 0;
fe4da5cc 80 fPoints = 0;
81 fHits = 0;
82 fDigits = 0;
83 fTimeGate = 200.e-9;
fe4da5cc 84 fBufferSize = 16000;
2ab0c725 85 fDigitsFile = 0;
fe4da5cc 86}
87
88//_____________________________________________________________________________
8494b010 89AliDetector::AliDetector(const char* name,const char *title):AliModule(name,title)
fe4da5cc 90{
91 //
92 // Normal constructor invoked by all Detectors.
93 // Create the list for detector specific histograms
94 // Add this Detector to the global list of Detectors in Run.
95 //
96
97 fTimeGate = 200.e-9;
98 fActive = kTRUE;
99 fNhits = 0;
100 fHits = 0;
101 fDigits = 0;
102 fNdigits = 0;
103 fPoints = 0;
104 fBufferSize = 16000;
2ab0c725 105 fDigitsFile = 0;
fe4da5cc 106}
107
108//_____________________________________________________________________________
109AliDetector::~AliDetector()
110{
111 //
112 // Destructor
113 //
114 fNhits = 0;
115 fNdigits = 0;
fe4da5cc 116 //
117 // Delete space point structure
e460afec 118 if (fPoints) {
119 fPoints->Delete();
120 delete fPoints;
121 fPoints = 0;
122 }
123 // Delete digits structure
124 if (fDigits) {
125 fDigits->Delete();
126 delete fDigits;
127 fDigits = 0;
128 }
2ab0c725 129 if (fDigitsFile) delete [] fDigitsFile;
fe4da5cc 130}
131
132//_____________________________________________________________________________
133void AliDetector::Browse(TBrowser *b)
134{
135 //
136 // Insert Detector objects in the list of objects to be browsed
137 //
138 char name[64];
139 if( fHits == 0) return;
140 TObject *obj;
141 Int_t i, nobjects;
142 //
143 nobjects = fHits->GetEntries();
144 for (i=0;i<nobjects;i++) {
145 obj = fHits->At(i);
146 sprintf(name,"%s_%d",obj->GetName(),i);
147 b->Add(obj, &name[0]);
148 }
149}
150
8918e700 151//_____________________________________________________________________________
152void AliDetector::Copy(AliDetector &det) const
153{
154 //
155 // Copy *this onto det -- not implemented
156 //
157 Fatal("Copy","Not implemented~\n");
158}
159
fe4da5cc 160//_____________________________________________________________________________
161void AliDetector::FinishRun()
162{
163 //
164 // Procedure called at the end of a run.
165 //
166}
167
168//_____________________________________________________________________________
169AliHit* AliDetector::FirstHit(Int_t track)
170{
171 //
172 // Initialise the hit iterator
173 // Return the address of the first hit for track
174 // If track>=0 the track is read from disk
175 // while if track<0 the first hit of the current
176 // track is returned
177 //
178 if(track>=0) {
179 gAlice->ResetHits();
180 gAlice->TreeH()->GetEvent(track);
181 }
182 //
183 sMaxIterHit=fHits->GetEntriesFast();
184 sCurIterHit=0;
185 if(sMaxIterHit) return (AliHit*) fHits->UncheckedAt(0);
186 else return 0;
187}
188
189//_____________________________________________________________________________
190AliHit* AliDetector::NextHit()
191{
192 //
193 // Return the next hit for the current track
194 //
195 if(sMaxIterHit) {
196 if(++sCurIterHit<sMaxIterHit)
197 return (AliHit*) fHits->UncheckedAt(sCurIterHit);
198 else
199 return 0;
200 } else {
201 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
202 return 0;
203 }
204}
205
206//_____________________________________________________________________________
207void AliDetector::LoadPoints(Int_t)
208{
209 //
210 // Store x, y, z of all hits in memory
211 //
212 if (fHits == 0) return;
213 //
fe4da5cc 214 Int_t nhits = fHits->GetEntriesFast();
215 if (nhits == 0) return;
080a67a1 216 Int_t tracks = gAlice->GetNtrack();
217 if (fPoints == 0) fPoints = new TObjArray(tracks);
fe4da5cc 218 AliHit *ahit;
219 //
080a67a1 220 Int_t *ntrk=new Int_t[tracks];
221 Int_t *limi=new Int_t[tracks];
222 Float_t **coor=new Float_t*[tracks];
223 for(Int_t i=0;i<tracks;i++) {
224 ntrk[i]=0;
225 coor[i]=0;
226 limi[i]=0;
227 }
228 //
fe4da5cc 229 AliPoints *points = 0;
080a67a1 230 Float_t *fp=0;
231 Int_t trk;
232 Int_t chunk=nhits/4+1;
fe4da5cc 233 //
234 // Loop over all the hits and store their position
235 for (Int_t hit=0;hit<nhits;hit++) {
236 ahit = (AliHit*)fHits->UncheckedAt(hit);
080a67a1 237 trk=ahit->GetTrack();
27d40e08 238 assert(trk<=tracks);
080a67a1 239 if(ntrk[trk]==limi[trk]) {
fe4da5cc 240 //
241 // Initialise a new track
080a67a1 242 fp=new Float_t[3*(limi[trk]+chunk)];
243 if(coor[trk]) {
244 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
245 delete [] coor[trk];
246 }
247 limi[trk]+=chunk;
248 coor[trk] = fp;
249 } else {
250 fp = coor[trk];
251 }
94de3818 252 fp[3*ntrk[trk] ] = ahit->X();
253 fp[3*ntrk[trk]+1] = ahit->Y();
254 fp[3*ntrk[trk]+2] = ahit->Z();
080a67a1 255 ntrk[trk]++;
256 }
257 //
258 for(trk=0; trk<tracks; ++trk) {
259 if(ntrk[trk]) {
260 points = new AliPoints();
fe4da5cc 261 points->SetMarkerColor(GetMarkerColor());
fe4da5cc 262 points->SetMarkerSize(GetMarkerSize());
263 points->SetDetector(this);
264 points->SetParticle(trk);
080a67a1 265 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
266 fPoints->AddAt(points,trk);
267 delete [] coor[trk];
268 coor[trk]=0;
fe4da5cc 269 }
fe4da5cc 270 }
080a67a1 271 delete [] coor;
272 delete [] ntrk;
273 delete [] limi;
fe4da5cc 274}
275
276//_____________________________________________________________________________
2ab0c725 277void AliDetector::MakeBranch(Option_t *option, char *file)
fe4da5cc 278{
279 //
280 // Create a new branch in the current Root Tree
281 // The branch of fHits is automatically split
282 //
2ab0c725 283
fe4da5cc 284 char branchname[10];
285 sprintf(branchname,"%s",GetName());
286 //
287 // Get the pointer to the header
8918e700 288 char *cH = strstr(option,"H");
fe4da5cc 289 //
2ab0c725 290 if (fHits && gAlice->TreeH() && cH) {
291 gAlice->MakeBranchInTree(gAlice->TreeH(),
292 branchname, &fHits, fBufferSize, file) ;
fe4da5cc 293 }
2ab0c725 294
295 char *cD = strstr(option,"D");
296
297 if (cD) {
298 if (file) {
299 fDigitsFile = new char[strlen (file)];
300 strcpy(fDigitsFile,file);
301 }
302 }
fe4da5cc 303}
304
fe4da5cc 305//_____________________________________________________________________________
306void AliDetector::ResetDigits()
307{
308 //
309 // Reset number of digits and the digits array
310 //
311 fNdigits = 0;
312 if (fDigits) fDigits->Clear();
313}
314
315//_____________________________________________________________________________
316void AliDetector::ResetHits()
317{
318 //
319 // Reset number of hits and the hits array
320 //
321 fNhits = 0;
322 if (fHits) fHits->Clear();
323}
324
325//_____________________________________________________________________________
326void AliDetector::ResetPoints()
327{
328 //
329 // Reset array of points
330 //
331 if (fPoints) {
332 fPoints->Delete();
333 delete fPoints;
334 fPoints = 0;
335 }
336}
337
fe4da5cc 338//_____________________________________________________________________________
339void AliDetector::SetTreeAddress()
340{
341 //
342 // Set branch address for the Hits and Digits Trees
343 //
344 TBranch *branch;
345 char branchname[20];
346 sprintf(branchname,"%s",GetName());
347 //
348 // Branch address for hit tree
349 TTree *treeH = gAlice->TreeH();
350 if (treeH && fHits) {
351 branch = treeH->GetBranch(branchname);
352 if (branch) branch->SetAddress(&fHits);
353 }
354 //
355 // Branch address for digit tree
356 TTree *treeD = gAlice->TreeD();
357 if (treeD && fDigits) {
358 branch = treeD->GetBranch(branchname);
359 if (branch) branch->SetAddress(&fDigits);
360 }
361}
362
fe4da5cc 363