LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
AuxDetGeometryCore.cxx
Go to the documentation of this file.
1 
7 // class header
9 
10 // LArSoft includes
18 
19 // Framework includes
20 #include "cetlib_except/exception.h"
21 #include "fhiclcpp/types/Table.h"
23 
24 // ROOT includes
25 #include "TGeoManager.h"
26 #include "TROOT.h"
27 
28 // C/C++ includes
29 #include <algorithm> // std::for_each(), std::transform()
30 #include <cctype> // std::tolower()
31 #include <cstddef> // std::size_t
32 #include <memory>
33 #include <string>
34 
35 namespace geo {
36 
37  //......................................................................
38  // Constructor.
40  std::unique_ptr<AuxDetGeoObjectSorter> sorter,
41  std::unique_ptr<AuxDetInitializer> initializer)
42  : fSorter{std::move(sorter)}
43  , fInitializer{std::move(initializer)}
44  , fGDMLfile{lar::searchPathPlusRelative(pset.get<std::string>("RelativePath", ""),
45  pset.get<std::string>("GDML"))}
47  , fBuilderParameters(pset.get<fhicl::ParameterSet>("Builder", {}))
48  , fThrowIfAbsent(pset.get("ThrowIfAbsent", true))
49  {
50  std::transform(fDetectorName.begin(), fDetectorName.end(), fDetectorName.begin(), [](auto c) {
51  return std::tolower(c);
52  });
53 
55  }
56 
57  //......................................................................
59  {
60  auto initializers = fInitializer ? fInitializer->init(fAuxDets) : AuxDetReadoutInitializers{};
61  fReadoutGeom = std::make_unique<AuxDetReadoutGeom>(std::move(initializers));
62  }
63 
64  //......................................................................
66  {
67 
68  if (fGDMLfile.empty()) {
69  throw cet::exception("AuxDetGeometryCore") << "No GDML Geometry file specified!\n";
70  }
71 
72  (void)gROOT; // <= Can be removed once ROOT 6.26/08 is adopted
73 
74  // Open the GDML file, and convert it into ROOT TGeoManager format. Try to be
75  // efficient - if the GeometryCore object already imported the file, then the
76  // gGeoManager will be non-null. If not, import it. Then lock the gGeoManager to
77  // prevent future imports.
78  if (!gGeoManager) {
79  // [20210701, petrillo@slac.stanford.edu]
80  // same code, same comment as in `geo::GeometryCore::LoadGeometryFile()`.
81  TGeoManager::LockDefaultUnits(false);
82  TGeoManager::SetDefaultUnits(TGeoManager::kRootUnits);
83  TGeoManager::LockDefaultUnits(true);
84  TGeoManager::Import(fGDMLfile.c_str());
85  gGeoManager->LockGeometry();
86  }
87 
90  GeoNodePath path{gGeoManager->GetTopNode()};
91 
92  fAuxDets = builder.extractAuxiliaryDetectors(path);
93  if (fSorter) { fSorter->sort(fAuxDets); }
94 
96 
97  mf::LogInfo("AuxDetGeometryCore") << "New detector geometry loaded from\n\t" << fGDMLfile;
98  }
99 
100  //......................................................................
101  //
102  // Return the geometry description of the ith AuxDet.
103  //
104  // \param ad : input AuxDet number, starting from 0
105  // \returns AuxDet geometry for ith AuxDet
106  //
107  // \throws geo::Exception if "ad" is outside allowed range
108  //
109  AuxDetGeo const& AuxDetGeometryCore::AuxDet(std::size_t const ad) const
110  {
111  if (ad >= NAuxDets()) {
112  throw cet::exception("AuxDetGeometryCore") << "AuxDet " << ad << " does not exist\n";
113  }
114  return fAuxDets[ad];
115  }
116 
117  //......................................................................
118  std::size_t AuxDetGeometryCore::NAuxDetSensitive(std::size_t const aid) const
119  {
120  if (aid >= NAuxDets()) {
121  throw cet::exception("AuxDetGeometry")
122  << "Requested AuxDet index " << aid << " is out of range: " << NAuxDets();
123  }
124  return fAuxDets[aid].NSensitiveVolume();
125  }
126 
127  //......................................................................
128  std::size_t AuxDetGeometryCore::FindAuxDetAtPosition(Point_t const& point, double tolerance) const
129  {
130  return fReadoutGeom->NearestAuxDet(point, fAuxDets, tolerance, fThrowIfAbsent);
131  }
132 
133  //......................................................................
135  double tolerance) const
136  {
137  return AuxDet(FindAuxDetAtPosition(point, tolerance));
138  }
139 
140  //......................................................................
142  std::size_t& adg,
143  std::size_t& sv,
144  double tolerance) const
145  {
146  adg = FindAuxDetAtPosition(point, tolerance);
147  sv = fReadoutGeom->NearestSensitiveAuxDet(point, fAuxDets, tolerance, fThrowIfAbsent);
148  }
149 
150  //......................................................................
152  uint32_t const channel) const
153  {
154  return fReadoutGeom->AuxDetChannelToPosition(channel, auxDetName, fAuxDets);
155  }
156 
157  //......................................................................
159  std::string const& auxDetName,
160  uint32_t const channel) const
161  {
162  auto idx = fReadoutGeom->ChannelToSensitiveAuxDet(auxDetName, channel);
163  return AuxDet(idx.first).SensitiveVolume(idx.second);
164  }
165 
166 } // namespace geo
AuxDetGeo const & AuxDet(std::size_t const ad=0) const
Returns the specified auxiliary detector.
std::size_t FindAuxDetAtPosition(Point_t const &point, double tolerance=0) const
Returns the index of the auxiliary detector at specified location.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
AuxDetSensitiveGeo const & SensitiveVolume(size_t sv) const
Definition: AuxDetGeo.h:123
std::size_t NAuxDetSensitive(size_t ad) const
Returns the number of sensitive components of auxiliary detector.
Interface for geometry extractor classes.
Class representing a path in ROOT geometry.
Point_t AuxDetChannelToPosition(std::string const &auxDetName, uint32_t channel) const
std::size_t NAuxDets() const
Returns the number of auxiliary detectors.
std::unique_ptr< AuxDetReadoutGeom const > fReadoutGeom
Object containing the channel to wire mapping.
Access the description of auxiliary detector geometry.
std::string searchPathPlusRelative(std::string relativePath, std::string fileName)
AuxDets_t extractAuxiliaryDetectors(Path_t path) const
Looks for all auxiliary detectors under the specified path.
std::unique_ptr< AuxDetGeoObjectSorter > fSorter
fhicl::ParameterSet fBuilderParameters
Configuration of geometry builder.
Encapsulate the geometry of an auxiliary detector.
void FindAuxDetSensitiveAtPosition(Point_t const &point, std::size_t &adg, std::size_t &sv, double tolerance=0) const
Fills the indices of the sensitive auxiliary detector at location.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:180
std::string maybe_default_detector_name(fhicl::ParameterSet const &pset, std::string const &filename)
std::vector< AuxDetGeo > fAuxDets
AuxDetGeometryCore(fhicl::ParameterSet const &pset, std::unique_ptr< AuxDetGeoObjectSorter > sorter=nullptr, std::unique_ptr< AuxDetInitializer > initializer=nullptr)
Initialize geometry from a given configuration.
std::string fGDMLfile
path to geometry file used for Geant4 simulation
AuxDetGeo const & PositionToAuxDet(Point_t const &point, double tolerance=0.) const
Returns the auxiliary detector at specified location.
Representation of a node and its ancestry.
Definition: GeoNodePath.h:34
ROOT libraries.
Extracts of LArSoft geometry information from ROOT.
Interface to auxiliary-detector geometry for wire readouts. .
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::unique_ptr< AuxDetInitializer > fInitializer
AuxDetSensitiveGeo const & ChannelToAuxDetSensitive(std::string const &auxDetName, uint32_t channel) const