Jpp
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | List of all members
JFIT::JRegressor< JShower3EZ, JSimplex > Struct Template Reference

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

#include <JShower3EZRegressor.hh>

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

Public Types

typedef JTOOLS::JSplineFunction1S_t JFunction1D_t
 
typedef JTOOLS::JMapList< JTOOLS::JPolint1FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint1FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap > > > > JPDFMaplist_t
 
typedef JPHYSICS::JPDFTable< JFunction1D_t, JPDFMaplist_tJPDF_t
 
typedef JTOOLS::JMapList< JTOOLS::JPolint1FunctionalMapH, JTOOLS::JMapList< JTOOLS::JPolint1FunctionalMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap, JTOOLS::JMapList< JTOOLS::JPolint0FunctionalGridMap > > > > JNPEMaplist_t
 
typedef JPHYSICS::JNPETable< double, double, JNPEMaplist_tJNPE_t
 
typedef JSimplex< JShower3EZminimiser_type
 
typedef JRegressor< JShower3EZ, JSimplexregressor_type
 
typedef minimiser_type::result_type result_type
 

Public Member Functions

 JRegressor ()
 Default constructor. More...
 
 JRegressor (const std::string &fileDescriptor)
 Parameterized constructor. More...
 
double operator() (const JShower3EZ &shower, const JPMTW0 &pmt) const
 Fit function. More...
 
JNPE_t::result_type getH0 (const double R_Hz) const
 Get background hypothesis value for time integrated PDF. More...
 
JNPE_t::result_type getH1 (const double D, const double cosDelta, const double theta, const double phi, const double E) const
 Get signal hypothesis value for time integrated PDF. More...
 
double getRmax () const
 Get maximal road width of PDF. More...
 
result_type operator() (const JShower3EZ &value, T __begin, T __end)
 Global fit. More...
 
result_type operator() (const JShower3EZ &value, T1 __begin1, T1 __end1, T2 __begin2, T2 __end2)
 Global fit. More...
 
double operator() (const JFunction_t &fit, T __begin, T __end)
 Multi-dimensional fit. More...
 
double operator() (const JFunction_t &fit, T __begin, T __end, const JShower3EZ &step)
 1D fit. More...
 

Public Attributes

JPDF_t pdf [NUMBER_OF_PDFS]
 PDF. More...
 
JNPE_t npe [NUMBER_OF_PDFS]
 PDF. More...
 
JLANG::JSharedPointer< JMEstimatorestimator
 M-Estimator function. More...
 
JShower3EZ value
 
std::vector< JShower3EZstep
 
int numberOfIterations
 

Static Public Attributes

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

Private Member Functions

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

Detailed Description

template<>
struct JFIT::JRegressor< JShower3EZ, JSimplex >

Regressor function object for JShower3EZ fit using JSimplex minimiser.

Definition at line 44 of file JShower3EZRegressor.hh.

Member Typedef Documentation

◆ JFunction1D_t

Definition at line 49 of file JShower3EZRegressor.hh.

◆ JPDFMaplist_t

Definition at line 53 of file JShower3EZRegressor.hh.

◆ JPDF_t

Definition at line 54 of file JShower3EZRegressor.hh.

◆ JNPEMaplist_t

Definition at line 59 of file JShower3EZRegressor.hh.

◆ JNPE_t

Definition at line 60 of file JShower3EZRegressor.hh.

◆ minimiser_type

Definition at line 78 of file JRegressor.hh.

◆ regressor_type

Definition at line 79 of file JRegressor.hh.

◆ result_type

Definition at line 80 of file JRegressor.hh.

Constructor & Destructor Documentation

◆ JRegressor() [1/2]

Default constructor.

Definition at line 65 of file JShower3EZRegressor.hh.

66  {}

◆ JRegressor() [2/2]

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

Parameterized constructor.

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

Parameters
fileDescriptorPDF file descriptor

Definition at line 77 of file JShower3EZRegressor.hh.

77  :
78  estimator(new JMEstimatorNull())
79  {
80  using namespace std;
81  using namespace JPHYSICS;
82 
83  const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(JMATH::zero));
84 
85  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
86 
87  try {
88 
89  const string file_name = getFilename(fileDescriptor, pdf_t[i]);
90 
91  NOTICE("loading PDF from file " << file_name << "... " << flush);
92 
93  pdf[i].load(file_name.c_str());
94 
95  NOTICE("OK" << endl);
96 
97  pdf[i].setExceptionHandler(supervisor);
98 
99  }
100  catch(const JException& error) {
101  FATAL(error.what() << endl);
102  }
103  }
104 
105  // Add PDFs
106  for (int i = 0; i < NUMBER_OF_PDFS; i++) {
107  npe[ i ] = JNPE_t(pdf[i]);
108  }
109 
110  }

