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.6 2000/07/12 08:56:25 fca
19 Coding convention correction and warning removal
21 Revision 1.5 1999/09/29 09:24:29 fca
22 Introduction of the Copyright and cvs Log
26 ///////////////////////////////////////////////////////////////////////////////
28 // Base class for ALICE modules. Both sensitive modules (detectors) and //
29 // non-sensitive ones are described by this base class. This class //
30 // supports the hit and digit trees produced by the simulation and also //
31 // the objects produced by the reconstruction. //
33 // This class is also responsible for building the geometry of the //
38 <img src="picts/AliDetectorClass.gif">
42 ///////////////////////////////////////////////////////////////////////////////
49 #include "AliDetector.h"
52 #include "AliPoints.h"
53 // Static variables for the hit iterator routines
54 static Int_t sMaxIterHit=0;
55 static Int_t sCurIterHit=0;
59 //_____________________________________________________________________________
60 AliDetector::AliDetector()
63 // Default constructor for the AliDetector class
74 //_____________________________________________________________________________
75 AliDetector::AliDetector(const char* name,const char *title):AliModule(name,title)
78 // Normal constructor invoked by all Detectors.
79 // Create the list for detector specific histograms
80 // Add this Detector to the global list of Detectors in Run.
93 //_____________________________________________________________________________
94 AliDetector::~AliDetector()
102 // Delete space point structure
103 if (fPoints) fPoints->Delete();
108 //_____________________________________________________________________________
109 void AliDetector::Browse(TBrowser *b)
112 // Insert Detector objects in the list of objects to be browsed
115 if( fHits == 0) return;
119 nobjects = fHits->GetEntries();
120 for (i=0;i<nobjects;i++) {
122 sprintf(name,"%s_%d",obj->GetName(),i);
123 b->Add(obj, &name[0]);
127 //_____________________________________________________________________________
128 void AliDetector::Copy(AliDetector &det) const
131 // Copy *this onto det -- not implemented
133 Fatal("Copy","Not implemented~\n");
136 //_____________________________________________________________________________
137 void AliDetector::FinishRun()
140 // Procedure called at the end of a run.
144 //_____________________________________________________________________________
145 AliHit* AliDetector::FirstHit(Int_t track)
148 // Initialise the hit iterator
149 // Return the address of the first hit for track
150 // If track>=0 the track is read from disk
151 // while if track<0 the first hit of the current
156 gAlice->TreeH()->GetEvent(track);
159 sMaxIterHit=fHits->GetEntriesFast();
161 if(sMaxIterHit) return (AliHit*) fHits->UncheckedAt(0);
165 //_____________________________________________________________________________
166 AliHit* AliDetector::NextHit()
169 // Return the next hit for the current track
172 if(++sCurIterHit<sMaxIterHit)
173 return (AliHit*) fHits->UncheckedAt(sCurIterHit);
177 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
182 //_____________________________________________________________________________
183 void AliDetector::LoadPoints(Int_t)
186 // Store x, y, z of all hits in memory
188 if (fHits == 0) return;
190 Int_t nhits = fHits->GetEntriesFast();
191 if (nhits == 0) return;
192 Int_t tracks = gAlice->GetNtrack();
193 if (fPoints == 0) fPoints = new TObjArray(tracks);
196 Int_t *ntrk=new Int_t[tracks];
197 Int_t *limi=new Int_t[tracks];
198 Float_t **coor=new Float_t*[tracks];
199 for(Int_t i=0;i<tracks;i++) {
205 AliPoints *points = 0;
208 Int_t chunk=nhits/4+1;
210 // Loop over all the hits and store their position
211 for (Int_t hit=0;hit<nhits;hit++) {
212 ahit = (AliHit*)fHits->UncheckedAt(hit);
213 trk=ahit->GetTrack();
214 if(ntrk[trk]==limi[trk]) {
216 // Initialise a new track
217 fp=new Float_t[3*(limi[trk]+chunk)];
219 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
227 fp[3*ntrk[trk] ] = ahit->X();
228 fp[3*ntrk[trk]+1] = ahit->Y();
229 fp[3*ntrk[trk]+2] = ahit->Z();
233 for(trk=0; trk<tracks; ++trk) {
235 points = new AliPoints();
236 points->SetMarkerColor(GetMarkerColor());
237 points->SetMarkerSize(GetMarkerSize());
238 points->SetDetector(this);
239 points->SetParticle(trk);
240 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
241 fPoints->AddAt(points,trk);
251 //_____________________________________________________________________________
252 void AliDetector::MakeBranch(Option_t *option)
255 // Create a new branch in the current Root Tree
256 // The branch of fHits is automatically split
259 sprintf(branchname,"%s",GetName());
261 // Get the pointer to the header
262 char *cH = strstr(option,"H");
264 if (fHits && gAlice->TreeH() && cH) {
265 gAlice->TreeH()->Branch(branchname,&fHits, fBufferSize);
266 printf("* AliDetector::MakeBranch * Making Branch %s for hits\n",branchname);
270 //_____________________________________________________________________________
271 void AliDetector::ResetDigits()
274 // Reset number of digits and the digits array
277 if (fDigits) fDigits->Clear();
280 //_____________________________________________________________________________
281 void AliDetector::ResetHits()
284 // Reset number of hits and the hits array
287 if (fHits) fHits->Clear();
290 //_____________________________________________________________________________
291 void AliDetector::ResetPoints()
294 // Reset array of points
303 //_____________________________________________________________________________
304 void AliDetector::SetTreeAddress()
307 // Set branch address for the Hits and Digits Trees
311 sprintf(branchname,"%s",GetName());
313 // Branch address for hit tree
314 TTree *treeH = gAlice->TreeH();
315 if (treeH && fHits) {
316 branch = treeH->GetBranch(branchname);
317 if (branch) branch->SetAddress(&fHits);
320 // Branch address for digit tree
321 TTree *treeD = gAlice->TreeD();
322 if (treeD && fDigits) {
323 branch = treeD->GetBranch(branchname);
324 if (branch) branch->SetAddress(&fDigits);
328 //_____________________________________________________________________________
329 void AliDetector::Streamer(TBuffer &R__b)
332 // Stream an object of class Detector.
334 if (R__b.IsReading()) {
335 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
336 TNamed::Streamer(R__b);
337 TAttLine::Streamer(R__b);
338 TAttMarker::Streamer(R__b);
339 AliModule::Streamer(R__b);
344 // Stream the pointers but not the TClonesArrays
345 R__b >> fHits; // diff
346 R__b >> fDigits; // diff
349 R__b.WriteVersion(AliDetector::IsA());
350 TNamed::Streamer(R__b);
351 TAttLine::Streamer(R__b);
352 TAttMarker::Streamer(R__b);
353 AliModule::Streamer(R__b);
358 // Stream the pointers but not the TClonesArrays
359 R__b << fHits; // diff
360 R__b << fDigits; // diff