00001
00012 #ifdef _MSC_VER
00013 #include "msdevstudio/MSconfig.h"
00014 #endif
00015
00016 #include "NTuplePearsonFCN.h"
00017
00018 #include "functions/FunctionBase.h"
00019
00020 #include "datasrcs/DataPointTuple.h"
00021 #include "datasrcs/DataSource.h"
00022
00023 using std::vector;
00024
00025 using namespace hippodraw;
00026
00027 NTuplePearsonFCN::
00028 NTuplePearsonFCN ( )
00029 {
00030 }
00031
00032 NTuplePearsonFCN::
00033 NTuplePearsonFCN ( const NTuplePearsonFCN & fcn )
00034 : NTupleFCN ( fcn )
00035 {
00036 }
00037
00038 StatedFCN *
00039 NTuplePearsonFCN::
00040 clone () const
00041 {
00042 return new NTuplePearsonFCN ( *this );
00043 }
00044
00045 double
00046 NTuplePearsonFCN::
00047 #ifdef HAVE_MINUIT2
00048 Up () const
00049 #else
00050 up () const
00051 #endif
00052 {
00053 return 1.0;
00054 }
00055
00056 namespace dp = hippodraw::DataPoint2DTuple;
00057
00058 double
00059 NTuplePearsonFCN::
00060 objectiveValue () const
00061 {
00062 double result = 0.0;
00063
00064 unsigned int size = m_indices.size ();
00065
00066 if ( size == dp::SIZE ) {
00067 int ix = m_indices [ dp::X ];
00068 int iy = m_indices [ dp::Y ];
00069
00070 unsigned int rows = m_ntuple -> rows ();
00071
00072 for ( unsigned int i = 0; i < rows; i++ ) {
00073 if ( acceptRow ( i ) ) {
00074 const vector < double > & row = m_ntuple -> getRow ( i );
00075 double function_value = m_function -> operator () ( row [ ix ] );
00076 double diff = function_value - row [ iy ];
00077 result += diff * diff / (function_value + 10e-6);
00078 }
00079 }
00080 }
00081 else {
00082 unsigned int dimen = size - 2;
00083 vector < double > coord ( dimen );
00084
00085 int iy = m_indices [ size / 2 - 1 ];
00086 int ie = m_indices [ size - 1 ];
00087
00088 unsigned int rows = m_ntuple -> rows ();
00089
00090 for ( unsigned int i = 0; i < rows; i++ ) {
00091 if ( acceptRow ( i ) ) {
00092 const vector < double > & row = m_ntuple -> getRow ( i );
00093
00094 double err = ie < 0 ? 0. : row [ ie ];
00095 if ( err == 0.0 && m_has_errors ) continue;
00096 if ( m_has_errors == false ) err = 1.0;
00097
00098 for ( unsigned int j = 0; j < dimen; j++ ) {
00099 coord [ j ] = row [ m_indices [ j ] ];
00100 }
00101 double value = m_function -> operator () ( coord );
00102 double diff = value - row [ iy ];
00103 result += diff * diff / ( value * 10e-6 );
00104 }
00105 }
00106 }
00107
00108 return result;
00109 }
00110
00111 bool
00112 NTuplePearsonFCN::
00113 needsIntegrated () const
00114 {
00115 return false;
00116 }