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