Jpp master_rocky-44-g75b7c4f75
the software that should make you happy
Loading...
Searching...
No Matches
JFIT::JRegressor< JEnergy, JSimplex > Struct Reference

Regressor function object for JShower3EZ fit using JSimplex minimiser. More...

#include <JShowerEnergyRegressor.hh>

Inheritance diagram for JFIT::JRegressor< JEnergy, JSimplex >:
JFIT::JAbstractRegressor< JEnergy, JSimplex > JFIT::JSimplex< JEnergy > JEEP::JMessage< T >

Public Types

typedef JTOOLS::JSplineFunction1S_t JFunction1D_t
 
typedef JTOOLS::JMAPLIST< JTOOLS::JPolint1FunctionalMap, JTOOLS::JPolint1FunctionalGridMap >::maplist JMapList_t
 
typedef JPHYSICS::JPDFTable< JFunction1D_t, JMapList_tJPDF_t
 
typedef JPHYSICS::JNPETable< double, double, JMapList_tJNPE_t
 
typedef JSimplex< JEnergyminimiser_type
 
typedef JRegressor< JEnergy, JSimplexregressor_type
 
typedef minimiser_type::result_type result_type
 

Public Member Functions

 JRegressor (const std::string &fileDescriptor)
 Parameterized constructor.
 
double operator() (const JEnergy &x, const JShowerNPEHit &npe) const
 Fit function.
 
JShowerNPE getNPE (const JAxis3D &axis, const double R_Hz) const
 Create data structure for handling light yields for PMT.
 
result_type operator() (const JEnergy &value, T __begin, T __end)
 Global fit.
 
double operator() (const JFunction_t &fit, T __begin, T __end)
 Multi-dimensional fit.
 
double operator() (const JFunction_t &fit, T __begin, T __end, const JEnergy &step)
 1D fit.
 

Static Public Member Functions

static double getNPE (const std::vector< JNPE_t > &NPE, const double D, const double cd)
 Get number of photo-electrons.
 

Public Attributes

std::vector< JNPE_tY
 light from EM showers
 
JLANG::JSharedPointer< JMEstimatorestimator
 M-Estimator function.
 
JEnergy value
 
std::vector< JEnergystep
 
int numberOfIterations
 

Static Public Attributes

static JTimeRange T_ns
 Time window with respect to Cherenkov hypothesis [ns].
 
static double Vmax_npe = std::numeric_limits<double>::max()
 Maximal integral of PDF [npe].
 
static const int NUMBER_OF_PDFS = 2
 
static const JPDFType_t pdf_t [NUMBER_OF_PDFS]
 
static int MAXIMUM_ITERATIONS
 maximal number of iterations
 
static double EPSILON
 maximal distance to minimum
 
static int debug = 0
 debug level (default is off).
 

Private Member Functions

double evaluate (const JFunction_t &fit, T __begin, T __end) const
 Evaluate chi2 for given data set.
 

Private Attributes

JEnergy p0
 
JEnergy p1
 
JEnergy wall
 

Detailed Description

Regressor function object for JShower3EZ fit using JSimplex minimiser.

Definition at line 50 of file JShowerEnergyRegressor.hh.

Member Typedef Documentation

◆ JFunction1D_t

◆ JMapList_t

◆ JPDF_t

◆ JNPE_t

Definition at line 60 of file JShowerEnergyRegressor.hh.

◆ minimiser_type

JSimplex<JEnergy> JFIT::JAbstractRegressor< JEnergy, JSimplex >::minimiser_type
inherited

Definition at line 80 of file JRegressor.hh.

◆ regressor_type

Definition at line 81 of file JRegressor.hh.

◆ result_type

Definition at line 82 of file JRegressor.hh.

Constructor & Destructor Documentation

◆ JRegressor()

JFIT::JRegressor< JEnergy, JSimplex >::JRegressor ( const std::string & fileDescriptor)
inline

Parameterized constructor.

The PDF file descriptor should contain the wild card character JPHYSICS::WILDCARD which will be replaced by the corresponding PDF types listed in JRegressor<JEnergy, JSimplex>::pdf_t.

Parameters
fileDescriptorPDF file descriptor

Definition at line 71 of file JShowerEnergyRegressor.hh.

71 :
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 }
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
General exception.
Definition JException.hh:24
virtual const char * what() const override
Get error message.
Definition JException.hh:64
static const JZero zero
Function object to assign zero value.
Definition JZero.hh:105
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
static const JPDFType_t pdf_t[NUMBER_OF_PDFS]
std::vector< JNPE_t > Y
light from EM showers
JLANG::JSharedPointer< JMEstimator > estimator
M-Estimator function.
JPHYSICS::JNPETable< double, double, JMapList_t > JNPE_t
JPHYSICS::JPDFTable< JFunction1D_t, JMapList_t > JPDF_t

Member Function Documentation

◆ operator()() [1/4]

double JFIT::JRegressor< JEnergy, JSimplex >::operator() ( const JEnergy & x,
const JShowerNPEHit & npe ) const
inline

