LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
OpDetGeo.h
Go to the documentation of this file.
1 
9 #ifndef LARCOREALG_GEOMETRY_OPDETGEO_H
10 #define LARCOREALG_GEOMETRY_OPDETGEO_H
11 
12 // LArSoft libraries
15 
16 // ROOT libraries
17 #include "TGeoMatrix.h" // TGeoHMatrix
18 #include "TGeoTube.h"
19 #include "TGeoBBox.h"
20 #include "TClass.h"
21 
22 // C/C++ standard libraries
23 #include <vector>
24 #include <array>
25 
26 
27 // forward declarations
28 class TGeoNode;
29 
30 namespace geo {
31 
33  class OpDetGeo {
34  public:
35 
37 
51  struct OpDetGeoCoordinatesTag {};
53 
56 
59 
61 
62  OpDetGeo(std::vector<const TGeoNode*>& path,
63  int depth);
64 
65  void GetCenter(double* xyz, double localz=0.0) const;
66  geo::Point_t const& GetCenter() const { return fCenter; }
67  double RMin() const;
68  double RMax() const;
69  double HalfL() const;
70  double HalfW() const;
71  double HalfH() const;
72  double Length() const { return 2.0 * HalfL(); }
73  double Width() const { return 2.0 * HalfW(); }
74  double Height() const { return 2.0 * HalfH(); }
75  double ThetaZ() const;
76  double ThetaZ(bool degrees) const;
79 
82  double CosThetaFromNormal(geo::Point_t const& point) const;
84  double CosThetaFromNormal(double const* xyz) const;
86 
87  double DistanceToPoint(geo::Point_t const& point) const;
89  double DistanceToPoint(double const* xyz) const;
91 
92 
94 
102  void LocalToWorld(const double* opdet, double* world) const
104  { fTrans.LocalToWorld(opdet, world); }
105 
108  { return fTrans.toWorldCoords(local); }
109 
111  void LocalToWorldVect(const double* opdet, double* world) const
112  { fTrans.LocalToWorldVect(opdet, world); }
113 
116  { return fTrans.toWorldCoords(local); }
117 
119  void WorldToLocal(const double* world, double* opdet) const
120  { fTrans.WorldToLocal(world, opdet); }
121 
124  { return fTrans.toLocalCoords(world); }
125 
127  void WorldToLocalVect(const double* world, double* opdet) const
128  { fTrans.WorldToLocalVect(world, opdet); }
129 
132  { return fTrans.toLocalCoords(world); }
133 
135 
137  const TGeoNode* Node() const { return fOpDetNode; }
138 
140  TGeoShape const* Shape() const { return Node()->GetVolume()->GetShape(); }
141 
143  bool isTube() const { return asTube() != nullptr; }
144 
146  bool isBar() const { return (asBox() != nullptr) && !isTube(); }
147 
167  template <typename Stream>
168  void PrintOpDetInfo
169  (Stream&& out, std::string indent = "", unsigned int verbosity = 0) const;
170 
172  static constexpr unsigned int MaxVerbosity = 2;
173 
174  private:
177 
179  const TGeoNode* fOpDetNode;
181 
183  TGeoTube const* asTube() const
184  { return dynamic_cast<TGeoTube const*>(Shape()); }
185 
187  TGeoBBox const* asBox() const
188  { return dynamic_cast<TGeoBBox const*>(Shape()); }
189 
190  }; // class OpDetGeo
191 
192 } // namespace geo
193 
194 
195 //------------------------------------------------------------------------------
196 //--- template implementation
197 //---
198 template <typename Stream>
200  Stream&& out,
201  std::string indent /* = "" */,
202  unsigned int verbosity /* = 0 */
203 ) const {
204 
205  //----------------------------------------------------------------------------
206  out << "centered at " << GetCenter() << " cm";
207 
208  if (verbosity-- <= 0) return; // 0
209 
210  //----------------------------------------------------------------------------
211  if (isTube()) {
212  out << ", radius: " << RMax() << " cm";
213  if (RMin() != 0.0) out << " (inner: " << RMin() << " cm)";
214  out << ", length: " << Length() << " cm";
215  }
216  else if (isBar()) {
217  out << ", bar size " << Width() << " x " << Height() << " x " << Length()
218  << " cm";
219  }
220  else out << ", shape: '" << Shape()->IsA()->GetName() << "'";
221 
222  if (verbosity-- <= 0) return; // 1
223 
224  //----------------------------------------------------------------------------
225  out << ", theta(z): " << ThetaZ() << " rad";
226 
227 // if (verbosity-- <= 0) return; // 2
228 
229  //----------------------------------------------------------------------------
230 
231 } // geo::OpDetGeo::PrintOpDetInfo()
232 
233 
234 #endif // LARCOREALG_GEOMETRY_OPDETGEO_H
const TGeoNode * Node() const
Returns the ROOT object describing the detector geometry.
Definition: OpDetGeo.h:137
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:167
Tag for vectors in the "local" GDML coordinate frame of the TPC.
Definition: OpDetGeo.h:52
double CosThetaFromNormal(geo::Point_t const &point) const
Get cos(angle) to normal of this detector - used for solid angle calcs.
Definition: OpDetGeo.cxx:121
bool isTube() const
Returns whether the detector shape is a cilynder (TGeoTube).
Definition: OpDetGeo.h:143
bool isBar() const
Returns whether the detector shape is a bar (TGeoBBox).
Definition: OpDetGeo.h:146
LocalPoint_t toLocalCoords(GlobalPoint_t const &world) const
Transforms a point from world frame to local frame.
OpDetGeo(std::vector< const TGeoNode * > &path, int depth)
Definition: OpDetGeo.cxx:32
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.
const TGeoNode * fOpDetNode
Pointer to theopdet node.
Definition: OpDetGeo.h:179
LocalVector_t toLocalCoords(geo::Vector_t const &world) const
Transform direction vector from world to local.
Definition: OpDetGeo.h:131
double RMin() const
Definition: OpDetGeo.cxx:86
geo::Vector_t toWorldCoords(LocalVector_t const &local) const
Transform direction vector from local to world.
Definition: OpDetGeo.h:115
double RMax() const
Definition: OpDetGeo.cxx:55
double HalfW() const
Definition: OpDetGeo.cxx:70
Local-to-world transformations with LArSoft geometry vectors.
double HalfL() const
Definition: OpDetGeo.cxx:62
Definitions of geometry vector data types.
TGeoBBox const * asBox() const
Returns the geometry object as TGeoBBox, nullptr if not a tube.
Definition: OpDetGeo.h:187
std::string indent(std::size_t const i)
void WorldToLocal(const double *world, double *opdet) const
Transform point from world frame to local optical detector frame.
Definition: OpDetGeo.h:119
double Length() const
Definition: OpDetGeo.h:72
void PrintOpDetInfo(Stream &&out, std::string indent="", unsigned int verbosity=0) const
Prints information about this optical detector.
Definition: OpDetGeo.h:199
geo::Point_t fCenter
Stored geometric center of the optical detector.
Definition: OpDetGeo.h:180
void LocalToWorldVect(const double *opdet, double *world) const
Transform direction vector from local to world.
Definition: OpDetGeo.h:111
geo::Vector3DBase_t< OpDetGeoCoordinatesTag > LocalVector_t
Type of displacement vectors in the local GDML TPC frame.
Definition: OpDetGeo.h:58
geo::Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local optical detector frame to world frame.
Definition: OpDetGeo.h:107
geo::Point_t const & GetCenter() const
Definition: OpDetGeo.h:66
double DistanceToPoint(geo::Point_t const &point) const
Returns the distance of the specified point from detector center [cm].
Definition: OpDetGeo.cxx:114
void WorldToLocal(double const *world, double *local) const
Transforms a point from world frame to local frame.
TGeoTube const * asTube() const
Returns the geometry object as TGeoTube, nullptr if not a tube.
Definition: OpDetGeo.h:183
double HalfH() const
Definition: OpDetGeo.cxx:78
static constexpr unsigned int MaxVerbosity
Maximum verbosity supported by PrintOpDetInfo().
Definition: OpDetGeo.h:172
double ThetaZ() const
Definition: OpDetGeo.cxx:92
GenPoint3DBase_t< double, C > Point3DBase_t
Type of 3D point with representation in double precision.
Definition: geo_vectors.h:95
GenVector3DBase_t< double, C > Vector3DBase_t
Definition: geo_vectors.h:90
LocalTransformation_t fTrans
Optical-detector-to-world transformation.
Definition: OpDetGeo.h:178
GlobalPoint_t toWorldCoords(LocalPoint_t const &local) const
Transforms a point from local frame to world frame.
double Width() const
Definition: OpDetGeo.h:73
geo::Point3DBase_t< OpDetGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML TPC frame.
Definition: OpDetGeo.h:55
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:187
Namespace collecting geometry-related classes utilities.
void WorldToLocalVect(const double *world, double *opdet) const
Transform direction vector from world to local.
Definition: OpDetGeo.h:127
double Height() const
Definition: OpDetGeo.h:74
void WorldToLocalVect(const double *world, double *local) const
Transforms a vector from world frame to local frame.
TGeoShape const * Shape() const
Returns the geometry object as TGeoShape.
Definition: OpDetGeo.h:140
void LocalToWorld(const double *opdet, double *world) const
Transform point from local optical detector frame to world frame.
Definition: OpDetGeo.h:103
LocalPoint_t toLocalCoords(geo::Point_t const &world) const
Transform point from world frame to local optical detector frame.
Definition: OpDetGeo.h:123