WireGeo.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file larcorealg/Geometry/WireGeo.cxx
3 /// \brief Encapsulate the geometry of a wire
4 ///
5 /// \author brebel@fnal.gov
6 ////////////////////////////////////////////////////////////////////////
7 
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 "TGeoTube.h"
20 #include "TGeoNode.h"
21 
22 // C/C++ libraries
23 #include <algorithm> // std::clamp()...
24 #include <cmath> // std::cos(), std::isfinite()...
25 #include <sstream>
26 #include <cassert>
27 
28 
29 namespace geo{
30 
31  //-----------------------------------------
32  WireGeo::WireGeo(TGeoNode const& node, geo::TransformationMatrix&& trans)
33  : fWireNode(&node)
34  , fTrans(std::move(trans))
35  , flipped(false)
36  {
37  fHalfL = ((TGeoTube*)fWireNode->GetVolume()->GetShape())->GetDZ();
38 
39  // uncomment the following to check the paths to the wires
40  // std::string p(base);
41  // for(int i = 0; i <= depth; ++i){
42  // p += "/";
43  // p += path[i]->GetName();
44  // }
45  // std::cout << p.c_str() << std::endl;
46 
47  // determine the orientation of the wire
48  auto lp = geo::origin<LocalPoint_t>();
49  fCenter = toWorldCoords(lp);
50 
51  lp.SetZ(fHalfL);
52  auto end = toWorldCoords(lp);
53 
54  fThetaZ = std::acos(std::clamp((end.Z() - fCenter.Z())/fHalfL, -1.0, +1.0));
55 
56  // check to see if it runs "forward" or "backwards" in z
57  // check is made looking at the y position of the end point
58  // relative to the center point because you want to know if
59  // the end point is above or below the center of the wire in
60  // the yz plane
61  if(end.Y() < fCenter.Y()) fThetaZ *= -1.;
62 
63  //This ensures we are looking at the angle between 0 and Pi
64  //as if the wire runs at one angle it also runs at that angle +-Pi
65  if(fThetaZ < 0) fThetaZ += util::pi();
66 
67  assert(std::isfinite(fThetaZ));
68 
69  } // geo::WireGeo::WireGeo()
70 
71 
72  //......................................................................
73  void WireGeo::GetCenter(double* xyz, double localz) const
74  {
75  if (localz == 0.) { // if no dislocation is requested, we already have it
77  return;
78  }
79 
80  double locz = relLength(localz);
81  if (std::abs(locz) > fHalfL) {
82  mf::LogWarning("WireGeo") << "asked for position along wire that"
83  " extends beyond the wire, returning position at end point";
84  locz = relLength((locz < 0)? -fHalfL: fHalfL);
85  }
86  const double local[3] = { 0., 0., locz };
87  LocalToWorld(local, xyz);
88  }
89 
90  //......................................................................
91  double geo::WireGeo::RMax() const
92  { return ((TGeoTube*)fWireNode->GetVolume()->GetShape())->GetRmax(); }
93 
94  //......................................................................
95  double geo::WireGeo::RMin() const
96  { return ((TGeoTube*)fWireNode->GetVolume()->GetShape())->GetRmin(); }
97 
98  //......................................................................
99  double WireGeo::ThetaZ(bool degrees) const
100  { return degrees? util::RadiansToDegrees(fThetaZ): fThetaZ; }
101 
102  //......................................................................
104  (std::string indent /* = "" */, unsigned int verbosity /* = 1 */) const
105  {
106  std::ostringstream sstr;
107  PrintWireInfo(sstr, indent, verbosity);
108  return sstr.str();
109  } // WireGeo::WireInfo()
110 
111 
112  //......................................................................
113  double WireGeo::DistanceFrom(geo::WireGeo const& wire) const {
114  //
115  // The algorithm assumes that picking any point on the wire will do,
116  // that is, that the wires are parallel.
117  //
118 
119  if (!isParallelTo(wire)) return 0;
120 
121  // a vector connecting to the other wire
122  auto const toWire = wire.GetCenter() - GetCenter();
123 
124  // the distance is that vector, times the sine of the angle with the wire
125  // direction; we get that in a generic way with a cross product.
126  // We don't even care about the sign here
127  // (if we did, we would do a dot-product with the normal to the plane,
128  // and we should get a positive distance if the other wire has larger wire
129  // coordinate than this one).
130  return toWire.Cross(Direction()).Mag();
131 
132  } // WireGeo::DistanceFrom()
133 
134 
135  //......................................................................
136  void WireGeo::UpdateAfterSorting(geo::WireID const&, bool flip) {
137 
138  // flip, if asked
139  if (flip) Flip();
140 
141  } // WireGeo::UpdateAfterSorting()
142 
143  //......................................................................
144  void WireGeo::Flip() {
145  // we don't need to do much to flip so far:
146  // - ThetaZ() is defined in [0, pi], invariant to flipping
147  // - we don't change the transformation matrices, that we want to be
148  // untouched and coherent with the original geometry source
149  // - center is invariant for flipping
150  // - start and end are computed on the fly (taking flipping into account)
151  // - ... and we chose to leave half length unsigned and independent
152 
153  // change the flipping bit
154  flipped = !flipped;
155 
156  } // WireGeo::Flip()
157 
158  //......................................................................
159 
160 }
161 ////////////////////////////////////////////////////////////////////////
void Flip()
Set to swap the start and end wire.
Definition: WireGeo.cxx:144
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
Definition: WireGeo.h:65
Utilities to extend the interface of geometry vectors.
void PrintWireInfo(Stream &&out, std::string indent="", unsigned int verbosity=1) const
Prints information about this wire.
Definition: WireGeo.h:596
Point GetCenter() const
Definition: WireGeo.h:212
double fThetaZ
angle of the wire with respect to the z direction
Definition: WireGeo.h:484
geo::Point_t fCenter
Center of the wire in world coordinates.
Definition: WireGeo.h:486
std::string string
Definition: nybbler.cc:12
double DistanceFrom(geo::WireGeo const &wire) const
Returns 3D distance from the specified wire.
Definition: WireGeo.cxx:113
STL namespace.
geo::Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local wire frame to world frame.
Definition: WireGeo.h:359
double ThetaZ() const
Returns angle of wire with respect to z axis in the Y-Z plane in radians.
Definition: WireGeo.h:250
unsigned int fillCoords(Coords &dest, Vector const &src)
Fills a coordinate array with the coordinates of a vector.
double fHalfL
half length of the wire
Definition: WireGeo.h:485
std::string WireInfo(std::string indent="", unsigned int verbosity=1) const
Returns a string with all the information of the wire.
Definition: WireGeo.cxx:104
void UpdateAfterSorting(geo::WireID const &, bool flip)
Definition: WireGeo.cxx:136
T abs(T value)
void LocalToWorld(const double *wire, double *world) const
Transform point from local wire frame to world frame.
Definition: WireGeo.h:355
bool isfinite(Vector const &v)
Returns whether all components of the vector are finite.
double RMax() const
Returns the outer half-size of the wire [cm].
Definition: WireGeo.cxx:91
def move(depos, offset)
Definition: depos.py:107
Vector Direction() const
Definition: WireGeo.h:587
Encapsulate the geometry of a wire.
double relLength(double local) const
Returns the relative length from center to be used when transforming.
Definition: WireGeo.h:495
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
WireGeo(TGeoNode const &node, geo::TransformationMatrix &&trans)
Constructor from a ROOT geometry node and a transformation.
Definition: WireGeo.cxx:32
constexpr T RadiansToDegrees(T angle)
Converts the argument angle from radians into degrees ( )
void GetCenter(double *xyz, double localz=0.0) const
Fills the world coordinate of a point on the wire.
Definition: WireGeo.cxx:73
Collection of Physical constants used in LArSoft.
LArSoft geometry interface.
Definition: ChannelGeo.h:16
bool isParallelTo(geo::WireGeo const &wire) const
Returns if this wire is parallel to another.
Definition: WireGeo.h:281
double RMin() const
Returns the inner radius of the wire (usually 0) [cm].
Definition: WireGeo.cxx:95
ROOT::Math::Transform3D TransformationMatrix
Type of transformation matrix used in geometry.
const TGeoNode * fWireNode
Pointer to the wire node.
Definition: WireGeo.h:483
bool flipped
whether start and end are reversed
Definition: WireGeo.h:488