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