Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
JFIT::JRegressor< JLine3Z, JGandalf > Struct Reference

Regressor function object for JLine3Z fit using JGandalf minimiser. More...

#include <JLine3ZRegressor.hh>

Inheritance diagram for JFIT::JRegressor< JLine3Z, JGandalf >:
JFIT::JAbstractRegressor< JLine3Z, JGandalf > JFIT::JRegressorStorage< JLine3Z, JGandalf > JFIT::JGandalf< JModel_t > JFIT::JRegressorHelper< JLine3Z, JGandalf > JEEP::JMessage< T >

Public Types

typedef JRegressorStorage< JLine3Z, JGandalfJRegressorStorage_t
 
typedef JGandalf< JLine3Zminimiser_type
 
typedef JRegressor< JLine3Z, JGandalfregressor_type
 
typedef minimiser_type::result_type result_type
 
typedef JFIT_LOCAL::JTypedef_t< JModel_t >::parameter_type parameter_type
 Data type of fit parameter. More...
 
typedef JTOOLS::JSplineFunction1S_t JFunction1D_t
 
typedef JTOOLS::JMAPLIST< JTOOLS::JPolint1FunctionalMap, JTOOLS::JPolint0FunctionalGridMap, JTOOLS::JPolint0FunctionalGridMap >::maplist JPDFMaplist_t
 
typedef JPHYSICS::JPDFTable< JFunction1D_t, JPDFMaplist_tJPDF_t
 time dependent PDF More...
 
typedef JTOOLS::JMAPLIST< JTOOLS::JPolint1FunctionalMapH, JTOOLS::JPolint1FunctionalGridMap, JTOOLS::JPolint1FunctionalGridMap >::maplist JNPEMaplist_t
 
typedef JPHYSICS::JNPETable< double, double, JNPEMaplist_tJNPE_t
 time integrated PDF More...
 
typedef JPDF_t::transformer_type transformer_type
 
typedef std::array< JPDF_t, NUMBER_OF_PDFSJPDFs_t
 PDFs. More...
 
typedef std::array< JNPE_t, NUMBER_OF_PDFSJNPEs_t
 NPEs. More...
 

Public Member Functions

 JRegressor ()
 Default constructor. More...
 
 JRegressor (const std::string &fileDescriptor, const double TTS, const int numberOfPoints=25, const double epsilon=1.0e-10)
 Constructor. More...
 
 JRegressor (const JRegressorStorage< JLine3Z, JGandalf > &storage)
 Constructor. More...
 
template<class JHit_t >
result_type operator() (const JLine3Z &track, const JHit_t &hit) const
 Fit function. More...
 
result_type operator() (const JLine3Z &track, const JPMTW0 &pmt) const
 Fit function. More...
 
JPDF_t::result_type getH0 (const double R_Hz, const double t1) const
 Get background hypothesis value for time differentiated PDF. More...
 
JPDF_t::result_type getH1 (const double E, const double R, const double theta, const double phi, const double t1) const
 Get signal hypothesis value for time differentiated PDF. More...
 
JNPE_t::result_type getH0 (const double R_Hz) const
 Get background hypothesis value for time integrated PDF. More...
 
JNPE_t::result_type getH1 (const double E, const double R, const double theta, const double phi) const
 Get signal hypothesis value for time integrated PDF. More...
 
double getRmax () const
 Get maximal road width of PDF. More...
 
result_type operator() (const JLine3Z &value, T __begin, T __end)
 Global fit. More...
 
template<class JFunction_t , class T , class ... Args>
result_type operator() (const JFunction_t &fit, T __begin, T __end, Args ...args)
 Multi-dimensional fit of multiple data sets. More...
 
const JPDFs_tgetPDF () const
 Get PDFs. More...
 
const JNPEs_tgetNPE () const
 Get NPEs. More...
 
void transform (const transformer_type &transformer)
 Transform PDFs and NPEs. More...
 
void setRmax (const double Rmax)
 Set maximal road width of PDF. More...
 

Public Attributes

const JPDFs_tpdf
 PDF. More...
 
const JNPEs_tnpe
 PDF. More...
 
double E_GeV = 0.0
 Energy of muon at vertex [GeV]. More...
 
JLANG::JSharedPointer< JMEstimatorestimator = new JMEstimatorNormal()
 M-Estimator function. More...
 
std::vector< parameter_typeparameters
 fit parameters More...
 
int numberOfIterations
 number of iterations More...
 
double lambda
 control parameter More...
 
JModel_t value
 value More...
 
JModel_t error
 error More...
 
JMATH::JMatrixNS V
 Hesse matrix. More...
 

Static Public Attributes

static JTimeRange T_ns
 Time window with respect to Cherenkov hypothesis [ns]. More...
 
static double Vmax_npe = std::numeric_limits<double>::max()
 Maximal integral of PDF [npe]. More...
 
static double Rmin_m = 0.1
 Minimal distance of [m]. More...
 
static int MAXIMUM_ITERATIONS = 1000
 maximal number of iterations More...
 
static double EPSILON = 1.0e-3
 maximal distance to minimum More...
 
static bool EPSILON_ABSOLUTE = false
 set epsilon to absolute difference instead of relative More...
 
static double LAMBDA_MIN = 0.01
 minimal value control parameter More...
 
static double LAMBDA_MAX = 100.0
 maximal value control parameter More...
 
static double LAMBDA_UP = 10.0
 multiplication factor control parameter More...
 
static double LAMBDA_DOWN = 10.0
 multiplication factor control parameter More...
 
