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.9 2000/12/12 18:19:06 alibrary
19 Introduce consistency check when loading points
21 Revision 1.8 2000/11/30 07:12:48 alibrary
22 Introducing new Rndm and QA classes
24 Revision 1.7 2000/10/02 21:28:14 fca
25 Removal of useless dependecies via forward declarations
27 Revision 1.6 2000/07/12 08:56:25 fca
28 Coding convention correction and warning removal
30 Revision 1.5 1999/09/29 09:24:29 fca
31 Introduction of the Copyright and cvs Log
35 ///////////////////////////////////////////////////////////////////////////////
37 // Base class for ALICE modules. Both sensitive modules (detectors) and //
38 // non-sensitive ones are described by this base class. This class //
39 // supports the hit and digit trees produced by the simulation and also //
40 // the objects produced by the reconstruction. //
42 // This class is also responsible for building the geometry of the //
47 <img src="picts/AliDetectorClass.gif">
51 ///////////////////////////////////////////////////////////////////////////////
58 #include "AliDetector.h"
61 #include "AliPoints.h"
62 // Static variables for the hit iterator routines
63 static Int_t sMaxIterHit=0;
64 static Int_t sCurIterHit=0;
68 //_____________________________________________________________________________
69 AliDetector::AliDetector()
72 // Default constructor for the AliDetector class
83 //_____________________________________________________________________________
84 AliDetector::AliDetector(const char* name,const char *title):AliModule(name,title)
87 // Normal constructor invoked by all Detectors.
88 // Create the list for detector specific histograms
89 // Add this Detector to the global list of Detectors in Run.
102 //_____________________________________________________________________________
103 AliDetector::~AliDetector()
111 // Delete space point structure
117 // Delete digits structure
125 //_____________________________________________________________________________
126 void AliDetector::Browse(TBrowser *b)
129 // Insert Detector objects in the list of objects to be browsed
132 if( fHits == 0) return;
136 nobjects = fHits->GetEntries();
137 for (i=0;i<nobjects;i++) {
139 sprintf(name,"%s_%d",obj->GetName(),i);
140 b->Add(obj, &name[0]);
144 //_____________________________________________________________________________
145 void AliDetector::Copy(AliDetector &det) const
148 // Copy *this onto det -- not implemented
150 Fatal("Copy","Not implemented~\n");
153 //_____________________________________________________________________________
154 void AliDetector::FinishRun()
157 // Procedure called at the end of a run.
161 //_____________________________________________________________________________
162 AliHit* AliDetector::FirstHit(Int_t track)
165 // Initialise the hit iterator
166 // Return the address of the first hit for track
167 // If track>=0 the track is read from disk
168 // while if track<0 the first hit of the current
173 gAlice->TreeH()->GetEvent(track);
176 sMaxIterHit=fHits->GetEntriesFast();
178 if(sMaxIterHit) return (AliHit*) fHits->UncheckedAt(0);
182 //_____________________________________________________________________________
183 AliHit* AliDetector::NextHit()
186 // Return the next hit for the current track
189 if(++sCurIterHit<sMaxIterHit)
190 return (AliHit*) fHits->UncheckedAt(sCurIterHit);
194 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
199 //_____________________________________________________________________________
200 void AliDetector::LoadPoints(Int_t)
203 // Store x, y, z of all hits in memory
205 if (fHits == 0) return;
207 Int_t nhits = fHits->GetEntriesFast();
208 if (nhits == 0) return;
209 Int_t tracks = gAlice->GetNtrack();
210 if (fPoints == 0) fPoints = new TObjArray(tracks);
213 Int_t *ntrk=new Int_t[tracks];
214 Int_t *limi=new Int_t[tracks];
215 Float_t **coor=new Float_t*[tracks];
216 for(Int_t i=0;i<tracks;i++) {
222 AliPoints *points = 0;
225 Int_t chunk=nhits/4+1;
227 // Loop over all the hits and store their position
228 for (Int_t hit=0;hit<nhits;hit++) {
229 ahit = (AliHit*)fHits->UncheckedAt(hit);
230 trk=ahit->GetTrack();
232 if(ntrk[trk]==limi[trk]) {
234 // Initialise a new track
235 fp=new Float_t[3*(limi[trk]+chunk)];
237 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
245 fp[3*ntrk[trk] ] = ahit->X();
246 fp[3*ntrk[trk]+1] = ahit->Y();
247 fp[3*ntrk[trk]+2] = ahit->Z();
251 for(trk=0; trk<tracks; ++trk) {
253 points = new AliPoints();
254 points->SetMarkerColor(GetMarkerColor());
255 points->SetMarkerSize(GetMarkerSize());
256 points->SetDetector(this);
257 points->SetParticle(trk);
258 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
259 fPoints->AddAt(points,trk);
269 //_____________________________________________________________________________
270 void AliDetector::MakeBranch(Option_t *option)
273 // Create a new branch in the current Root Tree
274 // The branch of fHits is automatically split
277 sprintf(branchname,"%s",GetName());
279 // Get the pointer to the header
280 char *cH = strstr(option,"H");
282 if (fHits && gAlice->TreeH() && cH) {
283 gAlice->TreeH()->Branch(branchname,&fHits, fBufferSize);
284 printf("* AliDetector::MakeBranch * Making Branch %s for hits\n",branchname);
288 //_____________________________________________________________________________
289 void AliDetector::ResetDigits()
292 // Reset number of digits and the digits array
295 if (fDigits) fDigits->Clear();
298 //_____________________________________________________________________________
299 void AliDetector::ResetHits()
302 // Reset number of hits and the hits array
305 if (fHits) fHits->Clear();
308 //_____________________________________________________________________________
309 void AliDetector::ResetPoints()
312 // Reset array of points
321 //_____________________________________________________________________________
322 void AliDetector::SetTreeAddress()
325 // Set branch address for the Hits and Digits Trees
329 sprintf(branchname,"%s",GetName());
331 // Branch address for hit tree
332 TTree *treeH = gAlice->TreeH();
333 if (treeH && fHits) {
334 branch = treeH->GetBranch(branchname);
335 if (branch) branch->SetAddress(&fHits);
338 // Branch address for digit tree
339 TTree *treeD = gAlice->TreeD();
340 if (treeD && fDigits) {
341 branch = treeD->GetBranch(branchname);
342 if (branch) branch->SetAddress(&fDigits);
346 //_____________________________________________________________________________
347 void AliDetector::Streamer(TBuffer &R__b)
350 // Stream an object of class Detector.
352 if (R__b.IsReading()) {
353 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
354 TNamed::Streamer(R__b);
355 TAttLine::Streamer(R__b);
356 TAttMarker::Streamer(R__b);
357 AliModule::Streamer(R__b);
362 // Stream the pointers but not the TClonesArrays
363 R__b >> fHits; // diff
364 R__b >> fDigits; // diff
367 R__b.WriteVersion(AliDetector::IsA());
368 TNamed::Streamer(R__b);
369 TAttLine::Streamer(R__b);
370 TAttMarker::Streamer(R__b);
371 AliModule::Streamer(R__b);
376 // Stream the pointers but not the TClonesArrays
377 R__b << fHits; // diff
378 R__b << fDigits; // diff