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
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:367
TrivialWeightEstimator.h
Clusterizer1DCommons
Definition: Clusterizer1DCommons.h:6
Measurement1D
Definition: Measurement1D.h:11
mps_fire.i
i
Definition: mps_fire.py:428
Cluster1D
Definition: Cluster1D.h:13
Clusterizer1DCommons::add
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
Definition: Clusterizer1DCommons.h:18
mps_merge.weight
weight
Definition: mps_merge.py:88
MtvClusterizer1D::MtvClusterizer1D
MtvClusterizer1D(const WeightEstimator< T > &est=TrivialWeightEstimator< T >())
Definition: MtvClusterizer1D.h:41
MtvClusterizer1D::clone
virtual MtvClusterizer1D * clone() const
Definition: MtvClusterizer1D.h:49
Clusterizer1DCommons::square
double square(const double a)
Definition: Clusterizer1DCommons.h:8
findQualityFiles.v
v
Definition: findQualityFiles.py:179
TrivialWeightEstimator
Definition: TrivialWeightEstimator.h:13
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:36
MtvClusterizer1D::theEstimator
WeightEstimator< T > * theEstimator
Definition: MtvClusterizer1D.h:28
Clusterizer1DCommons::ComparePairs
Definition: Clusterizer1DCommons.h:11
Clusterizer1D.h
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
mps_fire.end
end
Definition: mps_fire.py:242
WeightEstimator
Definition: WeightEstimator.h:12
MtvClusterizer1D::~MtvClusterizer1D
~MtvClusterizer1D()
Definition: MtvClusterizer1D.h:44
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
MtvClusterizer1D::operator()
std::pair< std::vector< Cluster1D< T > >, std::vector< const T * > > operator()(const std::vector< Cluster1D< T > > &) const
Definition: MtvClusterizer1D.h:54
Clusterizer1D
Definition: Clusterizer1D.h:16
Clustering1DException.h
Clusterizer1DCommons.h
Clustering1DException
Definition: Clustering1DException.h:10
weight
Definition: weight.py:1
MtvClusterizer1D::theErrorStretchFactor
float theErrorStretchFactor
Definition: MtvClusterizer1D.h:29
MtvClusterizer1D
Definition: MtvClusterizer1D.h:17