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