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 char* name,const char *title):
73 AliModule(name,title),
87 // Normal constructor invoked by all Detectors.
88 // Create the list for detector specific histograms
89 // Add this Detector to the global list of Detectors in Run.
93 AliConfig::Instance()->Add(this);
97 //_______________________________________________________________________
98 AliDetector::~AliDetector()
104 // Delete space point structure
110 // Delete digits structure
119 fLoader->GetModulesFolder()->Remove(this);
124 //_______________________________________________________________________
125 void AliDetector::Publish(const char */*dir*/, void */*address*/, const char */*name*/) const
128 // Register pointer to detector objects.
130 MayNotUse("Publish");
133 //_______________________________________________________________________
134 void AliDetector::AddAlignableVolumes() const
137 AliWarning(Form("%s still has to implement the AddAlignableVolumes method!",GetName()));
140 //_______________________________________________________________________
141 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
142 void* address, Int_t size,
145 return(MakeBranchInTree(tree,name,0,address,size,99,file));
148 //_______________________________________________________________________
149 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
150 const char *classname,
151 void* address,Int_t size,
152 Int_t splitlevel, const char */*file*/)
155 // Makes branch in given tree and diverts them to a separate file
160 AliDebug(2,Form("Making Branch %s",name));
163 AliError(Form("Making Branch %s Tree is NULL",name));
166 TBranch *branch = tree->GetBranch(name);
169 AliDebug(2,Form("Branch %s is already in tree.",name));
175 branch = tree->Branch(name,classname,address,size,splitlevel);
179 branch = tree->Bronch(name, "TClonesArray", address, size, splitlevel);
181 AliDebug(2,Form("Branch %s returning branch %#x",name,branch));
185 //_______________________________________________________________________
186 void AliDetector::Browse(TBrowser *b)
189 // Insert Detector objects in the list of objects to be browsed
192 if( fHits == 0) return;
196 nobjects = fHits->GetEntries();
197 for (i=0;i<nobjects;i++) {
199 sprintf(name,"%s_%d",obj->GetName(),i);
200 b->Add(obj, &name[0]);
204 //_______________________________________________________________________
205 void AliDetector::FinishRun()
208 // Procedure called at the end of a run.
212 //_______________________________________________________________________
213 AliHit* AliDetector::FirstHit(Int_t track)
216 // Initialise the hit iterator
217 // Return the address of the first hit for track
218 // If track>=0 the track is read from disk
219 // while if track<0 the first hit of the current
223 gAlice->ResetHits(); //stupid = if N detector this method is called N times
224 TreeH()->GetEvent(track); //skowron
227 fMaxIterHit=fHits->GetEntriesFast();
229 if(fMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
233 //_______________________________________________________________________
234 AliHit* AliDetector::NextHit()
237 // Return the next hit for the current track
240 if(++fCurIterHit<fMaxIterHit)
241 return dynamic_cast<AliHit*>(fHits->UncheckedAt(fCurIterHit));
245 AliWarning("Hit Iterator called without calling FistHit before");
250 //_______________________________________________________________________
251 void AliDetector::LoadPoints(Int_t)
254 // Store x, y, z of all hits in memory
258 AliError(Form("fHits == 0. Name is %s",GetName()));
262 Int_t nhits = fHits->GetEntriesFast();
265 // Error("LoadPoints","nhits == 0. Name is %s",GetName());
268 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
269 if (fPoints == 0) fPoints = new TObjArray(tracks);
272 Int_t *ntrk=new Int_t[tracks];
273 Int_t *limi=new Int_t[tracks];
274 Float_t **coor=new Float_t*[tracks];
275 for(Int_t i=0;i<tracks;i++) {
281 AliPoints *points = 0;
284 Int_t chunk=nhits/4+1;
286 // Loop over all the hits and store their position
287 for (Int_t hit=0;hit<nhits;hit++) {
288 ahit = dynamic_cast<AliHit*>(fHits->UncheckedAt(hit));
289 trk=ahit->GetTrack();
291 AliError(Form("Found track number %d, max track %d",trk, tracks));
294 if(ntrk[trk]==limi[trk])
297 // Initialise a new track
298 fp=new Float_t[3*(limi[trk]+chunk)];
301 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
311 fp[3*ntrk[trk] ] = ahit->X();
312 fp[3*ntrk[trk]+1] = ahit->Y();
313 fp[3*ntrk[trk]+2] = ahit->Z();
317 for(trk=0; trk<tracks; ++trk) {
319 points = new AliPoints();
320 points->SetMarkerColor(3); //PH color=3 was set in AliModule
321 points->SetMarkerSize(1); //PH size-1 is the default value
322 points->SetDetector(this);
323 points->SetParticle(trk);
324 points->SetPolyMarker(ntrk[trk],coor[trk],1);//PH style=1 is the default value
325 fPoints->AddAt(points,trk);
335 //_______________________________________________________________________
336 void AliDetector::MakeBranch(Option_t *option)
339 // Create a new branch for this detector in its treeH
342 AliDebug(2,Form(" for %s",GetName()));
343 const char *cH = strstr(option,"H");
345 if (fHits && TreeH() && cH)
347 MakeBranchInTree(TreeH(), GetName(), &fHits, fBufferSize, 0);
351 //_______________________________________________________________________
352 void AliDetector::ResetDigits()
355 // Reset number of digits and the digits array
358 if (fDigits) fDigits->Clear();
361 //_______________________________________________________________________
362 void AliDetector::ResetHits()
365 // Reset number of hits and the hits array
368 if (fHits) fHits->Clear();
371 //_______________________________________________________________________
372 void AliDetector::ResetPoints()
375 // Reset array of points
384 //_______________________________________________________________________
385 void AliDetector::SetTreeAddress()
388 // Set branch address for the Hits and Digits Trees
392 // Branch address for hit tree
394 TTree *tree = TreeH();
396 branch = tree->GetBranch(GetName());
399 AliDebug(2,Form("(%s) Setting for Hits",GetName()));
400 branch->SetAddress(&fHits);
403 { //can be invoked before branch creation
404 AliDebug(2,Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
409 // Branch address for digit tree
410 TTree *treeD = fLoader->TreeD();
411 if (treeD && fDigits) {
412 branch = treeD->GetBranch(GetName());
413 if (branch) branch->SetAddress(&fDigits);
416 AliModule::SetTreeAddress();
419 //_______________________________________________________________________
420 void AliDetector::MakeTree(Option_t *option)
422 //makes a tree (container) for the data defined in option
425 //"S" - summable digits
426 //"R" - recontructed points and tracks
428 AliLoader* loader = GetLoader();
431 AliError(Form("Can not get loader for %s",GetName()));
434 loader->MakeTree(option); //delegate this job to getter
437 //_______________________________________________________________________
438 AliLoader* AliDetector::MakeLoader(const char* topfoldername)
440 //builds standard getter (AliLoader type)
441 //if detector wants to use castomized getter, it must overload this method
443 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
444 GetName(),topfoldername));
446 fLoader = new AliLoader(GetName(),topfoldername);
450 //_______________________________________________________________________
451 TTree* AliDetector::TreeH() const
453 //Get the hits container from the folder
454 if (GetLoader() == 0x0)
456 //sunstitude this with make getter when we can obtain the event folder name
457 AliError("Can not get the getter");
461 TTree* tree = (TTree*)GetLoader()->TreeH();