NTupleLikeliHoodFCN.cxx
Go to the documentation of this file.
1 
12 #ifdef _MSC_VER
13 #include "msdevstudio/MSconfig.h"
14 #endif
15 
16 #include "NTupleLikeliHoodFCN.h"
17 
19 #include "datasrcs/DataSource.h"
20 #include "functions/FunctionBase.h"
21 
22 #include <cmath>
23 #include <cassert>
24 
25 using std::vector;
26 using std::log;
27 using std::pow;
28 using std::exp;
29 
30 using namespace hippodraw;
31 
34 {
35 }
36 
39  : NTupleFCN ( fcn )
40 {
41 }
42 
43 StatedFCN *
45 clone () const
46 {
47  return new NTupleLikeliHoodFCN ( *this );
48 }
49 
50 namespace dp = hippodraw::DataPoint2DTuple;
51 
52 double
55 {
56  double result = 0.0;
57  double sum1 = 0.0;
58  double sum2 = 0.0;
59 
60  int ix = m_indices [ dp::X ];
61  int iy = m_indices [ dp::Y ];
62  int ie = m_indices [ dp::XERR ];
63 
64  int num_bins = m_ntuple -> rows ();
65  for( int i = 0; i < num_bins; i++ )
66  {
67  if ( acceptRow ( i ) ) {
68  const vector < double > & row = m_ntuple -> getRow ( i );
69 
70  // Get the edges of the bin.
71  double x = row [ ix ];
72  double hwidth = 0.5 * row [ ie ];
73  double edgeL = x - hwidth;
74  double edgeR = x + hwidth;
75 
76  // Integrate function over the entire i-th bin
77  double theta = m_function-> integrate( edgeL, edgeR );
78 
79  // Get number of enteries in the ith bin
80  double n = 2.0 * hwidth * row [ iy ];
81 
82  // Computing the factorial of n and taking log of it.
83  // Exact computation is done when N is small ( < 100) else
84  // we use sterliing's approximations for it.
85  // CAUTION: Exactly calculating factorial itself usually leads to
86  // a very large and unrepresentable number so we avoid it.
87  //double logfactn = 0.0;
88  //if( n < 100 )
89  //{
90  //
91  // for( int j = 2; j <= n; j++)
92  // logfactn += log( (double) j );
93  //
94  // result += ( n * log ( theta ) - theta - logfactn );
95  //}
96  //else
97  //{
98  // logfactn = n * log( (double) n ) - n;
99  // result +=( n * ( log ( theta ) - log( (double) n ) + 1 ) - theta );
100  //}
101 
102  //result += ( n * log ( theta ) - theta );
103 
104  sum1 += n * log ( theta );
105  sum2 += theta;
106 
107  }
108  }
109  result = sum1 - sum2;
110  // The quantity that is (asymptotically) equivalent to
111  // chi-square is -2 log( L ) i.e we return -2 * result
112 
113  return ( -2 * result );
114 }
115 
116 bool
119 {
120  return true;
121 }

Generated for HippoDraw Class Library by doxygen