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.12 2001/03/12 17:47:03 hristov
19 Changes needed on Sun with CC 5.0
21 Revision 1.11 2001/01/26 19:58:46 hristov
22 Major upgrade of AliRoot code
24 Revision 1.10 2001/01/17 10:50:50 hristov
25 Corrections to destructors
27 Revision 1.9 2000/12/12 18:19:06 alibrary
28 Introduce consistency check when loading points
30 Revision 1.8 2000/11/30 07:12:48 alibrary
31 Introducing new Rndm and QA classes
33 Revision 1.7 2000/10/02 21:28:14 fca
34 Removal of useless dependecies via forward declarations
36 Revision 1.6 2000/07/12 08:56:25 fca
37 Coding convention correction and warning removal
39 Revision 1.5 1999/09/29 09:24:29 fca
40 Introduction of the Copyright and cvs Log
44 ///////////////////////////////////////////////////////////////////////////////
46 // Base class for ALICE modules. Both sensitive modules (detectors) and //
47 // non-sensitive ones are described by this base class. This class //
48 // supports the hit and digit trees produced by the simulation and also //
49 // the objects produced by the reconstruction. //
51 // This class is also responsible for building the geometry of the //
56 <img src="picts/AliDetectorClass.gif">
60 ///////////////////////////////////////////////////////////////////////////////
71 #include "AliConfig.h"
72 #include "AliDetector.h"
75 #include "AliPoints.h"
77 // Static variables for the hit iterator routines
78 static Int_t sMaxIterHit=0;
79 static Int_t sCurIterHit=0;
83 //_____________________________________________________________________________
84 AliDetector::AliDetector()
87 // Default constructor for the AliDetector class
99 //_____________________________________________________________________________
100 AliDetector::AliDetector(const char* name,const char *title):AliModule(name,title)
103 // Normal constructor invoked by all Detectors.
104 // Create the list for detector specific histograms
105 // Add this Detector to the global list of Detectors in Run.
118 AliConfig::Instance()->Add(this);
121 //_____________________________________________________________________________
122 AliDetector::~AliDetector()
130 // Delete space point structure
136 // Delete digits structure
142 if (fDigitsFile) delete [] fDigitsFile;
145 //_____________________________________________________________________________
146 void AliDetector::Publish(const char *dir, void *address, const char *name)
149 // Register pointer to detector objects.
151 TFolder *topFolder = (TFolder *)gROOT->FindObjectAny("/Folders");
152 TFolder *folder = (TFolder *)topFolder->FindObjectAny(dir);
153 // TFolder *folder = (TFolder *)gROOT->FindObjectAny(dir);
155 cerr << "Cannot register: Missing folder: " << dir << endl;
157 TFolder *subfolder = (TFolder *) folder->FindObjectAny(this->GetName());
160 subfolder = folder->AddFolder(this->GetName(),this->GetTitle());
162 TObject **obj = (TObject **) address;
163 if ((*obj)->InheritsFrom(TCollection::Class())) {
164 TCollection *collection = (TCollection *) (*obj);
166 collection->SetName(name);
168 subfolder->Add(*obj);
173 //_____________________________________________________________________________
174 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, void* address, Int_t size,const char *file)
176 return(MakeBranchInTree(tree,name,0,address,size,1,file));
179 //_____________________________________________________________________________
180 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, const char *classname, void* address,Int_t size, Int_t splitlevel, const char *file)
183 // Makes branch in given tree and diverts them to a separate file
186 printf("* MakeBranch * Making Branch %s \n",name);
188 TDirectory *cwd = gDirectory;
192 branch = tree->Branch(name,classname,address,size,splitlevel);
194 branch = tree->Branch(name,address,size);
198 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
199 sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
200 branch->SetFile(outFile);
201 TIter next( branch->GetListOfBranches());
202 while ((branch=(TBranch*)next())) {
203 branch->SetFile(outFile);
210 printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
214 if (!strncmp(tree->GetName(),"TreeE",5)) folder = "RunMC/Event/Data";
215 if (!strncmp(tree->GetName(),"TreeK",5)) folder = "RunMC/Event/Data";
216 if (!strncmp(tree->GetName(),"TreeH",5)) folder = "RunMC/Event/Data";
217 if (!strncmp(tree->GetName(),"TreeD",5)) folder = "Run/Event/Data";
218 if (!strncmp(tree->GetName(),"TreeS",5)) folder = "Run/Event/Data";
219 if (!strncmp(tree->GetName(),"TreeR",5)) folder = "Run/Event/RecData";
223 printf("%15s: Publishing %s to %s\n",ClassName(),name,folder);
224 Publish(folder,address,name);
229 //_____________________________________________________________________________
230 void AliDetector::Browse(TBrowser *b)
233 // Insert Detector objects in the list of objects to be browsed
236 if( fHits == 0) return;
240 nobjects = fHits->GetEntries();
241 for (i=0;i<nobjects;i++) {
243 sprintf(name,"%s_%d",obj->GetName(),i);
244 b->Add(obj, &name[0]);
248 //_____________________________________________________________________________
249 void AliDetector::Copy(AliDetector &det) const
252 // Copy *this onto det -- not implemented
254 Fatal("Copy","Not implemented~\n");
257 //_____________________________________________________________________________
258 void AliDetector::FinishRun()
261 // Procedure called at the end of a run.
265 //_____________________________________________________________________________
266 AliHit* AliDetector::FirstHit(Int_t track)
269 // Initialise the hit iterator
270 // Return the address of the first hit for track
271 // If track>=0 the track is read from disk
272 // while if track<0 the first hit of the current
277 gAlice->TreeH()->GetEvent(track);
280 sMaxIterHit=fHits->GetEntriesFast();
282 if(sMaxIterHit) return (AliHit*) fHits->UncheckedAt(0);
286 //_____________________________________________________________________________
287 AliHit* AliDetector::NextHit()
290 // Return the next hit for the current track
293 if(++sCurIterHit<sMaxIterHit)
294 return (AliHit*) fHits->UncheckedAt(sCurIterHit);
298 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
303 //_____________________________________________________________________________
304 void AliDetector::LoadPoints(Int_t)
307 // Store x, y, z of all hits in memory
309 if (fHits == 0) return;
311 Int_t nhits = fHits->GetEntriesFast();
312 if (nhits == 0) return;
313 Int_t tracks = gAlice->GetNtrack();
314 if (fPoints == 0) fPoints = new TObjArray(tracks);
317 Int_t *ntrk=new Int_t[tracks];
318 Int_t *limi=new Int_t[tracks];
319 Float_t **coor=new Float_t*[tracks];
320 for(Int_t i=0;i<tracks;i++) {
326 AliPoints *points = 0;
329 Int_t chunk=nhits/4+1;
331 // Loop over all the hits and store their position
332 for (Int_t hit=0;hit<nhits;hit++) {
333 ahit = (AliHit*)fHits->UncheckedAt(hit);
334 trk=ahit->GetTrack();
336 if(ntrk[trk]==limi[trk]) {
338 // Initialise a new track
339 fp=new Float_t[3*(limi[trk]+chunk)];
341 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
349 fp[3*ntrk[trk] ] = ahit->X();
350 fp[3*ntrk[trk]+1] = ahit->Y();
351 fp[3*ntrk[trk]+2] = ahit->Z();
355 for(trk=0; trk<tracks; ++trk) {
357 points = new AliPoints();
358 points->SetMarkerColor(GetMarkerColor());
359 points->SetMarkerSize(GetMarkerSize());
360 points->SetDetector(this);
361 points->SetParticle(trk);
362 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
363 fPoints->AddAt(points,trk);
373 //_____________________________________________________________________________
374 void AliDetector::MakeBranch(Option_t *option, const char *file)
377 // Create a new branch in the current Root Tree
378 // The branch of fHits is automatically split
382 sprintf(branchname,"%s",GetName());
384 // Get the pointer to the header
385 const char *cH = strstr(option,"H");
387 if (fHits && gAlice->TreeH() && cH) {
388 MakeBranchInTree(gAlice->TreeH(),
389 branchname, &fHits, fBufferSize, file) ;
392 const char *cD = strstr(option,"D");
396 fDigitsFile = new char[strlen (file)];
397 strcpy(fDigitsFile,file);
402 //_____________________________________________________________________________
403 void AliDetector::ResetDigits()
406 // Reset number of digits and the digits array
409 if (fDigits) fDigits->Clear();
412 //_____________________________________________________________________________
413 void AliDetector::ResetHits()
416 // Reset number of hits and the hits array
419 if (fHits) fHits->Clear();
422 //_____________________________________________________________________________
423 void AliDetector::ResetPoints()
426 // Reset array of points
435 //_____________________________________________________________________________
436 void AliDetector::SetTreeAddress()
439 // Set branch address for the Hits and Digits Trees
443 sprintf(branchname,"%s",GetName());
445 // Branch address for hit tree
446 TTree *treeH = gAlice->TreeH();
447 if (treeH && fHits) {
448 branch = treeH->GetBranch(branchname);
449 if (branch) branch->SetAddress(&fHits);
452 // Branch address for digit tree
453 TTree *treeD = gAlice->TreeD();
454 if (treeD && fDigits) {
455 branch = treeD->GetBranch(branchname);
456 if (branch) branch->SetAddress(&fDigits);