Jpp  15.0.1-rc.1-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
JFIT::JRegressor< JShowerEH, JSimplex > Struct Template Reference

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

#include <JShowerBjorkenYRegressor.hh>

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

Public Types

typedef JTOOLS::JSplineFunction1S_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_t
JPDF_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_t
JNPE_t
 
typedef JTOOLS::JMAPLIST
< JTOOLS::JPolint1FunctionalMap,
JTOOLS::JPolint1FunctionalGridMap >
::maplist 
JMapList_t2
 
typedef JPHYSICS::JPDFTable
< JFunction1D_t, JMapList_t2
JPDF_t2
 
typedef JTOOLS::JMAPLIST
< JTOOLS::JPolint1FunctionalMap,
JTOOLS::JPolint1FunctionalGridMap >
::maplist 
JNPEMapList_t2
 
typedef JPHYSICS::JNPETable
< double, double,
JNPEMapList_t2
JNPE_t2
 
typedef JSimplex< JShowerEHminimiser_type
 
typedef JRegressor< JShowerEH,
JSimplex
regressor_type
 
typedef minimiser_type::result_type result_type
 

Public Member Functions

 JRegressor (const std::string &fileDescriptor)
 Parameterized constructor. More...
 
double operator() (const JShowerEH &shower, const JPMTW0 &pmt) const
 Fit function. More...
 
double getH0 (const double R_Hz) const
 Get background hypothesis value for time integrated PDF. More...
 
double getH1 (const double D, const double ct, const double cosDelta, const double theta, const double phi, const double Eem, const double Eh, const double Y) const
 Get signal hypothesis value for time integrated PDF. More...
 
result_type operator() (const JShowerEH &value, T __begin, T __end)
 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 JShowerEH &step)
 1D fit. More...
 

Public Attributes

JNPE_t npe [NUMBER_OF_PDFS-2]
 PDF. More...
 
JNPE_t2 npe2 [NUMBER_OF_PDFS-2]
 PDF. More...
 
JLANG::JSharedPointer
< JMEstimator
estimator
 M-Estimator function. More...
 
JShowerEH value
 
std::vector< JShowerEHstep
 
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 = 4
 
static const JPDFType_t pdf_t [NUMBER_OF_PDFS]
 PDF types. More...
 
static int MAXIMUM_ITERATIONS
 maximal number of iterations More...
 
static double EPSILON
 maximal distance to minimum More...
 
static int debug = 0
 debug level (default is off). More...
 

Detailed Description

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

Regressor function object for JShowerEH fit using JSimplex minimiser.

Definition at line 53 of file JShowerBjorkenYRegressor.hh.

Member Typedef Documentation

Definition at line 58 of file JShowerBjorkenYRegressor.hh.

Definition at line 62 of file JShowerBjorkenYRegressor.hh.

Definition at line 63 of file JShowerBjorkenYRegressor.hh.

Definition at line 68 of file JShowerBjorkenYRegressor.hh.

Definition at line 69 of file JShowerBjorkenYRegressor.hh.

Definition at line 74 of file JShowerBjorkenYRegressor.hh.

Definition at line 75 of file JShowerBjorkenYRegressor.hh.

Definition at line 78 of file JShowerBjorkenYRegressor.hh.

Definition at line 79 of file JShowerBjorkenYRegressor.hh.

Definition at line 78 of file JRegressor.hh.

Definition at line 79 of file JRegressor.hh.

Definition at line 80 of file JRegressor.hh.

Constructor & Destructor Documentation

JFIT::JRegressor< JShowerEH, 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 91 of file JShowerBjorkenYRegressor.hh.

