All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LocalTransformationGeo.h
Go to the documentation of this file.
1 /**
2  * @file larcorealg/Geometry/LocalTransformationGeo.h
3  * @brief Local-to-world transformations with LArSoft geometry vectors.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date November 30, 2016
6  *
7  */
8 
9 #ifndef LARCOREALG_GEOMETRY_LOCALTRANSFORMATIONGEO_H
10 #define LARCOREALG_GEOMETRY_LOCALTRANSFORMATIONGEO_H
11 
12 // LArSoft libraries
15 #include "larcoreobj/SimpleTypesAndConstants/geo_vectors.h" // geo::Point_t...
16 
17 
18 // C/C++ standard libraries
19 #include <utility> // std::move()
20 #include <type_traits> // std::is_same
21 
22 
23 namespace geo {
24 
25  /**
26  * @brief Class to transform between world and local coordinates
27  * @tparam StoredMatrix type of transformation matrix internally stored
28  * @tparam LocalPoint type representing a local point
29  * @tparam LocalVector type representing a local displacement vector
30  * @see `geo::LocalTransformation`
31  *
32  * This class provides two directions of transformations (world to local and
33  * the other way around), for points and for vectors.
34  *
35  * Compared to `geo::LocalTransformation`, this class offers a simplified
36  * interface for the supported vectors: `toWorldCoords()` and
37  * `toLocalCoords()` apply the correct transformation depending on whether
38  * the argument is a point or a displacement vector.
39  *
40  * @note In the class method examples, the following definition is assumed:
41  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
42  * using LocalTransformationGeo_t = geo::LocalTransformationGeo
43  * <TGeoHMatrix, geo::Point_t, geo::Vector_t>;
44  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45  * This is conceptually wrong since `geo::Point_t` and `geo::Vector_t` are
46  * explicitly tagged to be in the global coordinate frame, but mechanically
47  * it will work just the same.
48  */
49  template <typename StoredMatrix
50  , typename LocalPoint = geo::Point_t
51  , typename LocalVector = geo::Vector_t
52  >
53  class LocalTransformationGeo: public geo::LocalTransformation<StoredMatrix> {
55 
56  public:
57  using GlobalPoint_t = geo::Point_t; ///< Type for global 3D point.
58  using GlobalVector_t = geo::Vector_t; ///< Type for global 3D displacement.
59  using LocalPoint_t = LocalPoint; ///< Type for local 3D point.
60  using LocalVector_t = LocalVector; ///< Type for local 3D displacement.
61 
62  using typename Base_t::TransformationMatrix_t;
63 
64  //@{
65  /**
66  * @brief Constructor: uses the specified transformation matrix.
67  * @param matrix the transformation matrix to be used
68  *
69  * The specified matrix is copied into a local copy.
70  */
72  : Base_t(matrix) {}
74  : Base_t(std::move(matrix)) {}
75  //@}
76 
77  /**
78  * @brief Constructor: uses the specified transformation matrix.
79  * @param path the path of ROOT geometry nodes
80  * @param depth the index in the path of the last node to be considered
81  *
82  * The specified matrix is copied into a local copy.
83  */
85  (std::vector<TGeoNode const*> const& path, size_t depth)
86  : Base_t(path, depth) {}
87 
88 
89  /**
90  * @brief Transforms a point from local frame to world frame.
91  * @param local local coordinates [cm]
92  * @return corresponding world coordinates [cm]
93  *
94  * The full transformation is applied. Fox example:
95  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96  * geo::LocalTransformationGeo_t trans( ... ); // with proper initialisation
97  *
98  * auto center = trans.toWorldCoords(geo::origin());
99  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100  * `center` will be a `geo::Point_t` containing the world coordinates of
101  * the center of the volume, which is usually represented by the origin in
102  * the local coordinates.
103  */
105  { return Base_t::template LocalToWorld<GlobalPoint_t>(local); }
106 
107 
108  /**
109  * @brief Transforms a vector from local frame to world frame.
110  * @param local local coordinates [cm]
111  * @return corresponding world coordinates [cm]
112  *
113  * The translation is not applied, since the argument is supposed to be a
114  * vector, relative difference between two points.
115  */
117  { return Base_t::template LocalToWorldVect<GlobalVector_t>(local); }
118 
119 
120  /**
121  * @brief Transforms a point from world frame to local frame.
122  * @param world world coordinates [cm]
123  * @return corresponding local coordinates [cm]
124  *
125  * The full transformation is applied. Fox example:
126  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
127  * geo::LocalTransformation trans( ... ); // with proper initialisation
128  * geo::Point_t p = { 4.0, 5.0, -2.5 };
129  * auto local = trans.toLocalCoords(p);
130  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
131  * `local` will be a `LocalPoint_t` containing the local coordinates of the
132  * specified point.
133  */
135  { return Base_t::template WorldToLocal<LocalPoint_t>(world); }
136 
137  /**
138  * @brief Transforms a vector from world frame to local frame.
139  * @param world world coordinates: [0] x, [1] y, [2] z [cm]
140  * @return a local vector with corresponding local coordinates [cm]
141  *
142  * The translation is not applied, since the argument is supposed to be a
143  * vector, relative difference between two points.
144  */
146  { return Base_t::template WorldToLocalVect<LocalVector_t>(world); }
147 
148 
149  static_assert(!std::is_same<LocalPoint_t, LocalVector_t>(),
150  "Vector and point types must be distinct");
151 
152  }; // class LocalTransformationGeo<>
153 
154 
155 } // namespace geo
156 
157 
158 #endif // LARCOREALG_GEOMETRY_LOCALTRANSFORMATIONGEO_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 std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
StoredMatrix TransformationMatrix_t
Type of transformation matrix.
LocalTransformationGeo(TransformationMatrix_t &&matrix)
LocalPoint_t toLocalCoords(GlobalPoint_t const &world) const
Transforms a point from world frame to local frame.
Class to transform between world and local coordinates.
Class containing local-to-world transformations.
LocalTransformationGeo(TransformationMatrix_t const &matrix)
Constructor: uses the specified transformation matrix.
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
then local
geo::LocalTransformation< StoredMatrix > Base_t
Class to transform between world and local coordinates.
Definitions of geometry vector data types.
GlobalPoint_t toWorldCoords(LocalPoint_t const &local) const
Transforms a point from local frame to world frame.
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
GlobalVector_t toWorldCoords(LocalVector_t const &local) const
Transforms a vector from local frame to world frame.
LocalVector_t toLocalCoords(GlobalVector_t const &world) const
Transforms a vector from world frame to local frame.
Specialization of local-to-world transformations for ROOT GenVector.