31{
34
35 const char* const count_t = "count";
36 const char* const value_t = "value";
37
38 struct {
39 double signal = 100;
40 double background = 5;
41 double center = 0.0;
43 } parameters;
44
45 string inputFile;
49 size_t N;
50 string option;
51 bool writeFits;
52 ULong_t seed;
54
55 try {
56
58
63
64 JParser<> zap(
"Program to test JRootfit algorithm.");
65
72 zap[
'O'] =
make_field(option) = count_t, value_t;
76
77 zap(argc, argv);
78 }
79 catch(const exception& error) {
80 FATAL(error.what() << endl);
81 }
82
83
84 gRandom->SetSeed(seed);
85
87
88 const size_t nx = 20 *
ls;
89 const double xmin = -5.0 *
ls;
90 const double xmax = +5.0 *
ls;
91
92 const size_t ny = 20 *
ls;
93 const double ymin = -5.0 *
ls;
94 const double ymax = +5.0 *
ls;
95
96 TH2D* h2 = NULL;
97
98 if (inputFile == "") {
99
100 h2 = new TH2D("h2", NULL, nx, xmin, xmax, ny, ymin, ymax);
101
102 h2->Sumw2();
103
104 auto f2 = (
JGauss2X<1>(parameters.center, parameters.sigma) *
106 JP0<1>(parameters.signal) +
107 JP0<2>(parameters.background));
108
109 if (N == 0)
111 else
113
114 } else {
115
116 TFile* in = TFile::Open(inputFile.c_str(), "exist");
117
118 in->GetObject("h2", h2);
119 }
120
121
122
123
124 const double x0 = h2->GetMean(1);
125 const double y0 = h2->GetMean(2);
126 const double xs = h2->GetStdDev(1) * 0.33;
127 const double ys = h2->GetStdDev(2) * 0.33;
128 const double signal = h2->GetMaximum();
129 const double background = h2->GetMinimum() + 0.10;
130
131
132
136
137
138
139 typedef decltype(f2) function_type;
140
142
143 for (size_t i = 0; i != getNumberOfParameters<function_type>(); ++i) {
144 cout << setw(2) << i << ' '
145 <<
FIXED(15,9) << getParameter(f2, i) << endl;
146 }
147
148 {
149 const chrono::steady_clock::time_point t0 = chrono::steady_clock::now();
150
151 const auto result = (option == count_t ?
152 (writeFits ? Fit<m_count>(h2, f2, {}, X, Y) :
Fit<
m_count>(*h2, f2, {}, X, Y)) :
154
155 const chrono::steady_clock::time_point t1 = chrono::steady_clock::now();
156
157 cout <<
"chi2/NDF " <<
FIXED(7,3) <<
result.getChi2() <<
"/" <<
result.getNDF() << endl;
158 cout <<
"Number of iterations " <<
result.numberOfIterations << endl;
159 cout << "Elapsed time [us] " << setw(8) << chrono::duration_cast<chrono::microseconds>(t1 - t0).count() << endl;
160
161 for (
size_t i = 0; i !=
result.getNumberOfParameters(); ++i) {
162 cout << setw(2) << i << ' '
165 }
166 }
167
169
170 out << *h2;
171
172 out.Write();
173 out.Close();
174}
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Utility class to parse parameter values.
Utility class to parse command line options.
JExp< JF1_t > Exp(const JF1_t &f1)
Exponent of function.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
void FillRandom(TH1 *h1, const T &f1)
Fill 1D histogram according Poisson statistics with expectation values from given 1D function.
JRootfit_t< JF1_t > Fit(const TH1 &h1, const JF1_t &f1, const index_list &ls=index_list(), const range_type &X=range_type())
Global fit fuction.
Auxiliary data structure for floating point format specification.
Make 2D function of x from 1D function.
Make 2D function of y from 1D function.
Termination class for polynomial function.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Data point for counting measurement.
Data point for value with error.
Auxiliary data structure to list files in directory.