1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
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. //
25 // This class is also responsible for building the geometry of the //
30 <img src="picts/AliDetectorClass.gif">
34 ///////////////////////////////////////////////////////////////////////////////
38 #include <Riostream.h>
45 #include "AliConfig.h"
46 #include "AliDetector.h"
48 #include "AliPoints.h"
52 // Static variables for the hit iterator routines
53 static Int_t sMaxIterHit=0;
54 static Int_t sCurIterHit=0;
59 //_______________________________________________________________________
60 AliDetector::AliDetector():
72 // Default constructor for the AliDetector class
76 //_______________________________________________________________________
77 AliDetector::AliDetector(const AliDetector &det):
92 //_____________________________________________________________________________
93 AliDetector::AliDetector(const char* name,const char *title):
94 AliModule(name,title),
106 // Normal constructor invoked by all Detectors.
107 // Create the list for detector specific histograms
108 // Add this Detector to the global list of Detectors in Run.
112 AliConfig::Instance()->Add(this);
116 //_______________________________________________________________________
117 AliDetector::~AliDetector()
123 // Delete space point structure
129 // Delete digits structure
135 // Delete track references
136 if (fTrackReferences) {
137 fTrackReferences->Delete();
138 delete fTrackReferences;
139 fTrackReferences = 0;
141 if (fDigitsFile) delete [] fDigitsFile;
144 //_______________________________________________________________________
145 void AliDetector::Publish(const char *dir, void *address, const char *name)
148 // Register pointer to detector objects.
150 TFolder *topFolder = dynamic_cast<TFolder *>(gROOT->FindObjectAny("/Folders"));
152 TFolder *folder = dynamic_cast<TFolder *>(topFolder->FindObjectAny(dir));
153 // TFolder *folder = dynamic_cast<TFolder *>(gROOT->FindObjectAny(dir));
155 cerr << "Cannot register: Missing folder: " << dir << endl;
157 TFolder *subfolder = dynamic_cast<TFolder *>(folder->FindObjectAny(this->GetName()));
160 subfolder = folder->AddFolder(this->GetName(),this->GetTitle());
162 TObject **obj = static_cast<TObject **>(address);
163 if ((*obj)->InheritsFrom(TCollection::Class())) {
164 TCollection *collection = dynamic_cast<TCollection *>(*obj);
166 collection->SetName(name);
168 subfolder->Add(*obj);
174 //_______________________________________________________________________
175 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
176 void* address, Int_t size,
179 return(MakeBranchInTree(tree,name,0,address,size,99,file));
182 //_______________________________________________________________________
183 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
184 const char *classname,
185 void* address,Int_t size,
186 Int_t splitlevel, const char *file)
189 // Makes branch in given tree and diverts them to a separate file
192 printf("* MakeBranch * Making Branch %s \n",name);
194 TDirectory *cwd = gDirectory;
198 branch = tree->Branch(name,classname,address,size,splitlevel);
200 branch = tree->Branch(name,address,size);
204 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
205 sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
206 branch->SetFile(outFile);
207 TIter next( branch->GetListOfBranches());
208 while ((branch=dynamic_cast<TBranch*>(next()))) {
209 branch->SetFile(outFile);
216 printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
218 const char *folder = 0;
219 TString folderName(name);
221 if (!strncmp(tree->GetName(),"TreeE",5)) folder = "RunMC/Event/Data";
222 if (!strncmp(tree->GetName(),"TreeK",5)) folder = "RunMC/Event/Data";
223 if (!strncmp(tree->GetName(),"TreeH",5)) {
224 folder = "RunMC/Event/Data/Hits";
225 folderName = "Hits" ;
227 if (!strncmp(tree->GetName(),"TreeTrackReferences",5)) {
228 folder = "RunMC/Event/Data/TrackReferences";
229 folderName = "TrackReferences" ;
232 if (!strncmp(tree->GetName(),"TreeD",5)) {
233 folder = "Run/Event/Data";
234 folderName = "Digits" ;
236 if (!strncmp(tree->GetName(),"TreeS",5)) {
237 folder = "RunMC/Event/Data/SDigits";
238 folderName = "SDigits" ;
240 if (!strncmp(tree->GetName(),"TreeR",5)) folder = "Run/Event/RecData";
244 printf("%15s: Publishing %s to %s\n",ClassName(),name,folder);
245 Publish(folder,address, folderName.Data());
250 //_______________________________________________________________________
251 void AliDetector::Browse(TBrowser *b)
254 // Insert Detector objects in the list of objects to be browsed
257 if( fHits == 0) return;
261 nobjects = fHits->GetEntries();
262 for (i=0;i<nobjects;i++) {
264 sprintf(name,"%s_%d",obj->GetName(),i);
265 b->Add(obj, &name[0]);
269 //_______________________________________________________________________
270 void AliDetector::Copy(AliDetector &) const
273 // Copy *this onto det -- not implemented
275 Fatal("Copy","Not implemented\n");
278 //_______________________________________________________________________
279 void AliDetector::FinishRun()
282 // Procedure called at the end of a run.
287 //_______________________________________________________________________
288 AliHit* AliDetector::FirstHit(Int_t track)
291 // Initialise the hit iterator
292 // Return the address of the first hit for track
293 // If track>=0 the track is read from disk
294 // while if track<0 the first hit of the current
299 gAlice->TreeH()->GetEvent(track);
302 sMaxIterHit=fHits->GetEntriesFast();
304 if(sMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
309 //_______________________________________________________________________
310 AliHit* AliDetector::NextHit()
313 // Return the next hit for the current track
316 if(++sCurIterHit<sMaxIterHit)
317 return dynamic_cast<AliHit*>(fHits->UncheckedAt(sCurIterHit));
321 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
327 //_______________________________________________________________________
328 void AliDetector::LoadPoints(Int_t)
331 // Store x, y, z of all hits in memory
333 if (fHits == 0) return;
335 Int_t nhits = fHits->GetEntriesFast();
336 if (nhits == 0) return;
337 Int_t tracks = gAlice->GetNtrack();
338 if (fPoints == 0) fPoints = new TObjArray(tracks);
341 Int_t *ntrk=new Int_t[tracks];
342 Int_t *limi=new Int_t[tracks];
343 Float_t **coor=new Float_t*[tracks];
344 for(Int_t i=0;i<tracks;i++) {
350 AliPoints *points = 0;
353 Int_t chunk=nhits/4+1;
355 // Loop over all the hits and store their position
356 for (Int_t hit=0;hit<nhits;hit++) {
357 ahit = dynamic_cast<AliHit*>(fHits->UncheckedAt(hit));
358 trk=ahit->GetTrack();
360 if(ntrk[trk]==limi[trk]) {
362 // Initialise a new track
363 fp=new Float_t[3*(limi[trk]+chunk)];
365 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
373 fp[3*ntrk[trk] ] = ahit->X();
374 fp[3*ntrk[trk]+1] = ahit->Y();
375 fp[3*ntrk[trk]+2] = ahit->Z();
379 for(trk=0; trk<tracks; ++trk) {
381 points = new AliPoints();
382 points->SetMarkerColor(GetMarkerColor());
383 points->SetMarkerSize(GetMarkerSize());
384 points->SetDetector(this);
385 points->SetParticle(trk);
386 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
387 fPoints->AddAt(points,trk);
397 //_______________________________________________________________________
398 void AliDetector::MakeBranch(Option_t *option, const char *file)
401 // Create a new branch in the current Root Tree
402 // The branch of fHits is automatically split
406 sprintf(branchname,"%s",GetName());
408 // Get the pointer to the header
409 const char *cH = strstr(option,"H");
411 if (fHits && gAlice->TreeH() && cH) {
412 MakeBranchInTree(gAlice->TreeH(),
413 branchname, &fHits, fBufferSize, file) ;
416 const char *cD = strstr(option,"D");
420 fDigitsFile = new char[strlen (file)];
421 strcpy(fDigitsFile,file);
425 //_______________________________________________________________________
426 void AliDetector::MakeBranchTR(Option_t *option, const char *file)
429 // Create a new branch in the current Root Tree
430 // The branch of fHits is automatically split
434 sprintf(branchname,"%s",GetName());
436 // Get the pointer to the header
437 const char *cTR = strstr(option,"T");
439 if (fTrackReferences && gAlice->TreeTR() && cTR) {
440 MakeBranchInTree(gAlice->TreeTR(),
441 branchname, &fTrackReferences, fBufferSize, file) ;
445 //_______________________________________________________________________
446 void AliDetector::ResetDigits()
449 // Reset number of digits and the digits array
452 if (fDigits) fDigits->Clear();
455 //_______________________________________________________________________
456 void AliDetector::ResetHits()
459 // Reset number of hits and the hits array
462 if (fHits) fHits->Clear();
465 //_______________________________________________________________________
466 void AliDetector::ResetPoints()
469 // Reset array of points
478 //_______________________________________________________________________
479 void AliDetector::SetTreeAddress()
482 // Set branch address for the Hits and Digits Trees
486 sprintf(branchname,"%s",GetName());
488 // Branch address for hit tree
489 TTree *treeH = gAlice->TreeH();
490 if (treeH && fHits) {
491 branch = treeH->GetBranch(branchname);
492 if (branch) branch->SetAddress(&fHits);
495 // Branch address for digit tree
496 TTree *treeD = gAlice->TreeD();
497 if (treeD && fDigits) {
498 branch = treeD->GetBranch(branchname);
499 if (branch) branch->SetAddress(&fDigits);
502 AliModule::SetTreeAddress();