Jpp  16.0.3
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

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,
63  JElement2D<double, double>,
64  JGridCollection,
65  double> JFunction1D_t;
66 
67  JFunction1D_t g1;
68 
69  JPolintFunction1D<M,
70  JElement2D<double, double>,
71  JGridCollection,
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 << 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 }
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
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
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
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
data_type v[N+1][M+1]
Definition: JPolint.hh:756
double u[N+1]
Definition: JPolint.hh:755
int numberOfBins
number of bins for average CDF integral of optical module
Definition: JSirene.cc:64
then $DIR JPlotNPE PDG P
Definition: JPlotNPE-PDG.sh:62
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25