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