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 **************************************************************************/
20 ///////////////////////////////////////////////////////////////////////////////
22 // Base class for ALICE modules. Both sensitive modules (detectors) and //
23 // non-sensitive ones are described by this base class. This class //
24 // supports the hit and digit trees produced by the simulation and also //
25 // the objects produced by the reconstruction. //
27 // This class is also responsible for building the geometry of the //
32 <img src="picts/AliDetectorClass.gif">
36 ///////////////////////////////////////////////////////////////////////////////
37 #include "AliDetector.h"
40 #include "AliPoints.h"
45 // Static variables for the hit iterator routines
46 static Int_t sMaxIterHit=0;
47 static Int_t sCurIterHit=0;
51 //_____________________________________________________________________________
52 AliDetector::AliDetector()
55 // Default constructor for the AliDetector class
66 //_____________________________________________________________________________
67 AliDetector::AliDetector(const char* name,const char *title):AliModule(name,title)
70 // Normal constructor invoked by all Detectors.
71 // Create the list for detector specific histograms
72 // Add this Detector to the global list of Detectors in Run.
85 //_____________________________________________________________________________
86 AliDetector::~AliDetector()
94 // Delete space point structure
95 if (fPoints) fPoints->Delete();
100 //_____________________________________________________________________________
101 void AliDetector::Browse(TBrowser *b)
104 // Insert Detector objects in the list of objects to be browsed
107 if( fHits == 0) return;
111 nobjects = fHits->GetEntries();
112 for (i=0;i<nobjects;i++) {
114 sprintf(name,"%s_%d",obj->GetName(),i);
115 b->Add(obj, &name[0]);
119 //_____________________________________________________________________________
120 void AliDetector::FinishRun()
123 // Procedure called at the end of a run.
127 //_____________________________________________________________________________
128 AliHit* AliDetector::FirstHit(Int_t track)
131 // Initialise the hit iterator
132 // Return the address of the first hit for track
133 // If track>=0 the track is read from disk
134 // while if track<0 the first hit of the current
139 gAlice->TreeH()->GetEvent(track);
142 sMaxIterHit=fHits->GetEntriesFast();
144 if(sMaxIterHit) return (AliHit*) fHits->UncheckedAt(0);
148 //_____________________________________________________________________________
149 AliHit* AliDetector::NextHit()
152 // Return the next hit for the current track
155 if(++sCurIterHit<sMaxIterHit)
156 return (AliHit*) fHits->UncheckedAt(sCurIterHit);
160 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
165 //_____________________________________________________________________________
166 void AliDetector::LoadPoints(Int_t)
169 // Store x, y, z of all hits in memory
171 if (fHits == 0) return;
173 Int_t nhits = fHits->GetEntriesFast();
174 if (nhits == 0) return;
175 Int_t tracks = gAlice->GetNtrack();
176 if (fPoints == 0) fPoints = new TObjArray(tracks);
179 Int_t *ntrk=new Int_t[tracks];
180 Int_t *limi=new Int_t[tracks];
181 Float_t **coor=new Float_t*[tracks];
182 for(Int_t i=0;i<tracks;i++) {
188 AliPoints *points = 0;
191 Int_t chunk=nhits/4+1;
193 // Loop over all the hits and store their position
194 for (Int_t hit=0;hit<nhits;hit++) {
195 ahit = (AliHit*)fHits->UncheckedAt(hit);
196 trk=ahit->GetTrack();
197 if(ntrk[trk]==limi[trk]) {
199 // Initialise a new track
200 fp=new Float_t[3*(limi[trk]+chunk)];
202 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
210 fp[3*ntrk[trk] ] = ahit->fX;
211 fp[3*ntrk[trk]+1] = ahit->fY;
212 fp[3*ntrk[trk]+2] = ahit->fZ;
216 for(trk=0; trk<tracks; ++trk) {
218 points = new AliPoints();
219 points->SetMarkerColor(GetMarkerColor());
220 points->SetMarkerSize(GetMarkerSize());
221 points->SetDetector(this);
222 points->SetParticle(trk);
223 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
224 fPoints->AddAt(points,trk);
234 //_____________________________________________________________________________
235 void AliDetector::MakeBranch(Option_t *option)
238 // Create a new branch in the current Root Tree
239 // The branch of fHits is automatically split
242 sprintf(branchname,"%s",GetName());
244 // Get the pointer to the header
245 char *H = strstr(option,"H");
247 if (fHits && gAlice->TreeH() && H) {
248 gAlice->TreeH()->Branch(branchname,&fHits, fBufferSize);
249 printf("* AliDetector::MakeBranch * Making Branch %s for hits\n",branchname);
253 //_____________________________________________________________________________
254 void AliDetector::ResetDigits()
257 // Reset number of digits and the digits array
260 if (fDigits) fDigits->Clear();
263 //_____________________________________________________________________________
264 void AliDetector::ResetHits()
267 // Reset number of hits and the hits array
270 if (fHits) fHits->Clear();
273 //_____________________________________________________________________________
274 void AliDetector::ResetPoints()
277 // Reset array of points
286 //_____________________________________________________________________________
287 void AliDetector::SetTreeAddress()
290 // Set branch address for the Hits and Digits Trees
294 sprintf(branchname,"%s",GetName());
296 // Branch address for hit tree
297 TTree *treeH = gAlice->TreeH();
298 if (treeH && fHits) {
299 branch = treeH->GetBranch(branchname);
300 if (branch) branch->SetAddress(&fHits);
303 // Branch address for digit tree
304 TTree *treeD = gAlice->TreeD();
305 if (treeD && fDigits) {
306 branch = treeD->GetBranch(branchname);
307 if (branch) branch->SetAddress(&fDigits);
311 //_____________________________________________________________________________
312 void AliDetector::Streamer(TBuffer &R__b)
315 // Stream an object of class Detector.
317 if (R__b.IsReading()) {
318 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
319 TNamed::Streamer(R__b);
320 TAttLine::Streamer(R__b);
321 TAttMarker::Streamer(R__b);
322 AliModule::Streamer(R__b);
327 // Stream the pointers but not the TClonesArrays
328 R__b >> fHits; // diff
329 R__b >> fDigits; // diff
332 R__b.WriteVersion(AliDetector::IsA());
333 TNamed::Streamer(R__b);
334 TAttLine::Streamer(R__b);
335 TAttMarker::Streamer(R__b);
336 AliModule::Streamer(R__b);
341 // Stream the pointers but not the TClonesArrays
342 R__b << fHits; // diff
343 R__b << fDigits; // diff