Jpp
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | List of all members
JFIT::JRegressor< JPoint4D, JSimplex > Struct Template Reference

Regressor function object for JPoint4D fit using JSimplex minimiser. More...

#include <JPoint4DRegressor.hh>

Inheritance diagram for JFIT::JRegressor< JPoint4D, JSimplex >:
JFIT::JAbstractRegressor< JPoint4D, JSimplex > JFIT::JSimplex< JPoint4D > JEEP::JMessage< JSimplex< JPoint4D > >

Public Types

typedef JSimplex< JPoint4Dminimiser_type
 
typedef JRegressor< JPoint4D, JSimplexregressor_type
 
typedef minimiser_type::result_type result_type
 

Public Member Functions

 JRegressor (const bool __prefit)
 Constructor. More...
 
 JRegressor (TH2D *hPDF2D, bool __prefit)
 Constructor for a 2D histogram as PDF
More...
 
template<class JHit_t >
double operator() (const JPoint4D &vertex, const JHit_t &hit) const
 
double evaluatePrefit (const double t_res, const double cosT, const double cosT_th) const
 
double evaluateFit (const double t_res, const double D) const
 
result_type operator() (const JPoint4D &value, T __begin, T __end)
 Global fit. More...
 
result_type operator() (const JPoint4D &value, T1 __begin1, T1 __end1, T2 __begin2, T2 __end2)
 Global fit. More...
 
double operator() (const JFunction_t &fit, T __begin, T __end)
 Multi-dimensional fit. More...
 
double operator() (const JFunction_t &fit, T __begin, T __end, const JPoint4D &step)
 1D fit. More...
 

Public Attributes

TH2D * hpdf2d [NUMBER_OF_PDFS]
 PDF 2D. More...
 
JLANG::JSharedPointer< JMEstimatorestimator
 M-Estimator function
More...
 
const bool prefit
 
JPoint4D value
 
std::vector< JPoint4Dstep
 
int numberOfIterations
 

Static Public Attributes

static const double a = 2.0
 constant to prevent the likelihood going to infinity More...
 
static const double d_ref = 10.0
 
static const double p_max = 100
 
static const int NUMBER_OF_PDFS = 1
 
static int MAXIMUM_ITERATIONS
 maximal number of iterations More...
 
static double EPSILON
 maximal distance to minimum More...
 
static int debug
 debug level (default is off). More...
 

Private Member Functions

double evaluate (const JFunction_t &fit, T __begin, T __end) const
 Evaluate chi2 for given data set. More...
 

Detailed Description

template<>
struct JFIT::JRegressor< JPoint4D, JSimplex >

Regressor function object for JPoint4D fit using JSimplex minimiser.

Definition at line 47 of file JPoint4DRegressor.hh.

Member Typedef Documentation

◆ minimiser_type

Definition at line 78 of file JRegressor.hh.

◆ regressor_type

Definition at line 79 of file JRegressor.hh.

◆ result_type

Definition at line 80 of file JRegressor.hh.

Constructor & Destructor Documentation

◆ JRegressor() [1/2]

JFIT::JRegressor< JPoint4D, JSimplex >::JRegressor ( const bool  __prefit)
inline

Constructor.

Definition at line 55 of file JPoint4DRegressor.hh.

55  :
56  estimator(new JMEstimatorTukey(30.0)),
57  prefit(__prefit)
58  {}

◆ JRegressor() [2/2]

JFIT::JRegressor< JPoint4D, JSimplex >::JRegressor ( TH2D *  hPDF2D,
bool  __prefit 
)
inline

Constructor for a 2D histogram as PDF

Definition at line 64 of file JPoint4DRegressor.hh.

64  :
65  estimator(new JMEstimatorTukey(30.0)),
66  prefit(__prefit)
67  {
68  hpdf2d[0] = (TH2D*)hPDF2D->Clone();
69  hpdf2d[0]->Smooth();
70  }

Member Function Documentation

◆ operator()() [1/5]

template<class JHit_t >
double JFIT::JRegressor< JPoint4D, JSimplex >::operator() ( const JPoint4D vertex,
const JHit_t hit 
) const
inline

Definition at line 82 of file JPoint4DRegressor.hh.

83  {
84  using namespace std;
85  using namespace JGEOMETRY3D;
86  using namespace JTOOLS;
87 
88  const JPosition3D hit_pos(hit.getPosition());
89  const double D = hit_pos.getDistance(vertex);
90  const double t_res = hit.getT() - vertex.getT(hit_pos);
91  const JDirection3D photonDir(hit_pos - vertex.getPosition());
92  const double cosT = photonDir.getDot(hit.getDirection());
93  const double cosT_th = d_ref / sqrt(d_ref*d_ref + D*D);
94 
95  double LogLik = 0;
96 
97  if(prefit){
98 
99  LogLik = evaluatePrefit(t_res, cosT, cosT_th);
100 
101  } else {
102 
103  LogLik = evaluateFit(t_res, D);
104 
105  }
106 
107  return LogLik;
108  }

