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
166 AliDebug(2,Form("Making Branch %s",name));
169 AliError(Form("Making Branch %s Tree is NULL",name));
172 TBranch *branch = tree->GetBranch(name);
175 AliDebug(2,Form("Branch %s is already in tree.",name));
181 branch = tree->Branch(name,classname,address,size,splitlevel);
185 branch = tree->Bronch(name, "TClonesArray", address, size, splitlevel);
187 AliDebug(2,Form("Branch %s returning branch %#x",name,branch));
191 //_______________________________________________________________________
192 void AliDetector::Browse(TBrowser *b)
195 // Insert Detector objects in the list of objects to be browsed
198 if( fHits == 0) return;
202 nobjects = fHits->GetEntries();
203 for (i=0;i<nobjects;i++) {
205 sprintf(name,"%s_%d",obj->GetName(),i);
206 b->Add(obj, &name[0]);
210 //_______________________________________________________________________
211 void AliDetector::Copy(TObject &) const
214 // Copy *this onto det -- not implemented
216 AliFatal("Not implemented");
219 //_______________________________________________________________________
220 void AliDetector::FinishRun()
223 // Procedure called at the end of a run.
227 //_______________________________________________________________________
228 AliHit* AliDetector::FirstHit(Int_t track)
231 // Initialise the hit iterator
232 // Return the address of the first hit for track
233 // If track>=0 the track is read from disk
234 // while if track<0 the first hit of the current
238 gAlice->ResetHits(); //stupid = if N detector this method is called N times
239 TreeH()->GetEvent(track); //skowron
242 fMaxIterHit=fHits->GetEntriesFast();
244 if(fMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
248 //_______________________________________________________________________
249 AliHit* AliDetector::NextHit()
252 // Return the next hit for the current track
255 if(++fCurIterHit<fMaxIterHit)
256 return dynamic_cast<AliHit*>(fHits->UncheckedAt(fCurIterHit));
260 AliWarning("Hit Iterator called without calling FistHit before");
265 //_______________________________________________________________________
266 void AliDetector::LoadPoints(Int_t)
269 // Store x, y, z of all hits in memory
273 AliError(Form("fHits == 0. Name is %s",GetName()));
277 Int_t nhits = fHits->GetEntriesFast();
280 // Error("LoadPoints","nhits == 0. Name is %s",GetName());
283 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
284 if (fPoints == 0) fPoints = new TObjArray(tracks);
287 Int_t *ntrk=new Int_t[tracks];
288 Int_t *limi=new Int_t[tracks];
289 Float_t **coor=new Float_t*[tracks];
290 for(Int_t i=0;i<tracks;i++) {
296 AliPoints *points = 0;
299 Int_t chunk=nhits/4+1;
301 // Loop over all the hits and store their position
302 for (Int_t hit=0;hit<nhits;hit++) {
303 ahit = dynamic_cast<AliHit*>(fHits->UncheckedAt(hit));
304 trk=ahit->GetTrack();
305 if(trk>tracks) AliFatal(Form("Found track number %d, max track %d",trk, tracks));
306 if(ntrk[trk]==limi[trk])
309 // Initialise a new track
310 fp=new Float_t[3*(limi[trk]+chunk)];
313 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
323 fp[3*ntrk[trk] ] = ahit->X();
324 fp[3*ntrk[trk]+1] = ahit->Y();
325 fp[3*ntrk[trk]+2] = ahit->Z();
329 for(trk=0; trk<tracks; ++trk) {
331 points = new AliPoints();
332 points->SetMarkerColor(GetMarkerColor());
333 points->SetMarkerSize(GetMarkerSize());
334 points->SetDetector(this);
335 points->SetParticle(trk);
336 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
337 fPoints->AddAt(points,trk);
347 //_______________________________________________________________________
348 void AliDetector::MakeBranch(Option_t *option)
351 // Create a new branch for this detector in its treeH
354 AliDebug(2,Form(" for %s",GetName()));
355 const char *cH = strstr(option,"H");
357 if (fHits && TreeH() && cH)
359 MakeBranchInTree(TreeH(), GetName(), &fHits, fBufferSize, 0);
363 //_______________________________________________________________________
364 void AliDetector::ResetDigits()
367 // Reset number of digits and the digits array
370 if (fDigits) fDigits->Clear();
373 //_______________________________________________________________________
374 void AliDetector::ResetHits()
377 // Reset number of hits and the hits array
380 if (fHits) fHits->Clear();
383 //_______________________________________________________________________
384 void AliDetector::ResetPoints()
387 // Reset array of points
396 //_______________________________________________________________________
397 void AliDetector::SetTreeAddress()
400 // Set branch address for the Hits and Digits Trees
404 // Branch address for hit tree
406 TTree *tree = TreeH();
408 branch = tree->GetBranch(GetName());
411 AliDebug(2,Form("(%s) Setting for Hits",GetName()));
412 branch->SetAddress(&fHits);
415 { //can be invoked before branch creation
416 AliDebug(2,Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
421 // Branch address for digit tree
422 TTree *treeD = fLoader->TreeD();
423 if (treeD && fDigits) {
424 branch = treeD->GetBranch(GetName());
425 if (branch) branch->SetAddress(&fDigits);
428 AliModule::SetTreeAddress();
431 //_______________________________________________________________________
432 void AliDetector::MakeTree(Option_t *option)
434 //makes a tree (container) for the data defined in option
437 //"S" - summable digits
438 //"R" - recontructed points and tracks
440 AliLoader* loader = GetLoader();
443 AliError(Form("Can not get loader for %s",GetName()));
446 loader->MakeTree(option); //delegate this job to getter
449 //_______________________________________________________________________
450 AliLoader* AliDetector::MakeLoader(const char* topfoldername)
452 //builds standard getter (AliLoader type)
453 //if detector wants to use castomized getter, it must overload this method
455 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
456 GetName(),topfoldername));
458 fLoader = new AliLoader(GetName(),topfoldername);
462 //_______________________________________________________________________
463 TTree* AliDetector::TreeH() const
465 //Get the hits container from the folder
466 if (GetLoader() == 0x0)
468 //sunstitude this with make getter when we can obtain the event folder name
469 AliError("Can not get the getter");
473 TTree* tree = (TTree*)GetLoader()->TreeH();