CbmRoot
GeoReader.cxx
Go to the documentation of this file.
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 
7 #include "GeoReader.h"
8 #include "Station3D.h"
9 #include "Station4D.h"
10 #include "TClonesArray.h"
11 #include "TGeoBBox.h"
12 #include "TMath.h"
13 #include "Tracker.h"
14 
15 using namespace std;
16 
18  static CbmBinnedGeoReader* theInstance = 0;
19 
20  if (0 != theInstance) return theInstance;
21 
22  FairRootManager* ioman = FairRootManager::Instance();
23 
24  if (0 == ioman) return 0;
25 
26  theInstance = new CbmBinnedGeoReader(ioman, CbmBinnedTracker::Instance());
27  return theInstance;
28 }
29 
31  CbmBinnedTracker* tracker)
32  : fNavigator(0)
33  , fDetectorReaders()
34  , fTracker(tracker)
35  , fLastStationNumber(0) {
36  Int_t nofChildren = gGeoManager->GetTopNode()->GetNdaughters();
37 
38  for (Int_t i = 0; i < nofChildren; ++i) {
39  TGeoNode* child = gGeoManager->GetTopNode()->GetDaughter(i);
40  TString childName(child->GetName());
41  cout << "Have detecting system: " << childName.Data() << endl;
42  }
43 
44  fNavigator = gGeoManager->GetCurrentNavigator();
46 
47  if (settings->Use(ECbmModuleId::kSts)) {
49 
50  if (settings->IsConfiguring())
52  else
54  }
55 
56  if (settings->Use(ECbmModuleId::kRich)) {
58 
59  if (settings->IsConfiguring())
61  else
63  }
64 
65  if (settings->Use(ECbmModuleId::kMuch)) {
67 
68  if (settings->IsConfiguring())
70  else
72  }
73 
74  if (settings->Use(ECbmModuleId::kTrd)) {
76 
77  if (settings->IsConfiguring())
79  else
81  }
82 
83  if (settings->Use(ECbmModuleId::kTof)) {
85 
86  if (settings->IsConfiguring())
88  else
90  }
91 }
92 
94  const char* name,
95  list<TGeoNode*>& results) {
96  Int_t nofChildren = node->GetNdaughters();
97 
98  for (Int_t i = 0; i < nofChildren; ++i) {
99  TGeoNode* child = node->GetDaughter(i);
100  TString childName(child->GetName());
101 
102  if (childName.Contains(name, TString::kIgnoreCase))
103  results.push_back(child);
104  }
105 }
106 
107 Double_t cbmBinnedSOL = 0;
108 
112 
113  if (settings->Use(ECbmModuleId::kSts)) ReadDetector("sts");
114 
115  if (settings->Use(ECbmModuleId::kRich)) ReadDetector("rich");
116 
117  if (settings->Use(ECbmModuleId::kMuch)) ReadDetector("much");
118 
119  if (settings->Use(ECbmModuleId::kTrd)) ReadDetector("trd");
120 
121  if (settings->Use(ECbmModuleId::kTof)) ReadDetector("tof");
122 
123  ReadTarget();
124  cbmBinnedSOL = 1.e-7 * TMath::C(); // Speed of light in cm/ns
125 }
126 
127 void CbmBinnedGeoReader::ReadDetector(const char* name) {
128  (this->*fDetectorReaders[name])();
129 }
130 
131 static const int gNofZbins = 5;
132 static const int gNofYbins = 20;
133 static const int gNofXbins = 20;
134 static const int gNofTbins = 1;
135 
137  ECbmModuleId stationType,
138  TGeoNode* node,
139  CbmBinnedHitReader* hitReader,
140  list<const char*>::const_iterator stationPath,
141  list<const char*>::const_iterator stationPathEnd,
142  const std::list<const char*>& geoPath,
143  bool is4d) {
144  if (stationPath == stationPathEnd) {
145  //Double_t localCoords[3] = { 0, 0, 0 };
146  //Double_t globalCoords[3];
147  //gGeoManager->LocalToMaster(localCoords, globalCoords);
148  //Double_t z = globalCoords[2];
149  //const char* name1 = node->GetName();
150  //const char* name2 = gGeoManager->GetCurrentNode()->GetName();
151  Double_t left = 10000;
152  Double_t right = -10000;
153  Double_t top = -10000;
154  Double_t bottom = 10000;
155  Double_t front = 10000;
156  Double_t back = -10000;
157  HandleStation(node,
158  geoPath.begin(),
159  geoPath.end(),
160  left,
161  right,
162  top,
163  bottom,
164  front,
165  back);
166  CbmBinnedStation* station = 0;
167 
168  if (is4d) {
169  CbmBinned4DStation* station4d = new CbmBinned4DStation(
170  stationType, front, back, gNofZbins, gNofYbins, gNofXbins, gNofTbins);
171  station = station4d;
172  } else {
173  CbmBinned3DStation* station3d = new CbmBinned3DStation(
174  stationType, front, back, gNofYbins, gNofXbins, gNofTbins);
175  station = station3d;
176  }
177 
178  station->SetMinY(bottom);
179  station->SetMaxY(top);
180  station->SetMinX(left);
181  station->SetMaxX(right);
183 
184  if (!settings->IsConfiguring()) {
185  Double_t xScat = settings->GetXScat(fLastStationNumber);
186  station->SetScatX(xScat);
187  Double_t yScat = settings->GetYScat(fLastStationNumber);
188  station->SetScatY(yScat);
189  }
190 
191  /*if (!CbmBinnedSettings::Instance()->IsConfiguring())
192  {
193  station->SetDx(CbmBinnedSettings::Instance()->GetXError(fLastStationNumber));
194  station->SetDy(CbmBinnedSettings::Instance()->GetYError(fLastStationNumber));
195  station->SetDt(CbmBinnedSettings::Instance()->GetTError(fLastStationNumber));
196  }*/
197 
198  //station->SetScatX(gStationScats[fLastStationNumber][0]);
199  //station->SetScatY(gStationScats[fLastStationNumber][1]);
200 
201  //station->SetNofSigmaX(gStationNofSigmas[stationNumber][0]);
202  //station->SetNofSigmaY(gStationNofSigmas[stationNumber][1]);
203 
204  station->Init();
205  fTracker->AddStation(station);
206  hitReader->AddStation(station);
209  } else {
210  const char* name = *stationPath++;
211  list<TGeoNode*> subNodes;
212  FindGeoChild(node, name, subNodes);
213 
214  for (list<TGeoNode*>::iterator i = subNodes.begin(); i != subNodes.end();
215  ++i) {
216  fNavigator->CdDown(*i);
218  stationType, *i, hitReader, stationPath, stationPathEnd, geoPath);
219  fNavigator->CdUp();
220  }
221  }
222 }
223 
225  TGeoNode* node,
226  list<const char*>::const_iterator geoPath,
227  list<const char*>::const_iterator geoPathEnd,
228  Double_t& left,
229  Double_t& right,
230  Double_t& top,
231  Double_t& bottom,
232  Double_t& front,
233  Double_t& back) {
234  if (geoPath == geoPathEnd)
235  HandleActive(node, left, right, top, bottom, front, back);
236  else {
237  const char* name = *geoPath++;
238  list<TGeoNode*> subNodes;
239  FindGeoChild(node, name, subNodes);
240 
241  for (list<TGeoNode*>::iterator i = subNodes.begin(); i != subNodes.end();
242  ++i) {
243  fNavigator->CdDown(*i);
245  *i, geoPath, geoPathEnd, left, right, top, bottom, front, back);
246  fNavigator->CdUp();
247  }
248  }
249 }
250 
252  Double_t& left,
253  Double_t& right,
254  Double_t& top,
255  Double_t& bottom,
256  Double_t& front,
257  Double_t& back) {
258  TGeoBBox* pBox = static_cast<TGeoBBox*>(node->GetVolume()->GetShape());
259  pBox->ComputeBBox();
260 
261  for (int i = -1; i <= 1; i += 2) {
262  for (int j = -1; j <= 1; j += 2) {
263  for (int k = -1; k <= 1; k += 2) {
264  Double_t localCoords[3] = {
265  i * pBox->GetDX(), j * pBox->GetDY(), k * pBox->GetDZ()};
266  Double_t globalCoords[3];
267  gGeoManager->LocalToMaster(localCoords, globalCoords);
268 
269  if (left > globalCoords[0]) left = globalCoords[0];
270 
271  if (right < globalCoords[0]) right = globalCoords[0];
272 
273  if (bottom > globalCoords[1]) bottom = globalCoords[1];
274 
275  if (top < globalCoords[1]) top = globalCoords[1];
276 
277  if (front > globalCoords[2]) front = globalCoords[2];
278 
279  if (back < globalCoords[2]) back = globalCoords[2];
280  }
281  }
282  }
283 }
284 
286  list<const char*> stationPath = {"sts", "Station"};
287  list<const char*> geoPath = {"Ladder", "HalfLadder", "Module", "Sensor"};
288  gGeoManager->cd("/cave_1");
289  int firstStationNumber = fLastStationNumber;
290  const char* readerName =
291  CbmBinnedSettings::Instance()->IsConfiguring() ? "stsmc" : "sts";
293  gGeoManager->GetCurrentNode(),
294  CbmBinnedHitReader::Instance(readerName),
295  stationPath.begin(),
296  stationPath.end(),
297  geoPath);
299  - firstStationNumber);
300 }
301 
303  list<const char*> stationPath = {"rich"};
304  list<const char*> geoPath = {
305  "rich_smallprototype", "Box", "Gas", "PmtContainer", "Pmt", "pmt_pixel"};
306  gGeoManager->cd("/cave_1");
307  const char* readerName =
308  CbmBinnedSettings::Instance()->IsConfiguring() ? "richmc" : "rich";
310  gGeoManager->GetCurrentNode(),
311  CbmBinnedHitReader::Instance(readerName),
312  stationPath.begin(),
313  stationPath.end(),
314  geoPath);
315 }
316 
318  list<const char*> stationPath = {"much", "station", "muchstation", "layer"};
319  list<const char*> geoPath = {"active"};
320  gGeoManager->cd("/cave_1");
321  int firstStationNumber = fLastStationNumber;
322  const char* readerName =
323  CbmBinnedSettings::Instance()->IsConfiguring() ? "muchmc" : "much";
325  gGeoManager->GetCurrentNode(),
326  CbmBinnedHitReader::Instance(readerName),
327  stationPath.begin(),
328  stationPath.end(),
329  geoPath);
331  - firstStationNumber);
332 }
333 
335  list<const char*> stationPath = {"trd", "layer"};
336  list<const char*> geoPath = {"module", "gas"};
337  gGeoManager->cd("/cave_1");
338  int firstStationNumber = fLastStationNumber;
339  const char* readerName =
340  CbmBinnedSettings::Instance()->IsConfiguring() ? "trdmc" : "trd";
342  gGeoManager->GetCurrentNode(),
343  CbmBinnedHitReader::Instance(readerName),
344  stationPath.begin(),
345  stationPath.end(),
346  geoPath);
348  - firstStationNumber);
349 }
350 
352  list<const char*> stationPath = {"tof"};
353  list<const char*> geoPath = {"module", "gas_box", "counter"};
354  gGeoManager->cd("/cave_1");
355  const char* readerName =
356  CbmBinnedSettings::Instance()->IsConfiguring() ? "tofmc" : "tof";
358  gGeoManager->GetCurrentNode(),
359  CbmBinnedHitReader::Instance(readerName),
360  stationPath.begin(),
361  stationPath.end(),
362  geoPath,
363  true);
364 }
365 
367  gGeoManager->cd("/cave_1");
368  list<TGeoNode*> pipeNodes;
369  FindGeoChild(gGeoManager->GetCurrentNode(), "pipe", pipeNodes);
370 
371  for (list<TGeoNode*>::iterator i = pipeNodes.begin(); i != pipeNodes.end();
372  ++i) {
373  TGeoNode* pipeNode = *i;
374  fNavigator->CdDown(pipeNode);
375  list<TGeoNode*> pipeVacNodes;
376  FindGeoChild(pipeNode, "pipevac", pipeVacNodes);
377 
378  for (list<TGeoNode*>::iterator j = pipeVacNodes.begin();
379  j != pipeVacNodes.end();
380  ++j) {
381  TGeoNode* pipeVacNode = *j;
382  fNavigator->CdDown(pipeVacNode);
383  list<TGeoNode*> targetNodes;
384  FindGeoChild(pipeVacNode, "target", targetNodes);
385 
386  for (list<TGeoNode*>::iterator k = targetNodes.begin();
387  k != targetNodes.end();
388  ++k) {
389  TGeoNode* targetNode = *k;
390  fNavigator->CdDown(targetNode);
391  Double_t localCoords[3] = {0, 0, 0};
392  Double_t globalCoords[3];
393  gGeoManager->LocalToMaster(localCoords, globalCoords);
394  //Double_t targetX = globalCoords[0]; (VF) unused
395  //Double_t targetY = globalCoords[1]; (VF) unused
396  //Double_t targetZ = globalCoords[2]; (VF) unused
397  TGeoBBox* targetBox =
398  static_cast<TGeoBBox*>(targetNode->GetVolume()->GetShape());
399  targetBox->ComputeBBox();
400  //Double_t targetDx = targetBox->GetDX(); (VF) unused
401  //Double_t targetDy = targetBox->GetDY(); (VF) unused
402  //Double_t targetDz = targetBox->GetDZ(); (VF) unused
403  fNavigator->CdUp();
404  }
405 
406  fNavigator->CdUp();
407  }
408 
409  fNavigator->CdUp();
410  }
411 
412  list<const char*> stsTest = {
413  "sts", "station", "ladder", "halfladder", "module", "sensor"};
414  list<TGeoNode*> stsTestResults;
415  FindNode(stsTest, stsTestResults);
416  //int nofStsSensors = stsTestResults.size(); (VF) unused
417 
418  /*
419  for (list<TGeoNode*>::iterator i = stsTestResults.begin(); i != stsTestResults.end(); ++i)
420  {
421  //TGeoNode* node = *i; (VF) unused
422  //const char* name = node->GetName(); (VF) unused
423  //TGeoVolume* vol = node->GetVolume(); (VF) unused
424  }
425 */
426 }
427 
428 void CbmBinnedGeoReader::FindNode(list<const char*> nodePath,
429  list<TGeoNode*>& results,
430  TGeoNode* rootNode) {
431  if (0 == rootNode) {
432  rootNode = gGeoManager->GetTopNode();
433  gGeoManager->CdTop();
434  }
435 
436  results.push_back(rootNode);
437 
438  for (list<const char*>::const_iterator i = nodePath.begin();
439  i != nodePath.end();
440  ++i) {
441  const char* name = *i;
442  list<TGeoNode*> work;
443 
444  for (list<TGeoNode*>::iterator j = results.begin(); j != results.end();
445  ++j) {
446  TGeoNode* node = *j;
447  FindGeoChild(node, name, work);
448  }
449 
450  results.clear();
451  results.splice(results.begin(), work);
452  }
453 }
CbmBinnedStation::SetScatX
void SetScatX(Double_t v)
Definition: Station.h:483
gNofZbins
static const int gNofZbins
Definition: GeoReader.cxx:131
CbmBinnedHitReader::AddStation
virtual void AddStation(CbmBinnedStation *station)
Definition: HitReader.h:38
CbmBinnedGeoReader::ReadMuch
void ReadMuch()
Definition: GeoReader.cxx:317
CbmBinnedGeoReader::fLastStationNumber
int fLastStationNumber
Definition: GeoReader.h:79
CbmBinnedGeoReader::FindNode
void FindNode(std::list< const char * > nodePath, std::list< TGeoNode * > &results, TGeoNode *rootNode=0)
Definition: GeoReader.cxx:428
CbmBinnedGeoReader::Instance
static CbmBinnedGeoReader * Instance()
Definition: GeoReader.cxx:17
CbmBinnedSettings::SetNofTrdStations
void SetNofTrdStations(Int_t v)
Definition: Settings.h:181
gNofTbins
static const int gNofTbins
Definition: GeoReader.cxx:134
CbmBinnedSettings::Use
bool Use(ECbmModuleId m) const
Definition: Settings.h:164
CbmBinnedSettings::SetNofStsStations
void SetNofStsStations(Int_t v)
Definition: Settings.h:177
CbmBinnedSettings::GetYScat
Double_t GetYScat(size_t stationNumber) const
Definition: Settings.h:199
CbmBinnedStation::SetMaxX
void SetMaxX(Double_t v)
Definition: Station.h:442
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
ECbmModuleId
ECbmModuleId
Definition: CbmDefs.h:33
CbmBinnedGeoReader::fNavigator
TGeoNavigator * fNavigator
Definition: GeoReader.h:76
Station4D.h
CbmBinnedGeoReader::ReadRich
void ReadRich()
Definition: GeoReader.cxx:302
ECbmModuleId::kTof
@ kTof
Time-of-flight Detector.
CbmBinnedGeoReader::fDetectorReaders
std::map< std::string, void(CbmBinnedGeoReader::*)()> fDetectorReaders
Definition: GeoReader.h:77
CbmBinnedStation::Init
virtual void Init()
Definition: Station.h:547
gNofYbins
static const int gNofYbins
Definition: GeoReader.cxx:132
CbmBinnedTracker::AddStation
void AddStation(CbmBinnedStation *station)
Definition: Tracker.h:147
CbmBinnedHitReader::Instance
static CbmBinnedHitReader * Instance()
Definition: HitReader.cxx:813
CbmBinnedHitReader::SetSettings
static void SetSettings(CbmBinnedSettings *v)
Definition: HitReader.h:31
CbmBinnedGeoReader::CbmBinnedGeoReader
CbmBinnedGeoReader(FairRootManager *, CbmBinnedTracker *tracker)
Definition: GeoReader.cxx:30
cbmBinnedSOL
Double_t cbmBinnedSOL
Definition: GeoReader.cxx:107
CbmBinnedHitReader
Definition: HitReader.h:26
CbmBinnedStation
Definition: Station.h:29
CbmBinnedSettings::Instance
static CbmBinnedSettings * Instance()
Definition: Settings.h:29
CbmBinnedSettings::IsConfiguring
bool IsConfiguring() const
Definition: Settings.h:160
CbmBinnedHitReader::AddReader
static void AddReader(const char *name)
Definition: HitReader.cxx:832
CbmBinnedStation::SetMinY
void SetMinY(Double_t v)
Definition: Station.h:439
CbmBinnedGeoReader::HandleActive
void HandleActive(TGeoNode *node, Double_t &left, Double_t &right, Double_t &top, Double_t &bottom, Double_t &front, Double_t &back)
Definition: GeoReader.cxx:251
CbmBinnedGeoReader::HandleStation
void HandleStation(TGeoNode *node, std::list< const char * >::const_iterator geoPath, std::list< const char * >::const_iterator geoPathEnd, Double_t &left, Double_t &right, Double_t &top, Double_t &bottom, Double_t &front, Double_t &back)
Definition: GeoReader.cxx:224
gNofXbins
static const int gNofXbins
Definition: GeoReader.cxx:133
ECbmModuleId::kRich
@ kRich
Ring-Imaging Cherenkov Detector.
CbmBinnedTracker::Instance
static CbmBinnedTracker * Instance()
Definition: Tracker.cxx:9
Tracker.h
CbmBinned3DStation
Definition: Station3D.h:21
CbmBinned4DStation
Definition: Station4D.h:19
CbmBinnedSettings::SetNofStations
void SetNofStations(Int_t v)
Definition: Settings.h:183
CbmBinnedTracker
Definition: Tracker.h:29
ECbmModuleId::kTrd
@ kTrd
Transition Radiation Detector.
CbmBinnedGeoReader::ReadTrd
void ReadTrd()
Definition: GeoReader.cxx:334
CbmBinnedGeoReader::fTracker
CbmBinnedTracker * fTracker
Definition: GeoReader.h:78
CbmBinnedSettings::GetXScat
Double_t GetXScat(size_t stationNumber) const
Definition: Settings.h:196
CbmBinnedGeoReader::FindGeoChild
void FindGeoChild(TGeoNode *node, const char *name, std::list< TGeoNode * > &results)
Definition: GeoReader.cxx:93
CbmBinnedGeoReader
Definition: GeoReader.h:27
CbmBinnedStation::SetScatY
void SetScatY(Double_t v)
Definition: Station.h:491
CbmBinnedGeoReader::Read
void Read()
Definition: GeoReader.cxx:109
CbmBinnedGeoReader::SearchStation
void SearchStation(ECbmModuleId stationType, TGeoNode *node, CbmBinnedHitReader *hitReader, std::list< const char * >::const_iterator stationPath, std::list< const char * >::const_iterator stationPathEnd, const std::list< const char * > &geoPath, bool is4d=false)
Definition: GeoReader.cxx:136
CbmBinnedGeoReader::ReadSts
void ReadSts()
Definition: GeoReader.cxx:285
CbmBinnedGeoReader::ReadDetector
void ReadDetector(const char *name)
Definition: GeoReader.cxx:127
Station3D.h
CbmBinnedSettings
Definition: Settings.h:27
ECbmModuleId::kMuch
@ kMuch
Muon detection system.
GeoReader.h
CbmBinnedStation::SetMaxY
void SetMaxY(Double_t v)
Definition: Station.h:440
CbmBinnedStation::SetMinX
void SetMinX(Double_t v)
Definition: Station.h:441
CbmBinnedSettings::SetNofMuchStations
void SetNofMuchStations(Int_t v)
Definition: Settings.h:179
ECbmModuleId::kSts
@ kSts
Silicon Tracking System.
CbmBinnedGeoReader::ReadTarget
void ReadTarget()
Definition: GeoReader.cxx:366
CbmBinnedGeoReader::ReadTof
void ReadTof()
Definition: GeoReader.cxx:351