OpDetGeo.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file larcorealg/Geometry/OpDetGeo.cxx
3 /// \brief Encapsulate the geometry of an OpDet
4 ///
5 /// \author bjpjones@mit.edu
6 ////////////////////////////////////////////////////////////////////////
7 
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 "TGeoTube.h"
18 #include "TGeoNode.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 
31  fCenter = toWorldCoords(geo::origin<LocalPoint_t>());
32  }
33 
34  //......................................................................
35 
36  /// Return the center position of an opdet
37  /// \param xyz : 3-D array. The returned location.
38  /// \param localz : Distance along the length of the volume
39  /// (cm). Default is center of wire
40  void OpDetGeo::GetCenter(double* xyz, double localz) const
41  {
42  double xyzLocal[3] = {0.,0.,localz};
43  this->LocalToWorld(xyzLocal, xyz);
44  }
45 
46  //......................................................................
47 
48  double OpDetGeo::RMax() const
49  {
50  if (TGeoSphere const* sphere = asSphere(); sphere) {
51  return sphere->GetRmax();
52  }
53  else if (TGeoTube const* tube = asTube(); tube) {
54  return tube->GetRmax();
55  }
56  else {
57  throw std::bad_cast{};
58  }
59  }
60 
61  //......................................................................
62 
63  double OpDetGeo::HalfL() const
64  {
65  TGeoBBox const* pBox = asBox();
66  return pBox? pBox->GetDZ(): 0.0;
67  }
68 
69  //......................................................................
70 
71  double OpDetGeo::HalfW() const
72  {
73  TGeoBBox const* pBox = asBox();
74  return pBox? pBox->GetDX(): 0.0;
75  }
76 
77  //......................................................................
78 
79  double OpDetGeo::HalfH() const
80  {
81  TGeoBBox const* pBox = asBox();
82  return pBox? pBox->GetDY(): 0.0;
83  }
84 
85  //......................................................................
86 
87  double OpDetGeo::RMin() const
88  {
89  if (TGeoSphere const* sphere = asSphere(); sphere) {
90  return sphere->GetRmin();
91  }
92  else if (TGeoTube const* tube = asTube(); tube) {
93  return tube->GetRmin();
94  }
95  else {
96  throw std::bad_cast{};
97  }
98  }
99 
100  //......................................................................
101  double OpDetGeo::ThetaZ() const
102  {
103  auto const& center = GetCenter();
104  auto const& end = toWorldCoords(LocalPoint_t{ 0.0, 0.0, HalfL() });
105 
106  // TODO change this into something generic
107  //either y or x will be 0, so adding both will always catch the right
108  //one
109  double angle = (end.Y()-center.Y()+end.X()-center.X()) /
110  std::abs(end.Y()-center.Y()+center.X()-end.X()) *
111  std::acos((end.Z() - center.Z())/HalfL());
112  if (angle < 0) angle += util::pi();
113  return angle;
114  }
115 
116  //......................................................................
117  double OpDetGeo::ThetaZ(bool degree) const
118  { return degree? util::RadiansToDegrees(ThetaZ()): ThetaZ(); }
119 
120 
121 
122  //......................................................................
123  double OpDetGeo::DistanceToPoint(geo::Point_t const& point) const
124  { return (point - GetCenter()).R(); }
125  double OpDetGeo::DistanceToPoint(double const* xyz) const
126  { return DistanceToPoint(geo::vect::makeFromCoords<geo::Point_t>(xyz)); }
127 
128  //......................................................................
130  (std::string indent /* = "" */, unsigned int verbosity /* = 0 */) const
131  {
132  std::ostringstream sstr;
133  PrintOpDetInfo(sstr, indent, verbosity);
134  return sstr.str();
135  } // OpDetGeo::OpDetInfo()
136 
137  //......................................................................
138  double OpDetGeo::CosThetaFromNormal(geo::Point_t const& point) const {
139  auto const& local = toLocalCoords(point);
140  return local.Z() / local.R();
141  }
142  double OpDetGeo::CosThetaFromNormal(double const* xyz) const
143  { return CosThetaFromNormal(geo::vect::makeFromCoords<geo::Point_t>(xyz)); }
144 
145  //......................................................................
147 
148  fID = opdetid;
149 
150  } // OpDetGeo::UpdateAfterSorting()
151 
152 
153  //......................................................................
154 
155 }
156 ////////////////////////////////////////////////////////////////////////
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
TGeoSphere const * asSphere() const
Returns the geometry object as TGeoSphere, nullptr if not a sphere.
Definition: OpDetGeo.h:257
Utilities to extend the interface of geometry vectors.
double CosThetaFromNormal(geo::Point_t const &point) const
Get cos(angle) to normal of this detector - used for solid angle calcs.
Definition: OpDetGeo.cxx:138
std::string string
Definition: nybbler.cc:12
STL namespace.
const TGeoNode * fOpDetNode
Pointer to theopdet node.
Definition: OpDetGeo.h:247
double RMin() const
Definition: OpDetGeo.cxx:87
double RMax() const
Definition: OpDetGeo.cxx:48
double HalfW() const
Definition: OpDetGeo.cxx:71
T abs(T value)
double HalfL() const
Definition: OpDetGeo.cxx:63
TGeoBBox const * asBox() const
Returns the geometry object as TGeoBBox, nullptr if not box-derived.
Definition: OpDetGeo.h:261
OpDetGeo(TGeoNode const &node, geo::TransformationMatrix &&trans)
Definition: OpDetGeo.cxx:26
def move(depos, offset)
Definition: depos.py:107
void PrintOpDetInfo(Stream &&out, std::string indent="", unsigned int verbosity=0) const
Prints information about this optical detector.
Definition: OpDetGeo.h:296
geo::Point_t fCenter
Stored geometric center of the optical detector.
Definition: OpDetGeo.h:248
geo::Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local optical detector frame to world frame.
Definition: OpDetGeo.h:116
void UpdateAfterSorting(geo::OpDetID opdetid)
Performs all updates after cryostat has sorted the optical detectors.
Definition: OpDetGeo.cxx:146
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:184
Encapsulate the geometry of an optical detector.
geo::Point_t const & GetCenter() const
Definition: OpDetGeo.h:75
double DistanceToPoint(geo::Point_t const &point) const
Returns the distance of the specified point from detector center [cm].
Definition: OpDetGeo.cxx:123
geo::OpticalPoint_t LocalPoint_t
Type of points in the local GDML TPC frame.
Definition: OpDetGeo.h:62
TGeoTube const * asTube() const
Returns the geometry object as TGeoTube, nullptr if not a tube.
Definition: OpDetGeo.h:253
double HalfH() const
Definition: OpDetGeo.cxx:79
def center(depos, point)
Definition: depos.py:117
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
double ThetaZ() const
Definition: OpDetGeo.cxx:101
constexpr T RadiansToDegrees(T angle)
Converts the argument angle from radians into degrees ( )
static constexpr double degree
Definition: Units.h:161
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:130
The data type to uniquely identify a optical detector.
Definition: geo_types.h:297
LArSoft geometry interface.
Definition: ChannelGeo.h:16
geo::OpDetID fID
Identifier of this optical detector.
Definition: OpDetGeo.h:250
void LocalToWorld(const double *opdet, double *world) const
Transform point from local optical detector frame to world frame.
Definition: OpDetGeo.h:112
LocalPoint_t toLocalCoords(geo::Point_t const &world) const
Transform point from world frame to local optical detector frame.
Definition: OpDetGeo.h:132
ROOT::Math::Transform3D TransformationMatrix
Type of transformation matrix used in geometry.