LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Edge.cxx
Go to the documentation of this file.
1 
10 
11 // C/C++ standard libraries
12 #include <cmath> // std::sqrt()
13 #include <iomanip>
14 #include <ostream>
15 
16 namespace {
17 
18  double sqr(double v)
19  {
20  return v * v;
21  }
22 
23  double spacePointDistance(recob::SpacePoint const& a, recob::SpacePoint const& b)
24  {
25  double const* aXYZ = a.XYZ();
26  double const* bXYZ = b.XYZ();
27  return std::sqrt(sqr(aXYZ[0] - bXYZ[0]) + sqr(aXYZ[1] - bXYZ[1]) + sqr(aXYZ[2] - bXYZ[2]));
28  } // spacePointDistance()
29 
30 } // local namespace
31 
32 namespace recob {
33 
34  //----------------------------------------------------------------------
35  Edge::Edge(const double length,
36  SpacePointID_t firstPointID,
37  SpacePointID_t secondPointID,
38  ID_t id /* = InvalidID */)
39  : fLength(length), fFirstPointID(firstPointID), fSecondPointID(secondPointID), fID(id)
40  {}
41 
42  //----------------------------------------------------------------------
43  Edge::Edge(SpacePoint const& firstPoint, SpacePoint const& secondPoint, ID_t id /* = InvalidID */)
44  : fLength(::spacePointDistance(firstPoint, secondPoint))
45  , fFirstPointID(firstPoint.ID())
46  , fSecondPointID(secondPoint.ID())
47  , fID(id)
48  {}
49 
50  //----------------------------------------------------------------------
51  // ostream operator.
52  //
53  std::ostream& operator<<(std::ostream& o, const Edge& a)
54  {
55  o << std::setiosflags(std::ios::fixed) << std::setprecision(2);
56  o << " Edge ID " << a.ID() << " has length " << std::setw(6) << a.Length() << " cm"
57  << std::endl;
58  o << " - First Point ID: " << a.FirstPointID() << ", second point ID: " << a.SecondPointID()
59  << std::endl;
60 
61  return o;
62  }
63 
64 } // End of namespace
An object to define a "edge" which is used to connect space points in a triangulation algorithm...
Reconstruction base classes.
double Length() const
Returns the length of this edge [cm].
Definition: Edge.h:99
SpacePointID_t FirstPointID() const
Returns the ID of the SpacePoint this edge emanates from.
Definition: Edge.h:102
constexpr T sqr(T v)
unsigned int ID_t
Type to represent recob::Edge IDs.
Definition: Edge.h:62
const Double32_t * XYZ() const
Definition: SpacePoint.h:78
double fLength
Length of this Edge [cm].
Definition: Edge.h:114
SpacePointID_t fSecondPointID
ID of the SpacePoint edge ends on.
Definition: Edge.h:118
SpacePointID_t fFirstPointID
ID of the SpacePoint edge emanates from.
Definition: Edge.h:116
ID_t fID
Edge ID.
Definition: Edge.h:120
Edge()=default
Default constructor (all invalid IDs).
ID_t ID() const
Returns the ID of this edge.
Definition: Edge.h:108
std::ostream & operator<<(std::ostream &o, Cluster const &c)
Definition: Cluster.cxx:168
Edge is an object containing the results of a Principal Components Analysis of a group of space point...
Definition: Edge.h:59
recob::SpacePoint::ID_t SpacePointID_t
Type to represent recob::SpacePoint IDs.
Definition: Edge.h:65
SpacePointID_t SecondPointID() const
Returns the ID of the SpacePoint this edge ends on.
Definition: Edge.h:105