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.16.8.3 2002/10/14 09:45:57 hristov
19 Updating VirtualMC to v3-09-02
21 Revision 1.19 2002/09/23 09:19:54 hristov
22 FirsTrackReference updated (M.Ivanov)
24 Revision 1.18 2002/08/26 13:51:17 hristov
25 Remaping of track references at the end of each primary particle (M.Ivanov)
27 Revision 1.17 2002/05/24 13:29:58 hristov
28 AliTrackReference added, AliDisplay modified
30 Revision 1.16 2001/10/04 15:30:56 hristov
31 Changes to accommodate the set of PHOS folders and tasks (Y.Schutz)
33 Revision 1.15 2001/07/27 13:03:13 hristov
34 Default Branch split level set to 99
36 Revision 1.14 2001/05/21 17:22:51 buncic
37 Fixed problem with missing AliConfig while reading galice.root
39 Revision 1.13 2001/05/16 14:57:22 alibrary
40 New files for folders and Stack
42 Revision 1.12 2001/03/12 17:47:03 hristov
43 Changes needed on Sun with CC 5.0
45 Revision 1.11 2001/01/26 19:58:46 hristov
46 Major upgrade of AliRoot code
48 Revision 1.10 2001/01/17 10:50:50 hristov
49 Corrections to destructors
51 Revision 1.9 2000/12/12 18:19:06 alibrary
52 Introduce consistency check when loading points
54 Revision 1.8 2000/11/30 07:12:48 alibrary
55 Introducing new Rndm and QA classes
57 Revision 1.7 2000/10/02 21:28:14 fca
58 Removal of useless dependecies via forward declarations
60 Revision 1.6 2000/07/12 08:56:25 fca
61 Coding convention correction and warning removal
63 Revision 1.5 1999/09/29 09:24:29 fca
64 Introduction of the Copyright and cvs Log
68 ///////////////////////////////////////////////////////////////////////////////
70 // Base class for ALICE modules. Both sensitive modules (detectors) and //
71 // non-sensitive ones are described by this base class. This class //
72 // supports the hit and digit trees produced by the simulation and also //
73 // the objects produced by the reconstruction. //
75 // This class is also responsible for building the geometry of the //
80 <img src="picts/AliDetectorClass.gif">
84 ///////////////////////////////////////////////////////////////////////////////
95 #include "AliConfig.h"
96 #include "AliDetector.h"
99 #include "AliPoints.h"
100 #include "AliTrackReference.h"
103 // Static variables for the hit iterator routines
104 static Int_t sMaxIterHit=0;
105 static Int_t sCurIterHit=0;
108 ClassImp(AliDetector)
110 //_____________________________________________________________________________
111 AliDetector::AliDetector()
114 // Default constructor for the AliDetector class
127 //_____________________________________________________________________________
128 AliDetector::AliDetector(const char* name,const char *title):AliModule(name,title)
131 // Normal constructor invoked by all Detectors.
132 // Create the list for detector specific histograms
133 // Add this Detector to the global list of Detectors in Run.
147 AliConfig::Instance()->Add(this);
149 fTrackReferences = new TClonesArray("AliTrackReference", 100);
150 //if detector to want to create another track reference - than let's be free
154 //_____________________________________________________________________________
155 AliDetector::~AliDetector()
163 // Delete space point structure
169 // Delete digits structure
175 if (fDigitsFile) delete [] fDigitsFile;
178 //_____________________________________________________________________________
179 void AliDetector::Publish(const char *dir, void *address, const char *name)
182 // Register pointer to detector objects.
184 TFolder *topFolder = (TFolder *)gROOT->FindObjectAny("/Folders");
186 TFolder *folder = (TFolder *)topFolder->FindObjectAny(dir);
187 // TFolder *folder = (TFolder *)gROOT->FindObjectAny(dir);
189 cerr << "Cannot register: Missing folder: " << dir << endl;
191 TFolder *subfolder = (TFolder *) folder->FindObjectAny(this->GetName());
194 subfolder = folder->AddFolder(this->GetName(),this->GetTitle());
196 TObject **obj = (TObject **) address;
197 if ((*obj)->InheritsFrom(TCollection::Class())) {
198 TCollection *collection = (TCollection *) (*obj);
200 collection->SetName(name);
202 subfolder->Add(*obj);
208 //_____________________________________________________________________________
209 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, void* address, Int_t size,const char *file)
211 return(MakeBranchInTree(tree,name,0,address,size,99,file));
214 //_____________________________________________________________________________
215 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, const char *classname, void* address,Int_t size, Int_t splitlevel, const char *file)
218 // Makes branch in given tree and diverts them to a separate file
221 printf("* MakeBranch * Making Branch %s \n",name);
223 TDirectory *cwd = gDirectory;
227 branch = tree->Branch(name,classname,address,size,splitlevel);
229 branch = tree->Branch(name,address,size);
233 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
234 sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
235 branch->SetFile(outFile);
236 TIter next( branch->GetListOfBranches());
237 while ((branch=(TBranch*)next())) {
238 branch->SetFile(outFile);
245 printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
248 TString folderName(name);
250 if (!strncmp(tree->GetName(),"TreeE",5)) folder = "RunMC/Event/Data";
251 if (!strncmp(tree->GetName(),"TreeK",5)) folder = "RunMC/Event/Data";
252 if (!strncmp(tree->GetName(),"TreeH",5)) {
253 folder = "RunMC/Event/Data/Hits";
254 folderName = "Hits" ;
256 if (!strncmp(tree->GetName(),"TreeTrackReferences",5)) {
257 folder = "RunMC/Event/Data/TrackReferences";
258 folderName = "TrackReferences" ;
261 if (!strncmp(tree->GetName(),"TreeD",5)) {
262 folder = "Run/Event/Data";
263 folderName = "Digits" ;
265 if (!strncmp(tree->GetName(),"TreeS",5)) {
266 folder = "RunMC/Event/Data/SDigits";
267 folderName = "SDigits" ;
269 if (!strncmp(tree->GetName(),"TreeR",5)) folder = "Run/Event/RecData";
273 printf("%15s: Publishing %s to %s\n",ClassName(),name,folder);
274 Publish(folder,address, folderName.Data());
279 //_____________________________________________________________________________
280 void AliDetector::Browse(TBrowser *b)
283 // Insert Detector objects in the list of objects to be browsed
286 if( fHits == 0) return;
290 nobjects = fHits->GetEntries();
291 for (i=0;i<nobjects;i++) {
293 sprintf(name,"%s_%d",obj->GetName(),i);
294 b->Add(obj, &name[0]);
298 //_____________________________________________________________________________
299 void AliDetector::Copy(AliDetector &det) const
302 // Copy *this onto det -- not implemented
304 Fatal("Copy","Not implemented~\n");
307 //_____________________________________________________________________________
308 void AliDetector::FinishRun()
311 // Procedure called at the end of a run.
317 void AliDetector::RemapTrackReferencesIDs(Int_t *map)
320 //remaping track reference
321 //called at finish primary
322 if (!fTrackReferences) return;
323 for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
324 AliTrackReference * ref = (AliTrackReference*) fTrackReferences->UncheckedAt(i);
326 Int_t newID = map[ref->GetTrack()];
327 if (newID>=0) ref->SetTrack(newID);
328 else ref->SetTrack(-1);
334 //_____________________________________________________________________________
335 AliHit* AliDetector::FirstHit(Int_t track)
338 // Initialise the hit iterator
339 // Return the address of the first hit for track
340 // If track>=0 the track is read from disk
341 // while if track<0 the first hit of the current
346 gAlice->TreeH()->GetEvent(track);
349 sMaxIterHit=fHits->GetEntriesFast();
351 if(sMaxIterHit) return (AliHit*) fHits->UncheckedAt(0);
356 //_____________________________________________________________________________
357 AliTrackReference* AliDetector::FirstTrackReference(Int_t track)
360 // Initialise the hit iterator
361 // Return the address of the first hit for track
362 // If track>=0 the track is read from disk
363 // while if track<0 the first hit of the current
367 gAlice->ResetTrackReferences();
368 gAlice->TreeTR()->GetEvent(track);
371 fMaxIterTrackRef = fTrackReferences->GetEntriesFast();
372 fCurrentIterTrackRef = 0;
373 if(fMaxIterTrackRef) return (AliTrackReference*) fTrackReferences->UncheckedAt(0);
379 //_____________________________________________________________________________
380 AliHit* AliDetector::NextHit()
383 // Return the next hit for the current track
386 if(++sCurIterHit<sMaxIterHit)
387 return (AliHit*) fHits->UncheckedAt(sCurIterHit);
391 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
395 //_____________________________________________________________________________
396 AliTrackReference* AliDetector::NextTrackReference()
399 // Return the next hit for the current track
401 if(fMaxIterTrackRef) {
402 if(++fCurrentIterTrackRef<fMaxIterTrackRef)
403 return (AliTrackReference*) fTrackReferences->UncheckedAt(fCurrentIterTrackRef);
407 printf("* AliDetector::NextTrackReference * TrackReference Iterator called without calling FistTrackReference before\n");
412 //_____________________________________________________________________________
413 void AliDetector::LoadPoints(Int_t)
416 // Store x, y, z of all hits in memory
418 if (fHits == 0) return;
420 Int_t nhits = fHits->GetEntriesFast();
421 if (nhits == 0) return;
422 Int_t tracks = gAlice->GetNtrack();
423 if (fPoints == 0) fPoints = new TObjArray(tracks);
426 Int_t *ntrk=new Int_t[tracks];
427 Int_t *limi=new Int_t[tracks];
428 Float_t **coor=new Float_t*[tracks];
429 for(Int_t i=0;i<tracks;i++) {
435 AliPoints *points = 0;
438 Int_t chunk=nhits/4+1;
440 // Loop over all the hits and store their position
441 for (Int_t hit=0;hit<nhits;hit++) {
442 ahit = (AliHit*)fHits->UncheckedAt(hit);
443 trk=ahit->GetTrack();
445 if(ntrk[trk]==limi[trk]) {
447 // Initialise a new track
448 fp=new Float_t[3*(limi[trk]+chunk)];
450 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
458 fp[3*ntrk[trk] ] = ahit->X();
459 fp[3*ntrk[trk]+1] = ahit->Y();
460 fp[3*ntrk[trk]+2] = ahit->Z();
464 for(trk=0; trk<tracks; ++trk) {
466 points = new AliPoints();
467 points->SetMarkerColor(GetMarkerColor());
468 points->SetMarkerSize(GetMarkerSize());
469 points->SetDetector(this);
470 points->SetParticle(trk);
471 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
472 fPoints->AddAt(points,trk);
482 //_____________________________________________________________________________
483 void AliDetector::MakeBranch(Option_t *option, const char *file)
486 // Create a new branch in the current Root Tree
487 // The branch of fHits is automatically split
491 sprintf(branchname,"%s",GetName());
493 // Get the pointer to the header
494 const char *cH = strstr(option,"H");
496 if (fHits && gAlice->TreeH() && cH) {
497 MakeBranchInTree(gAlice->TreeH(),
498 branchname, &fHits, fBufferSize, file) ;
501 const char *cD = strstr(option,"D");
505 fDigitsFile = new char[strlen (file)];
506 strcpy(fDigitsFile,file);
510 //_____________________________________________________________________________
511 void AliDetector::MakeBranchTR(Option_t *option, const char *file)
514 // Create a new branch in the current Root Tree
515 // The branch of fHits is automatically split
519 sprintf(branchname,"%s",GetName());
521 // Get the pointer to the header
522 const char *cTR = strstr(option,"T");
524 if (fTrackReferences && gAlice->TreeTR() && cTR) {
525 MakeBranchInTree(gAlice->TreeTR(),
526 branchname, &fTrackReferences, fBufferSize, file) ;
530 //_____________________________________________________________________________
531 void AliDetector::ResetDigits()
534 // Reset number of digits and the digits array
537 if (fDigits) fDigits->Clear();
540 //_____________________________________________________________________________
541 void AliDetector::ResetHits()
544 // Reset number of hits and the hits array
547 if (fHits) fHits->Clear();
552 //_____________________________________________________________________________
553 void AliDetector::ResetTrackReferences()
556 // Reset number of hits and the hits array
558 fMaxIterTrackRef = 0;
559 if (fTrackReferences) fTrackReferences->Clear();
564 //_____________________________________________________________________________
565 void AliDetector::ResetPoints()
568 // Reset array of points
577 //_____________________________________________________________________________
578 void AliDetector::SetTreeAddress()
581 // Set branch address for the Hits and Digits Trees
585 sprintf(branchname,"%s",GetName());
587 // Branch address for hit tree
588 TTree *treeH = gAlice->TreeH();
589 if (treeH && fHits) {
590 branch = treeH->GetBranch(branchname);
591 if (branch) branch->SetAddress(&fHits);
594 // Branch address for digit tree
595 TTree *treeD = gAlice->TreeD();
596 if (treeD && fDigits) {
597 branch = treeD->GetBranch(branchname);
598 if (branch) branch->SetAddress(&fDigits);
601 // Branch address for tr tree
602 TTree *treeTR = gAlice->TreeTR();
603 if (treeTR && fTrackReferences) {
604 branch = treeTR->GetBranch(branchname);
605 if (branch) branch->SetAddress(&fTrackReferences);