Jpp  15.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JShowerBrightPointRegressor.hh
Go to the documentation of this file.
1 #ifndef __JFIT__JSHOWERBRIGHTPOINTREGRESSOR__
2 #define __JFIT__JSHOWERBRIGHTPOINTREGRESSOR__
3 
4 #include "JPhysics/JPDFTypes.hh"
5 #include "JPhysics/JPDFTable.hh"
7 #include "JPhysics/JNPETable.hh"
8 #include "JPhysics/JConstants.hh"
9 
10 #include "JTools/JResult.hh"
11 
12 #include "JMath/JZero.hh"
13 
14 #include "JFit/JGandalf.hh"
15 #include "JFit/JPoint4D.hh"
16 #include "JFit/JMEstimator.hh"
17 #include "JFit/JRegressor.hh"
18 #include "JFit/JFitToolkit.hh"
19 
20 #include "Jeep/JMessage.hh"
21 
22 /**
23  * \file
24  * Data regression method for JFIT::JPoint4D from a bright point isoptropic emission PDF.
25  *
26  * \author adomi
27  */
28 
29 namespace JFIT {}
30 namespace JPP { using namespace JFIT; }
31 
32 namespace JFIT {
33 
37  using JTOOLS::get_value;
38 
39  /**
40  * Regressor function object for JPoint4D fit using JGandalf minimiser.
41  */
42  template<>
44  public JAbstractRegressor<JPoint4D, JGandalf>
45  {
47 
52 
53 
54  /**
55  * Parameterized constructor
56  *
57  * The PDF file descriptor should contain the wild card character JPHYSICS::WILD_CARD which
58  * will be replaced by the corresponding PDF types.
59  *
60  * \param fileDescriptor PDF file descriptor
61  * \param TTS TTS [ns]
62  * \param numberOfPoints number of points for Gauss-Hermite integration of TTS
63  * \param epsilon precision for Gauss-Hermite integration of TTS
64  */
65  JRegressor(const std::string& fileDescriptor,
66  const double TTS,
67  const int numberOfPoints = 25,
68  const double epsilon = 1.0e-10):
69  E_GeV(0.0)
70  {
71  using namespace std;
72  using namespace JPP;
73 
74  const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(JMATH::zero));
75 
76  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
77 
78  try {
79 
80  const string file_name = getFilename(fileDescriptor, pdf_t[i]);
81 
82  NOTICE("loading PDF from file " << file_name << "... " << flush);
83 
84  pdf[i].load(file_name.c_str());
85 
86  NOTICE("OK" << endl);
87 
88  pdf[i].setExceptionHandler(supervisor);
89  }
90  catch(const JException& error) {
91  FATAL(error.what() << endl);
92  }
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  } else if (TTS < 0.0) {
107  ERROR("Illegal value of TTS [ns]: " << TTS << endl);
108  }
109  }
110  }
111 
112  /**
113  * Fit function.
114  * This method is used to determine the chi2 and gradient of given hit with respect a bright point emitting isotropically
115  *
116  * JHit_t refers to a data structure which should have the following member methods:
117  * - double getX(); // [m]
118  * - double getY(); // [m]
119  * - double getZ(); // [m]
120  * - double getDX(); // [u]
121  * - double getDY(); // [u]
122  * - double getDZ(); // [u]
123  * - double getT(); // [ns]
124  *
125  * \param vx shower vertex
126  * \param hit hit
127  * \return chi2 and gradient
128  */
129  template<class JHit_t>
130  result_type operator()(const JPoint4D& vx, const JHit_t& hit) const
131  {
132  using namespace JPP;
133 
134  JPosition3D D(hit.getPosition());
135  JDirection3D U(hit.getDirection());
136 
137  D.sub(vx.getPosition());
138 
139  double ct = U.getDot(D) / D.getLength();
140 
141  if (ct > +1.0) { ct = +1.0; }
142  if (ct < -1.0) { ct = -1.0; }
143 
144  const double t = vx.getT() + (D.getLength() * getIndexOfRefraction() * getInverseSpeedOfLight());
145 
146  const double dt = T_ns.constrain(hit.getT() - t);
147 
148  JPDF_t::result_type H0 = getH0(hit.getR(), dt); // getH0 = Get background hypothesis value
149  JPDF_t::result_type H1 = getH1(D.getLength(), ct, dt, E_GeV); // getH1 = Get signal hypothesis value
150 
151  if (get_value(H1) >= Vmax_npe) {
152  H1 *= Vmax_npe / get_value(H1);
153  }
154 
155  H1 += H0; // now H1 is signal + background
156 
158 
159  result.chi2 = H1.getChi2() - H0.getChi2(); // Likelihood ratio
160 
161  /*
162  * Here it is evaluated: d(chi2)/d(ct) * d(ct)/d(x0,y0,z0,t0)
163  */
164  result.gradient = JPoint4D(JVector3D(-getIndexOfRefraction() * D.getX() / D.getLength(), // d(ct)/d(x0)
165  -getIndexOfRefraction() * D.getY() / D.getLength(), // d(ct)/d(y0)
166  -getIndexOfRefraction() * D.getZ() / D.getLength()), // d(ct)/d(z0)
167  getSpeedOfLight()); // d(ct)/d(t0)
168 
169  result.gradient.mul(getInverseSpeedOfLight() * (H1.getDerivativeOfChi2() -
170  H0.getDerivativeOfChi2())); // x d(chi2)/d(ct1)
171 
172  return result;
173 
174  }
175 
176  /**
177  * Get background hypothesis value for time differentiated PDF.
178  *
179  * \param R_Hz rate [Hz]
180  * \param t1 time [ns]
181  * \return hypothesis value
182  */
183  JPDF_t::result_type getH0(const double R_Hz,
184  const double t1) const
185  {
186  using namespace JPP;
187 
188  return JPDF_t::result_type(R_Hz * 1e-9, t1, T_ns);
189  }
190 
191  /**
192  * Get signal hypothesis value for bright point emission PDF.
193  *
194  * \param D hit distance from shower vertex [m]
195  * \param ct cosine of the HIT angle
196  * \param t arrival time of the light
197  * \param E shower energy [GeV]
198  * \return hypothesis value
199  */
201  const double ct,
202  const double t,
203  const double E) const
204  {
205  using namespace JPP;
206 
208 
209  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
210 
211  if (!pdf[i].empty() && D <= pdf[i].getXmax()) {
212 
213  try {
214 
215  JPDF_t::result_type y1 = E * pdf[i](std::max(D, pdf[i].getXmin()), ct, t);
216 
217  // safety measures
218 
219  if (y1.f <= 0.0) {
220  y1.f = 0.0;
221  y1.fp = 0.0;
222  }
223 
224  if (y1.v <= 0.0) {
225  y1.v = 0.0;
226  }
227 
228  h1 += y1;
229 
230  }
231  catch(JLANG::JException& error) {
232  ERROR(error << std::endl);
233  }
234  }
235  }
236 
237  return h1;
238  }
239 
240  /**
241  * Get maximal road width of PDF.
242  *
243  * \return road width [m]
244  */
245  inline double getRmax() const
246  {
247  using namespace JPP;
248 
249  double xmax = 0.0;
250 
251  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
252 
253  if (!pdf[i].empty() && pdf[i].getXmax() > xmax) {
254  xmax = pdf[i].getXmax();
255  }
256 
257  }
258 
259  return xmax;
260  }
261 
262  static JTimeRange T_ns; //!< Time window with respect to Cherenkov hypothesis [ns]
263  static double Vmax_npe; //!< Maximal integral of PDF [npe]
264 
265  static const int NUMBER_OF_PDFS = 2;
266 
267  static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
268 
269  JPDF_t pdf[NUMBER_OF_PDFS]; //!< PDF
270 
271  double E_GeV; //!< Energy of the shower [GeV]
272  };
273 
274 
275  /**
276  * PDF types.
277  */
280 
281  /**
282  * Default values.
283  */
285  double JRegressor<JPoint4D, JGandalf>::Vmax_npe = std::numeric_limits<double>::max();
286 
287 }
288 
289 #endif
Auxiliary methods to evaluate Poisson probabilities and chi2.
Template definition of a data regressor of given model.
Definition: JRegressor.hh:68
Type definition of a spline interpolation method based on a JCollection with JResultPDF result type...
General exception.
Definition: JException.hh:23
Type definition of a 2nd degree polynomial interpolation based on a JMap implementation.
General purpose data regression method.
Auxiliary methods for PDF calculations.
JPHYSICS::JPDFTable< JFunction1D_t, JPDFMapList_t > JPDF_t
double getRmax() const
Get maximal road width of PDF.
This include file containes various data structures that can be used as specific return types for the...
double getIndexOfRefraction()
Get average index of refraction of water corresponding to group velocity.
do rm f tmp H1
Data structure for vertex fit.
Definition: JPoint4D.hh:22
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [ns]).
void blur(const double TTS, const int numberOfPoints=25, const double epsilon=1.0e-10, const double quantile=0.99)
Blur PDF.
Definition: JPDFTable.hh:110
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
direct light from bright point
Definition: JPDFTypes.hh:45
Definition of zero value for any class.
then usage E
Definition: JMuonPostfit.sh:35
Numbering scheme for PDF types.
Type definition of a 1st degree polynomial interpolation based on a JGridMap implementation.
minimiser_type::result_type result_type
Definition: JRegressor.hh:80
JPDF_t::result_type getH0(const double R_Hz, const double t1) const
Get background hypothesis value for time differentiated PDF.
Data structure for vector in three dimensions.
Definition: JVector3D.hh:34
return result
Definition: JPolint.hh:727
JRegressor(const std::string &fileDescriptor, const double TTS, const int numberOfPoints=25, const double epsilon=1.0e-10)
Parameterized constructor.
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
Physics constants.
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
JPDFType_t
PDF types.
Definition: JPDFTypes.hh:27
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:108
General purpose messaging.
scattered light from bright point
Definition: JPDFTypes.hh:46
result_type operator()(const JPoint4D &vx, const JHit_t &hit) const
Fit function.
#define FATAL(A)
Definition: JMessage.hh:67
Fit method based on the Levenberg-Marquardt method.
Definition: JGandalf.hh:52
static double Vmax_npe
Maximal integral of PDF [npe].
virtual const char * what() const override
Get error message.
Definition: JException.hh:48
const double getSpeedOfLight()
Get speed of light.
const double getInverseSpeedOfLight()
Get inverse speed of light.
int numberOfPoints
Definition: JResultPDF.cc:22
std::string getFilename(const std::string &file_name)
Get file name part, i.e. part after last JEEP::PATHNAME_SEPARATOR if any.
Definition: JeepToolkit.hh:88
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
transformablemultifunction_type::result_type result_type
Definition: JPDFTable.hh:49
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition: JVertex3D.hh:145
Abstract class for global fit method.
Definition: JRegressor.hh:75
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
JResultEvaluator< JResult_t >::result_type get_value(const JResult_t &value)
Helper method to recursively evaluate a to function value.
Definition: JResult.hh:998
Maximum likelihood estimator (M-estimators).
JPDF_t::result_type getH1(const double D, const double ct, const double t, const double E) const
Get signal hypothesis value for bright point emission PDF.
JTOOLS::JMAPLIST< JTOOLS::JPolint2FunctionalMap, JTOOLS::JPolint1FunctionalGridMap >::maplist JPDFMapList_t
static JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].