static double PIVOT = std::numeric_limits<double>::epsilon()
 minimal value diagonal element of Hesse matrix More...
 
static int debug = 0
 debug level (default is off). More...
 
static const int NUMBER_OF_PDFS = 6
 Number of PDFs. More...
 
static const JPDFType_t pdf_t [NUMBER_OF_PDFS]
 PDF types. More...
 

Private Member Functions

void reset ()
 Reset current parameters. More...
 
template<class JFunction_t , class T , class ... Args>
void update (const JFunction_t &fit, T __begin, T __end, Args ...args)
 Recursive method to update current parameters. More...
 
template<class JFunction_t >
void update (const JFunction_t &fit)
 Termination method to update current parameters. More...
 

Static Private Member Functions

static double get (const JModel_t &model, double JModel_t::*parameter)
 Read/write access to parameter value by data member. More...
 
static double & get (JModel_t &model, double JModel_t::*parameter)
 Read/write access to parameter value by data member. More...
 
static double get (const JModel_t &model, const size_t index)
 Read/write access to parameter value by index. More...
 
static double & get (JModel_t &model, const size_t index)
 Read/write access to parameter value by index. More...
 
static double get (const JModel_t &model, const int index)
 Read/write access to parameter value by index. More...
 
static double & get (JModel_t &model, const int index)
 Read/write access to parameter value by index. More...
 

Private Attributes

std::vector< double > h
 
JMATH::JVectorND x
 
struct {
   result_type   result
 
current
 
struct {
   JModel_t   value
 
   result_type   result
 
previous
 
JPDFs_t _pdf
 PDFs. More...
 
JNPEs_t _npe
 NPEs. More...
 

Detailed Description

Regressor function object for JLine3Z fit using JGandalf minimiser.

Definition at line 103 of file JLine3ZRegressor.hh.

Member Typedef Documentation

◆ JRegressorStorage_t

Definition at line 109 of file JLine3ZRegressor.hh.

◆ minimiser_type

Definition at line 80 of file JRegressor.hh.

◆ regressor_type

Definition at line 81 of file JRegressor.hh.

◆ result_type

Definition at line 82 of file JRegressor.hh.

◆ parameter_type

template<class JModel_t >
typedef JFIT_LOCAL::JTypedef_t<JModel_t>::parameter_type JFIT::JGandalf< JModel_t >::parameter_type
inherited

Data type of fit parameter.

Definition at line 95 of file JGandalf.hh.

◆ JFunction1D_t

Definition at line 57 of file JRegressorHelper.hh.

◆ JPDFMaplist_t

Definition at line 60 of file JRegressorHelper.hh.

◆ JPDF_t

time dependent PDF

Definition at line 61 of file JRegressorHelper.hh.

◆ JNPEMaplist_t

Definition at line 65 of file JRegressorHelper.hh.

◆ JNPE_t

time integrated PDF

Definition at line 66 of file JRegressorHelper.hh.

◆ transformer_type

Definition at line 68 of file JRegressorHelper.hh.

◆ JPDFs_t

PDFs.

Definition at line 72 of file JRegressorHelper.hh.

◆ JNPEs_t

NPEs.

Definition at line 73 of file JRegressorHelper.hh.

Constructor & Destructor Documentation

◆ JRegressor() [1/3]

Default constructor.

Definition at line 114 of file JLine3ZRegressor.hh.

114  :
116  pdf(getPDF()),
117  npe(getNPE())
118  {}
const JPDFs_t & getPDF() const
Get PDFs.
const JNPEs_t & getNPE() const
Get NPEs.
JRegressorStorage< JLine3Z, JGandalf > JRegressorStorage_t

◆ JRegressor() [2/3]

JFIT::JRegressor< JLine3Z, JGandalf >::JRegressor ( const std::string &  fileDescriptor,
const double  TTS,
const int  numberOfPoints = 25,
const double  epsilon = 1.0e-10 
)
inline

Constructor.

The PDF file descriptor should contain the wild card character JPHYSICS::WILDCARD which will be replaced by the corresponding PDF types listed in JRegressor<JLine3Z, JGandalf>::pdf_t.

The TTS corresponds to the additional time smearing applied to the PDFs.

Parameters
fileDescriptorPDF file descriptor
TTSTTS [ns]
numberOfPointsnumber of points for Gauss-Hermite integration of TTS
epsilonprecision for Gauss-Hermite integration of TTS

Definition at line 134 of file JLine3ZRegressor.hh.

137  :
138  JRegressorStorage_t(fileDescriptor, TTS, numberOfPoints, epsilon),
139  pdf(getPDF()),
140  npe(getNPE())
141  {}
int numberOfPoints
Definition: JResultPDF.cc:22
const double epsilon
Definition: JQuadrature.cc:21

◆ JRegressor() [3/3]

Constructor.

Parameters
storagePDF storage

Definition at line 149 of file JLine3ZRegressor.hh.

149  :
150  pdf(storage.getPDF()),
151  npe(storage.getNPE())
152  {}

Member Function Documentation

◆ operator()() [1/4]

template<class JHit_t >
result_type JFIT::JRegressor< JLine3Z, JGandalf >::operator() ( const JLine3Z track,
const JHit_t hit 
) const
inline

Fit function.

This method is used to determine the chi2 and gradient of given hit with respect to trajectory of muon.

The template argument JHit_t refers to a data structure which should have the following member methods:

