1#ifndef __JFIT__JSHOWERBRIGHTPOINTREGRESSOR__
2#define __JFIT__JSHOWERBRIGHTPOINTREGRESSOR__
6#include "JPhysics/JPDFTypes.hh"
7#include "JPhysics/JPDFTable.hh"
8#include "JPhysics/JPDFToolkit.hh"
9#include "JPhysics/JNPETable.hh"
10#include "JPhysics/JConstants.hh"
12#include "JTools/JResult.hh"
14#include "JMath/JZero.hh"
23#include "Jeep/JMessage.hh"
33namespace JPP {
using namespace JFIT; }
37 using JPHYSICS::JPDFType_t;
38 using JPHYSICS::DIRECT_LIGHT_FROM_BRIGHT_POINT;
39 using JPHYSICS::SCATTERED_LIGHT_FROM_BRIGHT_POINT;
40 using JTOOLS::get_value;
51 double E = max(0.0,value.
getE());
62 typedef JTOOLS::JMAPLIST<JTOOLS::JPolint2FunctionalMap,
64 typedef JPHYSICS::JPDFTable<JFunction1D_t, JPDFMapList_t>
JPDF_t;
66 static const int NUMBER_OF_PDFS = 2;
68 typedef std::array<JPDF_t, NUMBER_OF_PDFS>
JPDFs_t;
91 const JTimeRange& T_ns,
93 const int numberOfPoints = 25,
94 const double epsilon = 1.0e-10) :
101 const JPDF_t::JSupervisor supervisor(
new JPDF_t::JDefaultResult(JMATH::zero));
103 for (
int i = 0; i != NUMBER_OF_PDFS; ++i) {
105 const string file_name = getFilename(fileDescriptor, pdf_t[i]);
107 _pdf[i].load(file_name.c_str());
109 _pdf[i].setExceptionHandler(supervisor);
113 for (
int i = 1; i < NUMBER_OF_PDFS; i += 2) {
115 _pdf[ i ].add(_pdf[i-1]);
119 _pdf[i-1].swap(buffer);
122 _pdf[i].blur(TTS, numberOfPoints, epsilon);
141 static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
152 DIRECT_LIGHT_FROM_BRIGHT_POINT,
153 SCATTERED_LIGHT_FROM_BRIGHT_POINT
192 const JTimeRange& T_ns,
194 const int numberOfPoints = 25,
195 const double epsilon = 1.0e-10) :
196 storage_type(fileDescriptor, T_ns, TTS, numberOfPoints, epsilon),
206 pdf(storage.getPDF())
228 template<
class JHit_t>
233 JPosition3D D(hit.getPosition());
234 JDirection3D U(hit.getDirection());
236 D.sub(vx.getPosition());
237 double length = D.getLength();
238 double ct = U.getDot(D) / length;
240 if (ct > +1.0) { ct = +1.0; }
241 if (ct < -1.0) { ct = -1.0; }
243 const double t = vx.getT() + (length * getIndexOfRefraction() * getInverseSpeedOfLight());
245 const double dt = T_ns.constrain(hit.getT() - t);
247 JPDF_t::result_type H0 = getH0(hit.getR(), dt);
248 JPDF_t::result_type H1 = getH1(length, ct, dt);
250 if (get_value(H1) >= Vmax_npe) {
251 H1 *= Vmax_npe / get_value(H1);
254 double H1_value = get_value(H1);
259 JPDF_t::result_type HT = H1+H0;
260 double HT_value = get_value(HT);
262 result.
chi2 = HT.getChi2() - H0.getChi2();
264 double exp_V_HT = exp(-HT.V);
266 double energy_gradient = -1 / HT_value;
267 energy_gradient *= (H1_value - HT_value * v_H1) * (1-exp_V_HT) - HT_value * exp_V_HT * V_H1;
268 energy_gradient /= (1-exp_V_HT);
274 -getIndexOfRefraction() * D.getY() / length,
275 -getIndexOfRefraction() * D.getZ() / length),
279 static_cast<JPoint4D&
>(result.
gradient).mul(getInverseSpeedOfLight() * (HT.getDerivativeOfChi2() -
280 H0.getDerivativeOfChi2()));
293 JPDF_t::result_type
getH0(
const double R_Hz,
294 const double t1)
const
298 return JPDF_t::result_type(R_Hz * 1e-9, t1, T_ns);
309 JPDF_t::result_type
getH1(
const double D,
311 const double t)
const
315 JPDF_t::result_type h1 = JMATH::zero;
317 for (
int i = 0; i != NUMBER_OF_PDFS; ++i) {
319 if (!pdf[i].empty() && D <= pdf[i].getXmax()) {
323 JPDF_t::result_type y1 = pdf[i](std::max(D, pdf[i].getXmin()), ct, t);
338 catch(JLANG::JException& error) {
339 ERROR(error << std::endl);
358 for (
int i = 0; i != NUMBER_OF_PDFS; ++i) {
360 if (!pdf[i].empty() && pdf[i].getXmax() > xmax) {
361 xmax = pdf[i].getXmax();
Maximum likelihood estimator (M-estimators).
General purpose data regression method.
Fit method based on the Levenberg-Marquardt method.
Data structure for vertex fit.
Data structure for vertex fit.
double getE() const
Get energy.
Auxiliary classes and methods for linear and iterative data regression.
void model(JModel_t &value)
Auxiliary function to constrain model during fit.
Abstract class for global fit method.
Data structure for return value of fit function.
JModel_t gradient
partial derivatives of chi2
Template specialisation for storage of PDF tables.
JRegressorStorage(const std::string &fileDescriptor, const JTimeRange &T_ns, const double TTS, const int numberOfPoints=25, const double epsilon=1.0e-10)
Parameterized constructor.
JTOOLS::JSplineFunction1S_t JFunction1D_t
const JPDFs_t & getPDF() const
Get PDFs.
JPHYSICS::JPDFTable< JFunction1D_t, JPDFMapList_t > JPDF_t
JRegressorStorage()
Default constructor.
JTOOLS::JMAPLIST< JTOOLS::JPolint2FunctionalMap, JTOOLS::JPolint1FunctionalGridMap >::maplist JPDFMapList_t
JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
std::array< JPDF_t, NUMBER_OF_PDFS > JPDFs_t
PDFs.
Template data structure for storage of internal data.
JPDF_t::result_type getH0(const double R_Hz, const double t1) const
Get background hypothesis value for time differentiated PDF.
double getRmax() const
Get maximal road width of PDF.
static double Vmax_npe
Maximal integral of PDF [npe].
JRegressorStorage< JPoint4E, JGandalf > storage_type
result_type operator()(const JPoint4E &vx, const JHit_t &hit) const
Fit function.
JRegressor(const std::string &fileDescriptor, const JTimeRange &T_ns, const double TTS, const int numberOfPoints=25, const double epsilon=1.0e-10)
Constructor.
JPDF_t::result_type getH1(const double D, const double ct, const double t) const
Get signal hypothesis value per 1 GeV for bright point emission PDF.
JRegressor(const storage_type &storage)
Constructor.
JRegressor()
Default constructor.
Template definition of a data regressor of given model.