AuxDetGeo.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file larcorealg/Geometry/AuxDetGeo.h
3 /// \brief Encapsulate the geometry of an auxiliary detector
4 /// \ingroup Geometry
5 ///
6 /// \author miceli@fnal.gov
7 ////////////////////////////////////////////////////////////////////////
8 
9 #ifndef LARCOREALG_GEOMETRY_AUXDETGEO_H
10 #define LARCOREALG_GEOMETRY_AUXDETGEO_H
11 
12 // LArSoft libraries
19 
20 // ROOT libraries
21 #include "TGeoVolume.h"
22 #include "Math/GenVector/DisplacementVector3D.h"
23 #include "Math/GenVector/PositionVector3D.h"
24 
25 // C/C++ libraries
26 #include <stddef.h>
27 #include <string>
28 #include <vector>
29 #include <type_traits>
30 
31 class TGeoNode;
32 
33 namespace geo {
34 
35  class GeoObjectSorter;
36 
37  /// \ingroup Geometry
38  class AuxDetGeo {
39  public:
40 
41  /// Type of list of sensitive volumes.
42  using AuxDetSensitiveList_t = std::vector<geo::AuxDetSensitiveGeo>;
43 
44  /// @{
45  /**
46  * @name Types for geometry-local reference vectors.
47  *
48  * These types represents points and displacement vectors in the reference
49  * frame defined in the auxiliary detector geometry box from the GDML
50  * geometry description.
51  *
52  * No alias is explicitly defined for the LArSoft global vector types,
53  * `geo::Point_t` and `geo::Vector_t`.
54  *
55  * Remember the `LocalPoint_t` and `LocalVector_t` vectors from different
56  * instances of `geo::AuxDetGeo` have the same type but are not compatible.
57  */
58 
59  /// Tag for vectors in the "local" GDML coordinate frame of the
60  /// auxiliary detector.
62 
63  /// Type of points in the local GDML auxiliary detector frame.
65 
66  /// Type of displacement vectors in the local GDML auxiliary detector frame.
68 
69  ///@}
70 
71  AuxDetGeo(
72  TGeoNode const& node, geo::TransformationMatrix&& trans,
73  AuxDetSensitiveList_t&& sensitive
74  );
75 
76 
77  /**
78  * @brief Return the center position of an AuxDet.
79  * @param xyz _(output)_ the returned location: `{ x, y, z }` [cm]
80  * @param localz (default: `0`) distance along the length of the volume (z)
81  * [cm]
82  */
83  void GetCenter(double* xyz, double localz=0.0) const;
84 
85  /**
86  * @brief Returns the geometric center of the sensitive volume.
87  * @param localz (default: `0`) distance from the center along the length
88  * of the volume (z) [cm]
89  * @return the geometric center of the sensitive volume [cm]
90  */
91  geo::Point_t GetCenter(double localz = 0.0) const;
92 
93  /// Returns the unit normal vector to the detector.
95 
96  /// Fills the unit normal vector to the detector.
97  void GetNormalVector(double* xyzDir) const;
98 
99 
100  /// @{
101  /// @name Box geometry
102  double Length() const { return fLength; }
103  double HalfWidth1() const { return fHalfWidth1; }
104  double HalfWidth2() const { return fHalfWidth2; }
105  double HalfHeight() const { return fHalfHeight; }
106  const TGeoVolume* TotalVolume() const { return fTotalVolume; }
107  /// @}
108 
109  //@{
110  /// Returns the distance of `point` from the center of the detector.
112  { return (point - GetCenter()).R(); }
113  geo::Length_t DistanceToPoint(double const* point) const;
114  //@}
115 
116  /// @{
117  /// @name Coordinate transformation
118 
119  /// Transform point from local auxiliary detector frame to world frame.
120  void LocalToWorld(const double* auxdet, double* world) const
121  { fTrans.LocalToWorld(auxdet, world); }
122 
123  /// Transform point from local auxiliary detector frame to world frame.
125  { return fTrans.toWorldCoords(local); }
126 
127  /// Transform direction vector from local to world.
128  void LocalToWorldVect(const double* auxdet, double* world) const
129  { fTrans.LocalToWorldVect(auxdet, world); }
130 
131  /// Transform direction vector from local to world.
133  { return fTrans.toWorldCoords(local); }
134 
135  /// Transform point from world frame to local auxiliary detector frame.
136  void WorldToLocal(const double* world, double* auxdet) const
137  { fTrans.WorldToLocal(world, auxdet); }
138 
139  /// Transform point from world frame to local auxiliary detector frame.
141  { return fTrans.toLocalCoords(world); }
142 
143  /// Transform direction vector from world to local.
144  void WorldToLocalVect(const double* world, double* auxdet) const
145  { fTrans.WorldToLocalVect(world, auxdet); }
146 
147  /// Transform direction vector from world to local.
149  { return fTrans.toLocalCoords(world); }
150 
151  /// @}
152 
153 
154  std::string Name() const { return fTotalVolume->GetName(); }
155 
156  /// @{
157  /// @name Access to the sensitive volumes in the detector
158 
159  //@{
160  std::size_t FindSensitiveVolume(geo::Point_t const& point) const;
161  /// @deprecated Use the version with `geo::Point_t` argument instead
162  std::size_t FindSensitiveVolume(double const worldLoc[3]) const;
163  //@}
164  //@{
166  (geo::Point_t const& point, size_t& sv) const;
167  /// @deprecated Use the version with `geo::Point_t` argument instead
169  (double const worldLoc[3], size_t& sv) const;
170  //@}
171  AuxDetSensitiveGeo const& SensitiveVolume(size_t sv) const { return fSensitive[sv]; }
172  size_t NSensitiveVolume() const { return fSensitive.size(); }
173 
174  /// @}
175 
176  void SortSubVolumes(geo::GeoObjectSorter const& sorter);
177 
178 
179  /**
180  * @brief Prints information about this auxiliary detector.
181  * @tparam Stream type of output stream to use
182  * @param out stream to send the information to
183  * @param indent prepend each line with this string
184  * @param verbosity amount of information printed
185  *
186  * Note that the first line out the output is _not_ indented.
187  *
188  * Verbosity levels
189  * -----------------
190  *
191  * * 0: only detector name
192  * * 1 _(default)_: also center
193  * * 2: also size
194  * * 3: also number of sensitive detectors
195  * * 4: also normal direction
196  *
197  * The constant `MaxVerbosity` is set to the highest supported verbosity
198  * level.
199  */
200  template <typename Stream>
201  void PrintAuxDetInfo
202  (Stream&& out, std::string indent = "", unsigned int verbosity = 1) const;
203 
204  /**
205  * @brief Returns a string with auxiliary detector information.
206  * @see `PrintAuxDetInfo()`
207  *
208  * The arguments and provided information are the same as in
209  * `PrintAuxDetInfo()`.
210  */
212  (std::string indent = "", unsigned int verbosity = 1) const;
213 
214  /// Maximum verbosity supported by `PrintAuxDetInfo()`.
215  static constexpr unsigned int MaxVerbosity = 4;
216 
217 
218  private:
219 
222 
223  const TGeoVolume* fTotalVolume; ///< Total volume of AuxDet, called vol*
224  LocalTransformation_t fTrans; ///< Auxiliary detector-to-world transformation.
225  double fLength; ///< length of volume, along z direction in local
226  double fHalfWidth1; ///< 1st half width of volume, at -z/2 in local coordinates
227  double fHalfWidth2; ///< 2nd half width (width1==width2 for boxes), at +z/2
228  double fHalfHeight; ///< half height of volume
229  std::vector<AuxDetSensitiveGeo> fSensitive; ///< sensitive volumes in the detector
230 
231  /// Extracts the size of the detector from the geometry information.
232  void InitShapeSize();
233  }; // class AuxDetGeo
234 
235  static_assert(std::is_move_assignable_v<geo::AuxDetGeo>);
236  static_assert(std::is_move_constructible_v<geo::AuxDetGeo>);
237 
238 }
239 
240 
241 //------------------------------------------------------------------------------
242 //--- template implementation
243 //---
244 template <typename Stream>
246  Stream&& out,
247  std::string indent /* = "" */,
248  unsigned int verbosity /* = 1 */
249 ) const {
250 
251  //----------------------------------------------------------------------------
252  out << "\"" << Name() << "\"";
253 
254  if (verbosity-- <= 0) return; // 0
255 
256  //----------------------------------------------------------------------------
257  out << " centered at " << GetCenter() << " cm";
258 
259  if (verbosity-- <= 0) return; // 1
260 
261  //----------------------------------------------------------------------------
263  out << ", size ( " << (2.0 * HalfWidth1());
264  if (coordIs.nonEqual(HalfWidth1(), HalfWidth2()))
265  out << "/" << (2.0 * HalfWidth2());
266  out << " x " << (2.0 * HalfHeight()) << " x " << Length() << " ) cm";
267 
268  if (verbosity-- <= 0) return; // 2
269 
270  //----------------------------------------------------------------------------
271  out << "\n" << indent
272  << "with ";
273  switch (NSensitiveVolume()) {
274  case 0: out << "no sensitive volume"; break;
275  case 1: out << "1 sensitive volume"; break;
276  default: out << NSensitiveVolume() << " sensitive volumes"; break;
277  } // switch
278 
279  if (verbosity-- <= 0) return; // 3
280 
281  //----------------------------------------------------------------------------
282  out << ", normal facing " << GetNormalVector();
283 
284 // if (verbosity-- <= 0) return; // 4
285 
286  //----------------------------------------------------------------------------
287 
288 } // geo::AuxDetGeo::PrintAuxDetInfo()
289 
290 
291 //------------------------------------------------------------------------------
292 
293 #endif // LARCOREALG_GEOMETRY_AUXDETGEO_H
std::string AuxDetInfo(std::string indent="", unsigned int verbosity=1) const
Returns a string with auxiliary detector information.
Definition: AuxDetGeo.cxx:150
LocalPoint_t toLocalCoords(geo::Point_t const &world) const
Transform point from world frame to local auxiliary detector frame.
Definition: AuxDetGeo.h:140
void LocalToWorld(const double *auxdet, double *world) const
Transform point from local auxiliary detector frame to world frame.
Definition: AuxDetGeo.h:120
constexpr bool nonEqual(Value_t a, Value_t b) const
Returns whether a and b are farther than the threshold.
std::string string
Definition: nybbler.cc:12
AuxDetSensitiveGeo const & SensitiveVolume(size_t sv) const
Definition: AuxDetGeo.h:171
double fHalfWidth2
2nd half width (width1==width2 for boxes), at +z/2
Definition: AuxDetGeo.h:227
geo::Length_t DistanceToPoint(geo::Point_t const &point) const
Returns the distance of point from the center of the detector.
Definition: AuxDetGeo.h:111
Provides simple real number checks.
LocalTransformation_t fTrans
Auxiliary detector-to-world transformation.
Definition: AuxDetGeo.h:224
void WorldToLocal(const double *world, double *auxdet) const
Transform point from world frame to local auxiliary detector frame.
Definition: AuxDetGeo.h:136
LocalPoint_t toLocalCoords(GlobalPoint_t const &world) const
Transforms a point from world frame to local frame.
LocalVector_t toLocalCoords(geo::Vector_t const &world) const
Transform direction vector from world to local.
Definition: AuxDetGeo.h:148
double fHalfWidth1
1st half width of volume, at -z/2 in local coordinates
Definition: AuxDetGeo.h:226
void WorldToLocalVect(const double *world, double *auxdet) const
Transform direction vector from world to local.
Definition: AuxDetGeo.h:144
void SortSubVolumes(geo::GeoObjectSorter const &sorter)
Definition: AuxDetGeo.cxx:143
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
void LocalToWorld(double const *local, double *world) const
Transforms a point from local frame to world frame.
geo::Vector_t toWorldCoords(LocalVector_t const &local) const
Transform direction vector from local to world.
Definition: AuxDetGeo.h:132
void LocalToWorldVect(double const *local, double *world) const
Transforms a vector from local frame to world frame.
geo::Point3DBase_t< AuxDetGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML auxiliary detector frame.
Definition: AuxDetGeo.h:64
double fLength
length of volume, along z direction in local
Definition: AuxDetGeo.h:225
Class for approximate comparisons.
AuxDetSensitiveGeo const & PositionToSensitiveVolume(geo::Point_t const &point, size_t &sv) const
Definition: AuxDetGeo.cxx:127
double HalfWidth2() const
Definition: AuxDetGeo.h:104
const TGeoVolume * fTotalVolume
Total volume of AuxDet, called vol*.
Definition: AuxDetGeo.h:223
void LocalToWorldVect(const double *auxdet, double *world) const
Transform direction vector from local to world.
Definition: AuxDetGeo.h:128
geo::Vector3DBase_t< AuxDetGeoCoordinatesTag > LocalVector_t
Type of displacement vectors in the local GDML auxiliary detector frame.
Definition: AuxDetGeo.h:67
const double e
std::size_t FindSensitiveVolume(geo::Point_t const &point) const
Definition: AuxDetGeo.cxx:91
Encapsulate the geometry of the sensitive portion of an auxiliary detector.
Local-to-world transformations with LArSoft geometry vectors.
double HalfHeight() const
Definition: AuxDetGeo.h:105
size_t NSensitiveVolume() const
Definition: AuxDetGeo.h:172
geo::Vector_t GetNormalVector() const
Returns the unit normal vector to the detector.
Definition: AuxDetGeo.cxx:72
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
double Length_t
Type used for coordinates and distances. They are measured in centimeters.
Definition: geo_vectors.h:137
void WorldToLocal(double const *world, double *local) const
Transforms a point from world frame to local frame.
Selection of the type of transformation matrix used in geometry.
double Length() const
Definition: AuxDetGeo.h:102
std::string Name() const
Definition: AuxDetGeo.h:154
const TGeoVolume * TotalVolume() const
Definition: AuxDetGeo.h:106
AuxDetGeo(TGeoNode const &node, geo::TransformationMatrix &&trans, AuxDetSensitiveList_t &&sensitive)
Definition: AuxDetGeo.cxx:32
static constexpr unsigned int MaxVerbosity
Maximum verbosity supported by PrintAuxDetInfo().
Definition: AuxDetGeo.h:215
GenPoint3DBase_t< double, C > Point3DBase_t
Type of 3D point with representation in double precision.
Definition: geo_vectors.h:92
Definitions of geometry vector data types.
GenVector3DBase_t< double, C > Vector3DBase_t
Definition: geo_vectors.h:87
GlobalPoint_t toWorldCoords(LocalPoint_t const &local) const
Transforms a point from local frame to world frame.
double HalfWidth1() const
Definition: AuxDetGeo.h:103
std::vector< geo::AuxDetSensitiveGeo > AuxDetSensitiveList_t
Type of list of sensitive volumes.
Definition: AuxDetGeo.h:42
LArSoft geometry interface.
Definition: ChannelGeo.h:16
double fHalfHeight
half height of volume
Definition: AuxDetGeo.h:228
void WorldToLocalVect(const double *world, double *local) const
Transforms a vector from world frame to local frame.
void InitShapeSize()
Extracts the size of the detector from the geometry information.
Definition: AuxDetGeo.cxx:159
void PrintAuxDetInfo(Stream &&out, std::string indent="", unsigned int verbosity=1) const
Prints information about this auxiliary detector.
Definition: AuxDetGeo.h:245
ROOT::Math::Transform3D TransformationMatrix
Type of transformation matrix used in geometry.
geo::Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local auxiliary detector frame to world frame.
Definition: AuxDetGeo.h:124
Specialization of local-to-world transformations for ROOT GenVector.
std::vector< AuxDetSensitiveGeo > fSensitive
sensitive volumes in the detector
Definition: AuxDetGeo.h:229
void GetCenter(double *xyz, double localz=0.0) const
Return the center position of an AuxDet.
Definition: AuxDetGeo.cxx:62