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