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

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

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TKey.h"
#include "TString.h"
#include "TRegexp.h"
#include "TH1.h"
#include "TProfile.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 JRangeTest1D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file JRangeTest1D.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  bool invertX;
41  bool invertY;
42  int numberOfOutliers;
43  map_type zmap;
44  int debug;
45 
46  try {
47 
48  JParser<> zap("Auxiliary program to test contents of 1D histograms.");
49 
50  zap['f'] = make_field(inputFile, "measurement histogram, e.g: <file name>:<object name>");
51  zap['x'] = make_field(X, "accepted x-range values") = JRange_t();
52  zap['y'] = make_field(Y, "accepted y-range values") = JRange_t();
53  zap['X'] = make_field(invertX);
54  zap['Y'] = make_field(invertY);
55  zap['N'] = make_field(numberOfOutliers) = 0;
56  zap['H'] = make_field(zmap, "global tests") = JPARSER::initialised();
57  zap['d'] = make_field(debug) = 1;
58 
59  zap(argc, argv);
60  }
61  catch(const exception &error) {
62  FATAL(error.what() << endl);
63  }
64 
65 
66  int number_of_failures = 0;
67 
68  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
69 
70  DEBUG("Input: " << *input << endl);
71 
72  TDirectory* dir = getDirectory(*input);
73 
74  if (dir == NULL) {
75  ERROR("File: " << input->getFullFilename() << " not opened." << endl);
76  continue;
77  }
78 
79  const TRegexp regexp(input->getObjectName());
80 
81  TIter iter(dir->GetListOfKeys());
82 
83  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
84 
85  const TString tag(key->GetName());
86 
87  DEBUG("Key: " << tag << " match = " << tag.Index(regexp) << " (-1 /= OK)" << endl);
88 
89  // option match
90 
91  if (tag.Index(regexp) != -1) {
92 
93  TObject* p = key->ReadObj();
94 
95 
96  TH1* h1 = NULL;
97 
98  if (h1 == NULL && dynamic_cast<TProfile*>(p) != NULL) { h1 = dynamic_cast<TProfile*>(p)->ProjectionX(); }
99 
100  if (h1 == NULL && dynamic_cast<TH1*>(p) != NULL) { h1 = dynamic_cast<TH1*>(p); }
101 
102  if (h1 == NULL) {
103  FATAL("Object at " << *input << " is not TH1." << endl);
104  };
105 
106 
107  for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
108 
109  const double value = getResult(i->first, h1);
110  const JRange_t& range = i->second;
111 
112  DEBUG("Global test " << i->first << ' ' << (range(value) ? "passed" : "failed") << endl);
113 
114  ASSERT(range(value));
115  }
116 
117 
118  int number_of_outliers = 0;
119 
120  for (Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
121 
122  const Double_t x = h1->GetBinCenter (i);
123  const Double_t y = h1->GetBinContent(i);
124 
125  if (X(x) == !invertX) {
126 
127  const bool ok = (Y(y) == !invertY);
128 
129  DEBUG("Test outlier " << h1->GetName() << " bin (" << i << ") " << y << ' ' << (ok ? "passed" : "failed") << endl);
130 
131  if (!ok) {
132  ++number_of_outliers;
133  }
134  }
135  }
136 
137  cout << (number_of_outliers > numberOfOutliers ? RED : GREEN);
138  NOTICE("Number of outliers \"" << h1->GetName() << "\" = " << number_of_outliers << endl);
139  cout << RESET;
140 
141  if (number_of_outliers > numberOfOutliers) {
142  ++number_of_failures;
143  }
144  }
145  }
146  }
147 
148  ASSERT(number_of_failures == 0);
149 
150  return 0;
151 }
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