31int main(
int argc,
char **argv)
36 const char*
const count_t =
"count";
37 const char*
const value_t =
"value";
41 double background = 5;
64 JParser<> zap(
"Program to test JRootfit algorithm.");
71 zap[
'O'] =
make_field(option) = count_t, value_t;
78 catch(
const exception& error) {
79 FATAL(error.what() << endl);
83 gRandom->SetSeed(seed);
86 const double xmin = parameters.center - 5.0 * parameters.sigma;
87 const double xmax = parameters.center + 5.0 * parameters.sigma;
91 if (inputFile ==
"") {
93 h1 =
new TH1D(
"h1", NULL, nx, xmin, xmax);
97 auto f0 =
JP0<1>(parameters.signal) * JGauss<1>(parameters.center, parameters.sigma) +
JP0<2>(parameters.background);
102 FillRandom(h1, f0, N);
106 TFile* in = TFile::Open(inputFile.c_str(),
"exist");
108 in->GetObject(
"h1", h1);
114 const double center = h1->GetMean();
115 const double sigma = h1->GetStdDev() * 0.66;
116 const double signal = h1->GetMaximum();
117 const double background = h1->GetMinimum() + 0.1;
122 auto f1 =
JP0<1>(signal) * JGauss<1>(center, sigma) + Exp(
JP0<2>(log(background)));
124 typedef decltype(f1) function_type;
128 for (
size_t i = 0; i != getNumberOfParameters<function_type>(); ++i) {
129 cout << setw(2) << i <<
' ' <<
FIXED(15,9) << f1[i] << endl;
133 const chrono::steady_clock::time_point t0 = chrono::steady_clock::now();
135 const auto result = (option == count_t ?
136 (writeFits ? Fit<m_count>(h1, f1, {}, X) : Fit<m_count>(*h1, f1, {}, X)) :
137 (writeFits ? Fit<m_value>(h1, f1, {}, X) : Fit<m_value>(*h1, f1, {}, X)));
139 const chrono::steady_clock::time_point t1 = chrono::steady_clock::now();
141 cout <<
"chi2/NDF " <<
FIXED(7,3) << result.getChi2() <<
"/" << result.getNDF() << endl;
142 cout <<
"Number of iterations " << result.numberOfIterations << endl;
143 cout <<
"Elapsed time [us] " << setw(8) << chrono::duration_cast<chrono::microseconds>(t1 - t0).count() << endl;
145 for (
size_t i = 0; i != result.getNumberOfParameters(); ++i) {
146 cout << setw(2) << i <<
' '
147 <<
FIXED(15,9) << result.getValue(i) <<
" +/- "
148 <<
FIXED(15,9) << result.getError(i) << endl;
154 for (Int_t ix = 1; ix <= h1->GetXaxis()->GetNbins(); ++ix) {
156 const double x = h1->GetXaxis()->GetBinCenter(ix);
157 const double value = h1->GetBinContent(ix);
158 const double error = h1->GetBinError (ix);
160 gs.
put(x, value, 0.0, error);
165 const auto result = Fit(
g1, f1, {}, X);
167 cout <<
"chi2/NDF " <<
FIXED(7,3) << result.getChi2() <<
"/" << result.getNDF() << endl;
168 cout <<
"Number of iterations " << result.numberOfIterations << endl;
170 for (
size_t i = 0; i != result.getNumberOfParameters(); ++i) {
171 cout << setw(2) << i <<
' '
172 <<
FIXED(15,9) << result.getValue(i) <<
" +/- "
173 <<
FIXED(15,9) << result.getError(i) << endl;