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.17 2002/05/24 13:29:58 hristov
19 AliTrackReference added, AliDisplay modified
21 Revision 1.16 2001/10/04 15:30:56 hristov
22 Changes to accommodate the set of PHOS folders and tasks (Y.Schutz)
24 Revision 1.15 2001/07/27 13:03:13 hristov
25 Default Branch split level set to 99
27 Revision 1.14 2001/05/21 17:22:51 buncic
28 Fixed problem with missing AliConfig while reading galice.root
30 Revision 1.13 2001/05/16 14:57:22 alibrary
31 New files for folders and Stack
33 Revision 1.12 2001/03/12 17:47:03 hristov
34 Changes needed on Sun with CC 5.0
36 Revision 1.11 2001/01/26 19:58:46 hristov
37 Major upgrade of AliRoot code
39 Revision 1.10 2001/01/17 10:50:50 hristov
40 Corrections to destructors
42 Revision 1.9 2000/12/12 18:19:06 alibrary
43 Introduce consistency check when loading points
45 Revision 1.8 2000/11/30 07:12:48 alibrary
46 Introducing new Rndm and QA classes
48 Revision 1.7 2000/10/02 21:28:14 fca
49 Removal of useless dependecies via forward declarations
51 Revision 1.6 2000/07/12 08:56:25 fca
52 Coding convention correction and warning removal
54 Revision 1.5 1999/09/29 09:24:29 fca
55 Introduction of the Copyright and cvs Log
59 ///////////////////////////////////////////////////////////////////////////////
61 // Base class for ALICE modules. Both sensitive modules (detectors) and //
62 // non-sensitive ones are described by this base class. This class //
63 // supports the hit and digit trees produced by the simulation and also //
64 // the objects produced by the reconstruction. //
66 // This class is also responsible for building the geometry of the //
71 <img src="picts/AliDetectorClass.gif">
75 ///////////////////////////////////////////////////////////////////////////////
86 #include "AliConfig.h"
87 #include "AliDetector.h"
90 #include "AliPoints.h"
91 #include "AliTrackReference.h"
94 // Static variables for the hit iterator routines
95 static Int_t sMaxIterHit=0;
96 static Int_t sCurIterHit=0;
101 //_____________________________________________________________________________
102 AliDetector::AliDetector()
105 // Default constructor for the AliDetector class
118 //_____________________________________________________________________________
119 AliDetector::AliDetector(const char* name,const char *title):AliModule(name,title)
122 // Normal constructor invoked by all Detectors.
123 // Create the list for detector specific histograms
124 // Add this Detector to the global list of Detectors in Run.
138 AliConfig::Instance()->Add(this);
140 fTrackReferences = new TClonesArray("AliTrackReference", 100);
141 //if detector to want to create another track reference - than let's be free
145 //_____________________________________________________________________________
146 AliDetector::~AliDetector()
154 // Delete space point structure
160 // Delete digits structure
166 if (fDigitsFile) delete [] fDigitsFile;
169 //_____________________________________________________________________________
170 void AliDetector::Publish(const char *dir, void *address, const char *name)
173 // Register pointer to detector objects.
175 TFolder *topFolder = (TFolder *)gROOT->FindObjectAny("/Folders");
177 TFolder *folder = (TFolder *)topFolder->FindObjectAny(dir);
178 // TFolder *folder = (TFolder *)gROOT->FindObjectAny(dir);
180 cerr << "Cannot register: Missing folder: " << dir << endl;
182 TFolder *subfolder = (TFolder *) folder->FindObjectAny(this->GetName());
185 subfolder = folder->AddFolder(this->GetName(),this->GetTitle());
187 TObject **obj = (TObject **) address;
188 if ((*obj)->InheritsFrom(TCollection::Class())) {
189 TCollection *collection = (TCollection *) (*obj);
191 collection->SetName(name);
193 subfolder->Add(*obj);
199 //_____________________________________________________________________________
200 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, void* address, Int_t size,const char *file)
202 return(MakeBranchInTree(tree,name,0,address,size,99,file));
205 //_____________________________________________________________________________
206 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, const char *classname, void* address,Int_t size, Int_t splitlevel, const char *file)
209 // Makes branch in given tree and diverts them to a separate file
212 printf("* MakeBranch * Making Branch %s \n",name);
214 TDirectory *cwd = gDirectory;
218 branch = tree->Branch(name,classname,address,size,splitlevel);
220 branch = tree->Branch(name,address,size);
224 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
225 sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
226 branch->SetFile(outFile);
227 TIter next( branch->GetListOfBranches());
228 while ((branch=(TBranch*)next())) {
229 branch->SetFile(outFile);
236 printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
239 TString folderName(name);
241 if (!strncmp(tree->GetName(),"TreeE",5)) folder = "RunMC/Event/Data";
242 if (!strncmp(tree->GetName(),"TreeK",5)) folder = "RunMC/Event/Data";
243 if (!strncmp(tree->GetName(),"TreeH",5)) {
244 folder = "RunMC/Event/Data/Hits";
245 folderName = "Hits" ;
247 if (!strncmp(tree->GetName(),"TreeTrackReferences",5)) {
248 folder = "RunMC/Event/Data/TrackReferences";
249 folderName = "TrackReferences" ;
252 if (!strncmp(tree->GetName(),"TreeD",5)) {
253 folder = "Run/Event/Data";
254 folderName = "Digits" ;
256 if (!strncmp(tree->GetName(),"TreeS",5)) {
257 folder = "RunMC/Event/Data/SDigits";
258 folderName = "SDigits" ;
260 if (!strncmp(tree->GetName(),"TreeR",5)) folder = "Run/Event/RecData";
264 printf("%15s: Publishing %s to %s\n",ClassName(),name,folder);
265 Publish(folder,address, folderName.Data());
270 //_____________________________________________________________________________
271 void AliDetector::Browse(TBrowser *b)
274 // Insert Detector objects in the list of objects to be browsed
277 if( fHits == 0) return;
281 nobjects = fHits->GetEntries();
282 for (i=0;i<nobjects;i++) {
284 sprintf(name,"%s_%d",obj->GetName(),i);
285 b->Add(obj, &name[0]);
289 //_____________________________________________________________________________
290 void AliDetector::Copy(AliDetector &det) const
293 // Copy *this onto det -- not implemented
295 Fatal("Copy","Not implemented~\n");
298 //_____________________________________________________________________________
299 void AliDetector::FinishRun()
302 // Procedure called at the end of a run.
308 void AliDetector::RemapTrackReferencesIDs(Int_t *map)
311 //remaping track reference
312 //called at finish primary
313 if (!fTrackReferences) return;
314 for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
315 AliTrackReference * ref = (AliTrackReference*) fTrackReferences->UncheckedAt(i);
317 Int_t newID = map[ref->GetTrack()];
318 if (newID>=0) ref->SetTrack(newID);
319 else ref->SetTrack(-1);
325 //_____________________________________________________________________________
326 AliHit* AliDetector::FirstHit(Int_t track)
329 // Initialise the hit iterator
330 // Return the address of the first hit for track
331 // If track>=0 the track is read from disk
332 // while if track<0 the first hit of the current
337 gAlice->TreeH()->GetEvent(track);
340 sMaxIterHit=fHits->GetEntriesFast();
342 if(sMaxIterHit) return (AliHit*) fHits->UncheckedAt(0);
347 //_____________________________________________________________________________
348 AliTrackReference* AliDetector::FirstTrackReference(Int_t track)
351 // Initialise the hit iterator
352 // Return the address of the first hit for track
353 // If track>=0 the track is read from disk
354 // while if track<0 the first hit of the current
358 gAlice->ResetTrackReferences();
359 gAlice->TreeTR()->GetEvent(track);
362 sMaxIterHit=fTrackReferences->GetEntriesFast();
364 if(sMaxIterHit) return (AliTrackReference*) fTrackReferences->UncheckedAt(0);
370 //_____________________________________________________________________________
371 AliHit* AliDetector::NextHit()
374 // Return the next hit for the current track
377 if(++sCurIterHit<sMaxIterHit)
378 return (AliHit*) fHits->UncheckedAt(sCurIterHit);
382 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
386 //_____________________________________________________________________________
387 AliTrackReference* AliDetector::NextTrackReference()
390 // Return the next hit for the current track
392 if(fMaxIterTrackRef) {
393 if(++fCurrentIterTrackRef<fMaxIterTrackRef)
394 return (AliTrackReference*) fTrackReferences->UncheckedAt(fCurrentIterTrackRef);
398 printf("* AliDetector::NextTrackReference * TrackReference Iterator called without calling FistTrackReference before\n");
403 //_____________________________________________________________________________
404 void AliDetector::LoadPoints(Int_t)
407 // Store x, y, z of all hits in memory
409 if (fHits == 0) return;
411 Int_t nhits = fHits->GetEntriesFast();
412 if (nhits == 0) return;
413 Int_t tracks = gAlice->GetNtrack();
414 if (fPoints == 0) fPoints = new TObjArray(tracks);
417 Int_t *ntrk=new Int_t[tracks];
418 Int_t *limi=new Int_t[tracks];
419 Float_t **coor=new Float_t*[tracks];
420 for(Int_t i=0;i<tracks;i++) {
426 AliPoints *points = 0;
429 Int_t chunk=nhits/4+1;
431 // Loop over all the hits and store their position
432 for (Int_t hit=0;hit<nhits;hit++) {
433 ahit = (AliHit*)fHits->UncheckedAt(hit);
434 trk=ahit->GetTrack();
436 if(ntrk[trk]==limi[trk]) {
438 // Initialise a new track
439 fp=new Float_t[3*(limi[trk]+chunk)];
441 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
449 fp[3*ntrk[trk] ] = ahit->X();
450 fp[3*ntrk[trk]+1] = ahit->Y();
451 fp[3*ntrk[trk]+2] = ahit->Z();
455 for(trk=0; trk<tracks; ++trk) {
457 points = new AliPoints();
458 points->SetMarkerColor(GetMarkerColor());
459 points->SetMarkerSize(GetMarkerSize());
460 points->SetDetector(this);
461 points->SetParticle(trk);
462 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
463 fPoints->AddAt(points,trk);
473 //_____________________________________________________________________________
474 void AliDetector::MakeBranch(Option_t *option, const char *file)
477 // Create a new branch in the current Root Tree
478 // The branch of fHits is automatically split
482 sprintf(branchname,"%s",GetName());
484 // Get the pointer to the header
485 const char *cH = strstr(option,"H");
487 if (fHits && gAlice->TreeH() && cH) {
488 MakeBranchInTree(gAlice->TreeH(),
489 branchname, &fHits, fBufferSize, file) ;
492 const char *cD = strstr(option,"D");
496 fDigitsFile = new char[strlen (file)];
497 strcpy(fDigitsFile,file);
501 //_____________________________________________________________________________
502 void AliDetector::MakeBranchTR(Option_t *option, const char *file)
505 // Create a new branch in the current Root Tree
506 // The branch of fHits is automatically split
510 sprintf(branchname,"%s",GetName());
512 // Get the pointer to the header
513 const char *cTR = strstr(option,"T");
515 if (fTrackReferences && gAlice->TreeTR() && cTR) {
516 MakeBranchInTree(gAlice->TreeTR(),
517 branchname, &fTrackReferences, fBufferSize, file) ;
521 //_____________________________________________________________________________
522 void AliDetector::ResetDigits()
525 // Reset number of digits and the digits array
528 if (fDigits) fDigits->Clear();
531 //_____________________________________________________________________________
532 void AliDetector::ResetHits()
535 // Reset number of hits and the hits array
538 if (fHits) fHits->Clear();
543 //_____________________________________________________________________________
544 void AliDetector::ResetTrackReferences()
547 // Reset number of hits and the hits array
549 fMaxIterTrackRef = 0;
550 if (fTrackReferences) fTrackReferences->Clear();
555 //_____________________________________________________________________________
556 void AliDetector::ResetPoints()
559 // Reset array of points
568 //_____________________________________________________________________________
569 void AliDetector::SetTreeAddress()
572 // Set branch address for the Hits and Digits Trees
576 sprintf(branchname,"%s",GetName());
578 // Branch address for hit tree
579 TTree *treeH = gAlice->TreeH();
580 if (treeH && fHits) {
581 branch = treeH->GetBranch(branchname);
582 if (branch) branch->SetAddress(&fHits);
585 // Branch address for digit tree
586 TTree *treeD = gAlice->TreeD();
587 if (treeD && fDigits) {
588 branch = treeD->GetBranch(branchname);
589 if (branch) branch->SetAddress(&fDigits);
592 // Branch address for tr tree
593 TTree *treeTR = gAlice->TreeTR();
594 if (treeTR && fTrackReferences) {
595 branch = treeTR->GetBranch(branchname);
596 if (branch) branch->SetAddress(&fTrackReferences);