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.7 2000/10/02 21:28:14 fca
19 Removal of useless dependecies via forward declarations
21 Revision 1.6 2000/07/12 08:56:25 fca
22 Coding convention correction and warning removal
24 Revision 1.5 1999/09/29 09:24:29 fca
25 Introduction of the Copyright and cvs Log
29 ///////////////////////////////////////////////////////////////////////////////
31 // Base class for ALICE modules. Both sensitive modules (detectors) and //
32 // non-sensitive ones are described by this base class. This class //
33 // supports the hit and digit trees produced by the simulation and also //
34 // the objects produced by the reconstruction. //
36 // This class is also responsible for building the geometry of the //
41 <img src="picts/AliDetectorClass.gif">
45 ///////////////////////////////////////////////////////////////////////////////
50 #include "AliDetector.h"
53 #include "AliPoints.h"
54 // Static variables for the hit iterator routines
55 static Int_t sMaxIterHit=0;
56 static Int_t sCurIterHit=0;
60 //_____________________________________________________________________________
61 AliDetector::AliDetector()
64 // Default constructor for the AliDetector class
75 //_____________________________________________________________________________
76 AliDetector::AliDetector(const char* name,const char *title):AliModule(name,title)
79 // Normal constructor invoked by all Detectors.
80 // Create the list for detector specific histograms
81 // Add this Detector to the global list of Detectors in Run.
94 //_____________________________________________________________________________
95 AliDetector::~AliDetector()
103 // Delete space point structure
104 if (fPoints) fPoints->Delete();
109 //_____________________________________________________________________________
110 void AliDetector::Browse(TBrowser *b)
113 // Insert Detector objects in the list of objects to be browsed
116 if( fHits == 0) return;
120 nobjects = fHits->GetEntries();
121 for (i=0;i<nobjects;i++) {
123 sprintf(name,"%s_%d",obj->GetName(),i);
124 b->Add(obj, &name[0]);
128 //_____________________________________________________________________________
129 void AliDetector::Copy(AliDetector &det) const
132 // Copy *this onto det -- not implemented
134 Fatal("Copy","Not implemented~\n");
137 //_____________________________________________________________________________
138 void AliDetector::FinishRun()
141 // Procedure called at the end of a run.
145 //_____________________________________________________________________________
146 AliHit* AliDetector::FirstHit(Int_t track)
149 // Initialise the hit iterator
150 // Return the address of the first hit for track
151 // If track>=0 the track is read from disk
152 // while if track<0 the first hit of the current
157 gAlice->TreeH()->GetEvent(track);
160 sMaxIterHit=fHits->GetEntriesFast();
162 if(sMaxIterHit) return (AliHit*) fHits->UncheckedAt(0);
166 //_____________________________________________________________________________
167 AliHit* AliDetector::NextHit()
170 // Return the next hit for the current track
173 if(++sCurIterHit<sMaxIterHit)
174 return (AliHit*) fHits->UncheckedAt(sCurIterHit);
178 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
183 //_____________________________________________________________________________
184 void AliDetector::LoadPoints(Int_t)
187 // Store x, y, z of all hits in memory
189 if (fHits == 0) return;
191 Int_t nhits = fHits->GetEntriesFast();
192 if (nhits == 0) return;
193 Int_t tracks = gAlice->GetNtrack();
194 if (fPoints == 0) fPoints = new TObjArray(tracks);
197 Int_t *ntrk=new Int_t[tracks];
198 Int_t *limi=new Int_t[tracks];
199 Float_t **coor=new Float_t*[tracks];
200 for(Int_t i=0;i<tracks;i++) {
206 AliPoints *points = 0;
209 Int_t chunk=nhits/4+1;
211 // Loop over all the hits and store their position
212 for (Int_t hit=0;hit<nhits;hit++) {
213 ahit = (AliHit*)fHits->UncheckedAt(hit);
214 trk=ahit->GetTrack();
215 if(ntrk[trk]==limi[trk]) {
217 // Initialise a new track
218 fp=new Float_t[3*(limi[trk]+chunk)];
220 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
228 fp[3*ntrk[trk] ] = ahit->X();
229 fp[3*ntrk[trk]+1] = ahit->Y();
230 fp[3*ntrk[trk]+2] = ahit->Z();
234 for(trk=0; trk<tracks; ++trk) {
236 points = new AliPoints();
237 points->SetMarkerColor(GetMarkerColor());
238 points->SetMarkerSize(GetMarkerSize());
239 points->SetDetector(this);
240 points->SetParticle(trk);
241 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
242 fPoints->AddAt(points,trk);
252 //_____________________________________________________________________________
253 void AliDetector::MakeBranch(Option_t *option)
256 // Create a new branch in the current Root Tree
257 // The branch of fHits is automatically split
260 sprintf(branchname,"%s",GetName());
262 // Get the pointer to the header
263 char *cH = strstr(option,"H");
265 if (fHits && gAlice->TreeH() && cH) {
266 gAlice->TreeH()->Branch(branchname,&fHits, fBufferSize);
267 printf("* AliDetector::MakeBranch * Making Branch %s for hits\n",branchname);
271 //_____________________________________________________________________________
272 void AliDetector::ResetDigits()
275 // Reset number of digits and the digits array
278 if (fDigits) fDigits->Clear();
281 //_____________________________________________________________________________
282 void AliDetector::ResetHits()
285 // Reset number of hits and the hits array
288 if (fHits) fHits->Clear();
291 //_____________________________________________________________________________
292 void AliDetector::ResetPoints()
295 // Reset array of points
304 //_____________________________________________________________________________
305 void AliDetector::SetTreeAddress()
308 // Set branch address for the Hits and Digits Trees
312 sprintf(branchname,"%s",GetName());
314 // Branch address for hit tree
315 TTree *treeH = gAlice->TreeH();
316 if (treeH && fHits) {
317 branch = treeH->GetBranch(branchname);
318 if (branch) branch->SetAddress(&fHits);
321 // Branch address for digit tree
322 TTree *treeD = gAlice->TreeD();
323 if (treeD && fDigits) {
324 branch = treeD->GetBranch(branchname);
325 if (branch) branch->SetAddress(&fDigits);
329 //_____________________________________________________________________________
330 void AliDetector::Streamer(TBuffer &R__b)
333 // Stream an object of class Detector.
335 if (R__b.IsReading()) {
336 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
337 TNamed::Streamer(R__b);
338 TAttLine::Streamer(R__b);
339 TAttMarker::Streamer(R__b);
340 AliModule::Streamer(R__b);
345 // Stream the pointers but not the TClonesArrays
346 R__b >> fHits; // diff
347 R__b >> fDigits; // diff
350 R__b.WriteVersion(AliDetector::IsA());
351 TNamed::Streamer(R__b);
352 TAttLine::Streamer(R__b);
353 TAttMarker::Streamer(R__b);
354 AliModule::Streamer(R__b);
359 // Stream the pointers but not the TClonesArrays
360 R__b << fHits; // diff
361 R__b << fDigits; // diff