26{
29
30 double precision;
32
33 try {
34
35 JParser<> zap(
"Program to test ROOT fit.");
36
37 zap[
'e'] =
make_field(precision) = numeric_limits<double>::min();
39
40 zap(argc, argv);
41 }
42 catch(const exception& error) {
43 FATAL(error.what() << endl);
44 }
45
46 string option = "";
47
48 if (option.find('S') == string::npos) {
49 option += 'S';
50 }
51
52 if (
debug < debug_t && option.find(
'Q') == string::npos) {
53 option += "Q";
54 }
55
56
57 TH1D h1("h1", NULL, 1, -0.5, +0.5);
58
59
60 struct {
62 double z;
64 { 100.0, 10.0 },
65 { 0.0, 10.0 }
66 };
67
68
69 for (
int i = 0; i !=
sizeof(
data)/
sizeof(
data[0]); ++i) {
70
71 const double y =
data[i].y;
72 const double z =
data[i].z;
73
74 h1.SetBinContent(1, y);
75 h1.SetBinError (1, z);
76
77 {
78 NOTICE(
"ROOT fit " <<
FIXED(7,3) << y <<
" +/- " <<
FIXED(7,3) << z << endl);
79
80 TF1 f1("f1", "[0]");
81
82 double ymin, ymax;
83
84 f1.SetParLimits(0, 0.0, 0.0);
85 f1.GetParLimits(0, ymin, ymax);
86
87 const TFitResultPtr
result = h1.Fit(&f1, option.c_str());
88
90
92 <<
FIXED(7,3) << f1.GetParameter(0) <<
" +/- "
93 <<
FIXED(7,3) << f1.GetParError (0) <<
" "
94 <<
"[" <<
FIXED(7,3) << ymin <<
"," <<
FIXED(7,3) << ymax <<
"]" <<
" "
95 << (
result->IsParameterBound(0) ?
" *** bound *** " :
"")
96 << (
result->IsParameterFixed(0) ?
" *** fixed *** " :
"")
97 << endl);
98 }
99 {
100 NOTICE(
"Normal fit " <<
FIXED(7,3) << y <<
" +/- " <<
FIXED(7,3) << z << endl);
101
102 TF1 f1("f1", "[0]");
103
106
107 const TFitResultPtr
result = h1.Fit(&f1, option.c_str());
108
110
112 <<
FIXED(7,3) << f1.GetParameter(0) <<
" +/- "
113 <<
FIXED(7,3) << f1.GetParError (0) <<
" "
114 << (
result->IsParameterBound(0) ?
" *** bound *** " :
"")
115 << (
result->IsParameterFixed(0) ?
" *** fixed *** " :
"")
116 << endl);
117
121 ASSERT(fabs(f1.GetParameter(0) - y) < f1.GetParError(0));
122 }
123 {
124 NOTICE(
"Fixed parameters fit " <<
FIXED(7,3) << y <<
" +/- " <<
FIXED(7,3) << z << endl);
125
126 TF1 f1("f1", "[0]");
127
131
133
136
137 const TFitResultPtr
result = h1.Fit(&f1, option.c_str());
138
140
142 <<
FIXED(7,3) << f1.GetParameter(0) <<
" +/- "
143 <<
FIXED(7,3) << f1.GetParError (0) <<
" "
144 << (
result->IsParameterBound(0) ?
" *** bound *** " :
"")
145 << (
result->IsParameterFixed(0) ?
" *** fixed *** " :
"")
146 << endl);
147
151 ASSERT(fabs(f1.GetParameter(0) - parameter.value) < precision);
152 ASSERT(fabs(f1.GetParError (0)) < precision);
153 }
154 {
155 NOTICE(
"Fixed parameters fit " <<
FIXED(7,3) << y <<
" +/- " <<
FIXED(7,3) << z << endl);
156
157 TF1 f1("f1", "[0]");
158
162
164
167
168 const TFitResultPtr
result = h1.Fit(&f1, option.c_str());
169
171
173 <<
FIXED(7,3) << f1.GetParameter(0) <<
" +/- "
174 <<
FIXED(7,3) << f1.GetParError (0) <<
" "
175 << (
result->IsParameterBound(0) ?
" *** bound *** " :
"")
176 << (
result->IsParameterFixed(0) ?
" *** fixed *** " :
"")
177 << endl);
178
182 ASSERT(fabs(f1.GetParameter(0) - parameter.value) < precision);
183 ASSERT(fabs(f1.GetParError (0)) < precision);
184 }
185 {
186 NOTICE(
"Released parameters fit " <<
FIXED(7,3) << y <<
" +/- " <<
FIXED(7,3) << z << endl);
187
188 TF1 f1("f1", "[0]");
189
192
195
197
198 const TFitResultPtr
result = h1.Fit(&f1, option.c_str());
199
201
203 <<
FIXED(7,3) << f1.GetParameter(0) <<
" +/- "
204 <<
FIXED(7,3) << f1.GetParError (0) <<
" "
205 << (
result->IsParameterBound(0) ?
" *** bound *** " :
"")
206 << (
result->IsParameterFixed(0) ?
" *** fixed *** " :
"")
207 << endl);
208
212 ASSERT(fabs(f1.GetParameter(0) - y) < f1.GetParError(0));
213 }
214 }
215
216 return 0;
217}
#define DEBUG(A)
Message macros.
#define ASSERT(A,...)
Assert macro.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Utility class to parse command line options.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
bool fixParameter(TF1 &f1, const JFitParameter_t ¶meter)
Fix fit parameter.
bool setParameter(TF1 &f1, const JFitParameter_t ¶meter)
Set fit parameter.
bool isParameterFixed(const TF1 &f1, const Int_t index)
Check if fit parameter is fixed.
bool releaseParameter(TF1 &f1, const Int_t index)
Release fit parameter.
Auxiliary data structure for floating point format specification.
Auxiliary data structure for a parameter index and its value.