Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JShower3EZRegressor.hh
Go to the documentation of this file.
1 #ifndef __JFIT__JSHOWER3EZREGRESSOR__
2 #define __JFIT__JSHOWER3EZREGRESSOR__
3 
4 #include <string>
5 
6 #include <JPhysics/JPDFTypes.hh>
7 #include <JPhysics/JPDFTable.hh>
9 #include <JPhysics/JNPETable.hh>
10 
11 #include <JTools/JFunction1D_t.hh>
13 #include <JTools/JConstants.hh>
14 
15 #include <JGeometry3D/JVector3D.hh>
16 #include <JGeometry3D/JVersor3D.hh>
17 
18 #include "JMath/JZero.hh"
19 
20 #include "JFit/JTimeRange.hh"
21 #include "JFit/JPMTW0.hh"
22 #include "JFit/JSimplex.hh"
23 #include "JFit/JMEstimator.hh"
24 #include "JFit/JRegressor.hh"
25 #include "JFit/JShower3EZ.hh"
26 
27 #include "Jeep/JMessage.hh"
28 
29 /**
30  * \file
31  * Data regression method for JFIT::JShower3Z.
32  */
33 
34 namespace JFIT {
35 
39 
40  /**
41  * Regressor function object for JShower3EZ fit using JSimplex minimiser.
42  */
43  template<>
45  public JAbstractRegressor<JShower3EZ, JSimplex>
46  {
48 
55 
61 
62  /**
63  * Default constructor
64  */
66  {}
67 
68  /**
69  * Parameterized constructor
70  *
71  * The PDF file descriptor should contain the wild card character JPHYSICS::WILD_CARD which
72  * will be replaced by the corresponding PDF types listed in JRegressor<JShower3Z, JGandalf>::pdf_t.
73  *
74  * \param fileDescriptor PDF file descriptor
75  */
76 
77  JRegressor(const std::string& fileDescriptor):
78  estimator(new JMEstimatorLorentzian())
79  {
80  using namespace std;
81  using namespace JPHYSICS;
82 
83  const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(JMATH::zero));
84 
85  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
86 
87  try {
88 
89  const string file_name = getFilename(fileDescriptor, pdf_t[i]);
90 
91  NOTICE("loading PDF from file " << file_name << "... " << flush);
92 
93  pdf[i].load(file_name.c_str());
94 
95  NOTICE("OK" << endl);
96 
97  pdf[i].setExceptionHandler(supervisor);
98 
99  }
100  catch(const JException& error) {
101  FATAL(error.what() << endl);
102  }
103  }
104 
105  // Add PDFs
106  for (int i = 0; i < NUMBER_OF_PDFS; i++) {
107  npe[ i ] = JNPE_t(pdf[i]);
108  }
109 
110  }
111 
112  /**
113  * Fit function.
114  * This method is used to determine the chi2 of given PMT with respect to shower hypothesis.
115  *
116  * \param shower shower
117  * \param pmt pmt
118  * \return chi2
119  */
120  double operator()(const JShower3EZ& shower, const JPMTW0& pmt) const
121  {
122  using namespace JGEOMETRY3D;
123  using namespace JPHYSICS;
124 
125  JVector3D D(pmt.getPosition());
126  JDirection3D U(pmt.getDirection());
127 
128  D.sub(shower.getPosition());
129 
130  const double z = shower.getDirection().getDot(D);
131  const double x = D.getX() - z * shower.getDX();
132  const double y = D.getY() - z * shower.getDY();
133  const double cosDelta = z/D.getLength(); // Delta = angle between shower direction and PMT position
134 
135  U.rotate(JRotation3Z(-atan2(y,x))); // rotate PMT axis to x-z plane
136 
137  const double theta = U.getTheta();
138  const double phi = fabs(U.getPhi());
139 
140  JNPE_t::result_type H0 = getH0(pmt.getR()); // getH0 = Get background hypothesis value for time integrated PDF.
141  JNPE_t::result_type H1 = getH1(D.getLength(), cosDelta, theta, phi, shower.getE()); // getH1 = Get signal hypothesis value for time integrated PDF.
142 
143  if (H1.f >= Vmax_npe) {
144  H1 *= Vmax_npe / H1.f;
145  }
146 
147  H1 += H0; // now H1 is signal + background
148 
149  const bool hit = pmt.getN() != 0;
150  const double u = H1.getChi2(hit); // -log(lik)
151 
152  return estimator->getRho(u);
153  }
154 
155  /**
156  * Get background hypothesis value for time integrated PDF.
157  *
158  * \param R_Hz rate [Hz]
159  * \return hypothesis value
160  */
161  JNPE_t::result_type getH0(const double R_Hz) const
162  {
163  return JNPE_t::result_type(R_Hz * 1e-9 * T_ns.getLength(), 0.0);
164  }
165 
166  /**
167  * Get signal hypothesis value for time integrated PDF.
168  *
169  * \param D PMT distance from shower [m]
170  * \param cosDelta angle between shower direction and PMT position
171  * \param theta PMT zenith angle [deg]
172  * \param phi PMT azimuth angle [deg]
173  * \param E shower energy [GeV]
174  * \return hypothesis value
175  */
176  JNPE_t::result_type getH1(const double D,
177  const double cosDelta,
178  const double theta,
179  const double phi,
180  const double E) const
181  {
183 
184  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
185 
186  if (!npe[i].empty() && D <= npe[i].getXmax()) {
187 
188  try {
189 
190  JNPE_t::result_type y1 = E * npe[i](std::max(D, npe[i].getXmin()), cosDelta, theta, phi);
191 
192  if (y1.f > 0.0) {
193  h1 += y1;
194  }
195 
196  }
197  catch(JLANG::JException& error) {
198  ERROR(error << std::endl);
199  }
200  }
201  }
202 
203  return h1;
204  }
205 
206 
207  /**
208  * Get maximal road width of PDF.
209  *
210  * \return road width [m]
211  */
212  inline double getRmax() const
213  {
214  double xmax = 0.0;
215 
216  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
217 
218  if (!pdf[i].empty() && pdf[i].getXmax() > xmax) {
219  xmax = pdf[i].getXmax();
220  }
221 
222  }
223 
224  return xmax;
225  }
226 
227 
228  static JTimeRange T_ns; //!< Time window with respect to Cherenkov hypothesis [ns]
229  static double Vmax_npe; //!< Maximal integral of PDF [npe]
230 
231  static const int NUMBER_OF_PDFS = 1;
232 
233  static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
234 
235  JPDF_t pdf[NUMBER_OF_PDFS]; //!< PDF
236  JNPE_t npe[NUMBER_OF_PDFS]; //!< PDF
237 
239  };
240 
241  /**
242  * PDF types.
243  */
245 
246 
247  /**
248  * Default values.
249  */
251  double JRegressor<JShower3EZ, JSimplex>::Vmax_npe = std::numeric_limits<double>::max();
252 }
253 
254 #endif
Template definition of a data regressor of given model.
Definition: JRegressor.hh:66
double getDot(const JVersor3Z &dir) const
Get dot product.
Definition: JVersor3Z.hh:270
double getE() const
Get energy.
Definition: JEnergy.hh:144
Type definition of a spline interpolation method based on a JCollection with JResultPDF result type...
General exception.
Definition: JException.hh:40
General purpose data regression method.
double getR() const
Get rate.
Definition: JPMTW0.hh:56
Auxiliary methods for PDF calculations.
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:32
Auxiliary class for handling PMT geometry, rate and response.
Definition: JPMTW0.hh:22
scattered light from EM shower
Definition: JPDFTypes.hh:41
JTOOLS::JMapList< JTOOLS::JPolint1FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint1FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap > > > > JPDFMaplist_t
const JDirection3D & getDirection() const
Get direction.
JTOOLS::JMapList< JTOOLS::JPolint1FunctionalMapH, JTOOLS::JMapList< JTOOLS::JPolint1FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap > > > > JNPEMaplist_t
JNPE_t::result_type getH1(const double D, const double cosDelta, const double theta, const double phi, const double E) const
Get signal hypothesis value for time integrated PDF.
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:94
Type definition of a 1st degree polynomial interpolation based on a JMap implementation.
Definition of zero value for any class.
double getDY() const
Get y direction.
Definition: JVersor3Z.hh:155
Various implementations of functional maps.
JRange< double > JTimeRange
Type definition for time range.
Numbering scheme for PDF types.
Rotation around Z-axis.
Definition: JRotation3D.hh:82
double operator()(const JShower3EZ &shower, const JPMTW0 &pmt) const
Fit function.
Constants.
Data structure for fit of straight line in positive z-direction with energy.
Definition: JShower3EZ.hh:25
The template JSharedPointer class can be used to share a pointer to an object.
Data structure for vector in three dimensions.
Definition: JVector3D.hh:32
Map list.
Definition: JMapList.hh:24
Type definition of a 1st degree polynomial interpolation based on a JMap implementation.
static double Vmax_npe
Maximal integral of PDF [npe].
#define NOTICE(A)
Definition: JMessage.hh:62
direct light from EM shower
Definition: JPDFTypes.hh:40
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:129
JPDFType_t
PDF types.
Definition: JPDFTypes.hh:27
JLANG::JSharedPointer< JMEstimator > estimator
M-Estimator function.
General purpose messaging.
const JVersor3Z & getDirection() const
Get direction.
Definition: JVersor3Z.hh:78
#define FATAL(A)
Definition: JMessage.hh:65
int getN() const
Get number of hits.
Definition: JPMTW0.hh:67
double getRmax() const
Get maximal road width of PDF.
Simple fit method based on Powell&#39;s algorithm, see reference: Numerical Recipes in C++...
Definition: JSimplex.hh:42
double getDX() const
Get x direction.
Definition: JVersor3Z.hh:144
Type definition of a zero degree polynomial interpolation based on a JGridMap implementation.
std::string getFilename(const std::string &file_name)
Get file name part, i.e.
Definition: JeepToolkit.hh:85
JNPE_t::result_type getH0(const double R_Hz) const
Get background hypothesis value for time integrated PDF.
virtual const char * what() const
Get error message.
Definition: JException.hh:65
JPHYSICS::JPDFTable< JFunction1D_t, JPDFMaplist_t > JPDF_t
Abstract class for global fit method.
Definition: JRegressor.hh:73
static JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
Maximum likelihood estimator (M-estimators).
Lorentzian M-estimator.
Definition: JMEstimator.hh:79
JPHYSICS::JNPETable< double, double, JNPEMaplist_t > JNPE_t
JRegressor(const std::string &fileDescriptor)
Parameterized constructor.