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 ///////////////////////////////////////////////////////////////////////////////
40 #include "AliConfig.h"
41 #include "AliDetector.h"
43 #include "AliPoints.h"
44 #include "AliLoader.h"
51 //_______________________________________________________________________
52 AliDetector::AliDetector():
64 // Default constructor for the AliDetector class
68 //_______________________________________________________________________
69 AliDetector::AliDetector(const AliDetector &det):
84 //_____________________________________________________________________________
85 AliDetector::AliDetector(const char* name,const char *title):
86 AliModule(name,title),
98 // Normal constructor invoked by all Detectors.
99 // Create the list for detector specific histograms
100 // Add this Detector to the global list of Detectors in Run.
104 AliConfig::Instance()->Add(this);
108 //_______________________________________________________________________
109 AliDetector::~AliDetector()
115 // Delete space point structure
121 // Delete digits structure
130 fLoader->GetModulesFolder()->Remove(this);
135 //_______________________________________________________________________
136 void AliDetector::Publish(const char */*dir*/, void */*address*/, const char */*name*/) const
139 // Register pointer to detector objects.
141 MayNotUse("Publish");
144 //_______________________________________________________________________
145 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
146 void* address, Int_t size,
149 return(MakeBranchInTree(tree,name,0,address,size,99,file));
152 //_______________________________________________________________________
153 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
154 const char *classname,
155 void* address,Int_t size,
156 Int_t splitlevel, const char */*file*/)
159 // Makes branch in given tree and diverts them to a separate file
164 AliDebug(2,Form("Making Branch %s",name));
167 AliError(Form("Making Branch %s Tree is NULL",name));
170 TBranch *branch = tree->GetBranch(name);
173 AliDebug(2,Form("Branch %s is already in tree.",name));
179 branch = tree->Branch(name,classname,address,size,splitlevel);
183 branch = tree->Branch(name,address,size);
185 AliDebug(2,Form("Branch %s returning branch %#x",name,branch));
189 //_______________________________________________________________________
190 void AliDetector::Browse(TBrowser *b)
193 // Insert Detector objects in the list of objects to be browsed
196 if( fHits == 0) return;
200 nobjects = fHits->GetEntries();
201 for (i=0;i<nobjects;i++) {
203 sprintf(name,"%s_%d",obj->GetName(),i);
204 b->Add(obj, &name[0]);
208 //_______________________________________________________________________
209 void AliDetector::Copy(TObject &) const
212 // Copy *this onto det -- not implemented
214 AliFatal("Not implemented");
217 //_______________________________________________________________________
218 void AliDetector::FinishRun()
221 // Procedure called at the end of a run.
225 //_______________________________________________________________________
226 AliHit* AliDetector::FirstHit(Int_t track)
229 // Initialise the hit iterator
230 // Return the address of the first hit for track
231 // If track>=0 the track is read from disk
232 // while if track<0 the first hit of the current
236 gAlice->ResetHits(); //stupid = if N detector this method is called N times
237 TreeH()->GetEvent(track); //skowron
240 fMaxIterHit=fHits->GetEntriesFast();
242 if(fMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
246 //_______________________________________________________________________
247 AliHit* AliDetector::NextHit()
250 // Return the next hit for the current track
253 if(++fCurIterHit<fMaxIterHit)
254 return dynamic_cast<AliHit*>(fHits->UncheckedAt(fCurIterHit));
258 AliWarning("Hit Iterator called without calling FistHit before");
263 //_______________________________________________________________________
264 void AliDetector::LoadPoints(Int_t)
267 // Store x, y, z of all hits in memory
271 AliError(Form("fHits == 0. Name is %s",GetName()));
275 Int_t nhits = fHits->GetEntriesFast();
278 // Error("LoadPoints","nhits == 0. Name is %s",GetName());
281 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
282 if (fPoints == 0) fPoints = new TObjArray(tracks);
285 Int_t *ntrk=new Int_t[tracks];
286 Int_t *limi=new Int_t[tracks];
287 Float_t **coor=new Float_t*[tracks];
288 for(Int_t i=0;i<tracks;i++) {
294 AliPoints *points = 0;
297 Int_t chunk=nhits/4+1;
299 // Loop over all the hits and store their position
300 for (Int_t hit=0;hit<nhits;hit++) {
301 ahit = dynamic_cast<AliHit*>(fHits->UncheckedAt(hit));
302 trk=ahit->GetTrack();
303 if(trk>tracks) AliFatal(Form("Found track number %d, max track %d",trk, tracks));
304 if(ntrk[trk]==limi[trk])
307 // Initialise a new track
308 fp=new Float_t[3*(limi[trk]+chunk)];
311 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
321 fp[3*ntrk[trk] ] = ahit->X();
322 fp[3*ntrk[trk]+1] = ahit->Y();
323 fp[3*ntrk[trk]+2] = ahit->Z();
327 for(trk=0; trk<tracks; ++trk) {
329 points = new AliPoints();
330 points->SetMarkerColor(GetMarkerColor());
331 points->SetMarkerSize(GetMarkerSize());
332 points->SetDetector(this);
333 points->SetParticle(trk);
334 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
335 fPoints->AddAt(points,trk);
345 //_______________________________________________________________________
346 void AliDetector::MakeBranch(Option_t *option)
349 // Create a new branch for this detector in its treeH
352 AliDebug(2,Form(" for %s",GetName()));
353 const char *cH = strstr(option,"H");
355 if (fHits && TreeH() && cH)
357 MakeBranchInTree(TreeH(), GetName(), &fHits, fBufferSize, 0);
361 //_______________________________________________________________________
362 void AliDetector::ResetDigits()
365 // Reset number of digits and the digits array
368 if (fDigits) fDigits->Clear();
371 //_______________________________________________________________________
372 void AliDetector::ResetHits()
375 // Reset number of hits and the hits array
378 if (fHits) fHits->Clear();
381 //_______________________________________________________________________
382 void AliDetector::ResetPoints()
385 // Reset array of points
394 //_______________________________________________________________________
395 void AliDetector::SetTreeAddress()
398 // Set branch address for the Hits and Digits Trees
402 // Branch address for hit tree
404 TTree *tree = TreeH();
406 branch = tree->GetBranch(GetName());
409 AliDebug(2,Form("(%s) Setting for Hits",GetName()));
410 branch->SetAddress(&fHits);
413 { //can be invoked before branch creation
414 AliDebug(2,Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
419 // Branch address for digit tree
420 TTree *treeD = fLoader->TreeD();
421 if (treeD && fDigits) {
422 branch = treeD->GetBranch(GetName());
423 if (branch) branch->SetAddress(&fDigits);
426 AliModule::SetTreeAddress();
429 //_______________________________________________________________________
430 void AliDetector::MakeTree(Option_t *option)
432 //makes a tree (container) for the data defined in option
435 //"S" - summable digits
436 //"R" - recontructed points and tracks
438 AliLoader* loader = GetLoader();
441 AliError(Form("Can not get loader for %s",GetName()));
444 loader->MakeTree(option); //delegate this job to getter
447 //_______________________________________________________________________
448 AliLoader* AliDetector::MakeLoader(const char* topfoldername)
450 //builds standard getter (AliLoader type)
451 //if detector wants to use castomized getter, it must overload this method
453 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
454 GetName(),topfoldername));
456 fLoader = new AliLoader(GetName(),topfoldername);
460 //_______________________________________________________________________
461 TTree* AliDetector::TreeH() const
463 //Get the hits container from the folder
464 if (GetLoader() == 0x0)
466 //sunstitude this with make getter when we can obtain the event folder name
467 AliError("Can not get the getter");
471 TTree* tree = (TTree*)GetLoader()->TreeH();