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 ///////////////////////////////////////////////////////////////////////////////
20 // Base class for ALICE modules. Both sensitive modules (detectors) and //
21 // non-sensitive ones are described by this base class. This class //
22 // supports the hit and digit trees produced by the simulation and also //
23 // the objects produced by the reconstruction. //
25 // This class is also responsible for building the geometry of the //
30 <img src="picts/AliDetectorClass.gif">
34 ///////////////////////////////////////////////////////////////////////////////
38 #include <Riostream.h>
45 #include "AliConfig.h"
46 #include "AliDetector.h"
48 #include "AliPoints.h"
50 #include "AliTrackReference.h"
53 // Static variables for the hit iterator routines
54 static Int_t sMaxIterHit=0;
55 static Int_t sCurIterHit=0;
60 //_______________________________________________________________________
61 AliDetector::AliDetector():
73 fCurrentIterTrackRef(0)
76 // Default constructor for the AliDetector class
80 //_______________________________________________________________________
81 AliDetector::AliDetector(const AliDetector &det):
94 fCurrentIterTrackRef(0)
99 //_____________________________________________________________________________
100 AliDetector::AliDetector(const char* name,const char *title):
101 AliModule(name,title),
111 fTrackReferences(new TClonesArray("AliTrackReference", 100)),
113 fCurrentIterTrackRef(0)
116 // Normal constructor invoked by all Detectors.
117 // Create the list for detector specific histograms
118 // Add this Detector to the global list of Detectors in Run.
122 AliConfig::Instance()->Add(this);
126 //_______________________________________________________________________
127 AliDetector::~AliDetector()
133 // Delete space point structure
139 // Delete digits structure
145 if (fDigitsFile) delete [] fDigitsFile;
148 //_______________________________________________________________________
149 void AliDetector::Publish(const char *dir, void *address, const char *name)
152 // Register pointer to detector objects.
154 TFolder *topFolder = dynamic_cast<TFolder *>(gROOT->FindObjectAny("/Folders"));
156 TFolder *folder = dynamic_cast<TFolder *>(topFolder->FindObjectAny(dir));
157 // TFolder *folder = dynamic_cast<TFolder *>(gROOT->FindObjectAny(dir));
159 cerr << "Cannot register: Missing folder: " << dir << endl;
161 TFolder *subfolder = dynamic_cast<TFolder *>(folder->FindObjectAny(this->GetName()));
164 subfolder = folder->AddFolder(this->GetName(),this->GetTitle());
166 TObject **obj = static_cast<TObject **>(address);
167 if ((*obj)->InheritsFrom(TCollection::Class())) {
168 TCollection *collection = dynamic_cast<TCollection *>(*obj);
170 collection->SetName(name);
172 subfolder->Add(*obj);
178 //_______________________________________________________________________
179 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
180 void* address, Int_t size,
183 return(MakeBranchInTree(tree,name,0,address,size,99,file));
186 //_______________________________________________________________________
187 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
188 const char *classname,
189 void* address,Int_t size,
190 Int_t splitlevel, const char *file)
193 // Makes branch in given tree and diverts them to a separate file
196 printf("* MakeBranch * Making Branch %s \n",name);
198 TDirectory *cwd = gDirectory;
202 branch = tree->Branch(name,classname,address,size,splitlevel);
204 branch = tree->Branch(name,address,size);
208 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
209 sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
210 branch->SetFile(outFile);
211 TIter next( branch->GetListOfBranches());
212 while ((branch=dynamic_cast<TBranch*>(next()))) {
213 branch->SetFile(outFile);
220 printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
222 const char *folder = 0;
223 TString folderName(name);
225 if (!strncmp(tree->GetName(),"TreeE",5)) folder = "RunMC/Event/Data";
226 if (!strncmp(tree->GetName(),"TreeK",5)) folder = "RunMC/Event/Data";
227 if (!strncmp(tree->GetName(),"TreeH",5)) {
228 folder = "RunMC/Event/Data/Hits";
229 folderName = "Hits" ;
231 if (!strncmp(tree->GetName(),"TreeTrackReferences",5)) {
232 folder = "RunMC/Event/Data/TrackReferences";
233 folderName = "TrackReferences" ;
236 if (!strncmp(tree->GetName(),"TreeD",5)) {
237 folder = "Run/Event/Data";
238 folderName = "Digits" ;
240 if (!strncmp(tree->GetName(),"TreeS",5)) {
241 folder = "RunMC/Event/Data/SDigits";
242 folderName = "SDigits" ;
244 if (!strncmp(tree->GetName(),"TreeR",5)) folder = "Run/Event/RecData";
248 printf("%15s: Publishing %s to %s\n",ClassName(),name,folder);
249 Publish(folder,address, folderName.Data());
254 //_______________________________________________________________________
255 void AliDetector::Browse(TBrowser *b)
258 // Insert Detector objects in the list of objects to be browsed
261 if( fHits == 0) return;
265 nobjects = fHits->GetEntries();
266 for (i=0;i<nobjects;i++) {
268 sprintf(name,"%s_%d",obj->GetName(),i);
269 b->Add(obj, &name[0]);
273 //_______________________________________________________________________
274 void AliDetector::Copy(AliDetector &) const
277 // Copy *this onto det -- not implemented
279 Fatal("Copy","Not implemented\n");
282 //_______________________________________________________________________
283 void AliDetector::FinishRun()
286 // Procedure called at the end of a run.
290 //_______________________________________________________________________
291 void AliDetector::RemapTrackReferencesIDs(Int_t *map)
294 // Remapping track reference
295 // Called at finish primary
297 if (!fTrackReferences) return;
298 for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
299 AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(i));
301 Int_t newID = map[ref->GetTrack()];
302 if (newID>=0) ref->SetTrack(newID);
303 else ref->SetTrack(-1);
309 //_______________________________________________________________________
310 AliHit* AliDetector::FirstHit(Int_t track)
313 // Initialise the hit iterator
314 // Return the address of the first hit for track
315 // If track>=0 the track is read from disk
316 // while if track<0 the first hit of the current
321 gAlice->TreeH()->GetEvent(track);
324 sMaxIterHit=fHits->GetEntriesFast();
326 if(sMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
331 //_______________________________________________________________________
332 AliTrackReference* AliDetector::FirstTrackReference(Int_t track)
335 // Initialise the hit iterator
336 // Return the address of the first hit for track
337 // If track>=0 the track is read from disk
338 // while if track<0 the first hit of the current
342 gAlice->ResetTrackReferences();
343 gAlice->TreeTR()->GetEvent(track);
346 fMaxIterTrackRef = fTrackReferences->GetEntriesFast();
347 fCurrentIterTrackRef = 0;
348 if(fMaxIterTrackRef) return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(0));
352 //_______________________________________________________________________
353 AliHit* AliDetector::NextHit()
356 // Return the next hit for the current track
359 if(++sCurIterHit<sMaxIterHit)
360 return dynamic_cast<AliHit*>(fHits->UncheckedAt(sCurIterHit));
364 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
369 //_______________________________________________________________________
370 AliTrackReference* AliDetector::NextTrackReference()
373 // Return the next hit for the current track
375 if(fMaxIterTrackRef) {
376 if(++fCurrentIterTrackRef<fMaxIterTrackRef)
377 return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(fCurrentIterTrackRef));
381 printf("* AliDetector::NextTrackReference * TrackReference Iterator called without calling FistTrackReference before\n");
386 //_______________________________________________________________________
387 void AliDetector::LoadPoints(Int_t)
390 // Store x, y, z of all hits in memory
392 if (fHits == 0) return;
394 Int_t nhits = fHits->GetEntriesFast();
395 if (nhits == 0) return;
396 Int_t tracks = gAlice->GetNtrack();
397 if (fPoints == 0) fPoints = new TObjArray(tracks);
400 Int_t *ntrk=new Int_t[tracks];
401 Int_t *limi=new Int_t[tracks];
402 Float_t **coor=new Float_t*[tracks];
403 for(Int_t i=0;i<tracks;i++) {
409 AliPoints *points = 0;
412 Int_t chunk=nhits/4+1;
414 // Loop over all the hits and store their position
415 for (Int_t hit=0;hit<nhits;hit++) {
416 ahit = dynamic_cast<AliHit*>(fHits->UncheckedAt(hit));
417 trk=ahit->GetTrack();
419 if(ntrk[trk]==limi[trk]) {
421 // Initialise a new track
422 fp=new Float_t[3*(limi[trk]+chunk)];
424 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
432 fp[3*ntrk[trk] ] = ahit->X();
433 fp[3*ntrk[trk]+1] = ahit->Y();
434 fp[3*ntrk[trk]+2] = ahit->Z();
438 for(trk=0; trk<tracks; ++trk) {
440 points = new AliPoints();
441 points->SetMarkerColor(GetMarkerColor());
442 points->SetMarkerSize(GetMarkerSize());
443 points->SetDetector(this);
444 points->SetParticle(trk);
445 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
446 fPoints->AddAt(points,trk);
456 //_______________________________________________________________________
457 void AliDetector::MakeBranch(Option_t *option, const char *file)
460 // Create a new branch in the current Root Tree
461 // The branch of fHits is automatically split
465 sprintf(branchname,"%s",GetName());
467 // Get the pointer to the header
468 const char *cH = strstr(option,"H");
470 if (fHits && gAlice->TreeH() && cH) {
471 MakeBranchInTree(gAlice->TreeH(),
472 branchname, &fHits, fBufferSize, file) ;
475 const char *cD = strstr(option,"D");
479 fDigitsFile = new char[strlen (file)];
480 strcpy(fDigitsFile,file);
484 //_______________________________________________________________________
485 void AliDetector::MakeBranchTR(Option_t *option, const char *file)
488 // Create a new branch in the current Root Tree
489 // The branch of fHits is automatically split
493 sprintf(branchname,"%s",GetName());
495 // Get the pointer to the header
496 const char *cTR = strstr(option,"T");
498 if (fTrackReferences && gAlice->TreeTR() && cTR) {
499 MakeBranchInTree(gAlice->TreeTR(),
500 branchname, &fTrackReferences, fBufferSize, file) ;
504 //_______________________________________________________________________
505 void AliDetector::ResetDigits()
508 // Reset number of digits and the digits array
511 if (fDigits) fDigits->Clear();
514 //_______________________________________________________________________
515 void AliDetector::ResetHits()
518 // Reset number of hits and the hits array
521 if (fHits) fHits->Clear();
524 //_______________________________________________________________________
525 void AliDetector::ResetTrackReferences()
528 // Reset number of hits and the hits array
530 fMaxIterTrackRef = 0;
531 if (fTrackReferences) fTrackReferences->Clear();
534 //_______________________________________________________________________
535 void AliDetector::ResetPoints()
538 // Reset array of points
547 //_______________________________________________________________________
548 void AliDetector::SetTreeAddress()
551 // Set branch address for the Hits and Digits Trees
555 sprintf(branchname,"%s",GetName());
557 // Branch address for hit tree
558 TTree *treeH = gAlice->TreeH();
559 if (treeH && fHits) {
560 branch = treeH->GetBranch(branchname);
561 if (branch) branch->SetAddress(&fHits);
564 // Branch address for digit tree
565 TTree *treeD = gAlice->TreeD();
566 if (treeD && fDigits) {
567 branch = treeD->GetBranch(branchname);
568 if (branch) branch->SetAddress(&fDigits);
571 // Branch address for tr tree
572 TTree *treeTR = gAlice->TreeTR();
573 if (treeTR && fTrackReferences) {
574 branch = treeTR->GetBranch(branchname);
575 if (branch) branch->SetAddress(&fTrackReferences);