All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AuxDetGeometryCore.h
Go to the documentation of this file.
1 /**
2  * @file AuxDetGeometryCore.h
3  * @brief Access the description of auxiliary detector geometry
4  * @author brebel@fnal.gov
5  * @see AuxDetGeometryCore.cxx
6  * @ingroup Geometry
7  */
8 #ifndef GEO_AUXDETGEOMETRYCORE_H
9 #define GEO_AUXDETGEOMETRYCORE_H
10 
11 // LArSoft libraries
14 
15 // Framework and infrastructure libraries
16 #include "fhiclcpp/ParameterSet.h"
17 
18 // ROOT libraries
19 #include <TVector3.h>
20 
21 // C/C++ standard libraries
22 #include <cstddef> // size_t
23 #include <cstdint> // uint32_t
24 #include <string>
25 #include <vector>
26 #include <memory> // std::shared_ptr<>
27 
28 /// Namespace collecting geometry-related classes utilities
29 namespace geo {
30 
31  // Forward declarations within namespace.
32  class AuxDetSensitiveGeo;
33 
34  /// Data in the geometry description
35  /// \ingroup Geometry
37 
38  /// Type of list of auxiliary detectors
39  using AuxDetList_t = std::vector<AuxDetGeo>;
40 
41  AuxDetList_t auxDets; ///< The auxiliary detectors
42 
43  }; // AuxDetGeometryData_t
44 
45 
46  /** **************************************************************************
47  * @brief Description of geometry of one set of auxiliary detectors
48  * @ingroup Geometry
49  *
50  * @note All lengths are specified in centimetres
51  *
52  *
53  * How to correctly instantiate a GeometryCore object
54  * ---------------------------------------------------
55  *
56  * Instantiation is a multi-step procedure:
57  * 1. construct a GeometryCore object (the "service provider"),
58  * with the full configuration; at this step, configuration is just stored
59  * 2. load a geometry with GeometryCore::LoadGeometryFile();
60  * this loads the detector geometry information
61  * 3. prepare a channel map algorithm object (might use for example
62  * GeometryCore::DetectorName() or the detector geometry from the
63  * newly created object, but any use of channel mapping related functions
64  * is forbidden and it would yield undefined behaviour (expected to be
65  * catastrophic)
66  * 4. acquire the channel mapping algorithm with
67  * GeometryCore::ApplyChannelMap(); at this point, the ChannelMapAlg object
68  * is asked to initialize itself and to perform whatever modifications to
69  * the geometry provider is needed.
70  *
71  * Step 3 (creation of the channel mapping algorithm object) can be performed
72  * at any time before step 4, provided that no GeometryCore instance is needed
73  * for it.
74  *
75  *
76  * Configuration parameters
77  * -------------------------
78  *
79  * - *Name* (string; mandatory): string identifying the detector; it can be
80  * different from the base name of the file used to initialize the geometry;
81  * standard names are recommended by each experiment.
82  * This name can be used, for example, to select which channel mapping
83  * algorithm to use.
84  * - *SurfaceY* (real; mandatory): depth of the detector, in centimetrs;
85  * see SurfaceY() for details
86  * - *MinWireZDist* (real; default: 3)
87  * - *PositionEpsilon* (real; default: 0.01%) set the default tolerance
88  * (see DefaultWiggle())
89  *
90  */
92  public:
93 
94  /// Type of list of auxiliary detectors
96 
97  /**
98  * @brief Initialize geometry from a given configuration
99  * @param pset configuration parameters
100  *
101  * This constructor does not load any geometry description.
102  * The next step is to do exactly that, by GeometryCore::LoadGeometryFile().
103  */
104  AuxDetGeometryCore(fhicl::ParameterSet const& pset);
105 
106  // You shall not copy or move or assign me!
107  AuxDetGeometryCore(AuxDetGeometryCore const&) = delete;
111 
112 
113  /**
114  * @brief Returns the full directory path to the geometry file source
115  * @return the full directory path to the geometry file source
116  *
117  * This is the full path of the source of the detector geometry GeometryCore
118  * relies on.
119  */
120  std::string ROOTFile() const { return fROOTfile; }
121 
122  /**
123  * @brief Returns the full directory path to the GDML file source
124  * @return the full directory path to the GDML file source
125  *
126  * This is the full path of the source of the detector geometry handed to
127  * the detector simulation (GEANT).
128  */
129  std::string GDMLFile() const { return fGDMLfile; }
130 
131 
132  /// Returns a string with the name of the detector, as configured
133  std::string DetectorName() const { return fDetectorName; }
134 
135  //
136  // object description and information
137  //
138 
139  /// @todo use a AutDetID_t instead of unsigned int?
140 
141  //
142  // group features
143  //
144 
145  /**
146  * @brief Returns the number of auxiliary detectors
147  *
148  * This method returns the total number of scintillator paddles
149  * (Auxiliary Detectors aka AuxDet) outside of the cryostat
150  *
151  * @todo Change return type to size_t
152  */
153  unsigned int NAuxDets() const { return AuxDets().size(); }
154 
155  /**
156  * @brief Returns the number of sensitive components of auxiliary detector
157  * @param aid ID of the auxiliary detector
158  * @return number of sensitive components in the auxiliary detector aid
159  * @throws cet::exception (category "Geometry") if aid does not exist
160  */
161  unsigned int NAuxDetSensitive(size_t const& aid) const;
162 
163  //
164  // access
165  //
166 
167  /// Returns the full list of pointer to the auxiliary detectors
168  std::vector<AuxDetGeo> const& AuxDetGeoVec() const { return AuxDets(); }
169 
170  /**
171  * @brief Returns the specified auxiliary detector
172  * @param ad the auxiliary detector index
173  * @return a constant reference to the specified auxiliary detector
174  *
175  * @todo what happens if it does not exist?
176  * @todo remove the default parameter?
177  */
178  AuxDetGeo const& AuxDet(unsigned int const ad = 0) const;
179 
180  /**
181  * @brief Returns the index of the auxiliary detector at specified location
182  * @param worldLoc 3D coordinates of the point (world reference frame)
183  * @return the index of the detector, or UINT_MAX if no detector is there
184  *
185  * @todo replace with numeric_limits<>?
186  */
187  unsigned int FindAuxDetAtPosition(double const worldLoc[3], double tolerance = 0) const;
188 
189  /**
190  * @brief Fills the indices of the sensitive auxiliary detector at location
191  * @param worldLoc 3D coordinates of the point (world reference frame)
192  * @param adg (output) auxiliary detector index
193  * @param sv (output) sensitive volume index
194  * @param tolerance tolerance (cm) for matches. Default 0.
195  */
196  void FindAuxDetSensitiveAtPosition(double const worldLoc[3],
197  size_t & adg,
198  size_t & sv,
199  double tolerance = 0) const;
200 
201  /**
202  * @brief Returns the auxiliary detector at specified location
203  * @param worldLoc 3D coordinates of the point (world reference frame)
204  * @param ad (output) the auxiliary detector index
205  * @param tolerance tolerance (cm) for matches. Default 0
206  * @return constant reference to AuxDetGeo object of the auxiliary detector
207  *
208  * @todo what happens if it does not exist?
209  */
210  AuxDetGeo const& PositionToAuxDet(double const worldLoc[3],
211  unsigned int &ad,
212  double tolerance = 0) const;
213 
214  /**
215  * @brief Returns the auxiliary detector at specified location
216  * @param worldLoc 3D coordinates of the point (world reference frame
217  * @param tolerance tolerance (cm) for matches. Default 0.
218  * @param ad (output) the auxiliary detector index
219  * @param sv (output) the auxiliary detector sensitive volume index
220  * @return reference to AuxDetSensitiveGeo object of the auxiliary detector
221  *
222  * @todo what happens if it does not exist?
223  */
224  const AuxDetSensitiveGeo& PositionToAuxDetSensitive(double const worldLoc[3],
225  size_t & ad,
226  size_t & sv,
227  double tolerance = 0) const;
228 
229  uint32_t PositionToAuxDetChannel(double const worldLoc[3],
230  size_t & ad,
231  size_t & sv) const;
232 
233  TVector3 AuxDetChannelToPosition(uint32_t const& channel,
234  std::string const& auxDetName) const;
235 
236 
237  const AuxDetGeo& ChannelToAuxDet(std::string const& auxDetName,
238  uint32_t const& channel) const; // return the AuxDetGeo for the given detector
239  // name and channel
240 
241  const AuxDetSensitiveGeo& ChannelToAuxDetSensitive(std::string const& auxDetName,
242  uint32_t const& channel) const; // return the AuxDetSensitiveGeo for the given
243 
244  /// @name Geometry initialization
245  /// @{
246 
247  /**
248  * @brief Loads the geometry information from the specified files
249  * @param gdmlfile path to file to be used for Geant4 simulation
250  * @param rootfile path to file for internal geometry representation
251  * @see ApplyChannelMap()
252  *
253  * Both paths must directly resolve to an available file, as no search
254  * is performed for them.
255  *
256  * The gdmlfile parameter does not have to necessarily be in GDML format,
257  * as long as it's something supported by Geant4. This file is not used by
258  * the geometry, but its path is provided on request by the simulation
259  * modules (see LArSoft `LArG4` module).
260  * The rootfile also does not need to be a ROOT file, but just anything
261  * that TGeoManager::Import() supports. This file is parsed immediately
262  * and the internal geometry representation is built out of it.
263  *
264  * @note After calling this method, the detector geometry information can
265  * be considered complete, but the geometry service provider is not fully
266  * initialized yet, since it's still necessary to provide or update the
267  * channel mapping.
268  */
269  void LoadGeometryFile(std::string gdmlfile, std::string rootfile);
270 
271 
272  /// Returns whether we have a channel map
273  bool hasAuxDetChannelMap() const { return bool(fChannelMapAlg); }
274 
275 
276  /**
277  * @brief Initializes the geometry to work with this channel map
278  * @param pChannelMap a pointer to the channel mapping algorithm to be used
279  * @see LoadGeometryFile()
280  *
281  * The specified channel mapping is used with this geometry.
282  * The algorithm object is asked and allowed to make the necessary
283  * modifications to the geometry description.
284  * These modifications typically involve some resorting of the objects.
285  *
286  * The ownership of the algorithm object is shared, usually with a calling
287  * framework: we maintain it alive as long as we need it (and no other code
288  * can delete it), and we delete it only if no other code is sharing the
289  * ownership.
290  *
291  * This method needs to be called after LoadGeometryFile() to complete the
292  * geometry initialization.
293  */
294  void ApplyChannelMap(std::unique_ptr<geo::AuxDetChannelMapAlg> pChannelMap);
295  /// @}
296 
297 
298  protected:
299 
300  /// Returns the object handling the channel map
302 
303  //@{
304  /// Return the internal auxiliary detectors list
306  AuxDetList_t const& AuxDets() const { return fGeoData.auxDets; }
307  //@}
308 
309  private:
310 
311  /// Deletes the detector geometry structures
312  void ClearGeometry();
313 
314  AuxDetGeometryData_t fGeoData; ///< The detector description data
315 
316  std::string fDetectorName; ///< Name of the detector.
317  std::string fGDMLfile; ///< path to geometry file used for Geant4 simulation
318  std::string fROOTfile; ///< path to geometry file for geometry in GeometryCore
319  fhicl::ParameterSet fBuilderParameters; ///< Configuration of geometry builder.
320  std::unique_ptr<const geo::AuxDetChannelMapAlg> fChannelMapAlg; ///< Object containing the channel to wire mapping
321  }; // class GeometryCore
322 
323 } // namespace geo
324 
325 
326 
327 
328 #endif // GEO_AUXDETGEOMETRYCORE_H
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::vector< AuxDetGeo > AuxDetList_t
Type of list of auxiliary detectors.
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
static constexpr bool
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.
std::string GDMLFile() const
Returns the full directory path to the GDML file source.
std::unique_ptr< const geo::AuxDetChannelMapAlg > fChannelMapAlg
Object containing the channel to wire mapping.
Description of geometry of one set of auxiliary detectors.
bool hasAuxDetChannelMap() const
Returns whether we have a channel map.
std::string ROOTFile() const
Returns the full directory path to the geometry file source.
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.
unsigned int FindAuxDetAtPosition(double const worldLoc[3], double tolerance=0) const
Returns the index of the auxiliary detector at specified location.
geo::AuxDetChannelMapAlg const * AuxDetChannelMap() const
Returns the object handling the channel map.
fhicl::ParameterSet fBuilderParameters
Configuration of geometry builder.
Encapsulate the geometry of an auxiliary detector.
AuxDetList_t auxDets
The auxiliary detectors.
std::string fROOTfile
path to geometry file for geometry in GeometryCore
AuxDetGeometryCore(fhicl::ParameterSet const &pset)
Initialize geometry from a given configuration.
std::vector< AuxDetGeo > const & AuxDetGeoVec() const
Returns the full list of pointer to the auxiliary detectors.
void ClearGeometry()
Deletes the detector geometry structures.
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
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
AuxDetGeometryCore & operator=(AuxDetGeometryCore const &)=delete
AuxDetGeo const & PositionToAuxDet(double const worldLoc[3], unsigned int &ad, double tolerance=0) const
Returns the auxiliary detector at specified location.
TVector3 AuxDetChannelToPosition(uint32_t const &channel, std::string const &auxDetName) const
AuxDetGeometryData_t::AuxDetList_t AuxDetList_t
Type of list of auxiliary detectors.
AuxDetList_t const & AuxDets() const