Jpp  16.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEnergyRegressor.hh
Go to the documentation of this file.
1 #ifndef __JFIT__JENERGYREGRESSOR__
2 #define __JFIT__JENERGYREGRESSOR__
3 
4 #include <string>
5 
7 #include "JPhysics/JPDFTypes.hh"
8 #include "JPhysics/JPDFTable.hh"
9 #include "JPhysics/JNPETable.hh"
10 #include "JPhysics/JPDFToolkit.hh"
11 #include "JPhysics/JConstants.hh"
12 #include "JTools/JFunction1D_t.hh"
14 #include "JGeometry3D/JAxis3D.hh"
15 #include "JFit/JRegressor.hh"
16 #include "JFit/JEnergy.hh"
17 #include "JFit/JNPE.hh"
18 #include "JFit/JNPEHit.hh"
19 #include "JFit/JMEstimator.hh"
20 #include "JFit/JFitToolkit.hh"
21 #include "JFit/JTimeRange.hh"
22 #include "Jeep/JMessage.hh"
23 
24 
25 /**
26  * \file
27  * Data regression method for JFIT::JEnergy.
28  * \author mdejong
29  */
30 namespace JFIT {}
31 namespace JPP { using namespace JFIT; }
32 
33 namespace JFIT {
34 
43 
44 
45  /**
46  * Regressor function object for fit of muon energy.
47  */
48  template<>
49  struct JRegressor<JEnergy> :
50  public JAbstractRegressor<JEnergy>
51  {
54 
59 
60 
61  /**
62  * Constructor.
63  *
64  * The PDF file descriptor should contain the wild card character JPHYSICS::WILD_CARD
65  * which will be replaced by the PDF types listed in JRegressor<JEnergy, JSimplex>::pdf_t.
66  *
67  * \param fileDescriptor PDF file descriptor
68  */
69  JRegressor(const std::string& fileDescriptor) :
70  estimator(new JMEstimatorNormal())
71  {
72  using namespace std;
73  using namespace JPP;
74 
75  typedef JSplineFunction1D_t JFunction1D_t;
76  typedef JPDFTable<JFunction1D_t, JNPEMaplist_t> JPDF_t;
77 
78  const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(JMATH::zero));
79 
80  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
81 
82  try {
83 
84  JPDF_t pdf;
85 
86  const JPDFType_t type = pdf_t[i];
87  const string file_name = getFilename(fileDescriptor, type);
88 
89  NOTICE("loading PDF from file " << file_name << "... " << flush);
90 
91  pdf.load(file_name.c_str());
92 
93  NOTICE("OK" << endl);
94 
95  pdf.setExceptionHandler(supervisor);
96 
97  if (is_bremsstrahlung(type))
98  YB.push_back(JNPE_t(pdf));
99  else if (is_deltarays(type))
100  YA.push_back(JNPE_t(pdf));
101  else
102  Y1.push_back(JNPE_t(pdf));
103  }
104  catch(const JLANG::JException& error) {
105  FATAL(error.what() << endl);
106  }
107  }
108 
109  // Add PDFs
110 
111  if (Y1.size() == 2) { Y1[1].add(Y1[0]); Y1.erase(Y1.begin()); }
112  if (YA.size() == 2) { YA[1].add(YA[0]); YA.erase(YA.begin()); }
113  if (YB.size() == 2) { YB[1].add(YB[0]); YB.erase(YB.begin()); }
114  }
115 
116 
117  /**
118  * Fit function.
119  * This method is used to determine chi2 of given number of photo-electrons for given energy of muon.
120  *
121  * \param x energy
122  * \param npe npe
123  * \return chi2
124  */
125  inline double operator()(const JEnergy& x, const JNPEHit& npe) const
126  {
127  const double E = x.getE();
128  const double u = npe.getChi2(E);
129 
130  return estimator->getRho(u);
131  }
132 
133 
134  /**
135  * Create data structure for handling light yields for PMT.
136  * Note that the PMT geometry should be relative to the muon trajectory,
137  * conform method JGEOMETRY3D::JAxis3D::transform.
138  *
139  * \param axis PMT axis
140  * \param R_Hz singles rate [Hz]
141  * \return light yields
142  */
143  inline JNPE getNPE(const JAxis3D& axis,
144  const double R_Hz) const
145  {
146  using namespace std;
147  using namespace JPP;
148 
149  const double x = axis.getX();
150  const double y = axis.getY();
151  const double R = sqrt(x*x + y*y);
152  const double z = axis.getZ() - R / getTanThetaC();
153 
154  const double theta = axis.getTheta();
155  const double phi = fabs(axis.getPhi());
156 
157  const double y1 = getNPE(Y1, R, theta, phi);
158  const double yA = getNPE(YA, R, theta, phi);
159  const double yB = getNPE(YB, R, theta, phi);
160 
161  return JNPE(getN(T_ns, R_Hz * 1.0e-9), y1, yA, yB, z);
162  }
163 
164 
165  /**
166  * Get maximal road width of NPE.
167  *
168  * \return road width [m]
169  */
170  inline double getRmax() const
171  {
172  return std::max(getRmax(Y1), std::max(getRmax(YA), getRmax(YB)));
173  }
174 
175 
176  std::vector<JNPE_t> Y1; //!< light from muon
177  std::vector<JNPE_t> YA; //!< light from delta-rays
178  std::vector<JNPE_t> YB; //!< light from EM showers
179 
180  static JTimeRange T_ns; //!< Time window with respect to Cherenkov hypothesis [ns]
181 
182 
183  static const int NUMBER_OF_PDFS = 6;
184 
185  static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
186 
188 
189 
190  protected:
191  /**
192  * Get maximal road width of PDF.
193  *
194  * \param NPE NPE tables
195  * \return road width [m]
196  */
197  static inline double getRmax(const std::vector<JNPE_t>& NPE)
198  {
199  double xmax = 0.0;
200 
201  for (std::vector<JNPE_t>::const_iterator i = NPE.begin(); i != NPE.end(); ++i) {
202  if (!i->empty() && i->getXmax() > xmax) {
203  xmax = i->getXmax();
204  }
205  }
206 
207  return xmax;
208  }
209 
210 
211  /**
212  * Get number of photo-electrons.
213  *
214  * \param NPE NPE tables
215  * \param R distance between muon and PMT [m]
216  * \param theta zenith angle orientation PMT [rad]
217  * \param phi azimuth angle orientation PMT [rad]
218  * \return number of photo-electrons
219  */
220  static inline double getNPE(const std::vector<JNPE_t>& NPE,
221  const double R,
222  const double theta,
223  const double phi)
224  {
225  using JTOOLS::get_value;
226 
227  double npe = 0.0;
228 
229  for (std::vector<JNPE_t>::const_iterator i = NPE.begin(); i != NPE.end(); ++i) {
230 
231  if (R <= i->getXmax()) {
232 
233  try {
234 
235  const double y = get_value((*i)(std::max(R, i->getXmin()), theta, phi));
236 
237  if (y > 0.0) {
238  npe += y;
239  }
240  }
241  catch(const JLANG::JException& error) {
242  ERROR(error << std::endl);
243  }
244  }
245  }
246 
247  return npe;
248  }
249  };
250 
251 
252  /**
253  * PDF types.
254  */
261 
262 
263  /**
264  * Time range.
265  */
267 }
268 
269 #endif
Auxiliary methods to evaluate Poisson probabilities and chi2.
Template definition of a data regressor of given model.
Definition: JRegressor.hh:68
JPHYSICS::JNPETable< double, double, JNPEMaplist_t > JNPE_t
double getE() const
Get energy.
Definition: JEnergy.hh:170
General exception.
Definition: JException.hh:23
General purpose data regression method.
double getN(const JRange< T > &range, const double R)
Get expected number of occurrences due to given rate within specified interval.
Definition: JRange.hh:713
Auxiliary methods for PDF calculations.
then usage E
Definition: JMuonPostfit.sh:35
std::vector< JNPE_t > YA
light from delta-rays
static double getNPE(const std::vector< JNPE_t > &NPE, const double R, const double theta, const double phi)
Get number of photo-electrons.
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [ns]).
direct light from EM showers
Definition: JPDFTypes.hh:32
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
double getChi2(const double E_GeV) const
Get chi2.
Definition: JNPEHit.hh:87
double getPhi() const
Get phi angle.
Definition: JVersor3D.hh:144
direct light from muon
Definition: JPDFTypes.hh:29
Various implementations of functional maps.
Numbering scheme for PDF types.
Axis object.
Definition: JAxis3D.hh:38
The template JSinglePointer class can be used to hold a pointer to an object.
bool is_bremsstrahlung(const int pdf)
Test if given PDF type corresponds to Cherenkov light from Bremsstrahlung.
Definition: JPDFTypes.hh:163
JNPE getNPE(const JAxis3D &axis, const double R_Hz) const
Create data structure for handling light yields for PMT.
scattered light from muon
Definition: JPDFTypes.hh:30
Type definition of a 1st degree polynomial interpolation based on a JGridMap implementation.
JLANG::JSinglePointer< JMEstimator > estimator
M-Estimator function.
JRegressor(const std::string &fileDescriptor)
Constructor.
Type definition of a 1st degree polynomial interpolation based on a JMap implementation.
std::vector< JNPE_t > Y1
light from muon
static JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
double operator()(const JEnergy &x, const JNPEHit &npe) const
Fit function.
double getTheta() const
Get theta angle.
Definition: JVersor3D.hh:128
scattered light from delta-rays
Definition: JPDFTypes.hh:36
Auxiliary class for handling various light yields.
Definition: JNPE.hh:29
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
Physics constants.
Auxiliary class for simultaneously handling light yields and response of PMT.
Definition: JNPEHit.hh:19
scattered light from EM showers
Definition: JPDFTypes.hh:33
double getY() const
Get y position.
Definition: JVector3D.hh:104
Normal M-estimator.
Definition: JMEstimator.hh:66
int debug
debug level
Definition: JSirene.cc:63
JPDFType_t
PDF types.
Definition: JPDFTypes.hh:27
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:108
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:43
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
direct light from delta-rays
Definition: JPDFTypes.hh:35
double getRmax() const
Get maximal road width of NPE.
virtual const char * what() const override
Get error message.
Definition: JException.hh:48
static double getRmax(const std::vector< JNPE_t > &NPE)
Get maximal road width of PDF.
JTOOLS::JMAPLIST< JTOOLS::JPolint1FunctionalMap, JTOOLS::JPolint1FunctionalGridMap, JTOOLS::JPolint1FunctionalGridMap >::maplist JNPEMaplist_t
bool is_deltarays(const int pdf)
Test if given PDF type corresponds to Cherenkov light from delta-rays.
Definition: JPDFTypes.hh:177
double getX() const
Get x position.
Definition: JVector3D.hh:94
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 fit of energy.
Definition: JEnergy.hh:28
double getTanThetaC()
Get average tangent of Cherenkov angle of water corresponding to group velocity.
double getNPE(const Hit &hit)
Get true charge of hit.
double u[N+1]
Definition: JPolint.hh:755
Abstract class for global fit method.
Definition: JRegressor.hh:75
JResultEvaluator< JResult_t >::result_type get_value(const JResult_t &value)
Helper method to recursively evaluate a to function value.
Definition: JResult.hh:998
double getZ() const
Get z position.
Definition: JVector3D.hh:115
Maximum likelihood estimator (M-estimators).
Auxiliary class for handling debug parameter within a class.
Definition: JMessage.hh:44
std::vector< JNPE_t > YB
light from EM showers