Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JPrintFit.cc File Reference

Auxiliary program to print ROOT fit results. More...

#include <string>
#include <iomanip>
#include <iostream>
#include <vector>
#include <set>
#include "TROOT.h"
#include "TFile.h"
#include "TH1.h"
#include "TGraph.h"
#include "TGraph2D.h"
#include "TF1.h"
#include "JTools/JRange.hh"
#include "JGizmo/JRootObjectID.hh"
#include "JGizmo/JGizmoToolkit.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

std::istream & operator>> (std::istream &in, TString &object)
 Read formula from input stream.
 
std::ostream & operator<< (std::ostream &out, const TString &object)
 Write formula to output stream.
 
int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to print ROOT fit results.

Author
mdejong

Definition in file JPrintFit.cc.

Function Documentation

◆ operator>>()

std::istream & operator>> ( std::istream & in,
TString & object )
inline

Read formula from input stream.

Parameters
ininput stream
objectformula
Returns
input stream

Definition at line 30 of file JPrintFit.cc.

31{
32 return object.ReadLine(in);
33}

◆ operator<<()

std::ostream & operator<< ( std::ostream & out,
const TString & object )
inline

Write formula to output stream.

Parameters
outoutput stream
objectformula
Returns
output stream

Definition at line 42 of file JPrintFit.cc.

43{
44 return out << object.Data();
45}

◆ main()

int main ( int argc,
char ** argv )

Definition at line 53 of file JPrintFit.cc.

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['='] = make_field(fcn, "function name") = ".*";
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 = getFunction(dynamic_cast<TH1*> (p), fcn.c_str()); };
93 if (f1 == NULL && dynamic_cast<TGraph*> (p) != NULL) { f1 = getFunction(dynamic_cast<TGraph*> (p), fcn.c_str()); };
94 if (f1 == NULL && dynamic_cast<TGraph2D*>(p) != NULL) { f1 = getFunction(dynamic_cast<TGraph2D*>(p), fcn.c_str()); };
95
96 if (f1 == NULL) {
97 FATAL("No function at " << inputFile << " " << fcn << endl);
98 };
99
100 for (int i = 0; i != f1->GetNpar(); ++i) {
101 if (parameter.count(f1->GetParName(i)) != 0) {
102 cout << FIXED(20,10) << f1->GetParameter(i) << ' '
103 << FIXED(20,10) << f1->GetParError (i) << endl;
104 }
105 }
106
107 if (!x.empty()) {
108 cout << f1->EvalPar(x.data()) << endl;
109 }
110
111 if (formula != "") {
112 cout << SCIENTIFIC(15,5) << getResult(formula, f1) << endl;
113 }
114}
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Auxiliary class to handle file name, ROOT directory and object name.
Utility class to parse command line options.
Definition JParser.hh:1698
const JPolynome f1(1.0, 2.0, 3.0)
Function.
TF1 * getFunction(TH1 *h1, const char *const fcn)
Get function.
Double_t getResult(const TString &text, TObject *object=NULL)
Get result of given textual formula.
TObject * getObject(const JRootObjectID &id)
Get first TObject with given identifier.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
Auxiliary data structure for floating point format specification.
Definition JManip.hh:488