Member Function Documentation

◆ operator()() [1/5]

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 120 of file JShower3EZRegressor.hh.

121  {
122  using namespace JGEOMETRY3D;
123  using namespace JPHYSICS;
124 
125  JPosition3D D(pmt.getPosition());
126  JDirection3D U(pmt.getDirection());
127 
128  D.sub(shower.getPosition());
129 
130  JVersor3D shower_dir(shower.getDirection());
131 
132  const double z = D.getDot(shower_dir);
133  const double x = D.getX() - z * shower.getDX();
134  const double y = D.getY() - z * shower.getDY();
135  const double cosDelta = z/D.getLength(); // Delta = angle between shower direction and PMT position
136 
137  U.rotate(JRotation3Z(-atan2(y,x))); // rotate PMT axis to x-z plane
138 
139  const double theta = U.getTheta();
140  const double phi = fabs(U.getPhi());
141 
142  JNPE_t::result_type H0 = getH0(pmt.getR()); // getH0 = Get background hypothesis value for time integrated PDF.
143  JNPE_t::result_type H1 = getH1(D.getLength(), cosDelta, theta, phi, shower.getE()); // getH1 = Get signal hypothesis value for time integrated PDF.
144 
145  if (H1.f >= Vmax_npe) {
146  H1 *= Vmax_npe / H1.f;
147  }
148 
149  H1 += H0; // now H1 is signal + background
150 
151  const bool hit = pmt.getN() != 0;
152  const double u = H1.getChi2(hit); // -log(lik)
153 
154  return estimator->getRho(u);
155  }

◆ 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 163 of file JShower3EZRegressor.hh.

164  {
165  return JNPE_t::result_type(R_Hz * 1e-9 * T_ns.getLength(), 0.0);
166  }

◆ getH1()

JNPE_t::result_type JFIT::JRegressor< JShower3EZ, JSimplex >::getH1 ( const double  D,
const double  cosDelta,
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]
cosDeltaangle between shower direction and PMT position
thetaPMT zenith angle [deg]
phiPMT azimuth angle [deg]
Eshower energy [GeV]
Returns
hypothesis value

Definition at line 178 of file JShower3EZRegressor.hh.

183  {
184  JNPE_t::result_type h1 = JMATH::zero;
185 
186  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
187 
188  if (!npe[i].empty() && D <= npe[i].getXmax()) {
189 
190  try {
191 
192  JNPE_t::result_type y1 = E * npe[i](std::max(D, npe[i].getXmin()), cosDelta, theta, phi);
193 
194  if (y1.f > 0.0) {
195  h1 += y1;
196  }
197 
198  }
199  catch(JLANG::JException& error) {
200  ERROR(error << std::endl);
201  }
202  }
203  }
204 
205  return h1;
206  }

◆ getRmax()

double JFIT::JRegressor< JShower3EZ, JSimplex >::getRmax ( ) const
inline

Get maximal road width of PDF.

Returns
road width [m]

Definition at line 214 of file JShower3EZRegressor.hh.

215  {
216  double xmax = 0.0;
217 
218  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
219 
220  if (!pdf[i].empty() && pdf[i].getXmax() > xmax) {
221  xmax = pdf[i].getXmax();
222  }
223 
224  }
225 
226  return xmax;
227  }

◆ operator()() [2/5]

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

Global fit.

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

Definition at line 92 of file JRegressor.hh.

93  {
94  static_cast<minimiser_type&>(*this).value = value;
95 
96  return static_cast<minimiser_type&>(*this)(static_cast<regressor_type&>(*this), __begin, __end);
97  }

◆ operator()() [3/5]

result_type JFIT::JAbstractRegressor< JShower3EZ , JSimplex >::operator() ( const JShower3EZ value,
T1  __begin1,
T1  __end1,
T2  __begin2,
T2  __end2 
)
inlineinherited

Global fit.

Parameters
valuestart value
__begin1begin of first data set
__end1end of first data set
__begin2begin of second data set
__end2end of second data set
Returns
chi2

Definition at line 111 of file JRegressor.hh.

114  {
115  static_cast<minimiser_type&>(*this).value = value;
116 
117  return static_cast<minimiser_type&>(*this)(static_cast<regressor_type&>(*this), __begin1, __end1, __begin2, __end2);
118  }

