LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
WireGeo.h
Go to the documentation of this file.
1 
7 #ifndef LARCOREALG_GEOMETRY_WIREGEO_H
8 #define LARCOREALG_GEOMETRY_WIREGEO_H
9 
10 // LArSoft
14 #include "larcorealg/Geometry/geo_vectors_utils.h" // geo::vect
15 
16 // ROOT
17 #include "Math/GenVector/Transform3D.h"
18 #include "TVector3.h"
19 
20 // C/C++ libraries
21 #include <cmath> // std::sin(), ...
22 #include <string>
23 #include <type_traits> // std::is_nothrow_move_constructible<>
24 #include <vector>
25 
26 class TGeoNode;
27 
28 namespace geo {
29 
30  class WireGeo;
31  struct WireID;
32 
49  Point_t WiresIntersection(WireGeo const& wireA, WireGeo const& wireB);
50 
82  IntersectionPointAndOffsets<Point_t> WiresIntersectionAndOffsets(WireGeo const& wireA,
83  WireGeo const& wireB);
84 
112  class WireGeo {
113  public:
114  using ID_t = WireID;
115  using GeoNodePath_t = std::vector<TGeoNode const*>;
116 
117  // -- BEGIN -- Types for geometry-local reference vectors ------------------
119 
133  struct WireGeoCoordinatesTag {};
135 
138 
141 
143  // -- END ---- Types for geometry-local reference vectors ------------------
144 
157  WireGeo(TGeoNode const* node, TransformationMatrix&& trans);
158 
159  // -- BEGIN -- Size and coordinates ----------------------------------------
162 
164  double RMax() const;
167 
169  double HalfL() const { return fHalfL; }
172 
174  double RMin() const;
177 
179 
192  Point_t GetPositionFromCenter(double localz) const
193  {
195  }
197 
199 
212  {
213  return toWorldCoords(LocalPoint_t{0.0, 0.0, relLength(localz)});
214  }
216 
218  Point_t const& GetCenter() const { return fCenter; }
221 
223  Point_t GetStart() const { return GetPositionFromCenterUnbounded(-HalfL()); }
226 
228  Point_t GetEnd() const { return GetPositionFromCenterUnbounded(+HalfL()); }
231 
233  double Length() const { return 2. * HalfL(); }
236 
238  // -- END ---- Size and coordinates ---------------------------------------
239 
240  // -- BEGIN -- Orientation and angles --------------------------------------
243 
245  double ThetaZ() const { return fThetaZ; }
248 
250 
255  double ThetaZ(bool degrees) const;
257 
259  double CosThetaZ() const { return std::cos(ThetaZ()); }
261  double SinThetaZ() const { return std::sin(ThetaZ()); }
262  double TanThetaZ() const { return std::tan(ThetaZ()); }
264 
266  bool isHorizontal() const { return std::abs(SinThetaZ()) < 1e-5; }
269 
271  bool isVertical() const { return std::abs(CosThetaZ()) < 1e-5; }
274 
276  bool isParallelTo(WireGeo const& wire) const
278  {
279  return // parallel if the dot product of the directions is about +/- 1
280  std::abs(std::abs(Direction().Dot(wire.Direction())) - 1.) < 1e-5;
281  }
283 
285  Vector_t Direction() const
288  {
289  // maybe (GetCenter() - GetStart()) / HalfL() would be faster;
290  return (GetEnd() - GetStart()) / Length();
291  }
293 
295  // -- END ---- Orientation and angles --------------------------------------
296 
297  // -- BEGIN -- Printing ----------------------------------------------------
300 
322  template <typename Stream>
323  void PrintWireInfo(Stream&& out, std::string indent = "", unsigned int verbosity = 1) const;
324 
331  std::string WireInfo(std::string indent = "", unsigned int verbosity = 1) const;
332 
334  static constexpr unsigned int MaxVerbosity = 4;
335 
337  // -- END ---- Printing ----------------------------------------------------
338 
339  // -- BEGIN -- Coordinate transformation -----------------------------------
347 
350  Point_t toWorldCoords(LocalPoint_t const& local) const { return fTrans.toWorldCoords(local); }
351 
353  Vector_t toWorldCoords(LocalVector_t const& local) const { return fTrans.toWorldCoords(local); }
354 
356  LocalPoint_t toLocalCoords(Point_t const& world) const { return fTrans.toLocalCoords(world); }
357 
359  LocalVector_t toLocalCoords(Vector_t const& world) const { return fTrans.toLocalCoords(world); }
360 
362  // -- END ---- Coordinate transformation -----------------------------------
363 
364  const TGeoNode* Node() const { return fWireNode; }
365 
366  // -- BEGIN -- Geometric properties and algorithms -------------------------
369 
372  double ComputeZatY0() const { return fCenter.Z() - fCenter.Y() / TanThetaZ(); }
373 
381  double DistanceFrom(WireGeo const& wire) const;
382 
398  Point_t IntersectionWith(WireGeo const& other) const { return WiresIntersection(*this, other); }
399 
434  {
435  auto const [point, ofsA, ofsB] = WiresIntersectionAndOffsets(*this, other);
436  return {point, ofsA, ofsB};
437  }
438 
440  // -- END ---- Geometric properties and algorithms -------------------------
441 
444  void UpdateAfterSorting(WireID const&, bool flip);
445 
447  static double WirePitch(WireGeo const& w1, WireGeo const& w2)
448  {
449  return std::abs(w2.DistanceFrom(w1));
450  }
451 
452  private:
453  using LocalTransformation_t =
455 
456  const TGeoNode* fWireNode;
457  double fThetaZ;
458  double fHalfL;
461  bool flipped;
462 
464  double relLength(double local) const { return flipped ? -local : local; }
465 
467  double capLength(double local) const { return std::min(+HalfL(), std::max(-HalfL(), local)); }
468 
470  void Flip();
471 
472  }; // class WireGeo
473 
474  static_assert(std::is_move_assignable_v<WireGeo>);
475  static_assert(std::is_move_constructible_v<WireGeo>);
476 
477 } // namespace geo
478 
479 //------------------------------------------------------------------------------
480 //--- template implementation
481 //---
482 //------------------------------------------------------------------------------
483 template <typename Stream>
484 void geo::WireGeo::PrintWireInfo(Stream&& out,
485  std::string indent /* = "" */,
486  unsigned int verbosity /* = 1 */
487 ) const
488 {
489  //----------------------------------------------------------------------------
490  out << "wire from " << GetStart() << " to " << GetEnd();
491 
492  if (verbosity-- <= 0) return; // 0
493 
494  //----------------------------------------------------------------------------
495  out << " (" << Length() << " cm long)";
496 
497  if (verbosity-- <= 0) return; // 1
498 
499  //----------------------------------------------------------------------------
500  out << ", theta(z)=" << ThetaZ() << " rad";
501 
502  if (verbosity-- <= 0) return; // 2
503 
504  //----------------------------------------------------------------------------
505  out << "\n" << indent << " center at " << GetCenter() << " cm";
506 
507  if (verbosity-- <= 0) return; // 3
508 
509  //----------------------------------------------------------------------------
510  out << ", direction: " << Direction();
511  if (isHorizontal()) out << " (horizontal)";
512  if (isVertical()) out << " (vertical)";
513 }
514 
515 //------------------------------------------------------------------------------
517  WireGeo const& wireA,
518  WireGeo const& wireB)
519 {
520 
522  wireA.GetCenter(), wireA.Direction(), wireB.GetCenter(), wireB.Direction());
523 }
524 
525 //------------------------------------------------------------------------------
526 inline geo::Point_t geo::WiresIntersection(WireGeo const& wireA, WireGeo const& wireB)
527 {
529  wireA.GetCenter(), wireA.Direction(), wireB.GetCenter(), wireB.Direction());
530 }
531 
532 //------------------------------------------------------------------------------
533 
534 #endif // LARCOREALG_GEOMETRY_WIREGEO_H
bool isVertical() const
Returns if this wire is vertical (theta_z ~ pi/2)
Definition: WireGeo.h:272
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
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:457
double Length() const
Returns the wire length in centimeters.
Definition: WireGeo.h:234
Point_t fCenter
Center of the wire in world coordinates.
Definition: WireGeo.h:459
const TGeoNode * Node() const
Definition: WireGeo.h:364
double SinThetaZ() const
Returns trigonometric operations on ThetaZ()
Definition: WireGeo.h:261
Point_t GetPositionFromCenter(double localz) const
Returns the position (world coordinate) of a point on the wire.
Definition: WireGeo.h:192
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:211
Vector_t toWorldCoords(LocalVector_t const &local) const
Transform direction vector from local to world.
Definition: WireGeo.h:353
Point_t WiresIntersection(WireGeo const &wireA, WireGeo const &wireB)
Returns the point of wireA that is closest to wireB.
Definition: WireGeo.h:526
Point_t GetStart() const
Returns the world coordinate of one end of the wire [cm].
Definition: WireGeo.h:224
Point_t GetEnd() const
Returns the world coordinate of one end of the wire [cm].
Definition: WireGeo.h:229
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
recob::tracking::Point_t Point_t
double fHalfL
half length of the wire
Definition: WireGeo.h:458
IntersectionPointAndOffsets< Point_t > WiresIntersectionAndOffsets(WireGeo const &wireA, WireGeo const &wireB)
Returns the point of wireA that is closest to wireB.
Definition: WireGeo.h:516
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
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:267
Local-to-world transformations with LArSoft geometry vectors.
Vector_t Direction() const
Definition: WireGeo.h:287
double RMax() const
Returns the outer half-size of the wire [cm].
Definition: WireGeo.cxx:67
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:356
LocalVector_t toLocalCoords(Vector_t const &world) const
Transform direction vector from world to local.
Definition: WireGeo.h:359
std::string indent(std::size_t const i)
Utilities to extend the interface of geometry vectors.This library provides facilities that can be us...
Point_t IntersectionWith(WireGeo const &other) const
Returns the point of this wire that is closest to other wire.
Definition: WireGeo.h:398
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:170
double TanThetaZ() const
Returns trigonometric operations on ThetaZ()
Definition: WireGeo.h:262
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
WireGeo(TGeoNode const *node, TransformationMatrix &&trans)
Constructor from a ROOT geometry node and a transformation.
Definition: WireGeo.cxx:29
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:464
std::vector< TGeoNode const * > GeoNodePath_t
Definition: WireGeo.h:115
LocalTransformation_t fTrans
Wire to world transform.
Definition: WireGeo.h:460
double capLength(double local) const
Caps the specified local length coordinate to lay on the wire.
Definition: WireGeo.h:467
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:447
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:433
Tag for vectors in the "local" GDML coordinate frame of the plane.
Definition: WireGeo.h:134
double DistanceFrom(WireGeo const &wire) const
Returns 3D distance from the specified wire.
Definition: WireGeo.cxx:94
static constexpr unsigned int MaxVerbosity
Maximum verbosity supported by PrintWireInfo().
Definition: WireGeo.h:334
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:260
Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local wire frame to world frame.
Definition: WireGeo.h:350
double ComputeZatY0() const
Definition: WireGeo.h:372
Float_t e
Definition: plot.C:35
ROOT libraries.
Vector3DBase_t< WireGeoCoordinatesTag > LocalVector_t
Type of displacement vectors in the local GDML wire plane frame.
Definition: WireGeo.h:140
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
Point3DBase_t< WireGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML wire plane frame.
Definition: WireGeo.h:137
bool flipped
whether (0, 0, fHalfL) identified end (false) or start (true)
Definition: WireGeo.h:461