91  :
92  estimator(new JMEstimatorNull())
93  {
94  using namespace std;
95  using namespace JPP;
96 
97  const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(JMATH::zero));
98  const JPDF_t2::JSupervisor supervisor2(new JPDF_t2::JDefaultResult(JMATH::zero));
99 
100  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
101 
102  try {
103 
104  JPDF_t pdf;
105  JPDF_t2 pdf2;
106 
107  const string file_name = getFilename(fileDescriptor, pdf_t[i]);
108 
109  NOTICE("loading PDF from file " << file_name << "... " << flush);
110 
111  if(i < 2){
112 
113  pdf.load(file_name.c_str());
114 
115  pdf.setExceptionHandler(supervisor);
116 
117  npe[ i ] = JNPE_t(pdf);
118 
119  } else {
120 
121  pdf2.load(file_name.c_str());
122 
123  NOTICE("OK" << endl);
124 
125  pdf2.setExceptionHandler(supervisor2);
126 
127  npe2[ i-2 ] = JNPE_t2(pdf2);
128 
129  }
130  }
131  catch(const JException& error) {
132  FATAL(error.what() << endl);
133  }
134  }
135 
136  // Add PDFs
137  for (int i = 1; i < (NUMBER_OF_PDFS-2); i += 2) {
138 
139  npe[ i ].add(npe[i-1]);
140 
141  JNPE_t buffer;
142 
143  npe[i-1].swap(buffer);
144 
145  npe2[ i ].add(npe2[i-1]);
146 
147  JNPE_t2 buffer2;
148 
149  npe2[i-1].swap(buffer2);
150 
151  }
152  }
static const JPDFType_t pdf_t[NUMBER_OF_PDFS]
PDF types.
JLANG::JSharedPointer< JMEstimator > estimator
M-Estimator function.
JPHYSICS::JPDFTable< JFunction1D_t, JMapList_t2 > JPDF_t2
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
void add(const JNPETable &input)
Add NPE table.
Definition: JNPETable.hh:124
JPHYSICS::JNPETable< double, double, JNPEMapList_t2 > JNPE_t2
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
JPHYSICS::JNPETable< double, double, JNPEMaplist_t > JNPE_t
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
JPHYSICS::JPDFTable< JFunction1D_t, JPDFMaplist_t > JPDF_t

Member Function Documentation

