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 ///////////////////////////////////////////////////////////////////////////////
37 #include <TClonesArray.h>
41 #include "AliConfig.h"
42 #include "AliDetector.h"
44 #include "AliPoints.h"
45 #include "AliLoader.h"
52 //_______________________________________________________________________
53 AliDetector::AliDetector():
68 // Default constructor for the AliDetector class
72 //_____________________________________________________________________________
73 AliDetector::AliDetector(const char* name,const char *title):
74 AliModule(name,title),
88 // Normal constructor invoked by all Detectors.
89 // Create the list for detector specific histograms
90 // Add this Detector to the global list of Detectors in Run.
94 AliConfig::Instance()->Add(this);
98 //_______________________________________________________________________
99 AliDetector::~AliDetector()
105 // Delete space point structure
111 // Delete digits structure
120 fLoader->GetModulesFolder()->Remove(this);
125 //_______________________________________________________________________
126 void AliDetector::Publish(const char */*dir*/, void */*address*/, const char */*name*/) const
129 // Register pointer to detector objects.
131 MayNotUse("Publish");
134 //_______________________________________________________________________
135 void AliDetector::AddAlignableVolumes() const
138 AliWarning(Form("%s still has to implement the AddAlignableVolumes method!",GetName()));
141 //_______________________________________________________________________
142 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
143 void* address, Int_t size,
146 return(MakeBranchInTree(tree,name,0,address,size,99,file));
149 //_______________________________________________________________________
150 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
151 const char *classname,
152 void* address,Int_t size,
153 Int_t splitlevel, const char */*file*/)
156 // Makes branch in given tree and diverts them to a separate file
161 AliDebug(2,Form("Making Branch %s",name));
164 AliError(Form("Making Branch %s Tree is NULL",name));
167 TBranch *branch = tree->GetBranch(name);
170 AliDebug(2,Form("Branch %s is already in tree.",name));
176 branch = tree->Branch(name,classname,address,size,splitlevel);
180 branch = tree->Bronch(name, "TClonesArray", address, size, splitlevel);
182 AliDebug(2,Form("Branch %s returning branch %#x",name,branch));
186 //_______________________________________________________________________
187 void AliDetector::Browse(TBrowser *b)
190 // Insert Detector objects in the list of objects to be browsed
193 if( fHits == 0) return;
197 nobjects = fHits->GetEntries();
198 for (i=0;i<nobjects;i++) {
200 sprintf(name,"%s_%d",obj->GetName(),i);
201 b->Add(obj, &name[0]);
205 //_______________________________________________________________________
206 void AliDetector::FinishRun()
209 // Procedure called at the end of a run.
213 //_______________________________________________________________________
214 AliHit* AliDetector::FirstHit(Int_t track)
217 // Initialise the hit iterator
218 // Return the address of the first hit for track
219 // If track>=0 the track is read from disk
220 // while if track<0 the first hit of the current
224 gAlice->ResetHits(); //stupid = if N detector this method is called N times
225 TreeH()->GetEvent(track); //skowron
228 fMaxIterHit=fHits->GetEntriesFast();
230 if(fMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
234 //_______________________________________________________________________
235 AliHit* AliDetector::NextHit()
238 // Return the next hit for the current track
241 if(++fCurIterHit<fMaxIterHit)
242 return dynamic_cast<AliHit*>(fHits->UncheckedAt(fCurIterHit));
246 AliWarning("Hit Iterator called without calling FistHit before");
251 //_______________________________________________________________________
252 void AliDetector::LoadPoints(Int_t)
255 // Store x, y, z of all hits in memory
259 AliError(Form("fHits == 0. Name is %s",GetName()));
263 Int_t nhits = fHits->GetEntriesFast();
266 // Error("LoadPoints","nhits == 0. Name is %s",GetName());
269 Int_t tracks = gAlice->GetMCApp()->GetNtrack();
270 if (fPoints == 0) fPoints = new TObjArray(tracks);
273 Int_t *ntrk=new Int_t[tracks];
274 Int_t *limi=new Int_t[tracks];
275 Float_t **coor=new Float_t*[tracks];
276 for(Int_t i=0;i<tracks;i++) {
282 AliPoints *points = 0;
285 Int_t chunk=nhits/4+1;
287 // Loop over all the hits and store their position
288 for (Int_t hit=0;hit<nhits;hit++) {
289 ahit = dynamic_cast<AliHit*>(fHits->UncheckedAt(hit));
290 trk=ahit->GetTrack();
292 AliError(Form("Found track number %d, max track %d",trk, tracks));
295 if(ntrk[trk]==limi[trk])
298 // Initialise a new track
299 fp=new Float_t[3*(limi[trk]+chunk)];
302 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
312 fp[3*ntrk[trk] ] = ahit->X();
313 fp[3*ntrk[trk]+1] = ahit->Y();
314 fp[3*ntrk[trk]+2] = ahit->Z();
318 for(trk=0; trk<tracks; ++trk) {
320 points = new AliPoints();
321 points->SetMarkerColor(3); //PH color=3 was set in AliModule
322 points->SetMarkerSize(1); //PH size-1 is the default value
323 points->SetDetector(this);
324 points->SetParticle(trk);
325 points->SetPolyMarker(ntrk[trk],coor[trk],1);//PH style=1 is the default value
326 fPoints->AddAt(points,trk);
336 //_______________________________________________________________________
337 void AliDetector::MakeBranch(Option_t *option)
340 // Create a new branch for this detector in its treeH
343 AliDebug(2,Form(" for %s",GetName()));
344 const char *cH = strstr(option,"H");
346 if (fHits && TreeH() && cH)
348 MakeBranchInTree(TreeH(), GetName(), &fHits, fBufferSize, 0);
352 //_______________________________________________________________________
353 void AliDetector::ResetDigits()
356 // Reset number of digits and the digits array
359 if (fDigits) fDigits->Clear();
362 //_______________________________________________________________________
363 void AliDetector::ResetHits()
366 // Reset number of hits and the hits array
369 if (fHits) fHits->Clear();
372 //_______________________________________________________________________
373 void AliDetector::ResetPoints()
376 // Reset array of points
385 //_______________________________________________________________________
386 void AliDetector::SetTreeAddress()
389 // Set branch address for the Hits and Digits Trees
393 // Branch address for hit tree
395 TTree *tree = TreeH();
397 branch = tree->GetBranch(GetName());
400 AliDebug(2,Form("(%s) Setting for Hits",GetName()));
401 branch->SetAddress(&fHits);
404 { //can be invoked before branch creation
405 AliDebug(2,Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
410 // Branch address for digit tree
411 TTree *treeD = fLoader->TreeD();
412 if (treeD && fDigits) {
413 branch = treeD->GetBranch(GetName());
414 if (branch) branch->SetAddress(&fDigits);
417 AliModule::SetTreeAddress();
420 //_______________________________________________________________________
421 void AliDetector::MakeTree(Option_t *option)
423 //makes a tree (container) for the data defined in option
426 //"S" - summable digits
427 //"R" - recontructed points and tracks
429 AliLoader* loader = GetLoader();
432 AliError(Form("Can not get loader for %s",GetName()));
435 loader->MakeTree(option); //delegate this job to getter
438 //_______________________________________________________________________
439 AliLoader* AliDetector::MakeLoader(const char* topfoldername)
441 //builds standard getter (AliLoader type)
442 //if detector wants to use castomized getter, it must overload this method
444 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
445 GetName(),topfoldername));
447 fLoader = new AliLoader(GetName(),topfoldername);
451 //_______________________________________________________________________
452 TTree* AliDetector::TreeH() const
454 //Get the hits container from the folder
455 if (GetLoader() == 0x0)
457 //sunstitude this with make getter when we can obtain the event folder name
458 AliError("Can not get the getter");
462 TTree* tree = (TTree*)GetLoader()->TreeH();