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.15 2001/07/27 13:03:13 hristov
19 Default Branch split level set to 99
21 Revision 1.14 2001/05/21 17:22:51 buncic
22 Fixed problem with missing AliConfig while reading galice.root
24 Revision 1.13 2001/05/16 14:57:22 alibrary
25 New files for folders and Stack
27 Revision 1.12 2001/03/12 17:47:03 hristov
28 Changes needed on Sun with CC 5.0
30 Revision 1.11 2001/01/26 19:58:46 hristov
31 Major upgrade of AliRoot code
33 Revision 1.10 2001/01/17 10:50:50 hristov
34 Corrections to destructors
36 Revision 1.9 2000/12/12 18:19:06 alibrary
37 Introduce consistency check when loading points
39 Revision 1.8 2000/11/30 07:12:48 alibrary
40 Introducing new Rndm and QA classes
42 Revision 1.7 2000/10/02 21:28:14 fca
43 Removal of useless dependecies via forward declarations
45 Revision 1.6 2000/07/12 08:56:25 fca
46 Coding convention correction and warning removal
48 Revision 1.5 1999/09/29 09:24:29 fca
49 Introduction of the Copyright and cvs Log
53 ///////////////////////////////////////////////////////////////////////////////
55 // Base class for ALICE modules. Both sensitive modules (detectors) and //
56 // non-sensitive ones are described by this base class. This class //
57 // supports the hit and digit trees produced by the simulation and also //
58 // the objects produced by the reconstruction. //
60 // This class is also responsible for building the geometry of the //
65 <img src="picts/AliDetectorClass.gif">
69 ///////////////////////////////////////////////////////////////////////////////
80 #include "AliConfig.h"
81 #include "AliDetector.h"
84 #include "AliPoints.h"
86 // Static variables for the hit iterator routines
87 static Int_t sMaxIterHit=0;
88 static Int_t sCurIterHit=0;
92 //_____________________________________________________________________________
93 AliDetector::AliDetector()
96 // Default constructor for the AliDetector class
108 //_____________________________________________________________________________
109 AliDetector::AliDetector(const char* name,const char *title):AliModule(name,title)
112 // Normal constructor invoked by all Detectors.
113 // Create the list for detector specific histograms
114 // Add this Detector to the global list of Detectors in Run.
127 AliConfig::Instance()->Add(this);
130 //_____________________________________________________________________________
131 AliDetector::~AliDetector()
139 // Delete space point structure
145 // Delete digits structure
151 if (fDigitsFile) delete [] fDigitsFile;
154 //_____________________________________________________________________________
155 void AliDetector::Publish(const char *dir, void *address, const char *name)
158 // Register pointer to detector objects.
160 TFolder *topFolder = (TFolder *)gROOT->FindObjectAny("/Folders");
162 TFolder *folder = (TFolder *)topFolder->FindObjectAny(dir);
163 // TFolder *folder = (TFolder *)gROOT->FindObjectAny(dir);
165 cerr << "Cannot register: Missing folder: " << dir << endl;
167 TFolder *subfolder = (TFolder *) folder->FindObjectAny(this->GetName());
170 subfolder = folder->AddFolder(this->GetName(),this->GetTitle());
172 TObject **obj = (TObject **) address;
173 if ((*obj)->InheritsFrom(TCollection::Class())) {
174 TCollection *collection = (TCollection *) (*obj);
176 collection->SetName(name);
178 subfolder->Add(*obj);
184 //_____________________________________________________________________________
185 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, void* address, Int_t size,const char *file)
187 return(MakeBranchInTree(tree,name,0,address,size,99,file));
190 //_____________________________________________________________________________
191 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, const char *classname, void* address,Int_t size, Int_t splitlevel, const char *file)
194 // Makes branch in given tree and diverts them to a separate file
197 printf("* MakeBranch * Making Branch %s \n",name);
199 TDirectory *cwd = gDirectory;
203 branch = tree->Branch(name,classname,address,size,splitlevel);
205 branch = tree->Branch(name,address,size);
209 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
210 sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
211 branch->SetFile(outFile);
212 TIter next( branch->GetListOfBranches());
213 while ((branch=(TBranch*)next())) {
214 branch->SetFile(outFile);
221 printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
224 TString folderName(name);
226 if (!strncmp(tree->GetName(),"TreeE",5)) folder = "RunMC/Event/Data";
227 if (!strncmp(tree->GetName(),"TreeK",5)) folder = "RunMC/Event/Data";
228 if (!strncmp(tree->GetName(),"TreeH",5)) {
229 folder = "RunMC/Event/Data/Hits";
230 folderName = "Hits" ;
232 if (!strncmp(tree->GetName(),"TreeD",5)) {
233 folder = "Run/Event/Data";
234 folderName = "Digits" ;
236 if (!strncmp(tree->GetName(),"TreeS",5)) {
237 folder = "RunMC/Event/Data/SDigits";
238 folderName = "SDigits" ;
240 if (!strncmp(tree->GetName(),"TreeR",5)) folder = "Run/Event/RecData";
244 printf("%15s: Publishing %s to %s\n",ClassName(),name,folder);
245 Publish(folder,address, folderName.Data());
250 //_____________________________________________________________________________
251 void AliDetector::Browse(TBrowser *b)
254 // Insert Detector objects in the list of objects to be browsed
257 if( fHits == 0) return;
261 nobjects = fHits->GetEntries();
262 for (i=0;i<nobjects;i++) {
264 sprintf(name,"%s_%d",obj->GetName(),i);
265 b->Add(obj, &name[0]);
269 //_____________________________________________________________________________
270 void AliDetector::Copy(AliDetector &det) const
273 // Copy *this onto det -- not implemented
275 Fatal("Copy","Not implemented~\n");
278 //_____________________________________________________________________________
279 void AliDetector::FinishRun()
282 // Procedure called at the end of a run.
286 //_____________________________________________________________________________
287 AliHit* AliDetector::FirstHit(Int_t track)
290 // Initialise the hit iterator
291 // Return the address of the first hit for track
292 // If track>=0 the track is read from disk
293 // while if track<0 the first hit of the current
298 gAlice->TreeH()->GetEvent(track);
301 sMaxIterHit=fHits->GetEntriesFast();
303 if(sMaxIterHit) return (AliHit*) fHits->UncheckedAt(0);
307 //_____________________________________________________________________________
308 AliHit* AliDetector::NextHit()
311 // Return the next hit for the current track
314 if(++sCurIterHit<sMaxIterHit)
315 return (AliHit*) fHits->UncheckedAt(sCurIterHit);
319 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
324 //_____________________________________________________________________________
325 void AliDetector::LoadPoints(Int_t)
328 // Store x, y, z of all hits in memory
330 if (fHits == 0) return;
332 Int_t nhits = fHits->GetEntriesFast();
333 if (nhits == 0) return;
334 Int_t tracks = gAlice->GetNtrack();
335 if (fPoints == 0) fPoints = new TObjArray(tracks);
338 Int_t *ntrk=new Int_t[tracks];
339 Int_t *limi=new Int_t[tracks];
340 Float_t **coor=new Float_t*[tracks];
341 for(Int_t i=0;i<tracks;i++) {
347 AliPoints *points = 0;
350 Int_t chunk=nhits/4+1;
352 // Loop over all the hits and store their position
353 for (Int_t hit=0;hit<nhits;hit++) {
354 ahit = (AliHit*)fHits->UncheckedAt(hit);
355 trk=ahit->GetTrack();
357 if(ntrk[trk]==limi[trk]) {
359 // Initialise a new track
360 fp=new Float_t[3*(limi[trk]+chunk)];
362 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
370 fp[3*ntrk[trk] ] = ahit->X();
371 fp[3*ntrk[trk]+1] = ahit->Y();
372 fp[3*ntrk[trk]+2] = ahit->Z();
376 for(trk=0; trk<tracks; ++trk) {
378 points = new AliPoints();
379 points->SetMarkerColor(GetMarkerColor());
380 points->SetMarkerSize(GetMarkerSize());
381 points->SetDetector(this);
382 points->SetParticle(trk);
383 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
384 fPoints->AddAt(points,trk);
394 //_____________________________________________________________________________
395 void AliDetector::MakeBranch(Option_t *option, const char *file)
398 // Create a new branch in the current Root Tree
399 // The branch of fHits is automatically split
403 sprintf(branchname,"%s",GetName());
405 // Get the pointer to the header
406 const char *cH = strstr(option,"H");
408 if (fHits && gAlice->TreeH() && cH) {
409 MakeBranchInTree(gAlice->TreeH(),
410 branchname, &fHits, fBufferSize, file) ;
413 const char *cD = strstr(option,"D");
417 fDigitsFile = new char[strlen (file)];
418 strcpy(fDigitsFile,file);
423 //_____________________________________________________________________________
424 void AliDetector::ResetDigits()
427 // Reset number of digits and the digits array
430 if (fDigits) fDigits->Clear();
433 //_____________________________________________________________________________
434 void AliDetector::ResetHits()
437 // Reset number of hits and the hits array
440 if (fHits) fHits->Clear();
443 //_____________________________________________________________________________
444 void AliDetector::ResetPoints()
447 // Reset array of points
456 //_____________________________________________________________________________
457 void AliDetector::SetTreeAddress()
460 // Set branch address for the Hits and Digits Trees
464 sprintf(branchname,"%s",GetName());
466 // Branch address for hit tree
467 TTree *treeH = gAlice->TreeH();
468 if (treeH && fHits) {
469 branch = treeH->GetBranch(branchname);
470 if (branch) branch->SetAddress(&fHits);
473 // Branch address for digit tree
474 TTree *treeD = gAlice->TreeD();
475 if (treeD && fDigits) {
476 branch = treeD->GetBranch(branchname);
477 if (branch) branch->SetAddress(&fDigits);