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