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.21 2002/10/22 15:02:15 alibrary
19 Introducing Riostream.h
21 Revision 1.20 2002/10/14 14:57:32 hristov
22 Merging the VirtualMC branch to the main development branch (HEAD)
24 Revision 1.16.8.3 2002/10/14 09:45:57 hristov
25 Updating VirtualMC to v3-09-02
27 Revision 1.19 2002/09/23 09:19:54 hristov
28 FirsTrackReference updated (M.Ivanov)
30 Revision 1.18 2002/08/26 13:51:17 hristov
31 Remaping of track references at the end of each primary particle (M.Ivanov)
33 Revision 1.17 2002/05/24 13:29:58 hristov
34 AliTrackReference added, AliDisplay modified
36 Revision 1.16 2001/10/04 15:30:56 hristov
37 Changes to accommodate the set of PHOS folders and tasks (Y.Schutz)
39 Revision 1.15 2001/07/27 13:03:13 hristov
40 Default Branch split level set to 99
42 Revision 1.14 2001/05/21 17:22:51 buncic
43 Fixed problem with missing AliConfig while reading galice.root
45 Revision 1.13 2001/05/16 14:57:22 alibrary
46 New files for folders and Stack
48 Revision 1.12 2001/03/12 17:47:03 hristov
49 Changes needed on Sun with CC 5.0
51 Revision 1.11 2001/01/26 19:58:46 hristov
52 Major upgrade of AliRoot code
54 Revision 1.10 2001/01/17 10:50:50 hristov
55 Corrections to destructors
57 Revision 1.9 2000/12/12 18:19:06 alibrary
58 Introduce consistency check when loading points
60 Revision 1.8 2000/11/30 07:12:48 alibrary
61 Introducing new Rndm and QA classes
63 Revision 1.7 2000/10/02 21:28:14 fca
64 Removal of useless dependecies via forward declarations
66 Revision 1.6 2000/07/12 08:56:25 fca
67 Coding convention correction and warning removal
69 Revision 1.5 1999/09/29 09:24:29 fca
70 Introduction of the Copyright and cvs Log
74 ///////////////////////////////////////////////////////////////////////////////
76 // Base class for ALICE modules. Both sensitive modules (detectors) and //
77 // non-sensitive ones are described by this base class. This class //
78 // supports the hit and digit trees produced by the simulation and also //
79 // the objects produced by the reconstruction. //
81 // This class is also responsible for building the geometry of the //
86 <img src="picts/AliDetectorClass.gif">
90 ///////////////////////////////////////////////////////////////////////////////
99 #include <Riostream.h>
101 #include "AliConfig.h"
102 #include "AliDetector.h"
104 #include "AliPoints.h"
106 #include "AliTrackReference.h"
109 // Static variables for the hit iterator routines
110 static Int_t sMaxIterHit=0;
111 static Int_t sCurIterHit=0;
114 ClassImp(AliDetector)
116 //_______________________________________________________________________
117 AliDetector::AliDetector():
129 fCurrentIterTrackRef(0)
132 // Default constructor for the AliDetector class
136 //_____________________________________________________________________________
137 AliDetector::AliDetector(const char* name,const char *title):
138 AliModule(name,title),
148 fTrackReferences(new TClonesArray("AliTrackReference", 100)),
150 fCurrentIterTrackRef(0)
153 // Normal constructor invoked by all Detectors.
154 // Create the list for detector specific histograms
155 // Add this Detector to the global list of Detectors in Run.
159 AliConfig::Instance()->Add(this);
163 //_______________________________________________________________________
164 AliDetector::~AliDetector()
170 // Delete space point structure
176 // Delete digits structure
182 if (fDigitsFile) delete [] fDigitsFile;
185 //_______________________________________________________________________
186 void AliDetector::Publish(const char *dir, void *address, const char *name)
189 // Register pointer to detector objects.
191 TFolder *topFolder = (TFolder *)gROOT->FindObjectAny("/Folders");
193 TFolder *folder = (TFolder *)topFolder->FindObjectAny(dir);
194 // TFolder *folder = (TFolder *)gROOT->FindObjectAny(dir);
196 cerr << "Cannot register: Missing folder: " << dir << endl;
198 TFolder *subfolder = (TFolder *) folder->FindObjectAny(this->GetName());
201 subfolder = folder->AddFolder(this->GetName(),this->GetTitle());
203 TObject **obj = (TObject **) address;
204 if ((*obj)->InheritsFrom(TCollection::Class())) {
205 TCollection *collection = (TCollection *) (*obj);
207 collection->SetName(name);
209 subfolder->Add(*obj);
215 //_______________________________________________________________________
216 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
217 void* address, Int_t size,
220 return(MakeBranchInTree(tree,name,0,address,size,99,file));
223 //_______________________________________________________________________
224 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
225 const char *classname,
226 void* address,Int_t size,
227 Int_t splitlevel, const char *file)
230 // Makes branch in given tree and diverts them to a separate file
233 printf("* MakeBranch * Making Branch %s \n",name);
235 TDirectory *cwd = gDirectory;
239 branch = tree->Branch(name,classname,address,size,splitlevel);
241 branch = tree->Branch(name,address,size);
245 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
246 sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
247 branch->SetFile(outFile);
248 TIter next( branch->GetListOfBranches());
249 while ((branch=(TBranch*)next())) {
250 branch->SetFile(outFile);
257 printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
260 TString folderName(name);
262 if (!strncmp(tree->GetName(),"TreeE",5)) folder = "RunMC/Event/Data";
263 if (!strncmp(tree->GetName(),"TreeK",5)) folder = "RunMC/Event/Data";
264 if (!strncmp(tree->GetName(),"TreeH",5)) {
265 folder = "RunMC/Event/Data/Hits";
266 folderName = "Hits" ;
268 if (!strncmp(tree->GetName(),"TreeTrackReferences",5)) {
269 folder = "RunMC/Event/Data/TrackReferences";
270 folderName = "TrackReferences" ;
273 if (!strncmp(tree->GetName(),"TreeD",5)) {
274 folder = "Run/Event/Data";
275 folderName = "Digits" ;
277 if (!strncmp(tree->GetName(),"TreeS",5)) {
278 folder = "RunMC/Event/Data/SDigits";
279 folderName = "SDigits" ;
281 if (!strncmp(tree->GetName(),"TreeR",5)) folder = "Run/Event/RecData";
285 printf("%15s: Publishing %s to %s\n",ClassName(),name,folder);
286 Publish(folder,address, folderName.Data());
291 //_______________________________________________________________________
292 void AliDetector::Browse(TBrowser *b)
295 // Insert Detector objects in the list of objects to be browsed
298 if( fHits == 0) return;
302 nobjects = fHits->GetEntries();
303 for (i=0;i<nobjects;i++) {
305 sprintf(name,"%s_%d",obj->GetName(),i);
306 b->Add(obj, &name[0]);
310 //_______________________________________________________________________
311 void AliDetector::Copy(AliDetector &det) const
314 // Copy *this onto det -- not implemented
316 Fatal("Copy","Not implemented~\n");
319 //_______________________________________________________________________
320 void AliDetector::FinishRun()
323 // Procedure called at the end of a run.
327 //_______________________________________________________________________
328 void AliDetector::RemapTrackReferencesIDs(Int_t *map)
331 // Remapping track reference
332 // Called at finish primary
334 if (!fTrackReferences) return;
335 for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
336 AliTrackReference * ref = (AliTrackReference*) fTrackReferences->UncheckedAt(i);
338 Int_t newID = map[ref->GetTrack()];
339 if (newID>=0) ref->SetTrack(newID);
340 else ref->SetTrack(-1);
346 //_______________________________________________________________________
347 AliHit* AliDetector::FirstHit(Int_t track)
350 // Initialise the hit iterator
351 // Return the address of the first hit for track
352 // If track>=0 the track is read from disk
353 // while if track<0 the first hit of the current
358 gAlice->TreeH()->GetEvent(track);
361 sMaxIterHit=fHits->GetEntriesFast();
363 if(sMaxIterHit) return (AliHit*) fHits->UncheckedAt(0);
368 //_______________________________________________________________________
369 AliTrackReference* AliDetector::FirstTrackReference(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
379 gAlice->ResetTrackReferences();
380 gAlice->TreeTR()->GetEvent(track);
383 fMaxIterTrackRef = fTrackReferences->GetEntriesFast();
384 fCurrentIterTrackRef = 0;
385 if(fMaxIterTrackRef) return (AliTrackReference*) fTrackReferences->UncheckedAt(0);
389 //_______________________________________________________________________
390 AliHit* AliDetector::NextHit()
393 // Return the next hit for the current track
396 if(++sCurIterHit<sMaxIterHit)
397 return (AliHit*) fHits->UncheckedAt(sCurIterHit);
401 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
406 //_______________________________________________________________________
407 AliTrackReference* AliDetector::NextTrackReference()
410 // Return the next hit for the current track
412 if(fMaxIterTrackRef) {
413 if(++fCurrentIterTrackRef<fMaxIterTrackRef)
414 return (AliTrackReference*) fTrackReferences->UncheckedAt(fCurrentIterTrackRef);
418 printf("* AliDetector::NextTrackReference * TrackReference Iterator called without calling FistTrackReference before\n");
423 //_______________________________________________________________________
424 void AliDetector::LoadPoints(Int_t)
427 // Store x, y, z of all hits in memory
429 if (fHits == 0) return;
431 Int_t nhits = fHits->GetEntriesFast();
432 if (nhits == 0) return;
433 Int_t tracks = gAlice->GetNtrack();
434 if (fPoints == 0) fPoints = new TObjArray(tracks);
437 Int_t *ntrk=new Int_t[tracks];
438 Int_t *limi=new Int_t[tracks];
439 Float_t **coor=new Float_t*[tracks];
440 for(Int_t i=0;i<tracks;i++) {
446 AliPoints *points = 0;
449 Int_t chunk=nhits/4+1;
451 // Loop over all the hits and store their position
452 for (Int_t hit=0;hit<nhits;hit++) {
453 ahit = (AliHit*)fHits->UncheckedAt(hit);
454 trk=ahit->GetTrack();
456 if(ntrk[trk]==limi[trk]) {
458 // Initialise a new track
459 fp=new Float_t[3*(limi[trk]+chunk)];
461 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
469 fp[3*ntrk[trk] ] = ahit->X();
470 fp[3*ntrk[trk]+1] = ahit->Y();
471 fp[3*ntrk[trk]+2] = ahit->Z();
475 for(trk=0; trk<tracks; ++trk) {
477 points = new AliPoints();
478 points->SetMarkerColor(GetMarkerColor());
479 points->SetMarkerSize(GetMarkerSize());
480 points->SetDetector(this);
481 points->SetParticle(trk);
482 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
483 fPoints->AddAt(points,trk);
493 //_______________________________________________________________________
494 void AliDetector::MakeBranch(Option_t *option, const char *file)
497 // Create a new branch in the current Root Tree
498 // The branch of fHits is automatically split
502 sprintf(branchname,"%s",GetName());
504 // Get the pointer to the header
505 const char *cH = strstr(option,"H");
507 if (fHits && gAlice->TreeH() && cH) {
508 MakeBranchInTree(gAlice->TreeH(),
509 branchname, &fHits, fBufferSize, file) ;
512 const char *cD = strstr(option,"D");
516 fDigitsFile = new char[strlen (file)];
517 strcpy(fDigitsFile,file);
521 //_______________________________________________________________________
522 void AliDetector::MakeBranchTR(Option_t *option, const char *file)
525 // Create a new branch in the current Root Tree
526 // The branch of fHits is automatically split
530 sprintf(branchname,"%s",GetName());
532 // Get the pointer to the header
533 const char *cTR = strstr(option,"T");
535 if (fTrackReferences && gAlice->TreeTR() && cTR) {
536 MakeBranchInTree(gAlice->TreeTR(),
537 branchname, &fTrackReferences, fBufferSize, file) ;
541 //_______________________________________________________________________
542 void AliDetector::ResetDigits()
545 // Reset number of digits and the digits array
548 if (fDigits) fDigits->Clear();
551 //_______________________________________________________________________
552 void AliDetector::ResetHits()
555 // Reset number of hits and the hits array
558 if (fHits) fHits->Clear();
561 //_______________________________________________________________________
562 void AliDetector::ResetTrackReferences()
565 // Reset number of hits and the hits array
567 fMaxIterTrackRef = 0;
568 if (fTrackReferences) fTrackReferences->Clear();
571 //_______________________________________________________________________
572 void AliDetector::ResetPoints()
575 // Reset array of points
584 //_______________________________________________________________________
585 void AliDetector::SetTreeAddress()
588 // Set branch address for the Hits and Digits Trees
592 sprintf(branchname,"%s",GetName());
594 // Branch address for hit tree
595 TTree *treeH = gAlice->TreeH();
596 if (treeH && fHits) {
597 branch = treeH->GetBranch(branchname);
598 if (branch) branch->SetAddress(&fHits);
601 // Branch address for digit tree
602 TTree *treeD = gAlice->TreeD();
603 if (treeD && fDigits) {
604 branch = treeD->GetBranch(branchname);
605 if (branch) branch->SetAddress(&fDigits);
608 // Branch address for tr tree
609 TTree *treeTR = gAlice->TreeTR();
610 if (treeTR && fTrackReferences) {
611 branch = treeTR->GetBranch(branchname);
612 if (branch) branch->SetAddress(&fTrackReferences);