105 typedef JToken<
';'> JToken_t;
123 JParser<> zap(
"General purpose fit program for 1D ROOT objects.");
125 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
127 zap[
'F'] =
make_field(formula,
"fit formula, e.g: \"[0]+[1]*x\"");
128 zap[
'@'] =
make_field(startValues,
"start values, e.g: \"p0 = GetMaximum;\"");
134 zap[
'P'] =
make_field(project,
"projection") =
'\0',
'x',
'X',
'y',
'Y';
135 zap[
'O'] =
make_field(option,
"Fit option") =
"";
141 catch(
const exception &error) {
142 FATAL(error.what() << endl);
146 if (option.find(
'O') == string::npos) { option +=
"O"; }
147 if (option.find(
"R") == string::npos) { option +=
"R"; }
148 if (option.find(
"S") == string::npos) { option +=
"S"; }
150 if (
debug == 0 && option.find(
'Q') == string::npos) { option +=
"Q"; }
152 bool px = (project ==
'x' || project ==
'X');
153 bool py = (project ==
'y' || project ==
'Y');
163 TF1* fcn =
new TF1(
"user", formula.c_str());
167 if (fcn->IsZombie()) {
168 FATAL(
"Function: " << formula <<
" is zombie." << endl);
171 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
173 DEBUG(
"Input: " << *input << endl);
178 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
182 const TRegexp regexp(input->getObjectName());
184 TIter iter(dir->GetListOfKeys());
186 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
188 const TString tag(key->GetName());
190 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
194 if (tag.Contains(regexp) &&
isTObject(key)) {
196 TObject*
object = key->ReadObj();
200 TProfile& h1 =
dynamic_cast<TProfile&
>(*object);
202 object = h1.ProjectionX();
208 TH2& h2 =
dynamic_cast<TH2&
>(*object);
212 object = h2.ProjectionX(
"_px",
218 object = h2.ProjectionY(
"_py",
224 ERROR(
"For 2D histograms, use option option -P for projections." << endl);
236 for (vector<JToken_t>::const_iterator i = startValues.begin(); i != startValues.end(); ++i) {
240 for (Int_t i = 0; i != fcn->GetNpar(); ++i) {
241 fcn->SetParError (i, 0.0);
244 for (vector<JToken_t>::const_iterator i = startErrors.begin(); i != startErrors.end(); ++i) {
248 for (vector<JToken_t>::const_iterator i = fixedValues.begin(); i != fixedValues.end(); ++i) {
252 for (vector<JToken_t>::const_iterator i = limitValues.begin(); i != limitValues.end(); ++i) {
257 FATAL(error << endl);
260 DEBUG(
"Start values " << object->GetName() << endl);
262 for (
int j = 0;
j != fcn->GetNpar(); ++
j) {
263 DEBUG(left << setw(12) << fcn->GetParName (
j) <<
' ' <<
267 Double_t xmin = numeric_limits<Double_t>::max();
268 Double_t xmax = numeric_limits<Double_t>::lowest();
271 TH1* h1 =
dynamic_cast<TH1*
>(object);
274 xmin = min(xmin, h1->GetXaxis()->GetXmin());
275 xmax = max(xmax, h1->GetXaxis()->GetXmax());
280 TGraph*
g1 =
dynamic_cast<TGraph*
>(object);
283 for (Int_t i = 0; i !=
g1->GetN(); ++i) {
284 xmin = min(xmin,
g1->GetX()[i]);
285 xmax = max(xmax,
g1->GetX()[i]);
295 fcn->SetRange(xmin, xmax);
300 const chrono::steady_clock::time_point t0 = chrono::steady_clock::now();
302 JFit fit(*
object, fcn, option);
306 const chrono::steady_clock::time_point t1 = chrono::steady_clock::now();
308 if (fit.result != -1) {
312 NOTICE(
"Fit values " << object->GetName() << endl);
313 NOTICE(
"Fit formula " << formula << endl);
314 NOTICE(
"chi2/NDF " <<
FIXED(7,3) << fit.result->Chi2() <<
'/' << fit.result->Ndf() <<
' ' << (fit.result->IsValid() ?
"" :
"failed") << endl);
315 NOTICE(
"Number of calls " << fit.result->NCalls() << endl);
316 NOTICE(
"Elapsed time [us] " << setw(8) << chrono::duration_cast<chrono::microseconds>(t1 - t0).count() << endl);
318 for (
int j = 0;
j != fcn->GetNpar(); ++
j) {
319 NOTICE(left << setw(12) << fcn->GetParName (
j) <<
' ' <<
320 SCIENTIFIC(12,5) << fcn->GetParameter(
j) <<
" +/- " <<
326 WARNING(
"Object: not compatible with ROOT Fit." << endl);