double JFIT::JRegressor< JShowerEH, JSimplex >::operator() ( const JShowerEH 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 162 of file JShowerBjorkenYRegressor.hh.

163  {
164  using namespace JPP;
165  using namespace std;
166 
167  JPosition3D D(pmt.getPosition());
168  JDirection3D U(pmt.getDirection());
169 
170  D.sub(shower.getPosition());
171 
172  double ct = U.getDot(D) / D.getLength();
173 
174  JVersor3D shower_dir(shower.getDirection());
175 
176  const double z = D.getDot(shower_dir);
177  const double x = D.getX() - z * shower.getDX();
178  const double y = D.getY() - z * shower.getDY();
179  const double cosDelta = z/D.getLength(); // Delta = angle between shower direction and PMT position
180 
181  U.rotate(JRotation3Z(-atan2(y,x))); // rotate PMT axis to x-z plane
182 
183  const double theta = U.getTheta();
184  const double phi = fabs(U.getPhi());
185 
186  double H0 = getH0(pmt.getR()); // background
187  double H1 = getH1(D.getLength(), ct, cosDelta, theta, phi,
188  shower.getEem(), shower.getEh(), shower.getBy()); // signal
189 
190  if (H1 >= Vmax_npe) {
191  H1 *= Vmax_npe / H1;
192  }
193 
194  H1 += H0; // now H1 is signal + background
195 
196  const bool hit = pmt.getN() != 0;
197  const double u = getChi2(H1, hit); // -log(lik)
198 
199  return estimator->getRho(u);
200  }
do rm f tmp H1
JLANG::JSharedPointer< JMEstimator > estimator
M-Estimator function.
double getH1(const double D, const double ct, const double cosDelta, const double theta, const double phi, const double Eem, const double Eh, const double Y) const
Get signal hypothesis value for time integrated PDF.
double getH0(const double R_Hz) const
Get background hypothesis value for time integrated PDF.
static double Vmax_npe
Maximal integral of PDF [npe].
double u[N+1]
Definition: JPolint.hh:739
double getChi2(const double P)
Get chi2 corresponding to given probability.
Definition: JFitToolkit.hh:70
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
double JFIT::JRegressor< JShowerEH, 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 208 of file JShowerBjorkenYRegressor.hh.

209  {
210  return get_value(JNPE_t::result_type(R_Hz * 1e-9 * T_ns.getLength()));
211  }
static JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
JResultEvaluator< JResult_t >::result_type get_value(const JResult_t &value)
Helper method to recursively evaluate a to function value.
Definition: JResult.hh:998
double JFIT::JRegressor< JShowerEH, JSimplex >::getH1 ( const double  D,
const double  ct,
const double  cosDelta,
const double  theta,
const double  phi,
const double  Eem,
const double  Eh,
const double  Y 
) const
inline

Get signal hypothesis value for time integrated PDF.

Parameters
DPMT distance from shower [m]
ctangle between shower direction and PMT position
cosDeltaangle between shower direction and PMT position
thetaPMT zenith angle [deg]
phiPMT azimuth angle [deg]
EemEM shower energy [GeV]
EhH shower energy [GeV]
YBjorken Y
Returns
hypothesis value

Definition at line 226 of file JShowerBjorkenYRegressor.hh.

234  {
235 
236  double h1 = 0;
237 
238  for (int i = 0; i != (NUMBER_OF_PDFS-1); ++i) {
239 
240  if (!npe[i].empty() && D <= npe[i].getXmax() && !npe2[i].empty() && D <= npe2[i].getXmax()) {
241 
242  try {
243 
244  JNPE_t::result_type P_em;
245  JNPE_t2::result_type P_h;
246 
247  P_em = abs(Eem) * npe[i](std::max(D, npe[i].getXmin()), cosDelta, theta, phi);
248 
249  P_h = abs(Eh) * npe2[i](std::max(D, npe2[i].getXmin()), ct);
250 
251  double y1 = get_value(P_em) + get_value(P_h);
252 
253  if(y1 > 0.0){
254  h1 += y1;
255  }
256 
257  }
258  catch(JLANG::JException& error) {
259  ERROR(error << std::endl);
260  }
261  }
262  }
263 
264  return h1;
265  }
General exception.
Definition: JException.hh:23
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
JResultEvaluator< JResult_t >::result_type get_value(const JResult_t &value)
Helper method to recursively evaluate a to function value.
Definition: JResult.hh:998
result_type JFIT::JAbstractRegressor< JShowerEH , JSimplex >::operator() ( const JShowerEH value,
T  __begin,
T  __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  }
JRegressor< JShowerEH, JSimplex > regressor_type
Definition: JRegressor.hh:79
JModel_t value
Definition: JSimplex.hh:240
double JFIT::JSimplex< JShowerEH >::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  }
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
double evaluate(const JFunction_t &fit, T __begin, T __end) const
Evaluate chi2 for given data set.
Definition: JSimplex.hh:253
static int MAXIMUM_ITERATIONS
maximal number of iterations
Definition: JSimplex.hh:237
static double EPSILON
maximal distance to minimum
Definition: JSimplex.hh:238
std::vector< JShowerEH > step
Definition: JSimplex.hh:241
double JFIT::JSimplex< JShowerEH >::operator() ( const JFunction_t &  fit,
T  __begin,
T  __end,
const JShowerEH 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  }
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
double evaluate(const JFunction_t &fit, T __begin, T __end) const
Evaluate chi2 for given data set.
Definition: JSimplex.hh:253
static int MAXIMUM_ITERATIONS
maximal number of iterations
Definition: JSimplex.hh:237
static double EPSILON
maximal distance to minimum
Definition: JSimplex.hh:238
std::vector< JShowerEH > step
Definition: JSimplex.hh:241

Member Data Documentation

JTimeRange JFIT::JRegressor< JShowerEH, JSimplex >::T_ns
static

Time window with respect to Cherenkov hypothesis [ns].

Default values.

Definition at line 267 of file JShowerBjorkenYRegressor.hh.

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

Maximal integral of PDF [npe].

Definition at line 268 of file JShowerBjorkenYRegressor.hh.

const int JFIT::JRegressor< JShowerEH, JSimplex >::NUMBER_OF_PDFS = 4
static

Definition at line 270 of file JShowerBjorkenYRegressor.hh.

const JPDFType_t JFIT::JRegressor< JShowerEH, JSimplex >::pdf_t
static

PDF.

Definition at line 274 of file JShowerBjorkenYRegressor.hh.

PDF.

Definition at line 275 of file JShowerBjorkenYRegressor.hh.

M-Estimator function.

Definition at line 277 of file JShowerBjorkenYRegressor.hh.

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

maximal number of iterations

maximal number of iterations.

Definition at line 237 of file JSimplex.hh.

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

maximal distance to minimum

maximal distance to minimum.

Definition at line 238 of file JSimplex.hh.

JShowerEH JFIT::JSimplex< JShowerEH >::value
inherited

Definition at line 240 of file JSimplex.hh.

Definition at line 241 of file JSimplex.hh.

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

Definition at line 242 of file JSimplex.hh.

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: