30int main(
int argc,
char **argv)
35 const char*
const count_t =
"count";
36 const char*
const value_t =
"value";
40 double background = 5;
65 JParser<> zap(
"Program to test JRootfit algorithm.");
74 zap[
'O'] =
make_field(option) = count_t, value_t;
81 catch(
const exception& error) {
82 FATAL(error.what() << endl);
86 gRandom->SetSeed(seed);
90 const size_t nx = 20 *
ls;
91 const double xmin = -5.0 *
ls;
92 const double xmax = +5.0 *
ls;
94 const size_t ny = 20 *
ls;
95 const double ymin = -5.0 *
ls;
96 const double ymax = +5.0 *
ls;
98 const size_t nz = 20 *
ls;
99 const double zmin = -5.0 *
ls;
100 const double zmax = +5.0 *
ls;
104 if (inputFile ==
"") {
106 h3 =
new TH3D(
"h3", NULL, nx, xmin, xmax, ny, ymin, ymax, nz, zmin, zmax);
110 auto f3 = (
JGauss3X<1>(parameters.center, parameters.sigma) *
113 JP0<1>(parameters.signal) +
114 JP0<2>(parameters.background));
119 FillRandom(h3,
f3, N);
123 TFile* in = TFile::Open(inputFile.c_str(),
"exist");
125 in->GetObject(
"h3", h3);
131 const double x0 = h3->GetMean(1);
132 const double y0 = h3->GetMean(2);
133 const double z0 = h3->GetMean(3);
134 const double xs = h3->GetStdDev(1) * 0.17;
135 const double ys = h3->GetStdDev(2) * 0.17;
136 const double zs = h3->GetStdDev(3) * 0.17;
137 const double signal = h3->GetMaximum();
138 const double background = h3->GetMinimum() + 0.10;
148 typedef decltype(
f3) function_type;
152 for (
size_t i = 0; i != getNumberOfParameters<function_type>(); ++i) {
153 cout << setw(2) << i <<
' '
154 <<
FIXED(12,5) << getParameter(
f3, i) << endl;
158 const chrono::steady_clock::time_point t0 = chrono::steady_clock::now();
160 const auto result = (option == count_t ?
161 (writeFits ? Fit<m_count>(h3,
f3, {}, X, Y, Z) : Fit<m_count>(*h3,
f3, {}, X, Y, Z)) :
162 (writeFits ? Fit<m_value>(h3,
f3, {}, X, Y, Z) : Fit<m_value>(*h3,
f3, {}, X, Y, Z)));
164 const chrono::steady_clock::time_point t1 = chrono::steady_clock::now();
166 cout <<
"chi2/NDF " <<
FIXED(7,3) << result.getChi2() <<
"/" << result.getNDF() << endl;
167 cout <<
"Number of iterations " << result.numberOfIterations << endl;
168 cout <<
"Elapsed time [us] " << setw(8) << chrono::duration_cast<chrono::microseconds>(t1 - t0).count() << endl;
170 for (
size_t i = 0; i != result.getNumberOfParameters(); ++i) {
171 cout << setw(2) << i <<
' '
172 <<
FIXED(12,5) << result.getValue(i) <<
" +/- "
173 <<
FIXED(12,5) << result.getError(i) << endl;