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