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 ///////////////////////////////////////////////////////////////////////////////
43 #include <Riostream.h>
45 #include "AliConfig.h"
46 #include "AliDetector.h"
48 #include "AliPoints.h"
49 #include "AliLoader.h"
54 // Static variables for the hit iterator routines
55 static Int_t sMaxIterHit=0;
56 static Int_t sCurIterHit=0;
61 //_______________________________________________________________________
62 AliDetector::AliDetector():
74 // Default constructor for the AliDetector class
78 //_______________________________________________________________________
79 AliDetector::AliDetector(const AliDetector &det):
94 //_____________________________________________________________________________
95 AliDetector::AliDetector(const char* name,const char *title):
96 AliModule(name,title),
108 // Normal constructor invoked by all Detectors.
109 // Create the list for detector specific histograms
110 // Add this Detector to the global list of Detectors in Run.
114 AliConfig::Instance()->Add(this);
118 //_______________________________________________________________________
119 AliDetector::~AliDetector()
125 // Delete space point structure
131 // Delete digits structure
140 fLoader->GetModulesFolder()->Remove(this);
145 //_______________________________________________________________________
146 void AliDetector::Publish(const char */*dir*/, void */*address*/, const char */*name*/)
149 // Register pointer to detector objects.
151 // TFolder *topFolder = (TFolder *)gROOT->FindObjectAny("/Folders");
152 MayNotUse("Publish");
155 //_______________________________________________________________________
156 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
157 void* address, Int_t size,
160 return(MakeBranchInTree(tree,name,0,address,size,99,file));
163 //_______________________________________________________________________
164 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
165 const char *classname,
166 void* address,Int_t size,
167 Int_t splitlevel, const char */*file*/)
170 // Makes branch in given tree and diverts them to a separate file
175 if(GetDebug()) Info("MakeBranch","Making Branch %s",name);
178 Error("MakeBranch","Making Branch %s Tree is NULL",name);
181 TBranch *branch = tree->GetBranch(name);
184 if(GetDebug()) Info("MakeBranch","Branch %s is already in tree.",name);
190 branch = tree->Branch(name,classname,address,size,splitlevel);
194 branch = tree->Branch(name,address,size);
196 if(GetDebug()) Info("MakeBranch","Branch %s returning branch %#x",name,branch);
200 //_______________________________________________________________________
201 void AliDetector::Browse(TBrowser *b)
204 // Insert Detector objects in the list of objects to be browsed
207 if( fHits == 0) return;
211 nobjects = fHits->GetEntries();
212 for (i=0;i<nobjects;i++) {
214 sprintf(name,"%s_%d",obj->GetName(),i);
215 b->Add(obj, &name[0]);
219 //_______________________________________________________________________
220 void AliDetector::Copy(TObject &) const
223 // Copy *this onto det -- not implemented
225 Fatal("Copy","Not implemented\n");
228 //_______________________________________________________________________
229 void AliDetector::FinishRun()
232 // Procedure called at the end of a run.
236 //_______________________________________________________________________
237 AliHit* AliDetector::FirstHit(Int_t track)
240 // Initialise the hit iterator
241 // Return the address of the first hit for track
242 // If track>=0 the track is read from disk
243 // while if track<0 the first hit of the current
247 gAlice->ResetHits(); //stupid = if N detector this method is called N times
248 TreeH()->GetEvent(track); //skowron
251 sMaxIterHit=fHits->GetEntriesFast();
253 if(sMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
257 //_______________________________________________________________________
258 AliHit* AliDetector::NextHit()
261 // Return the next hit for the current track
264 if(++sCurIterHit<sMaxIterHit)
265 return dynamic_cast<AliHit*>(fHits->UncheckedAt(sCurIterHit));
269 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
274 //_______________________________________________________________________
275 void AliDetector::LoadPoints(Int_t)
278 // Store x, y, z of all hits in memory
282 Error("LoadPoints","fHits == 0. Name is %s",GetName());
286 Int_t nhits = fHits->GetEntriesFast();
289 // Error("LoadPoints","nhits == 0. Name is %s",GetName());
292 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
293 if (fPoints == 0) fPoints = new TObjArray(tracks);
296 Int_t *ntrk=new Int_t[tracks];
297 Int_t *limi=new Int_t[tracks];
298 Float_t **coor=new Float_t*[tracks];
299 for(Int_t i=0;i<tracks;i++) {
305 AliPoints *points = 0;
308 Int_t chunk=nhits/4+1;
310 // Loop over all the hits and store their position
311 for (Int_t hit=0;hit<nhits;hit++) {
312 ahit = dynamic_cast<AliHit*>(fHits->UncheckedAt(hit));
313 trk=ahit->GetTrack();
315 if(ntrk[trk]==limi[trk])
318 // Initialise a new track
319 fp=new Float_t[3*(limi[trk]+chunk)];
322 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
332 fp[3*ntrk[trk] ] = ahit->X();
333 fp[3*ntrk[trk]+1] = ahit->Y();
334 fp[3*ntrk[trk]+2] = ahit->Z();
338 for(trk=0; trk<tracks; ++trk) {
340 points = new AliPoints();
341 points->SetMarkerColor(GetMarkerColor());
342 points->SetMarkerSize(GetMarkerSize());
343 points->SetDetector(this);
344 points->SetParticle(trk);
345 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
346 fPoints->AddAt(points,trk);
356 //_______________________________________________________________________
357 void AliDetector::MakeBranch(Option_t *option)
360 // Create a new branch for this detector in its treeH
363 if(GetDebug()) Info("MakeBranch"," for %s",GetName());
364 const char *cH = strstr(option,"H");
366 if (fHits && TreeH() && cH)
368 MakeBranchInTree(TreeH(), GetName(), &fHits, fBufferSize, 0);
372 //_______________________________________________________________________
373 void AliDetector::ResetDigits()
376 // Reset number of digits and the digits array
379 if (fDigits) fDigits->Clear();
382 //_______________________________________________________________________
383 void AliDetector::ResetHits()
386 // Reset number of hits and the hits array
389 if (fHits) fHits->Clear();
392 //_______________________________________________________________________
393 void AliDetector::ResetPoints()
396 // Reset array of points
405 //_______________________________________________________________________
406 void AliDetector::SetTreeAddress()
409 // Set branch address for the Hits and Digits Trees
413 // Branch address for hit tree
415 TTree *tree = TreeH();
417 branch = tree->GetBranch(GetName());
420 if(GetDebug()) Info("SetTreeAddress","(%s) Setting for Hits",GetName());
421 branch->SetAddress(&fHits);
424 { //can be invoked before branch creation
425 if(GetDebug()) Warning("SetTreeAddress","(%s) Failed for Hits. Can not find branch in tree.",GetName());
430 // Branch address for digit tree
431 TTree *treeD = fLoader->TreeD();
432 if (treeD && fDigits) {
433 branch = treeD->GetBranch(GetName());
434 if (branch) branch->SetAddress(&fDigits);
437 AliModule::SetTreeAddress();
440 //_______________________________________________________________________
441 void AliDetector::MakeTree(Option_t *option)
443 //makes a tree (container) for the data defined in option
446 //"S" - summable digits
447 //"R" - recontructed points and tracks
449 AliLoader* loader = GetLoader();
452 Error("MakeTree","Can not get loader for %s",GetName());
455 loader->MakeTree(option); //delegate this job to getter
458 //_______________________________________________________________________
459 AliLoader* AliDetector::MakeLoader(const char* topfoldername)
461 //builds standard getter (AliLoader type)
462 //if detector wants to use castomized getter, it must overload this method
466 "Creating standard getter for detector %s. Top folder is %s.",
467 GetName(),topfoldername);
469 fLoader = new AliLoader(GetName(),topfoldername);
473 //_______________________________________________________________________
474 TTree* AliDetector::TreeH()
476 //Get the hits container from the folder
477 if (GetLoader() == 0x0)
479 //sunstitude this with make getter when we can obtain the event folder name
480 Error("TreeH","Can not get the getter");
484 TTree* tree = (TTree*)GetLoader()->TreeH();