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