AuxDetSensitiveGeo.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file larcorealg/Geometry/AuxDetSensitiveGeo.h
3 /// \brief Encapsulate the geometry of the sensitive portion of an auxiliary detector
4 /// \ingroup Geometry
5 ///
6 /// \author brebel@fnal.gov
7 ////////////////////////////////////////////////////////////////////////
8 
9 #ifndef LARCOREALG_GEOMETRY_AUXDETSENSITIVEGEO_H
10 #define LARCOREALG_GEOMETRY_AUXDETSENSITIVEGEO_H
11 
12 // LArSoft libraries
18 
19 // ROOT libraries
20 #include "Math/GenVector/DisplacementVector3D.h"
21 #include "Math/GenVector/PositionVector3D.h"
22 #include "Math/GenVector/Transform3D.h"
23 
24 // C/C++ standard libraries
25 #include <string>
26 #include <type_traits>
27 
28 class TGeoNode;
29 class TGeoVolume;
30 
31 namespace geo {
32 
33  /// \ingroup Geometry
35  public:
36  /// @{
37  /**
38  * @name Types for geometry-local reference vectors.
39  *
40  * These types represents points and displacement vectors in the reference
41  * frame defined in the auxiliary detector geometry box from the GDML
42  * geometry description.
43  *
44  * No alias is explicitly defined for the LArSoft global vector types,
45  * `geo::Point_t` and `geo::Vector_t`.
46  *
47  * Remember the `LocalPoint_t` and `LocalVector_t` vectors from different
48  * instances of `geo::AuxDetSensitiveGeo` have the same type but are not
49  * compatible.
50  */
51 
52  /// Tag for vectors in the "local" GDML coordinate frame of the
53  /// auxiliary detector.
55 
56  /// Type of points in the local GDML auxiliary detector frame.
58 
59  /// Type of displacement vectors in the local GDML auxiliary detector frame.
61 
62  ///@}
63 
64  AuxDetSensitiveGeo(TGeoNode const& node, geo::TransformationMatrix&& trans);
65 
66  /**
67  * @brief Return the center position of an AuxDet.
68  * @param xyz _(output)_ the returned location: `{ x, y, z }` [cm]
69  * @param localz (default: `0`) distance along the length of the volume (z)
70  * [cm]
71  * @deprecated Use the version returning a vector instead.
72  */
73  void GetCenter(double* xyz, double localz=0.0) const;
74 
75  /**
76  * @brief Returns the geometric center of the sensitive volume.
77  * @param localz (default: `0`) distance from the center along the length
78  * of the volume (z) [cm]
79  * @return the geometric center of the sensitive volume [cm]
80  */
81  geo::Point_t GetCenter(double localz = 0.0) const;
82 
83  /// Returns the unit normal vector to the detector.
85 
86  /// Fills the unit normal vector to the detector.
87  /// @deprecated Use the version returning a vector instead.
88  void GetNormalVector(double* xyzDir) const;
89 
90  //box geometry
91  double Length() const { return fLength; }
92  double HalfLength() const { return Length() / 2.0; }
93  double HalfWidth1() const { return fHalfWidth1; }
94  double HalfWidth2() const { return fHalfWidth2; }
95  double HalfCenterWidth() const { return (HalfWidth1() + HalfWidth2()) / 2.0; }
96  double HalfHeight() const { return fHalfHeight; }
97  const TGeoVolume* TotalVolume() const { return fTotalVolume; }
98 
99  //@{
100  /// Returns the distance of `point` from the center of the detector.
102  { return (point - GetCenter()).R(); }
103  geo::Length_t DistanceToPoint(double const* point) const;
104  //@}
105 
106  /// @{
107  /// @name Coordinate transformation
108 
109  /// Transform point from local auxiliary detector frame to world frame.
110  void LocalToWorld(const double* auxdet, double* world) const
111  { fTrans.LocalToWorld(auxdet, world); }
112 
113  /// Transform point from local auxiliary detector frame to world frame.
115  { return fTrans.toWorldCoords(local); }
116 
117  /// Transform direction vector from local to world.
118  void LocalToWorldVect(const double* auxdet, double* world) const
119  { fTrans.LocalToWorldVect(auxdet, world); }
120 
121  /// Transform direction vector from local to world.
123  { return fTrans.toWorldCoords(local); }
124 
125  /// Transform point from world frame to local auxiliary detector frame.
126  void WorldToLocal(const double* world, double* auxdet) const
127  { fTrans.WorldToLocal(world, auxdet); }
128 
129  /// Transform point from world frame to local auxiliary detector frame.
131  { return fTrans.toLocalCoords(world); }
132 
133  /// Transform direction vector from world to local.
134  void WorldToLocalVect(const double* world, double* auxdet) const
135  { fTrans.WorldToLocalVect(world, auxdet); }
136 
137  /// Transform direction vector from world to local.
139  { return fTrans.toLocalCoords(world); }
140 
141  /// @}
142 
143 
144  /**
145  * @brief Prints information about this auxiliary sensitive detector.
146  * @tparam Stream type of output stream to use
147  * @param out stream to send the information to
148  * @param indent prepend each line with this string
149  * @param verbosity amount of information printed
150  *
151  * Note that the first line out the output is _not_ indented.
152  *
153  * Verbosity levels
154  * -----------------
155  *
156  * * 0 _(default)_: only center
157  * * 1: also size
158  * * 2: also normal direction
159  *
160  * The constant `MaxVerbosity` is set to the highest supported verbosity
161  * level.
162  */
163  template <typename Stream>
164  void PrintAuxDetInfo
165  (Stream&& out, std::string indent = "", unsigned int verbosity = 0) const;
166 
167  /**
168  * @brief Returns a string with auxiliary sensitive detector information.
169  * @see `PrintAuxDetInfo()`
170  *
171  * The arguments and provided information are the same as in
172  * `PrintAuxDetInfo()`.
173  */
175  (std::string indent = "", unsigned int verbosity = 1) const;
176 
177  /// Maximum verbosity supported by `PrintAuxDetInfo()`.
178  static constexpr unsigned int MaxVerbosity = 2;
179 
180  private:
181 
183  <ROOT::Math::Transform3D, LocalPoint_t, LocalVector_t>;
184 
185  LocalTransformation_t fTrans; ///< Auxiliary detector-to-world transformation.
186  const TGeoVolume* fTotalVolume; ///< Total volume of AuxDet, called vol*
187  double fLength; ///< length of volume, along z direction in local
188  double fHalfWidth1; ///< 1st half width of volume, at -z/2 in local coordinates
189  double fHalfWidth2; ///< 2nd half width (width1==width2 for boxes), at +z/2
190  double fHalfHeight; ///< half height of volume
191 
192  /// Extracts the size of the detector from the geometry information.
193  void InitShapeSize();
194 
195  }; // class AuxDetSensitiveGeo
196 
197  static_assert(std::is_move_assignable_v<geo::AuxDetSensitiveGeo>);
198  static_assert(std::is_move_constructible_v<geo::AuxDetSensitiveGeo>);
199 
200 } // namespace geo
201 
202 
203 //------------------------------------------------------------------------------
204 //--- template implementation
205 //---
206 template <typename Stream>
208  Stream&& out,
209  std::string indent /* = "" */,
210  unsigned int verbosity /* = 0 */
211 ) const {
212 
213  //----------------------------------------------------------------------------
214  out << "centered at " << GetCenter() << " cm";
215 
216  if (verbosity-- <= 0) return; // 0
217 
218  //----------------------------------------------------------------------------
220  out << ", size ( " << (2.0 * HalfWidth1());
221  if (coordIs.nonEqual(HalfWidth1(), HalfWidth2()))
222  out << "/" << (2.0 * HalfWidth2());
223  out << " x " << (2.0 * HalfHeight()) << " x " << Length() << " ) cm";
224 
225  if (verbosity-- <= 0) return; // 1
226 
227  //----------------------------------------------------------------------------
228  out << ", normal facing " << GetNormalVector();
229 
230 // if (verbosity-- <= 0) return; // 2
231 
232  //----------------------------------------------------------------------------
233 
234 } // geo::AuxDetSensitiveGeo::PrintAuxDetInfo()
235 
236 
237 //------------------------------------------------------------------------------
238 
239 #endif // LARCOREALG_GEOMETRY_AUXDETSENSITIVEGEO_H
double fLength
length of volume, along z direction in local
constexpr bool nonEqual(Value_t a, Value_t b) const
Returns whether a and b are farther than the threshold.
void WorldToLocalVect(const double *world, double *auxdet) const
Transform direction vector from world to local.
geo::Vector_t GetNormalVector() const
Returns the unit normal vector to the detector.
std::string string
Definition: nybbler.cc:12
double HalfCenterWidth() const
Provides simple real number checks.
LocalPoint_t toLocalCoords(GlobalPoint_t const &world) const
Transforms a point from world frame to local frame.
double fHalfWidth1
1st half width of volume, at -z/2 in local coordinates
double fHalfHeight
half height of volume
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.
void LocalToWorldVect(double const *local, double *world) const
Transforms a vector from local frame to world frame.
geo::Vector_t toWorldCoords(LocalVector_t const &local) const
Transform direction vector from local to world.
Class for approximate comparisons.
AuxDetSensitiveGeo(TGeoNode const &node, geo::TransformationMatrix &&trans)
void InitShapeSize()
Extracts the size of the detector from the geometry information.
LocalVector_t toLocalCoords(geo::Vector_t const &world) const
Transform direction vector from world to local.
const TGeoVolume * fTotalVolume
Total volume of AuxDet, called vol*.
const double e
Local-to-world transformations with LArSoft geometry vectors.
const TGeoVolume * TotalVolume() const
void LocalToWorldVect(const double *auxdet, double *world) const
Transform direction vector from local to world.
geo::Length_t DistanceToPoint(geo::Point_t const &point) const
Returns the distance of point from the center of the detector.
void PrintAuxDetInfo(Stream &&out, std::string indent="", unsigned int verbosity=0) const
Prints information about this auxiliary sensitive detector.
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.
std::string AuxDetInfo(std::string indent="", unsigned int verbosity=1) const
Returns a string with auxiliary sensitive detector information.
Selection of the type of transformation matrix used in geometry.
static constexpr unsigned int MaxVerbosity
Maximum verbosity supported by PrintAuxDetInfo().
void WorldToLocal(const double *world, double *auxdet) const
Transform point from world frame to local auxiliary detector frame.
geo::Point3DBase_t< AuxDetSensitiveGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML auxiliary detector frame.
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.
double fHalfWidth2
2nd half width (width1==width2 for boxes), at +z/2
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.
LocalTransformation_t fTrans
Auxiliary detector-to-world transformation.
void LocalToWorld(const double *auxdet, double *world) const
Transform point from local auxiliary detector frame to world frame.
LArSoft geometry interface.
Definition: ChannelGeo.h:16
LocalPoint_t toLocalCoords(geo::Point_t const &world) const
Transform point from world frame to local auxiliary detector frame.
void WorldToLocalVect(const double *world, double *local) const
Transforms a vector from world frame to local frame.
void GetCenter(double *xyz, double localz=0.0) const
Return the center position of an AuxDet.
ROOT::Math::Transform3D TransformationMatrix
Type of transformation matrix used in geometry.
Specialization of local-to-world transformations for ROOT GenVector.
geo::Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local auxiliary detector frame to world frame.
geo::Vector3DBase_t< AuxDetSensitiveGeoCoordinatesTag > LocalVector_t
Type of displacement vectors in the local GDML auxiliary detector frame.