75{
78
81 Int_t seed;
83
84 try {
85
86 JParser<> zap(
"Program to test JGandalf algorithm.");
87
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
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
124
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}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Double_t g1(const Double_t x)
Function.
Place holder for custom implementation.
Utility class to parse command line options.
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).