Jpp master_rocky-44-g75b7c4f75
the software that should make you happy
Loading...
Searching...
No Matches
JEnergyRegressor.hh
Go to the documentation of this file.
1#ifndef __JFIT__JENERGYREGRESSOR__
2#define __JFIT__JENERGYREGRESSOR__
3
4#include <string>
5
15#include "JFit/JRegressor.hh"
16#include "JFit/JEnergy.hh"
17#include "JFit/JNPE.hh"
18#include "JFit/JNPEHit.hh"
19#include "JFit/JMEstimator.hh"
20#include "JFit/JFitToolkit.hh"
21#include "JFit/JTimeRange.hh"
22#include "Jeep/JMessage.hh"
23
24
25/**
26 * \file
27 * Data regression method for JFIT::JEnergy.
28 * \author mdejong
29 */
30namespace JFIT {}
31namespace JPP { using namespace JFIT; }
32
33namespace JFIT {
34
43
44
45 /**
46 * Regressor function object for fit of muon energy.
47 */
48 template<>
49 struct JRegressor<JEnergy> :
50 public JAbstractRegressor<JEnergy>
51 {
52 using JAbstractRegressor<JEnergy>::operator();
54
57 JTOOLS::JPolint1FunctionalGridMap>::maplist JNPEMaplist_t;
59
60
61 /**
62 * Constructor.
63 *
64 * The PDF file descriptor should contain the wild card character JPHYSICS::WILDCARD
65 * which will be replaced by the PDF types listed in JRegressor<JEnergy, JSimplex>::pdf_t.
66 *
67 * \param fileDescriptor PDF file descriptor
68 */
69 JRegressor(const std::string& fileDescriptor) :
70 estimator(new JMEstimatorNormal())
71 {
72 using namespace std;
73 using namespace JPP;
74
75 typedef JSplineFunction1D_t JFunction1D_t;
77
78 const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(JMATH::zero));
79
80 for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
81
82 try {
83
84 JPDF_t pdf;
85
86 const JPDFType_t type = pdf_t[i];
87 const string file_name = getFilename(fileDescriptor, type);
88
89 NOTICE("loading PDF from file " << file_name << "... " << flush);
90
91 pdf.load(file_name.c_str());
92
93 NOTICE("OK" << endl);
94
95 pdf.setExceptionHandler(supervisor);
96
97 if (is_bremsstrahlung(type))
98 YB.push_back(JNPE_t(pdf));
99 else if (is_deltarays(type))
100 YA.push_back(JNPE_t(pdf));
101 else
102 Y1.push_back(JNPE_t(pdf));
103 }
104 catch(const JLANG::JException& error) {
105 FATAL(error.what() << endl);
106 }
107 }
108
109 // Add PDFs
110
111 if (Y1.size() == 2) { Y1[1].add(Y1[0]); Y1.erase(Y1.begin()); }
112 if (YA.size() == 2) { YA[1].add(YA[0]); YA.erase(YA.begin()); }
113 if (YB.size() == 2) { YB[1].add(YB[0]); YB.erase(YB.begin()); }
114 }
115
116
117 /**
118 * Fit function.
119 * This method is used to determine chi2 of given number of photo-electrons for given energy of muon.
120 *
121 * \param x energy
122 * \param npe npe
123 * \return chi2
124 */
125 inline double operator()(const JEnergy& x, const JNPEHit& npe) const
126 {
127 const double E = x.getE();
128 const double u = npe.getChi2(E);
129
130 return estimator->getRho(u);
131 }
132
133
134 /**
135 * Create data structure for handling light yields for PMT.
136 * Note that the PMT geometry should be relative to the muon trajectory,
137 * conform method JGEOMETRY3D::JAxis3D::transform.
138 *
139 * \param axis PMT axis
140 * \param R_Hz singles rate [Hz]
141 * \return light yields
142 */
143 inline JNPE getNPE(const JAxis3D& axis,
144 const double R_Hz) const
145 {
146 using namespace std;
147 using namespace JPP;
148
149 const double x = axis.getX();
150 const double y = axis.getY();
151 const double R = sqrt(x*x + y*y);
152 const double z = axis.getZ() - R / getTanThetaC();
153
154 const double theta = axis.getTheta();
155 const double phi = fabs(axis.getPhi());
156
157 const double y1 = getNPE(Y1, R, theta, phi);
158 const double yA = getNPE(YA, R, theta, phi);
159 const double yB = getNPE(YB, R, theta, phi);
160
161 return JNPE(getN(T_ns, R_Hz * 1.0e-9), y1, yA, yB, z);
162 }
163
164
165 /**
166 * Get maximal road width of NPE.
167 *
168 * \return road width [m]
169 */
170 inline double getRmax() const
171 {
172 return std::max(getRmax(Y1), std::max(getRmax(YA), getRmax(YB)));
173 }
174
175
176 std::vector<JNPE_t> Y1; //!< light from muon
177 std::vector<JNPE_t> YA; //!< light from delta-rays
178 std::vector<JNPE_t> YB; //!< light from EM showers
179
180 static JTimeRange T_ns; //!< Time window with respect to Cherenkov hypothesis [ns]
181
182
183 static const int NUMBER_OF_PDFS = 6;
184
185 static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
186
187 JLANG::JSinglePointer<JMEstimator> estimator; //!< M-Estimator function
188
189
190 protected:
191 /**
192 * Get maximal road width of PDF.
193 *
194 * \param NPE NPE tables
195 * \return road width [m]
196 */
197 static inline double getRmax(const std::vector<JNPE_t>& NPE)
198 {
199 double xmax = 0.0;
200
201 for (std::vector<JNPE_t>::const_iterator i = NPE.begin(); i != NPE.end(); ++i) {
202 if (!i->empty() && i->getXmax() > xmax) {
203 xmax = i->getXmax();
204 }
205 }
206
207 return xmax;
208 }
209
210
211 /**
212 * Get number of photo-electrons.
213 *
214 * \param NPE NPE tables
215 * \param R distance between muon and PMT [m]
216 * \param theta zenith angle orientation PMT [rad]
217 * \param phi azimuth angle orientation PMT [rad]
218 * \return number of photo-electrons
219 */
220 static inline double getNPE(const std::vector<JNPE_t>& NPE,
221 const double R,
222 const double theta,
223 const double phi)
224 {
225 using JTOOLS::get_value;
226
227 double npe = 0.0;
228
229 for (std::vector<JNPE_t>::const_iterator i = NPE.begin(); i != NPE.end(); ++i) {
230
231 if (R <= i->getXmax()) {
232
233 try {
234
235 const double y = get_value((*i)(std::max(R, i->getXmin()), theta, phi));
236
237 if (y > 0.0) {
238 npe += y;
239 }
240 }
241 catch(const JLANG::JException& error) {
242 ERROR(error << std::endl);
243 }
244 }
245 }
246
247 return npe;
248 }
249 };
250
251
252 /**
253 * PDF types.
254 */
255 const JPDFType_t JRegressor<JEnergy>::pdf_t[] = { DIRECT_LIGHT_FROM_MUON,
256 SCATTERED_LIGHT_FROM_MUON,
257 DIRECT_LIGHT_FROM_DELTARAYS,
258 SCATTERED_LIGHT_FROM_DELTARAYS,
259 DIRECT_LIGHT_FROM_EMSHOWERS,
260 SCATTERED_LIGHT_FROM_EMSHOWERS };
261
262
263 /**
264 * Time range.
265 */
267}
268
269#endif
Auxiliary methods to evaluate Poisson probabilities and chi2.
Various implementations of functional maps.
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
int debug
debug level
Definition JSirene.cc:69
Auxiliary methods for PDF calculations.
Numbering scheme for PDF types.
Physics constants.
General purpose data regression method.
Data structure for fit of energy.
Definition JEnergy.hh:31
Axis object.
Definition JAxis3D.hh:41
double getY() const
Get y position.
Definition JVector3D.hh:104
double getZ() const
Get z position.
Definition JVector3D.hh:115
double getX() const
Get x position.
Definition JVector3D.hh:94
double getTheta() const
Get theta angle.
Definition JVersor3D.hh:128
double getPhi() const
Get phi angle.
Definition JVersor3D.hh:144
General exception.
Definition JException.hh:24
virtual const char * what() const override
Get error message.
Definition JException.hh:64
The template JSinglePointer class can be used to hold a pointer to an object.
Custom class for integrated values of the PDF of the arrival time of Cherenkov light.
Definition JNPETable.hh:43
Multi-dimensional PDF table for arrival time of Cherenkov light.
Definition JPDFTable.hh:44
const double xmax
double getNPE(const Hit &hit)
Get true charge of hit.
Auxiliary classes and methods for linear and iterative data regression.
Definition JEnergy.hh:15
static const JZero zero
Function object to assign zero value.
Definition JZero.hh:105
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
JPDFType_t
PDF types.
Definition JPDFTypes.hh:24
@ 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
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double getN(const JRange< T > &range, const double R)
Get expected number of occurrences due to given rate within specified interval.
Definition JRange.hh:704
double u[N+1]
Definition JPolint.hh:865
JResultEvaluator< JResult_t >::result_type get_value(const JResult_t &value)
Helper method to recursively evaluate a to function value.
Definition JResult.hh:998
Auxiliary class for handling debug parameter within a class.
Definition JMessage.hh:44
Abstract class for global fit method.
Definition JRegressor.hh:79
Normal M-estimator.
Auxiliary class for simultaneously handling light yields and response of PMT.
Definition JNPEHit.hh:21
double getChi2(const double E_GeV) const
Get chi2.
Definition JNPEHit.hh:87
Auxiliary class for handling various light yields.
Definition JNPE.hh:32
Template definition of a data regressor of given model.
Definition JRegressor.hh:70
Auxiliary class for recursive map list generation.
Definition JMapList.hh:109
Type definition of a 1st degree polynomial interpolation based on a JGridMap implementation.
Type definition of a 1st degree polynomial interpolation based on a JMap implementation.
Type definition of a spline interpolation method based on a JCollection with double result type.