LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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) :
24  fPlane(-1),
25  fHasPath(has_path),
26  fPath(path)
27  {}
28 
31  {}
32 
39  void KHitGroup::addHit(const std::shared_ptr<const KHitBase>& hit)
40  {
41  // Make sure that the measurement pointer is not null (throw exception if null).
42 
43  if(hit.get() == 0)
44  throw cet::exception("KHitGroup") << "Attempt to add null measurement.\n";
45 
46  // If the stored common surface pointer has not yet been initialized,
47  // initialize it now.
48  // Otherwise, make sure that the new measurement surface matches
49  // the common surface (pointer to same surface object).
50  // Throw exception if the new surface doesn't match.
51 
52  if(hit->getMeasPlane() < 0)
53  throw cet::exception("KHitGroup") << __func__ << ": invalid hit plane " << hit->getMeasPlane() << "\n";
54 
55  if(fSurf.get() == 0) {
56  fSurf = hit->getMeasSurface();
57  fPlane = hit->getMeasPlane();
58  }
59  else {
60  if(fSurf.get() != hit->getMeasSurface().get())
61  throw cet::exception("KHitGroup") << "Attempt to add non-matching measurement.\n";
62  if(hit->getMeasPlane() != fPlane) {
63  throw cet::exception("KHitGroup") << __func__ << ": hit plane mismatch, "
64  << hit->getMeasPlane() << " vs. " << fPlane << "\n";
65  }
66  if (fPlane < 0)
67  throw cet::exception("KHitGroup") << __func__ << ": invalid plane " << fPlane << "\n";
68  }
69 
70  // Everything OK. Add the measurement.
71 
72  fHits.push_back(hit);
73  }
74 
86  bool KHitGroup::operator==(const KHitGroup& obj) const
87  {
88  bool result =
89  (!fHasPath && !obj.fHasPath) ||
90  (fHasPath && obj.fHasPath && fPath == obj.fPath);
91  return result;
92  }
93 
107  bool KHitGroup::operator<(const KHitGroup& obj) const
108  {
109  bool result = false;
110  if(fHasPath != obj.fHasPath)
111  throw cet::exception("KHitGroup") << "Attempt to compare incomparable objects.\n";
112  if(fHasPath)
113  result = fPath < obj.fPath;
114  return result;
115  }
116 
117 } // end namespace trkf
bool operator<(const KHitGroup &obj) const
Less than operator.
Definition: KHitGroup.cxx:107
bool fHasPath
Path flag.
Definition: KHitGroup.h:87
KHitGroup(bool has_path=false, double path=0.)
Default constructor.
Definition: KHitGroup.cxx:23
virtual ~KHitGroup()
Destructor.
Definition: KHitGroup.cxx:30
std::shared_ptr< const Surface > fSurf
Common surface.
Definition: KHitGroup.h:84
int fPlane
Plane index of measurements.
Definition: KHitGroup.h:85
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:39
std::vector< std::shared_ptr< const KHitBase > > fHits
Measuement collection.
Definition: KHitGroup.h:86
bool operator==(const KHitGroup &obj) const
Equivalance operator.
Definition: KHitGroup.cxx:86
double fPath
Estimated path distance.
Definition: KHitGroup.h:88
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33