Fit function.

This method is used to determine the chi2 of given PMT with respect to shower hypothesis.

Parameters
xenergy
npenumber of photoelectrons
Returns
chi2

Definition at line 120 of file JShowerEnergyRegressor.hh.

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 }
double u[N+1]
Definition JPolint.hh:865

◆ getNPE() [1/2]

JShowerNPE JFIT::JRegressor< JEnergy, JSimplex >::getNPE ( const JAxis3D & axis,
const double R_Hz ) const
inline

Create data structure for handling light yields for PMT.

Parameters
axisPMT axis
R_Hzsingles rate [Hz]
Returns
light yields

Definition at line 137 of file JShowerEnergyRegressor.hh.

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 }
Data structure for direction in three dimensions.
Data structure for position in three dimensions.
double getN(const JRange< T > &range, const double R)
Get expected number of occurrences due to given rate within specified interval.
Definition JRange.hh:704
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.
Auxiliary class for handling EM shower light yield.
Definition JShowerNPE.hh:27

◆ getNPE() [2/2]

static double JFIT::JRegressor< JEnergy, JSimplex >::getNPE ( const std::vector< JNPE_t > & NPE,
const double D,
const double cd )
inlinestatic

Get number of photo-electrons.

Parameters
NPENPE tables
DPMT distance from shower [m]
cdcosine of the PMT angle wrt the photon direction
Returns
number of photo-electrons

Definition at line 165 of file JShowerEnergyRegressor.hh.

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 }
#define ERROR(A)
Definition JMessage.hh:66

◆ operator()() [2/4]

result_type JFIT::JAbstractRegressor< JEnergy, JSimplex >::operator() ( const JEnergy & value,
T __begin,
T __end )
inlineinherited

Global fit.

Parameters
valuestart value
__beginbegin of data set
__endend of data set
Returns
chi2

Definition at line 94 of file JRegressor.hh.

95 {
96 static_cast<minimiser_type&>(*this).value = value;
97
98 return static_cast<minimiser_type&>(*this)(static_cast<regressor_type&>(*this), __begin, __end);
99 }
JModel_t value
Definition JSimplex.hh:240
JRegressor< JEnergy, JSimplex > regressor_type
Definition JRegressor.hh:81

◆ operator()() [3/4]

double JFIT::JSimplex< JEnergy >::operator() ( const JFunction_t & fit,
T __begin,
T __end )
inlineinherited

Multi-dimensional fit.

The given fit function should return the equivalent of chi2 for the current value of the given model and a given data point.

Parameters
fitfit function
__beginbegin of data
__endend of data
Returns
chi2

Definition at line 71 of file JSimplex.hh.

72 {
73 using namespace std;
74 using namespace JPP;
75
76 double chi2_old = evaluate(fit, __begin, __end);
77
78 const int N = step.size();
79
80 if (N != 0) {
81
82 p0 = value;
83 p1 = value;
84 wall = value;
85
86 double chi2[N];
87
89
91
92 DEBUG("old: " << FIXED(12,5) << chi2_old << endl);
93
94 p0 = value;
95
96 for (int i = 0; i != N; ++i) {
97
98 DEBUG("step: " << i << ' ' << setw(5) << numberOfIterations << endl);
99
100 chi2[i] = (*this)(fit, __begin, __end, step[i]);
101 }
102
103 // overall step direction of last iteration
104
105 wall = value;
106 wall -= p0;
107
108 const double chi2_new = (*this)(fit, __begin, __end, wall);
109
110 DEBUG("new: " << FIXED(12,5) << chi2_new << endl);
111
112
113 if (fabs(chi2_old - chi2_new) < EPSILON*fabs(chi2_old)) {
114 return chi2_new;
115 }
116
117 // double overall step
118
119 wall = value;
120 wall -= p0;
121 value += wall;
122
123 const double fe = evaluate(fit, __begin, __end);
124
125 value -= wall;
126
127
128 for (int i = N-1; i != 0; --i) {
129 chi2[i] = chi2[i-1] - chi2[i];
130 }
131
132 chi2[0] = chi2_old - chi2[0];
133
134
135 double df = 0.0;
136
137 for (int i = 0; i != N; ++i) {
138 if (chi2[i] > df) {
139 df = chi2[i];
140 }
141 }
142
143 const double fn = chi2_new;
144 const double f0 = chi2_old;
145 const double ff = f0 - fn - df;
146
147 // shift step directions
148
149 if (fe < f0 && 2.0*(f0 - 2.0*fn + fe)*ff*ff < (f0-fe)*(f0-fe)*df) {
150
151 for (int i = 0; i != N - 1; ++i) {
152 step[i] = step[i+1];
153 }
154
155 step[N-1] = wall;
156 }
157
158 chi2_old = chi2_new;
159 }
160 }
161
162 return chi2_old;
163 }
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
static int MAXIMUM_ITERATIONS
Definition JSimplex.hh:237
std::vector< JEnergy > step
Definition JSimplex.hh:241
double evaluate(const JFunction_t &fit, T __begin, T __end) const
Definition JSimplex.hh:253
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448