◆ operator()() [4/5]

double JFIT::JSimplex< JShower3EZ >::operator() ( const JFunction_t &  fit,
__begin,
__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  double chi2[N];
83 
85 
87 
88  DEBUG("old: " << FIXED(12,5) << chi2_old << endl);
89 
90  const JModel_t p0(value);
91 
92  for (int i = 0; i != N; ++i) {
93 
94  DEBUG("step: " << i << ' ' << setw(5) << numberOfIterations << endl);
95 
96  chi2[i] = (*this)(fit, __begin, __end, step[i]);
97  }
98 
99  // overall step direction of last iteration
100 
101  JModel_t wall = value - p0;
102 
103  const double chi2_new = (*this)(fit, __begin, __end, wall);
104 
105  DEBUG("new: " << FIXED(12,5) << chi2_new << endl);
106 
107 
108  if (fabs(chi2_old - chi2_new) < EPSILON*fabs(chi2_old)) {
109  return chi2_new;
110  }
111 
112  // double overall step
113 
114  wall = value - p0;
115 
116  value += wall;
117 
118  const double fe = evaluate(fit, __begin, __end);
119 
120  value -= wall;
121 
122 
123  for (int i = N-1; i != 0; --i) {
124  chi2[i] = chi2[i-1] - chi2[i];
125  }
126 
127  chi2[0] = chi2_old - chi2[0];
128 
129 
130  double df = 0.0;
131 
132  for (int i = 0; i != N; ++i) {
133  if (chi2[i] > df) {
134  df = chi2[i];
135  }
136  }
137 
138  const double fn = chi2_new;
139  const double f0 = chi2_old;
140  const double ff = f0 - fn - df;
141 
142  // shift step directions
143 
144  if (fe < f0 && 2.0*(f0 - 2.0*fn + fe)*ff*ff < (f0-fe)*(f0-fe)*df) {
145 
146  for (int i = 0; i != N - 1; ++i) {
147  step[i] = step[i+1];
148  }
149 
150  step[N-1] = wall;
151  }
152 
153  chi2_old = chi2_new;
154  }
155  }
156 
157  return chi2_old;
158  }

◆ operator()() [5/5]