  • double getX(); // [m]
  • double getY(); // [m]
  • double getZ(); // [m]
  • double getDX(); // [u]
  • double getDY(); // [u]
  • double getDZ(); // [u]
  • double getT(); // [ns]
Parameters
tracktrack
hithit
Returns
chi2 and gradient

Definition at line 173 of file JLine3ZRegressor.hh.

174  {
175  using namespace JPP;
176 
177  JPosition3D D(hit.getX(), hit.getY(), hit.getZ());
178  JDirection3D U(hit.getDX(), hit.getDY(), hit.getDZ());
179 
180  D.sub(track.getPosition());
181 
182  const double z = D.getDot(track.getDirection());
183  const double x = D.getX() - z * track.getDX();
184  const double y = D.getY() - z * track.getDY();
185  const double R2 = D.getLengthSquared() - z*z;
186  const double R = (R2 > Rmin_m*Rmin_m ? sqrt(R2) : Rmin_m);
187 
188  const double t1 = track.getT() + (z + R * getTanThetaC()) * getInverseSpeedOfLight();
189 
190  U.rotate(JRotation3Z(-atan2(y,x))); // rotate PMT axis to x-z plane
191 
192  const double theta = U.getTheta();
193  const double phi = fabs(U.getPhi());
194 
195  const double E = gWater.getE(E_GeV, z);
196  const double dt = T_ns.constrain(hit.getT() - t1);
197 
198  JPDF_t::result_type H0 = getH0(hit.getR(), dt);
199  JPDF_t::result_type H1 = getH1(E, R, theta, phi, dt);
200 
201  if (H1.V >= Vmax_npe) {
202  H1 *= Vmax_npe / H1.V;
203  }
204 
205  H1 += H0; // signal + background
206 
208 
209  result.chi2 = H1.getChi2() - H0.getChi2(); // Likelihood ratio
210 
211  const double wc = 1.0 - getTanThetaC() * z / R; // d(ct1)/d(z)
212 
213  result.gradient = JLine3Z(JLine1Z(JPosition3D(-getTanThetaC() * D.getX() / R, // d(ct1)/d(x)
214  -getTanThetaC() * D.getY() / R, // d(ct1)/d(y)
215  0.0),
216  getSpeedOfLight()), // d(ct1)/d(t)
217  JVersor3Z(wc * (D.getX() - D.getZ()*track.getDX()/track.getDZ()), // d(ct1)/d(dx)
218  wc * (D.getY() - D.getZ()*track.getDY()/track.getDZ()))); // d(ct1)/d(dy)
219 
220  result.gradient.mul(getInverseSpeedOfLight() * (H1.getDerivativeOfChi2() -
221  H0.getDerivativeOfChi2())); // x d(chi2)/d(ct1)
222 
223  return result;
224  }
JMATH::JVectorND x
Definition: JGandalf.hh:483
result_type result
Definition: JGandalf.hh:486
Data structure for fit of straight line paralel to z-axis.
Definition: JLine1Z.hh:29
Data structure for fit of straight line in positive z-direction.
Definition: JLine3Z.hh:40
JVersor3D getDirection(const JVector3D &pos) const
Get photon direction of Cherenkov light on PMT.
Definition: JLine3Z.hh:255
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition: JLine3Z.hh:234
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:35
Data structure for position in three dimensions.
Definition: JPosition3D.hh:38
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
Rotation around Z-axis.
Definition: JRotation3D.hh:87
Data structure for normalised vector in positive z-direction.
Definition: JVersor3Z.hh:41
double getDZ() const
Get z direction.
Definition: JVersor3Z.hh:169
double getDY() const
Get y direction.
Definition: JVersor3Z.hh:158
double getDX() const
Get x direction.
Definition: JVersor3Z.hh:147
virtual double getE(const double E, const double dx) const override
Get energy of muon after specified distance.
Definition: JGeane.hh:257
T constrain(argument_type x) const
Constrain value to range.
Definition: JRange.hh:350
const double getInverseSpeedOfLight()
Get inverse speed of light.
static const JGeaneWater gWater
Function object for energy loss of muon in sea water.
Definition: JGeane.hh:381
double getTanThetaC()
Get average tangent of Cherenkov angle of water corresponding to group velocity.
const double getSpeedOfLight()
Get speed of light.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
minimiser_type::result_type result_type
Definition: JRegressor.hh:82
JModel_t gradient
partial derivatives of chi2
Definition: JGandalf.hh:136
static double Rmin_m
Minimal distance of [m].
static JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
static double Vmax_npe
Maximal integral of PDF [npe].
JPDF_t::result_type getH0(const double R_Hz, const double t1) const
Get background hypothesis value for time differentiated PDF.
JPDF_t::result_type getH1(const double E, const double R, const double theta, const double phi, const double t1) const
Get signal hypothesis value for time differentiated PDF.
double E_GeV
Energy of muon at vertex [GeV].
JModel_t & mul(const double factor)
Scale model.

◆ operator()() [2/4]

result_type JFIT::JRegressor< JLine3Z, JGandalf >::operator() ( const JLine3Z track,
const JPMTW0 pmt 
) const
inline

Fit function.

This method is used to determine the chi2 and gradient of given PMT with respect to trajectory of muon.

Parameters
tracktrack
pmtpmt
Returns
chi2 and gradient

Definition at line 235 of file JLine3ZRegressor.hh.

236  {
237  using namespace JGEOMETRY3D;
238  using namespace JPHYSICS;
239 
240  JPosition3D D(pmt.getPosition());
241  JDirection3D U(pmt.getDirection());
242 
243  D.sub(track.getPosition());
244 
245  const double z = D.getDot(track.getDirection());
246  const double x = D.getX() - z * track.getDX();
247  const double y = D.getY() - z * track.getDY();
248  const double R2 = D.getLengthSquared() - z*z;
249  const double R = (R2 > Rmin_m*Rmin_m ? sqrt(R2) : Rmin_m);
250 
251  U.rotate(JRotation3Z(-atan2(y,x))); // rotate PMT axis to x-z plane
252 
253  const double theta = U.getTheta();
254  const double phi = fabs(U.getPhi());
255 
256  const double E = gWater.getE(E_GeV, z);
257 
258  JNPE_t::result_type H0 = getH0(pmt.getR());
259  JNPE_t::result_type H1 = getH1(E, R, theta, phi);
260 
261  if (H1.f >= Vmax_npe) {
262  H1 *= Vmax_npe / H1.f;
263  }
264 
265  H1 += H0;
266 
267  const bool hit = pmt.getN() != 0;
268  const double u = H1.getChi2(hit);
269 
271 
272  result.chi2 = estimator->getRho(u);
273 
274  result.gradient = JLine3Z(JLine1Z(JPosition3D(-D.getX() / R, // d(R)/d(x)
275  -D.getY() / R, // d(R)/d(y)
276  0.0),
277  0.0),
278  JVersor3Z(-z * D.getX() / R, // d(R)/d(dx)
279  -z * D.getY() / R)); // d(R)/d(dy)
280 
281  result.gradient.mul(estimator->getPsi(u));
282  result.gradient.mul(H1.getDerivativeOfChi2(hit)); // x d(chi2)/d(R)
283 
284  return result;
285  }
const JDirection3D & getDirection() const
Get direction.
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition: JAngle3D.hh:19
Auxiliary methods for light properties of deep-sea water.
double u[N+1]
Definition: JPolint.hh:865
int getN() const
Get number of hits.
Definition: JPMTW0.hh:67
double getR() const
Get rate.
Definition: JPMTW0.hh:56
JLANG::JSharedPointer< JMEstimator > estimator
M-Estimator function.

◆ getH0() [1/2]

JPDF_t::result_type JFIT::JRegressor< JLine3Z, JGandalf >::getH0 ( const double  R_Hz,
const double  t1 
) const
inline

Get background hypothesis value for time differentiated PDF.

Parameters
R_Hzrate [Hz]
t1time [ns]
Returns
hypothesis value

Definition at line 295 of file JLine3ZRegressor.hh.

297  {
298  return JPDF_t::result_type(R_Hz * 1e-9, t1, T_ns);
299  }

◆ getH1() [1/2]

JPDF_t::result_type JFIT::JRegressor< JLine3Z, JGandalf >::getH1 ( const double  E,
const double  R,
const double  theta,
const double  phi,
const double  t1 
) const
inline

Get signal hypothesis value for time differentiated PDF.

Parameters
Emuon energy at minimum distance of approach [GeV]
Rminimum distance of approach [m]
thetaPMT zenith angle [rad]
phiPMT azimuth angle [rad]
t1arrival time relative to Cherenkov hypothesis [ns]
Returns
hypothesis value

Definition at line 312 of file JLine3ZRegressor.hh.

317  {
318  using namespace std;
319  using namespace JPP;
320 
321  JPDF_t::result_type h1 = zero;
322 
323  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
324 
325  if (!pdf[i].empty() && R <= pdf[i].getXmax()) {
326 
327  JPDF_t::result_type y1 = pdf[i](max(R, pdf[i].getXmin()), theta, phi, t1);
328 
329  // safety measures
330 
331  if (y1.f <= 0.0) {
332  y1.f = 0.0;
333  y1.fp = 0.0;
334  }
335 
336  if (y1.v <= 0.0) {
337  y1.v = 0.0;
338  }
339 
340  // energy dependence
341 
342  if (is_deltarays(pdf_t[i])) {
343  y1 *= getDeltaRaysFromMuon(E);
344  } else if (is_bremsstrahlung(pdf_t[i])) {
345  y1 *= E;
346  }
347 
348  h1 += y1;
349  }
350  }
351 
352  return h1;
353  }
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
double getDeltaRaysFromMuon(const double E, const JRange< double > T_GeV=JRange< double >(DELTARAY_TMIN, DELTARAY_TMAX))
Equivalent EM-shower energy due to delta-rays per unit muon track length.
Definition: JPDFToolkit.hh:260
bool is_deltarays(const int pdf)
Test if given PDF type corresponds to Cherenkov light from delta-rays.
Definition: JPDFTypes.hh:151
bool is_bremsstrahlung(const int pdf)
Test if given PDF type corresponds to Cherenkov light from Bremsstrahlung.
Definition: JPDFTypes.hh:137
Definition: JSTDTypes.hh:14
static const JPDFType_t pdf_t[NUMBER_OF_PDFS]
PDF types.
static const int NUMBER_OF_PDFS
Number of PDFs.

◆ getH0() [2/2]

JNPE_t::result_type JFIT::JRegressor< JLine3Z, JGandalf >::getH0 ( const double  R_Hz) const
inline

Get background hypothesis value for time integrated PDF.

Parameters
R_Hzrate [Hz]
Returns
hypothesis value

Definition at line 362 of file JLine3ZRegressor.hh.

363  {
364  return JNPE_t::result_type(R_Hz * 1e-9 * T_ns.getLength(), 0.0);
365  }
T getLength() const
Get length (difference between upper and lower limit).
Definition: JRange.hh:289

◆ getH1() [2/2]

JNPE_t::result_type JFIT::JRegressor< JLine3Z, JGandalf >::getH1 ( const double  E,
const double  R,
const double  theta,
const double  phi 
) const
inline

Get signal hypothesis value for time integrated PDF.

Parameters
Emuon energy at minimum distance of approach [GeV]
Rminimum distance of approach [m]
thetaPMT zenith angle [rad]
phiPMT azimuth angle [rad]
Returns
hypothesis value

Definition at line 377 of file JLine3ZRegressor.hh.

381  {
382  using namespace std;
383  using namespace JPP;
384 
385  JNPE_t::result_type h1 = JMATH::zero;
386 
387  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
388 
389  if (!npe[i].empty() && R <= npe[i].getXmax()) {
390 
391  try {
392 
393  JNPE_t::result_type y1 = npe[i](max(R, npe[i].getXmin()), theta, phi);
394 
395  // safety measures
396 
397  if (y1.f > 0.0) {
398 
399  // energy dependence
400 
401  if (is_deltarays(pdf_t[i])) {
402  y1 *= getDeltaRaysFromMuon(E);
403  } else if (is_bremsstrahlung(pdf_t[i])) {
404  y1 *= E;
405  }
406 
407  h1 += y1;
408  }
409  }
410  catch(JException& error) {
411  ERROR(error << endl);
412  }
413  }
414  }
415 
416  return h1;
417  }
#define ERROR(A)
Definition: JMessage.hh:66
JModel_t error
error
Definition: JGandalf.hh:342
General exception.
Definition: JException.hh:24

