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 ///////////////////////////////////////////////////////////////////////////////
43 #include <Riostream.h>
45 #include "AliConfig.h"
46 #include "AliDetector.h"
48 #include "AliPoints.h"
49 #include "AliLoader.h"
53 // Static variables for the hit iterator routines
54 static Int_t sMaxIterHit=0;
55 static Int_t sCurIterHit=0;
60 //_______________________________________________________________________
61 AliDetector::AliDetector():
73 // Default constructor for the AliDetector class
77 //_______________________________________________________________________
78 AliDetector::AliDetector(const AliDetector &det):
93 //_____________________________________________________________________________
94 AliDetector::AliDetector(const char* name,const char *title):
95 AliModule(name,title),
107 // Normal constructor invoked by all Detectors.
108 // Create the list for detector specific histograms
109 // Add this Detector to the global list of Detectors in Run.
113 AliConfig::Instance()->Add(this);
117 //_______________________________________________________________________
118 AliDetector::~AliDetector()
124 // Delete space point structure
130 // Delete digits structure
139 fLoader->GetModulesFolder()->Remove(this);
144 //_______________________________________________________________________
145 void AliDetector::Publish(const char *dir, void *address, const char *name)
148 // Register pointer to detector objects.
150 // TFolder *topFolder = (TFolder *)gROOT->FindObjectAny("/Folders");
151 MayNotUse("Publish");
154 //_______________________________________________________________________
155 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
156 void* address, Int_t size,
159 return(MakeBranchInTree(tree,name,0,address,size,99,file));
162 //_______________________________________________________________________
163 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
164 const char *classname,
165 void* address,Int_t size,
166 Int_t splitlevel, const char *file)
169 // Makes branch in given tree and diverts them to a separate file
174 if(GetDebug()) Info("MakeBranch","Making Branch %s",name);
177 Error("MakeBranch","Making Branch %s Tree is NULL",name);
180 TBranch *branch = tree->GetBranch(name);
183 if(GetDebug()) Info("MakeBranch","Branch %s is already in tree.",name);
189 branch = tree->Branch(name,classname,address,size,splitlevel);
193 branch = tree->Branch(name,address,size);
195 if(GetDebug()) Info("MakeBranch","Branch %s returning branch %#x",name,branch);
199 //_______________________________________________________________________
200 void AliDetector::Browse(TBrowser *b)
203 // Insert Detector objects in the list of objects to be browsed
206 if( fHits == 0) return;
210 nobjects = fHits->GetEntries();
211 for (i=0;i<nobjects;i++) {
213 sprintf(name,"%s_%d",obj->GetName(),i);
214 b->Add(obj, &name[0]);
218 //_______________________________________________________________________
219 void AliDetector::Copy(AliDetector &) const
222 // Copy *this onto det -- not implemented
224 Fatal("Copy","Not implemented\n");
227 //_______________________________________________________________________
228 void AliDetector::FinishRun()
231 // Procedure called at the end of a run.
235 //_______________________________________________________________________
236 AliHit* AliDetector::FirstHit(Int_t track)
239 // Initialise the hit iterator
240 // Return the address of the first hit for track
241 // If track>=0 the track is read from disk
242 // while if track<0 the first hit of the current
246 gAlice->ResetHits(); //stupid = if N detector this method is called N times
247 TreeH()->GetEvent(track); //skowron
250 sMaxIterHit=fHits->GetEntriesFast();
252 if(sMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
256 //_______________________________________________________________________
257 AliHit* AliDetector::NextHit()
260 // Return the next hit for the current track
263 if(++sCurIterHit<sMaxIterHit)
264 return dynamic_cast<AliHit*>(fHits->UncheckedAt(sCurIterHit));
268 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
273 //_______________________________________________________________________
274 void AliDetector::LoadPoints(Int_t)
277 // Store x, y, z of all hits in memory
281 Error("LoadPoints","fHits == 0. Name is %s",GetName());
285 Int_t nhits = fHits->GetEntriesFast();
288 // Error("LoadPoints","nhits == 0. Name is %s",GetName());
291 Int_t tracks = gAlice->GetNtrack();
292 if (fPoints == 0) fPoints = new TObjArray(tracks);
295 Int_t *ntrk=new Int_t[tracks];
296 Int_t *limi=new Int_t[tracks];
297 Float_t **coor=new Float_t*[tracks];
298 for(Int_t i=0;i<tracks;i++) {
304 AliPoints *points = 0;
307 Int_t chunk=nhits/4+1;
309 // Loop over all the hits and store their position
310 for (Int_t hit=0;hit<nhits;hit++) {
311 ahit = dynamic_cast<AliHit*>(fHits->UncheckedAt(hit));
312 trk=ahit->GetTrack();
314 if(ntrk[trk]==limi[trk])
317 // Initialise a new track
318 fp=new Float_t[3*(limi[trk]+chunk)];
321 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
331 fp[3*ntrk[trk] ] = ahit->X();
332 fp[3*ntrk[trk]+1] = ahit->Y();
333 fp[3*ntrk[trk]+2] = ahit->Z();
337 for(trk=0; trk<tracks; ++trk) {
339 points = new AliPoints();
340 points->SetMarkerColor(GetMarkerColor());
341 points->SetMarkerSize(GetMarkerSize());
342 points->SetDetector(this);
343 points->SetParticle(trk);
344 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
345 fPoints->AddAt(points,trk);
355 //_______________________________________________________________________
356 void AliDetector::MakeBranch(Option_t *option)
359 // Create a new branch for this detector in its treeH
362 if(GetDebug()) Info("MakeBranch"," for %s",GetName());
363 const char *cH = strstr(option,"H");
365 if (fHits && TreeH() && cH)
367 MakeBranchInTree(TreeH(), GetName(), &fHits, fBufferSize, 0);
371 //_______________________________________________________________________
372 void AliDetector::ResetDigits()
375 // Reset number of digits and the digits array
378 if (fDigits) fDigits->Clear();
381 //_______________________________________________________________________
382 void AliDetector::ResetHits()
385 // Reset number of hits and the hits array
388 if (fHits) fHits->Clear();
391 //_______________________________________________________________________
392 void AliDetector::ResetPoints()
395 // Reset array of points
404 //_______________________________________________________________________
405 void AliDetector::SetTreeAddress()
408 // Set branch address for the Hits and Digits Trees
412 // Branch address for hit tree
414 TTree *tree = TreeH();
416 branch = tree->GetBranch(GetName());
419 if(GetDebug()) Info("SetTreeAddress","(%s) Setting for Hits",GetName());
420 branch->SetAddress(&fHits);
424 Warning("SetTreeAddress","(%s) Failed for Hits. Can not find branch in tree.",GetName());
429 // Branch address for digit tree
430 TTree *treeD = fLoader->TreeD();
431 if (treeD && fDigits) {
432 branch = treeD->GetBranch(GetName());
433 if (branch) branch->SetAddress(&fDigits);
436 AliModule::SetTreeAddress();
439 //_______________________________________________________________________
440 void AliDetector::MakeTree(Option_t *option)
442 //makes a tree (container) for the data defined in option
445 //"S" - summable digits
446 //"R" - recontructed points and tracks
448 AliLoader* loader = GetLoader();
451 Error("MakeTree","Can not get loader for %s",GetName());
454 loader->MakeTree(option); //delegate this job to getter
457 //_______________________________________________________________________
458 AliLoader* AliDetector::MakeLoader(const char* topfoldername)
460 //builds standard getter (AliLoader type)
461 //if detector wants to use castomized getter, it must overload this method
463 cout<<"AliDetector::MakeLoader: Creating standard getter for detector "<<GetName()
464 <<". top folder is "<<topfoldername<<endl;
466 fLoader = new AliLoader(GetName(),topfoldername);
471 //_______________________________________________________________________
472 TTree* AliDetector::TreeH()
474 //Get the hits container from the folder
475 if (GetLoader() == 0x0)
477 //sunstitude this with make getter when we can obtain the event folder name
478 Error("TreeH","Can not get the getter");
482 TTree* tree = (TTree*)GetLoader()->TreeH();