LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
WireGeo.h
Go to the documentation of this file.
1 
9 #ifndef LARCOREALG_GEOMETRY_WIREGEO_H
10 #define LARCOREALG_GEOMETRY_WIREGEO_H
11 
12 // LArSoft
16 #include "larcorealg/Geometry/geo_vectors_utils.h" // geo::vect
17 
18 // ROOT
19 #include "Math/GenVector/Transform3D.h"
20 #include "TVector3.h"
21 
22 // C/C++ libraries
23 #include <cmath> // std::sin(), ...
24 #include <string>
25 #include <type_traits> // std::is_nothrow_move_constructible<>
26 #include <vector>
27 
28 class TGeoNode;
29 
30 namespace geo {
31 
32  class WireGeo;
33  struct WireID;
34 
51  Point_t WiresIntersection(WireGeo const& wireA, WireGeo const& wireB);
52 
84  IntersectionPointAndOffsets<Point_t> WiresIntersectionAndOffsets(WireGeo const& wireA,
85  WireGeo const& wireB);
86 
114  class WireGeo {
115  public:
116  using ID_t = WireID;
117  using GeoNodePath_t = std::vector<TGeoNode const*>;
118 
119  // -- BEGIN -- Types for geometry-local reference vectors ------------------
121 
135  struct WireGeoCoordinatesTag {};
137 
140 
143 
145  // -- END ---- Types for geometry-local reference vectors ------------------
146 
159  WireGeo(TGeoNode const& node, TransformationMatrix&& trans);
160 
161  // -- BEGIN -- Size and coordinates ----------------------------------------
164 
166  double RMax() const;
169 
171  double HalfL() const { return fHalfL; }
174 
176  double RMin() const;
179 
181 
194  Point_t GetPositionFromCenter(double localz) const
195  {
197  }
199 
201 
214  {
215  return toWorldCoords(LocalPoint_t{0.0, 0.0, relLength(localz)});
216  }
218 
220  Point_t const& GetCenter() const { return fCenter; }
223 
225  Point_t GetStart() const { return GetPositionFromCenterUnbounded(-HalfL()); }
228 
230  Point_t GetEnd() const { return GetPositionFromCenterUnbounded(+HalfL()); }
233 
235  double Length() const { return 2. * HalfL(); }
238 
240  // -- END ---- Size and coordinates ---------------------------------------
241 
242  // -- BEGIN -- Orientation and angles --------------------------------------
245 
247  double ThetaZ() const { return fThetaZ; }
250 
252 
257  double ThetaZ(bool degrees) const;
259 
261  double CosThetaZ() const { return std::cos(ThetaZ()); }
263  double SinThetaZ() const { return std::sin(ThetaZ()); }
264  double TanThetaZ() const { return std::tan(ThetaZ()); }
266 
268  bool isHorizontal() const { return std::abs(SinThetaZ()) < 1e-5; }
271 
273  bool isVertical() const { return std::abs(CosThetaZ()) < 1e-5; }
276 
278  bool isParallelTo(WireGeo const& wire) const
280  {
281  return // parallel if the dot product of the directions is about +/- 1
282  std::abs(std::abs(Direction().Dot(wire.Direction())) - 1.) < 1e-5;
283  }
285 
287  Vector_t Direction() const
290  {
291  // maybe (GetCenter() - GetStart()) / HalfL() would be faster;
292  return (GetEnd() - GetStart()) / Length();
293  }
295 
297  // -- END ---- Orientation and angles --------------------------------------
298 
299  // -- BEGIN -- Printing ----------------------------------------------------
302 
324  template <typename Stream>
325  void PrintWireInfo(Stream&& out, std::string indent = "", unsigned int verbosity = 1) const;
326 
333  std::string WireInfo(std::string indent = "", unsigned int verbosity = 1) const;
334 
336  static constexpr unsigned int MaxVerbosity = 4;
337 
339  // -- END ---- Printing ----------------------------------------------------
340 
341  // -- BEGIN -- Coordinate transformation -----------------------------------
349 
352  Point_t toWorldCoords(LocalPoint_t const& local) const { return fTrans.toWorldCoords(local); }
353 
355  Vector_t toWorldCoords(LocalVector_t const& local) const { return fTrans.toWorldCoords(local); }
356 
358  LocalPoint_t toLocalCoords(Point_t const& world) const { return fTrans.toLocalCoords(world); }
359 
361  LocalVector_t toLocalCoords(Vector_t const& world) const { return fTrans.toLocalCoords(world); }
362 
364  // -- END ---- Coordinate transformation -----------------------------------
365 
366  const TGeoNode* Node() const { return fWireNode; }
367 
368  // -- BEGIN -- Geometric properties and algorithms -------------------------
371 
374  double ComputeZatY0() const { return fCenter.Z() - fCenter.Y() / TanThetaZ(); }
375 
383  double DistanceFrom(WireGeo const& wire) const;
384 
400  Point_t IntersectionWith(WireGeo const& other) const { return WiresIntersection(*this, other); }
401 
436  {
437  auto const [point, ofsA, ofsB] = WiresIntersectionAndOffsets(*this, other);
438  return {point, ofsA, ofsB};
439  }
440 
442  // -- END ---- Geometric properties and algorithms -------------------------
443 
446  void UpdateAfterSorting(WireID const&, bool flip);
447 
449  static double WirePitch(WireGeo const& w1, WireGeo const& w2)
450  {
451  return std::abs(w2.DistanceFrom(w1));
452  }
453 
454  private:
455  using LocalTransformation_t =
457 
458  const TGeoNode* fWireNode;
459  double fThetaZ;
460  double fHalfL;
463  bool flipped;
464 
466  double relLength(double local) const { return flipped ? -local : local; }
467 
469  double capLength(double local) const { return std::min(+HalfL(), std::max(-HalfL(), local)); }
470 
472  void Flip();
473 
474  }; // class WireGeo
475 
476  static_assert(std::is_move_assignable_v<WireGeo>);
477  static_assert(std::is_move_constructible_v<WireGeo>);
478 
479 } // namespace geo
480 
481 //------------------------------------------------------------------------------
482 //--- template implementation
483 //---
484 //------------------------------------------------------------------------------
485 template <typename Stream>
486 void geo::WireGeo::PrintWireInfo(Stream&& out,
487  std::string indent /* = "" */,
488  unsigned int verbosity /* = 1 */
489 ) const
490 {
491  //----------------------------------------------------------------------------
492  out << "wire from " << GetStart() << " to " << GetEnd();
493 
494  if (verbosity-- <= 0) return; // 0
495 
496  //----------------------------------------------------------------------------
497  out << " (" << Length() << " cm long)";
498 
499  if (verbosity-- <= 0) return; // 1
500 
501  //----------------------------------------------------------------------------
502  out << ", theta(z)=" << ThetaZ() << " rad";
503 
504  if (verbosity-- <= 0) return; // 2
505 
506  //----------------------------------------------------------------------------
507  out << "\n" << indent << " center at " << GetCenter() << " cm";
508 
509  if (verbosity-- <= 0) return; // 3
510 
511  //----------------------------------------------------------------------------
512  out << ", direction: " << Direction();
513  if (isHorizontal()) out << " (horizontal)";
514  if (isVertical()) out << " (vertical)";
515 }
516 
517 //------------------------------------------------------------------------------
519  WireGeo const& wireA,
520  WireGeo const& wireB)
521 {
522 
524  wireA.GetCenter(), wireA.Direction(), wireB.GetCenter(), wireB.Direction());
525 }
526 
527 //------------------------------------------------------------------------------
528 inline geo::Point_t geo::WiresIntersection(WireGeo const& wireA, WireGeo const& wireB)
529 {
531  wireA.GetCenter(), wireA.Direction(), wireB.GetCenter(), wireB.Direction());
532 }
533 
534 //------------------------------------------------------------------------------
535 
536 #endif // LARCOREALG_GEOMETRY_WIREGEO_H
bool isVertical() const
Returns if this wire is vertical (theta_z ~ pi/2)
Definition: WireGeo.h:274
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
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:160
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
double Length() const
Returns the wire length in centimeters.
Definition: WireGeo.h:236
Point_t fCenter
Center of the wire in world coordinates.
Definition: WireGeo.h:461
const TGeoNode * Node() const
Definition: WireGeo.h:366
double SinThetaZ() const
Returns trigonometric operations on ThetaZ()
Definition: WireGeo.h:263
Point_t GetPositionFromCenter(double localz) const
Returns the position (world coordinate) of a point on the wire.
Definition: WireGeo.h:194
LocalPoint_t toLocalCoords(GlobalPoint_t const &world) const
Transforms a point from world frame to local frame.
constexpr auto abs(T v)
Returns the absolute value of the argument.
Point_t GetPositionFromCenterUnbounded(double localz) const
Returns the position (world coordinate) of a point on the wire.
Definition: WireGeo.h:213
Vector_t toWorldCoords(LocalVector_t const &local) const
Transform direction vector from local to world.
Definition: WireGeo.h:355
Point_t WiresIntersection(WireGeo const &wireA, WireGeo const &wireB)
Returns the point of wireA that is closest to wireB.
Definition: WireGeo.h:528
Point_t GetStart() const
Returns the world coordinate of one end of the wire [cm].
Definition: WireGeo.h:226
Point_t GetEnd() const
Returns the world coordinate of one end of the wire [cm].
Definition: WireGeo.h:231
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
recob::tracking::Point_t Point_t
double fHalfL
half length of the wire
Definition: WireGeo.h:460
IntersectionPointAndOffsets< Point_t > WiresIntersectionAndOffsets(WireGeo const &wireA, WireGeo const &wireB)
Returns the point of wireA that is closest to wireB.
Definition: WireGeo.h:518
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
IntersectionPointAndOffsets< Point > LineClosestPointAndOffsetsWithUnitVectors(Point const &startA, UnitVector const &dirA, Point const &startB, UnitVector const &dirB)
Returns the point of a line that is closest to a second line.
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
bool isHorizontal() const
Returns if this wire is horizontal (theta_z ~ 0)
Definition: WireGeo.h:269
Local-to-world transformations with LArSoft geometry vectors.
Vector_t Direction() const
Definition: WireGeo.h:289
double RMax() const
Returns the outer half-size of the wire [cm].
Definition: WireGeo.cxx:69
Utility for intersection of two 3D lines.
LocalPoint_t toLocalCoords(Point_t const &world) const
Transform point from world frame to local wire frame.
Definition: WireGeo.h:358
LocalVector_t toLocalCoords(Vector_t const &world) const
Transform direction vector from world to local.
Definition: WireGeo.h:361
std::string indent(std::size_t const i)
Utilities to extend the interface of geometry vectors.
Point_t IntersectionWith(WireGeo const &other) const
Returns the point of this wire that is closest to other wire.
Definition: WireGeo.h:400
Point LineClosestPointWithUnitVectors(Point const &startA, UnitVector const &dirA, Point const &startB, UnitVector const &dirB)
Returns the point of a line that is closest to a second line.
double HalfL() const
Returns half the length of the wire [cm].
Definition: WireGeo.h:172
double TanThetaZ() const
Returns trigonometric operations on ThetaZ()
Definition: WireGeo.h:264
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:180
Selection of the type of transformation matrix used in geometry.
double relLength(double local) const
Returns the relative length from center to be used when transforming.
Definition: WireGeo.h:466
std::vector< TGeoNode const * > GeoNodePath_t
Definition: WireGeo.h:117
LocalTransformation_t fTrans
Wire to world transform.
Definition: WireGeo.h:462
double capLength(double local) const
Caps the specified local length coordinate to lay on the wire.
Definition: WireGeo.h:469
static double WirePitch(WireGeo const &w1, WireGeo const &w2)
Returns the pitch (distance on y/z plane) between two wires, in cm.
Definition: WireGeo.h:449
Data structure for return values of LineClosestPointAndOffsets().
IntersectionPointAndOffsets< Point_t > IntersectionAndOffsetsWith(WireGeo const &other) const
Returns the point of this wire that is closest to other wire.
Definition: WireGeo.h:435
Tag for vectors in the "local" GDML coordinate frame of the plane.
Definition: WireGeo.h:136
double DistanceFrom(WireGeo const &wire) const
Returns 3D distance from the specified wire.
Definition: WireGeo.cxx:96
static constexpr unsigned int MaxVerbosity
Maximum verbosity supported by PrintWireInfo().
Definition: WireGeo.h:336
GenPoint3DBase_t< double, C > Point3DBase_t
Type of 3D point with representation in double precision.
Definition: geo_vectors.h:88
GenVector3DBase_t< double, C > Vector3DBase_t
Definition: geo_vectors.h:83
GlobalPoint_t toWorldCoords(LocalPoint_t const &local) const
Transforms a point from local frame to world frame.
double CosThetaZ() const
Returns trigonometric operations on ThetaZ()
Definition: WireGeo.h:262
Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local wire frame to world frame.
Definition: WireGeo.h:352
double ComputeZatY0() const
Definition: WireGeo.h:374
Float_t e
Definition: plot.C:35
Namespace collecting geometry-related classes utilities.
Vector3DBase_t< WireGeoCoordinatesTag > LocalVector_t
Type of displacement vectors in the local GDML wire plane frame.
Definition: WireGeo.h:142
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
Point3DBase_t< WireGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML wire plane frame.
Definition: WireGeo.h:139
bool flipped
whether (0, 0, fHalfL) identified end (false) or start (true)
Definition: WireGeo.h:463