geo_vectors.h
Go to the documentation of this file.
1 /**
2  * @file larcoreobj/SimpleTypesAndConstants/geo_vectors.h
3  * @brief Definitions of geometry vector data types.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date March 23, 2017
6  * @ingroup Geometry
7  *
8  * This library depends on ROOT GenVector.
9  * In the CET link list in `CMakeLists.txt`, link to `ROOT::GenVector`.
10  *
11  * Additional utilities are available from `geo_vectors_utils.h`.
12  */
13 
14 #ifndef LARCOREOBJ_SIMPLETYPESANDCONSTANTS_GEO_VECTORS_H
15 #define LARCOREOBJ_SIMPLETYPESANDCONSTANTS_GEO_VECTORS_H
16 
17 // ROOT libraries
18 #include "Math/GenVector/CoordinateSystemTags.h"
19 #include "Math/GenVector/Cartesian3D.h"
20 #include "Math/GenVector/PositionVector3D.h"
21 #include "Math/GenVector/DisplacementVector3D.h"
22 #include "Math/GenVector/Rotation3D.h"
23 
24 
25 // BEGIN -- GENVECTOR_CONSTEXPR issue ------------------------------------------
26 /**
27  * @def GENVECTOR_CONSTEXPR
28  * @brief A declaration is made `constexpr` if GenVector supports it.
29  *
30  * This macro defines as "constexpr", only if GenVector's vector types can be
31  * used as `constexpr`.
32  *
33  * Currently the implementation is quite lame, since it does not autodetect
34  * whether GenVector library supports the feature or not, and it assumes it
35  * doesn't. So this becomes basically a placeholder to remind the maintainers
36  * to replace it with an actual `constexpr` when that will be supported.
37  * To make maintainers not forget this, it will explode on each new ROOT
38  * version.
39  *
40  * A feature request to ROOT was opened as
41  * [JIRA 9320](https://sft.its.cern.ch/jira/browse/ROOT-9320).
42  *
43  * See also Fermilab Redmine issue #19476 (https://cdcvs.fnal.gov/redmine/issues/19476).
44  */
45 #include "RVersion.h"
46 #define GENVECTOR_CONSTEXPR
47 // use the following definition if the issue is ever resolved
48 // # define GENVECTOR_CONSTEXPR constexpr
49 // END -- GENVECTOR_CONSTEXPR issue --------------------------------------------
50 
51 
52 // BEGIN Geometry group --------------------------------------------------------
53 /// @ingroup Geometry
54 /// @{
55 
56 /**
57  * @brief LArSoft geometry interface.
58  * @see `geo::GeometryCore`
59  *
60  * The `geo` namespace includes all LArSoft data types, classes and functions
61  * related to detector geometry.
62  *
63  * For more guidance, dee the @ref Geometry "LArSoft geometry module".
64  */
65 namespace geo {
66 
67  ///@{
68  ///@name Generic vector types.
69 
70  /// Type of 3D displacement vector.
71  /// @tparam T data type for coordinate representation
72  /// @tparam C coordinate system tag (default: global coordinates)
73  template <typename T, typename C = ROOT::Math::GlobalCoordinateSystemTag>
74  using GenVector3DBase_t
75  = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<T>, C>;
76 
77  /// Type of 3D point.
78  /// @tparam T data type for coordinate representation
79  /// @tparam C coordinate system tag (default: global coordinates)
80  template <typename T, typename C = ROOT::Math::GlobalCoordinateSystemTag>
81  using GenPoint3DBase_t
82  = ROOT::Math::PositionVector3D<ROOT::Math::Cartesian3D<T>, C>;
83 
84  /// Type of 3D displacement vector with representation in double precision.
85  /// @tparam C coordinate system tag
86  template <typename C>
88 
89  /// Type of 3D point with representation in double precision.
90  template <typename C>
91  /// @tparam C coordinate system tag
93 
94  /// @}
95 
96  /// @{
97  /**
98  * @name Vector types for the standard LArSoft geometry.
99  *
100  * LArSoft geometry provides two main types of vectors in 3D space:
101  *
102  * 1. `geo::Point_t` to describe an absolute position in global coordinates
103  * 2. `geo::Vector_t` to describe a displacement or direction (or momentum!)
104  *
105  * Both vectors are supposed to represent:
106  *
107  * * centimeters in double precision when used on the real geometry space
108  * * in the global coordinate system, which is represented by the tag
109  * `geo::GlobalCoords`.
110  *
111  * These types constitute the basic objects the geometry works with.
112  *
113  * All interfaces should support them.
114  *
115  * @note As this requires some transition, please report any interface missing
116  * support for these types by opening a "necessary maintenance" request
117  * in the LArSoft issue tracker at
118  * https://cdcvs.fnal.gov/redmine/projects/larsoft/issues .
119  * Even if there are plenty.
120  *
121  * The same type of vectors, but in a different coordinate system
122  * representation, can be obtained by using `geo::Point3DBase_t` template:
123  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
124  * using LocalPoint_t = geo::Point3DBase_t<LocalCoordinateTag>;
125  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
126  * (`geo::Vector3DBase_t` is also available).
127  * If a single precision vector is desired, the most general
128  * `geo::GenPoint3DBase_t` and `geo::GenVector3DBase_t` are also available:
129  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
130  * using PointF_t = geo::GenPoint3DBase_t<float>;
131  * using VectorF_t = geo::GenVector3DBase_t<float>;
132  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
133  *
134  */
135 
136  /// Type used for coordinates and distances. They are measured in centimeters.
137  using Length_t = double;
138 
139  /**
140  * @brief Tag for vectors in the global coordinate system.
141  *
142  * A vector tagged as "global" is expected to be represented in the global
143  * (or "world") coordinate system.
144  *
145  * That system is the one the detector geometry is described in, and it is
146  * defined by the GDML detector description.
147  * The linear coordinates are described in _centimeters_.
148  *
149  */
150  using GlobalCoords = ROOT::Math::GlobalCoordinateSystemTag;
151 
152  /**
153  * @brief Type for representation of momenta in 3D space.
154  *
155  * A vector represents a direction and intensity, or a displacement respect to
156  * an unspecified starting point.
157  * Vectors can be added or subtracted, resulting in still a vector.
158  * Their modulus can also be scaled.
159  *
160  */
161  // the actual definition commented out is not understood by GenReflex
162 // using Vector_t = Vector3DBase_t<GlobalCoords>;
163  using Vector_t = ROOT::Math::DisplacementVector3D
164  <ROOT::Math::Cartesian3D<double>, ROOT::Math::GlobalCoordinateSystemTag>;
165 
166  /**
167  * @brief Type for representation of position in physical 3D space.
168  *
169  * A point represents a position in 3D space.
170  * As such, it makes no sense to add points, and the difference between two
171  * points is not a point any more (it is, in fact, a `geo::Vector_t`).
172  * Scaling and norm of a point also have no meaning.
173  *
174  * A vector can be added to a point, resulting in another point.
175  *
176  * Note that `middlePoint()` function and `MiddlePointAccumulator` class are
177  * provided to facilitate the computation of a middle point using any type
178  * of vector and in particular `geo::Point_t`.
179  *
180  */
181  // the actual definition commented out is not understood by GenReflex
182 // using Point_t = Point3DBase_t<GlobalCoords>;
183  using Point_t = ROOT::Math::PositionVector3D
184  <ROOT::Math::Cartesian3D<double>, ROOT::Math::GlobalCoordinateSystemTag>;
185 
186 
187  /**
188  * @brief Type for representation of momenta in 3D space.
189  * @tparam CoordSystemTag the coordinate system tag for this vector
190  *
191  * This vector type is equivalent to `geo::Vector_t` but it's tagged as from a
192  * different coordinate system.
193  */
194  template <typename CoordSystemTag>
196 
197  /**
198  * @brief Type for representation of positions in 3D space.
199  * @tparam CoordSystemTag the coordinate system tag for this point
200  *
201  * This point type is equivalent to `geo::Point_t` but it's tagged as from a
202  * different coordinate system.
203  */
204  template <typename CoordSystemTag>
206 
207 
208  /// Type for representation of space rotations.
209  using Rotation_t = ROOT::Math::Rotation3D;
210 
211 
212  //--------------------------------------------------------------------------
213  /// Returns a x axis vector of the specified type.
214  template <typename Vector = Vector_t>
215  constexpr Vector Xaxis() { return { 1.0, 0.0, 0.0 }; }
216 
217  /// Returns a y axis vector of the specified type.
218  template <typename Vector = Vector_t>
219  constexpr Vector Yaxis() { return { 0.0, 1.0, 0.0 }; }
220 
221  /// Returns a z axis vector of the specified type.
222  template <typename Vector = Vector_t>
223  constexpr Vector Zaxis() { return { 0.0, 0.0, 1.0 }; }
224 
225  /// Returns a origin position with a point of the specified type.
226  template <typename Point = Point_t>
227  constexpr Point origin() { return { 0.0, 0.0, 0.0 }; }
228 
229  /// @}
230 
231 
232  //----------------------------------------------------------------------------
233 
234 } // namespace geo
235 /// @}
236 // END Geometry group ----------------------------------------------------------
237 
238 
239 #endif // LARCOREOBJ_SIMPLETYPESANDCONSTANTS_GEO_VECTORS_H
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
double Length_t
Type used for coordinates and distances. They are measured in centimeters.
Definition: geo_vectors.h:137
std::vector< float > Vector
ROOT::Math::GlobalCoordinateSystemTag GlobalCoords
Tag for vectors in the global coordinate system.
Definition: geo_vectors.h:150
constexpr Vector Yaxis()
Returns a y axis vector of the specified type.
Definition: geo_vectors.h:219
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< T >, C > GenPoint3DBase_t
Definition: geo_vectors.h:82
Vector3DBase_t< CoordSystemTag > VectorIn_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:195
constexpr Vector Xaxis()
Returns a x axis vector of the specified type.
Definition: geo_vectors.h:215
constexpr Vector Zaxis()
Returns a z axis vector of the specified type.
Definition: geo_vectors.h:223
ROOT::Math::Rotation3D Rotation_t
Type for representation of space rotations.
Definition: geo_vectors.h:209
Point3DBase_t< CoordSystemTag > PointIn_t
Type for representation of positions in 3D space.
Definition: geo_vectors.h:205
GenPoint3DBase_t< double, C > Point3DBase_t
Type of 3D point with representation in double precision.
Definition: geo_vectors.h:92
GenVector3DBase_t< double, C > Vector3DBase_t
Definition: geo_vectors.h:87
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
Verifies that the geometry check information is available.
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< T >, C > GenVector3DBase_t
Definition: geo_vectors.h:75
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227