1#ifndef __JFIT__JFITTOOLKIT__
2#define __JFIT__JFITTOOLKIT__
6#include "JPhysics/JK40Rates.hh"
8#include "JMath/JMath.hh"
9#include "JMath/JMathSupportkit.hh"
26namespace JPP {
using namespace JFIT; }
30 using JPHYSICS::JK40Rates;
41 inline double getP(
const double expval,
bool hit)
44 return -expm1(-expval);
69 inline double getChi2(
const double expval,
bool hit)
72 return -log1p(-exp(-expval));
92 template<
class JModel_t,
class JHit_t>
93 inline double getChi2(
const JModel_t&
model,
const JHit_t& hit,
const double sigma)
95 const double ds = (hit.getT() -
model.getT(hit)) / sigma;
117 template<
class JModel_t,
class T>
118 inline double getChi2(
const JModel_t&
model, T __begin, T __end,
const double sigma)
122 for (T hit = __begin; hit != __end; ++hit) {
159 const JVectorNZ Y(track, __begin, __end);
176 inline double getChi2(
const JLine1Z& track, T __begin, T __end,
const double alpha,
const double sigma)
178 JMatrixNZ V(track, __begin, __end, alpha, sigma);
182 return getChi2(track, __begin, __end, V);
200 for (
size_t j = 0; j != V.size(); ++j) {
201 chi2 += V(i,j) * Y[j];
204 return chi2*chi2 / V(i,i);
226 template<
class JModel_t,
class JFit_t,
class T>
227 inline double getChi2(
const JModel_t&
model,
const JFit_t& fit, T __begin, T __end)
231 for (T hit = __begin; hit != __end; ++hit) {
232 chi2 += fit(
model, *hit);
250 const JK40Rates& R_Hz,
256 return (M == 0 ? 1.0 : 0.0);
259 const double T = T_ns * 1.0e-9;
260 const double p = -expm1(-R_Hz.getSinglesRate() * N * T);
264 for (multiplicity_type i = R_Hz.getLowerL1Multiplicity(); i <= R_Hz.getUpperL1Multiplicity(); ++i) {
265 P -= expm1(-R_Hz.getMultiplesRate(i) * T);
270 return (poisson(M, R_Hz.getSinglesRate() * N * T) +
271 (M >= 2 ? -expm1(-R_Hz.getMultiplesRate(M) * T) : 0.0) +
272 (M >= 3 ? -expm1(-R_Hz.getMultiplesRate(M-1) * T) : 0.0) * p) / (1.0 + P);
Data structure for fit of straight line paralel to z-axis.
Determination of the co-variance matrix of hits for a track along z-axis (JFIT::JLine1Z).
static double getDot(const variance &first, const variance &second)
Get dot product.
Determination of the time residual vector of hits for a track along z-axis (JFIT::JLine1Z).
Auxiliary classes and methods for linear and iterative data regression.
double getProbability(const size_t N, const size_t M, const JK40Rates &R_Hz, const double T_ns)
Get probability due to random background.
double getChi2(const double P)
Get chi2 corresponding to given probability.
double getP(const double expval, bool hit)
Get Poisson probability to observe a hit or not for given expectation value for the number of hits.
void model(JModel_t &value)
Auxiliary function to constrain model during fit.