double JFIT::JSimplex< JShower3EZ >::operator() ( const JFunction_t &  fit,
__begin,
__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 173 of file JSimplex.hh.

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

◆ evaluate()

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

Evaluate chi2 for given data set.

Parameters
fitfit function
__beginbegin of data
__endend of data

Definition at line 242 of file JSimplex.hh.

243  {
244  double chi2 = 0.0;
245 
246  for (T hit = __begin; hit != __end; ++hit) {
247  chi2 += fit(value, *hit);
248  }
249 
250  return chi2;
251  }

Member Data Documentation

◆ T_ns

Time window with respect to Cherenkov hypothesis [ns].

Default values.

Definition at line 230 of file JShower3EZRegressor.hh.

◆ Vmax_npe

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

Maximal integral of PDF [npe].

Definition at line 231 of file JShower3EZRegressor.hh.

◆ NUMBER_OF_PDFS

const int JFIT::JRegressor< JShower3EZ, JSimplex >::NUMBER_OF_PDFS = 1
static

Definition at line 233 of file JShower3EZRegressor.hh.

◆ pdf_t

const JPDFType_t JFIT::JRegressor< JShower3EZ, JSimplex >::pdf_t = { DIRECT_LIGHT_FROM_EMSHOWER }
static

PDF types.

Definition at line 235 of file JShower3EZRegressor.hh.

◆ pdf

PDF.

Definition at line 237 of file JShower3EZRegressor.hh.

◆ npe

PDF.

Definition at line 238 of file JShower3EZRegressor.hh.

◆ estimator

M-Estimator function.

Definition at line 240 of file JShower3EZRegressor.hh.

◆ MAXIMUM_ITERATIONS

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

maximal number of iterations

maximal number of iterations.

Definition at line 226 of file JSimplex.hh.

◆ EPSILON

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

maximal distance to minimum

maximal distance to minimum.

Definition at line 227 of file JSimplex.hh.

◆ value

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

Definition at line 229 of file JSimplex.hh.

◆ step

Definition at line 230 of file JSimplex.hh.

◆ numberOfIterations

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

Definition at line 231 of file JSimplex.hh.

◆ debug

int JEEP::JMessage< JSimplex< JShower3EZ > >::debug
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:
JFIT::JRegressor< JShower3EZ, JSimplex >::T_ns
static JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
Definition: JShower3EZRegressor.hh:230
JFIT::JRegressor< JShower3EZ, JSimplex >::getH1
JNPE_t::result_type getH1(const double D, const double cosDelta, const double theta, const double phi, const double E) const
Get signal hypothesis value for time integrated PDF.
Definition: JShower3EZRegressor.hh:178
JFIT::JRegressor< JShower3EZ, JSimplex >::JNPE_t
JPHYSICS::JNPETable< double, double, JNPEMaplist_t > JNPE_t
Definition: JShower3EZRegressor.hh:60
JFIT::JRegressor< JShower3EZ, JSimplex >::NUMBER_OF_PDFS
static const int NUMBER_OF_PDFS
Definition: JShower3EZRegressor.hh:233
FIXED
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
JFIT::ERROR
Definition: JFitStatus.hh:18
JTOOLS::u
double u[N+1]
Definition: JPolint.hh:706
JTOOLS::JRange::getLength
T getLength() const
Get length (difference between upper and lower limit).
Definition: JRange.hh:302
JPHYSICS
Auxiliary classes and methods for calculation of PDF and muon energy loss.
Definition: JAbstractMedium.hh:9
JGEOMETRY3D::JDirection3D
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:32
JTOOLS::JMultiFunction::setExceptionHandler
void setExceptionHandler(const supervisor_type &supervisor)
Set the supervisor for handling of exceptions.
Definition: JMultiFunction.hh:158
JGEOMETRY3D::JVersor3D
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:23
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JFIT::JRegressor< JShower3EZ, JSimplex >::pdf
JPDF_t pdf[NUMBER_OF_PDFS]
PDF.
Definition: JShower3EZRegressor.hh:237
JFIT::JRegressor< JShower3EZ, JSimplex >::Vmax_npe
static double Vmax_npe
Maximal integral of PDF [npe].
Definition: JShower3EZRegressor.hh:231
JFIT::JSimplex< JShower3EZ >::value
JShower3EZ value
Definition: JSimplex.hh:229
JGEOMETRY3D::JPosition3D
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
JGEOMETRY3D::JVersor3D::getDot
double getDot(const JVersor3D &versor) const
Get dot product.
Definition: JVersor3D.hh:152
JEEP::getFilename
std::string getFilename(const std::string &file_name)
Get file name part, i.e.
Definition: JeepToolkit.hh:86
JGEOMETRY3D::JRotation3Z
Rotation around Z-axis.
Definition: JRotation3D.hh:85
JFIT::JRegressor< JShower3EZ, JSimplex >::estimator
JLANG::JSharedPointer< JMEstimator > estimator
M-Estimator function.
Definition: JShower3EZRegressor.hh:240
JFIT::JRegressor< JShower3EZ, JSimplex >::pdf_t
static const JPDFType_t pdf_t[NUMBER_OF_PDFS]
PDF types.
Definition: JShower3EZRegressor.hh:235
JFIT::JRegressor< JShower3EZ, JSimplex >::getH0
JNPE_t::result_type getH0(const double R_Hz) const
Get background hypothesis value for time integrated PDF.
Definition: JShower3EZRegressor.hh:163
JFIT::JSimplex< JShower3EZ >::evaluate
double evaluate(const JFunction_t &fit, T __begin, T __end) const
Evaluate chi2 for given data set.
Definition: JSimplex.hh:242
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JFIT::JRegressor< JShower3EZ, JSimplex >::npe
JNPE_t npe[NUMBER_OF_PDFS]
PDF.
Definition: JShower3EZRegressor.hh:238
JGEOMETRY3D
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition: JAngle3D.hh:18
JMATH::zero
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:94
JFIT::JSimplex< JShower3EZ >::step
std::vector< JShower3EZ > step
Definition: JSimplex.hh:230
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
JFIT::JSimplex< JShower3EZ >::EPSILON
static double EPSILON
maximal distance to minimum
Definition: JSimplex.hh:227
JIO::JObjectBinaryIO::load
void load(const char *file_name)
Load from input file.
Definition: JObjectBinaryIO.hh:29
JLANG::JException
General exception.
Definition: JException.hh:40
JFIT::JSimplex< JShower3EZ >::MAXIMUM_ITERATIONS
static int MAXIMUM_ITERATIONS
maximal number of iterations
Definition: JSimplex.hh:226
JFIT::JSimplex< JShower3EZ >::numberOfIterations
int numberOfIterations
Definition: JSimplex.hh:231