Edge.cxx
Go to the documentation of this file.
1 /**
2  * @file Edge.cxx
3  * @brief Definition of Principal Components Axis object for LArSoft.
4  * @author Tracy Usher (usher@slac.stanford.edu)
5  * @see Edge.h
6  *
7  */
8 
9 
11 
12 // C/C++ standard libraries
13 #include <iomanip>
14 #include <cmath> // std::sqrt()
15 #include <ostream>
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
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
Q_EXPORT QTSManip setprecision(int p)
Definition: qtextstream.h:343
SpacePointID_t FirstPointID() const
Returns the ID of the SpacePoint this edge emanates from.
Definition: Edge.h:112
T sqr(T v)
const double a
unsigned int ID_t
Type to represent recob::Edge IDs.
Definition: Edge.h:66
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
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
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).
const Double32_t * XYZ() const
Definition: SpacePoint.h:76
static bool * b
Definition: config.cpp:1043
ID_t ID() const
Returns the ID of this edge.
Definition: Edge.h:120
QTextStream & endl(QTextStream &s)
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
static TemplateFilterFactory::AutoRegister< FilterLength > fLength("length")