Jpp  15.0.1-rc.1-highQE
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 JEnergy fit.
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(JK40(T_ns, R_Hz), y1, yA, yB, z);
162  }
163 
164 
165  /**
166  * Create data structure for handling light yields for set of PMTs.
167  * Note that the PMT geometry should be relative to the muon trajectory,
168  * conform method JGEOMETRY3D::JAxis3D::transform.
169  *
170  * \param __begin begin of PMTs
171  * \param __end end of PMTs
172  * \param rates_Hz K40 singles and multiples rates [Hz]
173  * \return light yields
174  */
175  template<class T>
176  inline JNPE getNPE(T __begin,
177  T __end,
178  const JK40Rates& rates_Hz) const
179  {
180  using namespace std;
181  using namespace JPP;
182 
183  double y1 = 0.0;
184  double yA = 0.0;
185  double yB = 0.0;
186  double z = 0.0;
187 
188  for (T i = __begin; i != __end; ++i) {
189 
190  const JNPE npe = this->getNPE(*i, rates_Hz.getSinglesRate());
191  const double x = i->getX();
192  const double y = i->getY();
193  const double R = sqrt(x*x + y*y);
194 
195  y1 += npe.getY1();
196  yA += npe.getYA();
197  yB += npe.getYB();
198  z += i->getZ() - R / getTanThetaC();
199  }
200 
201  const int N = distance(__begin, __end);
202 
203  return JNPE(JK40(T_ns, N, rates_Hz), y1, yA, yB, z / N);
204  }
205 
206 
207  /**
208  * Get maximal road width of NPE.
209  *
210  * \return road width [m]
211  */
212  inline double getRmax() const
213  {
214  return std::max(getRmax(Y1), std::max(getRmax(YA), getRmax(YB)));
215  }
216 
217 
218  std::vector<JNPE_t> Y1; //!< light from muon
219  std::vector<JNPE_t> YA; //!< light from delta-rays
220  std::vector<JNPE_t> YB; //!< light from EM showers
221 
222  static JTimeRange T_ns; //!< Time window with respect to Cherenkov hypothesis [ns]
223 
224 
225  static const int NUMBER_OF_PDFS = 6;
226 
227  static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
228 
230 
231 
232  protected:
233  /**
234  * Get maximal road width of PDF.
235  *
236  * \param NPE NPE tables
237  * \return road width [m]
238  */
239  static inline double getRmax(const std::vector<JNPE_t>& NPE)
240  {
241  double xmax = 0.0;
242 
243  for (std::vector<JNPE_t>::const_iterator i = NPE.begin(); i != NPE.end(); ++i) {
244  if (!i->empty() && i->getXmax() > xmax) {
245  xmax = i->getXmax();
246  }
247  }
248 
249  return xmax;
250  }
251 
252 
253  /**
254  * Get number of photo-electrons.
255  *
256  * \param NPE NPE tables
257  * \param R distance between muon and PMT [m]
258  * \param theta zenith angle orientation PMT [rad]
259  * \param phi azimuth angle orientation PMT [rad]
260  * \return number of photo-electrons
261  */
262  static inline double getNPE(const std::vector<JNPE_t>& NPE,
263  const double R,
264  const double theta,
265  const double phi)
266  {
267  using JTOOLS::get_value;
268 
269  double npe = 0.0;
270 
271  for (std::vector<JNPE_t>::const_iterator i = NPE.begin(); i != NPE.end(); ++i) {
272 
273  if (R <= i->getXmax()) {
274 
275  try {
276 
277  const double y = get_value((*i)(std::max(R, i->getXmin()), theta, phi));
278 
279  if (y > 0.0) {
280  npe += y;
281  }
282  }
283  catch(const JLANG::JException& error) {
284  ERROR(error << std::endl);
285  }
286  }
287  }
288 
289  return npe;
290  }
291  };
292 
293 
294  /**
295  * PDF types.
296  */
303 
304 
305  /**
306  * Time range.
307  */
309 }
310 
311 #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.
Auxiliary methods for PDF calculations.
std::vector< JNPE_t > YA
light from delta-rays
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
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]).
double getYB() const
Get light yield due to bremsstrahlung.
Definition: JNPE.hh:92
direct light from EM showers
Definition: JPDFTypes.hh:32
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
JNPE getNPE(T __begin, T __end, const JK40Rates &rates_Hz) const
Create data structure for handling light yields for set of PMTs.
Auxiliary class for converting various rates to expectation values of the number of hits within a giv...
Definition: JK40.hh:29
double getChi2(const double E_GeV) const
Get chi2.
Definition: JNPEHit.hh:87
double getPhi() const
Get phi angle.
Definition: JVersor3D.hh:144
then usage E
Definition: JMuonPostfit.sh:35
direct light from muon
Definition: JPDFTypes.hh:29
Various implementations of functional maps.
double getYA() const
Get light yield due to delta-rays.
Definition: JNPE.hh:81
Numbering scheme for PDF types.
Axis object.
Definition: JAxis3D.hh:38
double getY1() const
Get light yield due to muon itself.
Definition: JNPE.hh:70
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
do set_variable OUTPUT_DIRECTORY $WORKDIR T
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:28
#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.
double getSinglesRate() const
Get singles rate.
Definition: JK40Rates.hh:71
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:739
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 K40 rates.
Definition: JK40Rates.hh:41
Auxiliary class for handling debug parameter within a class.
Definition: JMessage.hh:44
std::vector< JNPE_t > YB
light from EM showers