Jpp 21.0.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JShowerEnergyRegressor.hh
Go to the documentation of this file.
1#ifndef __JFIT__JSHOWERENERGYREGRESSOR__
2#define __JFIT__JSHOWERENERGYREGRESSOR__
3
4#include <memory>
5
10
12#include "JTools/JResult.hh"
13
14#include "JMath/JZero.hh"
15
17
18#include "JFit/JEnergy.hh"
19#include "JFit/JSimplex.hh"
20#include "JFit/JMEstimator.hh"
21#include "JFit/JRegressor.hh"
22#include "JFit/JFitToolkit.hh"
23#include "JFit/JShowerNPE.hh"
24#include "JFit/JShowerNPEHit.hh"
25#include "JFit/JTimeRange.hh"
26
27#include "Jeep/JMessage.hh"
28
29/**
30 * \file
31 * Data regression method for JFIT::JShower3EZ only focused on the energy estimation from
32 * a bright point emission PDF and considering the hit/non hit information for each PMT.
33 *
34 * \author adomi
35 */
36
37namespace JFIT {}
38namespace JPP { using namespace JFIT; }
39
40namespace JFIT {
41
47
48 /**
49 * Regressor function object for JShower3EZ fit using JSimplex minimiser.
50 */
51 template<>
53 public JAbstractRegressor<JEnergy, JSimplex>
54 {
55 using JAbstractRegressor<JEnergy, JSimplex>::operator();
56
61
63
64 /**
65 * Parameterized constructor
66 *
67 * The PDF file descriptor should contain the wild card character JEEP::FILENAME_WILDCARD which
68 * will be replaced by the corresponding PDF types listed in JRegressor<JEnergy, JSimplex>::pdf_t.
69 *
70 * \param fileDescriptor PDF file descriptor
71 */
72
73 JRegressor(const std::string& fileDescriptor):
74 estimator(new JMEstimatorNull())
75 {
76 using namespace std;
77 using namespace JPP;
78
79
80 const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(JMATH::zero));
81
82 for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
83
84 try {
85
86 JPDF_t pdf;
87
88 const string file_name = getFilename(fileDescriptor, pdf_t[i]);
89
90 NOTICE("loading PDF from file " << file_name << "... " << flush);
91
92 pdf.load(file_name.c_str());
93
94 NOTICE("OK" << endl);
95
96 pdf.setExceptionHandler(supervisor);
97
98 Y.push_back(JNPE_t(pdf));
99 }
100 catch(const JException& error) {
101 FATAL(error.what() << endl);
102 }
103 }
104
105 // Add PDFs
106
107 for (int i = 1; i < NUMBER_OF_PDFS; i += 2) {
108 Y[i].add(Y[i-1]);
109 }
110
111 Y.erase(Y.begin());
112 }
113
114 /**
115 * Fit function.
116 * This method is used to determine the chi2 of given PMT with respect to shower hypothesis.
117 *
118 * \param x energy
119 * \param npe number of photoelectrons
120 * \return chi2
121 */
122 double operator()(const JEnergy& x, const JShowerNPEHit& npe) const
123 {
124 using namespace JPP;
125
126 const double E = x.getE();
127 const double u = npe.getChi2(E);
128
129 return estimator->getRho(u);
130 }
131
132 /**
133 * Create data structure for handling light yields for PMT.
134 *
135 * \param axis PMT axis
136 * \param R_Hz singles rate [Hz]
137 * \return light yields
138 */
139 inline JShowerNPE getNPE(const JAxis3D& axis,
140 const double R_Hz) const
141 {
142 using namespace JPP;
143
144 const JPosition3D D(axis.getPosition());
145 const JDirection3D U(axis.getDirection());
146
147 const double U_length = std::sqrt(U.getDX()*U.getDX() +
148 U.getDY()*U.getDY() +
149 U.getDZ()*U.getDZ());
150
151 const double ct = U.getDot(D) / (D.getLength()*U_length);
152
153 const double y = getNPE(Y, D.getLength(), ct);
154
155 return JShowerNPE(getN(T_ns, R_Hz * 1.0e-9), y);
156 }
157
158
159 /**
160 * Get number of photo-electrons.
161 *
162 * \param NPE NPE tables
163 * \param D PMT distance from shower [m]
164 * \param cd cosine of the PMT angle wrt the photon direction
165 * \return number of photo-electrons
166 */
167 static inline double getNPE(const std::vector<JNPE_t>& NPE,
168 const double D,
169 const double cd)
170 {
171 double npe = 0.0;
172
173 for (std::vector<JNPE_t>::const_iterator i = NPE.begin(); i != NPE.end(); ++i) {
174
175 if (D <= i->getXmax()) {
176
177 try {
178
179 const double y = get_value((*i)(std::max(D, i->getXmin()), cd));
180
181 if (y > 0.0) {
182 npe += y;
183 }
184 }
185 catch(const JLANG::JException& error) {
186 ERROR(error << std::endl);
187 }
188 }
189 }
190
191 return npe;
192 }
193
194
195 static JTimeRange T_ns; //!< Time window with respect to Cherenkov hypothesis [ns]
196 static double Vmax_npe; //!< Maximal integral of PDF [npe]
197
198 static const int NUMBER_OF_PDFS = 2;
199
200 static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
201
202 std::vector<JNPE_t> Y; //!< light from EM showers
203
204 std::shared_ptr<JMEstimator> estimator; //!< M-Estimator function
205 };
206
207 /**
208 * PDF types.
209 */
210 const JPDFType_t JRegressor<JEnergy, JSimplex>::pdf_t[] = { DIRECT_LIGHT_FROM_BRIGHT_POINT,
211 SCATTERED_LIGHT_FROM_BRIGHT_POINT };
212
213 /**
214 * Default values.
215 */
217 double JRegressor<JEnergy, JSimplex>::Vmax_npe = std::numeric_limits<double>::max();
218}
219
220#endif
Auxiliary methods to evaluate Poisson probabilities and chi2.
Maximum likelihood estimator (M-estimators).
General purpose messaging.
#define ERROR(A)
Definition JMessage.hh:66
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
Auxiliary methods for PDF calculations.
Numbering scheme for PDF types.
Physics constants.
General purpose data regression method.
This include file containes various data structures that can be used as specific return types for the...
Definition of zero value for any class.
Data structure for fit of energy.
Simple fit method based on Powell's algorithm, see reference: Numerical Recipes in C++,...
Definition JSimplex.hh:44
Axis object.
Definition JAxis3D.hh:41
Data structure for direction in three dimensions.
const JDirection3D & getDirection() const
Get direction.
double getDot(const JAngle3D &angle) const
Get dot product.
Data structure for position in three dimensions.
const JPosition3D & getPosition() const
Get position.
double getLength() const
Get length.
Definition JVector3D.hh:246
double getDY() const
Get y direction.
Definition JVersor3D.hh:106
double getDX() const
Get x direction.
Definition JVersor3D.hh:95
double getDZ() const
Get z direction.
Definition JVersor3D.hh:117
General exception.
Definition JException.hh:25
virtual const char * what() const override
Get error message.
Definition JException.hh:65
Custom class for integrated values of the PDF of the arrival time of Cherenkov light.
Definition JNPETable.hh:46
Multi-dimensional PDF table for arrival time of Cherenkov light.
Definition JPDFTable.hh:44
void setExceptionHandler(const typename function_type::supervisor_type &supervisor)
Set the supervisor for handling of exceptions.
Functional map with polynomial interpolation.
Definition JPolint.hh:1153
Template class for spline interpolation in 1D.
Definition JSpline.hh:734
Auxiliary classes and methods for linear and iterative data regression.
static const JZero zero
Function object to assign zero value.
Definition JZero.hh:105
JPDFType_t
PDF types.
Definition JPDFTypes.hh:24
@ SCATTERED_LIGHT_FROM_BRIGHT_POINT
scattered light from bright point
Definition JPDFTypes.hh:43
@ DIRECT_LIGHT_FROM_BRIGHT_POINT
direct light from bright point
Definition JPDFTypes.hh:42
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JResultEvaluator< JResult_t >::result_type get_value(const JResult_t &value)
Helper method to recursively evaluate a to function value.
Definition JResult.hh:998
JPolintMap< 1, JKey_t, JValue_t, JMap, typename JResultType< JValue_t >::result_type, JDistance_t > JPolint1FunctionalMap
Type definition of a 1st degree polynomial interpolation based on a JMap implementation.
Abstract class for global fit method.
Definition JRegressor.hh:79
Null M-estimator.
static JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
JShowerNPE getNPE(const JAxis3D &axis, const double R_Hz) const
Create data structure for handling light yields for PMT.
double operator()(const JEnergy &x, const JShowerNPEHit &npe) const
Fit function.
static double getNPE(const std::vector< JNPE_t > &NPE, const double D, const double cd)
Get number of photo-electrons.
std::vector< JNPE_t > Y
light from EM showers
JRegressor(const std::string &fileDescriptor)
Parameterized constructor.
std::shared_ptr< JMEstimator > estimator
M-Estimator function.
JTOOLS::JMAPLIST< JTOOLS::JPolint1FunctionalMap, JTOOLS::JPolint1FunctionalGridMap >::maplist JMapList_t
static double Vmax_npe
Maximal integral of PDF [npe].
JPHYSICS::JNPETable< double, double, JMapList_t > JNPE_t
JPHYSICS::JPDFTable< JFunction1D_t, JMapList_t > JPDF_t
Template definition of a data regressor of given model.
Definition JRegressor.hh:70
Auxiliary class for simultaneously handling light yields and response of PMT.
double getChi2(const double E_GeV) const
Get chi2.
Auxiliary class for handling EM shower light yield.
Definition JShowerNPE.hh:27
void load(const char *file_name)
Load from input file.
Auxiliary class for recursive map list generation.
Definition JMapList.hh:109