Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
JShowerBrightPointRegressor.hh
Go to the documentation of this file.
1#ifndef __JFIT__JSHOWERBRIGHTPOINTREGRESSOR__
2#define __JFIT__JSHOWERBRIGHTPOINTREGRESSOR__
3
4#include <array>
5
11
12#include "JTools/JResult.hh"
13
14#include "JMath/JZero.hh"
15
16#include "JFit/JGandalf.hh"
17#include "JFit/JPoint4E.hh"
18#include "JFit/JMEstimator.hh"
19#include "JFit/JRegressor.hh"
20#include "JFit/JFitToolkit.hh"
21#include "JFit/JTimeRange.hh"
22
23#include "Jeep/JMessage.hh"
24
25/**
26 * \file
27 * Data regression method for JFIT::JPoint4E from a bright point isoptropic emission PDF.
28 *
29 * \author adomi, vcarretero
30 */
31
32namespace JFIT {}
33namespace JPP { using namespace JFIT; }
34
35namespace JFIT {
36
41
42 /**
43 * Function to constrain the energy during the fit, to prevent unphysical values.
44 *
45 * \param value model (I/O)
46 */
47 inline void model(JPoint4E& value)
48 {
49 using namespace std;
50
51 const double Emin = 0.1; // [GeV]
52
53 double E = max(Emin, value.getE());
54
55 value = JPoint4E(static_cast<const JPoint4D&>(value), E);
56 }
57
58 /**
59 * Template specialisation for storage of PDF tables.
60 */
61 template<>
63 {
68
69 static const int NUMBER_OF_PDFS = 2;
70
72
73 /**
74 * Default constructor.
75 */
78
79 /**
80 * Parameterized constructor
81 *
82 * The PDF file descriptor should contain the wild card character JPHYSICS::WILDCARD which
83 * will be replaced by the corresponding PDF types listed in JRegressorStorage<JPoint4E, JGandalf>::pdf_t.
84 *
85 * The <tt>TTS</tt> corresponds to the additional time smearing applied to the PDFs.
86 *
87 * \param fileDescriptor PDF file descriptor
88 * \param T_ns time range [ns]
89 * \param TTS TTS [ns]
90 * \param numberOfPoints number of points for Gauss-Hermite integration of TTS
91 * \param epsilon precision for Gauss-Hermite integration of TTS
92 */
93 JRegressorStorage(const std::string& fileDescriptor,
94 const JTimeRange& T_ns,
95 const double TTS,
96 const int numberOfPoints = 25,
97 const double epsilon = 1.0e-10) :
98 T_ns(T_ns)
99
100 {
101 using namespace std;
102 using namespace JPP;
103
104 const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(JMATH::zero));
105
106 for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
107
108 const string file_name = getFilename(fileDescriptor, pdf_t[i]);
109
110 _pdf[i].load(file_name.c_str());
111
112 _pdf[i].setExceptionHandler(supervisor);
113 }
114
115 // Add PDFs
116 for (int i = 1; i < NUMBER_OF_PDFS; i += 2) {
117
118 _pdf[ i ].add(_pdf[i-1]);
119
120 JPDF_t buffer;
121
122 _pdf[i-1].swap(buffer);
123
124 if (TTS > 0.0) {
125 _pdf[i].blur(TTS, numberOfPoints, epsilon);
126 }
127 }
128 }
129
130 /**
131 * Get PDFs.
132 *
133 * \return PDFs
134 */
135 const JPDFs_t& getPDF() const
136 {
137 return _pdf;
138 }
139
140
141 /**
142 * PDF types.
143 */
144 static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
145 JTimeRange T_ns; //!< Time window with respect to Cherenkov hypothesis [ns]
146
147 private:
148 JPDFs_t _pdf; //!< PDFs
149 };
150
151 /**
152 * PDF types.
153 */
155 DIRECT_LIGHT_FROM_BRIGHT_POINT,
156 SCATTERED_LIGHT_FROM_BRIGHT_POINT
157 };
158
159
160 /**
161 * Regressor function object for JLine3Z fit using JGandalf minimiser.
162 */
163 template<>
164 struct JRegressor<JPoint4E, JGandalf> :
165 public JAbstractRegressor<JPoint4E, JGandalf>,
166 public JRegressorStorage <JPoint4E, JGandalf>
167 {
168 using JAbstractRegressor<JPoint4E, JGandalf>::operator();
169
170 typedef JRegressorStorage<JPoint4E, JGandalf> storage_type;
171
172 /**
173 * Default constructor
174 */
175 JRegressor() :
176 storage_type(),
177 pdf(getPDF())
178 {}
179
180 /**
181 * Constructor.
182 *
183 * The PDF file descriptor should contain the wild card character JPHYSICS::WILDCARD which
184 * will be replaced by the PDF types listed in JRegressorStorage<JPoint4E, JGandalf>::pdf_t.
185 *
186 * The <tt>TTS</tt> corresponds to the additional time smearing applied to the PDFs.
187 *
188 * \param fileDescriptor PDF file descriptor
189 * \param T_ns time range [ns]
190 * \param TTS TTS [ns]
191 * \param numberOfPoints number of points for Gauss-Hermite integration of TTS
192 * \param epsilon precision for Gauss-Hermite integration of TTS
193 */
194 JRegressor(const std::string& fileDescriptor,
195 const JTimeRange& T_ns,
196 const double TTS,
197 const int numberOfPoints = 25,
198 const double epsilon = 1.0e-10) :
199 storage_type(fileDescriptor, T_ns, TTS, numberOfPoints, epsilon),
200 pdf(getPDF())
201 {}
202
203 /**
204 * Constructor.
205 *
206 * \param storage PDF storage
207 */
208 JRegressor(const storage_type& storage) :
209 pdf(storage.getPDF())
210 {
211 T_ns = storage.T_ns;
212 }
213
214 /**
215 * Fit function.
216 * This method is used to determine the chi2 and gradient of given hit with respect a bright point emitting isotropically
217 *
218 * JHit_t refers to a data structure which should have the following member methods:
219 * - double getX(); // [m]
220 * - double getY(); // [m]
221 * - double getZ(); // [m]
222 * - double getDX(); // [u]
223 * - double getDY(); // [u]
224 * - double getDZ(); // [u]
225 * - double getT(); // [ns]
226 * - double getQE(); // relative quantum efficiency
227 * - double getR(); // rate [Hz]
228 *
229 * \param vx shower vertex
230 * \param hit hit
231 * \return chi2 and gradient
232 */
233 template<class JHit_t>
234 result_type operator()(const JPoint4E& vx, const JHit_t& hit) const
235 {
236 using namespace JPP;
237
238 JPosition3D D(hit.getPosition());
239 JDirection3D U(hit.getDirection());
240
241 D.sub(vx.getPosition());
242 double length = D.getLength();
243 double ct = U.getDot(D) / length;
244
245 if (ct > +1.0) { ct = +1.0; }
246 if (ct < -1.0) { ct = -1.0; }
247
248 const double t = vx.getT() + (length * getIndexOfRefraction() * getInverseSpeedOfLight());
249
250 const double dt = T_ns.constrain(hit.getT() - t);
251
252 JPDF_t::result_type H0 = getH0(hit.getR(), dt); // getH0 = Get background hypothesis value
253 JPDF_t::result_type H1 = getH1(length, ct, dt); // getH1 = Get signal hypothesis value / 1 GeV
254
255 H1 *= hit.getQE();
256
257 if (get_value(H1) >= Vmax_npe) {
258 H1 *= Vmax_npe / get_value(H1);
259 }
260
261 const double H1_value = get_value(H1);
262
263 const double v_H1 = H1.v; // Integral from tmin to t of just H1
264 const double V_H1 = H1.V; // Integral from tmin to tmax of just H1
265
266 H1 *= vx.getE();
267
268 JPDF_t::result_type HT = H1 + H0; // signal + background
269
270 const double HT_value = get_value(HT);
271
272 result_type result;
273
274 result.chi2 = HT.getChi2() - H0.getChi2(); // Likelihood ratio
275
276 double exp_V_HT = exp(-HT.V); // V is the integral from tmin to tmax of EH1+H0
277
278 double energy_gradient = -1 / HT_value; // dP/dE
279
280 energy_gradient *= (H1_value - HT_value * v_H1) * (1-exp_V_HT) - HT_value * exp_V_HT * V_H1; // Numerator
281 energy_gradient /= (1-exp_V_HT); // Denominator
282
283 // Here it is evaluated: d(chi2)/d(ct) * d(ct)/d(x0,y0,z0,t0) + d(chi2)/dE
284
285 result.gradient = JPoint4E(JPoint4D(JVector3D(-getIndexOfRefraction() * D.getX() / length, // d(ct)/d(x0)
286 -getIndexOfRefraction() * D.getY() / length, // d(ct)/d(y0)
287 -getIndexOfRefraction() * D.getZ() / length), // d(ct)/d(z0)
288 getSpeedOfLight()), // d(ct)/d(t0)
289 energy_gradient); // d(chi2)/d(E)
290
291 static_cast<JPoint4D&>(result.gradient).mul(getInverseSpeedOfLight() * (HT.getDerivativeOfChi2() -
292 H0.getDerivativeOfChi2())); // x d(chi2)/d(ct1)
293
294 return result;
295 }
296
297 /**
298 * Get background hypothesis value for time differentiated PDF.
299 *
300 * \param R_Hz rate [Hz]
301 * \param t1 time [ns]
302 * \return hypothesis value
303 */
304 JPDF_t::result_type getH0(const double R_Hz,
305 const double t1) const
306 {
307 using namespace JPP;
308
309 return JPDF_t::result_type(R_Hz * 1e-9, t1, T_ns);
310 }
311
312 /**
313 * Get signal hypothesis value per 1 GeV for bright point emission PDF.
314 *
315 * \param D hit distance from shower vertex [m]
316 * \param ct cosine of the HIT angle
317 * \param t arrival time of the light
318 * \return hypothesis value / GeV
319 */
320 JPDF_t::result_type getH1(const double D,
321 const double ct,
322 const double t) const
323 {
324 using namespace JPP;
325
326 JPDF_t::result_type h1 = JMATH::zero;
327
328 for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
329
330 if (!pdf[i].empty() && D <= pdf[i].getXmax()) {
331
332 try {
333
334 JPDF_t::result_type y1 = pdf[i](std::max(D, pdf[i].getXmin()), ct, t);
335
336 // safety measures
337
338 if (y1.f <= 0.0) {
339 y1.f = 0.0;
340 y1.fp = 0.0;
341 }
342
343 if (y1.v <= 0.0) {
344 y1.v = 0.0;
345 }
346
347 h1 += y1;
348 }
349 catch(JLANG::JException& error) {
350 ERROR(error << std::endl);
351 }
352 }
353 }
354
355 return h1;
356 }
357
358 /**
359 * Get maximal road width of PDF.
360 *
361 * \return road width [m]
362 */
363 inline double getRmax() const
364 {
365 using namespace JPP;
366
367 double xmax = 0.0;
368
369 for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
370
371 if (!pdf[i].empty() && pdf[i].getXmax() > xmax) {
372 xmax = pdf[i].getXmax();
373 }
374
375 }
376
377 return xmax;
378 }
379
380 static double Vmax_npe; //!< Maximal integral of PDF [npe]
381
382 const JPDFs_t& pdf; //!< PDF
383 };
384
385
386 /**
387 * Default values.
388 */
389 double JRegressor<JPoint4E, JGandalf>::Vmax_npe = std::numeric_limits<double>::max();
390
391}
392
393#endif
Auxiliary methods to evaluate Poisson probabilities and chi2.
Maximum likelihood estimator (M-estimators).
General purpose messaging.
#define ERROR(A)
Definition JMessage.hh:66
Auxiliary methods for PDF calculations.
Numbering scheme for PDF types.
Physics constants.
General purpose data regression method.
int numberOfPoints
Definition JResultPDF.cc:22
This include file containes various data structures that can be used as specific return types for the...
Definition of zero value for any class.
Fit method based on the Levenberg-Marquardt method.
Definition JGandalf.hh:87
Data structure for vertex fit.
Definition JPoint4D.hh:24
Data structure for vertex fit.
Definition JPoint4E.hh:24
double getE() const
Get energy.
Definition JPoint4E.hh:52
Data structure for direction in three dimensions.
Data structure for position in three dimensions.
const JPosition3D & getPosition() const
Get position.
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition JVertex3D.hh:160
General exception.
Definition JException.hh:24
Multi-dimensional PDF table for arrival time of Cherenkov light.
Definition JPDFTable.hh:44
Auxiliary classes and methods for linear and iterative data regression.
void model(JModel_t &value)
Auxiliary function to constrain model during fit.
Definition JGandalf.hh:57
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
Abstract class for global fit method.
Definition JRegressor.hh:79
JRegressorStorage(const std::string &fileDescriptor, const JTimeRange &T_ns, const double TTS, const int numberOfPoints=25, const double epsilon=1.0e-10)
Parameterized constructor.
JPHYSICS::JPDFTable< JFunction1D_t, JPDFMapList_t > JPDF_t
std::array< JPDF_t, NUMBER_OF_PDFS > JPDFs_t
PDFs.
JTOOLS::JMAPLIST< JTOOLS::JPolint2FunctionalMap, JTOOLS::JPolint1FunctionalGridMap >::maplist JPDFMapList_t
JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
Template data structure for storage of internal data.
Template definition of a data regressor of given model.
Definition JRegressor.hh:70
Auxiliary class to set-up Hit.
Definition JSirene.hh:60
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 2nd degree polynomial interpolation based on a JMap implementation.
Type definition of a spline interpolation method based on a JCollection with JResultPDF result type.