1 ///////////////////////////////////////////////////////////////////////////////
3 // Base class for ALICE modules. Both sensitive modules (detectors) and //
4 // non-sensitive ones are described by this base class. This class //
5 // supports the hit and digit trees produced by the simulation and also //
6 // the objects produced by the reconstruction. //
8 // This class is also responsible for building the geometry of the //
13 <img src="gif/AliDetectorClass.gif">
17 ///////////////////////////////////////////////////////////////////////////////
18 #include "AliDetector.h"
21 #include "AliPoints.h"
26 // Static variables for the hit iterator routines
27 static Int_t sMaxIterHit=0;
28 static Int_t sCurIterHit=0;
32 //_____________________________________________________________________________
33 AliDetector::AliDetector()
36 // Default constructor for the AliDetector class
47 //_____________________________________________________________________________
48 AliDetector::AliDetector(const char* name,const char *title):AliModule(name,title)
51 // Normal constructor invoked by all Detectors.
52 // Create the list for detector specific histograms
53 // Add this Detector to the global list of Detectors in Run.
66 //_____________________________________________________________________________
67 AliDetector::~AliDetector()
75 // Delete space point structure
76 if (fPoints) fPoints->Delete();
81 //_____________________________________________________________________________
82 void AliDetector::Browse(TBrowser *b)
85 // Insert Detector objects in the list of objects to be browsed
88 if( fHits == 0) return;
92 nobjects = fHits->GetEntries();
93 for (i=0;i<nobjects;i++) {
95 sprintf(name,"%s_%d",obj->GetName(),i);
96 b->Add(obj, &name[0]);
100 //_____________________________________________________________________________
101 void AliDetector::FinishRun()
104 // Procedure called at the end of a run.
108 //_____________________________________________________________________________
109 AliHit* AliDetector::FirstHit(Int_t track)
112 // Initialise the hit iterator
113 // Return the address of the first hit for track
114 // If track>=0 the track is read from disk
115 // while if track<0 the first hit of the current
120 gAlice->TreeH()->GetEvent(track);
123 sMaxIterHit=fHits->GetEntriesFast();
125 if(sMaxIterHit) return (AliHit*) fHits->UncheckedAt(0);
129 //_____________________________________________________________________________
130 AliHit* AliDetector::NextHit()
133 // Return the next hit for the current track
136 if(++sCurIterHit<sMaxIterHit)
137 return (AliHit*) fHits->UncheckedAt(sCurIterHit);
141 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
146 //_____________________________________________________________________________
147 void AliDetector::LoadPoints(Int_t)
150 // Store x, y, z of all hits in memory
152 if (fHits == 0) return;
154 if (fPoints == 0) fPoints = new TObjArray(gAlice->GetNtrack());
155 Int_t nhits = fHits->GetEntriesFast();
156 if (nhits == 0) return;
159 AliPoints *points = 0;
162 // Loop over all the hits and store their position
163 for (Int_t hit=0;hit<nhits;hit++) {
164 ahit = (AliHit*)fHits->UncheckedAt(hit);
165 if(trko!=(trk=ahit->GetTrack())) {
167 // Initialise a new track
169 points = new AliPoints(nhits);
170 fPoints->AddAt(points,trk);
171 points->SetMarkerColor(GetMarkerColor());
172 points->SetMarkerStyle(GetMarkerStyle());
173 points->SetMarkerSize(GetMarkerSize());
174 points->SetDetector(this);
175 points->SetParticle(trk);
177 points->SetPoint(hit,ahit->fX,ahit->fY,ahit->fZ);
181 //_____________________________________________________________________________
182 void AliDetector::MakeBranch(Option_t *option)
185 // Create a new branch in the current Root Tree
186 // The branch of fHits is automatically split
189 sprintf(branchname,"%s",GetName());
191 // Get the pointer to the header
192 char *H = strstr(option,"H");
194 if (fHits && gAlice->TreeH() && H) {
195 gAlice->TreeH()->Branch(branchname,&fHits, fBufferSize);
196 printf("* AliDetector::MakeBranch * Making Branch %s for hits\n",branchname);
200 //_____________________________________________________________________________
201 void AliDetector::ResetDigits()
204 // Reset number of digits and the digits array
207 if (fDigits) fDigits->Clear();
210 //_____________________________________________________________________________
211 void AliDetector::ResetHits()
214 // Reset number of hits and the hits array
217 if (fHits) fHits->Clear();
220 //_____________________________________________________________________________
221 void AliDetector::ResetPoints()
224 // Reset array of points
233 //_____________________________________________________________________________
234 void AliDetector::SetTreeAddress()
237 // Set branch address for the Hits and Digits Trees
241 sprintf(branchname,"%s",GetName());
243 // Branch address for hit tree
244 TTree *treeH = gAlice->TreeH();
245 if (treeH && fHits) {
246 branch = treeH->GetBranch(branchname);
247 if (branch) branch->SetAddress(&fHits);
250 // Branch address for digit tree
251 TTree *treeD = gAlice->TreeD();
252 if (treeD && fDigits) {
253 branch = treeD->GetBranch(branchname);
254 if (branch) branch->SetAddress(&fDigits);
258 //_____________________________________________________________________________
259 void AliDetector::Streamer(TBuffer &R__b)
262 // Stream an object of class Detector.
264 if (R__b.IsReading()) {
265 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
266 TNamed::Streamer(R__b);
267 TAttLine::Streamer(R__b);
268 TAttMarker::Streamer(R__b);
269 AliModule::Streamer(R__b);
274 // Stream the pointers but not the TClonesArrays
275 R__b >> fHits; // diff
276 R__b >> fDigits; // diff
279 R__b.WriteVersion(AliDetector::IsA());
280 TNamed::Streamer(R__b);
281 TAttLine::Streamer(R__b);
282 TAttMarker::Streamer(R__b);
283 AliModule::Streamer(R__b);
288 // Stream the pointers but not the TClonesArrays
289 R__b << fHits; // diff
290 R__b << fDigits; // diff