LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
AuxDetGeometryCore.cxx
Go to the documentation of this file.
1 
9 // class header
11 
12 // lar includes
15 
16 // Framework includes
17 #include "cetlib_except/exception.h"
19 
20 // ROOT includes
21 #include <TGeoManager.h>
22 #include <TGeoNode.h>
23 #include <TGeoVolume.h>
24 #include <TGeoMatrix.h>
25 #include <TGeoBBox.h>
26 // #include <Rtypes.h>
27 
28 // C/C++ includes
29 #include <cstddef> // size_t
30 #include <cctype> // ::tolower()
31 #include <cmath> // std::abs() ...
32 #include <vector>
33 #include <algorithm> // std::for_each(), std::transform()
34 #include <utility> // std::swap()
35 #include <limits> // std::numeric_limits<>
36 #include <memory> // std::default_deleter<>
37 
38 
39 namespace geo {
40 
41  //......................................................................
42  // Constructor.
44  : fDetectorName(pset.get< std::string >("Name"))
45  {
46  std::transform(fDetectorName.begin(), fDetectorName.end(), fDetectorName.begin(), ::tolower);
47  } // AuxDetGeometryCore::AuxDetGeometryCore()
48 
49 
50  //......................................................................
52  {
53  ClearGeometry();
54  } // AuxDetGeometryCore::~AuxDetGeometryCore()
55 
56 
57  //......................................................................
58  void AuxDetGeometryCore::ApplyChannelMap(std::shared_ptr<geo::AuxDetChannelMapAlg> pChannelMap)
59  {
60  pChannelMap->Initialize(fGeoData);
61  fChannelMapAlg = pChannelMap;
62  } // AuxDetGeometryCore::ApplyChannelMap()
63 
64  //......................................................................
65  void AuxDetGeometryCore::LoadGeometryFile(std::string gdmlfile, std::string rootfile)
66  {
67 
68  if (gdmlfile.empty()) {
69  throw cet::exception("AuxDetGeometryCore") << "No GDML Geometry file specified!\n";
70  }
71 
72  if (rootfile.empty()) {
73  throw cet::exception("AuxDetGeometryCore") << "No ROOT Geometry file specified!\n";
74  }
75 
76  ClearGeometry();
77 
78  // Open the GDML file, and convert it into ROOT TGeoManager format.
79  // try to be efficient - if the GeometryCore object already imported
80  // the file, then the gGeoManager will be non-null. If not, import it.
81  // Then lock the gGeoManager to prevent future imports.
82  if( !gGeoManager ){
83  TGeoManager::Import(rootfile.c_str());
84  gGeoManager->LockGeometry();
85  }
86 
87  std::vector<const TGeoNode*> path(8);
88  path[0] = gGeoManager->GetTopNode();
89  FindAuxDet(path, 0);
90 
91  fGDMLfile = gdmlfile;
92  fROOTfile = rootfile;
93 
94  mf::LogInfo("AuxDetGeometryCore") << "New detector geometry loaded from "
95  << "\n\t" << fROOTfile
96  << "\n\t" << fGDMLfile << "\n";
97 
98  } // AuxDetGeometryCore::LoadGeometryFile()
99 
100  //......................................................................
102  {
103  // auxiliary detectors
104  std::for_each(AuxDets().begin(), AuxDets().end(), std::default_delete<AuxDetGeo>());
105  AuxDets().clear();
106 
107  } // AuxDetGeometryCore::ClearGeometry()
108 
109 
110  //......................................................................
111  unsigned int AuxDetGeometryCore::NAuxDetSensitive(size_t const& aid) const
112  {
113  if( aid > NAuxDets() - 1)
114  throw cet::exception("Geometry") << "Requested AuxDet index " << aid
115  << " is out of range: " << NAuxDets();
116 
117  return AuxDets()[aid]->NSensitiveVolume();
118  }
119 
120  //......................................................................
121  //
122  // Return the geometry description of the ith AuxDet.
123  //
124  // \param ad : input AuxDet number, starting from 0
125  // \returns AuxDet geometry for ith AuxDet
126  //
127  // \throws geo::Exception if "ad" is outside allowed range
128  //
129  const AuxDetGeo& AuxDetGeometryCore::AuxDet(unsigned int const ad) const
130  {
131  if(ad >= NAuxDets())
132  throw cet::exception("AuxDetGeometryCore") << "AuxDet "
133  << ad
134  << " does not exist\n";
135 
136  return *(AuxDets()[ad]);
137  }
138 
139 
140  //......................................................................
141  unsigned int AuxDetGeometryCore::FindAuxDetAtPosition(double const worldPos[3]) const
142  {
143  return fChannelMapAlg->NearestAuxDet(worldPos, AuxDets());
144  } // AuxDetGeometryCore::FindAuxDetAtPosition()
145 
146  //......................................................................
147  const AuxDetGeo& AuxDetGeometryCore::PositionToAuxDet(double const worldLoc[3],
148  unsigned int &ad) const
149  {
150  // locate the desired Auxiliary Detector
151  ad = this->FindAuxDetAtPosition(worldLoc);
152 
153  return this->AuxDet(ad);
154  }
155 
156  //......................................................................
158  size_t & adg,
159  size_t & sv) const
160  {
161  adg = this->FindAuxDetAtPosition(worldPos);
162  sv = fChannelMapAlg->NearestSensitiveAuxDet(worldPos, AuxDets(), adg);
163 
164  return;
165  } // AuxDetGeometryCore::FindAuxDetAtPosition()
166 
167  //......................................................................
169  size_t &ad,
170  size_t &sv) const
171  {
172  // locate the desired Auxiliary Detector
173  this->FindAuxDetSensitiveAtPosition(worldLoc, ad, sv);
174  return this->AuxDet(ad).SensitiveVolume(sv);
175  }
176 
177  //......................................................................
178  uint32_t AuxDetGeometryCore::PositionToAuxDetChannel(double const worldLoc[3],
179  size_t &ad,
180  size_t &sv) const
181  {
182  return fChannelMapAlg->PositionToAuxDetChannel(worldLoc, AuxDets(), ad, sv);
183  }
184 
185  //......................................................................
186  TVector3 AuxDetGeometryCore::AuxDetChannelToPosition(uint32_t const& channel,
187  std::string const& auxDetName) const
188  {
189  return fChannelMapAlg->AuxDetChannelToPosition(channel, auxDetName, AuxDets());
190  }
191 
192  //......................................................................
193  const AuxDetGeo& AuxDetGeometryCore::ChannelToAuxDet(std::string const& auxDetName,
194  uint32_t const& channel) const
195  {
196  size_t adIdx = fChannelMapAlg->ChannelToAuxDet(AuxDets(), auxDetName, channel);
197  return this->AuxDet(adIdx);
198  }
199 
200  //......................................................................
202  uint32_t const& channel) const
203  {
204  auto idx = fChannelMapAlg->ChannelToSensitiveAuxDet(AuxDets(), auxDetName, channel);
205  return this->AuxDet(idx.first).SensitiveVolume(idx.second);
206  }
207 
208  //......................................................................
209  void AuxDetGeometryCore::FindAuxDet(std::vector<const TGeoNode*>& path,
210  unsigned int depth)
211  {
212  const char* nm = path[depth]->GetName();
213  if( (strncmp(nm, "volAuxDet", 9) == 0) ){
214  this->MakeAuxDet(path, depth);
215  return;
216  }
217 
218  //explore the next layer down
219  unsigned int deeper = depth+1;
220  if(deeper >= path.size()){
221  throw cet::exception("AuxDetGeometryCore") << "exceeded maximum TGeoNode depth\n";
222  }
223 
224  const TGeoVolume *v = path[depth]->GetVolume();
225  int nd = v->GetNdaughters();
226  for(int i = 0; i < nd; ++i){
227  path[deeper] = v->GetNode(i);
228  this->FindAuxDet(path, deeper);
229  }
230 
231  }
232 
233  //......................................................................
234  void AuxDetGeometryCore::MakeAuxDet(std::vector<const TGeoNode*>& path, int depth)
235  {
236  AuxDets().push_back(new AuxDetGeo(path, depth));
237  }
238 
239 
240 } // namespace geo
void LoadGeometryFile(std::string gdmlfile, std::string rootfile)
Loads the geometry information from the specified files.
AuxDetGeo const & AuxDet(unsigned int const ad=0) const
Returns the specified auxiliary detector.
Encapsulate the geometry of the sensitive portion of an 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:159
void FindAuxDetSensitiveAtPosition(double const worldLoc[3], size_t &adg, size_t &sv) const
Fills the indices of the sensitive auxiliary detector at location.
std::string fDetectorName
Name of the detector.
uint32_t PositionToAuxDetChannel(double const worldLoc[3], size_t &ad, size_t &sv) const
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.
Access the description of auxiliary detector geometry.
std::shared_ptr< const geo::AuxDetChannelMapAlg > fChannelMapAlg
Object containing the channel to wire mapping.
unsigned int NAuxDets() const
Returns the number of auxiliary detectors.
const AuxDetSensitiveGeo & ChannelToAuxDetSensitive(std::string const &auxDetName, uint32_t const &channel) const
AuxDetList_t & AuxDets()
Return the internal auxiliary detectors list.
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
void MakeAuxDet(std::vector< const TGeoNode * > &path, int depth)
void ApplyChannelMap(std::shared_ptr< geo::AuxDetChannelMapAlg > pChannelMap)
Initializes the geometry to work with this channel map.
Encapsulate the geometry of an auxiliary detector.
AuxDetGeo const & PositionToAuxDet(double const worldLoc[3], unsigned int &ad) const
Returns the auxiliary detector at specified location.
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.
std::string fGDMLfile
path to geometry file used for Geant4 simulation
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
Namespace collecting geometry-related classes utilities.
const AuxDetSensitiveGeo & PositionToAuxDetSensitive(double const worldLoc[3], size_t &ad, size_t &sv) const
Returns the auxiliary detector at specified location.
unsigned int FindAuxDetAtPosition(double const worldLoc[3]) const
Returns the index of the auxiliary detector at specified location.
TVector3 AuxDetChannelToPosition(uint32_t const &channel, std::string const &auxDetName) const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void FindAuxDet(std::vector< const TGeoNode * > &path, unsigned int depth)