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 Revision 1.5 1999/09/29 09:24:29 fca
19 Introduction of the Copyright and cvs Log
23 ///////////////////////////////////////////////////////////////////////////////
25 // Base class for ALICE modules. Both sensitive modules (detectors) and //
26 // non-sensitive ones are described by this base class. This class //
27 // supports the hit and digit trees produced by the simulation and also //
28 // the objects produced by the reconstruction. //
30 // This class is also responsible for building the geometry of the //
35 <img src="picts/AliDetectorClass.gif">
39 ///////////////////////////////////////////////////////////////////////////////
40 #include "AliDetector.h"
43 #include "AliPoints.h"
48 // Static variables for the hit iterator routines
49 static Int_t sMaxIterHit=0;
50 static Int_t sCurIterHit=0;
54 //_____________________________________________________________________________
55 AliDetector::AliDetector()
58 // Default constructor for the AliDetector class
69 //_____________________________________________________________________________
70 AliDetector::AliDetector(const char* name,const char *title):AliModule(name,title)
73 // Normal constructor invoked by all Detectors.
74 // Create the list for detector specific histograms
75 // Add this Detector to the global list of Detectors in Run.
88 //_____________________________________________________________________________
89 AliDetector::~AliDetector()
97 // Delete space point structure
98 if (fPoints) fPoints->Delete();
103 //_____________________________________________________________________________
104 void AliDetector::Browse(TBrowser *b)
107 // Insert Detector objects in the list of objects to be browsed
110 if( fHits == 0) return;
114 nobjects = fHits->GetEntries();
115 for (i=0;i<nobjects;i++) {
117 sprintf(name,"%s_%d",obj->GetName(),i);
118 b->Add(obj, &name[0]);
122 //_____________________________________________________________________________
123 void AliDetector::Copy(AliDetector &det) const
126 // Copy *this onto det -- not implemented
128 Fatal("Copy","Not implemented~\n");
131 //_____________________________________________________________________________
132 void AliDetector::FinishRun()
135 // Procedure called at the end of a run.
139 //_____________________________________________________________________________
140 AliHit* AliDetector::FirstHit(Int_t track)
143 // Initialise the hit iterator
144 // Return the address of the first hit for track
145 // If track>=0 the track is read from disk
146 // while if track<0 the first hit of the current
151 gAlice->TreeH()->GetEvent(track);
154 sMaxIterHit=fHits->GetEntriesFast();
156 if(sMaxIterHit) return (AliHit*) fHits->UncheckedAt(0);
160 //_____________________________________________________________________________
161 AliHit* AliDetector::NextHit()
164 // Return the next hit for the current track
167 if(++sCurIterHit<sMaxIterHit)
168 return (AliHit*) fHits->UncheckedAt(sCurIterHit);
172 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
177 //_____________________________________________________________________________
178 void AliDetector::LoadPoints(Int_t)
181 // Store x, y, z of all hits in memory
183 if (fHits == 0) return;
185 Int_t nhits = fHits->GetEntriesFast();
186 if (nhits == 0) return;
187 Int_t tracks = gAlice->GetNtrack();
188 if (fPoints == 0) fPoints = new TObjArray(tracks);
191 Int_t *ntrk=new Int_t[tracks];
192 Int_t *limi=new Int_t[tracks];
193 Float_t **coor=new Float_t*[tracks];
194 for(Int_t i=0;i<tracks;i++) {
200 AliPoints *points = 0;
203 Int_t chunk=nhits/4+1;
205 // Loop over all the hits and store their position
206 for (Int_t hit=0;hit<nhits;hit++) {
207 ahit = (AliHit*)fHits->UncheckedAt(hit);
208 trk=ahit->GetTrack();
209 if(ntrk[trk]==limi[trk]) {
211 // Initialise a new track
212 fp=new Float_t[3*(limi[trk]+chunk)];
214 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
222 fp[3*ntrk[trk] ] = ahit->fX;
223 fp[3*ntrk[trk]+1] = ahit->fY;
224 fp[3*ntrk[trk]+2] = ahit->fZ;
228 for(trk=0; trk<tracks; ++trk) {
230 points = new AliPoints();
231 points->SetMarkerColor(GetMarkerColor());
232 points->SetMarkerSize(GetMarkerSize());
233 points->SetDetector(this);
234 points->SetParticle(trk);
235 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
236 fPoints->AddAt(points,trk);
246 //_____________________________________________________________________________
247 void AliDetector::MakeBranch(Option_t *option)
250 // Create a new branch in the current Root Tree
251 // The branch of fHits is automatically split
254 sprintf(branchname,"%s",GetName());
256 // Get the pointer to the header
257 char *cH = strstr(option,"H");
259 if (fHits && gAlice->TreeH() && cH) {
260 gAlice->TreeH()->Branch(branchname,&fHits, fBufferSize);
261 printf("* AliDetector::MakeBranch * Making Branch %s for hits\n",branchname);
265 //_____________________________________________________________________________
266 void AliDetector::ResetDigits()
269 // Reset number of digits and the digits array
272 if (fDigits) fDigits->Clear();
275 //_____________________________________________________________________________
276 void AliDetector::ResetHits()
279 // Reset number of hits and the hits array
282 if (fHits) fHits->Clear();
285 //_____________________________________________________________________________
286 void AliDetector::ResetPoints()
289 // Reset array of points
298 //_____________________________________________________________________________
299 void AliDetector::SetTreeAddress()
302 // Set branch address for the Hits and Digits Trees
306 sprintf(branchname,"%s",GetName());
308 // Branch address for hit tree
309 TTree *treeH = gAlice->TreeH();
310 if (treeH && fHits) {
311 branch = treeH->GetBranch(branchname);
312 if (branch) branch->SetAddress(&fHits);
315 // Branch address for digit tree
316 TTree *treeD = gAlice->TreeD();
317 if (treeD && fDigits) {
318 branch = treeD->GetBranch(branchname);
319 if (branch) branch->SetAddress(&fDigits);
323 //_____________________________________________________________________________
324 void AliDetector::Streamer(TBuffer &R__b)
327 // Stream an object of class Detector.
329 if (R__b.IsReading()) {
330 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
331 TNamed::Streamer(R__b);
332 TAttLine::Streamer(R__b);
333 TAttMarker::Streamer(R__b);
334 AliModule::Streamer(R__b);
339 // Stream the pointers but not the TClonesArrays
340 R__b >> fHits; // diff
341 R__b >> fDigits; // diff
344 R__b.WriteVersion(AliDetector::IsA());
345 TNamed::Streamer(R__b);
346 TAttLine::Streamer(R__b);
347 TAttMarker::Streamer(R__b);
348 AliModule::Streamer(R__b);
353 // Stream the pointers but not the TClonesArrays
354 R__b << fHits; // diff
355 R__b << fDigits; // diff