◆ getRmax()

double JFIT::JRegressor< JLine3Z, JGandalf >::getRmax ( ) const
inline

Get maximal road width of PDF.

Returns
road width [m]

Definition at line 425 of file JLine3ZRegressor.hh.

426  {
427  double xmax = 0.0;
428 
429  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
430  if (!pdf[i].empty() && pdf[i].getXmax() > xmax) {
431  xmax = pdf[i].getXmax();
432  }
433  }
434 
435  return xmax;
436  }
const double xmax
Definition: JQuadrature.cc:24

◆ operator()() [3/4]

result_type JFIT::JAbstractRegressor< JLine3Z , JGandalf >::operator() ( const JLine3Z value,
__begin,
__end 
)
inlineinherited

Global fit.

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

Definition at line 94 of file JRegressor.hh.

95  {
96  static_cast<minimiser_type&>(*this).value = value;
97 
98  return static_cast<minimiser_type&>(*this)(static_cast<regressor_type&>(*this), __begin, __end);
99  }
JModel_t value
value
Definition: JGandalf.hh:341
JRegressor< JLine3Z, JGandalf > regressor_type
Definition: JRegressor.hh:81

◆ operator()() [4/4]

template<class JModel_t >
template<class JFunction_t , class T , class ... Args>
result_type JFIT::JGandalf< JModel_t >::operator() ( const JFunction_t &  fit,
__begin,
__end,
Args ...  args 
)
inlineinherited

