60 result =
dynamic_cast<T&
>(object).Fit(tuple.first, tuple.second.first.c_str(),
"same", tuple.second.second.first, tuple.second.second.second);
62 catch(
const std::exception&) {}
92 int main(
int argc,
char **argv)
113 JParser<> zap(
"General purpose fit program using ROOT.");
115 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
117 zap[
'F'] =
make_field(formula,
"fit formula, e.g: \"[0]+[1]*x\"");
118 zap[
'@'] =
make_field(startValues,
"start values, e.g: \"p0 = GetMaximum;\"");
119 zap[
'='] =
make_field(fixedValues,
"fixed values, e.g: \"p0 = GetMaximum;\"");
120 zap[
'x'] =
make_field(X,
"abscissa range") = JRange_t();
121 zap[
'y'] =
make_field(Y,
"ordinate range") = JRange_t();
122 zap[
'P'] =
make_field(project,
"projection") =
'\0',
'x',
'X',
'y',
'Y';
123 zap[
'O'] =
make_field(option,
"Fit option") =
"";
130 catch(
const exception &error) {
131 FATAL(error.what() << endl);
135 if (option.find(
'O') == string::npos) { option +=
"O"; }
137 if (
debug == 0 && option.find(
'Q') == string::npos) { option +=
"Q"; }
139 bool px = (project ==
'x' || project ==
'X');
140 bool py = (project ==
'y' || project ==
'Y');
150 TF1* fcn =
new TF1(
"user", formula.c_str());
154 if (fcn->IsZombie()) {
155 FATAL(
"Function: " << formula <<
" is zombie." << endl);
160 DEBUG(
"Input: " << *input << endl);
165 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
169 const TRegexp regexp(input->getObjectName());
171 TIter iter(dir->GetListOfKeys());
173 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
175 const TString tag(key->GetName());
177 DEBUG(
"Key: " << tag <<
" match = " << tag.Index(regexp) <<
" (-1 /= OK)" << endl);
181 if (tag.Index(regexp) != -1) {
183 TObject*
object = key->ReadObj();
187 TProfile& h1 =
dynamic_cast<TProfile&
>(*object);
189 object = h1.ProjectionX();
195 TH2& h2 =
dynamic_cast<TH2&
>(*object);
199 object = h2.ProjectionX(
"_px",
200 h2.GetYaxis()->FindBin(Y.getLowerLimit()),
201 h2.GetYaxis()->FindBin(Y.getUpperLimit()));
205 object = h2.ProjectionY(
"_py",
206 h2.GetXaxis()->FindBin(Y.getLowerLimit()),
207 h2.GetXaxis()->FindBin(Y.getUpperLimit()));
211 ERROR(
"For 2D histograms, use option option -P for projections." << endl);
232 FATAL(error << endl);
235 DEBUG(
"Start values " << object->GetName() << endl);
237 for (
int j = 0; j != fcn->GetNpar(); ++j) {
238 DEBUG(left << setw(12) << fcn->GetParName (j) <<
' ' <<
239 SCIENTIFIC(12,5) << fcn->GetParameter(j) << endl);
242 Double_t xmin = +numeric_limits<Double_t>::max();
243 Double_t xmax = -numeric_limits<Double_t>::max();
246 TH1* h1 =
dynamic_cast<TH1*
>(object);
249 xmin = min(xmin, h1->GetXaxis()->GetXmin());
250 xmax = max(xmax, h1->GetXaxis()->GetXmax());
255 TGraph*
g1 =
dynamic_cast<TGraph*
>(object);
258 for (Int_t i = 0; i != g1->GetN(); ++i) {
259 xmin = min(xmin, g1->GetX()[i]);
260 xmax = max(xmax, g1->GetX()[i]);
265 if (X != JRange_t()) {
266 xmin = X.getLowerLimit();
267 xmax = X.getUpperLimit();
278 if (fit.result != -1) {
282 NOTICE(
"Fit values " << object->GetName() << endl);
283 NOTICE(
"Fit formula " << formula << endl);
285 for (
int j = 0; j != fcn->GetNpar(); ++j) {
286 NOTICE(left << setw(12) << fcn->GetParName (j) <<
' ' <<
287 SCIENTIFIC(12,5) << fcn->GetParameter(j) <<
" +/- " <<
288 SCIENTIFIC(12,5) << fcn->GetParError (j) << endl);
293 WARNING(
"Object: not compatible with ROOT Fit." << endl);
Utility class to parse command line options.
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
int getParameter(const std::string &text)
Get parameter number from text string.
Empty structure for specification of parser element that is initialised (i.e.
Auxiliary class for a type holder.
Data structure for track fit results.
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
General purpose messaging.
JObject_t & for_each(JObject_t &object, JType< JTypeList< JHead_t, JTail_t > > typelist)
For each data type method.
Auxiliary class to define a range between two values.
Utility class to parse command line options.
Wrapper class around string.
Data structure based on type list.
Exception for parsing value.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
Auxiliary data structure for floating point format specification.
#define DEBUG(A)
Message macros.
Double_t g1(const Double_t x)
Function.
int main(int argc, char *argv[])