2 * @file larcorealg/Geometry/LocalTransformation.tcc
3 * @brief Class containing local-to-world transformations
4 * (template implementation)
5 * @author Gianluca Petrillo (petrillo@fnal.gov)
6 * @date November 30, 2016
7 * @see LocalTransformation.h
9 * This file is expected to be included directly in the header.
13 #ifndef LARCOREALG_GEOMETRY_LOCALTRANSFORMATION_TCC
14 #define LARCOREALG_GEOMETRY_LOCALTRANSFORMATION_TCC
16 // framework libraries
17 #include "cetlib_except/exception.h"
21 #include "TGeoMatrix.h"
24 #include "CLHEP/Geometry/Transform3D.h"
30 //------------------------------------------------------------------------------
34 template <typename T, std::size_t SrcN = 3, std::size_t DestN = SrcN>
35 bool doBuffersOverlap(T const* src, T const* dest)
36 { return (dest < (src + SrcN)) && (src < (dest + DestN)); }
38 template <typename T, std::size_t SrcN = 3, std::size_t DestN = SrcN>
39 void checkVectorBufferOverlap(T const* src, T const* dest) {
40 if (doBuffersOverlap<T, SrcN, DestN>(src, dest)) {
41 throw cet::exception("LocalTransformation")
42 << "source " << SrcN << "@[" << ((void*) src) << "]"
43 << " and destination " << DestN << "@[" << ((void*) dest) << "]"
44 << " buffers overlap!\n";
46 assert(!doBuffersOverlap(src, dest));
47 } // checkVectorBufferOverlap()
49 } // namespace details
53 //------------------------------------------------------------------------------
54 template <typename Matrix>
55 void geo::LocalTransformation<Matrix>::LocalToWorld
56 (double const* local, double* world) const
58 details::checkVectorBufferOverlap(local, world);
59 fGeoMatrix.LocalToMaster(local, world);
60 } // geo::LocalTransformation::LocalToWorld()
63 //------------------------------------------------------------------------------
64 template <typename Matrix>
65 void geo::LocalTransformation<Matrix>::LocalToWorldVect
66 (double const* local, double* world) const
68 details::checkVectorBufferOverlap(local, world);
69 fGeoMatrix.LocalToMasterVect(local, world);
70 } // geo::LocalTransformation::LocalToWorldVect()
73 //------------------------------------------------------------------------------
74 template <typename Matrix>
75 void geo::LocalTransformation<Matrix>::WorldToLocal
76 (double const* world, double* local) const
78 details::checkVectorBufferOverlap(local, world);
79 fGeoMatrix.MasterToLocal(world, local);
80 } // geo::LocalTransformation::WorldToLocal()
83 //------------------------------------------------------------------------------
84 template <typename Matrix>
85 void geo::LocalTransformation<Matrix>::WorldToLocalVect
86 (const double* world, double* local) const
88 details::checkVectorBufferOverlap(local, world);
89 fGeoMatrix.MasterToLocalVect(world, local);
90 } // geo::LocalTransformation::WorldToLocalVect()
93 //------------------------------------------------------------------------------
94 template <typename Matrix>
95 template <typename DestPoint, typename SrcPoint>
96 DestPoint geo::LocalTransformation<Matrix>::WorldToLocalImpl
97 (SrcPoint const& world) const
99 double const worldArray[3] = { world.X(), world.Y(), world.Z() };
100 double localArray[3];
101 WorldToLocal(worldArray, localArray);
102 return { localArray[0], localArray[1], localArray[2] };
103 } // geo::LocalTransformation::WorldToLocal()
106 //......................................................................
107 template <typename Matrix>
108 template <typename DestVector, typename SrcVector>
109 DestVector geo::LocalTransformation<Matrix>::WorldToLocalVectImpl
110 (SrcVector const& world) const
112 double const worldArray[3] = { world.X(), world.Y(), world.Z() };
113 double localArray[3];
114 WorldToLocalVect(worldArray, localArray);
115 return { localArray[0], localArray[1], localArray[2] };
116 } // geo::LocalTransformation::WorldToLocalVect()
119 //......................................................................
120 template <typename Matrix>
121 template <typename DestPoint, typename SrcPoint>
122 DestPoint geo::LocalTransformation<Matrix>::LocalToWorldImpl
123 (SrcPoint const& local) const
125 double const localArray[3] = { local.X(), local.Y(), local.Z() };
126 double worldArray[3];
127 LocalToWorld(localArray, worldArray);
128 return { worldArray[0], worldArray[1], worldArray[2] };
129 } // geo::LocalTransformation::LocalToWorld()
132 //......................................................................
133 template <typename Matrix>
134 template <typename DestVector, typename SrcVector>
135 DestVector geo::LocalTransformation<Matrix>::LocalToWorldVectImpl
136 (SrcVector const& local) const
138 double const localArray[3] = { local.X(), local.Y(), local.Z() };
139 double worldArray[3];
140 LocalToWorldVect(localArray, worldArray);
141 return { worldArray[0], worldArray[1], worldArray[2] };
142 } // geo::LocalTransformation::LocalToWorldVect()
145 //------------------------------------------------------------------------------
146 // specialisations (forward declarations)
151 TGeoHMatrix LocalTransformation<TGeoHMatrix>::transformationFromPath
152 (std::vector<TGeoNode const*> const& path, size_t depth);
156 LocalTransformation<HepGeom::Transform3D>::transformationFromPath
157 (std::vector<TGeoNode const*> const& path, size_t depth);
161 //------------------------------------------------------------------------------
163 #endif // LARCOREALG_GEOMETRY_LOCALTRANSFORMATION_TCC