LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
OpDetGeo.cxx
Go to the documentation of this file.
1 
8 // class header
10 
11 // LArSoft libraries
12 #include "larcorealg/Geometry/geo_vectors_utils.h" // geo::vect::makeFromCoords()
14 
15 // ROOT libraries
16 #include "TGeoManager.h"
17 #include "TGeoNode.h"
18 #include "TGeoTube.h"
19 
20 // C/C++ standard libraries
21 #include <cmath>
22 
23 namespace geo {
24 
25  //-----------------------------------------
26  OpDetGeo::OpDetGeo(TGeoNode const& node, geo::TransformationMatrix&& trans)
27  : fTrans(std::move(trans))
28  {
29  fOpDetNode = &node;
30  fCenter = toWorldCoords(geo::origin<LocalPoint_t>());
31  }
32 
33  //......................................................................
34 
35  double OpDetGeo::RMax() const
36  {
37  if (TGeoSphere const* sphere = asSphere(); sphere) { return sphere->GetRmax(); }
38  if (TGeoTube const* tube = asTube(); tube) { return tube->GetRmax(); }
39  throw std::bad_cast{};
40  }
41 
42  //......................................................................
43 
44  double OpDetGeo::HalfL() const
45  {
46  TGeoBBox const* pBox = asBox();
47  return pBox ? pBox->GetDZ() : 0.0;
48  }
49 
50  //......................................................................
51 
52  double OpDetGeo::HalfW() const
53  {
54  TGeoBBox const* pBox = asBox();
55  return pBox ? pBox->GetDX() : 0.0;
56  }
57 
58  //......................................................................
59 
60  double OpDetGeo::HalfH() const
61  {
62  TGeoBBox const* pBox = asBox();
63  return pBox ? pBox->GetDY() : 0.0;
64  }
65 
66  //......................................................................
67 
68  double OpDetGeo::RMin() const
69  {
70  if (TGeoSphere const* sphere = asSphere(); sphere) { return sphere->GetRmin(); }
71  if (TGeoTube const* tube = asTube(); tube) { return tube->GetRmin(); }
72  throw std::bad_cast{};
73  }
74 
75  //......................................................................
76  double OpDetGeo::ThetaZ() const
77  {
78  auto const& center = GetCenter();
79  auto const& end = toWorldCoords(LocalPoint_t{0.0, 0.0, HalfL()});
80 
81  // TODO change this into something generic
82  //either y or x will be 0, so adding both will always catch the right
83  //one
84  double angle = (end.Y() - center.Y() + end.X() - center.X()) /
85  std::abs(end.Y() - center.Y() + center.X() - end.X()) *
86  std::acos((end.Z() - center.Z()) / HalfL());
87  if (angle < 0) angle += util::pi();
88  return angle;
89  }
90 
91  //......................................................................
92  double OpDetGeo::ThetaZ(bool degree) const
93  {
94  return degree ? util::RadiansToDegrees(ThetaZ()) : ThetaZ();
95  }
96 
97  //......................................................................
98  double OpDetGeo::DistanceToPoint(geo::Point_t const& point) const
99  {
100  return (point - GetCenter()).R();
101  }
102 
103  //......................................................................
104  std::string OpDetGeo::OpDetInfo(std::string indent /* = "" */,
105  unsigned int verbosity /* = 0 */) const
106  {
107  std::ostringstream sstr;
108  PrintOpDetInfo(sstr, indent, verbosity);
109  return sstr.str();
110  }
111 
112  //......................................................................
113  double OpDetGeo::CosThetaFromNormal(geo::Point_t const& point) const
114  {
115  auto const& local = toLocalCoords(point);
116  return local.Z() / local.R();
117  }
118 
119  //......................................................................
121  {
122  fID = opdetid;
123  }
124 
125 }
TGeoSphere const * asSphere() const
Returns the geometry object as TGeoSphere, nullptr if not a sphere.
Definition: OpDetGeo.h:238
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
constexpr auto abs(T v)
Returns the absolute value of the argument.
STL namespace.
const TGeoNode * fOpDetNode
Pointer to theopdet node.
Definition: OpDetGeo.h:229
double RMin() const
Definition: OpDetGeo.cxx:68
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
double RMax() const
Definition: OpDetGeo.cxx:35
double HalfW() const
Definition: OpDetGeo.cxx:52
double HalfL() const
Definition: OpDetGeo.cxx:44
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)
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
Utilities to extend the interface of geometry vectors.
geo::Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local optical detector frame to world frame.
Definition: OpDetGeo.h:106
void UpdateAfterSorting(geo::OpDetID opdetid)
Performs all updates after cryostat has sorted the optical detectors.
Definition: OpDetGeo.cxx:120
Encapsulate the geometry of an optical detector.
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
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
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
double ThetaZ() const
Definition: OpDetGeo.cxx:76
constexpr T RadiansToDegrees(T angle)
Converts the argument angle from radians into degrees ( )
Collection of Physical constants used in LArSoft.
std::string OpDetInfo(std::string indent="", unsigned int verbosity=0) const
Returns a string with optical detector information.
Definition: OpDetGeo.cxx:104
The data type to uniquely identify a optical detector.
Definition: geo_types.h:297
Namespace collecting geometry-related classes utilities.
geo::OpDetID fID
Identifier of this optical detector.
Definition: OpDetGeo.h:232
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.