1#ifndef __JFIT__JSHOWER3EZREGRESSOR__
2#define __JFIT__JSHOWER3EZREGRESSOR__
6#include "JPhysics/JPDFTypes.hh"
7#include "JPhysics/JPDFTable.hh"
8#include "JPhysics/JPDFToolkit.hh"
9#include "JPhysics/JNPETable.hh"
11#include "JTools/JFunction1D_t.hh"
12#include "JTools/JFunctionalMap_t.hh"
13#include "JPhysics/JConstants.hh"
14#include "JTools/JRange.hh"
15#include "JTools/JResult.hh"
16#include "JTools/JFunction1D_t.hh"
17#include "JTools/JFunctionalMap_t.hh"
18#include "JTools/JAbstractHistogram.hh"
20#include "JGeometry3D/JVector3D.hh"
21#include "JGeometry3D/JVersor3D.hh"
22#include "JGeometry3D/JDirection3D.hh"
24#include "JMath/JZero.hh"
36#include "Jeep/JMessage.hh"
47 using JPHYSICS::JPDFType_t;
48 using JPHYSICS::DIRECT_LIGHT_FROM_EMSHOWER;
49 using JPHYSICS::SCATTERED_LIGHT_FROM_EMSHOWER;
50 using JTOOLS::get_value;
60 const double epsilon = 1.0e-6;
61 const JTOOLS::JRange<double> range(epsilon, JMATH::PI - epsilon);
63 return range.constrain(fabs(angle));
77 double Tx = value.getDX();
78 double Ty = value.getDY();
79 double E = max(0.0,value.
getE());
80 const double u = hypot(Tx, Ty);
98 typedef JTOOLS::JMapList<JTOOLS::JPolint0FunctionalMap,
99 JTOOLS::JMapList<JTOOLS::JPolint0FunctionalMap,
100 JTOOLS::JMapList<JTOOLS::JPolint0FunctionalGridMap,
102 typedef JPHYSICS::JPDFTable<JFunction1D_t, JPDFMaplist_t>
JPDF_t;
104 typedef JTOOLS::JMapList<JTOOLS::JPolint0FunctionalMap,
105 JTOOLS::JMapList<JTOOLS::JPolint0FunctionalMap,
106 JTOOLS::JMapList<JTOOLS::JPolint0FunctionalGridMap,
108 typedef JPHYSICS::JNPETable<double, double, JNPEMaplist_t>
JNPE_t;
111 static const int NUMBER_OF_PDFS = 2;
113 typedef std::array<JNPE_t, NUMBER_OF_PDFS>
JNPEs_t;
137 const JPDF_t::JSupervisor supervisor(
new JPDF_t::JDefaultResult(JMATH::zero));
139 for (
int i = 0; i != NUMBER_OF_PDFS; ++i) {
141 const string file_name = getFilename(fileDescriptor, pdf_t[i]);
144 _pdf.load(file_name.c_str());
146 _pdf.setExceptionHandler(supervisor);
148 _npe[ i ] =
JNPE_t(_pdf, T_ns);
151 for (
int i = 1; i < NUMBER_OF_PDFS; i += 2) {
153 _npe[ i ].add(_npe[i-1]);
157 _npe[i-1].swap(buffer);
176 static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
187 DIRECT_LIGHT_FROM_EMSHOWER,
188 SCATTERED_LIGHT_FROM_EMSHOWER
221 JRegressor(
const std::string& fileDescriptor,
const JTimeRange& T_ns) :
233 npe(storage.getNPE()),
252 JPosition3D D(pmt.getPosition());
253 JDirection3D U(pmt.getDirection());
255 D.sub(shower.getPosition());
257 const double z = D.getDot(shower.getDirection());
258 const double x = D.getX();
259 const double y = D.getY();
260 const double cd = z/D.getLength();
262 U.rotate(JRotation3Z(-atan2(y,x)));
267 JNPE_t::result_type H0 = getH0(pmt.
getR());
268 JNPE_t::result_type H1 = getH1(D.getLength(), cd, theta, phi, shower.
getE());
270 if (get_value(H1) >= Vmax_npe) {
271 H1 *= Vmax_npe / get_value(H1);
276 const bool hit = pmt.
getN() != 0;
277 const double u =
getChi2(get_value(H1), hit) -
getChi2(get_value(H0), hit);
279 return estimator->getRho(u);
288 JNPE_t::result_type
getH0(
const double R_Hz)
const
290 return JNPE_t::result_type(R_Hz * 1e-9 * T_ns.getLength());
303 JNPE_t::result_type
getH1(
const double D,
307 const double E)
const
309 JNPE_t::result_type h1 = JMATH::zero;
311 for (
int i = 0; i != NUMBER_OF_PDFS; ++i) {
313 if (!npe[i].empty() && D <= npe[i].getXmax()) {
317 JNPE_t::result_type y1 = E * npe[i](std::max(D, npe[i].getXmin()), cd, theta, phi);
328 catch(JLANG::JException& error) {
329 ERROR(error << std::endl);
352 typedef JTOOLS::JMapList<JTOOLS::JPolint0FunctionalMap,
353 JTOOLS::JMapList<JTOOLS::JPolint0FunctionalMap,
354 JTOOLS::JMapList<JTOOLS::JPolint0FunctionalGridMap,
356 typedef JPHYSICS::JPDFTable<JFunction1D_t, JPDFMaplist_t>
JPDF_t;
358 typedef JTOOLS::JMapList<JTOOLS::JPolint1FunctionalMap,
359 JTOOLS::JMapList<JTOOLS::JPolint1FunctionalMapH,
360 JTOOLS::JMapList<JTOOLS::JPolint1FunctionalGridMap,
362 typedef JPHYSICS::JNPETable<double, double, JNPEMaplist_t>
JNPE_t;
365 static const int NUMBER_OF_PDFS = 2;
367 typedef std::array<JNPE_t, NUMBER_OF_PDFS>
JNPEs_t;
392 const JPDF_t::JSupervisor supervisor(
new JPDF_t::JDefaultResult(JMATH::zero));
394 for (
int i = 0; i != NUMBER_OF_PDFS; ++i) {
396 const string file_name = getFilename(fileDescriptor, pdf_t[i]);
399 _pdf.load(file_name.c_str());
401 _pdf.setExceptionHandler(supervisor);
403 _npe[i] =
JNPE_t(_pdf, T_ns);
408 for (
int i = 1; i < NUMBER_OF_PDFS; i += 2) {
410 _npe[ i ].add(_npe[i-1]);
414 _npe[i-1].swap(buffer);
432 static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
443 DIRECT_LIGHT_FROM_EMSHOWER,
444 SCATTERED_LIGHT_FROM_EMSHOWER
477 JRegressor(
const std::string& fileDescriptor,
const JTimeRange& T_ns) :
489 npe(storage.getNPE()),
509 JPosition3D D(pmt.getPosition());
510 JDirection3D U(pmt.getDirection());
512 D.sub(shower.getPosition());
514 const double x = D.getX();
515 const double y = D.getY();
516 const double d = D.getLength();
517 const double cd = D.getDot(shower.getDirection())/d;
519 U.rotate(JRotation3Z(-atan2(y,x)));
524 JNPE_t::result_type H0 = getH0(pmt.
getR());
525 JNPE_t::result_type H1 = getH1(d, cd, theta, phi, shower.
getE());
527 if (get_value(H1) >= Vmax_npe) {
528 H1 *= Vmax_npe / get_value(H1);
531 double signal_npe = get_value(H1);
535 double expectation = get_value(H1);
537 const bool hit = pmt.
getN() != 0;
538 const double u = H1.getChi2(hit) - H0.getChi2(hit);
542 result.
chi2 = estimator->getRho(u);
544 double energy_gradient = signal_npe/shower.
getE();
545 if(hit) energy_gradient *= -exp(-expectation)/(1-exp(-expectation));
555 result.
gradient.mul(estimator->getPsi(u));
556 static_cast<JShower3Z&
>(result.
gradient).mul(H1.getDerivativeOfChi2(hit) - H0.getDerivativeOfChi2(hit));
567 JNPE_t::result_type
getH0(
const double R_Hz)
const
569 return JNPE_t::result_type(R_Hz * 1e-9 * T_ns.getLength(), 0.0);
582 JNPE_t::result_type
getH1(
const double D,
586 const double E)
const
588 JNPE_t::result_type h1 = JMATH::zero;
590 for (
int i = 0; i != NUMBER_OF_PDFS; ++i) {
592 if (!npe[i].empty() && D <= npe[i].getXmax()) {
596 JNPE_t::result_type y1 = E * npe[i](std::max(D, npe[i].getXmin()), cd, theta, phi);
598 if (get_value(y1) > 0.0) {
603 catch(JLANG::JException& error) {
604 ERROR(error << std::endl);
629 typedef JTOOLS::JMapList<JTOOLS::JPolint0FunctionalMap,
630 JTOOLS::JMapList<JTOOLS::JPolint0FunctionalMap,
631 JTOOLS::JMapList<JTOOLS::JPolint0FunctionalGridMap,
633 typedef JPHYSICS::JPDFTable<JFunction1D_t, JPDFMaplist_t>
JPDF_t;
635 typedef JTOOLS::JMapList<JTOOLS::JPolint0FunctionalMap,
636 JTOOLS::JMapList<JTOOLS::JPolint0FunctionalMap,
637 JTOOLS::JMapList<JTOOLS::JPolint0FunctionalGridMap,
639 typedef JPHYSICS::JNPETable<double, double, JNPEMaplist_t>
JNPE_t;
642 static const int NUMBER_OF_PDFS = 2;
644 typedef std::array<JNPE_t, NUMBER_OF_PDFS>
JNPEs_t;
669 const JPDF_t::JSupervisor supervisor(
new JPDF_t::JDefaultResult(JMATH::zero));
671 for (
int i = 0; i != NUMBER_OF_PDFS; ++i) {
673 const string file_name = getFilename(fileDescriptor, pdf_t[i]);
676 _pdf.load(file_name.c_str());
678 _pdf.setExceptionHandler(supervisor);
680 _npe[i] =
JNPE_t(_pdf, T_ns);
685 for (
int i = 1; i < NUMBER_OF_PDFS; i += 2) {
687 _npe[i].add(_npe[i-1]);
691 _npe[i-1].swap(buffer);
710 static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
721 DIRECT_LIGHT_FROM_EMSHOWER,
722 SCATTERED_LIGHT_FROM_EMSHOWER
756 JRegressor(
const std::string& fileDescriptor,
const JTimeRange& T_ns) :
768 npe(storage.getNPE()),
786 JPosition3D D(pmt.getPosition());
787 JDirection3D U(pmt.getDirection());
789 D.sub(shower.getPosition());
791 const double z = D.getDot(shower.getDirection());
792 const double x = D.getX();
793 const double y = D.getY();
794 const double cd = z/D.getLength();
796 U.rotate(JRotation3Z(-atan2(y,x)));
801 JNPE_t::result_type H0 = getH0(pmt.
getR());
802 JNPE_t::result_type H1 = getH1(D.getLength(), cd, theta, phi, shower.
getE());
804 if (get_value(H1) >= Vmax_npe) {
805 H1 *= Vmax_npe / get_value(H1);
810 const bool hit = pmt.
getN() != 0;
811 const double u =
getChi2(get_value(H1), hit) -
getChi2(get_value(H0), hit);
813 return estimator->getRho(u);
822 JNPE_t::result_type
getH0(
const double R_Hz)
const
824 return JNPE_t::result_type(R_Hz * 1e-9 * T_ns.getLength());
837 JNPE_t::result_type
getH1(
const double D,
841 const double E)
const
843 JNPE_t::result_type h1 = JMATH::zero;
845 for (
int i = 0; i != NUMBER_OF_PDFS; ++i) {
847 if (!npe[i].empty() && D <= npe[i].getXmax()) {
851 JNPE_t::result_type y1 = E * npe[i](std::max(D, npe[i].getXmin()), cd, theta, phi);
862 catch(JLANG::JException& error) {
863 ERROR(error << std::endl);
882 JPosition3D D(pmt.getPosition());
883 JDirection3D U(pmt.getDirection());
886 const double z = D.getDot(shower.getDirection());
887 const double x = D.getX();
888 const double y = D.getY();
889 const double cd = z/D.getLength();
891 U.rotate(JRotation3Z(-atan2(y,x)));
896 JNPE_t::result_type H1 = getH1(D.getLength(), cd, theta, phi, 1.0);
898 if (get_value(H1) >= Vmax_npe) {
899 H1 *= Vmax_npe / get_value(H1);
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 fit of straight line in positive z-direction with energy.
double getBy() const
Get bjorken y.
double getE() const
Get E.
Data structure for cascade in positive z-direction.
Simple fit method based on Powell's algorithm, see reference: Numerical Recipes in C++,...
Auxiliary classes and methods for linear and iterative data regression.
double getPMTAngle(const double angle)
Constrain PMT angle to [0,pi].
double getChi2(const double P)
Get chi2 corresponding to given probability.
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
Auxiliary class for handling PMT geometry, rate and response.
int getN() const
Get number of hits.
double getR() const
Get rate.
Template specialisation for storage of PDF tables.
JPHYSICS::JPDFTable< JFunction1D_t, JPDFMaplist_t > JPDF_t
JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
JTOOLS::JMapList< JTOOLS::JPolint0FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap > > > > JPDFMaplist_t
JPHYSICS::JNPETable< double, double, JNPEMaplist_t > JNPE_t
JRegressorStorage()
Default constructor.
const JNPEs_t & getNPE() const
Get NPEs.
std::array< JNPE_t, NUMBER_OF_PDFS > JNPEs_t
NPEs.
JTOOLS::JPolint1Function1D_t JFunction1D_t
JTOOLS::JMapList< JTOOLS::JPolint0FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap > > > > JNPEMaplist_t
JRegressorStorage(const std::string &fileDescriptor, const JTimeRange &T_ns)
Parameterized constructor.
Template specialisation for storage of PDF tables.
JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
JPHYSICS::JPDFTable< JFunction1D_t, JPDFMaplist_t > JPDF_t
JPHYSICS::JNPETable< double, double, JNPEMaplist_t > JNPE_t
std::array< JNPE_t, NUMBER_OF_PDFS > JNPEs_t
NPEs.
JTOOLS::JPolint1Function1D_t JFunction1D_t
JTOOLS::JMapList< JTOOLS::JPolint0FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap > > > > JPDFMaplist_t
JRegressorStorage(const std::string &fileDescriptor, const JTimeRange &T_ns)
Parameterized constructor.
JTOOLS::JMapList< JTOOLS::JPolint1FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint1FunctionalMapH, JTOOLS::JMapList< JTOOLS::JPolint1FunctionalGridMap, JTOOLS::JMapList< JTOOLS::JPolint1FunctionalGridMap > > > > JNPEMaplist_t
const JNPEs_t & getNPE() const
Get NPEs.
JRegressorStorage()
Default constructor.
Template specialisation for storage of PDF tables.
JTOOLS::JMapList< JTOOLS::JPolint0FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap > > > > JNPEMaplist_t
JPHYSICS::JPDFTable< JFunction1D_t, JPDFMaplist_t > JPDF_t
const JNPEs_t & getNPE() const
Get NPEs.
std::array< JNPE_t, NUMBER_OF_PDFS > JNPEs_t
NPEs.
JPHYSICS::JNPETable< double, double, JNPEMaplist_t > JNPE_t
JRegressorStorage()
Default constructor.
JTOOLS::JPolint1Function1D_t JFunction1D_t
JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
JTOOLS::JMapList< JTOOLS::JPolint0FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap > > > > JPDFMaplist_t
JRegressorStorage(const std::string &fileDescriptor, const JTimeRange &T_ns)
Constructor.
Template data structure for storage of internal data.
JRegressor()
Default constructor.
JNPE_t::result_type getH1(const double D, const double cd, const double theta, const double phi, const double E) const
Get signal hypothesis value for time integrated PDF.
static double Vmax_npe
Maximal integral of PDF [npe].
double operator()(const JShower3EZ &shower, const JPMTW0 &pmt) const
Fit function.
JRegressor(const std::string &fileDescriptor, const JTimeRange &T_ns)
Constructor.
JRegressorStorage< JShower3EZ, JAbstractMinimiser > storage_type
JNPE_t::result_type getH1(const JShower3EZ &shower, const JPMTW0 &pmt) const
Get signal hypothesis value for time integrated PDF.
JNPE_t::result_type getH0(const double R_Hz) const
Get background hypothesis value for time integrated PDF.
std::shared_ptr< JMEstimator > estimator
M-Estimator function
JRegressor(const storage_type &storage)
Constructor.
static double Vmax_npe
Maximal integral of PDF [npe].
JRegressor()
Default constructor.
JRegressor(const std::string &fileDescriptor, const JTimeRange &T_ns)
Constructor.
result_type operator()(const JShower3EZ &shower, const JPMTW0 &pmt) const
Fit function.
JNPE_t::result_type getH0(const double R_Hz) const
Get background hypothesis value for time integrated PDF.
JRegressorStorage< JShower3EZ, JGandalf > storage_type
JRegressor(const storage_type &storage)
Constructor.
JNPE_t::result_type getH1(const double D, const double cd, const double theta, const double phi, const double E) const
Get signal hypothesis value for time integrated PDF.
std::shared_ptr< JMEstimator > estimator
M-Estimator function.
JRegressor(const std::string &fileDescriptor, const JTimeRange &T_ns)
Constructor.
std::shared_ptr< JMEstimator > estimator
M-Estimator function.
static double Vmax_npe
Maximal integral of PDF [npe].
JNPE_t::result_type getH0(const double R_Hz) const
Get background hypothesis value for time integrated PDF.
JNPE_t::result_type getH1(const double D, const double cd, const double theta, const double phi, const double E) const
Get signal hypothesis value for time integrated PDF.
JRegressor()
Default constructor.
double operator()(const JShower3EZ &shower, const JPMTW0 &pmt) const
Fit function.
JRegressorStorage< JShower3EZ, JSimplex > storage_type
JRegressor(const storage_type &storage)
Constructor.
Template definition of a data regressor of given model.