LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
AuxDetGeometryCore.cxx
Go to the documentation of this file.
1 
9 // class header
11 
12 // lar 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 
27 // C/C++ includes
28 #include <algorithm> // std::for_each(), std::transform()
29 #include <cctype> // ::tolower()
30 #include <cstddef> // size_t
31 #include <memory> // std::default_deleter<>
32 #include <string>
33 #include <utility> // std::swap()
34 #include <vector>
35 
36 namespace geo {
37 
38  //......................................................................
39  // Constructor.
41  : fDetectorName(pset.get<std::string>("Name"))
42  , fBuilderParameters(pset.get<fhicl::ParameterSet>("Builder", fhicl::ParameterSet()))
43  {
44  std::transform(fDetectorName.begin(), fDetectorName.end(), fDetectorName.begin(), ::tolower);
45  }
46 
47  //......................................................................
48  void AuxDetGeometryCore::ApplyChannelMap(std::unique_ptr<geo::AuxDetChannelMapAlg> pChannelMap)
49  {
50  pChannelMap->Initialize(fGeoData);
51  fChannelMapAlg = move(pChannelMap);
52  }
53 
54  //......................................................................
55  void AuxDetGeometryCore::LoadGeometryFile(std::string gdmlfile, std::string rootfile)
56  {
57 
58  if (gdmlfile.empty()) {
59  throw cet::exception("AuxDetGeometryCore") << "No GDML Geometry file specified!\n";
60  }
61 
62  if (rootfile.empty()) {
63  throw cet::exception("AuxDetGeometryCore") << "No ROOT Geometry file specified!\n";
64  }
65 
66  ClearGeometry();
67 
68  // Open the GDML file, and convert it into ROOT TGeoManager format.
69  // try to be efficient - if the GeometryCore object already imported
70  // the file, then the gGeoManager will be non-null. If not, import it.
71  // Then lock the gGeoManager to prevent future imports.
72  if (!gGeoManager) {
73  // [20210701, petrillo@slac.stanford.edu]
74  // same code, same comment as in `geo::GeometryCore::LoadGeometryFile()`.
75  TGeoManager::LockDefaultUnits(false);
76  TGeoManager::SetDefaultUnits(TGeoManager::kRootUnits);
77  TGeoManager::LockDefaultUnits(true);
78  TGeoManager::Import(rootfile.c_str());
79  gGeoManager->LockGeometry();
80  }
81 
84  geo::GeoNodePath path{gGeoManager->GetTopNode()};
85 
86  AuxDets() = builder.extractAuxiliaryDetectors(path);
87 
88  fGDMLfile = gdmlfile;
89  fROOTfile = rootfile;
90 
91  mf::LogInfo("AuxDetGeometryCore") << "New detector geometry loaded from "
92  << "\n\t" << fROOTfile << "\n\t" << fGDMLfile << "\n";
93 
94  } // AuxDetGeometryCore::LoadGeometryFile()
95 
96  //......................................................................
98  {
99  AuxDets().clear();
100  }
101 
102  //......................................................................
103  unsigned int AuxDetGeometryCore::NAuxDetSensitive(size_t const& aid) const
104  {
105  if (aid > NAuxDets() - 1)
106  throw cet::exception("Geometry")
107  << "Requested AuxDet index " << aid << " is out of range: " << NAuxDets();
108 
109  return AuxDets()[aid].NSensitiveVolume();
110  }
111 
112  //......................................................................
113  //
114  // Return the geometry description of the ith AuxDet.
115  //
116  // \param ad : input AuxDet number, starting from 0
117  // \returns AuxDet geometry for ith AuxDet
118  //
119  // \throws geo::Exception if "ad" is outside allowed range
120  //
121  const AuxDetGeo& AuxDetGeometryCore::AuxDet(unsigned int const ad) const
122  {
123  if (ad >= NAuxDets())
124  throw cet::exception("AuxDetGeometryCore") << "AuxDet " << ad << " does not exist\n";
125 
126  return AuxDets()[ad];
127  }
128 
129  //......................................................................
130  unsigned int AuxDetGeometryCore::FindAuxDetAtPosition(Point_t const& worldPos,
131  double tolerance) const
132  {
133  return fChannelMapAlg->NearestAuxDet(worldPos, AuxDets(), tolerance);
134  }
135 
136  //......................................................................
138  unsigned int& ad,
139  double tolerance) const
140  {
141  // locate the desired Auxiliary Detector
142  ad = FindAuxDetAtPosition(worldLoc, tolerance);
143  return AuxDet(ad);
144  }
145 
146  //......................................................................
148  size_t& adg,
149  size_t& sv,
150  double tolerance) const
151  {
152  adg = FindAuxDetAtPosition(worldPos, tolerance);
153  sv = fChannelMapAlg->NearestSensitiveAuxDet(worldPos, AuxDets(), adg, tolerance);
154  }
155 
156  //......................................................................
158  size_t& ad,
159  size_t& sv,
160  double tolerance) const
161  {
162  // locate the desired Auxiliary Detector
163  FindAuxDetSensitiveAtPosition(worldLoc, ad, sv, tolerance);
164  return AuxDet(ad).SensitiveVolume(sv);
165  }
166 
167  //......................................................................
169  size_t& ad,
170  size_t& sv) const
171  {
172  return fChannelMapAlg->PositionToAuxDetChannel(worldLoc, AuxDets(), ad, sv);
173  }
174 
175  //......................................................................
177  uint32_t const channel) const
178  {
179  return fChannelMapAlg->AuxDetChannelToPosition(channel, auxDetName, AuxDets());
180  }
181 
182  //......................................................................
183  AuxDetGeo const& AuxDetGeometryCore::ChannelToAuxDet(std::string const& auxDetName,
184  uint32_t const channel) const
185  {
186  size_t adIdx = fChannelMapAlg->ChannelToAuxDet(AuxDets(), auxDetName, channel);
187  return AuxDet(adIdx);
188  }
189 
190  //......................................................................
192  std::string const& auxDetName,
193  uint32_t const channel) const
194  {
195  auto idx = fChannelMapAlg->ChannelToSensitiveAuxDet(AuxDets(), auxDetName, channel);
196  return AuxDet(idx.first).SensitiveVolume(idx.second);
197  }
198 
199  //......................................................................
200 
201 } // namespace geo
void LoadGeometryFile(std::string gdmlfile, std::string rootfile)
Loads the geometry information from the specified files.
void ApplyChannelMap(std::unique_ptr< geo::AuxDetChannelMapAlg > pChannelMap)
Initializes the geometry to work with this channel map.
AuxDetGeo const & ChannelToAuxDet(std::string const &auxDetName, uint32_t channel) const
AuxDetGeo const & AuxDet(unsigned int const ad=0) const
Returns the specified auxiliary detector.
AuxDetGeometryData_t fGeoData
The detector description data.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
AuxDetSensitiveGeo const & SensitiveVolume(size_t sv) const
Definition: AuxDetGeo.h:143
std::string fDetectorName
Name of the detector.
Interface for geometry extractor classes.
STL namespace.
unsigned int NAuxDetSensitive(size_t const &aid) const
Returns the number of sensitive components of auxiliary detector.
Class representing a path in ROOT geometry.
Point_t AuxDetChannelToPosition(std::string const &auxDetName, uint32_t channel) const
virtual void Initialize(AuxDetGeometryData_t &geodata)=0
Access the description of auxiliary detector geometry.
void FindAuxDetSensitiveAtPosition(Point_t const &worldLoc, size_t &adg, size_t &sv, double tolerance=0) const
Fills the indices of the sensitive auxiliary detector at location.
unsigned int NAuxDets() const
Returns the number of auxiliary detectors.
unsigned int FindAuxDetAtPosition(Point_t const &worldLoc, double tolerance=0) const
Returns the index of the auxiliary detector at specified location.
AuxDets_t extractAuxiliaryDetectors(Path_t const &path)
Looks for all auxiliary detectors under the specified path.
parameter set interface
AuxDetList_t & AuxDets()
Return the internal auxiliary detectors list.
AuxDetGeo const & PositionToAuxDet(Point_t const &worldLoc, unsigned int &ad, double tolerance=0) const
Returns the auxiliary detector at specified location.
fhicl::ParameterSet fBuilderParameters
Configuration of geometry builder.
Encapsulate the geometry of an auxiliary detector.
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
Standard implementation of geometry extractor.
std::string fROOTfile
path to geometry file for geometry in GeometryCore
AuxDetSensitiveGeo const & PositionToAuxDetSensitive(Point_t const &worldLoc, size_t &ad, size_t &sv, double tolerance=0) const
Returns the auxiliary detector at specified location.
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
AuxDetGeometryCore(fhicl::ParameterSet const &pset)
Initialize geometry from a given configuration.
void ClearGeometry()
Deletes the detector geometry structures.
uint32_t PositionToAuxDetChannel(Point_t const &worldLoc, size_t &ad, size_t &sv) const
std::string fGDMLfile
path to geometry file used for Geant4 simulation
Representation of a node and its ancestry.
Definition: GeoNodePath.h:37
Namespace collecting geometry-related classes utilities.
Extracts of LArSoft geometry information from ROOT.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::unique_ptr< AuxDetChannelMapAlg const > fChannelMapAlg
Object containing the channel to wire mapping.
AuxDetSensitiveGeo const & ChannelToAuxDetSensitive(std::string const &auxDetName, uint32_t channel) const