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="picts/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 Int_t nhits = fHits->GetEntriesFast();
155 if (nhits == 0) return;
156 Int_t tracks = gAlice->GetNtrack();
157 if (fPoints == 0) fPoints = new TObjArray(tracks);
160 Int_t *ntrk=new Int_t[tracks];
161 Int_t *limi=new Int_t[tracks];
162 Float_t **coor=new Float_t*[tracks];
163 for(Int_t i=0;i<tracks;i++) {
169 AliPoints *points = 0;
172 Int_t chunk=nhits/4+1;
174 // Loop over all the hits and store their position
175 for (Int_t hit=0;hit<nhits;hit++) {
176 ahit = (AliHit*)fHits->UncheckedAt(hit);
177 trk=ahit->GetTrack();
178 if(ntrk[trk]==limi[trk]) {
180 // Initialise a new track
181 fp=new Float_t[3*(limi[trk]+chunk)];
183 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
191 fp[3*ntrk[trk] ] = ahit->fX;
192 fp[3*ntrk[trk]+1] = ahit->fY;
193 fp[3*ntrk[trk]+2] = ahit->fZ;
197 for(trk=0; trk<tracks; ++trk) {
199 points = new AliPoints();
200 points->SetMarkerColor(GetMarkerColor());
201 points->SetMarkerSize(GetMarkerSize());
202 points->SetDetector(this);
203 points->SetParticle(trk);
204 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
205 fPoints->AddAt(points,trk);
215 //_____________________________________________________________________________
216 void AliDetector::MakeBranch(Option_t *option)
219 // Create a new branch in the current Root Tree
220 // The branch of fHits is automatically split
223 sprintf(branchname,"%s",GetName());
225 // Get the pointer to the header
226 char *H = strstr(option,"H");
228 if (fHits && gAlice->TreeH() && H) {
229 gAlice->TreeH()->Branch(branchname,&fHits, fBufferSize);
230 printf("* AliDetector::MakeBranch * Making Branch %s for hits\n",branchname);
234 //_____________________________________________________________________________
235 void AliDetector::ResetDigits()
238 // Reset number of digits and the digits array
241 if (fDigits) fDigits->Clear();
244 //_____________________________________________________________________________
245 void AliDetector::ResetHits()
248 // Reset number of hits and the hits array
251 if (fHits) fHits->Clear();
254 //_____________________________________________________________________________
255 void AliDetector::ResetPoints()
258 // Reset array of points
267 //_____________________________________________________________________________
268 void AliDetector::SetTreeAddress()
271 // Set branch address for the Hits and Digits Trees
275 sprintf(branchname,"%s",GetName());
277 // Branch address for hit tree
278 TTree *treeH = gAlice->TreeH();
279 if (treeH && fHits) {
280 branch = treeH->GetBranch(branchname);
281 if (branch) branch->SetAddress(&fHits);
284 // Branch address for digit tree
285 TTree *treeD = gAlice->TreeD();
286 if (treeD && fDigits) {
287 branch = treeD->GetBranch(branchname);
288 if (branch) branch->SetAddress(&fDigits);
292 //_____________________________________________________________________________
293 void AliDetector::Streamer(TBuffer &R__b)
296 // Stream an object of class Detector.
298 if (R__b.IsReading()) {
299 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
300 TNamed::Streamer(R__b);
301 TAttLine::Streamer(R__b);
302 TAttMarker::Streamer(R__b);
303 AliModule::Streamer(R__b);
308 // Stream the pointers but not the TClonesArrays
309 R__b >> fHits; // diff
310 R__b >> fDigits; // diff
313 R__b.WriteVersion(AliDetector::IsA());
314 TNamed::Streamer(R__b);
315 TAttLine::Streamer(R__b);
316 TAttMarker::Streamer(R__b);
317 AliModule::Streamer(R__b);
322 // Stream the pointers but not the TClonesArrays
323 R__b << fHits; // diff
324 R__b << fDigits; // diff