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.22 2002/10/23 07:43:00 alibrary
19 Introducing some effective C++ suggestions
21 Revision 1.21 2002/10/22 15:02:15 alibrary
22 Introducing Riostream.h
24 Revision 1.20 2002/10/14 14:57:32 hristov
25 Merging the VirtualMC branch to the main development branch (HEAD)
27 Revision 1.16.8.3 2002/10/14 09:45:57 hristov
28 Updating VirtualMC to v3-09-02
30 Revision 1.19 2002/09/23 09:19:54 hristov
31 FirsTrackReference updated (M.Ivanov)
33 Revision 1.18 2002/08/26 13:51:17 hristov
34 Remaping of track references at the end of each primary particle (M.Ivanov)
36 Revision 1.17 2002/05/24 13:29:58 hristov
37 AliTrackReference added, AliDisplay modified
39 Revision 1.16 2001/10/04 15:30:56 hristov
40 Changes to accommodate the set of PHOS folders and tasks (Y.Schutz)
42 Revision 1.15 2001/07/27 13:03:13 hristov
43 Default Branch split level set to 99
45 Revision 1.14 2001/05/21 17:22:51 buncic
46 Fixed problem with missing AliConfig while reading galice.root
48 Revision 1.13 2001/05/16 14:57:22 alibrary
49 New files for folders and Stack
51 Revision 1.12 2001/03/12 17:47:03 hristov
52 Changes needed on Sun with CC 5.0
54 Revision 1.11 2001/01/26 19:58:46 hristov
55 Major upgrade of AliRoot code
57 Revision 1.10 2001/01/17 10:50:50 hristov
58 Corrections to destructors
60 Revision 1.9 2000/12/12 18:19:06 alibrary
61 Introduce consistency check when loading points
63 Revision 1.8 2000/11/30 07:12:48 alibrary
64 Introducing new Rndm and QA classes
66 Revision 1.7 2000/10/02 21:28:14 fca
67 Removal of useless dependecies via forward declarations
69 Revision 1.6 2000/07/12 08:56:25 fca
70 Coding convention correction and warning removal
72 Revision 1.5 1999/09/29 09:24:29 fca
73 Introduction of the Copyright and cvs Log
77 ///////////////////////////////////////////////////////////////////////////////
79 // Base class for ALICE modules. Both sensitive modules (detectors) and //
80 // non-sensitive ones are described by this base class. This class //
81 // supports the hit and digit trees produced by the simulation and also //
82 // the objects produced by the reconstruction. //
84 // This class is also responsible for building the geometry of the //
89 <img src="picts/AliDetectorClass.gif">
93 ///////////////////////////////////////////////////////////////////////////////
102 #include <Riostream.h>
104 #include "AliConfig.h"
105 #include "AliDetector.h"
107 #include "AliPoints.h"
109 #include "AliTrackReference.h"
112 // Static variables for the hit iterator routines
113 static Int_t sMaxIterHit=0;
114 static Int_t sCurIterHit=0;
117 ClassImp(AliDetector)
119 //_______________________________________________________________________
120 AliDetector::AliDetector():
132 fCurrentIterTrackRef(0)
135 // Default constructor for the AliDetector class
139 //_______________________________________________________________________
140 AliDetector::AliDetector(const AliDetector &det):
153 fCurrentIterTrackRef(0)
158 //_____________________________________________________________________________
159 AliDetector::AliDetector(const char* name,const char *title):
160 AliModule(name,title),
170 fTrackReferences(new TClonesArray("AliTrackReference", 100)),
172 fCurrentIterTrackRef(0)
175 // Normal constructor invoked by all Detectors.
176 // Create the list for detector specific histograms
177 // Add this Detector to the global list of Detectors in Run.
181 AliConfig::Instance()->Add(this);
185 //_______________________________________________________________________
186 AliDetector::~AliDetector()
192 // Delete space point structure
198 // Delete digits structure
204 if (fDigitsFile) delete [] fDigitsFile;
207 //_______________________________________________________________________
208 void AliDetector::Publish(const char *dir, void *address, const char *name)
211 // Register pointer to detector objects.
213 TFolder *topFolder = dynamic_cast<TFolder *>(gROOT->FindObjectAny("/Folders"));
215 TFolder *folder = dynamic_cast<TFolder *>(topFolder->FindObjectAny(dir));
216 // TFolder *folder = dynamic_cast<TFolder *>(gROOT->FindObjectAny(dir));
218 cerr << "Cannot register: Missing folder: " << dir << endl;
220 TFolder *subfolder = dynamic_cast<TFolder *>(folder->FindObjectAny(this->GetName()));
223 subfolder = folder->AddFolder(this->GetName(),this->GetTitle());
225 TObject **obj = static_cast<TObject **>(address);
226 if ((*obj)->InheritsFrom(TCollection::Class())) {
227 TCollection *collection = dynamic_cast<TCollection *>(*obj);
229 collection->SetName(name);
231 subfolder->Add(*obj);
237 //_______________________________________________________________________
238 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
239 void* address, Int_t size,
242 return(MakeBranchInTree(tree,name,0,address,size,99,file));
245 //_______________________________________________________________________
246 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
247 const char *classname,
248 void* address,Int_t size,
249 Int_t splitlevel, const char *file)
252 // Makes branch in given tree and diverts them to a separate file
255 printf("* MakeBranch * Making Branch %s \n",name);
257 TDirectory *cwd = gDirectory;
261 branch = tree->Branch(name,classname,address,size,splitlevel);
263 branch = tree->Branch(name,address,size);
267 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
268 sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
269 branch->SetFile(outFile);
270 TIter next( branch->GetListOfBranches());
271 while ((branch=dynamic_cast<TBranch*>(next()))) {
272 branch->SetFile(outFile);
279 printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
281 const char *folder = 0;
282 TString folderName(name);
284 if (!strncmp(tree->GetName(),"TreeE",5)) folder = "RunMC/Event/Data";
285 if (!strncmp(tree->GetName(),"TreeK",5)) folder = "RunMC/Event/Data";
286 if (!strncmp(tree->GetName(),"TreeH",5)) {
287 folder = "RunMC/Event/Data/Hits";
288 folderName = "Hits" ;
290 if (!strncmp(tree->GetName(),"TreeTrackReferences",5)) {
291 folder = "RunMC/Event/Data/TrackReferences";
292 folderName = "TrackReferences" ;
295 if (!strncmp(tree->GetName(),"TreeD",5)) {
296 folder = "Run/Event/Data";
297 folderName = "Digits" ;
299 if (!strncmp(tree->GetName(),"TreeS",5)) {
300 folder = "RunMC/Event/Data/SDigits";
301 folderName = "SDigits" ;
303 if (!strncmp(tree->GetName(),"TreeR",5)) folder = "Run/Event/RecData";
307 printf("%15s: Publishing %s to %s\n",ClassName(),name,folder);
308 Publish(folder,address, folderName.Data());
313 //_______________________________________________________________________
314 void AliDetector::Browse(TBrowser *b)
317 // Insert Detector objects in the list of objects to be browsed
320 if( fHits == 0) return;
324 nobjects = fHits->GetEntries();
325 for (i=0;i<nobjects;i++) {
327 sprintf(name,"%s_%d",obj->GetName(),i);
328 b->Add(obj, &name[0]);
332 //_______________________________________________________________________
333 void AliDetector::Copy(AliDetector &) const
336 // Copy *this onto det -- not implemented
338 Fatal("Copy","Not implemented\n");
341 //_______________________________________________________________________
342 void AliDetector::FinishRun()
345 // Procedure called at the end of a run.
349 //_______________________________________________________________________
350 void AliDetector::RemapTrackReferencesIDs(Int_t *map)
353 // Remapping track reference
354 // Called at finish primary
356 if (!fTrackReferences) return;
357 for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
358 AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(i));
360 Int_t newID = map[ref->GetTrack()];
361 if (newID>=0) ref->SetTrack(newID);
362 else ref->SetTrack(-1);
368 //_______________________________________________________________________
369 AliHit* AliDetector::FirstHit(Int_t track)
372 // Initialise the hit iterator
373 // Return the address of the first hit for track
374 // If track>=0 the track is read from disk
375 // while if track<0 the first hit of the current
380 gAlice->TreeH()->GetEvent(track);
383 sMaxIterHit=fHits->GetEntriesFast();
385 if(sMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
390 //_______________________________________________________________________
391 AliTrackReference* AliDetector::FirstTrackReference(Int_t track)
394 // Initialise the hit iterator
395 // Return the address of the first hit for track
396 // If track>=0 the track is read from disk
397 // while if track<0 the first hit of the current
401 gAlice->ResetTrackReferences();
402 gAlice->TreeTR()->GetEvent(track);
405 fMaxIterTrackRef = fTrackReferences->GetEntriesFast();
406 fCurrentIterTrackRef = 0;
407 if(fMaxIterTrackRef) return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(0));
411 //_______________________________________________________________________
412 AliHit* AliDetector::NextHit()
415 // Return the next hit for the current track
418 if(++sCurIterHit<sMaxIterHit)
419 return dynamic_cast<AliHit*>(fHits->UncheckedAt(sCurIterHit));
423 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
428 //_______________________________________________________________________
429 AliTrackReference* AliDetector::NextTrackReference()
432 // Return the next hit for the current track
434 if(fMaxIterTrackRef) {
435 if(++fCurrentIterTrackRef<fMaxIterTrackRef)
436 return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(fCurrentIterTrackRef));
440 printf("* AliDetector::NextTrackReference * TrackReference Iterator called without calling FistTrackReference before\n");
445 //_______________________________________________________________________
446 void AliDetector::LoadPoints(Int_t)
449 // Store x, y, z of all hits in memory
451 if (fHits == 0) return;
453 Int_t nhits = fHits->GetEntriesFast();
454 if (nhits == 0) return;
455 Int_t tracks = gAlice->GetNtrack();
456 if (fPoints == 0) fPoints = new TObjArray(tracks);
459 Int_t *ntrk=new Int_t[tracks];
460 Int_t *limi=new Int_t[tracks];
461 Float_t **coor=new Float_t*[tracks];
462 for(Int_t i=0;i<tracks;i++) {
468 AliPoints *points = 0;
471 Int_t chunk=nhits/4+1;
473 // Loop over all the hits and store their position
474 for (Int_t hit=0;hit<nhits;hit++) {
475 ahit = dynamic_cast<AliHit*>(fHits->UncheckedAt(hit));
476 trk=ahit->GetTrack();
478 if(ntrk[trk]==limi[trk]) {
480 // Initialise a new track
481 fp=new Float_t[3*(limi[trk]+chunk)];
483 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
491 fp[3*ntrk[trk] ] = ahit->X();
492 fp[3*ntrk[trk]+1] = ahit->Y();
493 fp[3*ntrk[trk]+2] = ahit->Z();
497 for(trk=0; trk<tracks; ++trk) {
499 points = new AliPoints();
500 points->SetMarkerColor(GetMarkerColor());
501 points->SetMarkerSize(GetMarkerSize());
502 points->SetDetector(this);
503 points->SetParticle(trk);
504 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
505 fPoints->AddAt(points,trk);
515 //_______________________________________________________________________
516 void AliDetector::MakeBranch(Option_t *option, const char *file)
519 // Create a new branch in the current Root Tree
520 // The branch of fHits is automatically split
524 sprintf(branchname,"%s",GetName());
526 // Get the pointer to the header
527 const char *cH = strstr(option,"H");
529 if (fHits && gAlice->TreeH() && cH) {
530 MakeBranchInTree(gAlice->TreeH(),
531 branchname, &fHits, fBufferSize, file) ;
534 const char *cD = strstr(option,"D");
538 fDigitsFile = new char[strlen (file)];
539 strcpy(fDigitsFile,file);
543 //_______________________________________________________________________
544 void AliDetector::MakeBranchTR(Option_t *option, const char *file)
547 // Create a new branch in the current Root Tree
548 // The branch of fHits is automatically split
552 sprintf(branchname,"%s",GetName());
554 // Get the pointer to the header
555 const char *cTR = strstr(option,"T");
557 if (fTrackReferences && gAlice->TreeTR() && cTR) {
558 MakeBranchInTree(gAlice->TreeTR(),
559 branchname, &fTrackReferences, fBufferSize, file) ;
563 //_______________________________________________________________________
564 void AliDetector::ResetDigits()
567 // Reset number of digits and the digits array
570 if (fDigits) fDigits->Clear();
573 //_______________________________________________________________________
574 void AliDetector::ResetHits()
577 // Reset number of hits and the hits array
580 if (fHits) fHits->Clear();
583 //_______________________________________________________________________
584 void AliDetector::ResetTrackReferences()
587 // Reset number of hits and the hits array
589 fMaxIterTrackRef = 0;
590 if (fTrackReferences) fTrackReferences->Clear();
593 //_______________________________________________________________________
594 void AliDetector::ResetPoints()
597 // Reset array of points
606 //_______________________________________________________________________
607 void AliDetector::SetTreeAddress()
610 // Set branch address for the Hits and Digits Trees
614 sprintf(branchname,"%s",GetName());
616 // Branch address for hit tree
617 TTree *treeH = gAlice->TreeH();
618 if (treeH && fHits) {
619 branch = treeH->GetBranch(branchname);
620 if (branch) branch->SetAddress(&fHits);
623 // Branch address for digit tree
624 TTree *treeD = gAlice->TreeD();
625 if (treeD && fDigits) {
626 branch = treeD->GetBranch(branchname);
627 if (branch) branch->SetAddress(&fDigits);
630 // Branch address for tr tree
631 TTree *treeTR = gAlice->TreeTR();
632 if (treeTR && fTrackReferences) {
633 branch = treeTR->GetBranch(branchname);
634 if (branch) branch->SetAddress(&fTrackReferences);