LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
KHitGroup.cxx
Go to the documentation of this file.
1 
12 #include "cetlib_except/exception.h"
13 
14 namespace trkf {
15 
23  KHitGroup::KHitGroup(bool has_path, double path) : fPlane(-1), fHasPath(has_path), fPath(path) {}
24 
27 
34  void KHitGroup::addHit(const std::shared_ptr<const KHitBase>& hit)
35  {
36  // Make sure that the measurement pointer is not null (throw exception if null).
37 
38  if (hit.get() == 0) throw cet::exception("KHitGroup") << "Attempt to add null measurement.\n";
39 
40  // If the stored common surface pointer has not yet been initialized,
41  // initialize it now.
42  // Otherwise, make sure that the new measurement surface matches
43  // the common surface (pointer to same surface object).
44  // Throw exception if the new surface doesn't match.
45 
46  if (hit->getMeasPlane() < 0)
47  throw cet::exception("KHitGroup")
48  << __func__ << ": invalid hit plane " << hit->getMeasPlane() << "\n";
49 
50  if (fSurf.get() == 0) {
51  fSurf = hit->getMeasSurface();
52  fPlane = hit->getMeasPlane();
53  }
54  else {
55  if (fSurf.get() != hit->getMeasSurface().get())
56  throw cet::exception("KHitGroup") << "Attempt to add non-matching measurement.\n";
57  if (hit->getMeasPlane() != fPlane) {
58  throw cet::exception("KHitGroup") << __func__ << ": hit plane mismatch, "
59  << hit->getMeasPlane() << " vs. " << fPlane << "\n";
60  }
61  if (fPlane < 0)
62  throw cet::exception("KHitGroup") << __func__ << ": invalid plane " << fPlane << "\n";
63  }
64 
65  // Everything OK. Add the measurement.
66 
67  fHits.push_back(hit);
68  }
69 
81  bool KHitGroup::operator==(const KHitGroup& obj) const
82  {
83  bool result = (!fHasPath && !obj.fHasPath) || (fHasPath && obj.fHasPath && fPath == obj.fPath);
84  return result;
85  }
86 
100  bool KHitGroup::operator<(const KHitGroup& obj) const
101  {
102  bool result = false;
103  if (fHasPath != obj.fHasPath)
104  throw cet::exception("KHitGroup") << "Attempt to compare incomparable objects.\n";
105  if (fHasPath) result = fPath < obj.fPath;
106  return result;
107  }
108 
109 } // end namespace trkf
bool operator<(const KHitGroup &obj) const
Less than operator.
Definition: KHitGroup.cxx:100
bool fHasPath
Path flag.
Definition: KHitGroup.h:88
KHitGroup(bool has_path=false, double path=0.)
Default constructor.
Definition: KHitGroup.cxx:23
virtual ~KHitGroup()
Destructor.
Definition: KHitGroup.cxx:26
std::shared_ptr< const Surface > fSurf
Common surface.
Definition: KHitGroup.h:85
int fPlane
Plane index of measurements.
Definition: KHitGroup.h:86
A collection of measurements on the same surface.
Detector simulation of raw signals on wires.
void addHit(const std::shared_ptr< const KHitBase > &hit)
Add a mesaurement into the colleciton.
Definition: KHitGroup.cxx:34
std::vector< std::shared_ptr< const KHitBase > > fHits
Measuement collection.
Definition: KHitGroup.h:87
bool operator==(const KHitGroup &obj) const
Equivalance operator.
Definition: KHitGroup.cxx:81
double fPath
Estimated path distance.
Definition: KHitGroup.h:89
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33