Jpp  19.1.0-rc.1
the software that should make you happy
Functions
JTestRange3D.cc File Reference

Auxiliary program to test contents of 3D 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 "TH3.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 to test contents of 3D histograms.

Author
mdejong

Definition in file JTestRange3D.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 28 of file JTestRange3D.cc.

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