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():
65 // Default constructor for the AliDetector class
69 //_______________________________________________________________________
70 AliDetector::AliDetector(const AliDetector &det):
85 //_____________________________________________________________________________
86 AliDetector::AliDetector(const char* name,const char *title):
87 AliModule(name,title),
99 // Normal constructor invoked by all Detectors.
100 // Create the list for detector specific histograms
101 // Add this Detector to the global list of Detectors in Run.
105 AliConfig::Instance()->Add(this);
109 //_______________________________________________________________________
110 AliDetector::~AliDetector()
116 // Delete space point structure
122 // Delete digits structure
131 fLoader->GetModulesFolder()->Remove(this);
136 //_______________________________________________________________________
137 void AliDetector::Publish(const char */*dir*/, void */*address*/, const char */*name*/) const
140 // Register pointer to detector objects.
142 MayNotUse("Publish");
145 //_______________________________________________________________________
146 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
147 void* address, Int_t size,
150 return(MakeBranchInTree(tree,name,0,address,size,99,file));
153 //_______________________________________________________________________
154 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
155 const char *classname,
156 void* address,Int_t size,
157 Int_t splitlevel, const char */*file*/)
160 // Makes branch in given tree and diverts them to a separate file
165 AliDebug(2,Form("Making Branch %s",name));
168 AliError(Form("Making Branch %s Tree is NULL",name));
171 TBranch *branch = tree->GetBranch(name);
174 AliDebug(2,Form("Branch %s is already in tree.",name));
180 branch = tree->Branch(name,classname,address,size,splitlevel);
184 branch = tree->Branch(name,address,size);
186 AliDebug(2,Form("Branch %s returning branch %#x",name,branch));
190 //_______________________________________________________________________
191 void AliDetector::Browse(TBrowser *b)
194 // Insert Detector objects in the list of objects to be browsed
197 if( fHits == 0) return;
201 nobjects = fHits->GetEntries();
202 for (i=0;i<nobjects;i++) {
204 sprintf(name,"%s_%d",obj->GetName(),i);
205 b->Add(obj, &name[0]);
209 //_______________________________________________________________________
210 void AliDetector::Copy(TObject &) const
213 // Copy *this onto det -- not implemented
215 AliFatal("Not implemented");
218 //_______________________________________________________________________
219 void AliDetector::FinishRun()
222 // Procedure called at the end of a run.
226 //_______________________________________________________________________
227 AliHit* AliDetector::FirstHit(Int_t track)
230 // Initialise the hit iterator
231 // Return the address of the first hit for track
232 // If track>=0 the track is read from disk
233 // while if track<0 the first hit of the current
237 gAlice->ResetHits(); //stupid = if N detector this method is called N times
238 TreeH()->GetEvent(track); //skowron
241 fMaxIterHit=fHits->GetEntriesFast();
243 if(fMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
247 //_______________________________________________________________________
248 AliHit* AliDetector::NextHit()
251 // Return the next hit for the current track
254 if(++fCurIterHit<fMaxIterHit)
255 return dynamic_cast<AliHit*>(fHits->UncheckedAt(fCurIterHit));
259 AliWarning("Hit Iterator called without calling FistHit before");
264 //_______________________________________________________________________
265 void AliDetector::LoadPoints(Int_t)
268 // Store x, y, z of all hits in memory
272 AliError(Form("fHits == 0. Name is %s",GetName()));
276 Int_t nhits = fHits->GetEntriesFast();
279 // Error("LoadPoints","nhits == 0. Name is %s",GetName());
282 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
283 if (fPoints == 0) fPoints = new TObjArray(tracks);
286 Int_t *ntrk=new Int_t[tracks];
287 Int_t *limi=new Int_t[tracks];
288 Float_t **coor=new Float_t*[tracks];
289 for(Int_t i=0;i<tracks;i++) {
295 AliPoints *points = 0;
298 Int_t chunk=nhits/4+1;
300 // Loop over all the hits and store their position
301 for (Int_t hit=0;hit<nhits;hit++) {
302 ahit = dynamic_cast<AliHit*>(fHits->UncheckedAt(hit));
303 trk=ahit->GetTrack();
304 if(trk>tracks) AliFatal(Form("Found track number %d, max track %d",trk, tracks));
305 if(ntrk[trk]==limi[trk])
308 // Initialise a new track
309 fp=new Float_t[3*(limi[trk]+chunk)];
312 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
322 fp[3*ntrk[trk] ] = ahit->X();
323 fp[3*ntrk[trk]+1] = ahit->Y();
324 fp[3*ntrk[trk]+2] = ahit->Z();
328 for(trk=0; trk<tracks; ++trk) {
330 points = new AliPoints();
331 points->SetMarkerColor(GetMarkerColor());
332 points->SetMarkerSize(GetMarkerSize());
333 points->SetDetector(this);
334 points->SetParticle(trk);
335 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
336 fPoints->AddAt(points,trk);
346 //_______________________________________________________________________
347 void AliDetector::MakeBranch(Option_t *option)
350 // Create a new branch for this detector in its treeH
353 AliDebug(2,Form(" for %s",GetName()));
354 const char *cH = strstr(option,"H");
356 if (fHits && TreeH() && cH)
358 MakeBranchInTree(TreeH(), GetName(), &fHits, fBufferSize, 0);
362 //_______________________________________________________________________
363 void AliDetector::ResetDigits()
366 // Reset number of digits and the digits array
369 if (fDigits) fDigits->Clear();
372 //_______________________________________________________________________
373 void AliDetector::ResetHits()
376 // Reset number of hits and the hits array
379 if (fHits) fHits->Clear();
382 //_______________________________________________________________________
383 void AliDetector::ResetPoints()
386 // Reset array of points
395 //_______________________________________________________________________
396 void AliDetector::SetTreeAddress()
399 // Set branch address for the Hits and Digits Trees
403 // Branch address for hit tree
405 TTree *tree = TreeH();
407 branch = tree->GetBranch(GetName());
410 AliDebug(2,Form("(%s) Setting for Hits",GetName()));
411 branch->SetAddress(&fHits);
414 { //can be invoked before branch creation
415 AliDebug(2,Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
420 // Branch address for digit tree
421 TTree *treeD = fLoader->TreeD();
422 if (treeD && fDigits) {
423 branch = treeD->GetBranch(GetName());
424 if (branch) branch->SetAddress(&fDigits);
427 AliModule::SetTreeAddress();
430 //_______________________________________________________________________
431 void AliDetector::MakeTree(Option_t *option)
433 //makes a tree (container) for the data defined in option
436 //"S" - summable digits
437 //"R" - recontructed points and tracks
439 AliLoader* loader = GetLoader();
442 AliError(Form("Can not get loader for %s",GetName()));
445 loader->MakeTree(option); //delegate this job to getter
448 //_______________________________________________________________________
449 AliLoader* AliDetector::MakeLoader(const char* topfoldername)
451 //builds standard getter (AliLoader type)
452 //if detector wants to use castomized getter, it must overload this method
454 AliDebug(1,Form("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 AliError("Can not get the getter");
472 TTree* tree = (TTree*)GetLoader()->TreeH();