]>
Commit | Line | Data |
---|---|---|
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$ | |
18 | Revision 1.16 2001/10/04 15:30:56 hristov | |
19 | Changes to accommodate the set of PHOS folders and tasks (Y.Schutz) | |
20 | ||
21 | Revision 1.15 2001/07/27 13:03:13 hristov | |
22 | Default Branch split level set to 99 | |
23 | ||
24 | Revision 1.14 2001/05/21 17:22:51 buncic | |
25 | Fixed problem with missing AliConfig while reading galice.root | |
26 | ||
27 | Revision 1.13 2001/05/16 14:57:22 alibrary | |
28 | New files for folders and Stack | |
29 | ||
30 | Revision 1.12 2001/03/12 17:47:03 hristov | |
31 | Changes needed on Sun with CC 5.0 | |
32 | ||
33 | Revision 1.11 2001/01/26 19:58:46 hristov | |
34 | Major upgrade of AliRoot code | |
35 | ||
36 | Revision 1.10 2001/01/17 10:50:50 hristov | |
37 | Corrections to destructors | |
38 | ||
39 | Revision 1.9 2000/12/12 18:19:06 alibrary | |
40 | Introduce consistency check when loading points | |
41 | ||
42 | Revision 1.8 2000/11/30 07:12:48 alibrary | |
43 | Introducing new Rndm and QA classes | |
44 | ||
45 | Revision 1.7 2000/10/02 21:28:14 fca | |
46 | Removal of useless dependecies via forward declarations | |
47 | ||
48 | Revision 1.6 2000/07/12 08:56:25 fca | |
49 | Coding convention correction and warning removal | |
50 | ||
51 | Revision 1.5 1999/09/29 09:24:29 fca | |
52 | Introduction of the Copyright and cvs Log | |
53 | ||
54 | */ | |
55 | ||
56 | /////////////////////////////////////////////////////////////////////////////// | |
57 | // // | |
58 | // Base class for ALICE modules. Both sensitive modules (detectors) and // | |
59 | // non-sensitive ones are described by this base class. This class // | |
60 | // supports the hit and digit trees produced by the simulation and also // | |
61 | // the objects produced by the reconstruction. // | |
62 | // // | |
63 | // This class is also responsible for building the geometry of the // | |
64 | // detectors. // | |
65 | // // | |
66 | //Begin_Html | |
67 | /* | |
68 | <img src="picts/AliDetectorClass.gif"> | |
69 | */ | |
70 | //End_Html | |
71 | // // | |
72 | /////////////////////////////////////////////////////////////////////////////// | |
73 | ||
74 | #include <assert.h> | |
75 | #include <iostream.h> | |
76 | ||
77 | #include <TTree.h> | |
78 | #include <TBrowser.h> | |
79 | #include <TFile.h> | |
80 | #include <TROOT.h> | |
81 | #include <TFolder.h> | |
82 | ||
83 | #include "AliConfig.h" | |
84 | #include "AliDetector.h" | |
85 | #include "AliRun.h" | |
86 | #include "AliHit.h" | |
87 | #include "AliPoints.h" | |
88 | #include "AliTrackReference.h" | |
89 | ||
90 | ||
91 | // Static variables for the hit iterator routines | |
92 | static Int_t sMaxIterHit=0; | |
93 | static Int_t sCurIterHit=0; | |
94 | ||
95 | ||
96 | ClassImp(AliDetector) | |
97 | ||
98 | //_____________________________________________________________________________ | |
99 | AliDetector::AliDetector() | |
100 | { | |
101 | // | |
102 | // Default constructor for the AliDetector class | |
103 | // | |
104 | fNhits = 0; | |
105 | fNdigits = 0; | |
106 | fPoints = 0; | |
107 | fHits = 0; | |
108 | fTrackReferences =0; | |
109 | fDigits = 0; | |
110 | fTimeGate = 200.e-9; | |
111 | fBufferSize = 16000; | |
112 | fDigitsFile = 0; | |
113 | } | |
114 | ||
115 | //_____________________________________________________________________________ | |
116 | AliDetector::AliDetector(const char* name,const char *title):AliModule(name,title) | |
117 | { | |
118 | // | |
119 | // Normal constructor invoked by all Detectors. | |
120 | // Create the list for detector specific histograms | |
121 | // Add this Detector to the global list of Detectors in Run. | |
122 | // | |
123 | ||
124 | fTimeGate = 200.e-9; | |
125 | fActive = kTRUE; | |
126 | fNhits = 0; | |
127 | fHits = 0; | |
128 | fTrackReferences =0; | |
129 | fDigits = 0; | |
130 | fNdigits = 0; | |
131 | fPoints = 0; | |
132 | fBufferSize = 16000; | |
133 | fDigitsFile = 0; | |
134 | ||
135 | AliConfig::Instance()->Add(this); | |
136 | ||
137 | fTrackReferences = new TClonesArray("AliTrackReference", 100); | |
138 | //if detector to want to create another track reference - than let's be free | |
139 | ||
140 | } | |
141 | ||
142 | //_____________________________________________________________________________ | |
143 | AliDetector::~AliDetector() | |
144 | { | |
145 | // | |
146 | // Destructor | |
147 | // | |
148 | fNhits = 0; | |
149 | fNdigits = 0; | |
150 | // | |
151 | // Delete space point structure | |
152 | if (fPoints) { | |
153 | fPoints->Delete(); | |
154 | delete fPoints; | |
155 | fPoints = 0; | |
156 | } | |
157 | // Delete digits structure | |
158 | if (fDigits) { | |
159 | fDigits->Delete(); | |
160 | delete fDigits; | |
161 | fDigits = 0; | |
162 | } | |
163 | if (fDigitsFile) delete [] fDigitsFile; | |
164 | } | |
165 | ||
166 | //_____________________________________________________________________________ | |
167 | void AliDetector::Publish(const char *dir, void *address, const char *name) | |
168 | { | |
169 | // | |
170 | // Register pointer to detector objects. | |
171 | // | |
172 | TFolder *topFolder = (TFolder *)gROOT->FindObjectAny("/Folders"); | |
173 | if (topFolder) { | |
174 | TFolder *folder = (TFolder *)topFolder->FindObjectAny(dir); | |
175 | // TFolder *folder = (TFolder *)gROOT->FindObjectAny(dir); | |
176 | if (!folder) { | |
177 | cerr << "Cannot register: Missing folder: " << dir << endl; | |
178 | } else { | |
179 | TFolder *subfolder = (TFolder *) folder->FindObjectAny(this->GetName()); | |
180 | ||
181 | if(!subfolder) | |
182 | subfolder = folder->AddFolder(this->GetName(),this->GetTitle()); | |
183 | if (address) { | |
184 | TObject **obj = (TObject **) address; | |
185 | if ((*obj)->InheritsFrom(TCollection::Class())) { | |
186 | TCollection *collection = (TCollection *) (*obj); | |
187 | if (name) | |
188 | collection->SetName(name); | |
189 | } | |
190 | subfolder->Add(*obj); | |
191 | } | |
192 | } | |
193 | } | |
194 | } | |
195 | ||
196 | //_____________________________________________________________________________ | |
197 | TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, void* address, Int_t size,const char *file) | |
198 | { | |
199 | return(MakeBranchInTree(tree,name,0,address,size,99,file)); | |
200 | } | |
201 | ||
202 | //_____________________________________________________________________________ | |
203 | TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, const char *classname, void* address,Int_t size, Int_t splitlevel, const char *file) | |
204 | { | |
205 | // | |
206 | // Makes branch in given tree and diverts them to a separate file | |
207 | // | |
208 | if (GetDebug()>1) | |
209 | printf("* MakeBranch * Making Branch %s \n",name); | |
210 | ||
211 | TDirectory *cwd = gDirectory; | |
212 | TBranch *branch = 0; | |
213 | ||
214 | if (classname) { | |
215 | branch = tree->Branch(name,classname,address,size,splitlevel); | |
216 | } else { | |
217 | branch = tree->Branch(name,address,size); | |
218 | } | |
219 | ||
220 | if (file) { | |
221 | char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2]; | |
222 | sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file); | |
223 | branch->SetFile(outFile); | |
224 | TIter next( branch->GetListOfBranches()); | |
225 | while ((branch=(TBranch*)next())) { | |
226 | branch->SetFile(outFile); | |
227 | } | |
228 | delete outFile; | |
229 | ||
230 | cwd->cd(); | |
231 | ||
232 | if (GetDebug()>1) | |
233 | printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file); | |
234 | } | |
235 | char *folder = 0; | |
236 | TString folderName(name); | |
237 | ||
238 | if (!strncmp(tree->GetName(),"TreeE",5)) folder = "RunMC/Event/Data"; | |
239 | if (!strncmp(tree->GetName(),"TreeK",5)) folder = "RunMC/Event/Data"; | |
240 | if (!strncmp(tree->GetName(),"TreeH",5)) { | |
241 | folder = "RunMC/Event/Data/Hits"; | |
242 | folderName = "Hits" ; | |
243 | } | |
244 | if (!strncmp(tree->GetName(),"TreeTrackReferences",5)) { | |
245 | folder = "RunMC/Event/Data/TrackReferences"; | |
246 | folderName = "TrackReferences" ; | |
247 | } | |
248 | ||
249 | if (!strncmp(tree->GetName(),"TreeD",5)) { | |
250 | folder = "Run/Event/Data"; | |
251 | folderName = "Digits" ; | |
252 | } | |
253 | if (!strncmp(tree->GetName(),"TreeS",5)) { | |
254 | folder = "RunMC/Event/Data/SDigits"; | |
255 | folderName = "SDigits" ; | |
256 | } | |
257 | if (!strncmp(tree->GetName(),"TreeR",5)) folder = "Run/Event/RecData"; | |
258 | ||
259 | if (folder) { | |
260 | if (GetDebug()) | |
261 | printf("%15s: Publishing %s to %s\n",ClassName(),name,folder); | |
262 | Publish(folder,address, folderName.Data()); | |
263 | } | |
264 | return branch; | |
265 | } | |
266 | ||
267 | //_____________________________________________________________________________ | |
268 | void AliDetector::Browse(TBrowser *b) | |
269 | { | |
270 | // | |
271 | // Insert Detector objects in the list of objects to be browsed | |
272 | // | |
273 | char name[64]; | |
274 | if( fHits == 0) return; | |
275 | TObject *obj; | |
276 | Int_t i, nobjects; | |
277 | // | |
278 | nobjects = fHits->GetEntries(); | |
279 | for (i=0;i<nobjects;i++) { | |
280 | obj = fHits->At(i); | |
281 | sprintf(name,"%s_%d",obj->GetName(),i); | |
282 | b->Add(obj, &name[0]); | |
283 | } | |
284 | } | |
285 | ||
286 | //_____________________________________________________________________________ | |
287 | void AliDetector::Copy(AliDetector &det) const | |
288 | { | |
289 | // | |
290 | // Copy *this onto det -- not implemented | |
291 | // | |
292 | Fatal("Copy","Not implemented~\n"); | |
293 | } | |
294 | ||
295 | //_____________________________________________________________________________ | |
296 | void AliDetector::FinishRun() | |
297 | { | |
298 | // | |
299 | // Procedure called at the end of a run. | |
300 | // | |
301 | } | |
302 | ||
303 | //_____________________________________________________________________________ | |
304 | AliHit* AliDetector::FirstHit(Int_t track) | |
305 | { | |
306 | // | |
307 | // Initialise the hit iterator | |
308 | // Return the address of the first hit for track | |
309 | // If track>=0 the track is read from disk | |
310 | // while if track<0 the first hit of the current | |
311 | // track is returned | |
312 | // | |
313 | if(track>=0) { | |
314 | gAlice->ResetHits(); | |
315 | gAlice->TreeH()->GetEvent(track); | |
316 | } | |
317 | // | |
318 | sMaxIterHit=fHits->GetEntriesFast(); | |
319 | sCurIterHit=0; | |
320 | if(sMaxIterHit) return (AliHit*) fHits->UncheckedAt(0); | |
321 | else return 0; | |
322 | } | |
323 | ||
324 | ||
325 | //_____________________________________________________________________________ | |
326 | AliTrackReference* AliDetector::FirstTrackReference(Int_t track) | |
327 | { | |
328 | // | |
329 | // Initialise the hit iterator | |
330 | // Return the address of the first hit for track | |
331 | // If track>=0 the track is read from disk | |
332 | // while if track<0 the first hit of the current | |
333 | // track is returned | |
334 | // | |
335 | if(track>=0) { | |
336 | gAlice->ResetTrackReferences(); | |
337 | gAlice->TreeTR()->GetEvent(track); | |
338 | } | |
339 | // | |
340 | sMaxIterHit=fTrackReferences->GetEntriesFast(); | |
341 | sCurIterHit=0; | |
342 | if(sMaxIterHit) return (AliTrackReference*) fTrackReferences->UncheckedAt(0); | |
343 | else return 0; | |
344 | } | |
345 | ||
346 | ||
347 | ||
348 | //_____________________________________________________________________________ | |
349 | AliHit* AliDetector::NextHit() | |
350 | { | |
351 | // | |
352 | // Return the next hit for the current track | |
353 | // | |
354 | if(sMaxIterHit) { | |
355 | if(++sCurIterHit<sMaxIterHit) | |
356 | return (AliHit*) fHits->UncheckedAt(sCurIterHit); | |
357 | else | |
358 | return 0; | |
359 | } else { | |
360 | printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n"); | |
361 | return 0; | |
362 | } | |
363 | } | |
364 | //_____________________________________________________________________________ | |
365 | AliTrackReference* AliDetector::NextTrackReference() | |
366 | { | |
367 | // | |
368 | // Return the next hit for the current track | |
369 | // | |
370 | if(fMaxIterTrackRef) { | |
371 | if(++fCurrentIterTrackRef<fMaxIterTrackRef) | |
372 | return (AliTrackReference*) fTrackReferences->UncheckedAt(fCurrentIterTrackRef); | |
373 | else | |
374 | return 0; | |
375 | } else { | |
376 | printf("* AliDetector::NextTrackReference * TrackReference Iterator called without calling FistTrackReference before\n"); | |
377 | return 0; | |
378 | } | |
379 | } | |
380 | ||
381 | //_____________________________________________________________________________ | |
382 | void AliDetector::LoadPoints(Int_t) | |
383 | { | |
384 | // | |
385 | // Store x, y, z of all hits in memory | |
386 | // | |
387 | if (fHits == 0) return; | |
388 | // | |
389 | Int_t nhits = fHits->GetEntriesFast(); | |
390 | if (nhits == 0) return; | |
391 | Int_t tracks = gAlice->GetNtrack(); | |
392 | if (fPoints == 0) fPoints = new TObjArray(tracks); | |
393 | AliHit *ahit; | |
394 | // | |
395 | Int_t *ntrk=new Int_t[tracks]; | |
396 | Int_t *limi=new Int_t[tracks]; | |
397 | Float_t **coor=new Float_t*[tracks]; | |
398 | for(Int_t i=0;i<tracks;i++) { | |
399 | ntrk[i]=0; | |
400 | coor[i]=0; | |
401 | limi[i]=0; | |
402 | } | |
403 | // | |
404 | AliPoints *points = 0; | |
405 | Float_t *fp=0; | |
406 | Int_t trk; | |
407 | Int_t chunk=nhits/4+1; | |
408 | // | |
409 | // Loop over all the hits and store their position | |
410 | for (Int_t hit=0;hit<nhits;hit++) { | |
411 | ahit = (AliHit*)fHits->UncheckedAt(hit); | |
412 | trk=ahit->GetTrack(); | |
413 | assert(trk<=tracks); | |
414 | if(ntrk[trk]==limi[trk]) { | |
415 | // | |
416 | // Initialise a new track | |
417 | fp=new Float_t[3*(limi[trk]+chunk)]; | |
418 | if(coor[trk]) { | |
419 | memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]); | |
420 | delete [] coor[trk]; | |
421 | } | |
422 | limi[trk]+=chunk; | |
423 | coor[trk] = fp; | |
424 | } else { | |
425 | fp = coor[trk]; | |
426 | } | |
427 | fp[3*ntrk[trk] ] = ahit->X(); | |
428 | fp[3*ntrk[trk]+1] = ahit->Y(); | |
429 | fp[3*ntrk[trk]+2] = ahit->Z(); | |
430 | ntrk[trk]++; | |
431 | } | |
432 | // | |
433 | for(trk=0; trk<tracks; ++trk) { | |
434 | if(ntrk[trk]) { | |
435 | points = new AliPoints(); | |
436 | points->SetMarkerColor(GetMarkerColor()); | |
437 | points->SetMarkerSize(GetMarkerSize()); | |
438 | points->SetDetector(this); | |
439 | points->SetParticle(trk); | |
440 | points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle()); | |
441 | fPoints->AddAt(points,trk); | |
442 | delete [] coor[trk]; | |
443 | coor[trk]=0; | |
444 | } | |
445 | } | |
446 | delete [] coor; | |
447 | delete [] ntrk; | |
448 | delete [] limi; | |
449 | } | |
450 | ||
451 | //_____________________________________________________________________________ | |
452 | void AliDetector::MakeBranch(Option_t *option, const char *file) | |
453 | { | |
454 | // | |
455 | // Create a new branch in the current Root Tree | |
456 | // The branch of fHits is automatically split | |
457 | // | |
458 | ||
459 | char branchname[10]; | |
460 | sprintf(branchname,"%s",GetName()); | |
461 | // | |
462 | // Get the pointer to the header | |
463 | const char *cH = strstr(option,"H"); | |
464 | // | |
465 | if (fHits && gAlice->TreeH() && cH) { | |
466 | MakeBranchInTree(gAlice->TreeH(), | |
467 | branchname, &fHits, fBufferSize, file) ; | |
468 | } | |
469 | ||
470 | const char *cD = strstr(option,"D"); | |
471 | ||
472 | if (cD) { | |
473 | if (file) { | |
474 | fDigitsFile = new char[strlen (file)]; | |
475 | strcpy(fDigitsFile,file); | |
476 | } | |
477 | } | |
478 | } | |
479 | //_____________________________________________________________________________ | |
480 | void AliDetector::MakeBranchTR(Option_t *option, const char *file) | |
481 | { | |
482 | // | |
483 | // Create a new branch in the current Root Tree | |
484 | // The branch of fHits is automatically split | |
485 | // | |
486 | ||
487 | char branchname[10]; | |
488 | sprintf(branchname,"%s",GetName()); | |
489 | // | |
490 | // Get the pointer to the header | |
491 | const char *cTR = strstr(option,"T"); | |
492 | // | |
493 | if (fTrackReferences && gAlice->TreeTR() && cTR) { | |
494 | MakeBranchInTree(gAlice->TreeTR(), | |
495 | branchname, &fTrackReferences, fBufferSize, file) ; | |
496 | } | |
497 | } | |
498 | ||
499 | //_____________________________________________________________________________ | |
500 | void AliDetector::ResetDigits() | |
501 | { | |
502 | // | |
503 | // Reset number of digits and the digits array | |
504 | // | |
505 | fNdigits = 0; | |
506 | if (fDigits) fDigits->Clear(); | |
507 | } | |
508 | ||
509 | //_____________________________________________________________________________ | |
510 | void AliDetector::ResetHits() | |
511 | { | |
512 | // | |
513 | // Reset number of hits and the hits array | |
514 | // | |
515 | fNhits = 0; | |
516 | if (fHits) fHits->Clear(); | |
517 | } | |
518 | ||
519 | ||
520 | ||
521 | //_____________________________________________________________________________ | |
522 | void AliDetector::ResetTrackReferences() | |
523 | { | |
524 | // | |
525 | // Reset number of hits and the hits array | |
526 | // | |
527 | fMaxIterTrackRef = 0; | |
528 | if (fTrackReferences) fTrackReferences->Clear(); | |
529 | } | |
530 | ||
531 | ||
532 | ||
533 | //_____________________________________________________________________________ | |
534 | void AliDetector::ResetPoints() | |
535 | { | |
536 | // | |
537 | // Reset array of points | |
538 | // | |
539 | if (fPoints) { | |
540 | fPoints->Delete(); | |
541 | delete fPoints; | |
542 | fPoints = 0; | |
543 | } | |
544 | } | |
545 | ||
546 | //_____________________________________________________________________________ | |
547 | void AliDetector::SetTreeAddress() | |
548 | { | |
549 | // | |
550 | // Set branch address for the Hits and Digits Trees | |
551 | // | |
552 | TBranch *branch; | |
553 | char branchname[20]; | |
554 | sprintf(branchname,"%s",GetName()); | |
555 | // | |
556 | // Branch address for hit tree | |
557 | TTree *treeH = gAlice->TreeH(); | |
558 | if (treeH && fHits) { | |
559 | branch = treeH->GetBranch(branchname); | |
560 | if (branch) branch->SetAddress(&fHits); | |
561 | } | |
562 | // | |
563 | // Branch address for digit tree | |
564 | TTree *treeD = gAlice->TreeD(); | |
565 | if (treeD && fDigits) { | |
566 | branch = treeD->GetBranch(branchname); | |
567 | if (branch) branch->SetAddress(&fDigits); | |
568 | } | |
569 | } | |
570 | ||
571 |