Jpp 20.0.0-rc.9-29-gccc23c492-D
the software that should make you happy
Loading...
Searching...
No Matches
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"
6#include "JPhysics/JPDFToolkit.hh"
7#include "JPhysics/JNPETable.hh"
8
9#include "JPhysics/JConstants.hh"
10#include "JTools/JResult.hh"
11
12#include "JLang/JSharedPointer.hh"
13#include "JMath/JZero.hh"
14
15#include "JGeometry3D/JAxis3D.hh"
16
17#include "JFit/JEnergy.hh"
18#include "JFit/JSimplex.hh"
19#include "JFit/JMEstimator.hh"
20#include "JFit/JRegressor.hh"
21#include "JFit/JFitToolkit.hh"
22#include "JFit/JShowerNPE.hh"
23#include "JFit/JShowerNPEHit.hh"
24#include "JFit/JTimeRange.hh"
25
26#include "Jeep/JMessage.hh"
27
28/**
29 * \file
30 * Data regression method for JFIT::JShower3EZ only focused on the energy estimation from
31 * a bright point emission PDF and considering the hit/non hit information for each PMT.
32 *
33 * \author adomi
34 */
35
36namespace JFIT {}
37namespace JPP { using namespace JFIT; }
38
39namespace JFIT {
40
41 using JPHYSICS::JPDFType_t;
42 using JPHYSICS::DIRECT_LIGHT_FROM_BRIGHT_POINT;
43 using JPHYSICS::SCATTERED_LIGHT_FROM_BRIGHT_POINT;
44 using JTOOLS::get_value;
45 using JGEOMETRY3D::JAxis3D;
46
47 /**
48 * Regressor function object for JShower3EZ fit using JSimplex minimiser.
49 */
50 template<>
52 public JAbstractRegressor<JEnergy, JSimplex>
53 {
54 using JAbstractRegressor<JEnergy, JSimplex>::operator();
55
56 typedef JTOOLS::JSplineFunction1S_t JFunction1D_t;
57 typedef JTOOLS::JMAPLIST<JTOOLS::JPolint1FunctionalMap,
58 JTOOLS::JPolint1FunctionalGridMap>::maplist JMapList_t;
59 typedef JPHYSICS::JPDFTable<JFunction1D_t, JMapList_t> JPDF_t;
60
61 typedef JPHYSICS::JNPETable<double, double, JMapList_t> JNPE_t;
62
63 /**
64 * Parameterized constructor
65 *
66 * The PDF file descriptor should contain the wild card character JPHYSICS::WILDCARD which
67 * will be replaced by the corresponding PDF types listed in JRegressor<JEnergy, JSimplex>::pdf_t.
68 *
69 * \param fileDescriptor PDF file descriptor
70 */
71
72 JRegressor(const std::string& fileDescriptor):
73 estimator(new JMEstimatorNull())
74 {
75 using namespace std;
76 using namespace JPP;
77
78
79 const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(JMATH::zero));
80
81 for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
82
83 try {
84
85 JPDF_t pdf;
86
87 const string file_name = getFilename(fileDescriptor, pdf_t[i]);
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 Y.push_back(JNPE_t(pdf));
98 }
99 catch(const JException& error) {
100 FATAL(error.what() << endl);
101 }
102 }
103
104 // Add PDFs
105
106 for (int i = 1; i < NUMBER_OF_PDFS; i += 2) {
107 Y[i].add(Y[i-1]);
108 }
109
110 Y.erase(Y.begin());
111 }
112
113 /**
114 * Fit function.
115 * This method is used to determine the chi2 of given PMT with respect to shower hypothesis.
116 *
117 * \param x energy
118 * \param npe number of photoelectrons
119 * \return chi2
120 */
121 double operator()(const JEnergy& x, const JShowerNPEHit& npe) const
122 {
123 using namespace JPP;
124
125 const double E = x.getE();
126 const double u = npe.getChi2(E);
127
128 return estimator->getRho(u);
129 }
130
131 /**
132 * Create data structure for handling light yields for PMT.
133 *
134 * \param axis PMT axis
135 * \param R_Hz singles rate [Hz]
136 * \return light yields
137 */
138 inline JShowerNPE getNPE(const JAxis3D& axis,
139 const double R_Hz) const
140 {
141 using namespace JPP;
142
143 const JPosition3D D(axis.getPosition());
144 const JDirection3D U(axis.getDirection());
145
146 const double U_length = std::sqrt(U.getDX()*U.getDX() +
147 U.getDY()*U.getDY() +
148 U.getDZ()*U.getDZ());
149
150 const double ct = U.getDot(D) / (D.getLength()*U_length);
151
152 const double y = getNPE(Y, D.getLength(), ct);
153
154 return JShowerNPE(getN(T_ns, R_Hz * 1.0e-9), y);
155 }
156
157
158 /**
159 * Get number of photo-electrons.
160 *
161 * \param NPE NPE tables
162 * \param D PMT distance from shower [m]
163 * \param cd cosine of the PMT angle wrt the photon direction
164 * \return number of photo-electrons
165 */
166 static inline double getNPE(const std::vector<JNPE_t>& NPE,
167 const double D,
168 const double cd)
169 {
170 double npe = 0.0;
171
172 for (std::vector<JNPE_t>::const_iterator i = NPE.begin(); i != NPE.end(); ++i) {
173
174 if (D <= i->getXmax()) {
175
176 try {
177
178 const double y = get_value((*i)(std::max(D, i->getXmin()), cd));
179
180 if (y > 0.0) {
181 npe += y;
182 }
183 }
184 catch(const JLANG::JException& error) {
185 ERROR(error << std::endl);
186 }
187 }
188 }
189
190 return npe;
191 }
192
193
194 static JTimeRange T_ns; //!< Time window with respect to Cherenkov hypothesis [ns]
195 static double Vmax_npe; //!< Maximal integral of PDF [npe]
196
197 static const int NUMBER_OF_PDFS = 2;
198
199 static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
200
201 std::vector<JNPE_t> Y; //!< light from EM showers
202
203 JLANG::JSharedPointer<JMEstimator> estimator; //!< M-Estimator function
204 };
205
206 /**
207 * PDF types.
208 */
209 const JPDFType_t JRegressor<JEnergy, JSimplex>::pdf_t[] = { DIRECT_LIGHT_FROM_BRIGHT_POINT,
210 SCATTERED_LIGHT_FROM_BRIGHT_POINT };
211
212 /**
213 * Default values.
214 */
216 double JRegressor<JEnergy, JSimplex>::Vmax_npe = std::numeric_limits<double>::max();
217}
218
219#endif
Auxiliary methods to evaluate Poisson probabilities and chi2.
Maximum likelihood estimator (M-estimators).
General purpose data regression method.
Data structure for fit of energy.
Definition JEnergy.hh:31
double getE() const
Get energy.
Definition JEnergy.hh:170
Simple fit method based on Powell's algorithm, see reference: Numerical Recipes in C++,...
Definition JSimplex.hh:44
Auxiliary classes and methods for linear and iterative data regression.
Definition JEnergy.hh:15
Abstract class for global fit method.
Definition JRegressor.hh:79
Null M-estimator.
static JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
JShowerNPE getNPE(const JAxis3D &axis, const double R_Hz) const
Create data structure for handling light yields for PMT.
double operator()(const JEnergy &x, const JShowerNPEHit &npe) const
Fit function.
JPHYSICS::JNPETable< double, double, JMapList_t > JNPE_t
static double getNPE(const std::vector< JNPE_t > &NPE, const double D, const double cd)
Get number of photo-electrons.
JPHYSICS::JPDFTable< JFunction1D_t, JMapList_t > JPDF_t
std::vector< JNPE_t > Y
light from EM showers
JRegressor(const std::string &fileDescriptor)
Parameterized constructor.
JTOOLS::JMAPLIST< JTOOLS::JPolint1FunctionalMap, JTOOLS::JPolint1FunctionalGridMap >::maplist JMapList_t
JLANG::JSharedPointer< JMEstimator > estimator
M-Estimator function.
static double Vmax_npe
Maximal integral of PDF [npe].
Template definition of a data regressor of given model.
Definition JRegressor.hh:70
Auxiliary class for simultaneously handling light yields and response of PMT.
double getChi2(const double E_GeV) const
Get chi2.
Auxiliary class for handling EM shower light yield.
Definition JShowerNPE.hh:27