47 const std::string& option) :
60 void operator()(
const JType<T>& type)
63 result =
dynamic_cast<T&
>(object).
Fit(fcn, option.c_str(),
"same");
65 catch(
const std::exception&) {}
96 int main(
int argc,
char **argv)
117 JParser<> zap(
"General purpose fit program for 1D ROOT objects.");
119 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
121 zap[
'F'] =
make_field(formula,
"fit formula, e.g: \"[0]+[1]*x\"");
122 zap[
'@'] =
make_field(startValues,
"start values, e.g: \"p0 = GetMaximum;\"");
126 zap[
'P'] =
make_field(project,
"projection") =
'\0',
'x',
'X',
'y',
'Y';
127 zap[
'O'] =
make_field(option,
"Fit option") =
"";
132 catch(
const exception &error) {
133 FATAL(error.what() << endl);
137 if (option.find(
'O') == string::npos) { option +=
"O"; }
139 if (
debug == 0 && option.find(
'Q') == string::npos) { option +=
"Q"; }
141 bool px = (project ==
'x' || project ==
'X');
142 bool py = (project ==
'y' || project ==
'Y');
152 TF1* fcn =
new TF1(
"user", formula.c_str());
156 if (fcn->IsZombie()) {
157 FATAL(
"Function: " << formula <<
" is zombie." << endl);
162 DEBUG(
"Input: " << *input << endl);
167 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
171 const TRegexp regexp(input->getObjectName());
173 TIter iter(dir->GetListOfKeys());
175 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
177 const TString tag(key->GetName());
179 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
183 if (tag.Contains(regexp) &&
isTObject(key)) {
185 TObject*
object = key->ReadObj();
189 TProfile&
h1 =
dynamic_cast<TProfile&
>(*object);
191 object = h1.ProjectionX();
197 TH2& h2 =
dynamic_cast<TH2&
>(*object);
201 object = h2.ProjectionX(
"_px",
202 h2.GetYaxis()->FindBin(
Y.getLowerLimit()),
203 h2.GetYaxis()->FindBin(
Y.getUpperLimit()));
207 object = h2.ProjectionY(
"_py",
208 h2.GetXaxis()->FindBin(
Y.getLowerLimit()),
209 h2.GetXaxis()->FindBin(
Y.getUpperLimit()));
213 ERROR(
"For 2D histograms, use option option -P for projections." << endl);
234 FATAL(error << endl);
237 DEBUG(
"Start values " << object->GetName() << endl);
239 for (
int j = 0;
j != fcn->GetNpar(); ++
j) {
240 DEBUG(left << setw(12) << fcn->GetParName (
j) <<
' ' <<
244 Double_t
xmin = numeric_limits<Double_t>::max();
245 Double_t
xmax = numeric_limits<Double_t>::lowest();
248 TH1*
h1 =
dynamic_cast<TH1*
>(object);
251 xmin = min(xmin, h1->GetXaxis()->GetXmin());
252 xmax = max(xmax, h1->GetXaxis()->GetXmax());
257 TGraph*
g1 =
dynamic_cast<TGraph*
>(object);
260 for (Int_t i = 0; i != g1->GetN(); ++i) {
261 xmin = min(xmin, g1->GetX()[i]);
262 xmax = max(xmax, g1->GetX()[i]);
268 xmin =
X.getLowerLimit();
269 xmax =
X.getUpperLimit();
272 fcn->SetRange(xmin, xmax);
274 if (option.find(
"R") == string::npos) {
281 JFit fit(*
object, fcn, option);
286 if (fit.result != -1) {
290 NOTICE(
"Fit values " << object->GetName() << endl);
291 NOTICE(
"Fit formula " << formula << endl);
293 for (
int j = 0;
j != fcn->GetNpar(); ++
j) {
294 NOTICE(left << setw(12) << fcn->GetParName (
j) <<
' ' <<
295 SCIENTIFIC(12,5) << fcn->GetParameter(
j) <<
" +/- " <<
301 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 main(int argc, char *argv[])
int getParameter(const std::string &text)
Get parameter number from text string.
TFitResultPtr Fit(TH1D *h)
then for HISTOGRAM in h0 h1
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Auxiliary class for a type holder.
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
Type definition of range.
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
do set_variable OUTPUT_DIRECTORY $WORKDIR T
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.
Exception for parsing value.
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
no fit printf nominal n $STRING awk v X
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
Auxiliary data structure for floating point format specification.
#define DEBUG(A)
Message macros.
JFit()
Default constructor.
Double_t g1(const Double_t x)
Function.