Jpp  17.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrintFit.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iomanip>
3 #include <iostream>
4 #include <vector>
5 #include <set>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TH1.h"
10 #include "TGraph.h"
11 #include "TGraph2D.h"
12 #include "TF1.h"
13 
14 #include "JTools/JRange.hh"
15 #include "JGizmo/JRootObjectID.hh"
16 #include "JGizmo/JGizmoToolkit.hh"
17 
18 #include "Jeep/JPrint.hh"
19 #include "Jeep/JParser.hh"
20 #include "Jeep/JMessage.hh"
21 
22 
23 /**
24  * Read formula from input stream.
25  *
26  * \param in input stream
27  * \param object formula
28  * \return input stream
29  */
30 inline std::istream& operator>>(std::istream& in, TString& object)
31 {
32  return object.ReadLine(in);
33 }
34 
35 /**
36  * Write formula to output stream.
37  *
38  * \param out output stream
39  * \param object formula
40  * \return output stream
41  */
42 inline std::ostream& operator<<(std::ostream& out, const TString& object)
43 {
44  return out << object.Data();
45 }
46 
47 
48 /**
49  * \file
50  * Auxiliary program to print ROOT fit results.
51  * \author mdejong
52  */
53 int main(int argc, char **argv)
54 {
55  using namespace std;
56  using namespace JPP;
57 
58  JRootObjectID inputFile;
59  string fcn;
61  set<string> parameter;
62  TString formula;
63  int debug;
64 
65  try {
66 
67  JParser<> zap("Auxiliary program to print ROOT fit results.");
68 
69  zap['f'] = make_field(inputFile, "histogram, e.g: <file name>:<object name>");
70  zap['F'] = make_field(fcn, "function name") = "user";
71  zap['x'] = make_field(x, "(x)+, evaluate function at given point") = JPARSER::initialised();
72  zap['@'] = make_field(parameter, "(parameter)+, e.g. \"p0\"") = JPARSER::initialised();
73  zap['F'] = make_field(formula, "ROOT TFormula (may contain method names of TF1)") = JPARSER::initialised();
74  zap['d'] = make_field(debug) = 1;
75 
76  zap(argc, argv);
77  }
78  catch(const exception &error) {
79  FATAL(error.what() << endl);
80  }
81 
82 
83  TObject* p = getObject(inputFile);
84 
85  if (p == NULL) {
86  FATAL("No object at " << inputFile << endl);
87  }
88 
89  TF1* f1 = NULL;
90 
91  if (f1 == NULL && dynamic_cast<TF1*> (p) != NULL) { f1 = dynamic_cast<TF1*> (p); }
92  if (f1 == NULL && dynamic_cast<TH1*> (p) != NULL) { f1 = dynamic_cast<TH1*> (p)->GetFunction(fcn.c_str()); };
93  if (f1 == NULL && dynamic_cast<TGraph*>(p) != NULL) { f1 = dynamic_cast<TGraph*>(p)->GetFunction(fcn.c_str()); };
94 
95  if (f1 == NULL && dynamic_cast<TGraph2D*>(p) != NULL) {
96 
97  for (TIter i = dynamic_cast<TGraph2D*>(p)->GetListOfFunctions(); (f1 = (TF1*) i()) != NULL; ) {
98  if (fcn == f1->GetName()) {
99  break;
100  }
101  }
102  }
103 
104  if (f1 == NULL || fcn != f1->GetName()) {
105  FATAL("No function at " << inputFile << " " << fcn << endl);
106  };
107 
108  for (int i = 0; i != f1->GetNpar(); ++i) {
109  if (parameter.count(f1->GetParName(i)) != 0) {
110  cout << FIXED(20,10) << f1->GetParameter(i) << ' '
111  << FIXED(20,10) << f1->GetParError (i) << endl;
112  }
113  }
114 
115  if (!x.empty()) {
116  cout << f1->EvalPar(x.data()) << endl;
117  }
118 
119  if (formula != "") {
120  cout << SCIENTIFIC(15,5) << getResult(formula, f1) << endl;
121  }
122 }
Utility class to parse command line options.
Definition: JParser.hh:1500
TObject * getObject(const JRootObjectID &id)
Get first TObject with given identifier.
int main(int argc, char *argv[])
Definition: Main.cc:15
Definition: JRoot.hh:19
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
const JPolynome f1(1.0, 2.0, 3.0)
Function.
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Double_t getResult(const TString &text, TObject *object=NULL)
Get result of given textual formula.
int debug
debug level
Definition: JSirene.cc:66
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Definition: JHead.hh:1716
Auxiliary class to define a range between two values.
Utility class to parse command line options.
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484