Jpp  15.0.5
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPolynome1P.cc File Reference

Example program to test 1D interpolation of a polynome. More...

#include <string>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include "TRandom3.h"
#include "JLang/JException.hh"
#include "JMath/JPolynome.hh"
#include "JTools/JFunction1D_t.hh"
#include "JTools/JGrid.hh"
#include "JTools/JQuantile.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test 1D interpolation of a polynome.

Author
mdejong

Definition in file JPolynome1P.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 25 of file JPolynome1P.cc.

26 {
27  using namespace std;
28  using namespace JPP;
29 
30  unsigned int numberOfEvents;
31  unsigned int numberOfBins;
32  JPolynome f1;
33  double x0;
34  int debug;
35 
36  try {
37 
38  JParser<> zap("Example program to test 1D interpolation of a polynome.");
39 
40  zap['n'] = make_field(numberOfEvents) = 0;
41  zap['N'] = make_field(numberOfBins) = 21;
42  zap['P'] = make_field(f1);
43  zap['x'] = make_field(x0) = 0.0;
44  zap['d'] = make_field(debug) = 1;
45 
46  zap(argc, argv);
47  }
48  catch(const exception &error) {
49  FATAL(error.what() << endl);
50  }
51 
52  if (f1.empty()) {
53  FATAL("Invalid polynomial.");
54  }
55 
56 
57 
58  const int N = 3; // degree of polynomial interpolation
59 
60  typedef JResultPolynome<N, double> JResult_t;
61  typedef JPolintFunction1D<N, JElement2D<double, double>, JCollection, JResult_t> JFunction1D_t;
62 
63 
64  JFunction1D_t polint;
65 
66 
67  const double xmin = -1.0;
68  const double xmax = +1.0;
69 
70  polint.configure(JGrid<double>(numberOfBins, xmin, xmax), f1);
71 
72  polint.compile();
73 
74  polint.setExceptionHandler(new JFunction1D_t::JDefaultResult(JMATH::zero));
75 
76 
77  vector<JPolynome> fp(1, f1);
78 
79  for (int i = 1; i != (int) f1.size(); ++i) {
80  fp.push_back(fp.rbegin()->getDerivative());
81  }
82 
83  DEBUG("polynome: ");
84 
85  for (int i = 0; i != (int) f1.size(); ++i) {
86  DEBUG(' ' << fp[i](x0));
87  }
88  DEBUG(endl);
89 
90  DEBUG("result: ");
91 
92  JResult_t result = polint(x0);
93 
94  for (int i = 0; i != N+1; ++i) {
95  DEBUG(' ' << result.y[i]);
96  }
97  DEBUG(endl);
98 
99 
100  if (numberOfEvents != 0) {
101 
102  JQuantile Q[N+1];
103 
104  for (int j = 0; j != sizeof(Q)/sizeof(Q[0]); ++j) {
105 
106  ostringstream os;
107 
108  os << "f^" << j;
109 
110  Q[j].setTitle(os.str());
111  }
112 
113  const int M = min(fp.size(), sizeof(Q)/sizeof(Q[0]));
114 
115  for (unsigned int i = 0; i != numberOfEvents; ++i) {
116 
117  const double x = gRandom->Uniform(xmin, xmax);
118 
119  JResult_t result = polint(x);
120 
121  for (int j = 0; j != M; ++j) {
122  Q[j].put(fp[j](x) - result.y[j]);
123  }
124  }
125 
126  for (int j = 0; j != M; ++j) {
127  Q[j].print(cout, j == 0);
128  }
129  }
130 }
Utility class to parse command line options.
Definition: JParser.hh:1500
Q(UTCMax_s-UTCMin_s)-livetime_s
do $JPP JMEstimator M
Definition: JMEstimator.sh:37
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
return result
Definition: JPolint.hh:727
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
int j
Definition: JPolint.hh:666
int numberOfBins
number of bins for average CDF integral of optical module
Definition: JSirene.cc:64