◆ evaluatePrefit()

double JFIT::JRegressor< JPoint4D, JSimplex >::evaluatePrefit ( const double  t_res,
const double  cosT,
const double  cosT_th 
) const
inline

Definition at line 111 of file JPoint4DRegressor.hh.

112  {
113 
114  double p_T = 0;
115 
116  if(cosT < 0){
117  p_T = 0;
118  } else if(cosT > cosT_th){
119  p_T = p_max;
120  } else {
121  p_T = p_max * cosT/cosT_th;
122  }
123 
124  double lik = 1 / (sqrt(a*a + t_res*t_res) + p_T);
125  double u = -log(lik);
126 
127  return estimator->getRho(u);
128  }

◆ evaluateFit()

double JFIT::JRegressor< JPoint4D, JSimplex >::evaluateFit ( const double  t_res,
const double  D 
) const
inline

Definition at line 131 of file JPoint4DRegressor.hh.

132  {
133 
134  int x_bin = hpdf2d[0]->GetXaxis()->FindBin(t_res);
135  int y_bin = hpdf2d[0]->GetYaxis()->FindBin(D);
136 
137  int nbinsX = hpdf2d[0]->GetXaxis()->GetNbins();
138  int nbinsY = hpdf2d[0]->GetYaxis()->GetNbins();
139 
140  double lik = 0;
141 
142  if(x_bin > 1 && x_bin < nbinsX){
143  if(y_bin > 1 && y_bin < nbinsY){
144  lik = hpdf2d[0]->Interpolate(t_res, D);
145  }
146  }
147 
148  if(lik == 0){
149  lik = 0.000004; // value of K40 bg
150  }
151 
152  double u = -log(lik);
153  return estimator->getRho(u);
154 
155  }

◆ operator()() [2/5]

result_type JFIT::JAbstractRegressor< JPoint4D , JSimplex >::operator() ( const JPoint4D value,
__begin,
__end 
)
inlineinherited

Global fit.

Parameters
valuestart value
__beginbegin of data set
__endend of data set
Returns
chi2

Definition at line 92 of file JRegressor.hh.

93  {
94  static_cast<minimiser_type&>(*this).value = value;
95 
96  return static_cast<minimiser_type&>(*this)(static_cast<regressor_type&>(*this), __begin, __end);
97  }

◆ operator()() [3/5]

result_type JFIT::JAbstractRegressor< JPoint4D , JSimplex >::operator() ( const JPoint4D value,
T1  __begin1,
T1  __end1,
T2  __begin2,
T2  __end2 
)
inlineinherited

Global fit.

Parameters
valuestart value
__begin1begin of first data set
__end1end of first data set
__begin2begin of second data set
__end2end of second data set
Returns
chi2

Definition at line 111 of file JRegressor.hh.

114  {
115  static_cast<minimiser_type&>(*this).value = value;
116 
117  return static_cast<minimiser_type&>(*this)(static_cast<regressor_type&>(*this), __begin1, __end1, __begin2, __end2);
118  }

◆ operator()() [4/5]

double JFIT::JSimplex< JPoint4D >::operator() ( const JFunction_t &  fit,
__begin,
__end 
)
inlineinherited

Multi-dimensional fit.

The given fit function should return the equivalent of chi2 for the current value of the given model and a given data point.

Parameters
fitfit function
__beginbegin of data
__endend of data
Returns
chi2

Definition at line 71 of file JSimplex.hh.

