Jpp  17.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JShowerEnergyRegressor.hh
Go to the documentation of this file.
1 #ifndef __JFIT__JSHOWERENERGYREGRESSOR__
2 #define __JFIT__JSHOWERENERGYREGRESSOR__
3 
4 #include "JPhysics/JPDFTypes.hh"
5 #include "JPhysics/JPDFTable.hh"
7 #include "JPhysics/JNPETable.hh"
8 
9 #include "JPhysics/JConstants.hh"
10 #include "JTools/JResult.hh"
11 
12 #include "JMath/JZero.hh"
13 
14 #include "JGeometry3D/JAxis3D.hh"
15 
16 #include "JFit/JSimplex.hh"
17 #include "JFit/JShower3EZ.hh"
18 #include "JFit/JMEstimator.hh"
19 #include "JFit/JRegressor.hh"
20 #include "JFit/JFitToolkit.hh"
21 #include "JFit/JShowerNPE.hh"
22 #include "JFit/JShowerNPEHit.hh"
23 #include "JFit/JTimeRange.hh"
24 
25 #include "Jeep/JMessage.hh"
26 
27 /**
28  * \file
29  * Data regression method for JFIT::JShower3EZ only focused on the energy estimation from
30  * a bright point emission PDF and considering the hit/non hit information for each PMT.
31  *
32  * \author adomi
33  */
34 
35 namespace JFIT {}
36 namespace JPP { using namespace JFIT; }
37 
38 namespace JFIT {
39 
43  using JTOOLS::get_value;
45 
46  /**
47  * Regressor function object for JShower3EZ fit using JSimplex minimiser.
48  */
49  template<>
51  public JAbstractRegressor<JEnergy, JSimplex>
52  {
54 
59 
61 
62  /**
63  * Parameterized constructor
64  *
65  * The PDF file descriptor should contain the wild card character JPHYSICS::WILD_CARD which
66  * will be replaced by the corresponding PDF types listed in JRegressor<JEnergy, JSimplex>::pdf_t.
67  *
68  * \param fileDescriptor PDF file descriptor
69  */
70 
71  JRegressor(const std::string& fileDescriptor):
72  estimator(new JMEstimatorNull())
73  {
74  using namespace std;
75  using namespace JPP;
76 
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 string file_name = getFilename(fileDescriptor, pdf_t[i]);
87 
88  NOTICE("loading PDF from file " << file_name << "... " << flush);
89 
90  pdf.load(file_name.c_str());
91 
92  NOTICE("OK" << endl);
93 
94  pdf.setExceptionHandler(supervisor);
95 
96  Y.push_back(JNPE_t(pdf));
97  }
98  catch(const JException& error) {
99  FATAL(error.what() << endl);
100  }
101  }
102 
103  // Add PDFs
104 
105  for (int i = 1; i < NUMBER_OF_PDFS; i += 2) {
106  Y[i].add(Y[i-1]);
107  }
108 
109  Y.erase(Y.begin());
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 x energy
117  * \param npe number of photoelectrons
118  * \return chi2
119  */
120  double operator()(const JEnergy& x, const JShowerNPEHit& npe) const
121  {
122  using namespace JPP;
123 
124  const double E = x.getE();
125  const double u = npe.getChi2(E);
126 
127  return estimator->getRho(u);
128  }
129 
130  /**
131  * Create data structure for handling light yields for PMT.
132  *
133  * \param axis PMT axis
134  * \param R_Hz singles rate [Hz]
135  * \return light yields
136  */
137  inline JShowerNPE getNPE(const JAxis3D& axis,
138  const double R_Hz) const
139  {
140  using namespace JPP;
141 
142  const JPosition3D D(axis.getPosition());
143  const JDirection3D U(axis.getDirection());
144 
145  const double U_length = std::sqrt(U.getDX()*U.getDX() +
146  U.getDY()*U.getDY() +
147  U.getDZ()*U.getDZ());
148 
149  const double ct = U.getDot(D) / (D.getLength()*U_length);
150 
151  const double y = getNPE(Y, D.getLength(), ct);
152 
153  return JShowerNPE(getN(T_ns, R_Hz * 1.0e-9), y);
154  }
155 
156 
157  /**
158  * Get number of photo-electrons.
159  *
160  * \param NPE NPE tables
161  * \param D PMT distance from shower [m]
162  * \param cd cosine of the PMT angle wrt the photon direction
163  * \return number of photo-electrons
164  */
165  static inline double getNPE(const std::vector<JNPE_t>& NPE,
166  const double D,
167  const double cd)
168  {
169  double npe = 0.0;
170 
171  for (std::vector<JNPE_t>::const_iterator i = NPE.begin(); i != NPE.end(); ++i) {
172 
173  if (D <= i->getXmax()) {
174 
175  try {
176 
177  const double y = get_value((*i)(std::max(D, i->getXmin()), cd));
178 
179  if (y > 0.0) {
180  npe += y;
181  }
182  }
183  catch(const JLANG::JException& error) {
184  ERROR(error << std::endl);
185  }
186  }
187  }
188 
189  return npe;
190  }
191 
192 
193  static JTimeRange T_ns; //!< Time window with respect to Cherenkov hypothesis [ns]
194  static double Vmax_npe; //!< Maximal integral of PDF [npe]
195 
196  static const int NUMBER_OF_PDFS = 2;
197 
198  static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
199 
200  std::vector<JNPE_t> Y; //!< light from EM showers
201 
203  };
204 
205  /**
206  * PDF types.
207  */
210 
211  /**
212  * Default values.
213  */
215  double JRegressor<JEnergy, JSimplex>::Vmax_npe = std::numeric_limits<double>::max();
216 }
217 
218 #endif
Auxiliary methods to evaluate Poisson probabilities and chi2.
Template definition of a data regressor of given model.
Definition: JRegressor.hh:68
double getE() const
Get energy.
Definition: JEnergy.hh:170
double getChi2(const double E_GeV) const
Get chi2.
Type definition of a spline interpolation method based on a JCollection with JResultPDF result type...
General exception.
Definition: JException.hh:23
void load(const char *file_name)
Load from input file.
General purpose data regression method.
JRegressor(const std::string &fileDescriptor)
Parameterized constructor.
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
Null M-estimator.
Definition: JMEstimator.hh:92
Auxiliary methods for PDF calculations.
JTOOLS::JMAPLIST< JTOOLS::JPolint1FunctionalMap, JTOOLS::JPolint1FunctionalGridMap >::maplist JMapList_t
then usage E
Definition: JMuonPostfit.sh:35
static double Vmax_npe
Maximal integral of PDF [npe].
This include file containes various data structures that can be used as specific return types for the...
const JDirection3D & getDirection() const
Get direction.
double operator()(const JEnergy &x, const JShowerNPEHit &npe) const
Fit function.
std::vector< JNPE_t > Y
light from EM showers
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
direct light from bright point
Definition: JPDFTypes.hh:42
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
JShowerNPE getNPE(const JAxis3D &axis, const double R_Hz) const
Create data structure for handling light yields for PMT.
Definition of zero value for any class.
Numbering scheme for PDF types.
Axis object.
Definition: JAxis3D.hh:38
Type definition of a 1st degree polynomial interpolation based on a JGridMap implementation.
The template JSharedPointer class can be used to share a pointer to an object.
Type definition of a 1st degree polynomial interpolation based on a JMap implementation.
Multi-dimensional PDF table for arrival time of Cherenkov light.
Definition: JPDFTable.hh:40
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
then awk string
Physics constants.
static JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
JPDFType_t
PDF types.
Definition: JPDFTypes.hh:24
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:108
General purpose messaging.
scattered light from bright point
Definition: JPDFTypes.hh:43
#define FATAL(A)
Definition: JMessage.hh:67
void setExceptionHandler(const typename function_type::supervisor_type &supervisor)
Set the supervisor for handling of exceptions.
virtual const char * what() const override
Get error message.
Definition: JException.hh:48
Simple fit method based on Powell&#39;s algorithm, see reference: Numerical Recipes in C++...
Definition: JSimplex.hh:42
JPHYSICS::JNPETable< double, double, JMapList_t > JNPE_t
Auxiliary class for simultaneously handling light yields and response of PMT.
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:128
Data structure for fit of energy.
Definition: JEnergy.hh:28
double getNPE(const Hit &hit)
Get true charge of hit.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
Auxiliary class for handling EM shower light yield.
Definition: JShowerNPE.hh:25
double u[N+1]
Definition: JPolint.hh:776
Abstract class for global fit method.
Definition: JRegressor.hh:75
JLANG::JSharedPointer< JMEstimator > estimator
M-Estimator function.
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
JPHYSICS::JPDFTable< JFunction1D_t, JMapList_t > JPDF_t
Maximum likelihood estimator (M-estimators).
static double getNPE(const std::vector< JNPE_t > &NPE, const double D, const double cd)
Get number of photo-electrons.
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [s]).
Custom class for integrated values of the PDF of the arrival time of Cherenkov light.
Definition: JNPETable.hh:39