CMS 3D CMS Logo

MtvClusterizer1D.h
Go to the documentation of this file.
1 #ifndef _MtvClusterizer1D_H_
2 #define _MtvClusterizer1D_H_
3 
8 
9 #include <vector>
10 #include <cmath>
11 #include <algorithm>
12 
16 template <class T>
17 class MtvClusterizer1D : public Clusterizer1D<T> {
18 public:
22 
23  std::pair<std::vector<Cluster1D<T> >, std::vector<const T*> > operator()(const std::vector<Cluster1D<T> >&) const;
24 
25  virtual MtvClusterizer1D* clone() const;
26 
27 private:
30 };
31 
32 /*
33  * --- implementation ---
34  *
35  */
36 
37 template <class T>
38 MtvClusterizer1D<T>::MtvClusterizer1D(const MtvClusterizer1D<T>& o) : theEstimator(o.theEstimator->clone()) {}
39 
40 template <class T>
42 
43 template <class T>
45  delete theEstimator;
46 }
47 
48 template <class T>
50  return new MtvClusterizer1D<T>(*this);
51 }
52 
53 template <class T>
54 std::pair<std::vector<Cluster1D<T> >, std::vector<const T*> > MtvClusterizer1D<T>::operator()(
55  const std::vector<Cluster1D<T> >& ov) const {
56  typedef Cluster1D<T> Cluster1D;
57  using namespace Clusterizer1DCommons;
58  std::vector<const T*> unusedtracks;
59  switch (ov.size()) {
60  case 0:
61  throw Clustering1DException("[MtvClusterizer1D] no values given");
62  case 1:
63  std::pair<std::vector<Cluster1D>, std::vector<const T*> > ret(ov, unusedtracks);
64  return ret;
65  };
66  std::vector<Cluster1D> v = ov;
67  sort(v.begin(), v.end(), ComparePairs<T>());
68  std::vector<Cluster1D> sols;
69  std::vector<const T*> trks;
70 
71  typename std::vector<Cluster1D>::iterator cur = v.begin();
72  typename std::vector<Cluster1D>::iterator end = (v.end() - 1);
73  double cur_min = cur->weight() + (cur + 1)->weight();
74 
75  for (typename std::vector<Cluster1D>::iterator i = v.begin(); i != end; ++i) {
76  double cur_val = i->weight() + (i + 1)->weight();
77  if (cur_val > cur_min) {
78  cur_min = cur_val;
79  cur = i;
80  };
81  };
82 
83  double weight = (cur->weight() + (cur + 1)->weight());
84  double est = (cur->weight() * cur->position().value() + (cur + 1)->weight() * (cur + 1)->position().value()) / weight;
85  double sigma = sqrt(square(cur->position().value() - est) + square((cur + 1)->position().value() - est));
86  double err = 0.;
87  int inliers = 0;
88 
89  for (typename std::vector<Cluster1D>::iterator i = v.begin(); i != v.end(); ++i) {
90  if (fabs(i->position().value() - est) < 3 * sigma) {
91  // all within 3 sigma are 'in'
92  add(i->tracks(), trks);
93  err += square(i->position().value() - est);
94  inliers++;
95  } else {
96  add(i->tracks(), unusedtracks);
97  };
98  };
99  err /= (inliers - 1); // the algo definitely produces 2 or more inliers
100  err = sqrt(err);
101 
102  sols.push_back(Cluster1D(Measurement1D(est, err), trks, weight));
103  std::pair<std::vector<Cluster1D>, std::vector<const T*> > ret(sols, unusedtracks);
104  return ret;
105 }
106 
107 #endif
MtvClusterizer1D(const WeightEstimator< T > &est=TrivialWeightEstimator< T >())
ret
prodAgent to be discontinued
Definition: weight.py:1
T sqrt(T t)
Definition: SSEVec.h:23
void add(const std::vector< const T *> &source, std::vector< const T *> &dest)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
std::pair< std::vector< Cluster1D< T > >, std::vector< const T * > > operator()(const std::vector< Cluster1D< T > > &) const
static int position[264][3]
Definition: ReadPGInfo.cc:289
double square(const double a)
WeightEstimator< T > * theEstimator
virtual MtvClusterizer1D * clone() const