LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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
17 #include "larcoreobj/SimpleTypesAndConstants/geo_types.h" // geo::OpDetID
19 
20 // ROOT libraries
21 #include "TClass.h"
22 #include "TGeoBBox.h"
23 #include "TGeoMatrix.h" // TGeoHMatrix
24 #include "TGeoSphere.h"
25 #include "TGeoTube.h"
26 
27 // C/C++ standard libraries
28 #include <algorithm> // std::minmax()
29 #include <array>
30 #include <cassert>
31 #include <string>
32 #include <type_traits> // std::decay_t(), std::is_base_of_v
33 #include <typeinfo> // typeid()
34 #include <vector>
35 
36 // forward declarations
37 class TGeoNode;
38 
39 namespace geo {
40 
42  class OpDetGeo {
43  public:
45 
61 
64 
66 
67  OpDetGeo(TGeoNode const& node, geo::TransformationMatrix&& trans);
68 
70  geo::OpDetID const& ID() const { return fID; }
71 
72  geo::Point_t const& GetCenter() const { return fCenter; }
73  double RMin() const;
74  double RMax() const;
75  double HalfL() const;
76  double HalfW() const;
77  double HalfH() const;
78  double Length() const { return 2.0 * HalfL(); }
79  double Width() const { return 2.0 * HalfW(); }
80  double Height() const { return 2.0 * HalfH(); }
81  double ThetaZ() const;
82  double ThetaZ(bool degrees) const;
85 
88  double CosThetaFromNormal(geo::Point_t const& point) const;
91 
92  double DistanceToPoint(geo::Point_t const& point) const;
95 
97 
105  geo::Point_t toWorldCoords(LocalPoint_t const& local) const
107  {
108  return fTrans.toWorldCoords(local);
109  }
110 
113  {
114  return fTrans.toWorldCoords(local);
115  }
116 
119  {
120  return fTrans.toLocalCoords(world);
121  }
122 
125  {
126  return fTrans.toLocalCoords(world);
127  }
128 
130 
132  const TGeoNode* Node() const { return fOpDetNode; }
133 
134  // --- BEGIN -- detector shape ---------------------------------------------
137 
139  TGeoShape const* Shape() const { return Node()->GetVolume()->GetShape(); }
140 
156  template <typename ShapeObj>
157  bool isShape() const;
158 
173  template <typename ShapeObj>
174  bool isShapeLike() const;
175 
177  bool isTube() const { return isShapeLike<TGeoTube>(); }
178 
180  bool isBar() const { return isShape<TGeoBBox>(); }
181 
183  bool isSphere() const { return isShape<TGeoSphere>(); }
184 
186  // --- END -- detector shape -----------------------------------------------
187 
189  void UpdateAfterSorting(geo::OpDetID opdetid);
190 
210  template <typename Stream>
211  void PrintOpDetInfo(Stream&& out, std::string indent = "", unsigned int verbosity = 0) const;
212 
219  std::string OpDetInfo(std::string indent = "", unsigned int verbosity = 0) const;
220 
222  static constexpr unsigned int MaxVerbosity = 2;
223 
224  private:
225  using LocalTransformation_t =
227 
229  const TGeoNode* fOpDetNode;
231 
233 
235  TGeoTube const* asTube() const { return dynamic_cast<TGeoTube const*>(Shape()); }
236 
238  TGeoSphere const* asSphere() const { return dynamic_cast<TGeoSphere const*>(Shape()); }
239 
241  TGeoBBox const* asBox() const { return dynamic_cast<TGeoBBox const*>(Shape()); }
242 
243  }; // class OpDetGeo
244 
245 } // namespace geo
246 
247 //------------------------------------------------------------------------------
248 //--- template implementation
249 //---
250 
251 template <typename ShapeObj>
253 {
254  static_assert(std::is_base_of_v<TGeoShape, std::decay_t<ShapeObj>>);
255 
256  // C++ understanding of the business instead of ROOT's (no strong reason)
257  TGeoShape const* shape = Shape(); // needed to convince Clang 7 I really mean it
258  return typeid(*shape) == typeid(std::decay_t<ShapeObj>);
259 
260 } // geo::OpDetGeo::isShape()
261 
262 //------------------------------------------------------------------------------
263 template <typename ShapeObj>
265 {
266  static_assert(std::is_base_of_v<TGeoShape, std::decay_t<ShapeObj>>);
267 
268  // C++ understanding of the business instead of ROOT's (no strong reason)
269  return dynamic_cast<std::decay_t<ShapeObj> const*>(Shape()) != nullptr;
270 
271 } // geo::OpDetGeo::isShapeLike()
272 
273 //------------------------------------------------------------------------------
274 template <typename Stream>
276  std::string indent /* = "" */,
277  unsigned int verbosity /* = 0 */
278 ) const
279 {
280 
282 
283  //----------------------------------------------------------------------------
284  out << "optical detector " << ID() << " centered at " << GetCenter() << " cm";
285 
286  if (verbosity-- <= 0) return; // 0
287 
288  //----------------------------------------------------------------------------
289  if (isTube()) {
290  out << ", radius: " << RMax() << " cm";
291  if (cmp.nonZero(RMin())) out << " (inner: " << RMin() << " cm)";
292  out << ", length: " << Length() << " cm";
293  }
294  else if (isBar()) {
295  out << ", bar size " << Width() << " x " << Height() << " x " << Length() << " cm";
296  }
297  else if (TGeoSphere const* sphere = asSphere(); sphere) {
298  assert(isSphere());
299  auto const [th1, th2] = std::minmax({sphere->GetTheta1(), sphere->GetTheta2()});
300  out << ", ";
301  // some information out of the interface
302  if (cmp.zero(th1) && cmp.equal(th2, 180.0))
303  out << "spherical";
304  else if ((cmp.zero(th1) && cmp.equal(th2, 90.0)) ||
305  (cmp.equal(th1, 90.0) && cmp.equal(th2, 180.0))) {
306  out << "hemispherical";
307  }
308  else
309  out << "spherical portion (" << th1 << " -> " << th2 << " degree)";
310  out << " with external radius " << RMax() << " cm";
311  }
312  else
313  out << ", shape: '" << Shape()->IsA()->GetName() << "'";
314 
315  if (verbosity-- <= 0) return; // 1
316 
317  //----------------------------------------------------------------------------
318  out << ", theta(z): " << ThetaZ() << " rad";
319 
320  // if (verbosity-- <= 0) return; // 2
321 
322  //----------------------------------------------------------------------------
323 
324 } // geo::OpDetGeo::PrintOpDetInfo()
325 
326 //------------------------------------------------------------------------------
327 
328 #endif // LARCOREALG_GEOMETRY_OPDETGEO_H
const TGeoNode * Node() const
Returns the ROOT object describing the detector geometry.
Definition: OpDetGeo.h:132
TGeoSphere const * asSphere() const
Returns the geometry object as TGeoSphere, nullptr if not a sphere.
Definition: OpDetGeo.h:238
bool isShapeLike() const
Returns whether the detector inherits from the specified shape.
Definition: OpDetGeo.h:264
double CosThetaFromNormal(geo::Point_t const &point) const
Get cos(angle) to normal of this detector - used for solid angle calcs.
Definition: OpDetGeo.cxx:113
bool isShape() const
Returns whether the detector has the specified shape.
Definition: OpDetGeo.h:252
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:177
Provides simple real number checks.
bool isBar() const
Returns whether the detector shape is a bar (TGeoBBox).
Definition: OpDetGeo.h:180
constexpr bool zero(Value_t value) const
Returns whether the value is no farther from 0 than the threshold.
LocalPoint_t toLocalCoords(GlobalPoint_t const &world) const
Transforms a point from world frame to local frame.
const TGeoNode * fOpDetNode
Pointer to theopdet node.
Definition: OpDetGeo.h:229
geo::OpticalVector_t LocalVector_t
Type of displacement vectors in the local GDML TPC frame.
Definition: OpDetGeo.h:63
LocalVector_t toLocalCoords(geo::Vector_t const &world) const
Transform direction vector from world to local.
Definition: OpDetGeo.h:124
Class for approximate comparisons.
double RMin() const
Definition: OpDetGeo.cxx:68
geo::Vector_t toWorldCoords(LocalVector_t const &local) const
Transform direction vector from local to world.
Definition: OpDetGeo.h:112
bool isSphere() const
Returns whether the detector shape is a hemisphere (TGeoSphere).
Definition: OpDetGeo.h:183
double RMax() const
Definition: OpDetGeo.cxx:35
double HalfW() const
Definition: OpDetGeo.cxx:52
Definitions of vector data types for optical detectors.
Local-to-world transformations with LArSoft geometry vectors.
double HalfL() const
Definition: OpDetGeo.cxx:44
Definitions of geometry vector data types.
TGeoBBox const * asBox() const
Returns the geometry object as TGeoBBox, nullptr if not box-derived.
Definition: OpDetGeo.h:241
OpDetGeo(TGeoNode const &node, geo::TransformationMatrix &&trans)
Definition: OpDetGeo.cxx:26
std::string indent(std::size_t const i)
double Length() const
Definition: OpDetGeo.h:78
void PrintOpDetInfo(Stream &&out, std::string indent="", unsigned int verbosity=0) const
Prints information about this optical detector.
Definition: OpDetGeo.h:275
geo::Point_t fCenter
Stored geometric center of the optical detector.
Definition: OpDetGeo.h:230
geo::Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local optical detector frame to world frame.
Definition: OpDetGeo.h:106
Definition of data types for geometry description.
void UpdateAfterSorting(geo::OpDetID opdetid)
Performs all updates after cryostat has sorted the optical detectors.
Definition: OpDetGeo.cxx:120
geo::Point_t const & GetCenter() const
Definition: OpDetGeo.h:72
double DistanceToPoint(geo::Point_t const &point) const
Returns the distance of the specified point from detector center [cm].
Definition: OpDetGeo.cxx:98
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
geo::OpticalPoint_t LocalPoint_t
Type of points in the local GDML TPC frame.
Definition: OpDetGeo.h:60
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:235
double HalfH() const
Definition: OpDetGeo.cxx:60
static constexpr unsigned int MaxVerbosity
Maximum verbosity supported by PrintOpDetInfo().
Definition: OpDetGeo.h:222
constexpr bool nonZero(Value_t value) const
Returns whether the value is farther from 0 than the threshold.
double ThetaZ() const
Definition: OpDetGeo.cxx:76
geo::OpDetID const & ID() const
Returns the geometry ID of this optical detector.
Definition: OpDetGeo.h:70
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:228
GlobalPoint_t toWorldCoords(LocalPoint_t const &local) const
Transforms a point from local frame to world frame.
double Width() const
Definition: OpDetGeo.h:79
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:104
Float_t e
Definition: plot.C:35
The data type to uniquely identify a optical detector.
Definition: geo_types.h:297
Namespace collecting geometry-related classes utilities.
double Height() const
Definition: OpDetGeo.h:80
geo::OpDetID fID
Identifier of this optical detector.
Definition: OpDetGeo.h:232
TGeoShape const * Shape() const
Returns the geometry object as TGeoShape.
Definition: OpDetGeo.h:139
LocalPoint_t toLocalCoords(geo::Point_t const &world) const
Transform point from world frame to local optical detector frame.
Definition: OpDetGeo.h:118
ROOT::Math::Transform3D TransformationMatrix
Type of transformation matrix used in geometry.