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 using ROOT.");
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;\"");
123 zap[
'='] =
make_field(fixedValues,
"fixed values, e.g: \"p0 = GetMaximum;\"");
124 zap[
'x'] =
make_field(X,
"abscissa range") = JRange_t();
125 zap[
'y'] =
make_field(
Y,
"ordinate range") = JRange_t();
126 zap[
'P'] =
make_field(project,
"projection") =
'\0',
'x',
'X',
'y',
'Y';
127 zap[
'O'] =
make_field(option,
"Fit option") =
"";
134 catch(
const exception &error) {
135 FATAL(error.what() << endl);
139 if (option.find(
'O') == string::npos) { option +=
"O"; }
141 if (
debug == 0 && option.find(
'Q') == string::npos) { option +=
"Q"; }
143 bool px = (project ==
'x' || project ==
'X');
144 bool py = (project ==
'y' || project ==
'Y');
154 TF1* fcn =
new TF1(
"user", formula.c_str());
158 if (fcn->IsZombie()) {
159 FATAL(
"Function: " << formula <<
" is zombie." << endl);
164 DEBUG(
"Input: " << *input << endl);
169 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
173 const TRegexp regexp(input->getObjectName());
175 TIter iter(dir->GetListOfKeys());
177 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
179 const TString tag(key->GetName());
181 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
185 if (tag.Contains(regexp)) {
187 TObject*
object = key->ReadObj();
191 TProfile&
h1 =
dynamic_cast<TProfile&
>(*object);
193 object = h1.ProjectionX();
199 TH2& h2 =
dynamic_cast<TH2&
>(*object);
203 object = h2.ProjectionX(
"_px",
204 h2.GetYaxis()->FindBin(
Y.getLowerLimit()),
205 h2.GetYaxis()->FindBin(
Y.getUpperLimit()));
209 object = h2.ProjectionY(
"_py",
210 h2.GetXaxis()->FindBin(
Y.getLowerLimit()),
211 h2.GetXaxis()->FindBin(
Y.getUpperLimit()));
215 ERROR(
"For 2D histograms, use option option -P for projections." << endl);
236 FATAL(error << endl);
239 DEBUG(
"Start values " << object->GetName() << endl);
241 for (
int j = 0;
j != fcn->GetNpar(); ++
j) {
242 DEBUG(left << setw(12) << fcn->GetParName (
j) <<
' ' <<
246 Double_t xmin = numeric_limits<Double_t>::max();
247 Double_t xmax = numeric_limits<Double_t>::lowest();
250 TH1*
h1 =
dynamic_cast<TH1*
>(object);
253 xmin = min(xmin, h1->GetXaxis()->GetXmin());
254 xmax = max(xmax, h1->GetXaxis()->GetXmax());
259 TGraph*
g1 =
dynamic_cast<TGraph*
>(object);
262 for (Int_t i = 0; i != g1->GetN(); ++i) {
263 xmin = min(xmin, g1->GetX()[i]);
264 xmax = max(xmax, g1->GetX()[i]);
269 if (X != JRange_t()) {
270 xmin = X.getLowerLimit();
271 xmax = X.getUpperLimit();
274 fcn->SetRange(xmin, xmax);
276 if (option.find(
"R") == string::npos) {
283 JFit fit(*
object, fcn, option);
288 if (fit.result != -1) {
292 NOTICE(
"Fit values " << object->GetName() << endl);
293 NOTICE(
"Fit formula " << formula << endl);
295 for (
int j = 0;
j != fcn->GetNpar(); ++
j) {
296 NOTICE(left << setw(12) << fcn->GetParName (
j) <<
' ' <<
297 SCIENTIFIC(12,5) << fcn->GetParameter(
j) <<
" +/- " <<
303 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
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.
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.