CMS 3D CMS Logo

FsmwClusterizer1D< T > Class Template Reference

Fraction-of sample mode with weights clustering. More...

#include <CommonTools/Clustering1D/interface/FsmwClusterizer1D.h>

Inheritance diagram for FsmwClusterizer1D< T >:

Clusterizer1D< T >

List of all members.

Public Member Functions

virtual FsmwClusterizer1Dclone () const
 FsmwClusterizer1D (const FsmwClusterizer1D &)
 FsmwClusterizer1D (double fraction=.05, double n_sigma_in=3., const WeightEstimator< T > &est=TrivialWeightEstimator< T >())
 
Parameters:
fraction fraction of values that will be considered to be 'in'.

std::pair< std::vector
< Cluster1D< T > >,
std::vector< const T * > > 
operator() (const std::vector< Cluster1D< T > > &) const
 ~FsmwClusterizer1D ()

Private Attributes

WeightEstimator< T > * theEstimator
double theFraction
double theNSigmaIn


Detailed Description

template<class T>
class FsmwClusterizer1D< T >

Fraction-of sample mode with weights clustering.

Definition at line 17 of file FsmwClusterizer1D.h.


Constructor & Destructor Documentation

template<class T>
FsmwClusterizer1D< T >::FsmwClusterizer1D ( double  fraction = .05,
double  n_sigma_in = 3.,
const WeightEstimator< T > &  est = TrivialWeightEstimator<T>() 
) [inline]

Parameters:
fraction fraction of values that will be considered to be 'in'.

Definition at line 163 of file FsmwClusterizer1D.h.

00164     : theEstimator ( est.clone() ), theFraction ( fraction ), theNSigmaIn ( nsig )
00165 {}

template<class T>
FsmwClusterizer1D< T >::FsmwClusterizer1D ( const FsmwClusterizer1D< T > &  o  )  [inline]

Definition at line 156 of file FsmwClusterizer1D.h.

00157     : theEstimator( o.theEstimator->clone() ), theFraction ( o.theFraction ),
00158     theNSigmaIn ( o.theNSigmaIn )
00159 {}

template<class T>
FsmwClusterizer1D< T >::~FsmwClusterizer1D (  )  [inline]

Definition at line 169 of file FsmwClusterizer1D.h.

References FsmwClusterizer1D< T >::theEstimator.

00170 {
00171     delete theEstimator;
00172 }


Member Function Documentation

template<class T>
FsmwClusterizer1D< T > * FsmwClusterizer1D< T >::clone ( void   )  const [inline, virtual]

Implements Clusterizer1D< T >.

Definition at line 175 of file FsmwClusterizer1D.h.

00176 {
00177     return new FsmwClusterizer1D<T>( *this );
00178 }

template<class T>
std::pair< std::vector< Cluster1D< T > >, std::vector< const T * > > FsmwClusterizer1D< T >::operator() ( const std::vector< Cluster1D< T > > &  ov  )  const [inline, virtual]

Implements Clusterizer1D< T >.

Definition at line 182 of file FsmwClusterizer1D.h.

References err, FsmwClusterizer1DNameSpace::fsmw(), i, python::multivaluedict::sort(), funct::sqrt(), square(), FsmwClusterizer1D< T >::theFraction, FsmwClusterizer1D< T >::theNSigmaIn, v, and weight.

00183 {
00184     using namespace Clusterizer1DCommons;
00185     using namespace FsmwClusterizer1DNameSpace;
00186     typedef Cluster1D<T> Cluster1D;
00187     std::vector < const T * > unusedtracks;
00188 
00189     switch ( ov.size() )
00190     {
00191     case 0:
00192         throw Clustering1DException("[FsmwClusterizer1D] no values given" );
00193     case 1:
00194         std::pair < std::vector < Cluster1D >, std::vector < const T * > > ret ( ov, unusedtracks );
00195         return ret;
00196     };
00197 
00198     std::vector < Cluster1D > v = ov;
00199     sort ( v.begin(), v.end(), ComparePairs<T>() );
00200     std::vector < Cluster1D > sols;
00201 
00202     std::pair < typename std::vector< Cluster1D >::const_iterator,
00203     typename std::vector< Cluster1D >::const_iterator > estors
00204     = fsmw ( v, theFraction );
00205 
00206     double weight = estors.first->weight() + estors.second->weight();
00207     double est = ( estors.first->weight() * estors.first->position().value() +
00208                    estors.second->weight() * estors.second->position().value() ) /
00209                  weight;
00210     double err=0.;
00211     double sigma = sqrt ( square ( estors.first->position().value() - est ) +
00212                           square ( estors.second->position().value() - est ));
00213     /*
00214     std::cout << "[FsmwClusterizer1D] first=" << estors.first->position().value()
00215               << " second=" << estors.second->position().value()
00216               << " est=" << est << std::endl;
00217     double sigma = sqrt ( square ( estors.first->position().error() ) +
00218                           square ( estors.second->position().error() ) );
00219     double sigma = estors.first->position().error();
00220                           */
00221     std::vector < const T * > trks;
00222     int inliers=0;
00223 
00224     for ( typename std::vector< Cluster1D >::iterator i=v.begin();
00225             i!=v.end() ; ++i )
00226     {
00227         /*
00228         std::cout << "[FsmwClusterizer1D] see if they're in: delta="
00229                   << 10000 * fabs ( i->position().value() - est )
00230                   << " sigma=" << 10000 * sigma << std::endl;
00231          */
00232         if ( fabs ( i->position().value() - est ) < theNSigmaIn * sigma )
00233         {
00234             // all within theNSigmaIn sigma are 'in'
00235             add ( i->tracks(), trks );
00236             err+= square ( i->position().value() - est );
00237             inliers++;
00238         } else {
00239             add ( i->tracks(), unusedtracks );
00240         };
00241     };
00242     err /= ( inliers - 1 ); // the algo definitely produces 2 or more inliers
00243     err = sqrt ( err );
00244 
00245 
00246     err=sqrt(err);
00247     sols.push_back ( Cluster1D ( Measurement1D ( est, err ), trks, weight ) );
00248 
00249     std::pair < std::vector < Cluster1D >, std::vector < const T * > > ret ( sols, unusedtracks );
00250     return ret;
00251 }


Member Data Documentation

template<class T>
WeightEstimator<T>* FsmwClusterizer1D< T >::theEstimator [private]

Definition at line 33 of file FsmwClusterizer1D.h.

Referenced by FsmwClusterizer1D< T >::~FsmwClusterizer1D().

template<class T>
double FsmwClusterizer1D< T >::theFraction [private]

Definition at line 34 of file FsmwClusterizer1D.h.

Referenced by FsmwClusterizer1D< T >::operator()().

template<class T>
double FsmwClusterizer1D< T >::theNSigmaIn [private]

Definition at line 35 of file FsmwClusterizer1D.h.

Referenced by FsmwClusterizer1D< T >::operator()().


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:21:03 2009 for CMSSW by  doxygen 1.5.4