HighLAND
GeometryManager.cxx
1 #include <iostream>
2 #include <vector>
3 #include <string>
4 #include <cstring>
5 #include <sstream>
6 #include <fstream>
7 #include <memory>
8 #include <iomanip>
9 #include <typeinfo>
10 #include <cmath>
11 #include "GeometryManager.hxx"
12 
13 //------ ROOT includes ---------
14 
15 #include <TGeoManager.h>
16 #include <TGeoNode.h>
17 #include <TGeoVolume.h>
18 #include <TGeoBBox.h>
19 #include <TVector3.h>
20 #include <TKey.h>
21 #include <TFile.h>
22 #include <TString.h>
23 #include <TPRegexp.h>
24 
25 #include <VersioningUtils.hxx>
26 #include <ND280AnalysisUtils.hxx>
27 #include <Parameters.hxx>
28 
29 /// The static member pointer to the singleton.
30 GeometryManager* GeometryManager::fGeometryManager = NULL;
31 
32 //*****************************************************************************
33 GeometryManager& ND::hgman(){
34  //*****************************************************************************
35 
36  return GeometryManager::Get();
37 }
38 
39 //*****************************************************************************
40 GeometryManager::GeometryManager(){
41  //*****************************************************************************
42 
43  _GeoManagers.clear();
44  _defaultFileName = "$(PSYCHEUTILSROOT)/data/v5r1p3-baseline-2010-11_geom-aa7ba9d3-c9bce01d-1965fe02-bb7afdbf-6c35814b.root";
45  _useDefaultGeometry = ND::params().GetParameterD("psycheND280Utils.Geometry.UseDefaultGeometry");
46  _currentGeomID=-1;
47 
48 
49  }
50 
51 //*****************************************************************************
53  //*****************************************************************************
54  if (!fGeometryManager) {
55  std::cout<<"Create a new GeometryManager object"<<std::endl;
56  fGeometryManager = new GeometryManager;
57  }
58 
59  return *fGeometryManager;
60 }
61 
62 //*****************************************************************************
63 bool GeometryManager::LoadGeometry(const std::string& file_name0, Int_t geomID, const std::string& geomDir0) {
64  //*****************************************************************************
65 
66  std::string file_name = file_name0;
67  std::string geomDir = geomDir0;
68  if (_useDefaultGeometry || file_name==""){
69  file_name = fGeometryManager->_defaultFileName;
70  geomDir = "";
71  geomID = 0;
72  }
73 
74  // If the requested geometry is already available just set its ID as current
75  if (geomID>=0 && geomID<(Int_t)(_GeoManagers.size())){
76  _currentGeomID = geomID;
77  return false;
78  }
79 
80  //get geometry from the input file
81  TFile* file = TFile::Open(file_name.c_str());
82  if(!file || !file->IsOpen())
83  throw BadRootFileException();
84 
85  // Go to the appropriate directory in the root file
86  file->cd(geomDir.c_str());
87 
88  //iterate through file contents
89  TIter next(file->GetDirectory(geomDir.c_str())->GetListOfKeys());
90 
91  // Find the right key.
92  TKey* defaultKey = NULL;
93  TKey* key;
94 
95  while ((key = dynamic_cast<TKey*>(next()))) {
96  if (!defaultKey && std::string(key->GetName()).find("ND280Geometry")!=std::string::npos) {
97  defaultKey = key;
98  }
99  }
100 
101  key = defaultKey;
102 
103  if (!key)
105 
106  // Don't load when the hash code already exists in the current geometry loaded: in this way just change the ID
107  /*
108  for (size_t i=0; i<_GeoManagers.size(); i++){
109  if (_GeoManagers[i]->GetName() == key->GetName()){
110  _currentGeomID = i;
111  return false;
112  }
113  }
114  */
115 
116  // Don't load when the hash code is the same
117  if (_currentGeomID>=0 && _currentGeomID<(Int_t)(_GeoManagers.size()) &&
118  _GeoManagers[_currentGeomID] && !std::strcmp(_GeoManagers[_currentGeomID]->GetName(), key->GetName())) return false;
119 
120  // Unprotect the geometry so we can load a new one.
121  if (gGeoManager) gGeoManager->UnlockGeometry();
122 
123  TGeoManager *saveGeom = gGeoManager;
124  TGeoManager *geom = dynamic_cast<TGeoManager*>(file->GetDirectory(geomDir.c_str())->Get(key->GetName()));
125  if (!geom) {
126  gGeoManager = saveGeom;
128  }
129 
130  if(!gGeoManager->GetCache()->HasIdArray())
131  gGeoManager->GetCache()->BuildIdArray();
132 
133  //gGeoManager->GetCache()->BuildInfoBranch();
134 
135  // deal with the top volume.
136  TGeoVolume* top = gGeoManager->GetTopVolume();
137  std::string topName(top->GetName());
138  if (topName != "t2k") {
139  std::cout<<"Geometry top volume has changed from t2k " << topName<<std::endl;
140  top = gGeoManager->GetVolume("t2k");
141  if (!top)
143 
144  std::cout<<"Resetting top volume to " << top->GetName()<<std::endl;
145  gGeoManager->SetTopVolume(top);
146  }
147 
148 
149  fGeometryManager->_GeoManagers.push_back(gGeoManager);
150 
151  gGeoManager->LockGeometry();
152 
153  file->Close();
154 
155  // increment the currentGeomID;
156  _currentGeomID=fGeometryManager->_GeoManagers.size()-1;
157 
158  std::cout << "GeometryManager::LoadGeometry(). New Geometry with ID "<< _currentGeomID << " loaded. " << std::endl;
159  std::cout << "GeometryManager::LoadGeometry(). Geometry Name = " << fGeometryManager->GeoManager()->GetName() << std::endl;
160 
161  if (ND::params().GetParameterI("psycheND280Utils.Geometry.DetectorDefinitionFromROOTGeometry"))
163 
164  return true;
165 }
166 
167 //*****************************************************************************
168 void GeometryManager::InitializeGeometry(bool IsMC) const {
169  //*****************************************************************************
170  // ECal volumes has significant data/MC differences, up to ~3-4 cm for prod 6 (alignment applied but as-built geometry
171  // has not yet been changed)
172  // so set the appropriate values (substitute MC with data) when needed
173 
174  if (IsMC)
175  return;
176 
177  // only prod6 should be affected
178  if (!versionUtils::prod6_corrections)
179  return;
180 
181  anaUtils::CopyArray(DetDef::tecalLmin_p6_data, DetDef::tecalLmin, 3);
182 
183  anaUtils::CopyArray(DetDef::tecalLmax_p6_data, DetDef::tecalLmax, 3);
184 
185  anaUtils::CopyArray(DetDef::tecalRmin_p6_data, DetDef::tecalRmin, 3);
186 
187  anaUtils::CopyArray(DetDef::tecalRmax_p6_data, DetDef::tecalRmax, 3);
188 
189  anaUtils::CopyArray(DetDef::tecalTLmin_p6_data, DetDef::tecalTLmin, 3);
190 
191  anaUtils::CopyArray(DetDef::tecalTLmax_p6_data, DetDef::tecalTLmax, 3);
192 
193  anaUtils::CopyArray(DetDef::tecalTRmin_p6_data, DetDef::tecalTRmin, 3);
194 
195  anaUtils::CopyArray(DetDef::tecalTRmax_p6_data, DetDef::tecalTRmax, 3);
196 
197  anaUtils::CopyArray(DetDef::tecalBLmin_p6_data, DetDef::tecalBLmin, 3);
198 
199  anaUtils::CopyArray(DetDef::tecalBLmax_p6_data, DetDef::tecalBLmax, 3);
200 
201  anaUtils::CopyArray(DetDef::tecalBRmin_p6_data, DetDef::tecalBRmin, 3);
202 
203  anaUtils::CopyArray(DetDef::tecalBRmax_p6_data, DetDef::tecalBRmax, 3);
204 
205  return;
206 
207 }
208 
209 
210 //*****************************************************************************
212  //*****************************************************************************
213 
214  std::cout << "GeometryManager::InitializeDetectorDefinitionFromROOTGeometry(). Overwrite DetectorDefinition values with ROOT geometry !!!!" << std::endl;
215 
216  FillVolumesWithGeometryLoop();
217 
218  if (ND::params().GetParameterI("psycheND280Utils.Geometry.DetectorDefinitionFromROOTGeometry.FillFGDInfo"))
220 
221 
222  /*
223  // Get the FGD1 boundaries from the ROOT geometry
224  SetDetectorBoundaries("FGD1",DetDef::fgd1min, DetDef::fgd1max,
225  "/t2k_1/OA_0/Magnet_0/Basket_0/Tracker_0/FGD1_0/ScintX_0",
226  "/t2k_1/OA_0/Magnet_0/Basket_0/Tracker_0/FGD1_0/ScintY_14");
227 
228  // Get the FGD2 boundaries from the ROOT geometry
229  SetDetectorBoundaries("FGD2", DetDef::fgd2min, DetDef::fgd2max,
230  "/t2k_1/OA_0/Magnet_0/Basket_0/Tracker_0/FGD2_0/ScintX_0",
231  "/t2k_1/OA_0/Magnet_0/Basket_0/Tracker_0/FGD2_0/ScintY_6");
232 
233  // Get the DSECAL boundaries from the ROOT geometry
234  SetDetectorBoundaries("DsECAL", DetDef::dsecalmin, DetDef::dsecalmax, "/t2k_1/OA_0/Magnet_0/Basket_0/DsECal_0/Active_0");
235 
236  // Get the TrECAL Right boundaries from the ROOT geometry
237  SetDetectorBoundaries("TrECAL R", DetDef::tecalRmin, DetDef::tecalRmax, "/t2k_1/OA_0/Magnet_0/RightClam_0/BrlECal_1/Side_0/Active_0");
238 
239  // Get the TrECAL Left boundaries from the ROOT geometry
240  SetDetectorBoundaries("TrECAL L", DetDef::tecalLmin, DetDef::tecalLmax, "/t2k_1/OA_0/Magnet_0/LeftClam_0/BrlECal_1/Side_0/Active_0");
241 
242  // Get the TrECAL Top Right boundaries from the ROOT geometry
243  SetDetectorBoundaries("TrECAL TR", DetDef::tecalRmin, DetDef::tecalRmax, "/t2k_1/OA_0/Magnet_0/RightClam_0/BrlECal_0/Top_0/Active_0");
244 
245  // Get the TrECAL Top Left boundaries from the ROOT geometry
246  SetDetectorBoundaries("TrECAL TL", DetDef::tecalTLmin, DetDef::tecalTLmax, "/t2k_1/OA_0/Magnet_0/LeftClam_0/BrlECal_0/Top_0/Active_0");
247 
248  // Get the TrECAL Bottom Right boundaries from the ROOT geometry
249  SetDetectorBoundaries("TrECAL BR", DetDef::tecalRmin, DetDef::tecalRmax, "/t2k_1/OA_0/Magnet_0/RightClam_0/BrlECal_2/Bottom_0/Active_0");
250 
251  // Get the TrECAL Bottom Left boundaries from the ROOT geometry
252  SetDetectorBoundaries("TrECAL BL", DetDef::tecalBLmin, DetDef::tecalBLmax, "/t2k_1/OA_0/Magnet_0/LeftClam_0/BrlECal_2/Bottom_0/Active_0");
253 
254  std::cout << "---------------------------------------------------------------------------------------" << std::endl;
255  */
256 }
257 
258 //*****************************************************************************
260  //*****************************************************************************
261 
262  std::string full_path1 = "/t2k_1/OA_0/Magnet_0/Basket_0/Tracker_0/FGD1_0/";
263  std::string full_path2 = "/t2k_1/OA_0/Magnet_0/Basket_0/Tracker_0/FGD2_0/";
264 
265  Double_t pos[3];
266  Double_t size[3];
267 
268  int index = 0;
269 
270  // FGD1
271  // loop through the layers, fill bars
272  for (int i=0; i<15; i++){
273  std::stringstream sstream;
274  sstream << i;
275 
276  // get two positions
277  // X layer
278  GetVolumeProperties(full_path1 + "ScintX_" + sstream.str(), pos, size);
279  DetDef::fgd1BarCenter[index++] = pos[2];
280 
281  // Y layer
282  GetVolumeProperties(full_path1 + "ScintY_" + sstream.str(), pos, size);
283  DetDef::fgd1BarCenter[index++] = pos[2];
284  }
285 
286  // FGD2
287  // loop through the layers, fill bars
288  for (int i=0; i<7; i++){
289  std::stringstream sstream;
290  sstream << i;
291 
292  // get two positions
293  // X layer
294  GetVolumeProperties(full_path2 + "ScintX_" + sstream.str(), pos, size);
295  DetDef::fgd2BarCenter[index++] = pos[2];
296 
297  // Y layer
298  GetVolumeProperties(full_path2 + "ScintY_" + sstream.str(), pos, size);
299  DetDef::fgd2BarCenter[index++] = pos[2];
300  }
301 
302  // water bags
303  for (int i=0; i<6; i++){
304  std::stringstream sstream;
305  sstream << i;
306 
307  GetVolumeProperties(full_path2 + "WaterGap_" + sstream.str(), pos, size);
308  DetDef::fgd2WaterCenter[i] = pos[2];
309 
310  }
311 
312  //various module vars
313 
314  // bar width in Z
315  GetVolumeProperties(full_path2 + "ScintX_0/Bar_0", pos, size);
316  DetDef::fgdXYBarWidth = 2*fabs(size[2]);
317 
318  // glue between X and Y layers
319  GetVolumeProperties(full_path2 + "GlueGap1_0", pos, size);
320  DetDef::fgdXYGlueWidth = 2*fabs(size[2]);
321 
322  // glue before/after X/Y layers
323  GetVolumeProperties(full_path2 + "GlueGap2_0", pos, size);
324  DetDef::fgdXYMiddleGlueWidth = 2*fabs(size[2]);
325 
326  // glue for water bags
327  GetVolumeProperties(full_path2 + "GlueGap3_0", pos, size);
328  DetDef::fgdWaterGlueWidth = 2*fabs(size[2]);
329 
330  // air before/after X/Y layers
331  GetVolumeProperties(full_path2 + "AirGap1_0", pos, size);
332  DetDef::fgdXYAirWidth = 2*fabs(size[2]);
333 
334  // air before/after water bags
335  GetVolumeProperties(full_path2 + "AirGap2_0", pos, size);
336  DetDef::fgdWaterAirWidth = 2*fabs(size[2]);
337 
338  // G10 skin before/after X/Y layers
339  GetVolumeProperties(full_path2 + "G10Gap_0", pos, size);
340  DetDef::fgdXYSkinWidth = 2*fabs(size[2]);
341 
342  // polypropelene skin
343  GetVolumeProperties(full_path2 + "PropyleneGap_0", pos, size);
344  DetDef::fgdWaterSkinWidth = 2*fabs(size[2]);
345 
346  // water bag
347  GetVolumeProperties(full_path2 + "WaterGap_0", pos, size);
348  DetDef::fgdWaterPCWidth = 2*fabs(size[2]);
349 
350  // XY module = G10_sheets + glue + X layer + glue + Y layer + glue + G10_sheets
351  DetDef::fgdXYModuleWidth = DetDef::fgdXYSkinWidth + DetDef::fgdXYGlueWidth + DetDef::fgdXYBarWidth +
352  DetDef::fgdXYMiddleGlueWidth + DetDef::fgdXYBarWidth + DetDef::fgdXYGlueWidth + DetDef::fgdXYSkinWidth;
353 
354  // water module = polypropylene + glue + water/PC(polycarbonate) + glue + polypropylene
355  DetDef::fgdWaterModuleWidth = DetDef::fgdWaterSkinWidth + DetDef::fgdWaterGlueWidth + DetDef::fgdWaterPCWidth +
356  DetDef::fgdWaterGlueWidth + DetDef::fgdWaterSkinWidth;
357 
358 
359  //dump the results
360  DetDef::DumpFGDInfo();
361 }
362 
363 //*****************************************************************************
364 void GeometryManager::GetVolumeProperties(const std::string& name, Double_t* pos, Double_t* size) const {
365  //*****************************************************************************
366 
367  TGeoManager* geom = fGeometryManager->GeoManager();
368  int ini_node = geom->GetCurrentNodeId();
369 
370  geom->cd(name.c_str());
371  TGeoNode* node = geom->GetCurrentNode();
372  TGeoVolume* volume = node->GetVolume();
373  TGeoBBox *shape = static_cast<TGeoBBox*>(volume->GetShape());
374 
375  double local[3] = {0,0,0};
376  geom->LocalToMaster(local,pos);
377 
378  Double_t size0[3];
379  size0[0] = shape->GetDX();
380  size0[1] = shape->GetDY();
381  size0[2] = shape->GetDZ();
382 
383 
384  while (geom->GetCurrentNodeId() > 1){
385 
386  node = geom->GetCurrentNode();
387 
388  const Double_t *rot = node->GetMatrix()->GetRotationMatrix();
389  for (int i=0;i<3;i++){
390  size[i]=0;
391  for (int j=0;j<3;j++){
392  size[i] += rot[i*3+j]*size0[j];
393  }
394  }
395 
396  for (int i=0;i<3;i++)
397  size0[i]=size[i];
398 
399  geom->CdUp();
400 
401  }
402 
403  geom->CdNode(ini_node);
404 
405 }
406 
407 //*****************************************************************************
408 void GeometryManager::SetDetectorBoundaries(const std::string& det_name, Float_t* det_min, Float_t* det_max,
409  const std::string& name1, const std::string& name2) const {
410  //*****************************************************************************
411 
412  double pos1[3];
413  double size1[3];
414 
415  double pos2[3];
416  double size2[3];
417 
418 
419  for (Int_t i=0;i<3;i++){
420  det_min[i]= 1e10;
421  det_max[i]=-1e10;
422  }
423 
424  double temp[4][3];
425 
426  fGeometryManager->GetVolumeProperties(name1,pos1,size1);
427  if (name2!="")
428  fGeometryManager->GetVolumeProperties(name2,pos2,size2);
429 
430  for (Int_t i=0;i<3;i++){
431  temp[0][i] = pos1[i]+size1[i];
432  temp[1][i] = pos1[i]-size1[i];
433 
434  for (Int_t j=0;j<2;j++){
435  if (temp[j][i]<det_min[i]) det_min[i]=temp[j][i];
436  if (temp[j][i]>det_max[i]) det_max[i]=temp[j][i];
437  }
438 
439  if (name2!=""){
440  temp[2][i] = pos2[i]+size2[i];
441  temp[3][i] = pos2[i]-size2[i];
442 
443  for (Int_t j=2;j<4;j++){
444  if (temp[j][i]<det_min[i]) det_min[i]=temp[j][i];
445  if (temp[j][i]>det_max[i]) det_max[i]=temp[j][i];
446  }
447  }
448 
449 
450  }
451 
452  char out[256];
453  sprintf(out," %-13s %10.3f %10.3f %10.3f %10.3f %10.3f %10.3f", det_name.c_str(), det_min[0], det_max[0], det_min[1], det_max[1], det_min[2], det_max[2]);
454  std::cout << out << std::endl;
455 
456 
457 }
458 
459 
460 //*****************************************************************************
461 void GeometryManager::FillVolumesWithGeometryLoop() const {
462  //*****************************************************************************
463 
464  //reset the geometries
465  ResetVolumeDefinitions();
466 
467  TGeoManager* geom = fGeometryManager->GeoManager();
468 
469  //push the current state into the stack
470  geom->PushPath();
471  //go to top volume
472  geom->CdTop();
473 
474  //navigate over geometry and build volumes
475  RecurseGeometry("");
476 
477  //return back the last pushed state
478  gGeoManager->PopPath();
479 
480  DetDef::DumpVolumes();
481 
482 
483 }
484 
485 //*****************************************************************************
486 void GeometryManager::RecurseGeometry(std::string name) const {
487  //*****************************************************************************
488  TGeoManager* geom = fGeometryManager->GeoManager();
489 
490  TGeoNode* node = geom->GetCurrentNode();
491  name = name + "/" + node->GetName();
492 
493  if (!VisitNode(name, node)) {
494  geom->CdUp();
495  return;
496  }
497 
498  // navigate through daughters
499  for (int i=0; i<node->GetNdaughters(); ++i) {
500  geom->CdDown(i);
501  RecurseGeometry(name);
502  }
503 
504  geom->CdUp();
505 }
506 
507 //*****************************************************************************
508 bool GeometryManager::VisitNode(const std::string& name, const TGeoNode* node) const {
509  //*****************************************************************************
510  TGeoManager* geom = fGeometryManager->GeoManager();
511  TGeoVolume *volume = node->GetVolume();
512  TGeoBBox* shape = dynamic_cast<TGeoBBox*>(volume->GetShape());
513 
514  Double_t high_local[3] = {shape->GetDX(), shape->GetDY(), shape->GetDZ()};
515  Double_t low_local[3] = {-high_local[0], -high_local[1], -high_local[2]};
516 
517  Double_t high_tmp[3];
518  Double_t low_tmp[3];
519 
520  geom->LocalToMaster(low_local, low_tmp);
521  geom->LocalToMaster(high_local, high_tmp);
522 
523  Float_t high[3];
524  Float_t low[3];
525 
526  std::copy(low_tmp, low_tmp + 3, low);
527  std::copy(high_tmp, high_tmp + 3, high);
528 
529  //Tracker overall envelop
530  if (name.find("FGD") != std::string::npos
531  || name.find("TPC") != std::string::npos){
532  UpdateVolumeBound(DetDef::trackerAllmin, DetDef::trackerAllmax, low, high);
533  }
534 
535  //P0D
536  //ToDo: review
537  if (name.find("P0D_") != std::string::npos
538  && name.find("Bar_") != std::string::npos) {
539  UpdateVolumeBound(DetDef::p0dmin, DetDef::p0dmax, low, high);
540  return false;
541  }
542 
543  //TPC
544  //Should be split into left and right across the cathode!!!
545  if (name.find("TPC1") != std::string::npos
546  // && name.find("Drift") != std::string::npos) {
547  ){
548  UpdateVolumeBound(DetDef::tpc1min, DetDef::tpc1max, low, high);
549  return false;
550  }
551  if (name.find("TPC2") != std::string::npos
552  // && name.find("Drift") != std::string::npos) {
553  ){
554  UpdateVolumeBound(DetDef::tpc2min, DetDef::tpc2max, low, high);
555  return false;
556  }
557  if (name.find("TPC3") != std::string::npos
558  // && name.find("Drift") != std::string::npos) {
559  ){
560  UpdateVolumeBound(DetDef::tpc3min, DetDef::tpc3max, low, high);
561  return false;
562  }
563 
564  //FGD1
565  if (name.find("FGD1") != std::string::npos
566  && name.find("/Scint") != std::string::npos) {
567  UpdateVolumeBound(DetDef::fgd1min, DetDef::fgd1max, low, high);
568  return false;
569  }
570 
571  //FGD2
572  if (name.find("FGD2") != std::string::npos
573  && name.find("/Scint") != std::string::npos) {
574  UpdateVolumeBound(DetDef::fgd2min, DetDef::fgd2max, low, high);
575  return false;
576  }
577 
578  //DsECal
579  if (name.find("DsECal") != std::string::npos
580  && name.find("/Active") != std::string::npos) {
581  UpdateVolumeBound(DetDef::dsecalmin, DetDef::dsecalmax, low, high);
582  return false;
583  }
584 
585  //P0DECal
586  if (name.find("/LeftClam_") != std::string::npos
587  && name.find("/P0DECal_") != std::string::npos
588  && name.find("/Top_") != std::string::npos
589  && name.find("/Active") != std::string::npos) {
590  UpdateVolumeBound(DetDef::pecalTLmin, DetDef::pecalTLmax, low, high);
591  return false;
592  }
593  if (name.find("/LeftClam_") != std::string::npos
594  && name.find("/P0DECal_") != std::string::npos
595  && name.find("/Side_") != std::string::npos
596  && name.find("/Active") != std::string::npos) {
597  UpdateVolumeBound(DetDef::pecalLmin, DetDef::pecalLmax, low, high);
598  return false;
599  }
600  if (name.find("/LeftClam_") != std::string::npos
601  && name.find("/P0DECal_") != std::string::npos
602  && name.find("/Bottom_") != std::string::npos
603  && name.find("/Active_") != std::string::npos) {
604  UpdateVolumeBound(DetDef::pecalBLmin, DetDef::pecalBLmax, low, high);
605  return false;
606  }
607  if (name.find("/RightClam_") != std::string::npos
608  && name.find("/P0DECal_") != std::string::npos
609  && name.find("/Top_") != std::string::npos
610  && name.find("/Active") != std::string::npos) {
611  UpdateVolumeBound(DetDef::pecalTRmin, DetDef::pecalTRmax, low, high);
612  return false;
613  }
614  if (name.find("/RightClam_") != std::string::npos
615  && name.find("/P0DECal_") != std::string::npos
616  && name.find("/Side_") != std::string::npos
617  && name.find("/Active") != std::string::npos) {
618  UpdateVolumeBound(DetDef::pecalRmin, DetDef::pecalRmax, low, high);
619  return false;
620  }
621  if (name.find("/RightClam_") != std::string::npos
622  && name.find("/P0DECal_") != std::string::npos
623  && name.find("/Bottom_") != std::string::npos
624  && name.find("/Active_") != std::string::npos) {
625  UpdateVolumeBound(DetDef::pecalBRmin, DetDef::pecalBRmax, low, high);
626  return false;
627  }
628 
629  //BarrelECal
630  if (name.find("/LeftClam_") != std::string::npos
631  && name.find("/BrlECal_") != std::string::npos
632  && name.find("/Top_") != std::string::npos
633  && name.find("/Active") != std::string::npos) {
634  UpdateVolumeBound(DetDef::tecalTLmin, DetDef::tecalTLmax, low, high);
635  return false;
636  }
637  if (name.find("/LeftClam_") != std::string::npos
638  && name.find("/BrlECal_") != std::string::npos
639  && name.find("/Side_") != std::string::npos
640  && name.find("/Active") != std::string::npos) {
641  UpdateVolumeBound(DetDef::tecalLmin, DetDef::tecalLmax, low, high);
642  return false;
643  }
644  if (name.find("/LeftClam_") != std::string::npos
645  && name.find("/BrlECal_") != std::string::npos
646  && name.find("/Bottom_") != std::string::npos
647  && name.find("/Active_") != std::string::npos) {
648  UpdateVolumeBound(DetDef::tecalBLmin, DetDef::tecalBLmax, low, high);
649  return false;
650  }
651  if (name.find("/RightClam_") != std::string::npos
652  && name.find("/BrlECal_") != std::string::npos
653  && name.find("/Top_") != std::string::npos
654  && name.find("/Active") != std::string::npos) {
655  UpdateVolumeBound(DetDef::tecalTRmin, DetDef::tecalTRmax, low, high);
656  return false;
657  }
658  if (name.find("/RightClam_") != std::string::npos
659  && name.find("/BrlECal_") != std::string::npos
660  && name.find("/Side_") != std::string::npos
661  && name.find("/Active") != std::string::npos) {
662  UpdateVolumeBound(DetDef::tecalRmin, DetDef::tecalRmax, low, high);
663  return false;
664  }
665  if (name.find("/RightClam_") != std::string::npos
666  && name.find("/BrlECal_") != std::string::npos
667  && name.find("/Bottom_") != std::string::npos
668  && name.find("/Active_") != std::string::npos) {
669  UpdateVolumeBound(DetDef::tecalBRmin, DetDef::tecalBRmax, low, high);
670  return false;
671  }
672 
673  //SMRD
674  // Top and Bottom
675  if (name.find("LeftClam_") != std::string::npos
676  && ( name.find("0_pv") != std::string::npos
677  || name.find("FluxReturn_pv_0_") != std::string::npos)) {
678  UpdateVolumeBound(DetDef::smrdBLmin, DetDef::smrdBLmax, low, high);
679  return false;
680  }
681 
682  if (name.find("LeftClam_") != std::string::npos
683  && ( name.find("6_pv") != std::string::npos
684  || name.find("FluxReturn_pv_170_0") != std::string::npos)) {
685  UpdateVolumeBound(DetDef::smrdTLmin, DetDef::smrdTLmax, low, high);
686  return false;
687  }
688 
689  if (name.find("RightClam_") != std::string::npos
690  && ( name.find("0_pv") != std::string::npos
691  || name.find("FluxReturn_pv_0_") != std::string::npos)) {
692  UpdateVolumeBound(DetDef::smrdTRmin, DetDef::smrdTRmax, low, high);
693  return false;
694  }
695 
696  if (name.find("RightClam_") != std::string::npos
697  && ( name.find("6_pv") != std::string::npos
698  || name.find("FluxReturn_pv_170_0") != std::string::npos)) {
699  UpdateVolumeBound(DetDef::smrdBRmin, DetDef::smrdBRmax, low, high);
700  return false;
701  }
702 
703  // Sides
704  //Left
705  // three layers
706  if (name.find("LeftClam_") != std::string::npos
707  && ( name.find("MRDSide:4") != std::string::npos
708  || name.find("FluxReturn_pv_67_0") != std::string::npos)) {
709  UpdateVolumeBound(DetDef::smrd15Lmin, DetDef::smrd15Lmax, low, high);
710  return false;
711  }
712  //four layers
713  if (name.find("LeftClam_") != std::string::npos
714  && ( name.find("MRDSide:5") != std::string::npos
715  || name.find("FluxReturn_pv_67_5") != std::string::npos)) {
716  UpdateVolumeBound(DetDef::smrd6Lmin, DetDef::smrd6Lmax, low, high);
717  return false;
718  }
719  //6 layers
720  if (name.find("LeftClam_") != std::string::npos
721  && ( name.find("MRDSide:7") != std::string::npos
722  || name.find("FluxReturn_pv_67_6") != std::string::npos)) {
723  UpdateVolumeBound(DetDef::smrd78Lmin, DetDef::smrd78Lmax, low, high);
724  return false;
725  }
726 
727  // Right
728  // three layers
729  if (name.find("RightClam_") != std::string::npos
730  && ( name.find("MRDSide:4") != std::string::npos
731  || name.find("FluxReturn_pv_67_0") != std::string::npos)) {
732  UpdateVolumeBound(DetDef::smrd15Rmin, DetDef::smrd15Rmax, low, high);
733  return false;
734  }
735  //four layers
736  if (name.find("RightClam_") != std::string::npos
737  && ( name.find("MRDSide:5") != std::string::npos
738  || name.find("FluxReturn_pv_67_5") != std::string::npos)) {
739  UpdateVolumeBound(DetDef::smrd6Rmin, DetDef::smrd6Rmax, low, high);
740  return false;
741  }
742  //6 layers
743  if (name.find("RightClam_") != std::string::npos
744  && ( name.find("MRDSide:7") != std::string::npos
745  || name.find("FluxReturn_pv_67_6") != std::string::npos)) {
746  UpdateVolumeBound(DetDef::smrd78Rmin, DetDef::smrd78Rmax, low, high);
747  return false;
748  }
749 
750 
751  //keeping digging the geometry down the hierarchy
752  return true;
753 }
754 
755 //*****************************************************************************
756 void GeometryManager::UpdateVolumeBound(Float_t* detMin, Float_t* detMax, const Float_t* low, const Float_t* high) const{
757  //*****************************************************************************
758 
759  for (int i=0; i<3; i++){
760  //min
761  detMin[i] = std::min(detMin[i], low[i]);
762  detMin[i] = std::min(detMin[i], high[i]);
763  //max
764  detMax[i] = std::max(detMax[i], low[i]);
765  detMax[i] = std::max(detMax[i], high[i]);
766  }
767 
768 }
769 
770 //*****************************************************************************
771 void GeometryManager::ResetVolumeDefinitions() const {
772  //*****************************************************************************
773 
774  Float_t min[3] = {1e10, 1e10, 1e10};
775  Float_t max[3] = {-1e10, -1e10, -1e10};
776 
777  //FGD1
778  SetDetectorBoundaries(DetDef::fgd1min, DetDef::fgd1max, min, max);
779 
780  //FGD2
781  SetDetectorBoundaries(DetDef::fgd2min, DetDef::fgd2max, min, max);
782 
783  //TPC1
784  SetDetectorBoundaries(DetDef::tpc1min, DetDef::tpc1max, min, max);
785 
786  //TPC2
787  SetDetectorBoundaries(DetDef::tpc2min, DetDef::tpc2max, min, max);
788 
789  //TPC3
790  SetDetectorBoundaries(DetDef::tpc3min, DetDef::tpc3max, min, max);
791 
792  //P0D
793  SetDetectorBoundaries(DetDef::p0dmin, DetDef::p0dmax, min, max);
794 
795  //DsECal
796  SetDetectorBoundaries(DetDef::dsecalmin, DetDef::dsecalmax, min, max);
797 
798  //BarrelECal
799  SetDetectorBoundaries(DetDef::tecalLmin, DetDef::tecalLmax, min, max);
800  SetDetectorBoundaries(DetDef::tecalRmin, DetDef::tecalRmax, min, max);
801 
802  SetDetectorBoundaries(DetDef::tecalTLmin, DetDef::tecalTLmax, min, max);
803  SetDetectorBoundaries(DetDef::tecalTRmin, DetDef::tecalTRmax, min, max);
804 
805  SetDetectorBoundaries(DetDef::tecalBLmin, DetDef::tecalBLmax, min, max);
806  SetDetectorBoundaries(DetDef::tecalBRmin, DetDef::tecalBRmax, min, max);
807 
808  //P0DECal
809  SetDetectorBoundaries(DetDef::pecalLmin, DetDef::pecalLmax, min, max);
810  SetDetectorBoundaries(DetDef::pecalRmin, DetDef::pecalRmax, min, max);
811 
812  SetDetectorBoundaries(DetDef::pecalTLmin, DetDef::pecalTLmax, min, max);
813  SetDetectorBoundaries(DetDef::pecalTRmin, DetDef::pecalTRmax, min, max);
814 
815  SetDetectorBoundaries(DetDef::pecalBLmin, DetDef::pecalBLmax, min, max);
816  SetDetectorBoundaries(DetDef::pecalBRmin, DetDef::pecalBRmax, min, max);
817 
818  //SMRD
819  SetDetectorBoundaries(DetDef::smrdTLmin, DetDef::smrdTLmax, min, max);
820  SetDetectorBoundaries(DetDef::smrdTRmin, DetDef::smrdTRmax, min, max);
821 
822  SetDetectorBoundaries(DetDef::smrdBLmin, DetDef::smrdBLmax, min, max);
823  SetDetectorBoundaries(DetDef::smrdBRmin, DetDef::smrdBRmax, min, max);
824 
825 
826  SetDetectorBoundaries(DetDef::smrd15Lmin, DetDef::smrd15Lmax, min, max);
827  SetDetectorBoundaries(DetDef::smrd15Rmin, DetDef::smrd15Rmax, min, max);
828 
829  SetDetectorBoundaries(DetDef::smrd6Lmin, DetDef::smrd6Lmax, min, max);
830  SetDetectorBoundaries(DetDef::smrd6Rmin, DetDef::smrd6Rmax, min, max);
831 
832  SetDetectorBoundaries(DetDef::smrd78Lmin, DetDef::smrd78Lmax, min, max);
833  SetDetectorBoundaries(DetDef::smrd78Rmin, DetDef::smrd78Rmax, min, max);
834 
835 
836  //Tracker overall envelop
837  SetDetectorBoundaries(DetDef::trackerAllmin, DetDef::trackerAllmax, min, max);
838 
839 
840 }
void InitializeGeometry(bool IsMC=true) const
void SetDetectorBoundaries(const std::string &det_name, Float_t *det_min, Float_t *det_max, const std::string &name1, const std::string &name2="") const
Overrride the values in DetectorDefinion with the ones extracted from the ROOT geometry.
This exception is thrown when fail to open a file with geometry.
static GeometryManager & Get()
Get a pointer to the singleton instance of the geometry information.
double GetParameterD(std::string)
Get parameter. Value is returned as double.
Definition: Parameters.cxx:229
This exception is thrown when no geometry is found in a file.
void GetVolumeProperties(const std::string &name, Double_t *pos, Double_t *size) const
Get the volume position and size from the ROOT geometry.
void InitializeDetectorDefinitionFromROOTGeometry() const
Overrride the values in DetectorDefinion with the ones extracted from the ROOT geometry.
void FillFGDInfoFromROOTGeometry() const
Fill FGD info.
bool LoadGeometry(const std::string &file="", Int_t geomID=-1, const std::string &geomDir="")
Load the TGeoManager from the input root file. Returns true when the new geometry was loaded...