LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
StandaloneGeometrySetup.cxx
Go to the documentation of this file.
1 
10 
11 // LArSoft libraries
14 
15 // CET libraries
16 #include "fhiclcpp/ParameterSet.h"
17 
18 // ROOT libraries
19 #include "TGeoManager.h"
20 
21 // C/C++ standard libraries
22 #include <memory> // std::make_unique(), std::make_shared()
23 #include <string>
24 #include <utility> // std::forward()
25 
26 //------------------------------------------------------------------------------
27 std::unique_ptr<geo::GeometryCore> lar::standalone::SetupGeometryWithChannelMapping(
28  fhicl::ParameterSet const& pset,
29  std::unique_ptr<geo::ChannelMapAlg> channelMap)
30 {
31  auto const bForceReload = true;
32 
33  //
34  // create the geometry object
35  //
36  auto geom = std::make_unique<geo::GeometryCore>(pset);
37 
38  //
39  // extract of relevant configuration parameters
40  //
41  std::string relPath = pset.get<std::string>("RelativePath", "");
42  const bool disableWiresInG4 = pset.get<bool>("DisableWiresInG4", false);
43  const std::string GDMLFileName = pset.get<std::string>("GDML");
44  // const std::string ROOTFileName = pset.get<std::string>("ROOT" );
45 
46  // add a final directory separator ("/") to relPath if not already there
47  if (!relPath.empty() && (relPath.back() != '/')) relPath += '/';
48 
49  // We are going to find files now.
50  // cet::search_path constructor decides if the constructor argument is a path
51  // or an environment variable (in this case, the latter)
52  cet::search_path sp("FW_SEARCH_PATH");
53 
54  //
55  // "GDML" file (for GEANT4)
56  //
57  // this is our hint for the path; start with the relative path:
58  std::string GDMLFilePathHint = relPath + GDMLFileName;
59 
60  // special if geometry with no wires is used for GEANT4 simulation
61  if (disableWiresInG4) {
62  GDMLFilePathHint.insert(std::min(GDMLFilePathHint.rfind(".gdml"), GDMLFilePathHint.length()),
63  "_nowires");
64  } // if disable wires
65 
66  std::string GDMLFilePath;
67  if (!sp.find_file(GDMLFilePathHint, GDMLFilePath)) {
68  throw cet::exception("StaticLoadGeometry")
69  << "Can't find geometry file '" << GDMLFilePathHint << "' (for GEANT4)!\n";
70  }
71 
72  //
73  // "ROOT" file (for geometry)
74  //
75  // this is our hint for the path; start with the relative path:
76  std::string ROOTFilePathHint = relPath + GDMLFileName;
77 
78  std::string ROOTFilePath;
79  if (!sp.find_file(ROOTFilePathHint, ROOTFilePath)) {
80  throw cet::exception("StaticLoadGeometry")
81  << "Can't find geometry file '" << ROOTFilePathHint << "' (for geometry)!\n";
82  }
83 
84  //
85  // initialize the geometry with the files we have found
86  //
87  geom->LoadGeometryFile(GDMLFilePath, ROOTFilePath, bForceReload);
88 
89  //
90  // create and apply channel mapping
91  //
92 
93  geom->ApplyChannelMap(move(channelMap));
94 
95  return geom;
96 } // lar::standalone::SetupGeometryWithChannelMapping()
97 
98 //------------------------------------------------------------------------------
Utilities for one-line geometry initialization.
Access the description of detector geometry.
T get(std::string const &key) const
Definition: ParameterSet.h:314
std::unique_ptr< geo::GeometryCore > SetupGeometryWithChannelMapping(fhicl::ParameterSet const &pset, std::unique_ptr< geo::ChannelMapAlg > channelMap)
Initializes a LArSoft geometry object.
Interface to algorithm class for a specific detector channel mapping.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33