Jpp  debug
the software that should make you happy
JTestFit.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iomanip>
3 #include <iostream>
4 #include <map>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 #include "TH1.h"
9 #include "TGraph.h"
10 #include "TGraph2D.h"
11 #include "TF1.h"
12 
13 #include "JTools/JRange.hh"
14 #include "JGizmo/JRootObjectID.hh"
15 #include "JGizmo/JGizmoToolkit.hh"
16 
17 #include "Jeep/JPrint.hh"
18 #include "Jeep/JParser.hh"
19 #include "Jeep/JMessage.hh"
20 
21 
22 /**
23  * \file
24  * Auxiliary program to test ROOT fit results.
25  * \author mdejong
26  */
27 int main(int argc, char **argv)
28 {
29  using namespace std;
30  using namespace JPP;
31 
32  typedef JRange<Double_t> JRange_t;
34 
35  JRootObjectID inputFile;
36  string fcn;
37  JTest_t test;
38  int debug;
39 
40  try {
41 
42  JParser<> zap("Auxiliary program to test ROOT fit results.");
43 
44  zap['f'] = make_field(inputFile, "histogram, e.g: <file name>:<object name>");
45  zap['='] = make_field(fcn, "function name") = ".*";
46  zap['@'] = make_field(test, "<parameter> <min> <max>");
47  zap['d'] = make_field(debug) = 1;
48 
49  zap(argc, argv);
50  }
51  catch(const exception &error) {
52  FATAL(error.what() << endl);
53  }
54 
55 
56  TObject* p = getObject(inputFile);
57 
58  if (p == NULL) {
59  FATAL("No object at " << inputFile << endl);
60  };
61 
62  TF1* f1 = NULL;
63 
64  if (f1 == NULL && dynamic_cast<TF1*> (p) != NULL) { f1 = dynamic_cast<TF1*>(p); }
65  if (f1 == NULL && dynamic_cast<TH1*> (p) != NULL) { f1 = getFunction(dynamic_cast<TH1*> (p), fcn.c_str()); };
66  if (f1 == NULL && dynamic_cast<TGraph*> (p) != NULL) { f1 = getFunction(dynamic_cast<TGraph*> (p), fcn.c_str()); };
67  if (f1 == NULL && dynamic_cast<TGraph2D*>(p) != NULL) { f1 = getFunction(dynamic_cast<TGraph2D*>(p), fcn.c_str()); };
68 
69  if (f1 == NULL) {
70  FATAL("No function at " << inputFile << " " << fcn << endl);
71  };
72 
73 
74  for (int i = 0; i != f1->GetNpar(); ++i) {
75 
76  DEBUG(left << setw(12) << f1->GetParName(i) << ' ');
77  DEBUG(SCIENTIFIC(12,5) << f1->GetParameter(i) << " +/- " << SCIENTIFIC(12,5) << f1->GetParError(i));
78 
79  JTest_t::const_iterator p = test.find(f1->GetParName(i));
80 
81  if (p != test.end()) {
82 
83  DEBUG(" [" << SCIENTIFIC(12,5) << p->second.getLowerLimit() << "," << SCIENTIFIC(12,5) << p->second.getLowerLimit() << "] ");
84  DEBUG((p->second(f1->GetParameter(i)) ? "passed" : "failed"));
85 
86  } else {
87 
88  DEBUG("untested");
89  }
90 
91  DEBUG(endl);
92  }
93 
94 
95  for (int i = 0; i != f1->GetNpar(); ++i) {
96 
97  JTest_t::const_iterator p = test.find(f1->GetParName(i));
98 
99  if (p != test.end()) {
100  ASSERT(p->second(f1->GetParameter(i)), p->first << ' ' << p->second);
101  }
102  }
103 
104  return 0;
105 }
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
I/O formatting auxiliaries.
Auxiliary class to define a range between two values.
int main(int argc, char **argv)
Definition: JTestFit.cc:27
Interface to read input and write output for TObject tests.
Definition: JTest_t.hh:42
Auxiliary class to handle file name, ROOT directory and object name.
Utility class to parse command line options.
Definition: JParser.hh:1714
Range of values.
Definition: JRange.hh:42
const JPolynome f1(1.0, 2.0, 3.0)
Function.
TObject * getObject(const JRootObjectID &id)
Get first TObject with given identifier.
TF1 * getFunction(TH1 *h1, const char *const fcn)
Get function.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
Type definition of range.
Definition: JHead.hh:43
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:488
Definition: JRoot.hh:19