Multi-dimensional fit of multiple data sets.

The fit function should return the chi2 as well as the partial derivatives for the current value of the model and a given data point.

Parameters
fitfit function
__beginbegin of data
__endend of data
argsoptional data
Returns
chi2 and gradient

Definition at line 160 of file JGandalf.hh.

161  {
162  using namespace std;
163  using namespace JPP;
164 
165  // note that all model values should be assigned to the start value of the model before use
166  // because the actual list of model parameters can vary from fit to fit
167  // (e.g. if model consists of a container).
168 
169  const size_t N = parameters.size();
170 
171  V.resize(N);
172  h.resize(N);
173  x.resize(N);
174 
175  previous.result.chi2 = numeric_limits<double>::max();
176 
177  current.result.chi2 = numeric_limits<double>::max();
178  current.result.gradient = value;
179  current.result.gradient = zero;
180 
181  error = value;
182  error = zero;
183 
184  lambda = LAMBDA_MIN;
185 
187 
188  DEBUG("step: " << numberOfIterations << endl);
189 
190  reset();
191 
192  update(fit, __begin, __end, args...);
193 
194  DEBUG("lambda: " << FIXED(12,5) << lambda << endl);
195  DEBUG("chi2: " << FIXED(12,5) << current.result.chi2 << endl);
196 
197  if (current.result.chi2 < previous.result.chi2) {
198 
199  if (numberOfIterations != 0) {
200 
201  const double tolerance = EPSILON * (EPSILON_ABSOLUTE ? 1.0 : fabs(previous.result.chi2));
202 
203  if (fabs(previous.result.chi2 - current.result.chi2) <= tolerance) {
204 
205  // normal end
206 
207  const result_type result = current.result;
208 
209  reset();
210 
211  update(fit, __begin, __end, args...);
212 
213  try {
214  V.invert();
215  }
216  catch (const exception& error) {}
217 
218  for (size_t i = 0; i != N; ++i) {
219  get(error, parameters[i]) = sqrt(V(i,i));
220  }
221 
222  return result;
223  }
224 
225  if (lambda > LAMBDA_MIN) {
226  lambda /= LAMBDA_DOWN;
227  }
228  }
229 
230  // store current values
231 
232  previous.value = value;
233  previous.result = current.result;
234 
235  } else {
236 
237  value = previous.value; // restore value
238 
239  lambda *= LAMBDA_UP;
240 
241  if (lambda > LAMBDA_MAX) {
242  break;
243  }
244 
245  reset();
246 
247  update(fit, __begin, __end, args...);
248  }
249 
250  DEBUG("Hesse matrix:" << endl << V << endl);
251 
252  // force definite positiveness
253 
254  for (size_t i = 0; i != N; ++i) {
255 
256  if (V(i,i) < PIVOT) {
257  V(i,i) = PIVOT;
258  }
259 
260  h[i] = 1.0 / sqrt(V(i,i));
261  }
262 
263  // normalisation
264 
265  for (size_t row = 0; row != N; ++row) {
266  for (size_t col = 0; col != row; ++col) {
267  V(row,col) *= h[row] * h[col];
268  V(col,row) = V(row,col);
269  }
270  }
271 
272  for (size_t i = 0; i != N; ++i) {
273  V(i,i) = 1.0 + lambda;
274  }
275 
276  // solve A x = b
277 
278  for (size_t col = 0; col != N; ++col) {
279  x[col] = h[col] * get(current.result.gradient, parameters[col]);
280  }
281 
282  try {
283  V.solve(x);
284  }
285  catch (const exception& error) {
286 
287  ERROR("JGandalf: " << error.what() << endl << V << endl);
288 
289  break;
290  }
291 
292  // update value
293 
294  for (size_t row = 0; row != N; ++row) {
295 
296  DEBUG("u[" << noshowpos << setw(3) << row << "] = " << showpos << FIXED(15,5) << get(value, parameters[row]));
297 
298  get(value, parameters[row]) -= h[row] * x[row];
299 
300  DEBUG(" -> " << FIXED(15,5) << get(value, parameters[row]) << noshowpos << endl);
301  }
302 
303  model(value);
304  }
305 
306  // abnormal end
307 
308  const result_type result = previous.result;
309 
310  value = previous.value; // restore value
311 
312  reset();
313 
314  update(fit, __begin, __end, args...);
315 
316  try {
317  V.invert();
318  }
319  catch (const exception& error) {}
320 
321  for (size_t i = 0; i != N; ++i) {
322  get(error, parameters[i]) = sqrt(V(i,i));
323  }
324 
325  return result;
326  }
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
double lambda
control parameter
Definition: JGandalf.hh:340
static double LAMBDA_MIN
minimal value control parameter
Definition: JGandalf.hh:332
struct JFIT::JGandalf::@12 current
void reset()
Reset current parameters.
Definition: JGandalf.hh:349
static double LAMBDA_DOWN
multiplication factor control parameter
Definition: JGandalf.hh:335
std::vector< parameter_type > parameters
fit parameters
Definition: JGandalf.hh:338
static double LAMBDA_UP
multiplication factor control parameter
Definition: JGandalf.hh:334
int numberOfIterations
number of iterations
Definition: JGandalf.hh:339
static bool EPSILON_ABSOLUTE
set epsilon to absolute difference instead of relative
Definition: JGandalf.hh:331
std::vector< double > h
Definition: JGandalf.hh:482
static double get(const JModel_t &model, double JModel_t::*parameter)
Read/write access to parameter value by data member.
Definition: JGandalf.hh:412
static int MAXIMUM_ITERATIONS
maximal number of iterations
Definition: JGandalf.hh:329
static double PIVOT
minimal value diagonal element of Hesse matrix
Definition: JGandalf.hh:336
void update(const JFunction_t &fit, T __begin, T __end, Args ...args)
Recursive method to update current parameters.
Definition: JGandalf.hh:369
static double EPSILON
maximal distance to minimum
Definition: JGandalf.hh:330
JMATH::JMatrixNS V
Hesse matrix.
Definition: JGandalf.hh:343
static double LAMBDA_MAX
maximal value control parameter
Definition: JGandalf.hh:333
struct JFIT::JGandalf::@13 previous
void model(JModel_t &value)
Auxiliary function to constrain model during fit.
Definition: JGandalf.hh:56
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:446
void solve(JVectorND_t &u)
Get solution of equation A x = b.
Definition: JMatrixNS.hh:308
void invert()
Invert matrix according LDU decomposition.
Definition: JMatrixNS.hh:75

