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 ///////////////////////////////////////////////////////////////////////////////
39 #include "AliConfig.h"
40 #include "AliDetector.h"
42 #include "AliPoints.h"
43 #include "AliLoader.h"
50 //_______________________________________________________________________
51 AliDetector::AliDetector():
63 // Default constructor for the AliDetector class
67 //_______________________________________________________________________
68 AliDetector::AliDetector(const AliDetector &det):
83 //_____________________________________________________________________________
84 AliDetector::AliDetector(const char* name,const char *title):
85 AliModule(name,title),
97 // Normal constructor invoked by all Detectors.
98 // Create the list for detector specific histograms
99 // Add this Detector to the global list of Detectors in Run.
103 AliConfig::Instance()->Add(this);
107 //_______________________________________________________________________
108 AliDetector::~AliDetector()
114 // Delete space point structure
120 // Delete digits structure
129 fLoader->GetModulesFolder()->Remove(this);
134 //_______________________________________________________________________
135 void AliDetector::Publish(const char */*dir*/, void */*address*/, const char */*name*/) const
138 // Register pointer to detector objects.
140 MayNotUse("Publish");
143 //_______________________________________________________________________
144 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
145 void* address, Int_t size,
148 return(MakeBranchInTree(tree,name,0,address,size,99,file));
151 //_______________________________________________________________________
152 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
153 const char *classname,
154 void* address,Int_t size,
155 Int_t splitlevel, const char */*file*/)
158 // Makes branch in given tree and diverts them to a separate file
163 if(GetDebug()) Info("MakeBranch","Making Branch %s",name);
166 Error("MakeBranch","Making Branch %s Tree is NULL",name);
169 TBranch *branch = tree->GetBranch(name);
172 if(GetDebug()) Info("MakeBranch","Branch %s is already in tree.",name);
178 branch = tree->Branch(name,classname,address,size,splitlevel);
182 branch = tree->Branch(name,address,size);
184 if(GetDebug()) Info("MakeBranch","Branch %s returning branch %#x",name,branch);
188 //_______________________________________________________________________
189 void AliDetector::Browse(TBrowser *b)
192 // Insert Detector objects in the list of objects to be browsed
195 if( fHits == 0) return;
199 nobjects = fHits->GetEntries();
200 for (i=0;i<nobjects;i++) {
202 sprintf(name,"%s_%d",obj->GetName(),i);
203 b->Add(obj, &name[0]);
207 //_______________________________________________________________________
208 void AliDetector::Copy(TObject &) const
211 // Copy *this onto det -- not implemented
213 Fatal("Copy","Not implemented\n");
216 //_______________________________________________________________________
217 void AliDetector::FinishRun()
220 // Procedure called at the end of a run.
224 //_______________________________________________________________________
225 AliHit* AliDetector::FirstHit(Int_t track)
228 // Initialise the hit iterator
229 // Return the address of the first hit for track
230 // If track>=0 the track is read from disk
231 // while if track<0 the first hit of the current
235 gAlice->ResetHits(); //stupid = if N detector this method is called N times
236 TreeH()->GetEvent(track); //skowron
239 fMaxIterHit=fHits->GetEntriesFast();
241 if(fMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
245 //_______________________________________________________________________
246 AliHit* AliDetector::NextHit()
249 // Return the next hit for the current track
252 if(++fCurIterHit<fMaxIterHit)
253 return dynamic_cast<AliHit*>(fHits->UncheckedAt(fCurIterHit));
257 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
262 //_______________________________________________________________________
263 void AliDetector::LoadPoints(Int_t)
266 // Store x, y, z of all hits in memory
270 Error("LoadPoints","fHits == 0. Name is %s",GetName());
274 Int_t nhits = fHits->GetEntriesFast();
277 // Error("LoadPoints","nhits == 0. Name is %s",GetName());
280 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
281 if (fPoints == 0) fPoints = new TObjArray(tracks);
284 Int_t *ntrk=new Int_t[tracks];
285 Int_t *limi=new Int_t[tracks];
286 Float_t **coor=new Float_t*[tracks];
287 for(Int_t i=0;i<tracks;i++) {
293 AliPoints *points = 0;
296 Int_t chunk=nhits/4+1;
298 // Loop over all the hits and store their position
299 for (Int_t hit=0;hit<nhits;hit++) {
300 ahit = dynamic_cast<AliHit*>(fHits->UncheckedAt(hit));
301 trk=ahit->GetTrack();
302 if(trk>tracks) Fatal("LoadPoints","Found track number %d, max track %d\n",trk, tracks);
303 if(ntrk[trk]==limi[trk])
306 // Initialise a new track
307 fp=new Float_t[3*(limi[trk]+chunk)];
310 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
320 fp[3*ntrk[trk] ] = ahit->X();
321 fp[3*ntrk[trk]+1] = ahit->Y();
322 fp[3*ntrk[trk]+2] = ahit->Z();
326 for(trk=0; trk<tracks; ++trk) {
328 points = new AliPoints();
329 points->SetMarkerColor(GetMarkerColor());
330 points->SetMarkerSize(GetMarkerSize());
331 points->SetDetector(this);
332 points->SetParticle(trk);
333 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
334 fPoints->AddAt(points,trk);
344 //_______________________________________________________________________
345 void AliDetector::MakeBranch(Option_t *option)
348 // Create a new branch for this detector in its treeH
351 if(GetDebug()) Info("MakeBranch"," for %s",GetName());
352 const char *cH = strstr(option,"H");
354 if (fHits && TreeH() && cH)
356 MakeBranchInTree(TreeH(), GetName(), &fHits, fBufferSize, 0);
360 //_______________________________________________________________________
361 void AliDetector::ResetDigits()
364 // Reset number of digits and the digits array
367 if (fDigits) fDigits->Clear();
370 //_______________________________________________________________________
371 void AliDetector::ResetHits()
374 // Reset number of hits and the hits array
377 if (fHits) fHits->Clear();
380 //_______________________________________________________________________
381 void AliDetector::ResetPoints()
384 // Reset array of points
393 //_______________________________________________________________________
394 void AliDetector::SetTreeAddress()
397 // Set branch address for the Hits and Digits Trees
401 // Branch address for hit tree
403 TTree *tree = TreeH();
405 branch = tree->GetBranch(GetName());
408 if(GetDebug()) Info("SetTreeAddress","(%s) Setting for Hits",GetName());
409 branch->SetAddress(&fHits);
412 { //can be invoked before branch creation
413 if(GetDebug()) Warning("SetTreeAddress","(%s) Failed for Hits. Can not find branch in tree.",GetName());
418 // Branch address for digit tree
419 TTree *treeD = fLoader->TreeD();
420 if (treeD && fDigits) {
421 branch = treeD->GetBranch(GetName());
422 if (branch) branch->SetAddress(&fDigits);
425 AliModule::SetTreeAddress();
428 //_______________________________________________________________________
429 void AliDetector::MakeTree(Option_t *option)
431 //makes a tree (container) for the data defined in option
434 //"S" - summable digits
435 //"R" - recontructed points and tracks
437 AliLoader* loader = GetLoader();
440 Error("MakeTree","Can not get loader for %s",GetName());
443 loader->MakeTree(option); //delegate this job to getter
446 //_______________________________________________________________________
447 AliLoader* AliDetector::MakeLoader(const char* topfoldername)
449 //builds standard getter (AliLoader type)
450 //if detector wants to use castomized getter, it must overload this method
454 "Creating standard getter for detector %s. Top folder is %s.",
455 GetName(),topfoldername);
457 fLoader = new AliLoader(GetName(),topfoldername);
461 //_______________________________________________________________________
462 TTree* AliDetector::TreeH() const
464 //Get the hits container from the folder
465 if (GetLoader() == 0x0)
467 //sunstitude this with make getter when we can obtain the event folder name
468 Error("TreeH","Can not get the getter");
472 TTree* tree = (TTree*)GetLoader()->TreeH();