CMS 3D CMS Logo

MultiClusterizer1D.h
Go to the documentation of this file.
1 #ifndef _MultiClusterizer1D_H_
2 #define _MultiClusterizer1D_H_
3 
9 
10 #include <vector>
11 #include <map>
12 #include <cmath>
13 #include <algorithm>
14 
19 template <class T>
21 {
22 public:
23  // typedef Cluster1D<T> Cluster1D;
28 
29  std::pair < std::vector < Cluster1D<T> >, std::vector < const T * > >
30  operator() ( const std::vector< Cluster1D<T> > & ) const;
31 
32  virtual MultiClusterizer1D * clone() const;
33 
34 private:
37 };
38 
39 /*
40  * --- implementation ---
41  *
42  */
43 
44 /*
45 namespace MultiClusterizer1DNameSpace
46 {
47 }*/
48 
49 template <class T>
52 {}
53 
54 template <class T>
56  , const WeightEstimator<T> & est )
57  : theEstimator ( est.clone() ), theSingle ( single.clone() )
58 {}
59 
60 template <class T>
62 {
63  delete theEstimator;
64  delete theSingle;
65 }
66 
67 template <class T>
69 {
70  return new MultiClusterizer1D<T>( *this );
71 }
72 
73 template <class T>
74 std::pair < std::vector< Cluster1D<T> >, std::vector< const T * > >
75 MultiClusterizer1D<T>::operator() ( const std::vector < Cluster1D<T> > & ov ) const
76 {
77  using namespace Clusterizer1DCommons;
78  // using namespace MultiClusterizer1DNameSpace;
79  typedef Cluster1D<T> Cluster1D;
80  std::vector < const T * > unusedtracks;
81  switch ( ov.size() )
82  {
83  case 0:
84  throw Clustering1DException("[MultiClusterizer1D] no values given" );
85  case 1:
86  std::pair < std::vector < Cluster1D >, std::vector < const T * > > ret ( ov, unusedtracks );
87  return ret;
88  };
89 
90  std::pair < std::vector< Cluster1D >, std::vector< const T * > > res;
91 
92  // works only with one track per cluster!!!
93  std::map < const T *, Cluster1D > ass;
94  std::vector < Cluster1D > cur;
95 
96  for ( typename std::vector< Cluster1D >::const_iterator i=ov.begin();
97  i!=ov.end() ; ++i )
98  {
99  if ( i->tracks().size()==1 )
100  {
101  ass[ i->tracks()[0] ]=*i;
102  }
103  cur.push_back ( *i );
104  }
105 
106  int ctr=0;
107  try {
108  while ( true )
109  {
110  std::pair < std::vector< Cluster1D >, std::vector< const T * > > tmp = (*theSingle)( cur );
111 
112  for ( typename std::vector< Cluster1D >::const_iterator i=tmp.first.begin();
113  i!=tmp.first.end() ; ++i )
114  {
115  res.first.push_back ( *i );
116  }
117  res.second=tmp.second;
118 
119  cur.clear();
120 
121  for ( typename std::vector< const T * >::const_iterator
122  i=res.second.begin(); i!=res.second.end() ; ++i )
123  {
124  cur.push_back ( ass[*i] );
125  }
126  if ( ctr++ > 5 ) break;
127  if ( cur.size() < 2 ) break;
128  }
129  } catch ( ... ) {};
130 
131  return res;
132 }
133 
134 #endif
virtual MultiClusterizer1D * clone() const
WeightEstimator< T > * theEstimator
MultiClusterizer1D(const Clusterizer1D< T > &single, const WeightEstimator< T > &est=TrivialWeightEstimator< T >())
Definition: Electron.h:6
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
Clusterizer1D< T > * theSingle
std::pair< std::vector< Cluster1D< T > >, std::vector< const T * > > operator()(const std::vector< Cluster1D< T > > &) const