Jpp
 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 
9 #include "JTools/JConstants.hh"
10 #include "JTools/JResult.hh"
11 
12 #include "JMath/JZero.hh"
13 
14 #include "JFit/JHitW0.hh"
15 #include "JFit/JGandalf.hh"
16 #include "JFit/JPoint4D.hh"
17 #include "JFit/JMEstimator.hh"
18 #include "JFit/JRegressor.hh"
19 #include "JFit/JFitToolkit.hh"
20 
21 #include "Jeep/JMessage.hh"
22 
23 /**
24  * \file
25  * Data regression method for JFIT::JPoint4D from a bright point isoptropic emission PDF.
26  *
27  * \author adomi
28  */
29 
30 namespace JFIT {}
31 namespace JPP { using namespace JFIT; }
32 
33 namespace JFIT {
34 
38  using JTOOLS::get_value;
39 
40  /**
41  * Regressor function object for JPoint4D fit using JGandalf minimiser.
42  */
43  template<>
45  public JAbstractRegressor<JPoint4D, JGandalf>
46  {
48 
53 
54 
55  /**
56  * Parameterized constructor
57  *
58  * The PDF file descriptor should contain the wild card character JPHYSICS::WILD_CARD which
59  * will be replaced by the corresponding PDF types.
60  *
61  * \param fileDescriptor PDF file descriptor
62  * \param TTS TTS [ns]
63  * \param numberOfPoints number of points for Gauss-Hermite integration of TTS
64  * \param epsilon precision for Gauss-Hermite integration of TTS
65  */
66  JRegressor(const std::string& fileDescriptor,
67  const double TTS,
68  const int numberOfPoints = 25,
69  const double epsilon = 1.0e-10):
70  E_GeV(0.0)
71  {
72  using namespace std;
73  using namespace JPP;
74 
75  const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(JMATH::zero));
76 
77  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
78 
79  try {
80 
81  const string file_name = getFilename(fileDescriptor, pdf_t[i]);
82 
83  NOTICE("loading PDF from file " << file_name << "... " << flush);
84 
85  pdf[i].load(file_name.c_str());
86 
87  NOTICE("OK" << endl);
88 
89  pdf[i].setExceptionHandler(supervisor);
90  }
91  catch(const JException& error) {
92  FATAL(error.what() << endl);
93  }
94  }
95 
96  // Add PDFs
97  for (int i = 1; i < NUMBER_OF_PDFS; i += 2) {
98 
99  pdf[ i ].add(pdf[i-1]);
100 
101  JPDF_t buffer;
102 
103  pdf[i-1].swap(buffer);
104 
105  if (TTS > 0.0) {
106  pdf[i].blur(TTS, numberOfPoints, epsilon);
107  } else if (TTS < 0.0) {
108  ERROR("Illegal value of TTS [ns]: " << TTS << endl);
109  }
110  }
111  }
112 
113  /**
114  * Fit function.
115  * This method is used to determine the chi2 and gradient of given hit with respect a bright point emitting isotropically
116  *
117  * JHitW0 refers to a data structure which should have the following member methods:
118  * - double getX(); // [m]
119  * - double getY(); // [m]
120  * - double getZ(); // [m]
121  * - double getDX(); // [u]
122  * - double getDY(); // [u]
123  * - double getDZ(); // [u]
124  * - double getT(); // [ns]
125  *
126  * \param vx shower vertex
127  * \param hit hit
128  * \return chi2 and gradient
129  */
130  result_type operator()(const JPoint4D& vx, const JHitW0& 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  if (ct > +1.0) { ct = +1.0; }
141  if (ct < -1.0) { ct = -1.0; }
142 
143  const double t = vx.getT() + (D.getLength() * getIndexOfRefraction() * getInverseSpeedOfLight());
144 
145  const double dt = T_ns.constrain(hit.getT() - t);
146 
147  JPDF_t::result_type H0 = getH0(hit.getR(), dt); // getH0 = Get background hypothesis value
148  JPDF_t::result_type H1 = getH1(D.getLength(), ct, dt, E_GeV); // getH1 = Get signal hypothesis value
149 
150  if (get_value(H1) >= Vmax_npe) {
151  H1 *= Vmax_npe / get_value(H1);
152  }
153 
154  H1 += H0; // now H1 is signal + background
155 
157 
158  result.chi2 = H1.getChi2() - H0.getChi2(); // Likelihood ratio
159 
160  /*
161  * Here it is evaluated: d(chi2)/d(ct) * d(ct)/d(x0,y0,z0,t0)
162  */
163  result.gradient = JPoint4D(JVector3D(-getIndexOfRefraction() * D.getX() / D.getLength(), // d(ct)/d(x0)
164  -getIndexOfRefraction() * D.getY() / D.getLength(), // d(ct)/d(y0)
165  -getIndexOfRefraction() * D.getZ() / D.getLength()), // d(ct)/d(z0)
166  getSpeedOfLight()); // d(ct)/d(t0)
167 
168  result.gradient.mul(getInverseSpeedOfLight() * (H1.getDerivativeOfChi2() -
169  H0.getDerivativeOfChi2())); // x d(chi2)/d(ct1)
170 
171  return result;
172 
173  }
174 
175  /**
176  * Get background hypothesis value for time differentiated PDF.
177  *
178  * \param R_Hz rate [Hz]
179  * \param t1 time [ns]
180  * \return hypothesis value
181  */
182  JPDF_t::result_type getH0(const double R_Hz,
183  const double t1) const
184  {
185  using namespace JPP;
186 
187  return JPDF_t::result_type(R_Hz * 1e-9, t1, T_ns);
188  }
189 
190  /**
191  * Get signal hypothesis value for bright point emission PDF.
192  *
193  * \param D HIT distance from shower vertex [m]
194  * \param ct cosine of the HIT angle
195  * \param t arrival time of the light
196  * \param E shower energy [GeV]
197  * \return hypothesis value
198  */
200  const double ct,
201  const double t,
202  const double E) const
203  {
204  using namespace JPP;
205 
207 
208  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
209 
210  if (!pdf[i].empty() && D <= pdf[i].getXmax()) {
211 
212  try {
213 
214  JPDF_t::result_type y1 = E * pdf[i](std::max(D, pdf[i].getXmin()), ct, t);
215 
216  if (get_value(y1) > 0.0) {
217  h1 += y1;
218  }
219 
220  }
221  catch(JLANG::JException& error) {
222  ERROR(error << std::endl);
223  }
224  }
225  }
226 
227  return h1;
228  }
229 
230  /**
231  * Get maximal road width of PDF.
232  *
233  * \return road width [m]
234  */
235  inline double getRmax() const
236  {
237  using namespace JPP;
238 
239  double xmax = 0.0;
240 
241  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
242 
243  if (!pdf[i].empty() && pdf[i].getXmax() > xmax) {
244  xmax = pdf[i].getXmax();
245  }
246 
247  }
248 
249  return xmax;
250  }
251 
252  static JTimeRange T_ns; //!< Time window with respect to Cherenkov hypothesis [ns]
253  static double Vmax_npe; //!< Maximal integral of PDF [npe]
254 
255  static const int NUMBER_OF_PDFS = 2;
256 
257  static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
258 
259  JPDF_t pdf[NUMBER_OF_PDFS]; //!< PDF
260 
261  double E_GeV; //!< Energy of the shower [GeV]
262  };
263 
264 
265  /**
266  * PDF types.
267  */
270 
271  /**
272  * Default values.
273  */
275  double JRegressor<JPoint4D, JGandalf>::Vmax_npe = std::numeric_limits<double>::max();
276 
277 }
278 
279 #endif
Auxiliary methods to evaluate Poisson probabilities and chi2.
Template definition of a data regressor of given model.
Definition: JRegressor.hh:68
double getT() const
Get calibrated time of hit.
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.
do echo Generating $dir eval D
Definition: JDrawLED.sh:50
Auxiliary methods for PDF calculations.
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:32
JPHYSICS::JPDFTable< JFunction1D_t, JPDFMapList_t > JPDF_t
double getIndexOfRefraction()
Get average index of refraction of water.
Definition: JConstants.hh:111
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...
const double getSpeedOfLight()
Number of bytes in a gigabyte.
Definition: JConstants.hh:89
Data structure for vertex fit.
Definition: JPoint4D.hh:22
const JDirection3D & getDirection() const
Get direction.
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:69
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.
JRange< double > JTimeRange
Type definition for time range.
Numbering scheme for PDF types.
const double getInverseSpeedOfLight()
Get inverse speed of light.
Definition: JConstants.hh:100
Type definition of a 1st degree polynomial interpolation based on a JGridMap implementation.
Constants.
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:33
return result
Definition: JPolint.hh:695
JRegressor(const std::string &fileDescriptor, const double TTS, const int numberOfPoints=25, const double epsilon=1.0e-10)
Parameterized constructor.
Auxiliary class for a hit with background rate value.
Definition: JHitW0.hh:21
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:129
double getR() const
Get rate.
Definition: JHitW0.hh:52
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
#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].
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:35
transformablemultifunction_type::result_type result_type
Definition: JPDFTable.hh:49
virtual const char * what() const
Get error message.
Definition: JException.hh:48
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition: JVertex3D.hh:144
Abstract class for global fit method.
Definition: JRegressor.hh:75
result_type operator()(const JPoint4D &vx, const JHitW0 &hit) const
Fit function.
JResultEvaluator< JResult_t >::result_type get_value(const JResult_t &value)
Helper method to recursively evaluate a to function value.
Definition: JResult.hh:936
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
then usage $script[input file[working directory[option]]] nWhere option can be E
Definition: JMuonPostfit.sh:37
static JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].