CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OutermostClusterizer1D.h
Go to the documentation of this file.
1 #ifndef _OutermostClusterizer1D_H_
2 #define _OutermostClusterizer1D_H_
3 
9 
10 #include <vector>
11 #include <cmath>
12 #include <algorithm>
13 
19 template <class T>
21 {
22 public:
29 
30  std::pair < std::vector < Cluster1D<T> >, std::vector < const T * > >
31  operator() ( const std::vector< Cluster1D<T> > & ) const;
32 
33  virtual OutermostClusterizer1D * clone() const;
34 
35 private:
37 };
38 
39 /*
40  * --- implementation ---
41  *
42  */
43 
44 template <class T>
46  : theEstimator( o.theEstimator->clone() )
47 {}
48 
49 template <class T>
51  const WeightEstimator<T> & est ) : theEstimator ( est.clone() )
52 {}
53 
54 template <class T>
56 {
57  delete theEstimator;
58 }
59 
60 template <class T>
62 {
63  return new OutermostClusterizer1D<T>( *this );
64 }
65 
66 template <class T>
67 std::pair < std::vector< Cluster1D<T> >, std::vector< const T * > >
68 OutermostClusterizer1D<T>::operator() ( const std::vector < Cluster1D<T> > & ov ) const
69 {
70  using namespace Clusterizer1DCommons;
71  typedef Cluster1D<T> Cluster1D;
72  std::vector < const T * > unusedtracks;
73 
74  switch ( ov.size() )
75  {
76  case 0:
77  throw Clustering1DException("[OutermostClusterizer1D] no values given" );
78  case 1:
79  {
80  std::pair < std::vector < Cluster1D >, std::vector < const T * > > ret ( ov, unusedtracks );
81  return ret;
82  };
83  case 2:
84  {
85  std::pair < std::vector < Cluster1D >, std::vector < const T * > > ret ( ov, unusedtracks );
86  return ret;
87  };
88  };
89 
90  std::vector < Cluster1D > v = ov;
91  sort ( v.begin(), v.end(), ComparePairs<T>() );
92  std::vector < Cluster1D > sols;
93  int sze=v.size()/2;
94  Cluster1D tmp = v[0];
95  Cluster1DMerger< T > merger ( *theEstimator );
96  // merge the inner half to the primary cluster
97  for ( typename std::vector< Cluster1D >::const_iterator i=v.begin()+1; i!=v.begin()+sze ; ++i )
98  {
99  tmp = merger ( tmp, *i );
100  }
101  sols.push_back ( tmp );
102  tmp=v[sze];
103  for ( typename std::vector< Cluster1D >::const_iterator i=v.begin()+sze+1; i!=v.end() ; ++i )
104  {
105  tmp = merger ( tmp, *i );
106  }
107  sols.push_back ( tmp );
108 
109  std::pair < std::vector < Cluster1D >, std::vector < const T * > > ret ( sols, unusedtracks );
110  return ret;
111 }
112 
113 #endif
int i
Definition: DBlmapReader.cc:9
WeightEstimator< T > * theEstimator
virtual OutermostClusterizer1D * clone() const
OutermostClusterizer1D(const WeightEstimator< T > &est=TrivialWeightEstimator< T >())
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::pair< std::vector< Cluster1D< T > >, std::vector< const T * > > operator()(const std::vector< Cluster1D< T > > &) const
mathSSE::Vec4< T > v