![]() |
![]() |
00001 #ifndef _Cluster1DMerger_H_ 00002 #define _Cluster1DMerger_H_ 00003 00004 #include "CommonTools/Clustering1D/interface/Cluster1D.h" 00005 #include "CommonTools/Clustering1D/interface/WeightEstimator.h" 00006 #include <cmath> 00007 00013 template < class T > 00014 class Cluster1DMerger 00015 { 00016 public: 00017 Cluster1DMerger ( const WeightEstimator<T> & ); 00018 ~Cluster1DMerger(); 00019 Cluster1DMerger ( const Cluster1DMerger & ); 00020 Cluster1D<T> operator() ( const Cluster1D<T> & first, 00021 const Cluster1D<T> & second ) const; 00022 private: 00023 WeightEstimator<T> * theEstimator; 00024 }; 00025 00026 /* 00027 * implementation 00028 */ 00029 00030 template <class T> 00031 Cluster1DMerger<T>::Cluster1DMerger 00032 ( const WeightEstimator<T> & est ) : theEstimator ( est.clone() ) 00033 {} 00034 00035 template <class T> 00036 Cluster1DMerger<T>::~Cluster1DMerger() 00037 { 00038 delete theEstimator; 00039 } 00040 00041 template <class T> 00042 Cluster1DMerger<T>::Cluster1DMerger ( const Cluster1DMerger & other ) : 00043 theEstimator ( other.theEstimator->clone() ) 00044 {} 00045 00046 template <class T> 00047 Cluster1D<T> Cluster1DMerger<T>::operator() ( const Cluster1D<T> & first, 00048 const Cluster1D<T> & second ) const 00049 { 00050 std::vector < const T * > tracks = first.tracks(); 00051 std::vector < const T * > sectracks = second.tracks(); 00052 for ( typename std::vector< const T * >::const_iterator i=sectracks.begin(); 00053 i!=sectracks.end() ; ++i ) 00054 { 00055 tracks.push_back ( *i ); 00056 }; 00057 double V1=first.position().error() * first.position().error(); 00058 double V2=second.position().error() * second.position().error(); 00059 double C1=first.weight() / V1; 00060 double C2=second.weight() / V2; 00061 00062 double newpos = ( first.position().value() * C1 + 00063 second.position().value() * C2 ) / ( C1 + C2 ); 00064 00065 double newerr = sqrt ( C1 * C1 * V1 + C2 * C2 * V2 ) / ( C1 + C2 ); 00066 double newWeight = theEstimator->weight ( tracks ); 00067 00068 Measurement1D newmeas ( newpos, newerr ); 00069 return Cluster1D<T> ( newmeas, tracks, newWeight ); 00070 } 00071 00072 #endif