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