LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
OpDetGeo.h
Go to the documentation of this file.
1 
8 #ifndef LARCOREALG_GEOMETRY_OPDETGEO_H
9 #define LARCOREALG_GEOMETRY_OPDETGEO_H
10 
11 // LArSoft libraries
16 #include "larcoreobj/SimpleTypesAndConstants/geo_types.h" // geo::OpDetID
18 
19 // ROOT libraries
20 #include "TClass.h"
21 #include "TGeoBBox.h"
22 #include "TGeoMatrix.h" // TGeoHMatrix
23 #include "TGeoSphere.h"
24 #include "TGeoTube.h"
25 
26 // C/C++ standard libraries
27 #include <algorithm> // std::minmax()
28 #include <array>
29 #include <cassert>
30 #include <string>
31 #include <type_traits> // std::decay_t(), std::is_base_of_v
32 #include <typeinfo> // typeid()
33 #include <vector>
34 
35 // forward declarations
36 class TGeoNode;
37 
38 namespace geo {
39 
41  class OpDetGeo {
42  public:
44 
60 
63 
65 
66  OpDetGeo(TGeoNode const* node, TransformationMatrix&& trans);
67 
69  OpDetID const& ID() const { return fID; }
70 
71  Point_t const& GetCenter() const { return fCenter; }
72  double RMin() const;
73  double RMax() const;
74  double HalfL() const;
75  double HalfW() const;
76  double HalfH() const;
77  double Length() const { return 2.0 * HalfL(); }
78  double Width() const { return 2.0 * HalfW(); }
79  double Height() const { return 2.0 * HalfH(); }
80  double ThetaZ() const;
81  double ThetaZ(bool degrees) const;
84 
87  double CosThetaFromNormal(Point_t const& point) const;
90 
91  double DistanceToPoint(Point_t const& point) const;
94 
96 
104  Point_t toWorldCoords(LocalPoint_t const& local) const { return fTrans.toWorldCoords(local); }
106 
108  Vector_t toWorldCoords(LocalVector_t const& local) const { return fTrans.toWorldCoords(local); }
109 
111  LocalPoint_t toLocalCoords(Point_t const& world) const { return fTrans.toLocalCoords(world); }
112 
114  LocalVector_t toLocalCoords(Vector_t const& world) const { return fTrans.toLocalCoords(world); }
115 
117 
119  const TGeoNode* Node() const { return fOpDetNode; }
120 
121  // --- BEGIN -- detector shape ---------------------------------------------
124 
126  TGeoShape const* Shape() const { return Node()->GetVolume()->GetShape(); }
127 
143  template <typename ShapeObj>
144  bool isShape() const;
145 
160  template <typename ShapeObj>
161  bool isShapeLike() const;
162 
164  bool isTube() const { return isShapeLike<TGeoTube>(); }
165 
167  bool isBar() const { return isShape<TGeoBBox>(); }
168 
170  bool isSphere() const { return isShape<TGeoSphere>(); }
171 
173  // --- END -- detector shape -----------------------------------------------
174 
176  void UpdateAfterSorting(OpDetID opdetid);
177 
197  template <typename Stream>
198  void PrintOpDetInfo(Stream&& out, std::string indent = "", unsigned int verbosity = 0) const;
199 
206  std::string OpDetInfo(std::string indent = "", unsigned int verbosity = 0) const;
207 
209  static constexpr unsigned int MaxVerbosity = 2;
210 
211  private:
212  using LocalTransformation_t =
214 
216  const TGeoNode* fOpDetNode;
218 
220 
222  TGeoTube const* asTube() const { return dynamic_cast<TGeoTube const*>(Shape()); }
223 
225  TGeoSphere const* asSphere() const { return dynamic_cast<TGeoSphere const*>(Shape()); }
226 
228  TGeoBBox const* asBox() const { return dynamic_cast<TGeoBBox const*>(Shape()); }
229 
230  }; // class OpDetGeo
231 
232 } // namespace geo
233 
234 //------------------------------------------------------------------------------
235 //--- template implementation
236 //---
237 
238 template <typename ShapeObj>
240 {
241  static_assert(std::is_base_of_v<TGeoShape, std::decay_t<ShapeObj>>);
242 
243  // C++ understanding of the business instead of ROOT's (no strong reason)
244  TGeoShape const* shape = Shape(); // needed to convince Clang 7 I really mean it
245  return typeid(*shape) == typeid(std::decay_t<ShapeObj>);
246 }
247 
248 //------------------------------------------------------------------------------
249 template <typename ShapeObj>
251 {
252  static_assert(std::is_base_of_v<TGeoShape, std::decay_t<ShapeObj>>);
253 
254  // C++ understanding of the business instead of ROOT's (no strong reason)
255  return dynamic_cast<std::decay_t<ShapeObj> const*>(Shape()) != nullptr;
256 }
257 
258 //------------------------------------------------------------------------------
259 template <typename Stream>
261  std::string indent /* = "" */,
262  unsigned int verbosity /* = 0 */
263 ) const
264 {
265 
267 
268  //----------------------------------------------------------------------------
269  out << "optical detector " << ID() << " centered at " << GetCenter() << " cm";
270 
271  if (verbosity-- <= 0) return; // 0
272 
273  //----------------------------------------------------------------------------
274  if (isTube()) {
275  out << ", radius: " << RMax() << " cm";
276  if (cmp.nonZero(RMin())) out << " (inner: " << RMin() << " cm)";
277  out << ", length: " << Length() << " cm";
278  }
279  else if (isBar()) {
280  out << ", bar size " << Width() << " x " << Height() << " x " << Length() << " cm";
281  }
282  else if (TGeoSphere const* sphere = asSphere(); sphere) {
283  assert(isSphere());
284  auto const [th1, th2] = std::minmax({sphere->GetTheta1(), sphere->GetTheta2()});
285  out << ", ";
286  // some information out of the interface
287  if (cmp.zero(th1) && cmp.equal(th2, 180.0))
288  out << "spherical";
289  else if ((cmp.zero(th1) && cmp.equal(th2, 90.0)) ||
290  (cmp.equal(th1, 90.0) && cmp.equal(th2, 180.0))) {
291  out << "hemispherical";
292  }
293  else
294  out << "spherical portion (" << th1 << " -> " << th2 << " degree)";
295  out << " with external radius " << RMax() << " cm";
296  }
297  else
298  out << ", shape: '" << Shape()->IsA()->GetName() << "'";
299 
300  if (verbosity-- <= 0) return; // 1
301 
302  //----------------------------------------------------------------------------
303  out << ", theta(z): " << ThetaZ() << " rad";
304 
305  // if (verbosity-- <= 0) return; // 2
306 
307  //----------------------------------------------------------------------------
308 
309 } // geo::OpDetGeo::PrintOpDetInfo()
310 
311 //------------------------------------------------------------------------------
312 
313 #endif // LARCOREALG_GEOMETRY_OPDETGEO_H
const TGeoNode * Node() const
Returns the ROOT object describing the detector geometry.
Definition: OpDetGeo.h:119
TGeoSphere const * asSphere() const
Returns the geometry object as TGeoSphere, nullptr if not a sphere.
Definition: OpDetGeo.h:225
OpDetGeo(TGeoNode const *node, TransformationMatrix &&trans)
Definition: OpDetGeo.cxx:25
bool isShapeLike() const
Returns whether the detector inherits from the specified shape.
Definition: OpDetGeo.h:250
bool isShape() const
Returns whether the detector has the specified shape.
Definition: OpDetGeo.h:239
Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local optical detector frame to world frame.
Definition: OpDetGeo.h:105
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:160
std::pair< float, float > minmax(const float a, const float b)
minmax
bool isTube() const
Returns whether the detector shape is a cylinder (TGeoTube).
Definition: OpDetGeo.h:164
Provides simple real number checks.
bool isBar() const
Returns whether the detector shape is a bar (TGeoBBox).
Definition: OpDetGeo.h:167
constexpr bool zero(Value_t value) const
Returns whether the value is no farther from 0 than the threshold.
Point_t const & GetCenter() const
Definition: OpDetGeo.h:71
LocalPoint_t toLocalCoords(GlobalPoint_t const &world) const
Transforms a point from world frame to local frame.
OpticalVector_t LocalVector_t
Type of displacement vectors in the local GDML TPC frame.
Definition: OpDetGeo.h:62
const TGeoNode * fOpDetNode
Pointer to theopdet node.
Definition: OpDetGeo.h:216
Point_t fCenter
Stored geometric center of the optical detector.
Definition: OpDetGeo.h:217
OpDetID fID
Identifier of this optical detector.
Definition: OpDetGeo.h:219
Class for approximate comparisons.
double RMin() const
Definition: OpDetGeo.cxx:64
bool isSphere() const
Returns whether the detector shape is a hemisphere (TGeoSphere).
Definition: OpDetGeo.h:170
double RMax() const
Definition: OpDetGeo.cxx:31
double HalfW() const
Definition: OpDetGeo.cxx:48
Definitions of vector data types for optical detectors.
double DistanceToPoint(Point_t const &point) const
Returns the distance of the specified point from detector center [cm].
Definition: OpDetGeo.cxx:94
Local-to-world transformations with LArSoft geometry vectors.
double HalfL() const
Definition: OpDetGeo.cxx:40
Definitions of geometry vector data types.
TGeoBBox const * asBox() const
Returns the geometry object as TGeoBBox, nullptr if not box-derived.
Definition: OpDetGeo.h:228
void UpdateAfterSorting(OpDetID opdetid)
Performs all updates after cryostat has sorted the optical detectors.
Definition: OpDetGeo.cxx:116
std::string indent(std::size_t const i)
Vector_t toWorldCoords(LocalVector_t const &local) const
Transform direction vector from local to world.
Definition: OpDetGeo.h:108
double Length() const
Definition: OpDetGeo.h:77
void PrintOpDetInfo(Stream &&out, std::string indent="", unsigned int verbosity=0) const
Prints information about this optical detector.
Definition: OpDetGeo.h:260
Definition of data types for geometry description.
OpticalPoint_t LocalPoint_t
Type of points in the local GDML TPC frame.
Definition: OpDetGeo.h:59
OpDetID const & ID() const
Returns the geometry ID of this optical detector.
Definition: OpDetGeo.h:69
LocalVector_t toLocalCoords(Vector_t const &world) const
Transform direction vector from world to local.
Definition: OpDetGeo.h:114
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:180
double CosThetaFromNormal(Point_t const &point) const
Get cos(angle) to normal of this detector - used for solid angle calcs.
Definition: OpDetGeo.cxx:109
Selection of the type of transformation matrix used in geometry.
TGeoTube const * asTube() const
Returns the geometry object as TGeoTube, nullptr if not a tube.
Definition: OpDetGeo.h:222
double HalfH() const
Definition: OpDetGeo.cxx:56
static constexpr unsigned int MaxVerbosity
Maximum verbosity supported by PrintOpDetInfo().
Definition: OpDetGeo.h:209
constexpr bool nonZero(Value_t value) const
Returns whether the value is farther from 0 than the threshold.
LocalPoint_t toLocalCoords(Point_t const &world) const
Transform point from world frame to local optical detector frame.
Definition: OpDetGeo.h:111
double ThetaZ() const
Definition: OpDetGeo.cxx:72
OpticalPoint3DBase_t< double > OpticalPoint_t
Type of optical 3D point with representation in double precision.
LocalTransformation_t fTrans
Optical-detector-to-world transformation.
Definition: OpDetGeo.h:215
GlobalPoint_t toWorldCoords(LocalPoint_t const &local) const
Transforms a point from local frame to world frame.
double Width() const
Definition: OpDetGeo.h:78
OpticalVector3DBase_t< double > OpticalVector_t
constexpr bool equal(Value_t a, Value_t b) const
Returns whether a and b are no farther than the threshold.
std::string OpDetInfo(std::string indent="", unsigned int verbosity=0) const
Returns a string with optical detector information.
Definition: OpDetGeo.cxx:100
Float_t e
Definition: plot.C:35
The data type to uniquely identify a optical detector.
Definition: geo_types.h:249
ROOT libraries.
double Height() const
Definition: OpDetGeo.h:79
TGeoShape const * Shape() const
Returns the geometry object as TGeoShape.
Definition: OpDetGeo.h:126
ROOT::Math::Transform3D TransformationMatrix
Type of transformation matrix used in geometry.