74int main(
int argc,
char **argv)
86 JParser<> zap(
"Program to test JGandalf algorithm.");
95 catch(
const exception& error) {
96 FATAL(error.what() << endl);
100 gRandom->SetSeed(seed);
104 TF1 fs(
"fs",
"exp(-0.5 * (x-[0])*(x-[0]) / ([1]*[1]))");
107 fs.FixParameter(0,
gauss.mean);
108 fs.FixParameter(1,
gauss.sigma);
111 const Double_t xmin = -5.25;
112 const Double_t xmax = +5.25;
117 TH1D h0(
"h0", NULL, nx, xmin, xmax);
118 TH1D h1(
"h1", NULL, nx*100, xmin, xmax);
126 h0.FillRandom(
"fs", (Int_t)
gauss.signal);
127 h0.FillRandom(
"fb", (Int_t)
gauss.background * nx);
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;
140 for (Int_t i = 1; i <= h0.GetNbinsX(); ++i) {
141 data.push_back(JElement_t(h0.GetBinCenter (i),
142 h0.GetBinContent(i)));
149 fit.parameters.resize(4);
151 fit.parameters[0] = &JGauss::mean;
152 fit.parameters[1] = &JGauss::sigma;
153 fit.parameters[2] = &JGauss::signal;
154 fit.parameters[3] = &JGauss::background;
156 fit.value =
JGauss(h0.GetMean(),
158 h0.GetEntries() * (xmax - xmin) / nx - h0.GetMinimum(),
161 const double chi2 = fit(
g1, data.begin(), data.end());
163 DEBUG(
"Final value " << fit.value << endl);
164 DEBUG(
"Chi2 " << chi2 << endl);
166 for (Int_t ix = 1; ix <= h1.GetXaxis()->GetNbins(); ++ix) {
168 const double x = h1.GetXaxis()->GetBinCenter(ix);
169 const double y = fit.value(x);
171 h1.SetBinContent(ix, y);
174 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
175 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
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));
181 h2.SetBinContent(ix, iy, z);