CMS 3D CMS Logo

SubsetHsmModeFinder3d.cc
Go to the documentation of this file.
3 
5 
6 #include <algorithm>
7 
8 typedef std::pair<GlobalPoint, float> PointAndDistance;
9 
10 namespace {
11  struct compareByDistance {
12  bool operator()(const PointAndDistance& p1, const PointAndDistance& p2) { return (p1.second < p2.second); };
13  };
14 } // namespace
15 
16 GlobalPoint SubsetHsmModeFinder3d::operator()(const std::vector<PointAndDistance>& values) const {
17  if (values.empty()) {
18  throw VertexException("SubsetHsmModeFinder3d: no value given.");
19  };
20 
21  std::vector<GlobalPoint> pts;
22  pts.reserve(values.size() - 1);
23  std::vector<PointAndDistance> sorted_values(values.size());
24  partial_sort_copy(values.begin(), values.end(), sorted_values.begin(), sorted_values.end(), compareByDistance());
25 
26  std::vector<PointAndDistance>::iterator end = sorted_values.end();
27  std::vector<PointAndDistance>::iterator begin = sorted_values.begin();
28 
29  float dmax = 0.004; // 40 microns, as a first try.
30 
31  // we want at least 30 values
32  unsigned int min_num = values.size() < 30 ? values.size() : 30;
33 
34  // we also want at least 50 % of all values
35  if (values.size() > 2 * min_num)
36  min_num = (int)values.size() / 2;
37 
38  while (pts.size() < min_num) {
39  // we cut at a dmax
40  std::vector<PointAndDistance>::iterator i;
41  for (i = begin; i != end && (i->second < dmax); ++i) {
42  pts.push_back(i->first);
43  };
44  dmax += 0.003; // add 30 microns with every iteration
45  begin = i;
46  };
47 
49  return ret;
50 }
51 
std::pair< GlobalPoint, float > PointAndDistance
GlobalPoint hsm_3d(const std::vector< GlobalPoint > &values)
cordinate wise half sample mode in 3d
Definition: hsm_3d.cc:8
Common base class.
ret
prodAgent to be discontinued
static const double pts[33]
Definition: Constants.h:30
GlobalPoint operator()(const std::vector< PointAndDistance > &values) const override
std::pair< GlobalPoint, float > PointAndDistance
SubsetHsmModeFinder3d * clone() const override