Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JHistogram1D.cc File Reference

Example program to test JTOOLS::JHistogram1D. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TMath.h"
#include "TRandom.h"
#include "JTools/JHistogram1D.hh"
#include "JTools/JCollection.hh"
#include "JTools/JGrid.hh"
#include "JTools/JSet.hh"
#include "JTools/JQuadrature.hh"
#include "JTools/JFunction1D_t.hh"
#include "JTools/JToolsToolkit.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 JTOOLS::JHistogram1D.

Author
mdejong

Definition in file JTools/JHistogram1D.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 57 of file JTools/JHistogram1D.cc.

58{
59 using namespace std;
60
61 string outputFile;
62 int numberOfEvents;
63 int numberOfBins;
64 bool quadrature;
65 bool subtract;
66 int debug;
67
68 try {
69
70 JParser<> zap("Example program to test 1D histogram.");
71
72 zap['o'] = make_field(outputFile) = "histogram.root";
73 zap['n'] = make_field(numberOfEvents);
74 zap['N'] = make_field(numberOfBins);
75 zap['Q'] = make_field(quadrature);
76 zap['D'] = make_field(subtract);
77 zap['d'] = make_field(debug) = 3;
78
79 zap(argc, argv);
80 }
81 catch(const exception &error) {
82 FATAL(error.what() << endl);
83 }
84
85
86 if (numberOfEvents <= 0) {
87 FATAL("No events." << endl);
88 }
89
90 using namespace JPP;
91
92
93 const Int_t nx = 1000;
94 const Double_t xmin = -5.0;
95 const Double_t xmax = +5.0;
96
97
98 typedef JElement2D<double, double> JElement_t;
99
101
102
103 // abscissa
104
105 if (!quadrature)
106 histogram.configure(make_grid(numberOfBins, xmin, xmax));
107 else
108 histogram.configure(JGaussHermite(numberOfBins));
109
110
111 // fill
112
113 for (int i = 0; i != numberOfEvents; ++i) {
114 histogram.fill(gRandom->Gaus(0.0, 1.0), 1.0);
115 }
116
117 histogram.div((double) numberOfEvents);
118
119
120 // interpolation
121
122 typedef JSplineFunction1S_t JFunction1D_t;
123 //typedef JPolintFunction1D<3, JElement_t, JCollection, JResultHesse<double> > JFunction1D_t;
124
125
126 JFunction1D_t F1;
127
128 integrate(histogram, F1);
129
130 F1.compile();
131
132
133 JFunction1D_t f1;
134
135 makePDF(histogram, f1);
136
137 f1.compile();
138
139 f1.setExceptionHandler(new JFunction1D_t::JDefaultResult(JMATH::zero));
140 F1.setExceptionHandler(new JFunction1D_t::JDefaultResult(JMATH::zero));
141
142
143 TFile out(outputFile.c_str(), "recreate");
144
145 TH1D h0("h0", NULL, nx, xmin, xmax);
146 TH1D h1("h1", NULL, nx, xmin, xmax);
147 TH1D h2("h2", NULL, nx, xmin, xmax);
148
149 TH1D i0("i0", NULL, nx, xmin, xmax);
150 TH1D i1("i1", NULL, nx, xmin, xmax);
151
152 for (int i = 1; i <= h0.GetNbinsX(); ++i) {
153
154 const Double_t x = h0.GetBinCenter(i);
155
156 h0.SetBinContent(i, g1(x));
157 i0.SetBinContent(i, G1(x));
158
159 try {
160 h1.SetBinContent(i, get_value(F1(x).fp));
161 h2.SetBinContent(i, get_value(f1(x)));
162 i1.SetBinContent(i, get_value(F1(x)));
163 }
164 catch(const exception& error) {
165 ERROR(error.what() << endl);
166 }
167 }
168
169 if (subtract) {
170 h1.Add(&h0, -1.0);
171 h2.Add(&h0, -1.0);
172 i1.Add(&i0, -1.0);
173 }
174
175 out.Write();
176 out.Close();
177}
string outputFile
#define ERROR(A)
Definition JMessage.hh:66
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#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
Double_t G1(const Double_t x)
Integral of method g1.
Definition JQuantiles.cc:37
bool quadrature
Definition JResultPDF.cc:23
int numberOfBins
number of bins for average CDF integral of optical module
Definition JSirene.cc:73
Utility class to parse command line options.
Definition JParser.hh:1698
Numerical integrator for .
Histogram in 1D.
void fill(typename JClass< abscissa_type >::argument_type x, typename JClass< contents_type >::argument_type w)
Fill histogram.
JHistogram1D & div(const double value)
Scale contents.
const JPolynome F1
Integral.
const JPolynome f1(1.0, 2.0, 3.0)
Function.
const double xmax
const double xmin
static const JZero zero
Function object to assign zero value.
Definition JZero.hh:105
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JElement_t::ordinate_type integrate(const JCollection< JElement_t, JDistance_t > &input, typename JMappable< JElement_t >::map_type &output)
Conversion of data points to integral values.
void makePDF(const JHistogram1D< JElement_t, JContainer_t, JDistance_t > &input, typename JMappable< JElement_t >::map_type &output)
Conversion of histogram to probability density function (PDF).
JGrid< JAbscissa_t > make_grid(const int nx, const JAbscissa_t Xmin, const JAbscissa_t Xmax)
Helper method for JGrid.
Definition JGrid.hh:209
2D Element.
Definition JPolint.hh:1131
Type definition of a spline interpolation method based on a JCollection with JResultPDF result type.