Jpp in_tag_pdf_generation
the software that should make you happy
Loading...
Searching...
No Matches
JFIT::JRegressor< JShower3EZ, JSimplex > Struct Reference

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

#include <JShower3EZRegressor.hh>

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

Public Types

typedef JRegressorStorage< JShower3EZ, JSimplexstorage_type
 
typedef JSimplex< JShower3EZminimiser_type
 
typedef JRegressor< JShower3EZ, JSimplexregressor_type
 
typedef minimiser_type::result_type result_type
 
typedef JTOOLS::JPolint1Function1D_t JFunction1D_t
 
typedef JTOOLS::JMapList< JTOOLS::JPolint0FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap > > > > JPDFMaplist_t
 
typedef JPHYSICS::JPDFTable< JFunction1D_t, JPDFMaplist_tJPDF_t
 
typedef JTOOLS::JMapList< JTOOLS::JPolint0FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap > > > > JNPEMaplist_t
 
typedef JPHYSICS::JNPETable< double, double, JNPEMaplist_tJNPE_t
 
typedef std::array< JNPE_t, NUMBER_OF_PDFSJNPEs_t
 NPEs.
 

Public Member Functions

 JRegressor ()
 Default constructor.
 
 JRegressor (const std::string &fileDescriptor, const JTimeRange &T_ns)
 Constructor.
 
 JRegressor (const storage_type &storage)
 Constructor.
 
double operator() (const JShower3EZ &shower, const JPMTW0 &pmt) const
 Fit function.
 
JNPE_t::result_type getH0 (const double R_Hz) const
 Get background hypothesis value for time integrated PDF.
 
JNPE_t::result_type getH1 (const double D, const double cd, const double theta, const double phi, const double E) const
 Get signal hypothesis value for time integrated PDF.
 
result_type operator() (const JShower3EZ &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 JShower3EZ &step)
 1D fit.
 
const JNPEs_tgetNPE () const
 Get NPEs.
 

Public Attributes

const JNPEs_tnpe
 
std::shared_ptr< JMEstimatorestimator
 M-Estimator function.
 
JShower3EZ value
 
std::vector< JShower3EZstep
 
int numberOfIterations
 
JTimeRange T_ns
 Time window with respect to Cherenkov hypothesis [ns].
 

Static Public Attributes

static double Vmax_npe
 Maximal integral of PDF [npe].
 
static int MAXIMUM_ITERATIONS
 maximal number of iterations
 
static double EPSILON
 maximal distance to minimum
 
static int debug = 0
 debug level (default is off).
 
static const int NUMBER_OF_PDFS = 2
 
static const JPDFType_t pdf_t [NUMBER_OF_PDFS]
 PDF types.
 

Private Member Functions

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

Private Attributes

JShower3EZ p0
 
JShower3EZ p1
 
JShower3EZ wall
 
JNPEs_t _npe
 PDFs.
 

Detailed Description

Regressor function object for JShower3EZ fit using JGandalf minimiser.

Definition at line 195 of file JShower3EZRegressor.hh.

Member Typedef Documentation

◆ storage_type

◆ minimiser_type

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.

◆ JFunction1D_t

Definition at line 97 of file JShower3EZRegressor.hh.

◆ JPDFMaplist_t

◆ JPDF_t

◆ JNPEMaplist_t

◆ JNPE_t

Definition at line 108 of file JShower3EZRegressor.hh.

◆ JNPEs_t

NPEs.

Definition at line 113 of file JShower3EZRegressor.hh.

Constructor & Destructor Documentation

◆ JRegressor() [1/3]

JFIT::JRegressor< JShower3EZ, JSimplex >::JRegressor ( )
inline

Default constructor.

Definition at line 206 of file JShower3EZRegressor.hh.

206 :
207 storage_type(),
208 npe(getNPE()),
209 estimator()
210 {}
JRegressorStorage< JShower3EZ, JSimplex > storage_type
std::shared_ptr< JMEstimator > estimator
M-Estimator function.

◆ JRegressor() [2/3]