◆ operator()() [4/4]

double JFIT::JSimplex< JEnergy >::operator() ( const JFunction_t & fit,
T __begin,
T __end,
const JEnergy & step )
inlineinherited

1D fit.

The given fit function should return the equivalent of chi2 for the current value of the given model and a given data point.

Parameters
fitfit function
__beginbegin of data
__endend of data
stepstep direction

Definition at line 178 of file JSimplex.hh.

179 {
180 using namespace std;
181 using namespace JPP;
182
183 double lambda = 0.5; // control parameter
184 double factor = 1.0; // multiplication factor
185
186 double chi2_old = evaluate(fit, __begin, __end);
187
188 for (int i = 0; numberOfIterations != MAXIMUM_ITERATIONS; ++numberOfIterations, ++i) {
189
190 p1 = step;
191 p1 *= lambda;
192 value += p1;
193
194 const double chi2_new = evaluate(fit, __begin, __end);
195
196 DEBUG("step: " << setw(3) << i << ' ' << FIXED(12,5) << chi2_old << ' ' << FIXED(12,5) << chi2_new << ' ' << FIXED(5,2) << lambda << endl);
197
198 if (fabs(chi2_old - chi2_new) < EPSILON*fabs(chi2_old)) {
199
200 if (chi2_new > chi2_old) {
201
202 p1 = step;
203 p1 *= lambda;
204 value -= p1; // undo last step
205
206 return chi2_old;
207
208 } else {
209
210 return chi2_new;
211 }
212 }
213
214 if (chi2_new < chi2_old) {
215
216 chi2_old = chi2_new;
217
218 } else {
219
220 p1 = step;
221 p1 *= lambda;
222 value -= p1; // step back
223 lambda = -lambda; // change direction
224
225 if (i != 0) {
226 factor = 0.5; // reduce step size
227 }
228 }
229
230 lambda = factor * lambda;
231 }
232
233 return chi2_old;
234 }

◆ evaluate()

double JFIT::JSimplex< JEnergy >::evaluate ( const JFunction_t & fit,
T __begin,
T __end ) const
inlineprivateinherited

Evaluate chi2 for given data set.

Parameters
fitfit function
__beginbegin of data
__endend of data

Definition at line 253 of file JSimplex.hh.

254 {
255 double chi2 = 0.0;
256
257 for (T hit = __begin; hit != __end; ++hit) {
258 chi2 += fit(value, *hit);
259 }
260
261 return chi2;
262 }

Member Data Documentation

◆ T_ns

Time window with respect to Cherenkov hypothesis [ns].

Definition at line 193 of file JShowerEnergyRegressor.hh.

◆ Vmax_npe

double JFIT::JRegressor< JEnergy, JSimplex >::Vmax_npe = std::numeric_limits<double>::max()
static

Maximal integral of PDF [npe].

Definition at line 194 of file JShowerEnergyRegressor.hh.

◆ NUMBER_OF_PDFS

const int JFIT::JRegressor< JEnergy, JSimplex >::NUMBER_OF_PDFS = 2
static

Definition at line 196 of file JShowerEnergyRegressor.hh.

◆ pdf_t

Definition at line 198 of file JShowerEnergyRegressor.hh.

◆ Y

light from EM showers

Definition at line 200 of file JShowerEnergyRegressor.hh.

◆ estimator

M-Estimator function.

Definition at line 202 of file JShowerEnergyRegressor.hh.

◆ MAXIMUM_ITERATIONS

int JFIT::JSimplex< JEnergy >::MAXIMUM_ITERATIONS
staticinherited

maximal number of iterations

maximal number of iterations.

Definition at line 237 of file JSimplex.hh.

◆ EPSILON

double JFIT::JSimplex< JEnergy >::EPSILON
staticinherited

maximal distance to minimum

maximal distance to minimum.

Definition at line 238 of file JSimplex.hh.

◆ value

JEnergy JFIT::JSimplex< JEnergy >::value
inherited

Definition at line 240 of file JSimplex.hh.

◆ step

Definition at line 241 of file JSimplex.hh.

◆ numberOfIterations

int JFIT::JSimplex< JEnergy >::numberOfIterations
inherited

Definition at line 242 of file JSimplex.hh.

◆ p0

JEnergy JFIT::JSimplex< JEnergy >::p0
mutableprivateinherited

Definition at line 264 of file JSimplex.hh.

◆ p1

JEnergy JFIT::JSimplex< JEnergy >::p1
mutableprivateinherited

Definition at line 265 of file JSimplex.hh.

◆ wall

JEnergy JFIT::JSimplex< JEnergy >::wall
mutableprivateinherited

Definition at line 266 of file JSimplex.hh.

◆ debug

template<class T >
int JEEP::JMessage< T >::debug = 0
staticinherited

debug level (default is off).

Definition at line 45 of file JMessage.hh.


The documentation for this struct was generated from the following file: