Jpp  15.0.1-rc.2-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 "TF1.h"
11 
12 #include "JTools/JRange.hh"
13 #include "JGizmo/JRootObjectID.hh"
14 #include "JGizmo/JGizmoToolkit.hh"
15 
16 #include "Jeep/JPrint.hh"
17 #include "Jeep/JParser.hh"
18 #include "Jeep/JMessage.hh"
19 
20 
21 /**
22  * \file
23  * Auxiliary program to test ROOT fit results.
24  * \author mdejong
25  */
26 int main(int argc, char **argv)
27 {
28  using namespace std;
29  using namespace JPP;
30 
31  typedef JRange<Double_t> JRange_t;
32  typedef map<string, JRange_t> JTest_t;
33 
34  JRootObjectID inputFile;
35  string fcn;
36  JTest_t test;
37  int debug;
38 
39  try {
40 
41  JParser<> zap("Auxiliary program to test ROOT fit results.");
42 
43  zap['f'] = make_field(inputFile, "histogram, e.g: <file name>:<object name>");
44  zap['F'] = make_field(fcn, "function name") = "user";
45  zap['@'] = make_field(test, "<parameter> <min> <max>");
46  zap['d'] = make_field(debug) = 1;
47 
48  zap(argc, argv);
49  }
50  catch(const exception &error) {
51  FATAL(error.what() << endl);
52  }
53 
54 
55  TObject* p = getObject(inputFile);
56 
57  if (p == NULL) {
58  FATAL("No object at " << inputFile << endl);
59  };
60 
61  TF1* f1 = NULL;
62 
63  if (f1 == NULL && dynamic_cast<TF1*> (p) != NULL) { f1 = dynamic_cast<TF1*> (p); }
64  if (f1 == NULL && dynamic_cast<TH1*> (p) != NULL) { f1 = dynamic_cast<TH1*> (p)->GetFunction(fcn.c_str()); };
65  if (f1 == NULL && dynamic_cast<TGraph*>(p) != NULL) { f1 = dynamic_cast<TGraph*>(p)->GetFunction(fcn.c_str()); };
66 
67  if (f1 == NULL) {
68  FATAL("No function at " << inputFile << " " << fcn << endl);
69  };
70 
71 
72  for (int i = 0; i != f1->GetNpar(); ++i) {
73 
74  DEBUG(left << setw(12) << f1->GetParName(i) << ' ');
75  DEBUG(SCIENTIFIC(12,5) << f1->GetParameter(i) << " +/- " << SCIENTIFIC(12,5) << f1->GetParError(i));
76 
77  JTest_t::const_iterator p = test.find(f1->GetParName(i));
78 
79  if (p != test.end()) {
80 
81  DEBUG(" [" << SCIENTIFIC(12,5) << p->second.getLowerLimit() << "," << SCIENTIFIC(12,5) << p->second.getLowerLimit() << "] ");
82  DEBUG((p->second(f1->GetParameter(i)) ? "passed" : "failed"));
83 
84  } else {
85 
86  DEBUG("untested");
87  }
88 
89  DEBUG(endl);
90  }
91 
92 
93  for (int i = 0; i != f1->GetNpar(); ++i) {
94 
95  JTest_t::const_iterator p = test.find(f1->GetParName(i));
96 
97  if (p != test.end()) {
98  ASSERT(p->second(f1->GetParameter(i)));
99  }
100  }
101 
102  return 0;
103 }
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
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Auxiliary class to define a range between two values.
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484