Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
JSchwarzenegger.cc File Reference

Program to test JFIT::JGandalf algorithm. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include "TROOT.h"
#include "TFile.h"
#include "TF1.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TMath.h"
#include "TRandom3.h"
#include "JFit/JGandalf.hh"
#include "JTools/JElement.hh"
#include "JTools/JStats.hh"
#include "JROOT/JRootToolkit.hh"
#include "JMath/JGauss.hh"
#include "JMath/JConstants.hh"
#include "Jeep/JTimer.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

Program to test JFIT::JGandalf algorithm.

Author
mdejong

Definition in file JSchwarzenegger.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 74 of file JSchwarzenegger.cc.

75{
76 using namespace std;
77 using namespace JPP;
78
79 string outputFile;
81 Int_t seed;
82 int debug;
83
84 try {
85
86 JParser<> zap("Program to test JGandalf algorithm.");
87
88 zap['o'] = make_field(outputFile) = "";
89 zap['@'] = make_field(gauss) = JGauss(0.0, 1.0, 1000.0, 100.0);
90 zap['S'] = make_field(seed) = 0;
91 zap['d'] = make_field(debug) = 3;
92
93 zap(argc, argv);
94 }
95 catch(const exception& error) {
96 FATAL(error.what() << endl);
97 }
98
99
100 gRandom->SetSeed(seed);
101
103
104 TF1 fs("fs", "exp(-0.5 * (x-[0])*(x-[0]) / ([1]*[1]))");
105 TF1 fb("fb", "1.0");
106
107 fs.FixParameter(0, gauss.mean);
108 fs.FixParameter(1, gauss.sigma);
109
110 const Int_t nx = 21;
111 const Double_t xmin = -5.25;
112 const Double_t xmax = +5.25;
113
114
115 TFile out(outputFile.c_str(), "recreate");
116
117 TH1D h0("h0", NULL, nx, xmin, xmax);
118 TH1D h1("h1", NULL, nx*100, xmin, xmax);
119
120 h0.Sumw2();
121 h1.Sumw2();
122 /*
123 for (size_t i = 0; i != (size_t) (gauss.signal); ++i) { h0.Fill(fs.GetRandom(gRandom)); }
124 for (size_t i = 0; i != (size_t) (gauss.background * nx); ++i) { h0.Fill(fb.GetRandom(gRandom)); }
125 */
126 h0.FillRandom("fs", (Int_t) gauss.signal);
127 h0.FillRandom("fb", (Int_t) gauss.background * nx);
128
129 const Int_t ny = 5000;
130 const Double_t ymin = 0.0;
131 const Double_t ymax = gauss.signal + 3.0 * sqrt(gauss.signal) * (xmax - xmin) / nx + gauss.background;
132
133 TH2D h2("h2", NULL,
134 nx, xmin, xmax,
135 ny, ymin, ymax);
136
137
139
140 for (Int_t i = 1; i <= h0.GetNbinsX(); ++i) {
141 data.push_back(JElement_t(h0.GetBinCenter (i),
142 h0.GetBinContent(i)));
143 }
144
146
148
149 fit.parameters.resize(4);
150
151 fit.parameters[0] = &JGauss::mean;
152 fit.parameters[1] = &JGauss::sigma;
153 fit.parameters[2] = &JGauss::signal;
154 fit.parameters[3] = &JGauss::background;
155
156 fit.value = JGauss(h0.GetMean(),
157 h0.GetRMS(),
158 h0.GetEntries() * (xmax - xmin) / nx - h0.GetMinimum(),
159 h0.GetMinimum());
160
161 const double chi2 = fit(g1, data.begin(), data.end());
162
163 DEBUG("Final value " << fit.value << endl);
164 DEBUG("Chi2 " << chi2 << endl);
165
166 for (Int_t ix = 1; ix <= h1.GetXaxis()->GetNbins(); ++ix) {
167
168 const double x = h1.GetXaxis()->GetBinCenter(ix);
169 const double y = fit.value(x);
170
171 h1.SetBinContent(ix, y);
172 }
173
174 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
175 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
176
177 const double x = h2.GetXaxis()->GetBinCenter(ix);
178 const double y = h2.GetYaxis()->GetBinCenter(iy);
179 const double z = TMath::Poisson(y, fit.value(x));
180
181 h2.SetBinContent(ix, iy, z);
182 }
183 }
184
185 out.Write();
186 out.Close();
187}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
#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
Place holder for custom implementation.
Utility class to parse command line options.
Definition JParser.hh:1698
double gauss(const double x, const double sigma)
Gauss function (normalised to 1 at x = 0).
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Gauss function object.
Definition JMathlib.hh:1589