118 JParser<> zap(
"General purpose fit program for 2D ROOT objects.");
120 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
122 zap[
'F'] =
make_field(formula,
"fit formula, e.g: \"[0]+[1]*x\"");
123 zap[
'@'] =
make_field(startValues,
"start values, e.g: \"p0 = GetMaximum;\"");
128 zap[
'O'] =
make_field(option,
"Fit option") =
"";
129 zap[
'w'] =
make_field(writeFits,
"write fit results to ROOT file");
136 catch(
const exception &error) {
137 FATAL(error.what() << endl);
141 if (option.find(
'O') == string::npos) { option +=
"O"; }
143 if (
debug == 0 && option.find(
'Q') == string::npos) { option +=
"Q"; }
149 TF2* fcn =
new TF2(
"user", formula.c_str());
153 if (fcn->IsZombie()) {
154 FATAL(
"Function: " << formula <<
" is zombie." << endl);
159 DEBUG(
"Input: " << *input << endl);
164 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
168 const TRegexp regexp(input->getObjectName());
170 TIter iter(dir->GetListOfKeys());
172 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
174 const TString tag(key->GetName());
176 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
180 if (tag.Contains(regexp) &&
isTObject(key)) {
182 TObject*
object = key->ReadObj();
202 FATAL(error << endl);
205 DEBUG(
"Start values " << object->GetName() << endl);
207 for (
int i = 0;
i != fcn->GetNpar(); ++
i) {
208 DEBUG(left << setw(12) << fcn->GetParName (
i) <<
' ' <<
212 Double_t
xmin = numeric_limits<Double_t>::max();
213 Double_t
xmax = numeric_limits<Double_t>::lowest();
214 Double_t ymin = numeric_limits<Double_t>::max();
215 Double_t ymax = numeric_limits<Double_t>::lowest();
218 TH2* h2 =
dynamic_cast<TH2*
>(object);
222 xmin = min(xmin, h2->GetXaxis()->GetXmin());
223 xmax = max(xmax, h2->GetXaxis()->GetXmax());
224 ymin = min(ymin, h2->GetYaxis()->GetXmin());
225 ymax = max(ymax, h2->GetYaxis()->GetXmax());
227 if (
X !=
JRange_t()) { h2->GetXaxis()->SetRangeUser(
X.getLowerLimit(),
X.getUpperLimit()); }
228 if (
Y !=
JRange_t()) { h2->GetYaxis()->SetRangeUser(
Y.getLowerLimit(),
Y.getUpperLimit()); }
233 TGraph2D* g2 =
dynamic_cast<TGraph2D*
>(object);
236 for (Int_t
i = 0;
i != g2->GetN(); ++
i) {
237 xmin = min(xmin, g2->GetX()[
i]);
238 xmax = max(xmax, g2->GetX()[
i]);
239 ymin = min(ymin, g2->GetY()[
i]);
240 ymax = max(ymax, g2->GetY()[
i]);
246 xmin =
X.getLowerLimit();
247 xmax =
X.getUpperLimit();
251 ymin =
Y.getLowerLimit();
252 ymax =
Y.getUpperLimit();
255 fcn->SetRange(xmin, ymin, xmax, ymax);
257 if (option.find(
"R") == string::npos) {
264 JFit fit(*
object, fcn, option);
269 if (fit.result != -1) {
273 NOTICE(
"Fit values " << object->GetName() << endl);
274 NOTICE(
"Fit formula " << formula << endl);
276 for (
int j = 0;
j != fcn->GetNpar(); ++
j) {
277 NOTICE(left << setw(12) << fcn->GetParName (
j) <<
' ' <<
278 SCIENTIFIC(12,5) << fcn->GetParameter(
j) <<
" +/- " <<
284 WARNING(
"Object: not compatible with ROOT Fit." << endl);
297 TH2* h2 =
dynamic_cast<TH2*
>(p);
300 for (Int_t ix = 1; ix <= h2->GetXaxis()->GetNbins(); ++ix) {
301 for (Int_t iy = 1; iy <= h2->GetYaxis()->GetNbins(); ++iy) {
303 const Double_t
x = h2->GetXaxis()->GetBinCenter(ix);
304 const Double_t
y = h2->GetYaxis()->GetBinCenter(iy);
306 h2->SetBinContent(ix, iy, fcn->Eval(x,y));
307 h2->SetBinError (ix, iy, 0.0);
314 TGraph2D* g2 =
dynamic_cast<TGraph2D*
>(p);
317 for (Int_t
i = 0;
i != g2->GetN(); ++
i) {
319 const Double_t x = g2->GetX()[
i];
320 const Double_t y = g2->GetY()[
i];
322 g2->GetZ()[
i] = fcn->Eval(x,y);
328 TGraph2DErrors* g2 =
dynamic_cast<TGraph2DErrors*
>(p);
331 for (Int_t
i = 0;
i != g2->GetN(); ++
i) {
332 g2->SetPointError(
i, 0.0, 0.0, 0.0);
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.
#define MAKE_CSTRING(A)
Make C-string.
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.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
JObject_t & for_each(JObject_t &object, JType< JTypeList< JHead_t, JTail_t > > typelist)
For each data type method.
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.