15#include "TFitResult.h"
51 const std::string& option) :
64 void operator()(
const JType<T>& type)
67 result =
dynamic_cast<T&
>(object).
Fit(fcn, option.c_str(),
"same");
69 catch(
const std::exception&) {}
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\"");
134 zap[
'P'] =
make_field(project,
"projection") =
'\0',
'x',
'X',
'y',
'Y';
141 catch(
const exception &error) {
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);
178 ERROR(
"File: " << input->getFullFilename() <<
" not opened." <<
endl);
188 const TString tag(key->GetName());
196 TObject*
object = key->ReadObj();
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);
240 for (
Int_t i = 0; i != fcn->GetNpar(); ++i) {
241 fcn->SetParError (i, 0.0);
260 DEBUG(
"Start values " << object->GetName() <<
endl);
262 for (
int j = 0;
j != fcn->GetNpar(); ++
j) {
263 DEBUG(left <<
setw(12) << fcn->GetParName (
j) <<
' ' <<
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);
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);
General purpose messaging.
#define DEBUG(A)
Message macros.
static JMinimizer minimizer
ROOT minimizer.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
I/O formatting auxiliaries.
Double_t g1(const Double_t x)
Function.
Auxiliary class to define a range between two values.
Exception for parsing value.
Wrapper class around string.
Template definition of a multi-dimensional oscillation probability interpolation table.
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
int getParameter(const std::string &text)
Get parameter number from text string.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
void for_each(JObject_t &object, JType< JTypeList< JHead_t, JTail_t > > typelist)
For each data type method.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
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.
int main(int argc, char **argv)
Auxiliary data structure for floating point format specification.
Type definition of range.
Auxiliary class for a type holder.
Auxiliary data structure to define ROOT minimizer.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Auxiliary data structure for floating point format specification.