◆ reset()

template<class JModel_t >
void JFIT::JGandalf< JModel_t >::reset ( )
inlineprivateinherited

Reset current parameters.

Definition at line 349 of file JGandalf.hh.

350  {
351  using namespace JPP;
352 
353  current.result.chi2 = 0.0;
354  current.result.gradient = zero;
355 
356  V.reset();
357  }
JMatrixND & reset()
Set matrix to the null matrix.
Definition: JMatrixND.hh:459

◆ update() [1/2]

template<class JModel_t >
template<class JFunction_t , class T , class ... Args>
void JFIT::JGandalf< JModel_t >::update ( const JFunction_t &  fit,
__begin,
__end,
Args ...  args 
)
inlineprivateinherited

Recursive method to update current parameters.

Parameters
fitfit function
__beginbegin of data
__endend of data
argsoptional data

Definition at line 369 of file JGandalf.hh.

370  {
371  for (T i = __begin; i != __end; ++i) {
372 
373  const result_type& result = fit(value, *i);
374 
375  current.result.chi2 += result.chi2;
376  current.result.gradient += result.gradient;
377 
378  for (size_t row = 0; row != parameters.size(); ++row) {
379  for (size_t col = row; col != parameters.size(); ++col) {
380  V(row,col) += get(result.gradient, parameters[row]) * get(result.gradient, parameters[col]);
381  }
382  }
383  }
384 
385  update(fit, args...);
386  }

◆ update() [2/2]

