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