Jpp
 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 "JTools/JConstants.hh"
10 #include "JTools/JResult.hh"
11 
12 #include "JMath/JZero.hh"
13 
14 #include "JFit/JSimplex.hh"
15 #include "JFit/JShower3EZ.hh"
16 #include "JFit/JMEstimator.hh"
17 #include "JFit/JRegressor.hh"
18 #include "JFit/JFitToolkit.hh"
19 #include "JFit/JShowerNPE.hh"
20 #include "JFit/JShowerNPEHit.hh"
21 
22 #include "JDetector/JPMT.hh"
23 
24 #include "Jeep/JMessage.hh"
25 
26 /**
27  * \file
28  * Data regression method for JFIT::JShower3EZ only focused on the energy estimation from
29  * a bright point emission PDF and considering the hit/non hit information for each PMT.
30  *
31  * \author adomi
32  */
33 
34 namespace JFIT {}
35 namespace JPP { using namespace JFIT; }
36 
37 namespace JFIT {
38 
42  using JTOOLS::get_value;
43  using JDETECTOR::JPMT;
44 
45  /**
46  * Regressor function object for JShower3EZ fit using JSimplex minimiser.
47  */
48  template<>
50  public JAbstractRegressor<JEnergy, JSimplex>
51  {
53 
58 
60 
61  /**
62  * Parameterized constructor
63  *
64  * The PDF file descriptor should contain the wild card character JPHYSICS::WILD_CARD which
65  * will be replaced by the corresponding PDF types listed in JRegressor<JEnergy, JSimplex>::pdf_t.
66  *
67  * \param fileDescriptor PDF file descriptor
68  */
69 
70  JRegressor(const std::string& fileDescriptor):
71  estimator(new JMEstimatorNull())
72  {
73  using namespace std;
74  using namespace JPP;
75 
76 
77  const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(JMATH::zero));
78 
79  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
80 
81  try {
82 
83  JPDF_t pdf;
84 
85  const string file_name = getFilename(fileDescriptor, pdf_t[i]);
86 
87  NOTICE("loading PDF from file " << file_name << "... " << flush);
88 
89  pdf.load(file_name.c_str());
90 
91  NOTICE("OK" << endl);
92 
93  pdf.setExceptionHandler(supervisor);
94 
95  Y.push_back(JNPE_t(pdf));
96  }
97  catch(const JException& error) {
98  FATAL(error.what() << endl);
99  }
100  }
101 
102  // Add PDFs
103 
104  for (int i = 1; i < NUMBER_OF_PDFS; i += 2) {
105  Y[i].add(Y[i-1]);
106  }
107 
108  Y.erase(Y.begin());
109  }
110 
111  /**
112  * Fit function.
113  * This method is used to determine the chi2 of given PMT with respect to shower hypothesis.
114  *
115  * \param x energy
116  * \param npe number of photoelectrons
117  * \return chi2
118  */
119  double operator()(const JEnergy& x, const JShowerNPEHit& npe) const
120  {
121  using namespace JPP;
122 
123  const double E = x.getE();
124  const double u = npe.getChi2(E);
125 
126  return estimator->getRho(u);
127  }
128 
129  /**
130  * Create data structure for handling light yields for PMT.
131  *
132  * \param pmt PMT
133  * \param R_Hz singles rate [Hz]
134  * \return light yields
135  */
136  inline JShowerNPE getNPE(const JPMT& pmt,
137  const double R_Hz) const
138  {
139  using namespace JPP;
140 
141  const JPosition3D D(pmt.getPosition());
142  const JDirection3D U(pmt.getDirection());
143 
144  const double U_length = std::sqrt(U.getDX()*U.getDX() +
145  U.getDY()*U.getDY() +
146  U.getDZ()*U.getDZ());
147 
148  const double ct = U.getDot(D) / (D.getLength()*U_length);
149 
150  const double y = getNPE(Y, D.getLength(), ct);
151 
152  return JShowerNPE(JK40(T_ns, R_Hz), y);
153  }
154 
155 
156  /**
157  * Get number of photo-electrons.
158  *
159  * \param NPE NPE tables
160  * \param D PMT distance from shower [m]
161  * \param cd cosine of the PMT angle wrt the photon direction
162  * \return number of photo-electrons
163  */
164  static inline double getNPE(const std::vector<JNPE_t>& NPE,
165  const double D,
166  const double cd)
167  {
168  double npe = 0.0;
169 
170  for (std::vector<JNPE_t>::const_iterator i = NPE.begin(); i != NPE.end(); ++i) {
171 
172  if (D <= i->getXmax()) {
173 
174  try {
175 
176  const double y = get_value((*i)(std::max(D, i->getXmin()), cd));
177 
178  if (y > 0.0) {
179  npe += y;
180  }
181  }
182  catch(const JLANG::JException& error) {
183  ERROR(error << std::endl);
184  }
185  }
186  }
187 
188  return npe;
189  }
190 
191 
192  static JTimeRange T_ns; //!< Time window with respect to Cherenkov hypothesis [ns]
193  static double Vmax_npe; //!< Maximal integral of PDF [npe]
194 
195  static const int NUMBER_OF_PDFS = 2;
196 
197  static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
198 
199  std::vector<JNPE_t> Y; //!< light from EM showers
200 
202  };
203 
204  /**
205  * PDF types.
206  */
209 
210  /**
211  * Default values.
212  */
214  double JRegressor<JEnergy, JSimplex>::Vmax_npe = std::numeric_limits<double>::max();
215 }
216 
217 #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:166
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.
do echo Generating $dir eval D
Definition: JDrawLED.sh:50
JRegressor(const std::string &fileDescriptor)
Parameterized constructor.
Null M-estimator.
Definition: JMEstimator.hh:53
Auxiliary methods for PDF calculations.
JTOOLS::JMAPLIST< JTOOLS::JPolint1FunctionalMap, JTOOLS::JPolint1FunctionalGridMap >::maplist JMapList_t
JShowerNPE getNPE(const JPMT &pmt, const double R_Hz) const
Create data structure for handling light yields for PMT.
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.
void setExceptionHandler(const supervisor_type &supervisor)
Set the supervisor for handling of exceptions.
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
Auxiliary class for converting various rates to expectation values of the number of hits within a giv...
Definition: JK40.hh:30
direct light from bright point
Definition: JPDFTypes.hh:45
Definition of zero value for any class.
JRange< double > JTimeRange
Type definition for time range.
esac $JPP_DIR examples JDetector JTransitTime o $OUTPUT_FILE n N $NPE T $TTS_NS d $DEBUG for HISTOGRAM in tts tt2 pmt
Definition: JTransitTime.sh:36
Numbering scheme for PDF types.
Type definition of a 1st degree polynomial interpolation based on a JGridMap implementation.
Constants.
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:39
Data structure for PMT geometry and calibration.
Definition: JPMT.hh:47
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
static JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:129
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
Data structure for PMT geometry and calibration.
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:88
Data structure for fit of energy.
Definition: JEnergy.hh:24
double getNPE(const Hit &hit)
Get true charge of hit.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
Auxiliary class for handling EM shower light yield.
Definition: JShowerNPE.hh:25
virtual const char * what() const
Get error message.
Definition: JException.hh:48
double u[N+1]
Definition: JPolint.hh:706
Abstract class for global fit method.
Definition: JRegressor.hh:75
JLANG::JSharedPointer< JMEstimator > estimator
M-Estimator 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
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.
then usage $script[input file[working directory[option]]] nWhere option can be E
Definition: JMuonPostfit.sh:37
Custom class for integrated values of the PDF of the arrival time of Cherenkov light.
Definition: JNPETable.hh:39