template<class JModel_t >
template<class JFunction_t >
void JFIT::JGandalf< JModel_t >::update ( const JFunction_t &  fit)
inlineprivateinherited

Termination method to update current parameters.

Parameters
fitfit function

Definition at line 395 of file JGandalf.hh.

396  {
397  for (size_t row = 0; row != parameters.size(); ++row) {
398  for (size_t col = 0; col != row; ++col) {
399  V(row,col) = V(col,row);
400  }
401  }
402  }

◆ get() [1/6]

template<class JModel_t >
static double JFIT::JGandalf< JModel_t >::get ( const JModel_t model,
double JModel_t::*  parameter 
)
inlinestaticprivateinherited

Read/write access to parameter value by data member.

Parameters
modelmodel
parameterparameter
Returns
value

Definition at line 412 of file JGandalf.hh.

413  {
414  return model.*parameter;
415  }

◆ get() [2/6]

template<class JModel_t >
static double& JFIT::JGandalf< JModel_t >::get ( JModel_t model,
double JModel_t::*  parameter 
)
inlinestaticprivateinherited

Read/write access to parameter value by data member.

Parameters
modelmodel
parameterparameter
Returns
value

Definition at line 425 of file JGandalf.hh.

426  {
427  return model.*parameter;
428  }

◆ get() [3/6]

template<class JModel_t >
static double JFIT::JGandalf< JModel_t >::get ( const JModel_t model,
const size_t  index 
)
inlinestaticprivateinherited

Read/write access to parameter value by index.

Parameters
modelmodel
indexindex
Returns
value

Definition at line 438 of file JGandalf.hh.

439  {
440  return model[index];
441  }

◆ get() [4/6]

template<class JModel_t >
static double& JFIT::JGandalf< JModel_t >::get ( JModel_t model,
const size_t  index 
)
inlinestaticprivateinherited

Read/write access to parameter value by index.

Parameters
modelmodel
indexindex
Returns
value

Definition at line 451 of file JGandalf.hh.

452  {
453  return model[index];
454  }

◆ get() [5/6]

template<class JModel_t >
static double JFIT::JGandalf< JModel_t >::get ( const JModel_t model,
const int  index 
)
inlinestaticprivateinherited

Read/write access to parameter value by index.

Parameters
modelmodel
indexindex
Returns
value

Definition at line 464 of file JGandalf.hh.

465  {
466  return model[index];
467  }

◆ get() [6/6]

template<class JModel_t >
static double& JFIT::JGandalf< JModel_t >::get ( JModel_t model,
const int  index 
)
inlinestaticprivateinherited

Read/write access to parameter value by index.

Parameters
modelmodel
indexindex
Returns
value

Definition at line 477 of file JGandalf.hh.

478  {
479  return model[index];
480  }

◆ getPDF()

const JPDFs_t& JFIT::JRegressorStorage< JLine3Z, JGandalf >::getPDF ( ) const
inlineinherited

Get PDFs.

Returns
PDFs

Definition at line 172 of file JRegressorHelper.hh.

173  {
174  return _pdf;
175  }

◆ getNPE()

const JNPEs_t& JFIT::JRegressorStorage< JLine3Z, JGandalf >::getNPE ( ) const
inlineinherited

Get NPEs.

Returns
NPEs

Definition at line 183 of file JRegressorHelper.hh.

184  {
185  return _npe;
186  }

◆ transform()

void JFIT::JRegressorStorage< JLine3Z, JGandalf >::transform ( const transformer_type transformer)
inlineinherited

Transform PDFs and NPEs.

Parameters
transformertransformer

Definition at line 194 of file JRegressorHelper.hh.

195  {
196  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
197  _pdf[i].transform(transformer);
198  _npe[i].transform(transformer);
199  }
200  }

◆ setRmax()

void JFIT::JRegressorStorage< JLine3Z, JGandalf >::setRmax ( const double  Rmax)
inlineinherited

Set maximal road width of PDF.

Parameters
Rmaxroad width [m]

Definition at line 208 of file JRegressorHelper.hh.

209  {
211 
212  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
213  if (!_pdf[i].empty()) {
214  _pdf[i].compress(range);
215  }
216  }
217  }
Range of values.
Definition: JRange.hh:42

Member Data Documentation

◆ T_ns

Time window with respect to Cherenkov hypothesis [ns].

Default values.

Definition at line 439 of file JLine3ZRegressor.hh.

◆ Vmax_npe

double JFIT::JRegressor< JLine3Z, JGandalf >::Vmax_npe = std::numeric_limits<double>::max()
static

Maximal integral of PDF [npe].

Definition at line 440 of file JLine3ZRegressor.hh.

◆ Rmin_m

double JFIT::JRegressor< JLine3Z, JGandalf >::Rmin_m = 0.1
static

Minimal distance of [m].

Definition at line 441 of file JLine3ZRegressor.hh.

◆ pdf

PDF.

Definition at line 443 of file JLine3ZRegressor.hh.

◆ npe

PDF.

Definition at line 444 of file JLine3ZRegressor.hh.

◆ E_GeV

double JFIT::JRegressor< JLine3Z, JGandalf >::E_GeV = 0.0

Energy of muon at vertex [GeV].

Definition at line 446 of file JLine3ZRegressor.hh.

◆ estimator

M-Estimator function.

Definition at line 448 of file JLine3ZRegressor.hh.

◆ MAXIMUM_ITERATIONS

template<class JModel_t >
int JFIT::JGandalf< JModel_t >::MAXIMUM_ITERATIONS = 1000
staticinherited

maximal number of iterations

maximal number of iterations.