JFIT::JRegressor< JShower3EZ, JSimplex >::JRegressor ( const std::string & fileDescriptor,
const JTimeRange & T_ns )
inline

Constructor.

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

Parameters
fileDescriptorPDF file descriptor
T_nstime range [ns]

Definition at line 221 of file JShower3EZRegressor.hh.

221 :
222 storage_type(fileDescriptor, T_ns),
223 npe(getNPE()),
224 estimator(new JMEstimatorNull())
225 {}
JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].

◆ JRegressor() [3/3]

JFIT::JRegressor< JShower3EZ, JSimplex >::JRegressor ( const storage_type & storage)
inline

Constructor.

Parameters
storagePDF storage

Definition at line 232 of file JShower3EZRegressor.hh.

232 :
233 npe(storage.getNPE()),
234 estimator(new JMEstimatorNull())
235 {
236 T_ns = storage.T_ns;
237 }

Member Function Documentation

◆ operator()() [1/4]

double JFIT::JRegressor< JShower3EZ, JSimplex >::operator() ( const JShower3EZ & shower,
const JPMTW0 & pmt ) const
inline

Fit function.

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

Parameters
showershower
pmtpmt
Returns
chi2

Definition at line 248 of file JShower3EZRegressor.hh.

249 {
250 using namespace JPP;
251
252 JPosition3D D(pmt.getPosition());
253 JDirection3D U(pmt.getDirection());
254
255 D.sub(shower.getPosition());
256
257 const double z = D.getDot(shower.getDirection());
258 const double x = D.getX();
259 const double y = D.getY();
260 const double cd = z/D.getLength(); // cosine angle between shower direction and PMT position
261
262 U.rotate(JRotation3Z(-atan2(y,x))); // rotate PMT axis to x-z plane
263
264 const double theta = getPMTAngle(U.getTheta());
265 const double phi = getPMTAngle(U.getPhi());
266
267 JNPE_t::result_type H0 = getH0(pmt.getR()); // background hypothesis value for time integrated PDF.
268 JNPE_t::result_type H1 = getH1(D.getLength(), cd, theta, phi, shower.getE()); // signal hypothesis value for time integrated PDF.
269
270 if (get_value(H1) >= Vmax_npe) {
271 H1 *= Vmax_npe / get_value(H1);
272 }
273
274 H1 += H0; // now H1 is signal + background
275
276 const bool hit = pmt.getN() != 0;
277 const double u = getChi2(get_value(H1), hit) - getChi2(get_value(H0), hit); // - log likelihood ratio
278
279 return estimator->getRho(u);
280 }
Data structure for direction in three dimensions.
Data structure for position in three dimensions.
Rotation around Z-axis.
double getPMTAngle(const double angle)
Constrain PMT angle to [0,pi].
double getChi2(const double P)
Get chi2 corresponding to given probability.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
static double Vmax_npe
Maximal integral of PDF [npe].
JNPE_t::result_type getH0(const double R_Hz) const
Get background hypothesis value for time integrated PDF.
JNPE_t::result_type getH1(const double D, const double cd, const double theta, const double phi, const double E) const
Get signal hypothesis value for time integrated PDF.

◆ getH0()

JNPE_t::result_type JFIT::JRegressor< JShower3EZ, JSimplex >::getH0 ( const double R_Hz) const
inline

Get background hypothesis value for time integrated PDF.

Parameters
R_Hzrate [Hz]
Returns
hypothesis value

Definition at line 288 of file JShower3EZRegressor.hh.

289 {
290 return JNPE_t::result_type(R_Hz * 1e-9 * T_ns.getLength());
291 }
T getLength() const
Get length (difference between upper and lower limit).
Definition JRange.hh:289

◆ getH1()

JNPE_t::result_type JFIT::JRegressor< JShower3EZ, JSimplex >::getH1 ( const double D,
const double cd,
const double theta,
const double phi,
const double E ) const
inline

Get signal hypothesis value for time integrated PDF.

