All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Edge.h
Go to the documentation of this file.
1 /**
2  * @file Edge.h
3  * @brief An object to define a "edge" which is used to connect
4  * space points in a triangulation algorithm.
5  * @author Tracy Usher (usher@slac.stanford.edu)
6  * @see Edge.cxx
7  *
8  */
9 
10 #ifndef LARDATAOBJ_RECOBASE_EDGE_H
11 #define LARDATAOBJ_RECOBASE_EDGE_H
12 
13 
14 // LArSoft libraries
16 
17 // C/C++ libraries
18 #include <limits> // std::numeric_limits<>
19 #include <iosfwd> // std::ostream
20 
21 namespace recob
22 {
23 
24  /**
25  * @brief Edge is an object containing the results of a Principal Components
26  * Analysis of a group of space points.
27  *
28  * The edge contains references to an emanating space point
29  * (`FirstPointID()`) and to an ending one (`SecondPointID()`).
30  * For convenience, it also stores the distance between those points.
31  *
32  * To look up for a referenced space point, the easiest way is to start
33  * from a sorted list of space points (`recob::SpacePoint` sorts by ID
34  * value):
35  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
36  * if (!std::is_sorted(points.begin(), points.end()))
37  * throw std::runtime_error("Space points not sorted!");
38  *
39  * // find the first space point
40  * auto const iFirstPoint = std::lower_bound
41  * (points.begin(), points.end(), edge.FirstPointID());
42  *
43  * if ((iFirstPoint == points.end()) || (iFirstPoint->ID() != edge.FirstPointID())) {
44  * throw std::runtime_error
45  * ("First point not found: ID=" + std::to_string(edge.FirstPointID()));
46  * }
47  * recob::SpacePoint const& firstPoint = *iFirstPoint;
48  *
49  * // find the second space point
50  * auto const iSecondPoint = std::lower_bound
51  * (points.begin(), points.end(), edge.SecondPointID());
52  *
53  * if ((iSecondPoint == points.end()) || (iSecondPoint->ID() != edge.SecondPointID())) {
54  * throw std::runtime_error
55  * ("Second point not found: ID=" + std::to_string(edge.SecondPointID()));
56  * }
57  * recob::SpacePoint const& secondPoint = *iSecondPoint;
58  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59  *
60  */
61  class Edge
62  {
63  public:
64 
65  /// Type to represent `recob::Edge` IDs.
66  using ID_t = unsigned int;
67 
68  /// Type to represent `recob::SpacePoint` IDs.
70 
71  /// Special value for an invalid edge ID.
72  static constexpr ID_t InvalidID = std::numeric_limits<ID_t>::max();
73 
74 
75  /// Default constructor (all invalid IDs).
76  Edge() = default;
77 
78  /**
79  * @brief Constructor: assigns all values.
80  * @param length the length of the edge [cm]
81  * @param firstPointID ID of the emanating space point
82  * @param secondPointID ID of the ending space point
83  * @param id _(default: `InvalidID`) ID of this edge
84  *
85  */
86  Edge(
87  const double length,
88  SpacePointID_t firstPointID, SpacePointID_t secondPointID,
89  ID_t id = InvalidID
90  );
91 
92  /**
93  * @brief Constructor: uses the specified spacepoints.
94  * @param firstPoint the emanating space point
95  * @param secondPoint the ending space point
96  * @param id _(default: `InvalidID`) ID of this edge
97  *
98  */
99  Edge(
100  SpacePoint const& firstPoint, SpacePoint const& secondPoint,
101  ID_t id = InvalidID
102  );
103 
104  /// @{
105  /// @name Access
106 
107  /// Returns the length of this edge [cm].
108  double Length() const
109  { return fLength; }
110 
111  /// Returns the ID of the SpacePoint this edge emanates from.
113  { return fFirstPointID; }
114 
115  /// Returns the ID of the SpacePoint this edge ends on.
117  { return fSecondPointID; }
118 
119  /// Returns the ID of this edge.
120  ID_t ID() const
121  { return fID; }
122 
123  /// @}
124 
125  private:
126 
127  /// Length of this Edge [cm].
128  double fLength = 0.0;
129  /// ID of the SpacePoint edge emanates from.
131  /// ID of the SpacePoint edge ends on.
133  /// Edge ID.
135 
136  }; // class Edge
137 
138 
139  /// Streaming operator: prints the edge `a` into the specified stream.
140  std::ostream& operator << (std::ostream & o, const Edge& a);
141 
142 
143  /// Comparison operator: strict ordering of edge by ID.
144  inline bool operator< (const Edge& a, const Edge& b)
145  { return a.ID() < b.ID(); }
146  /// Comparison operator: strict ordering of edge by ID.
147  inline bool operator< (const Edge& e, Edge::ID_t id)
148  { return e.ID() < id; }
149  /// Comparison operator: strict ordering of edge by ID.
150  inline bool operator< (Edge::ID_t id, const Edge& e)
151  { return id < e.ID(); }
152 
153 } // namespace recob
154 
155 
156 
157 #endif // LARDATAOBJ_RECOBASE_EDGE_H
bool operator<(Cluster const &a, Cluster const &b)
Definition: Cluster.cxx:196
int ID_t
type of spacepoint ID
Definition: SpacePoint.h:26
static constexpr ID_t InvalidID
Special value for an invalid edge ID.
Definition: Edge.h:72
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
process_name gaushit a
unsigned int ID_t
Type to represent recob::Edge IDs.
Definition: Edge.h:66
static constexpr ID_t InvalidID
Special value for an invalid ID.
Definition: SpacePoint.h:29
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).
do i e
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