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