LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
GeoVectorLocalTransformation.tcc
Go to the documentation of this file.
1 /**
2  * @file larcorealg/Geometry/GeoVectorLocalTransformation.tcc
3  * @brief Specialization of local-to-world transformations for ROOT GenVector
4  * (template implementation).
5  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
6  * @date January 31, 2019
7  * @see `GeoVectorLocalTransformation.h`
8  *
9  * This file is expected to be included directly in the header.
10  *
11  */
12 
13 #ifndef LARCOREALG_GEOMETRY_GEOVECTORLOCALTRANSFORMATION_TCC
14 #define LARCOREALG_GEOMETRY_GEOVECTORLOCALTRANSFORMATION_TCC
15 
16 // LArSoft libraries
17 #include "larcorealg/Geometry/geo_vectors_utils.h" // geo::vect::fillCoords()...
18 
19 // framework libraries
20 #include "cetlib_except/exception.h"
21 
22 // ROOT
23 #include "TGeoMatrix.h"
24 #include "TGeoNode.h"
25 
26 // CLHEP
27 #include "CLHEP/Geometry/Transform3D.h"
28 #include "CLHEP/Vector/Rotation.h" // CLHEP::HepRotation
29 #include "CLHEP/Vector/RotationInterfaces.h" // CLHEP::HepRep3x3
30 #include "CLHEP/Vector/ThreeVector.h" // CLHEP::Hep3Vector
31 
32 // C standard library
33 #include <cassert>
34 
35 //------------------------------------------------------------------------------
36 template <>
37 struct geo::details::TransformationMatrixConverter<ROOT::Math::Transform3D, TGeoMatrix> {
38  static ROOT::Math::Transform3D convert(TGeoMatrix const& trans);
39 };
40 
41 //------------------------------------------------------------------------------
42 template <>
43 template <typename DestPoint, typename SrcPoint>
44 DestPoint geo::LocalTransformation<ROOT::Math::Transform3D>::WorldToLocalImpl(
45  SrcPoint const& world) const
46 {
47  // need inverse transformation
48  using geo::vect::convertTo;
49  return geo::vect::convertTo<DestPoint>(
50  fGeoMatrix.ApplyInverse(convertTo<typename TransformationMatrix_t::Point>(world)));
51 } // geo::LocalTransformation::WorldToLocal()
52 
53 //......................................................................
54 template <>
55 template <typename DestVector, typename SrcVector>
56 DestVector geo::LocalTransformation<ROOT::Math::Transform3D>::WorldToLocalVectImpl(
57  SrcVector const& world) const
58 {
59  // need inverse transformation
60  using geo::vect::convertTo;
61  return geo::vect::convertTo<DestVector>(
62  fGeoMatrix.ApplyInverse(convertTo<typename TransformationMatrix_t::Vector>(world)));
63 } // geo::LocalTransformation::WorldToLocalVect()
64 
65 //......................................................................
66 template <>
67 template <typename DestPoint, typename SrcPoint>
68 DestPoint geo::LocalTransformation<ROOT::Math::Transform3D>::LocalToWorldImpl(
69  SrcPoint const& local) const
70 {
71  // need direct transformation
72  using geo::vect::convertTo;
73  return convertTo<DestPoint>(fGeoMatrix(convertTo<typename TransformationMatrix_t::Point>(local)));
74 
75 } // geo::LocalTransformation::LocalToWorld()
76 
77 //......................................................................
78 template <>
79 template <typename DestVector, typename SrcVector>
80 DestVector geo::LocalTransformation<ROOT::Math::Transform3D>::LocalToWorldVectImpl(
81  SrcVector const& local) const
82 {
83  // need direct transformation
84  using geo::vect::convertTo;
85  return convertTo<DestVector>(
86  fGeoMatrix(convertTo<typename TransformationMatrix_t::Vector>(local)));
87 } // geo::LocalTransformation::LocalToWorldVect()
88 
89 //------------------------------------------------------------------------------
90 template <>
91 inline ROOT::Math::Transform3D geo::transformationFromPath<ROOT::Math::Transform3D>(
92  GeoNodeIterator_t begin,
93  GeoNodeIterator_t end)
94 {
95  if (begin == end) return {}; // identity by default construction
96  auto iNode = begin;
97  ROOT::Math::Transform3D matrix =
98  convertTransformationMatrix<ROOT::Math::Transform3D>(*((*iNode)->GetMatrix()));
99  while (++iNode != end) {
100  matrix *= convertTransformationMatrix<ROOT::Math::Transform3D>(*(*iNode)->GetMatrix());
101  }
102  return matrix;
103 } // geo::LocalTransformation<ROOT::Transform3D>::transformationFromPath()
104 
105 //------------------------------------------------------------------------------
106 template <>
107 inline ROOT::Math::Transform3D geo::transformationFromPath<ROOT::Math::Transform3D>(
108  std::vector<TGeoNode const*> const& path,
109  size_t depth)
110 {
111  return transformationFromPath<ROOT::Math::Transform3D>(path.begin(), path.begin() + depth + 1);
112 }
113 
114 //------------------------------------------------------------------------------
115 
116 #endif // LARCOREALG_GEOMETRY_GEOVECTORLOCALTRANSFORMATION_TCC
117 
118 // Local variables:
119 // mode: c++
120 // End: