Jpp in_tag_pdf_generation
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 * Template specialisation for storage of PDF tables.
44 */
45 template<>
47 {
52
53 static const int NUMBER_OF_PDFS = 2;
54
56
57 /**
58 * Default constructor.
59 */
62
63 /**
64 * Parameterized constructor
65 *
66 * The PDF file descriptor should contain the wild card character JPHYSICS::WILDCARD which
67 * will be replaced by the corresponding PDF types listed in JRegressorStorage<JPoint4E, JGandalf>::pdf_t.
68 *
69 * The <tt>TTS</tt> corresponds to the additional time smearing applied to the PDFs.
70 *
71 * \param fileDescriptor PDF file descriptor
72 * \param T_ns time range [ns]
73 * \param TTS TTS [ns]
74 * \param numberOfPoints number of points for Gauss-Hermite integration of TTS
75 * \param epsilon precision for Gauss-Hermite integration of TTS
76 */
77 JRegressorStorage(const std::string& fileDescriptor,
78 const JTimeRange& T_ns,
79 const double TTS,
80 const int numberOfPoints = 25,
81 const double epsilon = 1.0e-10) :
82 T_ns(T_ns)
83
84 {
85 using namespace std;
86 using namespace JPP;
87
88 const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(JMATH::zero));
89
90 for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
91
92 const string file_name = getFilename(fileDescriptor, pdf_t[i]);
93
94 _pdf[i].load(file_name.c_str());
95
96 _pdf[i].setExceptionHandler(supervisor);
97 }
98
99 // Add PDFs
100 for (int i = 1; i < NUMBER_OF_PDFS; i += 2) {
101
102 _pdf[ i ].add(_pdf[i-1]);
103
104 JPDF_t buffer;
105
106 _pdf[i-1].swap(buffer);
107
108 if (TTS > 0.0) {
109 _pdf[i].blur(TTS, numberOfPoints, epsilon);
110 }
111 }
112 }
113
114 /**
115 * Get PDFs.
116 *
117 * \return PDFs
118 */
119 const JPDFs_t& getPDF() const
120 {
121 return _pdf;
122 }
123
124
125 /**
126 * PDF types.
127 */
128 static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
129 JTimeRange T_ns; //!< Time window with respect to Cherenkov hypothesis [ns]
130
131 private:
132 JPDFs_t _pdf; //!< PDFs
133 };
134
135 /**
136 * PDF types.
137 */
139 DIRECT_LIGHT_FROM_BRIGHT_POINT,
140 SCATTERED_LIGHT_FROM_BRIGHT_POINT
141 };
142
143
144 /**
145 * Regressor function object for JLine3Z fit using JGandalf minimiser.
146 */
147 template<>
148 struct JRegressor<JPoint4E, JGandalf> :
149 public JAbstractRegressor<JPoint4E, JGandalf>,
150 public JRegressorStorage <JPoint4E, JGandalf>
151 {
152 using JAbstractRegressor<JPoint4E, JGandalf>::operator();
153
154 typedef JRegressorStorage<JPoint4E, JGandalf> storage_type;
155
156 /**
157 * Default constructor
158 */
159 JRegressor() :
160 storage_type(),
161 pdf(getPDF())
162 {}
163
164 /**
165 * Constructor.
166 *
167 * The PDF file descriptor should contain the wild card character JPHYSICS::WILDCARD which
168 * will be replaced by the PDF types listed in JRegressorStorage<JPoint4E, JGandalf>::pdf_t.
169 *
170 * The <tt>TTS</tt> corresponds to the additional time smearing applied to the PDFs.
171 *
172 * \param fileDescriptor PDF file descriptor
173 * \param T_ns time range [ns]
174 * \param TTS TTS [ns]
175 * \param numberOfPoints number of points for Gauss-Hermite integration of TTS
176 * \param epsilon precision for Gauss-Hermite integration of TTS
177 */
178 JRegressor(const std::string& fileDescriptor,
179 const double TTS,
180 const int numberOfPoints = 25,
181 const double epsilon = 1.0e-10) :
182 storage_type(fileDescriptor, T_ns, TTS, numberOfPoints, epsilon),
183 pdf(getPDF())
184 {}
185
186 /**
187 * Constructor.
188 *
189 * \param storage PDF storage
190 */
191 JRegressor(const storage_type& storage) :
192 pdf(storage.getPDF())
193 {
194 T_ns = storage.T_ns;
195 }
196
197 /**
198 * Fit function.
199 * This method is used to determine the chi2 and gradient of given hit with respect a bright point emitting isotropically
200 *
201 * JHit_t refers to a data structure which should have the following member methods:
202 * - double getX(); // [m]
203 * - double getY(); // [m]
204 * - double getZ(); // [m]
205 * - double getDX(); // [u]
206 * - double getDY(); // [u]
207 * - double getDZ(); // [u]
208 * - double getT(); // [ns]
209 *
210 * \param vx shower vertex
211 * \param hit hit
212 * \return chi2 and gradient
213 */
214 template<class JHit_t>
215 result_type operator()(const JPoint4E& vx, const JHit_t& hit) const
216 {
217 using namespace JPP;
218
219 JPosition3D D(hit.getPosition());
220 JDirection3D U(hit.getDirection());
221
222 D.sub(vx.getPosition());
223 double length = D.getLength();
224 double ct = U.getDot(D) / length;
225
226 if (ct > +1.0) { ct = +1.0; }
227 if (ct < -1.0) { ct = -1.0; }
228
229 const double t = vx.getT() + (length * getIndexOfRefraction() * getInverseSpeedOfLight());
230
231 const double dt = T_ns.constrain(hit.getT() - t);
232
233 JPDF_t::result_type H0 = getH0(hit.getR(), dt); // getH0 = Get background hypothesis value
234 JPDF_t::result_type H1 = getH1(length, ct, dt); // getH1 = Get signal hypothesis value / 1 GeV
235
236 if (get_value(H1) >= Vmax_npe) {
237 H1 *= Vmax_npe / get_value(H1);
238 }
239
240 double H1_value = get_value(H1);
241 double v_H1 = H1.v; //Integral from tmin to t of just H1
242 double V_H1 = H1.V; //Integral from tmin to tmax of just H1
243 H1 *= vx.getE();
244
245 JPDF_t::result_type HT = H1+H0; //now H1 is signal + background
246 double HT_value = get_value(HT);
247 result_type result;
248 result.chi2 = HT.getChi2() - H0.getChi2(); // Likelihood ratio
249
250 double exp_V_HT = exp(-HT.V); //V is the integral from tmin to tmax of EH1+H0
251
252 double energy_gradient = -1 / HT_value; //dPdE
253 energy_gradient *= (H1_value - HT_value * v_H1) * (1-exp_V_HT) - HT_value * exp_V_HT * V_H1; //Numerator
254 energy_gradient /= (1-exp_V_HT); // Denominator
255
256 /*
257 * Here it is evaluated: d(chi2)/d(ct) * d(ct)/d(x0,y0,z0,t0) + d(chi2)/dE
258 */
259 result.gradient = JPoint4E(JPoint4D(JVector3D(-getIndexOfRefraction() * D.getX() / length, // d(ct)/d(x0)
260 -getIndexOfRefraction() * D.getY() / length, // d(ct)/d(y0)
261 -getIndexOfRefraction() * D.getZ() / length), // d(ct)/d(z0)
262 getSpeedOfLight()), // d(ct)/d(t0)
263 energy_gradient); // d(chi2)/d(E)
264
265 static_cast<JPoint4D&>(result.gradient).mul(getInverseSpeedOfLight() * (HT.getDerivativeOfChi2() -
266 H0.getDerivativeOfChi2())); // x d(chi2)/d(ct1)
267
268 return result;
269
270 }
271
272 /**
273 * Get background hypothesis value for time differentiated PDF.
274 *
275 * \param R_Hz rate [Hz]
276 * \param t1 time [ns]
277 * \return hypothesis value
278 */
279 JPDF_t::result_type getH0(const double R_Hz,
280 const double t1) const
281 {
282 using namespace JPP;
283
284 return JPDF_t::result_type(R_Hz * 1e-9, t1, T_ns);
285 }
286
287 /**
288 * Get signal hypothesis value per 1 GeV for bright point emission PDF.
289 *
290 * \param D hit distance from shower vertex [m]
291 * \param ct cosine of the HIT angle
292 * \param t arrival time of the light
293 * \return hypothesis value / GeV
294 */
295 JPDF_t::result_type getH1(const double D,
296 const double ct,
297 const double t) const
298 {
299 using namespace JPP;
300
301 JPDF_t::result_type h1 = JMATH::zero;
302
303 for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
304
305 if (!pdf[i].empty() && D <= pdf[i].getXmax()) {
306
307 try {
308
309 JPDF_t::result_type y1 = pdf[i](std::max(D, pdf[i].getXmin()), ct, t);
310
311 // safety measures
312
313 if (y1.f <= 0.0) {
314 y1.f = 0.0;
315 y1.fp = 0.0;
316 }
317
318 if (y1.v <= 0.0) {
319 y1.v = 0.0;
320 }
321
322 h1 += y1;
323 }
324 catch(JLANG::JException& error) {
325 ERROR(error << std::endl);
326 }
327 }
328 }
329
330 return h1;
331 }
332
333 /**
334 * Get maximal road width of PDF.
335 *
336 * \return road width [m]
337 */
338 inline double getRmax() const
339 {
340 using namespace JPP;
341
342 double xmax = 0.0;
343
344 for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
345
346 if (!pdf[i].empty() && pdf[i].getXmax() > xmax) {
347 xmax = pdf[i].getXmax();
348 }
349
350 }
351
352 return xmax;
353 }
354
355 static double Vmax_npe; //!< Maximal integral of PDF [npe]
356
357 const JPDFs_t& pdf; //!< PDF
358 };
359
360
361 /**
362 * Default values.
363 */
364 double JRegressor<JPoint4E, JGandalf>::Vmax_npe = std::numeric_limits<double>::max();
365
366}
367
368#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:147
General exception.
Definition JException.hh:24
Multi-dimensional PDF table for arrival time of Cherenkov light.
Definition JPDFTable.hh:44
const double xmax
const double epsilon
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
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:58
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.