LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 "TGeoTube.h"
20 #include "TGeoNode.h"
21 
22 // C/C++ libraries
23 #include <cmath> // std::cos(), ...
24 
25 
26 namespace geo{
27 
28  //-----------------------------------------
29  WireGeo::WireGeo(GeoNodePath_t const& path, size_t depth)
30  : fTrans(path, depth)
31  , flipped(false)
32  {
33  fWireNode = path[depth];
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((end.Z() - fCenter.Z())/fHalfL);
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  } // geo::WireGeo::WireGeo()
65 
66 
67  //......................................................................
68  void WireGeo::GetCenter(double* xyz, double localz) const
69  {
70  if (localz == 0.) { // if no dislocation is requested, we already have it
71  xyz[0] = fCenter.X();
72  xyz[1] = fCenter.Y();
73  xyz[2] = fCenter.Z();
74  return;
75  }
76 
77  double locz = relLength(localz);
78  if (std::abs(locz) > fHalfL) {
79  mf::LogWarning("WireGeo") << "asked for position along wire that"
80  " extends beyond the wire, returning position at end point";
81  locz = relLength((locz < 0)? -fHalfL: fHalfL);
82  }
83  const double local[3] = { 0., 0., locz };
84  LocalToWorld(local, xyz);
85  }
86 
87  //......................................................................
88  double geo::WireGeo::RMax() const
89  { return ((TGeoTube*)fWireNode->GetVolume()->GetShape())->GetRmax(); }
90 
91  //......................................................................
92  double geo::WireGeo::RMin() const
93  { return ((TGeoTube*)fWireNode->GetVolume()->GetShape())->GetRmin(); }
94 
95  //......................................................................
96  double WireGeo::ThetaZ(bool degrees) const
97  { return degrees? util::RadiansToDegrees(fThetaZ): fThetaZ; }
98 
99  //......................................................................
100  double WireGeo::DistanceFrom(geo::WireGeo const& wire) const {
101  //
102  // The algorithm assumes that picking any point on the wire will do,
103  // that is, that the wires are parallel.
104  //
105 
106  if (!isParallelTo(wire)) return 0;
107 
108  // a vector connecting to the other wire
109  auto const toWire = wire.GetCenter() - GetCenter();
110 
111  // the distance is that vector, times the sine of the angle with the wire
112  // direction; we get that in a generic way with a cross product.
113  // We don't even care about the sign here
114  // (if we did, we would do a dot-product with the normal to the plane,
115  // and we should get a positive distance if the other wire has larger wire
116  // coordinate than this one).
117  return toWire.Cross(Direction()).Mag();
118 
119  } // WireGeo::DistanceFrom()
120 
121 
122  //......................................................................
123  void WireGeo::UpdateAfterSorting(geo::WireID const&, bool flip) {
124 
125  // flip, if asked
126  if (flip) Flip();
127 
128  } // WireGeo::UpdateAfterSorting()
129 
130  //......................................................................
131  void WireGeo::Flip() {
132  // we don't need to do much to flip so far:
133  // - ThetaZ() is defined in [0, pi], invariant to flipping
134  // - we don't change the transformation matrices, that we want to be
135  // untouched and coherent with the original geometry source
136  // - center is invariant for flipping
137  // - start and end are computed on the fly (taking flipping into account)
138  // - ... and we chose to leave half length unsigned and independent
139 
140  // change the flipping bit
141  flipped = !flipped;
142 
143  } // WireGeo::Flip()
144 
145  //......................................................................
146 
147 }
void Flip()
Set to swap the start and end wire.
Definition: WireGeo.cxx:131
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
Definition: WireGeo.h:61
Point GetCenter() const
Returns the world coordinate of the center of the wire [cm].
Definition: WireGeo.h:171
double fThetaZ
angle of the wire with respect to the z direction
Definition: WireGeo.h:333
geo::Point_t fCenter
Center of the wire in world coordinates.
Definition: WireGeo.h:335
double DistanceFrom(geo::WireGeo const &wire) const
Returns 3D distance from the specified wire.
Definition: WireGeo.cxx:100
geo::Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local wire frame to world frame.
Definition: WireGeo.h:273
double ThetaZ() const
Returns angle of wire with respect to z axis in the Y-Z plane in radians.
Definition: WireGeo.h:192
double fHalfL
half length of the wire
Definition: WireGeo.h:334
void UpdateAfterSorting(geo::WireID const &, bool flip)
Definition: WireGeo.cxx:123
void LocalToWorld(const double *wire, double *world) const
Transform point from local wire frame to world frame.
Definition: WireGeo.h:269
double RMax() const
Returns the outer half-size of the wire [cm].
Definition: WireGeo.cxx:88
Utilities to extend the interface of geometry vectors.
Vector Direction() const
Returns the wire direction as a norm-one vector.
Definition: WireGeo.h:377
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:344
std::vector< TGeoNode const * > GeoNodePath_t
Definition: WireGeo.h:68
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
constexpr T RadiansToDegrees(T angle)
Converts the argument angle from radians into degrees ( )
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
void GetCenter(double *xyz, double localz=0.0) const
Fills the world coordinate of a point on the wire.
Definition: WireGeo.cxx:68
Namespace collecting geometry-related classes utilities.
bool isParallelTo(geo::WireGeo const &wire) const
Returns if this wire is parallel to another.
Definition: WireGeo.h:215
double RMin() const
Returns the inner radius of the wire (usually 0) [cm].
Definition: WireGeo.cxx:92
WireGeo(GeoNodePath_t const &path, size_t depth)
Definition: WireGeo.cxx:29
const TGeoNode * fWireNode
Pointer to the wire node.
Definition: WireGeo.h:332
bool flipped
whether start and end are reversed
Definition: WireGeo.h:337