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 ///////////////////////////////////////////////////////////////////////////////
37 #include <TClonesArray.h>
41 #include "AliConfig.h"
42 #include "AliDetector.h"
44 #include "AliLoader.h"
51 //_______________________________________________________________________
52 AliDetector::AliDetector():
66 // Default constructor for the AliDetector class
70 //_____________________________________________________________________________
71 AliDetector::AliDetector(const char* name,const char *title):
72 AliModule(name,title),
85 // Normal constructor invoked by all Detectors.
86 // Create the list for detector specific histograms
87 // Add this Detector to the global list of Detectors in Run.
91 AliConfig::Instance()->Add(this);
95 //_______________________________________________________________________
96 AliDetector::~AliDetector()
102 // Delete digits structure
111 fLoader->GetModulesFolder()->Remove(this);
116 //_______________________________________________________________________
117 void AliDetector::Publish(const char */*dir*/, void */*address*/, const char */*name*/) const
120 // Register pointer to detector objects.
122 MayNotUse("Publish");
125 //_______________________________________________________________________
126 void AliDetector::AddAlignableVolumes() const
129 AliWarning(Form("%s still has to implement the AddAlignableVolumes method!",GetName()));
132 //_______________________________________________________________________
133 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
134 void* address, Int_t size,
137 return(MakeBranchInTree(tree,name,0,address,size,99,file));
140 //_______________________________________________________________________
141 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
142 const char *classname,
143 void* address,Int_t size,
144 Int_t splitlevel, const char */*file*/)
147 // Makes branch in given tree and diverts them to a separate file
152 AliDebug(2,Form("Making Branch %s",name));
155 AliError(Form("Making Branch %s Tree is NULL",name));
158 TBranch *branch = tree->GetBranch(name);
161 AliDebug(2,Form("Branch %s is already in tree.",name));
167 branch = tree->Branch(name,classname,address,size,splitlevel);
171 branch = tree->Bronch(name, "TClonesArray", address, size, splitlevel);
173 AliDebug(2,Form("Branch %s returning branch %#x",name,branch));
177 //_______________________________________________________________________
178 void AliDetector::Browse(TBrowser *b)
181 // Insert Detector objects in the list of objects to be browsed
184 if( fHits == 0) return;
188 nobjects = fHits->GetEntries();
189 for (i=0;i<nobjects;i++) {
191 sprintf(name,"%s_%d",obj->GetName(),i);
192 b->Add(obj, &name[0]);
196 //_______________________________________________________________________
197 void AliDetector::FinishRun()
200 // Procedure called at the end of a run.
204 //_______________________________________________________________________
205 AliHit* AliDetector::FirstHit(Int_t track)
208 // Initialise the hit iterator
209 // Return the address of the first hit for track
210 // If track>=0 the track is read from disk
211 // while if track<0 the first hit of the current
215 gAlice->GetMCApp()->ResetHits(); //stupid = if N detector this method is called N times
216 fLoader->TreeH()->GetEvent(track); //skowron
219 fMaxIterHit=fHits->GetEntriesFast();
221 if(fMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
225 //_______________________________________________________________________
226 AliHit* AliDetector::NextHit()
229 // Return the next hit for the current track
232 if(++fCurIterHit<fMaxIterHit)
233 return dynamic_cast<AliHit*>(fHits->UncheckedAt(fCurIterHit));
237 AliWarning("Hit Iterator called without calling FistHit before");
242 //_______________________________________________________________________
243 void AliDetector::MakeBranch(Option_t *option)
246 // Create a new branch for this detector in its treeH
249 AliDebug(2,Form(" for %s",GetName()));
250 const char *cH = strstr(option,"H");
252 if (fHits && fLoader->TreeH() && cH)
254 MakeBranchInTree(fLoader->TreeH(), GetName(), &fHits, fBufferSize, 0);
258 //_______________________________________________________________________
259 void AliDetector::ResetDigits()
262 // Reset number of digits and the digits array
265 if (fDigits) fDigits->Clear();
268 //_______________________________________________________________________
269 void AliDetector::ResetHits()
272 // Reset number of hits and the hits array
275 if (fHits) fHits->Clear();
278 //_______________________________________________________________________
279 void AliDetector::SetTreeAddress()
282 // Set branch address for the Hits and Digits Trees
286 // Branch address for hit tree
288 TTree* tree = fLoader->TreeH();
290 branch = tree->GetBranch(GetName());
293 AliDebug(2,Form("(%s) Setting for Hits",GetName()));
294 branch->SetAddress(&fHits);
297 { //can be invoked before branch creation
298 AliDebug(2,Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
303 // Branch address for digit tree
304 TTree *treeD = fLoader->TreeD();
305 if (treeD && fDigits) {
306 branch = treeD->GetBranch(GetName());
307 if (branch) branch->SetAddress(&fDigits);
311 //_______________________________________________________________________
312 void AliDetector::MakeTree(Option_t *option)
314 //makes a tree (container) for the data defined in option
317 //"S" - summable digits
318 //"R" - recontructed points and tracks
320 AliLoader* loader = GetLoader();
323 AliError(Form("Can not get loader for %s",GetName()));
326 loader->MakeTree(option); //delegate this job to getter
329 //_______________________________________________________________________
330 AliLoader* AliDetector::MakeLoader(const char* topfoldername)
332 //builds standard getter (AliLoader type)
333 //if detector wants to use castomized getter, it must overload this method
335 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
336 GetName(),topfoldername));
338 fLoader = new AliLoader(GetName(),topfoldername);