32{
35
36 const char* const count_t = "count";
37 const char* const value_t = "value";
38
39 struct {
40 double signal = 25;
41 double background = 5;
42 double center = 0.0;
43 double sigma = 1.0;
44 } parameters;
45
46 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
71 zap[
'O'] =
make_field(option) = count_t, value_t;
75
76 zap(argc, argv);
77 }
78 catch(const exception& error) {
79 FATAL(error.what() << endl);
80 }
81
82
83 gRandom->SetSeed(seed);
84
85 const size_t nx = 20;
86 const double xmin = parameters.center - 5.0 * parameters.sigma;
87 const double xmax = parameters.center + 5.0 * parameters.sigma;
88
89 TH1D* h1 = NULL;
90
91 if (inputFile == "") {
92
93 h1 = new TH1D("h1", NULL, nx, xmin, xmax);
94
95 h1->Sumw2();
96
97 auto f0 =
JP0<1>(parameters.signal) * JGauss<1>(parameters.center, parameters.sigma) +
JP0<2>(parameters.background);
98
99 if (N == 0)
101 else
103
104 } else {
105
106 TFile* in = TFile::Open(inputFile.c_str(), "exist");
107
108 in->GetObject("h1", h1);
109 }
110
111
112
113
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;
118
119
120
121
122 auto f1 =
JP0<1>(signal) * JGauss<1>(center, sigma) +
Exp(
JP0<2>(log(background)));
123
124 typedef decltype(f1) function_type;
125
127
128 for (size_t i = 0; i != getNumberOfParameters<function_type>(); ++i) {
129 cout << setw(2) << i <<
' ' <<
FIXED(15,9) << f1[i] << endl;
130 }
131
132 {
133 const chrono::steady_clock::time_point t0 = chrono::steady_clock::now();
134
135 const auto result = (option == count_t ?
136 (writeFits ? Fit<m_count>(h1, f1, {}, X) :
Fit<
m_count>(*h1, f1, {}, X)) :
138
139 const chrono::steady_clock::time_point t1 = chrono::steady_clock::now();
140
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;
144
145 for (
size_t i = 0; i !=
result.getNumberOfParameters(); ++i) {
146 cout << setw(2) << i << ' '
149 }
150 }
151 {
153
154 for (Int_t ix = 1; ix <= h1->GetXaxis()->GetNbins(); ++ix) {
155
156 const double x = h1->GetXaxis()->GetBinCenter(ix);
157 const double value = h1->GetBinContent(ix);
158 const double error = h1->GetBinError (ix);
159
160 gs.
put(x, value, 0.0, error);
161 }
162
164
166
167 cout <<
"chi2/NDF " <<
FIXED(7,3) <<
result.getChi2() <<
"/" <<
result.getNDF() << endl;
168 cout <<
"Number of iterations " <<
result.numberOfIterations << endl;
169
170 for (
size_t i = 0; i !=
result.getNumberOfParameters(); ++i) {
171 cout << setw(2) << i << ' '
174 }
175 }
176
178
179 out << *h1;
180
181 out.Write();
182 out.Close();
183}
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Double_t g1(const Double_t x)
Function.
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.
Termination class for polynomial function.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Data structure for graph data.
void put(const Double_t x, const Double_t y, const Double_t ex, const Double_t ey)
Put data.
Auxiliary data structure to build TGraphErrors.
Data point for counting measurement.
Data point for value with error.