Definition at line 329 of file JGandalf.hh.

◆ EPSILON

template<class JModel_t >
double JFIT::JGandalf< JModel_t >::EPSILON = 1.0e-3
staticinherited

maximal distance to minimum

maximal distance to minimum.

Definition at line 330 of file JGandalf.hh.

◆ EPSILON_ABSOLUTE

template<class JModel_t >
bool JFIT::JGandalf< JModel_t >::EPSILON_ABSOLUTE = false
staticinherited

set epsilon to absolute difference instead of relative

set epsilon to absolute difference instead of relative.

Definition at line 331 of file JGandalf.hh.

◆ LAMBDA_MIN

template<class JModel_t >
double JFIT::JGandalf< JModel_t >::LAMBDA_MIN = 0.01
staticinherited

minimal value control parameter

Definition at line 332 of file JGandalf.hh.

◆ LAMBDA_MAX

template<class JModel_t >
double JFIT::JGandalf< JModel_t >::LAMBDA_MAX = 100.0
staticinherited

maximal value control parameter

Definition at line 333 of file JGandalf.hh.

◆ LAMBDA_UP

template<class JModel_t >
double JFIT::JGandalf< JModel_t >::LAMBDA_UP = 10.0
staticinherited

multiplication factor control parameter

Definition at line 334 of file JGandalf.hh.

◆ LAMBDA_DOWN

template<class JModel_t >
double JFIT::JGandalf< JModel_t >::LAMBDA_DOWN = 10.0
staticinherited

multiplication factor control parameter

Definition at line 335 of file JGandalf.hh.

◆ PIVOT

template<class JModel_t >
double JFIT::JGandalf< JModel_t >::PIVOT = std::numeric_limits<double>::epsilon()
staticinherited

minimal value diagonal element of Hesse matrix

minimal value diagonal element of matrix

Definition at line 336 of file JGandalf.hh.

◆ parameters

template<class JModel_t >
std::vector<parameter_type> JFIT::JGandalf< JModel_t >::parameters
inherited

fit parameters

Definition at line 338 of file JGandalf.hh.

◆ numberOfIterations

template<class JModel_t >
int JFIT::JGandalf< JModel_t >::numberOfIterations
inherited

number of iterations

Definition at line 339 of file JGandalf.hh.

◆ lambda

template<class JModel_t >
double JFIT::JGandalf< JModel_t >::lambda
inherited

control parameter

Definition at line 340 of file JGandalf.hh.

◆ value

template<class JModel_t >
JModel_t JFIT::JGandalf< JModel_t >::value
inherited

value

Definition at line 341 of file JGandalf.hh.

◆ error

template<class JModel_t >
JModel_t JFIT::JGandalf< JModel_t >::error
inherited

error

Definition at line 342 of file JGandalf.hh.

◆ V

template<class JModel_t >
JMATH::JMatrixNS JFIT::JGandalf< JModel_t >::V
inherited

Hesse matrix.

Definition at line 343 of file JGandalf.hh.

◆ h

template<class JModel_t >
std::vector<double> JFIT::JGandalf< JModel_t >::h
privateinherited

Definition at line 482 of file JGandalf.hh.

◆ x

template<class JModel_t >
JMATH::JVectorND JFIT::JGandalf< JModel_t >::x
privateinherited

Definition at line 483 of file JGandalf.hh.

◆ result

template<class JModel_t >
result_type JFIT::JGandalf< JModel_t >::result
inherited

Definition at line 486 of file JGandalf.hh.

◆ 

struct { ... } JFIT::JGandalf< JModel_t >::current

◆ 

struct { ... } JFIT::JGandalf< JModel_t >::previous

◆ debug

template<class T >
int JEEP::JMessage< T >::debug = 0
staticinherited

debug level (default is off).

Definition at line 45 of file JMessage.hh.

◆ _pdf

JPDFs_t JFIT::JRegressorStorage< JLine3Z, JGandalf >::_pdf
privateinherited

PDFs.

Definition at line 221 of file JRegressorHelper.hh.

◆ _npe

JNPEs_t JFIT::JRegressorStorage< JLine3Z, JGandalf >::_npe
privateinherited

NPEs.

Definition at line 222 of file JRegressorHelper.hh.

◆ NUMBER_OF_PDFS

const int JFIT::JRegressorHelper< JLine3Z, JGandalf >::NUMBER_OF_PDFS = 6
staticinherited

Number of PDFs.

Definition at line 70 of file JRegressorHelper.hh.

◆ pdf_t

const JPDFType_t JFIT::JRegressorHelper< JLine3Z, JGandalf >::pdf_t
staticinherited
Initial value:
@ SCATTERED_LIGHT_FROM_DELTARAYS
scattered light from delta-rays
Definition: JPDFTypes.hh:33
@ DIRECT_LIGHT_FROM_EMSHOWERS
direct light from EM showers
Definition: JPDFTypes.hh:29
@ SCATTERED_LIGHT_FROM_EMSHOWERS
scattered light from EM showers
Definition: JPDFTypes.hh:30
@ SCATTERED_LIGHT_FROM_MUON
scattered light from muon
Definition: JPDFTypes.hh:27
@ DIRECT_LIGHT_FROM_DELTARAYS
direct light from delta-rays
Definition: JPDFTypes.hh:32
@ DIRECT_LIGHT_FROM_MUON
direct light from muon
Definition: JPDFTypes.hh:26

PDF types.

Definition at line 79 of file JRegressorHelper.hh.


The documentation for this struct was generated from the following file: