GeoVectorLocalTransformation.cxx
Go to the documentation of this file.
1 /**
2  * @file larcorealg/Geometry/GeoVectorLocalTransformation.cxx
3  * @brief Specialization of local-to-world transformations for ROOT GenVector.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date January 31, 2019
6  * @see `larcorealg/Geometry/GeoVectorLocalTransformation.h`
7  * @ingroup Geometry
8  *
9  * This is a header-only library.
10  */
11 
12 // LArSoft libraries
14 
15 // ROOT libraries
16 #include "TGeoMatrix.h"
17 
18 // C++ standard library
19 #include <stdexcept> // std::runtime_error
20 
21 
22 //------------------------------------------------------------------------------
23 template <>
25  (double const* local, double* world) const
26 {
27  details::checkVectorBufferOverlap(local, world);
28 
29  // need direct transformation
30  auto const local_v
31  = geo::vect::makeFromCoords<typename TransformationMatrix_t::Point>(local);
32  auto const world_v = fGeoMatrix(local_v);
33  geo::vect::fillCoords(world, world_v);
34 
35 } // geo::LocalTransformation::LocalToWorld()
36 
37 
38 //------------------------------------------------------------------------------
39 template <>
41  (double const* local, double* world) const
42 {
43  details::checkVectorBufferOverlap(local, world);
44 
45  // need direct transformation
46  auto const local_v
47  = geo::vect::makeFromCoords<typename TransformationMatrix_t::Vector>(local);
48  auto const world_v = fGeoMatrix(local_v);
49  geo::vect::fillCoords(world, world_v);
50 
51 } // geo::LocalTransformation::LocalToWorldVect()
52 
53 
54 //------------------------------------------------------------------------------
55 template <>
57  (double const* world, double* local) const
58 {
59  details::checkVectorBufferOverlap(local, world);
60 
61  // need inverse transformation
62  auto const world_v
63  = geo::vect::makeFromCoords<typename TransformationMatrix_t::Point>(world);
64  auto const local_v = fGeoMatrix.ApplyInverse(world_v);
65  geo::vect::fillCoords(local, local_v);
66 
67 } // geo::LocalTransformation::WorldToLocal()
68 
69 
70 //------------------------------------------------------------------------------
71 template <>
73  (const double* world, double* local) const
74 {
75  details::checkVectorBufferOverlap(local, world);
76 
77  // need inverse transformation
78  auto const world_v
79  = geo::vect::makeFromCoords<typename TransformationMatrix_t::Vector>(world);
80  auto const local_v = fGeoMatrix.ApplyInverse(world_v);
81  geo::vect::fillCoords(local, local_v);
82 
83 } // geo::LocalTransformation::WorldToLocalVect()
84 
85 
86 //------------------------------------------------------------------------------
87 ROOT::Math::Transform3D
90  (TGeoMatrix const& trans)
91 {
92  double const* rot = trans.GetRotationMatrix();
93  double const* transl = trans.GetTranslation();
94  double const* scale = trans.GetScale();
95 
96  for (auto ptr = scale; ptr != scale + 3; ++ptr)
97  if (*ptr != 1.0)
98  throw std::runtime_error
99  ("Matrix with scaling can't be converted to Transform3D");
100 
101  return {
102  rot[0], rot[1], rot[2], transl[0],
103  rot[3], rot[4], rot[5], transl[1],
104  rot[6], rot[7], rot[8], transl[2]
105  };
106 
107 } // geo::details::TransformationMatrixConverter<TGeoMatrix, Transform3D>::convert()
108 
109 
110 //------------------------------------------------------------------------------
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.
unsigned int fillCoords(Coords &dest, Vector const &src)
Fills a coordinate array with the coordinates of a vector.
def convert(inputfile, outputfile="wire-cell-garfield-fine-response.json.bz2", average=False, shaped=False)
Definition: garfield.py:262
void WorldToLocal(double const *world, double *local) const
Transforms a point from world frame to local frame.
void WorldToLocalVect(const double *world, double *local) const
Transforms a vector from world frame to local frame.
Specialization of local-to-world transformations for ROOT GenVector.