StandaloneGeometrySetup.cxx
Go to the documentation of this file.
1 /**
2  * @file StandaloneGeometrySetup.cxx
3  * @brief Utilities for one-line geometry initialization.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date June 22, 2017
6  *
7  */
8 
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 <string>
23 #include <utility> // std::forward()
24 #include <memory> // std::make_unique(), std::make_shared()
25 
26 
27 //------------------------------------------------------------------------------
28 std::unique_ptr<geo::GeometryCore>
30  (
31  fhicl::ParameterSet const& pset,
32  std::unique_ptr<geo::ChannelMapAlg> channelMap
33  )
34 {
35  auto const bForceReload = true;
36 
37  //
38  // create the geometry object
39  //
40  auto geom = std::make_unique<geo::GeometryCore>(pset);
41 
42  //
43  // extract of relevant configuration parameters
44  //
45  std::string relPath = pset.get<std::string>("RelativePath", "" );
46  const bool disableWiresInG4 = pset.get<bool> ("DisableWiresInG4", false);
47  const std::string GDMLFileName = pset.get<std::string>("GDML" );
48 // const std::string ROOTFileName = pset.get<std::string>("ROOT" );
49 
50  // add a final directory separator ("/") to relPath if not already there
51  if (!relPath.empty() && (relPath.back() != '/')) relPath += '/';
52 
53  // We are going to find files now.
54  // cet::search_path constructor decides if the constructor argument is a path
55  // or an environment variable (in this case, the latter)
56  cet::search_path sp("FW_SEARCH_PATH");
57 
58  //
59  // "GDML" file (for GEANT4)
60  //
61  // this is our hint for the path; start with the relative path:
62  std::string GDMLFilePathHint = relPath + GDMLFileName;
63 
64  // special if geometry with no wires is used for GEANT4 simulation
65  if(disableWiresInG4) {
66  GDMLFilePathHint.insert(
67  std::min(GDMLFilePathHint.rfind(".gdml"), GDMLFilePathHint.length()),
68  "_nowires"
69  );
70  } // if disable wires
71 
72  std::string GDMLFilePath;
73  if( !sp.find_file(GDMLFilePathHint, GDMLFilePath) ) {
74  throw cet::exception("StaticLoadGeometry")
75  << "Can't find geometry file '" << GDMLFilePathHint
76  << "' (for GEANT4)!\n";
77  }
78 
79  //
80  // "ROOT" file (for geometry)
81  //
82  // this is our hint for the path; start with the relative path:
83  std::string ROOTFilePathHint = relPath + GDMLFileName;
84 
85  std::string ROOTFilePath;
86  if( !sp.find_file(ROOTFilePathHint, ROOTFilePath) ) {
87  throw cet::exception("StaticLoadGeometry")
88  << "Can't find geometry file '" << ROOTFilePathHint
89  << "' (for geometry)!\n";
90  }
91 
92  //
93  // initialize the geometry with the files we have found
94  //
95  geom->LoadGeometryFile(GDMLFilePath, ROOTFilePath, bForceReload);
96 
97  //
98  // create and apply channel mapping
99  //
100 
101  geom->ApplyChannelMap(move(channelMap));
102 
103  return geom;
104 } // lar::standalone::SetupGeometryWithChannelMapping()
105 
106 
107 //------------------------------------------------------------------------------
Utilities for one-line geometry initialization.
std::string string
Definition: nybbler.cc:12
def move(depos, offset)
Definition: depos.py:107
T get(std::string const &key) const
Definition: ParameterSet.h:271
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
std::unique_ptr< geo::GeometryCore > SetupGeometryWithChannelMapping(fhicl::ParameterSet const &pset, std::unique_ptr< geo::ChannelMapAlg > channelMap)
Initializes a LArSoft geometry object.
std::string find_file(std::string const &filename) const
Definition: search_path.cc:96
Access the description of detector geometry.
Interface to algorithm class for a specific detector channel mapping.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33