]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliDetector.cxx
Compiles now using top makefile.
[u/mrichter/AliRoot.git] / STEER / AliDetector.cxx
CommitLineData
4c039060 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/*
17$Log$
aab9c8d5 18Revision 1.16 2001/10/04 15:30:56 hristov
19Changes to accommodate the set of PHOS folders and tasks (Y.Schutz)
20
7e90ff59 21Revision 1.15 2001/07/27 13:03:13 hristov
22Default Branch split level set to 99
23
d0f40f23 24Revision 1.14 2001/05/21 17:22:51 buncic
25Fixed problem with missing AliConfig while reading galice.root
26
682a4a95 27Revision 1.13 2001/05/16 14:57:22 alibrary
28New files for folders and Stack
29
9e1a0ddb 30Revision 1.12 2001/03/12 17:47:03 hristov
31Changes needed on Sun with CC 5.0
32
5cf7bbad 33Revision 1.11 2001/01/26 19:58:46 hristov
34Major upgrade of AliRoot code
35
2ab0c725 36Revision 1.10 2001/01/17 10:50:50 hristov
37Corrections to destructors
38
e460afec 39Revision 1.9 2000/12/12 18:19:06 alibrary
40Introduce consistency check when loading points
41
27d40e08 42Revision 1.8 2000/11/30 07:12:48 alibrary
43Introducing new Rndm and QA classes
44
65fb704d 45Revision 1.7 2000/10/02 21:28:14 fca
46Removal of useless dependecies via forward declarations
47
94de3818 48Revision 1.6 2000/07/12 08:56:25 fca
49Coding convention correction and warning removal
50
8918e700 51Revision 1.5 1999/09/29 09:24:29 fca
52Introduction of the Copyright and cvs Log
53
4c039060 54*/
55
fe4da5cc 56///////////////////////////////////////////////////////////////////////////////
57// //
58// Base class for ALICE modules. Both sensitive modules (detectors) and //
59// non-sensitive ones are described by this base class. This class //
60// supports the hit and digit trees produced by the simulation and also //
61// the objects produced by the reconstruction. //
62// //
63// This class is also responsible for building the geometry of the //
64// detectors. //
65// //
66//Begin_Html
67/*
1439f98e 68<img src="picts/AliDetectorClass.gif">
fe4da5cc 69*/
70//End_Html
71// //
72///////////////////////////////////////////////////////////////////////////////
65fb704d 73
27d40e08 74#include <assert.h>
9e1a0ddb 75#include <iostream.h>
27d40e08 76
94de3818 77#include <TTree.h>
2ab0c725 78#include <TBrowser.h>
79#include <TFile.h>
9e1a0ddb 80#include <TROOT.h>
81#include <TFolder.h>
fe4da5cc 82
9e1a0ddb 83#include "AliConfig.h"
94de3818 84#include "AliDetector.h"
85#include "AliRun.h"
86#include "AliHit.h"
87#include "AliPoints.h"
aab9c8d5 88#include "AliTrackReference.h"
89
9e1a0ddb 90
fe4da5cc 91// Static variables for the hit iterator routines
92static Int_t sMaxIterHit=0;
93static Int_t sCurIterHit=0;
94
aab9c8d5 95
fe4da5cc 96ClassImp(AliDetector)
97
98//_____________________________________________________________________________
99AliDetector::AliDetector()
100{
101 //
102 // Default constructor for the AliDetector class
103 //
104 fNhits = 0;
105 fNdigits = 0;
fe4da5cc 106 fPoints = 0;
107 fHits = 0;
aab9c8d5 108 fTrackReferences =0;
fe4da5cc 109 fDigits = 0;
110 fTimeGate = 200.e-9;
fe4da5cc 111 fBufferSize = 16000;
2ab0c725 112 fDigitsFile = 0;
fe4da5cc 113}
114
115//_____________________________________________________________________________
8494b010 116AliDetector::AliDetector(const char* name,const char *title):AliModule(name,title)
fe4da5cc 117{
118 //
119 // Normal constructor invoked by all Detectors.
120 // Create the list for detector specific histograms
121 // Add this Detector to the global list of Detectors in Run.
122 //
123
124 fTimeGate = 200.e-9;
125 fActive = kTRUE;
126 fNhits = 0;
127 fHits = 0;
aab9c8d5 128 fTrackReferences =0;
fe4da5cc 129 fDigits = 0;
130 fNdigits = 0;
131 fPoints = 0;
132 fBufferSize = 16000;
2ab0c725 133 fDigitsFile = 0;
9e1a0ddb 134
135 AliConfig::Instance()->Add(this);
aab9c8d5 136
137 fTrackReferences = new TClonesArray("AliTrackReference", 100);
138 //if detector to want to create another track reference - than let's be free
139
fe4da5cc 140}
141
142//_____________________________________________________________________________
143AliDetector::~AliDetector()
144{
145 //
146 // Destructor
147 //
148 fNhits = 0;
149 fNdigits = 0;
fe4da5cc 150 //
151 // Delete space point structure
e460afec 152 if (fPoints) {
153 fPoints->Delete();
154 delete fPoints;
155 fPoints = 0;
156 }
157 // Delete digits structure
158 if (fDigits) {
159 fDigits->Delete();
160 delete fDigits;
161 fDigits = 0;
162 }
2ab0c725 163 if (fDigitsFile) delete [] fDigitsFile;
fe4da5cc 164}
9e1a0ddb 165
166//_____________________________________________________________________________
167void AliDetector::Publish(const char *dir, void *address, const char *name)
168{
169 //
170 // Register pointer to detector objects.
171 //
172 TFolder *topFolder = (TFolder *)gROOT->FindObjectAny("/Folders");
682a4a95 173 if (topFolder) {
174 TFolder *folder = (TFolder *)topFolder->FindObjectAny(dir);
175 // TFolder *folder = (TFolder *)gROOT->FindObjectAny(dir);
176 if (!folder) {
177 cerr << "Cannot register: Missing folder: " << dir << endl;
178 } else {
179 TFolder *subfolder = (TFolder *) folder->FindObjectAny(this->GetName());
180
181 if(!subfolder)
182 subfolder = folder->AddFolder(this->GetName(),this->GetTitle());
183 if (address) {
184 TObject **obj = (TObject **) address;
185 if ((*obj)->InheritsFrom(TCollection::Class())) {
186 TCollection *collection = (TCollection *) (*obj);
187 if (name)
188 collection->SetName(name);
189 }
190 subfolder->Add(*obj);
9e1a0ddb 191 }
9e1a0ddb 192 }
193 }
194}
195
196//_____________________________________________________________________________
197TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, void* address, Int_t size,const char *file)
198{
d0f40f23 199 return(MakeBranchInTree(tree,name,0,address,size,99,file));
9e1a0ddb 200}
201
202//_____________________________________________________________________________
203TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, const char *classname, void* address,Int_t size, Int_t splitlevel, const char *file)
204{
205 //
206 // Makes branch in given tree and diverts them to a separate file
207 //
208 if (GetDebug()>1)
209 printf("* MakeBranch * Making Branch %s \n",name);
210
211 TDirectory *cwd = gDirectory;
212 TBranch *branch = 0;
213
214 if (classname) {
215 branch = tree->Branch(name,classname,address,size,splitlevel);
216 } else {
217 branch = tree->Branch(name,address,size);
218 }
219
220 if (file) {
221 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
222 sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
223 branch->SetFile(outFile);
224 TIter next( branch->GetListOfBranches());
225 while ((branch=(TBranch*)next())) {
226 branch->SetFile(outFile);
227 }
228 delete outFile;
229
230 cwd->cd();
231
232 if (GetDebug()>1)
233 printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
234 }
235 char *folder = 0;
7e90ff59 236 TString folderName(name);
237
9e1a0ddb 238 if (!strncmp(tree->GetName(),"TreeE",5)) folder = "RunMC/Event/Data";
239 if (!strncmp(tree->GetName(),"TreeK",5)) folder = "RunMC/Event/Data";
7e90ff59 240 if (!strncmp(tree->GetName(),"TreeH",5)) {
241 folder = "RunMC/Event/Data/Hits";
242 folderName = "Hits" ;
243 }
aab9c8d5 244 if (!strncmp(tree->GetName(),"TreeTrackReferences",5)) {
245 folder = "RunMC/Event/Data/TrackReferences";
246 folderName = "TrackReferences" ;
247 }
248
7e90ff59 249 if (!strncmp(tree->GetName(),"TreeD",5)) {
250 folder = "Run/Event/Data";
251 folderName = "Digits" ;
252 }
253 if (!strncmp(tree->GetName(),"TreeS",5)) {
254 folder = "RunMC/Event/Data/SDigits";
255 folderName = "SDigits" ;
256 }
9e1a0ddb 257 if (!strncmp(tree->GetName(),"TreeR",5)) folder = "Run/Event/RecData";
258
259 if (folder) {
260 if (GetDebug())
261 printf("%15s: Publishing %s to %s\n",ClassName(),name,folder);
7e90ff59 262 Publish(folder,address, folderName.Data());
9e1a0ddb 263 }
264 return branch;
265}
266
fe4da5cc 267//_____________________________________________________________________________
268void AliDetector::Browse(TBrowser *b)
269{
270 //
271 // Insert Detector objects in the list of objects to be browsed
272 //
273 char name[64];
274 if( fHits == 0) return;
275 TObject *obj;
276 Int_t i, nobjects;
277 //
278 nobjects = fHits->GetEntries();
279 for (i=0;i<nobjects;i++) {
280 obj = fHits->At(i);
281 sprintf(name,"%s_%d",obj->GetName(),i);
282 b->Add(obj, &name[0]);
283 }
284}
285
8918e700 286//_____________________________________________________________________________
287void AliDetector::Copy(AliDetector &det) const
288{
289 //
290 // Copy *this onto det -- not implemented
291 //
292 Fatal("Copy","Not implemented~\n");
293}
294
fe4da5cc 295//_____________________________________________________________________________
296void AliDetector::FinishRun()
297{
298 //
299 // Procedure called at the end of a run.
300 //
301}
302
303//_____________________________________________________________________________
304AliHit* AliDetector::FirstHit(Int_t track)
305{
306 //
307 // Initialise the hit iterator
308 // Return the address of the first hit for track
309 // If track>=0 the track is read from disk
310 // while if track<0 the first hit of the current
311 // track is returned
312 //
313 if(track>=0) {
314 gAlice->ResetHits();
315 gAlice->TreeH()->GetEvent(track);
316 }
317 //
318 sMaxIterHit=fHits->GetEntriesFast();
319 sCurIterHit=0;
320 if(sMaxIterHit) return (AliHit*) fHits->UncheckedAt(0);
321 else return 0;
322}
323
aab9c8d5 324
325//_____________________________________________________________________________
326AliTrackReference* AliDetector::FirstTrackReference(Int_t track)
327{
328 //
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
333 // track is returned
334 //
335 if(track>=0) {
336 gAlice->ResetTrackReferences();
337 gAlice->TreeTR()->GetEvent(track);
338 }
339 //
340 sMaxIterHit=fTrackReferences->GetEntriesFast();
341 sCurIterHit=0;
342 if(sMaxIterHit) return (AliTrackReference*) fTrackReferences->UncheckedAt(0);
343 else return 0;
344}
345
346
347
fe4da5cc 348//_____________________________________________________________________________
349AliHit* AliDetector::NextHit()
350{
351 //
352 // Return the next hit for the current track
353 //
354 if(sMaxIterHit) {
355 if(++sCurIterHit<sMaxIterHit)
356 return (AliHit*) fHits->UncheckedAt(sCurIterHit);
357 else
358 return 0;
359 } else {
360 printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
361 return 0;
362 }
363}
aab9c8d5 364//_____________________________________________________________________________
365AliTrackReference* AliDetector::NextTrackReference()
366{
367 //
368 // Return the next hit for the current track
369 //
370 if(fMaxIterTrackRef) {
371 if(++fCurrentIterTrackRef<fMaxIterTrackRef)
372 return (AliTrackReference*) fTrackReferences->UncheckedAt(fCurrentIterTrackRef);
373 else
374 return 0;
375 } else {
376 printf("* AliDetector::NextTrackReference * TrackReference Iterator called without calling FistTrackReference before\n");
377 return 0;
378 }
379}
fe4da5cc 380
381//_____________________________________________________________________________
382void AliDetector::LoadPoints(Int_t)
383{
384 //
385 // Store x, y, z of all hits in memory
386 //
387 if (fHits == 0) return;
388 //
fe4da5cc 389 Int_t nhits = fHits->GetEntriesFast();
390 if (nhits == 0) return;
080a67a1 391 Int_t tracks = gAlice->GetNtrack();
392 if (fPoints == 0) fPoints = new TObjArray(tracks);
fe4da5cc 393 AliHit *ahit;
394 //
080a67a1 395 Int_t *ntrk=new Int_t[tracks];
396 Int_t *limi=new Int_t[tracks];
397 Float_t **coor=new Float_t*[tracks];
398 for(Int_t i=0;i<tracks;i++) {
399 ntrk[i]=0;
400 coor[i]=0;
401 limi[i]=0;
402 }
403 //
fe4da5cc 404 AliPoints *points = 0;
080a67a1 405 Float_t *fp=0;
406 Int_t trk;
407 Int_t chunk=nhits/4+1;
fe4da5cc 408 //
409 // Loop over all the hits and store their position
410 for (Int_t hit=0;hit<nhits;hit++) {
411 ahit = (AliHit*)fHits->UncheckedAt(hit);
080a67a1 412 trk=ahit->GetTrack();
27d40e08 413 assert(trk<=tracks);
080a67a1 414 if(ntrk[trk]==limi[trk]) {
fe4da5cc 415 //
416 // Initialise a new track
080a67a1 417 fp=new Float_t[3*(limi[trk]+chunk)];
418 if(coor[trk]) {
419 memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
420 delete [] coor[trk];
421 }
422 limi[trk]+=chunk;
423 coor[trk] = fp;
424 } else {
425 fp = coor[trk];
426 }
94de3818 427 fp[3*ntrk[trk] ] = ahit->X();
428 fp[3*ntrk[trk]+1] = ahit->Y();
429 fp[3*ntrk[trk]+2] = ahit->Z();
080a67a1 430 ntrk[trk]++;
431 }
432 //
433 for(trk=0; trk<tracks; ++trk) {
434 if(ntrk[trk]) {
435 points = new AliPoints();
fe4da5cc 436 points->SetMarkerColor(GetMarkerColor());
fe4da5cc 437 points->SetMarkerSize(GetMarkerSize());
438 points->SetDetector(this);
439 points->SetParticle(trk);
080a67a1 440 points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
441 fPoints->AddAt(points,trk);
442 delete [] coor[trk];
443 coor[trk]=0;
fe4da5cc 444 }
fe4da5cc 445 }
080a67a1 446 delete [] coor;
447 delete [] ntrk;
448 delete [] limi;
fe4da5cc 449}
450
451//_____________________________________________________________________________
9e1a0ddb 452void AliDetector::MakeBranch(Option_t *option, const char *file)
fe4da5cc 453{
454 //
455 // Create a new branch in the current Root Tree
456 // The branch of fHits is automatically split
457 //
2ab0c725 458
fe4da5cc 459 char branchname[10];
460 sprintf(branchname,"%s",GetName());
461 //
462 // Get the pointer to the header
5cf7bbad 463 const char *cH = strstr(option,"H");
fe4da5cc 464 //
2ab0c725 465 if (fHits && gAlice->TreeH() && cH) {
9e1a0ddb 466 MakeBranchInTree(gAlice->TreeH(),
467 branchname, &fHits, fBufferSize, file) ;
fe4da5cc 468 }
2ab0c725 469
5cf7bbad 470 const char *cD = strstr(option,"D");
2ab0c725 471
472 if (cD) {
473 if (file) {
474 fDigitsFile = new char[strlen (file)];
475 strcpy(fDigitsFile,file);
476 }
477 }
fe4da5cc 478}
aab9c8d5 479//_____________________________________________________________________________
480void AliDetector::MakeBranchTR(Option_t *option, const char *file)
481{
482 //
483 // Create a new branch in the current Root Tree
484 // The branch of fHits is automatically split
485 //
486
487 char branchname[10];
488 sprintf(branchname,"%s",GetName());
489 //
490 // Get the pointer to the header
491 const char *cTR = strstr(option,"T");
492 //
493 if (fTrackReferences && gAlice->TreeTR() && cTR) {
494 MakeBranchInTree(gAlice->TreeTR(),
495 branchname, &fTrackReferences, fBufferSize, file) ;
496 }
497}
fe4da5cc 498
fe4da5cc 499//_____________________________________________________________________________
500void AliDetector::ResetDigits()
501{
502 //
503 // Reset number of digits and the digits array
504 //
505 fNdigits = 0;
506 if (fDigits) fDigits->Clear();
507}
508
509//_____________________________________________________________________________
510void AliDetector::ResetHits()
511{
512 //
513 // Reset number of hits and the hits array
514 //
515 fNhits = 0;
516 if (fHits) fHits->Clear();
517}
518
aab9c8d5 519
520
521//_____________________________________________________________________________
522void AliDetector::ResetTrackReferences()
523{
524 //
525 // Reset number of hits and the hits array
526 //
527 fMaxIterTrackRef = 0;
528 if (fTrackReferences) fTrackReferences->Clear();
529}
530
531
532
fe4da5cc 533//_____________________________________________________________________________
534void AliDetector::ResetPoints()
535{
536 //
537 // Reset array of points
538 //
539 if (fPoints) {
540 fPoints->Delete();
541 delete fPoints;
542 fPoints = 0;
543 }
544}
545
fe4da5cc 546//_____________________________________________________________________________
547void AliDetector::SetTreeAddress()
548{
549 //
550 // Set branch address for the Hits and Digits Trees
551 //
552 TBranch *branch;
553 char branchname[20];
554 sprintf(branchname,"%s",GetName());
555 //
556 // Branch address for hit tree
557 TTree *treeH = gAlice->TreeH();
558 if (treeH && fHits) {
559 branch = treeH->GetBranch(branchname);
560 if (branch) branch->SetAddress(&fHits);
561 }
562 //
563 // Branch address for digit tree
564 TTree *treeD = gAlice->TreeD();
565 if (treeD && fDigits) {
566 branch = treeD->GetBranch(branchname);
567 if (branch) branch->SetAddress(&fDigits);
568 }
569}
570
fe4da5cc 571