CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/CommonTools/Clustering1D/interface/OutermostClusterizer1D.h

Go to the documentation of this file.
00001 #ifndef _OutermostClusterizer1D_H_
00002 #define _OutermostClusterizer1D_H_
00003 
00004 #include "CommonTools/Clustering1D/interface/Clusterizer1D.h"
00005 #include "CommonTools/Clustering1D/interface/Clusterizer1DCommons.h"
00006 #include "CommonTools/Clustering1D/interface/TrivialWeightEstimator.h"
00007 #include "CommonTools/Clustering1D/interface/Clustering1DException.h"
00008 #include "CommonTools/Clustering1D/interface/Cluster1DMerger.h"
00009 
00010 #include <vector>
00011 #include <cmath>
00012 #include <algorithm>
00013 
00019 template <class T>
00020 class OutermostClusterizer1D : public Clusterizer1D<T>
00021 {
00022 public:
00025     OutermostClusterizer1D (
00026                       const WeightEstimator<T> & est = TrivialWeightEstimator<T>() );
00027     OutermostClusterizer1D ( const OutermostClusterizer1D & );
00028     ~OutermostClusterizer1D();
00029 
00030     std::pair < std::vector < Cluster1D<T> >, std::vector < const T * > >
00031     operator() ( const std::vector< Cluster1D<T> > & ) const;
00032 
00033     virtual OutermostClusterizer1D * clone() const;
00034 
00035 private:
00036     WeightEstimator<T> * theEstimator;
00037 };
00038 
00039 /*
00040  *                              --- implementation ---
00041  *
00042  */
00043 
00044 template <class T>
00045 OutermostClusterizer1D<T>::OutermostClusterizer1D( const OutermostClusterizer1D<T> & o ) 
00046     : theEstimator( o.theEstimator->clone() )
00047 {}
00048 
00049 template <class T>
00050 OutermostClusterizer1D<T>::OutermostClusterizer1D(
00051     const WeightEstimator<T> & est ) : theEstimator ( est.clone() )
00052 {}
00053 
00054 template <class T>
00055 OutermostClusterizer1D<T>::~OutermostClusterizer1D()
00056 {
00057     delete theEstimator;
00058 }
00059 
00060 template <class T>
00061 OutermostClusterizer1D<T> * OutermostClusterizer1D<T>::clone() const
00062 {
00063     return new OutermostClusterizer1D<T>( *this );
00064 }
00065 
00066 template <class T>
00067 std::pair < std::vector< Cluster1D<T> >, std::vector< const T * > >
00068 OutermostClusterizer1D<T>::operator() ( const std::vector < Cluster1D<T> > & ov ) const
00069 {
00070     using namespace Clusterizer1DCommons;
00071     typedef Cluster1D<T> Cluster1D;
00072     std::vector < const T * > unusedtracks;
00073 
00074     switch ( ov.size() )
00075     {
00076     case 0:
00077         throw Clustering1DException("[OutermostClusterizer1D] no values given" );
00078     case 1:
00079       {
00080         std::pair < std::vector < Cluster1D >, std::vector < const T * > > ret ( ov, unusedtracks );
00081         return ret;
00082       };
00083     case 2:
00084       {
00085         std::pair < std::vector < Cluster1D >, std::vector < const T * > > ret ( ov, unusedtracks );
00086         return ret;
00087       };
00088     };
00089 
00090     std::vector < Cluster1D > v = ov;
00091     sort ( v.begin(), v.end(), ComparePairs<T>() );
00092     std::vector < Cluster1D > sols;
00093     int sze=v.size()/2;
00094     Cluster1D tmp = v[0];
00095     Cluster1DMerger< T > merger ( *theEstimator );
00096     // merge the inner half to the primary cluster
00097     for ( typename std::vector< Cluster1D >::const_iterator i=v.begin()+1; i!=v.begin()+sze ; ++i )
00098     {
00099       tmp = merger ( tmp, *i );
00100     }
00101     sols.push_back ( tmp );
00102     tmp=v[sze];
00103     for ( typename std::vector< Cluster1D >::const_iterator i=v.begin()+sze+1; i!=v.end() ; ++i )
00104     {
00105       tmp = merger ( tmp, *i );
00106     }
00107     sols.push_back ( tmp );
00108 
00109     std::pair < std::vector < Cluster1D >, std::vector < const T * > > ret ( sols, unusedtracks );
00110     return ret;
00111 }
00112 
00113 #endif