72  {
73  using namespace std;
74  using namespace JPP;
75 
76  double chi2_old = evaluate(fit, __begin, __end);
77 
78  const int N = step.size();
79 
80  if (N != 0) {
81 
82  double chi2[N];
83 
85 
87 
88  DEBUG("old: " << FIXED(12,5) << chi2_old << endl);
89 
90  const JModel_t p0(value);
91 
92  for (int i = 0; i != N; ++i) {
93 
94  DEBUG("step: " << i << ' ' << setw(5) << numberOfIterations << endl);
95 
96  chi2[i] = (*this)(fit, __begin, __end, step[i]);
97  }
98 
99  // overall step direction of last iteration
100 
101  JModel_t wall = value - p0;
102 
103  const double chi2_new = (*this)(fit, __begin, __end, wall);
104 
105  DEBUG("new: " << FIXED(12,5) << chi2_new << endl);
106 
107 
108  if (fabs(chi2_old - chi2_new) < EPSILON*fabs(chi2_old)) {
109  return chi2_new;
110  }
111 
112  // double overall step
113 
114  wall = value - p0;
115 
116  value += wall;
117 
118  const double fe = evaluate(fit, __begin, __end);
119 
120  value -= wall;
121 
122 
123  for (int i = N-1; i != 0; --i) {
124  chi2[i] = chi2[i-1] - chi2[i];
125  }
126 
127  chi2[0] = chi2_old - chi2[0];
128 
129 
130  double df = 0.0;
131 
132  for (int i = 0; i != N; ++i) {
133  if (chi2[i] > df) {
134  df = chi2[i];
135  }
136  }
137 
138  const double fn = chi2_new;
139  const double f0 = chi2_old;
140  const double ff = f0 - fn - df;
141 
142  // shift step directions
143 
144  if (fe < f0 && 2.0*(f0 - 2.0*fn + fe)*ff*ff < (f0-fe)*(f0-fe)*df) {
145 
146  for (int i = 0; i != N - 1; ++i) {
147  step[i] = step[i+1];
148  }
149 
150  step[N-1] = wall;
151  }
152 
153  chi2_old = chi2_new;
154  }
155  }
156 
157  return chi2_old;
158  }

◆ operator()() [5/5]

double JFIT::JSimplex< JPoint4D >::operator() ( const JFunction_t &  fit,
__begin,
__end,
const JPoint4D step 
)
inlineinherited

1D fit.

The given fit function should return the equivalent of chi2 for the current value of the given model and a given data point.

Parameters
fitfit function
__beginbegin of data
__endend of data
stepstep direction

Definition at line 173 of file JSimplex.hh.

174  {
175  using namespace std;
176  using namespace JPP;
177 
178  double lambda = 0.5; // control parameter
179  double factor = 1.0; // multiplication factor
180 
181  double chi2_old = evaluate(fit, __begin, __end);
182 
183  for (int i = 0; numberOfIterations != MAXIMUM_ITERATIONS; ++numberOfIterations, ++i) {
184 
185  value += lambda * step;
186 
187  const double chi2_new = evaluate(fit, __begin, __end);
188 
189  DEBUG("step: " << setw(3) << i << ' ' << FIXED(12,5) << chi2_old << ' ' << FIXED(12,5) << chi2_new << ' ' << FIXED(5,2) << lambda << endl);
190 
191  if (fabs(chi2_old - chi2_new) < EPSILON*fabs(chi2_old)) {
192 
193  if (chi2_new > chi2_old) {
194 
195  value -= lambda * step; // undo last step
196 
197  return chi2_old;
198 
199  } else {
200 
201  return chi2_new;
202  }
203  }
204 
205  if (chi2_new < chi2_old) {
206 
207  chi2_old = chi2_new;
208 
209  } else {
210 
211  value -= lambda * step; // step back
212  lambda = -lambda; // change direction
213 
214  if (i != 0) {
215  factor = 0.5; // reduce step size
216  }
217  }
218 
219  lambda = factor * lambda;
220  }
221 
222  return chi2_old;
223  }

◆ evaluate()

double JFIT::JSimplex< JPoint4D >::evaluate ( const JFunction_t &  fit,
__begin,
__end 
) const
inlineprivateinherited

Evaluate chi2 for given data set.

Parameters
fitfit function
__beginbegin of data
__endend of data

Definition at line 242 of file JSimplex.hh.

243  {
244  double chi2 = 0.0;
245 
246  for (T hit = __begin; hit != __end; ++hit) {
247  chi2 += fit(value, *hit);
248  }
249 
250  return chi2;
251  }

Member Data Documentation

◆ a

const double JFIT::JRegressor< JPoint4D, JSimplex >::a = 2.0
static

constant to prevent the likelihood going to infinity

Definition at line 157 of file JPoint4DRegressor.hh.

◆ d_ref

const double JFIT::JRegressor< JPoint4D, JSimplex >::d_ref = 10.0
static

Definition at line 158 of file JPoint4DRegressor.hh.

◆ p_max

const double JFIT::JRegressor< JPoint4D, JSimplex >::p_max = 100
static

Definition at line 159 of file JPoint4DRegressor.hh.

◆ NUMBER_OF_PDFS

const int JFIT::JRegressor< JPoint4D, JSimplex >::NUMBER_OF_PDFS = 1
static

Definition at line 161 of file JPoint4DRegressor.hh.

◆ hpdf2d

PDF 2D.

