Jpp  19.1.0
the software that should make you happy
Functions
JPolfit1D.cc File Reference

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

#include <string>
#include <iostream>
#include <iomanip>
#include "TRandom3.h"
#include "JLang/JException.hh"
#include "JMath/JPolynome.hh"
#include "JTools/JPolfit.hh"
#include "JTools/JPolint.hh"
#include "JTools/JElement.hh"
#include "JTools/JGridCollection.hh"
#include "JTools/JGrid.hh"
#include "JTools/JQuantile.hh"
#include "JTools/JToolsToolkit.hh"
#include "Jeep/JPrint.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 Legendre interpolation of a polynome.

Author
mdejong

Definition in file JPolfit1D.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 28 of file JPolfit1D.cc.

29 {
30  using namespace std;
31  using namespace JPP;
32 
33  unsigned int numberOfEvents;
34  unsigned int numberOfBins;
35  JPolynome f1;
36  double sigma;
37  double P;
38  int debug;
39 
40  try {
41 
42  JParser<> zap("Example program to test 1D Legendre interpolation of a polynome.");
43 
44  zap['n'] = make_field(numberOfEvents) = 0;
45  zap['N'] = make_field(numberOfBins) = 21;
46  zap['P'] = make_field(f1);
47  zap['s'] = make_field(sigma) = 0.0;
48  zap['p'] = make_field(P) = 0.0;
49  zap['d'] = make_field(debug) = 3;
50 
51  zap(argc, argv);
52  }
53  catch(const exception &error) {
54  FATAL(error.what() << endl);
55  }
56 
57 
58  const int N = 7; // number of points for Legendre interpolation
59  const int M = 3; // degree of Legendre polynome
60 
61  typedef JPolfitFunction1D<N,
62  M,
65  double> JFunction1D_t;
66 
67  JFunction1D_t g1;
68 
72  double> h1;
73 
74  const double xmin = -10.0;
75  const double xmax = +10.0;
76 
77  const JGrid<double> grid(numberOfBins, xmin, xmax);
78 
79  for (int i = 0; i != grid.getSize(); ++i) {
80 
81  const double x = grid.getX(i);
82 
83  g1[x]= f1(x) + (sigma > 0.0 && gRandom->Rndm() < P ? gRandom->Gaus(0.0, sigma) : 0.0);
84  }
85 
86  copy(g1, h1);
87 
88  g1.compile();
89  h1.compile();
90 
91  for (JFunction1D_t::const_iterator i = g1.begin(); i != g1.end(); ++i) {
92  DEBUG(FIXED(12,5) << i->getX() << ' ' << FIXED(12,5) << i->getY() << endl);
93  }
94 
95 
96  if (numberOfEvents != 0) {
97 
98  JQuantile Q[2];
99 
100  for (unsigned int i = 0; i != numberOfEvents; ++i) {
101 
102  const double x = gRandom->Uniform(xmin, xmax);
103  const double y = f1(x);
104  const double u = g1(x);
105  const double v = h1(x);
106 
107  DEBUG(FIXED(12,5) << x << ' ' << FIXED(12,5) << y << ' ' << FIXED(12,5) << u << ' ' << FIXED(12,5) << v << endl);
108 
109  Q[0].put(u - y);
110  Q[1].put(v - y);
111  }
112 
113  Q[0].print(cout);
114  Q[1].print(cout, false);
115  }
116 
117  return 0;
118 }
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25
int numberOfBins
number of bins for average CDF integral of optical module
Definition: JSirene.cc:70
Utility class to parse command line options.
Definition: JParser.hh:1698
General purpose class for collection of equidistant elements.
Template class for polynomial interpolation in 1D.
Definition: JPolfit.hh:174
Template class for polynomial interpolation in 1D.
Definition: JPolint.hh:1095
const double sigma[]
Definition: JQuadrature.cc:74
const JPolynome f1(1.0, 2.0, 3.0)
Function.
const double xmax
Definition: JQuadrature.cc:24
const double xmin
Definition: JQuadrature.cc:23
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double u[N+1]
Definition: JPolint.hh:865
data_type v[N+1][M+1]
Definition: JPolint.hh:866
Definition: JSTDTypes.hh:14
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Recursive template class for polynomial function.
Definition: JMathlib.hh:1381
2D Element.
Definition: JElement.hh:46
Auxiliary data structure for running average, standard deviation and quantiles.
Definition: JQuantile.hh:46
std::ostream & print(std::ostream &out, bool lpr=true) const
Print quantile.
Definition: JQuantile.hh:382
void put(const double x, const double w=1.0)
Put value.
Definition: JQuantile.hh:133