Parameters
DPMT distance from shower [m]
cdcosine angle between shower direction and PMT position
thetaPMT zenith angle [deg]
phiPMT azimuth angle [deg]
Eshower energy [GeV]
Returns
hypothesis value

Definition at line 303 of file JShower3EZRegressor.hh.

308 {
310
311 for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
312
313 if (!npe[i].empty() && D <= npe[i].getXmax()) {
314
315 try {
316
317 JNPE_t::result_type y1 = E * npe[i](std::max(D, npe[i].getXmin()), cd, theta, phi);
318
319 // safety measure
320
321 if(y1 < 0){
322 y1 = 0;
323 }
324
325 h1 += y1;
326
327 }
328 catch(JLANG::JException& error) {
329 ERROR(error << std::endl);
330 }
331 }
332 }
333
334 return h1;
335 }
#define ERROR(A)
Definition JMessage.hh:66
General exception.
Definition JException.hh:24
static const JZero zero
Function object to assign zero value.
Definition JZero.hh:105

◆ operator()() [2/4]

result_type JFIT::JAbstractRegressor< JShower3EZ, JSimplex >::operator() ( const JShower3EZ & 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< JShower3EZ, JSimplex > regressor_type
Definition JRegressor.hh:81

◆ operator()() [3/4]

double JFIT::JSimplex< JShower3EZ >::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
std::vector< JShower3EZ > 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< JShower3EZ >::operator() ( const JFunction_t & fit,
T __begin,
T __end,
const JShower3EZ & 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< JShower3EZ >::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 }

◆ getNPE()

const JNPEs_t & JFIT::JRegressorStorage< JShower3EZ, JSimplex >::getNPE ( ) const
inlineinherited

Get NPEs.

Returns
PDFs

Definition at line 168 of file JShower3EZRegressor.hh.

Member Data Documentation

◆ Vmax_npe

double JFIT::JRegressor< JShower3EZ, JSimplex >::Vmax_npe
static

Maximal integral of PDF [npe].

Definition at line 338 of file JShower3EZRegressor.hh.

◆ npe

Definition at line 340 of file JShower3EZRegressor.hh.

◆ estimator

std::shared_ptr<JMEstimator> JFIT::JRegressor< JShower3EZ, JSimplex >::estimator

M-Estimator function.

Definition at line 342 of file JShower3EZRegressor.hh.

◆ MAXIMUM_ITERATIONS

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

maximal number of iterations

maximal number of iterations.

Definition at line 237 of file JSimplex.hh.

◆ EPSILON

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

maximal distance to minimum

maximal distance to minimum.

Definition at line 238 of file JSimplex.hh.

◆ value

JShower3EZ JFIT::JSimplex< JShower3EZ >::value
inherited

Definition at line 240 of file JSimplex.hh.

◆ step

Definition at line 241 of file JSimplex.hh.

◆ numberOfIterations

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

Definition at line 242 of file JSimplex.hh.

◆ p0

JShower3EZ JFIT::JSimplex< JShower3EZ >::p0
mutableprivateinherited

Definition at line 264 of file JSimplex.hh.

◆ p1

JShower3EZ JFIT::JSimplex< JShower3EZ >::p1
mutableprivateinherited

Definition at line 265 of file JSimplex.hh.

◆ wall

JShower3EZ JFIT::JSimplex< JShower3EZ >::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.

◆ NUMBER_OF_PDFS

const int JFIT::JRegressorStorage< JShower3EZ, JSimplex >::NUMBER_OF_PDFS = 2
staticinherited

Definition at line 111 of file JShower3EZRegressor.hh.

◆ pdf_t

PDF types.

Definition at line 176 of file JShower3EZRegressor.hh.

◆ T_ns

Time window with respect to Cherenkov hypothesis [ns].

Definition at line 177 of file JShower3EZRegressor.hh.

◆ _npe

JNPEs_t JFIT::JRegressorStorage< JShower3EZ, JSimplex >::_npe
privateinherited

PDFs.

Definition at line 180 of file JShower3EZRegressor.hh.


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