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():
67 // Default constructor for the AliDetector class
71 //_______________________________________________________________________
72 AliDetector::AliDetector(const AliDetector &det):
89 //_____________________________________________________________________________
90 AliDetector::AliDetector(const char* name,const char *title):
91 AliModule(name,title),
105 // Normal constructor invoked by all Detectors.
106 // Create the list for detector specific histograms
107 // Add this Detector to the global list of Detectors in Run.
111 AliConfig::Instance()->Add(this);
115 //_______________________________________________________________________
116 AliDetector::~AliDetector()
122 // Delete space point structure
128 // Delete digits structure
137 fLoader->GetModulesFolder()->Remove(this);
142 //_______________________________________________________________________
143 void AliDetector::Publish(const char */*dir*/, void */*address*/, const char */*name*/) const
146 // Register pointer to detector objects.
148 MayNotUse("Publish");
151 //_______________________________________________________________________
152 void AliDetector::AddAlignableVolumes() const
155 AliWarning(Form("%s still has to implement the AddAlignableVolumes method!",GetName()));
158 //_______________________________________________________________________
159 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
160 void* address, Int_t size,
163 return(MakeBranchInTree(tree,name,0,address,size,99,file));
166 //_______________________________________________________________________
167 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
168 const char *classname,
169 void* address,Int_t size,
170 Int_t splitlevel, const char */*file*/)
173 // Makes branch in given tree and diverts them to a separate file
178 AliDebug(2,Form("Making Branch %s",name));
181 AliError(Form("Making Branch %s Tree is NULL",name));
184 TBranch *branch = tree->GetBranch(name);
187 AliDebug(2,Form("Branch %s is already in tree.",name));
193 branch = tree->Branch(name,classname,address,size,splitlevel);
197 branch = tree->Bronch(name, "TClonesArray", address, size, splitlevel);
199 AliDebug(2,Form("Branch %s returning branch %#x",name,branch));
203 //_______________________________________________________________________
204 void AliDetector::Browse(TBrowser *b)
207 // Insert Detector objects in the list of objects to be browsed
210 if( fHits == 0) return;
214 nobjects = fHits->GetEntries();
215 for (i=0;i<nobjects;i++) {
217 sprintf(name,"%s_%d",obj->GetName(),i);
218 b->Add(obj, &name[0]);
222 //_______________________________________________________________________
223 void AliDetector::Copy(TObject &) const
226 // Copy *this onto det -- not implemented
228 AliFatal("Not implemented");
231 //_______________________________________________________________________
232 void AliDetector::FinishRun()
235 // Procedure called at the end of a run.
239 //_______________________________________________________________________
240 AliHit* AliDetector::FirstHit(Int_t track)
243 // Initialise the hit iterator
244 // Return the address of the first hit for track
245 // If track>=0 the track is read from disk
246 // while if track<0 the first hit of the current
250 gAlice->ResetHits(); //stupid = if N detector this method is called N times
251 TreeH()->GetEvent(track); //skowron
254 fMaxIterHit=fHits->GetEntriesFast();
256 if(fMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
260 //_______________________________________________________________________
261 AliHit* AliDetector::NextHit()
264 // Return the next hit for the current track
267 if(++fCurIterHit<fMaxIterHit)
268 return dynamic_cast<AliHit*>(fHits->UncheckedAt(fCurIterHit));
272 AliWarning("Hit Iterator called without calling FistHit before");
277 //_______________________________________________________________________
278 void AliDetector::LoadPoints(Int_t)
281 // Store x, y, z of all hits in memory
285 AliError(Form("fHits == 0. Name is %s",GetName()));
289 Int_t nhits = fHits->GetEntriesFast();
292 // Error("LoadPoints","nhits == 0. Name is %s",GetName());
295 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
296 if (fPoints == 0) fPoints = new TObjArray(tracks);
299 Int_t *ntrk=new Int_t[tracks];
300 Int_t *limi=new Int_t[tracks];
301 Float_t **coor=new Float_t*[tracks];
302 for(Int_t i=0;i<tracks;i++) {
308 AliPoints *points = 0;
311 Int_t chunk=nhits/4+1;
313 // Loop over all the hits and store their position
314 for (Int_t hit=0;hit<nhits;hit++) {
315 ahit = dynamic_cast<AliHit*>(fHits->UncheckedAt(hit));
316 trk=ahit->GetTrack();
318 AliError(Form("Found track number %d, max track %d",trk, tracks));
321 if(ntrk[trk]==limi[trk])
324 // Initialise a new track
325 fp=new Float_t[3*(limi[trk]+chunk)];
328 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
338 fp[3*ntrk[trk] ] = ahit->X();
339 fp[3*ntrk[trk]+1] = ahit->Y();
340 fp[3*ntrk[trk]+2] = ahit->Z();
344 for(trk=0; trk<tracks; ++trk) {
346 points = new AliPoints();
347 points->SetMarkerColor(GetMarkerColor());
348 points->SetMarkerSize(GetMarkerSize());
349 points->SetDetector(this);
350 points->SetParticle(trk);
351 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
352 fPoints->AddAt(points,trk);
362 //_______________________________________________________________________
363 void AliDetector::MakeBranch(Option_t *option)
366 // Create a new branch for this detector in its treeH
369 AliDebug(2,Form(" for %s",GetName()));
370 const char *cH = strstr(option,"H");
372 if (fHits && TreeH() && cH)
374 MakeBranchInTree(TreeH(), GetName(), &fHits, fBufferSize, 0);
378 //_______________________________________________________________________
379 void AliDetector::ResetDigits()
382 // Reset number of digits and the digits array
385 if (fDigits) fDigits->Clear();
388 //_______________________________________________________________________
389 void AliDetector::ResetHits()
392 // Reset number of hits and the hits array
395 if (fHits) fHits->Clear();
398 //_______________________________________________________________________
399 void AliDetector::ResetPoints()
402 // Reset array of points
411 //_______________________________________________________________________
412 void AliDetector::SetTreeAddress()
415 // Set branch address for the Hits and Digits Trees
419 // Branch address for hit tree
421 TTree *tree = TreeH();
423 branch = tree->GetBranch(GetName());
426 AliDebug(2,Form("(%s) Setting for Hits",GetName()));
427 branch->SetAddress(&fHits);
430 { //can be invoked before branch creation
431 AliDebug(2,Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
436 // Branch address for digit tree
437 TTree *treeD = fLoader->TreeD();
438 if (treeD && fDigits) {
439 branch = treeD->GetBranch(GetName());
440 if (branch) branch->SetAddress(&fDigits);
443 AliModule::SetTreeAddress();
446 //_______________________________________________________________________
447 void AliDetector::MakeTree(Option_t *option)
449 //makes a tree (container) for the data defined in option
452 //"S" - summable digits
453 //"R" - recontructed points and tracks
455 AliLoader* loader = GetLoader();
458 AliError(Form("Can not get loader for %s",GetName()));
461 loader->MakeTree(option); //delegate this job to getter
464 //_______________________________________________________________________
465 AliLoader* AliDetector::MakeLoader(const char* topfoldername)
467 //builds standard getter (AliLoader type)
468 //if detector wants to use castomized getter, it must overload this method
470 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
471 GetName(),topfoldername));
473 fLoader = new AliLoader(GetName(),topfoldername);
477 //_______________________________________________________________________
478 TTree* AliDetector::TreeH() const
480 //Get the hits container from the folder
481 if (GetLoader() == 0x0)
483 //sunstitude this with make getter when we can obtain the event folder name
484 AliError("Can not get the getter");
488 TTree* tree = (TTree*)GetLoader()->TreeH();