Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JRangeTest2D.cc File Reference

Auxiliary program for y-range test of 1D histograms. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include "TH2.h"
#include "TROOT.h"
#include "TFile.h"
#include "TKey.h"
#include "TString.h"
#include "TRegexp.h"
#include "JTools/JRange.hh"
#include "JGizmo/JRootObjectID.hh"
#include "JGizmo/JGizmoToolkit.hh"
#include "Jeep/JColor.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program for y-range test of 1D histograms.

Author
mdejong

Definition in file JRangeTest2D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file JRangeTest2D.cc.

30 {
31  using namespace std;
32  using namespace JPP;
33 
34  typedef JRange<Double_t> JRange_t;
35  typedef map<TString, JRange_t> map_type;
36 
37  vector<JRootObjectID> inputFile;
38  JRange_t X;
39  JRange_t Y;
40  JRange_t Z;
41  bool invertX;
42  bool invertY;
43  bool invertZ;
44  int numberOfOutliers;
45  map_type zmap;
46  int debug;
47 
48  try {
49 
50  JParser<> zap("Auxiliary program to test contents of 2D histograms.");
51 
52  zap['f'] = make_field(inputFile, "measurement histogram, e.g: <file name>:<object name>");
53  zap['x'] = make_field(X, "accepted x-range values") = JRange_t();
54  zap['y'] = make_field(Y, "accepted y-range values") = JRange_t();
55  zap['z'] = make_field(Z, "accepted z-range values") = JRange_t();
56  zap['X'] = make_field(invertX);
57  zap['Y'] = make_field(invertY);
58  zap['Z'] = make_field(invertZ);
59  zap['N'] = make_field(numberOfOutliers) = 0;
60  zap['H'] = make_field(zmap, "global tests") = JPARSER::initialised();
61  zap['d'] = make_field(debug) = 1;
62 
63  zap(argc, argv);
64  }
65  catch(const exception &error) {
66  FATAL(error.what() << endl);
67  }
68 
69  int number_of_failures = 0;
70 
71  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
72 
73  DEBUG("Input: " << *input << endl);
74 
75  TDirectory* dir = getDirectory(*input);
76 
77  if (dir == NULL) {
78  ERROR("File: " << input->getFullFilename() << " not opened." << endl);
79  continue;
80  }
81 
82  const TRegexp regexp(input->getObjectName());
83 
84  TIter iter(dir->GetListOfKeys());
85 
86  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
87 
88  const TString tag(key->GetName());
89 
90  DEBUG("Key: " << tag << " match = " << tag.Index(regexp) << " (-1 /= OK)" << endl);
91 
92  // option match
93 
94  if (tag.Index(regexp) != -1) {
95 
96  TObject* p = key->ReadObj();
97 
98 
99  TH2* h2 = NULL;
100 
101  if (h2 == NULL && dynamic_cast<TH2*>(p) != NULL) { h2 = dynamic_cast<TH2*>(p); }
102 
103  if (h2 == NULL) {
104  FATAL("Object at " << *input << " is not TH2." << endl);
105  };
106 
107 
108  for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
109 
110  const double value = getResult(i->first, h2);
111  const JRange_t& range = i->second;
112 
113  DEBUG("Global test " << i->first << ' ' << (range(value) ? "passed" : "failed") << endl);
114 
115  ASSERT(range(value));
116  }
117 
118 
119  int number_of_outliers = 0;
120 
121  for (Int_t ix = 1; ix <= h2->GetXaxis()->GetNbins(); ++ix) {
122  for (Int_t iy = 1; iy <= h2->GetYaxis()->GetNbins(); ++iy) {
123 
124  const Double_t x = h2->GetXaxis()->GetBinCenter(ix);
125  const Double_t y = h2->GetYaxis()->GetBinCenter(iy);
126  const Double_t z = h2->GetBinContent(ix, iy);
127 
128  if (X(x) == !invertX &&
129  Y(y) == !invertY) {
130 
131  const bool ok = (Z(z) == !invertZ);
132 
133  DEBUG("Test outlier " << h2->GetName() << " bin (" << ix << "," << iy << ") " << z << ' ' << (ok ? "passed" : "failed") << endl);
134 
135  if (!ok) {
136  ++number_of_outliers;
137  }
138  }
139  }
140  }
141 
142  cout << (number_of_outliers > numberOfOutliers ? RED : GREEN);
143  NOTICE("Number of outliers \"" << h2->GetName() << "\" = " << number_of_outliers << endl);
144  cout << RESET;
145 
146  if (number_of_outliers > numberOfOutliers) {
147  ++number_of_failures;
148  }
149  }
150  }
151  }
152 
153  ASSERT(number_of_failures == 0);
154 
155  return 0;
156 }
Utility class to parse command line options.
Definition: JParser.hh:1410
Definition: JRoot.hh:19
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:64
#define ASSERT(A)
Assert macro.
Definition: JMessage.hh:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
Double_t getResult(const TString &text, TObject *object=NULL)
Get result of given textual formula.
#define NOTICE(A)
Definition: JMessage.hh:62
#define ERROR(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:59
#define FATAL(A)
Definition: JMessage.hh:65
const char *const GREEN
print green
Definition: JColor.hh:15
const char *const RED
print red
Definition: JColor.hh:16
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60
const char *const RESET
print reset color
Definition: JColor.hh:17