Definition at line 162 of file JPoint4DRegressor.hh.

◆ estimator

M-Estimator function

Definition at line 164 of file JPoint4DRegressor.hh.

◆ prefit

const bool JFIT::JRegressor< JPoint4D, JSimplex >::prefit

Definition at line 165 of file JPoint4DRegressor.hh.

◆ MAXIMUM_ITERATIONS

int JFIT::JSimplex< JPoint4D >::MAXIMUM_ITERATIONS
staticinherited

maximal number of iterations

maximal number of iterations.

Definition at line 226 of file JSimplex.hh.

◆ EPSILON

double JFIT::JSimplex< JPoint4D >::EPSILON
staticinherited

maximal distance to minimum

maximal distance to minimum.

Definition at line 227 of file JSimplex.hh.

◆ value

JPoint4D JFIT::JSimplex< JPoint4D >::value
inherited

Definition at line 229 of file JSimplex.hh.

◆ step

Definition at line 230 of file JSimplex.hh.

◆ numberOfIterations

int JFIT::JSimplex< JPoint4D >::numberOfIterations
inherited

Definition at line 231 of file JSimplex.hh.

◆ debug

int JEEP::JMessage< JSimplex< JPoint4D > >::debug
staticinherited

debug level (default is off).

Definition at line 45 of file JMessage.hh.


The documentation for this struct was generated from the following file:
JFIT::JRegressor< JPoint4D, JSimplex >::d_ref
static const double d_ref
Definition: JPoint4DRegressor.hh:158
FIXED
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
JFIT::JRegressor< JPoint4D, JSimplex >::evaluatePrefit
double evaluatePrefit(const double t_res, const double cosT, const double cosT_th) const
Definition: JPoint4DRegressor.hh:111
JFIT::JRegressor< JPoint4D, JSimplex >::p_max
static const double p_max
Definition: JPoint4DRegressor.hh:159
JTOOLS::u
double u[N+1]
Definition: JPolint.hh:706
JGEOMETRY3D::JVector3D::getDistance
double getDistance(const JVector3D &pos) const
Get distance to point.
Definition: JVector3D.hh:269
JGEOMETRY3D::JDirection3D::getDot
double getDot(const JAngle3D &angle) const
Get dot product.
Definition: JDirection3D.hh:333
JGEOMETRY3D::JDirection3D
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:32
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JFIT::JRegressor< JPoint4D, JSimplex >::estimator
JLANG::JSharedPointer< JMEstimator > estimator
M-Estimator function
Definition: JPoint4DRegressor.hh:164
JFIT::JRegressor< JPoint4D, JSimplex >::hpdf2d
TH2D * hpdf2d[NUMBER_OF_PDFS]
PDF 2D.
Definition: JPoint4DRegressor.hh:162
JFIT::JSimplex< JPoint4D >::value
JPoint4D value
Definition: JSimplex.hh:229
JGEOMETRY3D::JPosition3D
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
JFIT::JRegressor< JPoint4D, JSimplex >::a
static const double a
constant to prevent the likelihood going to infinity
Definition: JPoint4DRegressor.hh:157
JFIT::JRegressor< JPoint4D, JSimplex >::prefit
const bool prefit
Definition: JPoint4DRegressor.hh:165
JFIT::JMEstimatorTukey
Tukey's biweight M-estimator.
Definition: JMEstimator.hh:105
JFIT::JSimplex< JPoint4D >::evaluate
double evaluate(const JFunction_t &fit, T __begin, T __end) const
Evaluate chi2 for given data set.
Definition: JSimplex.hh:242
JGEOMETRY3D::JPosition3D::getPosition
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:129
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JFIT::JRegressor< JPoint4D, JSimplex >::evaluateFit
double evaluateFit(const double t_res, const double D) const
Definition: JPoint4DRegressor.hh:131
JGEOMETRY3D
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition: JAngle3D.hh:18
JTOOLS
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
Definition: JAbstractCollection.hh:9
JFIT::JSimplex< JPoint4D >::step
std::vector< JPoint4D > step
Definition: JSimplex.hh:230
JGEOMETRY3D::JVertex3D::getT
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition: JVertex3D.hh:144
JFIT::JSimplex< JPoint4D >::EPSILON
static double EPSILON
maximal distance to minimum
Definition: JSimplex.hh:227
JFIT::JSimplex< JPoint4D >::MAXIMUM_ITERATIONS
static int MAXIMUM_ITERATIONS
maximal number of iterations
Definition: JSimplex.hh:226
JFIT::JSimplex< JPoint4D >::numberOfIterations
int numberOfIterations
Definition: JSimplex.hh:231