Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JPolfit1D.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4
5#include "TRandom3.h"
6
7#include "JLang/JException.hh"
8#include "JMath/JPolynome.hh"
9#include "JTools/JPolfit.hh"
10#include "JTools/JPolint.hh"
11#include "JTools/JElement.hh"
13#include "JTools/JGrid.hh"
14#include "JTools/JQuantile.hh"
16
17#include "Jeep/JPrint.hh"
18#include "Jeep/JParser.hh"
19#include "Jeep/JMessage.hh"
20
21
22/**
23 * \file
24 *
25 * Example program to test 1D Legendre interpolation of a polynome.
26 * \author mdejong
27 */
28int main(int argc, char **argv)
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}
The elements in a collection are sorted according to their abscissa values and a given distance opera...
Exceptions.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int main(int argc, char **argv)
Definition JPolfit1D.cc:28
I/O formatting auxiliaries.
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:73
This include file contains various recursive methods to operate on multi-dimensional collections.
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
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Recursive template class for polynomial function.
Definition JPolynome.hh:165
2D Element.
Definition JPolint.hh:1131
Simple data structure for an abstract collection of equidistant abscissa values.
Definition JGrid.hh:40
virtual int getSize() const override
Get number of elements.
Definition JGrid.hh:75
virtual abscissa_type getX(int index) const override
Get abscissa value.
Definition JGrid.hh:87
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