Jpp  master_rocky-43-ge265d140c
the software that should make you happy
Functions
JFit/JLegendre.cc File Reference

Example program to test Legendre polynome. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TRandom3.h"
#include "JMath/JLegendre.hh"
#include "JMath/JMathSupportkit.hh"
#include "JFit/JLegendreEstimator.hh"
#include "JTools/JCollection.hh"
#include "JTools/JElement.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 Legendre polynome.

Author
mdejong

Definition in file JFit/JLegendre.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 25 of file JFit/JLegendre.cc.

26 {
27  using namespace std;
28  using namespace JPP;
29 
30  const size_t N = 3;
31 
33 
34  const double xmin = -10.0;
35  const double xmax = +10.0;
36 
37  unsigned int numberOfEvents;
38  unsigned int numberOfBins;
40  double precision;
41  int debug;
42 
43  try {
44 
45  JParser<> zap("Example program to test Legendre polynome.");
46 
47  zap['n'] = make_field(numberOfEvents) = 1000;
48  zap['N'] = make_field(numberOfBins) = 10;
49  zap['L'] = make_field(f1);
50  zap['e'] = make_field(precision) = 1.0e-10;
51  zap['d'] = make_field(debug) = 3;
52 
53  zap(argc, argv);
54  }
55  catch(const exception &error) {
56  FATAL(error.what() << endl);
57  }
58 
59 
60  typedef JCollection< JElement2D<double, double> > collection_type;
61 
62  collection_type data;
63 
64  for (unsigned int i = 0; i != numberOfBins; ++i) {
65 
66  const double x = xmin + i * (xmax - xmin) / (numberOfBins - 1);
67 
68  data[x] = f1(x);
69  }
70 
71  for (collection_type::const_iterator i = data.begin(); i != data.end(); ++i) {
72  DEBUG("data: " << FIXED(7,3) << i->getX() << ' ' << FIXED(7,3) << i->getY() << endl);
73  }
74 
75 
76  JEstimator<JLegendre_t> g1(data.begin(), data.end());
77 
78  for (size_t n = 0; n != g1.size(); ++n) {
79  STATUS("Legendre: " << setw(2) << n << ' ' << FIXED(7,3) << g1[n] << endl);
80  }
81 
82 
83  JQuantile Q;
84 
85  if (numberOfEvents > 0) {
86 
87  for (unsigned int i = 0; i != numberOfEvents; ++i) {
88 
89  const double x = gRandom->Uniform(xmin, xmax);
90  const double y = f1(x);
91  const double z = g1(x);
92 
93  Q.put(y - z);
94  }
95 
96  DEBUG(Q << endl);
97  }
98 
99  ASSERT(numberOfEvents > 0);
100 
101  ASSERT(f1.size() == g1.size());
102 
103  for (size_t n = 0; n != g1.size(); ++n) {
104  ASSERT(fabs(f1[n] - g1[n]) <= precision, "Legendre: " << setw(2) << n << ' ' << FIXED(7,3) << g1[n]);
105  }
106 
107  ASSERT(fabs(Q.getMean()) <= precision);
108 
109  ASSERT(Q.getSTDev() <= precision);
110 
111  return 0;
112 }
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define STATUS(A)
Definition: JMessage.hh:63
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#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
Template definition of linear fit.
Definition: JEstimator.hh:25
Utility class to parse command line options.
Definition: JParser.hh:1698
General purpose class for collection of elements, see: <a href="JTools.PDF";>Collection of elements...
Definition: JCollection.hh:79
const JPolynome f1(1.0, 2.0, 3.0)
Function.
const double xmax
Definition: JQuadrature.cc:24
const double xmin
Definition: JQuadrature.cc:23
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
const int n
Definition: JPolint.hh:786
Definition: JSTDTypes.hh:14
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Base class for Legendre polynome.
Definition: JLegendre.hh:28
Template definition for function evaluation of Legendre polynome.
Definition: JLegendre.hh:269
Auxiliary data structure for running average, standard deviation and quantiles.
Definition: JQuantile.hh:46
double getSTDev() const
Get standard deviation.
Definition: JQuantile.hh:281
void put(const double x, const double w=1.0)
Put value.
Definition: JQuantile.hh:133
double getMean() const
Get mean value.
Definition: JQuantile.hh:252