KHitGroup.cxx
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////
2 ///
3 /// \file KHitGroup.cxx
4 ///
5 /// \brief A collection of measurements on the same surface.
6 ///
7 /// \author H. Greenlee
8 ///
9 ////////////////////////////////////////////////////////////////////////
10 
12 #include "cetlib_except/exception.h"
13 
14 namespace trkf {
15 
16  /// Default Constructor.
17  ///
18  /// Arguments:
19  ///
20  /// has_path - Path flag (optional).
21  /// path - Estimated path distance (optional).
22  ///
23  KHitGroup::KHitGroup(bool has_path, double path) :
24  fPlane(-1),
25  fHasPath(has_path),
26  fPath(path)
27  {}
28 
29  /// Destructor.
31  {}
32 
33  /// Add a mesaurement into the colleciton.
34  ///
35  /// Arguments:
36  ///
37  /// hit - Measurement to add.
38  ///
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 
75  /// Equivalance operator.
76  ///
77  /// Objects with path flag false compare equal.
78  /// Objects with path flag true compare according to estimated path distance.
79  ///
80  /// Arguments:
81  ///
82  /// g - Comparison object.
83  ///
84  /// Returned value: True if equal.
85  ///
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 
94  /// Less than operator.
95  ///
96  /// Objects with path flag false compare equal (return false).
97  /// Objects with path flag true compare according to estimated path distance.
98  /// Objects with path flag false are not comparable to objects
99  /// with path flag true (throw exception).
100  ///
101  /// Arguments:
102  ///
103  /// g - Comparison object.
104  ///
105  /// Returned value: True if less than.
106  ///
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
static QCString result
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