LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
WireGeo.cxx
Go to the documentation of this file.
1 
6 // class header
8 
9 // LArSoft libraries
10 #include "larcorealg/Geometry/geo_vectors_utils.h" // geo::vect
12 
13 // framework
15 
16 // ROOT
17 #include "TGeoNode.h"
18 #include "TGeoTube.h"
19 
20 // C/C++ libraries
21 #include <algorithm> // std::clamp()...
22 #include <cassert>
23 #include <cmath> // std::cos(), std::isfinite()...
24 #include <sstream>
25 
26 namespace geo {
27 
28  //-----------------------------------------
29  WireGeo::WireGeo(TGeoNode const* node, TransformationMatrix&& trans)
30  : fWireNode(node), fTrans(std::move(trans)), flipped(false)
31  {
32  fHalfL = ((TGeoTube*)fWireNode->GetVolume()->GetShape())->GetDZ();
33 
34  // uncomment the following to check the paths to the wires
35  // std::string p(base);
36  // for(int i = 0; i <= depth; ++i){
37  // p += "/";
38  // p += path[i]->GetName();
39  // }
40  // std::cout << p.c_str() << std::endl;
41 
42  // determine the orientation of the wire
43  auto lp = origin<LocalPoint_t>();
44  fCenter = toWorldCoords(lp);
45 
46  lp.SetZ(fHalfL);
47  auto end = toWorldCoords(lp);
48 
49  fThetaZ = std::acos(std::clamp((end.Z() - fCenter.Z()) / fHalfL, -1.0, +1.0));
50 
51  // check to see if it runs "forward" or "backwards" in z
52  // check is made looking at the y position of the end point
53  // relative to the center point because you want to know if
54  // the end point is above or below the center of the wire in
55  // the yz plane
56  if (end.Y() < fCenter.Y()) fThetaZ *= -1.;
57 
58  //This ensures we are looking at the angle between 0 and Pi
59  //as if the wire runs at one angle it also runs at that angle +-Pi
60  if (fThetaZ < 0) fThetaZ += util::pi();
61 
62  assert(std::isfinite(fThetaZ));
63 
64  } // geo::WireGeo::WireGeo()
65 
66  //......................................................................
67  double geo::WireGeo::RMax() const
68  {
69  return ((TGeoTube*)fWireNode->GetVolume()->GetShape())->GetRmax();
70  }
71 
72  //......................................................................
73  double geo::WireGeo::RMin() const
74  {
75  return ((TGeoTube*)fWireNode->GetVolume()->GetShape())->GetRmin();
76  }
77 
78  //......................................................................
79  double WireGeo::ThetaZ(bool degrees) const
80  {
81  return degrees ? util::RadiansToDegrees(fThetaZ) : fThetaZ;
82  }
83 
84  //......................................................................
85  std::string WireGeo::WireInfo(std::string indent /* = "" */,
86  unsigned int verbosity /* = 1 */) const
87  {
88  std::ostringstream sstr;
89  PrintWireInfo(sstr, indent, verbosity);
90  return sstr.str();
91  } // WireGeo::WireInfo()
92 
93  //......................................................................
94  double WireGeo::DistanceFrom(WireGeo const& wire) const
95  {
96  //
97  // The algorithm assumes that picking any point on the wire will do,
98  // that is, that the wires are parallel.
99  //
100 
101  if (!isParallelTo(wire)) return 0;
102 
103  // a vector connecting to the other wire
104  auto const toWire = wire.GetCenter() - GetCenter();
105 
106  // the distance is that vector, times the sine of the angle with the wire
107  // direction; we get that in a generic way with a cross product.
108  // We don't even care about the sign here
109  // (if we did, we would do a dot-product with the normal to the plane,
110  // and we should get a positive distance if the other wire has larger wire
111  // coordinate than this one).
112  return toWire.Cross(Direction()).R();
113 
114  } // WireGeo::DistanceFrom()
115 
116  //......................................................................
117  void WireGeo::UpdateAfterSorting(WireID const&, bool flip)
118  {
119 
120  // flip, if asked
121  if (flip) Flip();
122 
123  } // WireGeo::UpdateAfterSorting()
124 
125  //......................................................................
127  {
128  // we don't need to do much to flip so far:
129  // - ThetaZ() is defined in [0, pi], invariant to flipping
130  // - we don't change the transformation matrices, that we want to be
131  // untouched and coherent with the original geometry source
132  // - center is invariant for flipping
133  // - start and end are computed on the fly (taking flipping into account)
134  // - ... and we chose to leave half length unsigned and independent
135 
136  // change the flipping bit
137  flipped = !flipped;
138 
139  } // WireGeo::Flip()
140 
141  //......................................................................
142 
143 }
void Flip()
Set to swap the start and end wire.
Definition: WireGeo.cxx:126
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
Definition: WireGeo.h:112
bool isParallelTo(WireGeo const &wire) const
Returns if this wire is parallel to another.
Definition: WireGeo.h:277
void PrintWireInfo(Stream &&out, std::string indent="", unsigned int verbosity=1) const
Prints information about this wire.
Definition: WireGeo.h:484
Point_t const & GetCenter() const
Returns the world coordinate of the center of the wire [cm].
Definition: WireGeo.h:219
double fThetaZ
angle of the wire with respect to the z direction
Definition: WireGeo.h:457
Point_t fCenter
Center of the wire in world coordinates.
Definition: WireGeo.h:459
STL namespace.
double ThetaZ() const
Returns angle of wire with respect to z axis in the Y-Z plane in radians.
Definition: WireGeo.h:246
void UpdateAfterSorting(WireID const &, bool flip)
Definition: WireGeo.cxx:117
double fHalfL
half length of the wire
Definition: WireGeo.h:458
std::string WireInfo(std::string indent="", unsigned int verbosity=1) const
Returns a string with all the information of the wire.
Definition: WireGeo.cxx:85
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
bool isfinite(Vector const &v)
Returns whether all components of the vector are finite.
Vector_t Direction() const
Definition: WireGeo.h:287
double RMax() const
Returns the outer half-size of the wire [cm].
Definition: WireGeo.cxx:67
std::string indent(std::size_t const i)
Utilities to extend the interface of geometry vectors.This library provides facilities that can be us...
Encapsulate the geometry of a wire .
WireGeo(TGeoNode const *node, TransformationMatrix &&trans)
Constructor from a ROOT geometry node and a transformation.
Definition: WireGeo.cxx:29
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
double DistanceFrom(WireGeo const &wire) const
Returns 3D distance from the specified wire.
Definition: WireGeo.cxx:94
constexpr T RadiansToDegrees(T angle)
Converts the argument angle from radians into degrees ( )
Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local wire frame to world frame.
Definition: WireGeo.h:350
Collection of Physical constants used in LArSoft.
ROOT libraries.
double RMin() const
Returns the inner radius of the wire (usually 0) [cm].
Definition: WireGeo.cxx:73
ROOT::Math::Transform3D TransformationMatrix
Type of transformation matrix used in geometry.
const TGeoNode * fWireNode
Pointer to the wire node.
Definition: WireGeo.h:456
bool flipped
whether (0, 0, fHalfL) identified end (false) or start (true)
Definition: WireGeo.h:461