Jpp 20.0.0-27-g39925593c-D
the software that should make you happy
Loading...
Searching...
No Matches
JTestRange2D.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <vector>
5#include <map>
6
7#include "TROOT.h"
8#include "TFile.h"
9#include "TKey.h"
10#include "TString.h"
11#include "TRegexp.h"
12#include "TH2.h"
13#include "TGraph2D.h"
14
15#include "JTools/JRange.hh"
18
19#include "Jeep/JColor.hh"
20#include "Jeep/JParser.hh"
21#include "Jeep/JMessage.hh"
22
23
24/**
25 * \file
26 * Auxiliary program to test contents of 2D histograms.
27 * \author mdejong
28 */
29int main(int argc, char **argv)
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 FATAL("File: " << input->getFullFilename() << " not opened." << endl);
79 }
80
81 const TRegexp regexp(input->getObjectName());
82
83 TIter iter(dir->GetListOfKeys());
84
85 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
86
87 const TString tag(key->GetName());
88
89 DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
90
91 // option match
92
93 if (tag.Contains(regexp) && isTObject(key)) {
94
95 TObject* p = key->ReadObj();
96
97 const TH2* h2 = (dynamic_cast<TH2*>(p) != NULL ? dynamic_cast<TH2*>(p) : NULL);
98 const TGraph2D* g2 = (dynamic_cast<TGraph2D*>(p) != NULL ? dynamic_cast<TGraph2D*>(p) : NULL);
99
100 for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
101
102 const double value = getResult(i->first, p);
103 const JRange_t& range = i->second;
104
105 DEBUG("Global test " << i->first << ' ' << (range(value) ? "passed" : "failed") << endl);
106
107 ASSERT(range(value));
108 }
109
110
111 int number_of_events = 0;
112 int number_of_outliers = 0;
113
114 if (h2 != NULL) {
115
116 for (Int_t ix = 1; ix <= h2->GetXaxis()->GetNbins(); ++ix) {
117 for (Int_t iy = 1; iy <= h2->GetYaxis()->GetNbins(); ++iy) {
118
119 const Double_t x = h2->GetXaxis()->GetBinCenter(ix);
120 const Double_t y = h2->GetYaxis()->GetBinCenter(iy);
121 const Double_t z = h2->GetBinContent(ix, iy);
122
123 if (X(x) == !invertX &&
124 Y(y) == !invertY) {
125
127
128 const bool ok = (Z(z) == !invertZ);
129
130 DEBUG("Test outlier " << h2->GetName() << " bin (" << ix << "," << iy << ") (" << h2->GetXaxis()->GetBinLabel(ix) << "," << h2->GetYaxis()->GetBinLabel(iy) << ") " << z << ' ' << (ok ? "passed" : "failed") << endl);
131
132 if (!ok) {
133 ++number_of_outliers;
134 }
135 }
136 }
137 }
138
139 } else if (g2 != NULL) {
140
141 for (Int_t i = 0; i != g2->GetN(); ++i) {
142
143 const Double_t x = g2->GetX()[i];
144 const Double_t y = g2->GetY()[i];
145 const Double_t z = g2->GetZ()[i];
146
147 if (X(x) == !invertX &&
148 Y(y) == !invertY) {
149
151
152 const bool ok = (Z(z) == !invertZ);
153
154 DEBUG("Test outlier " << g2->GetName() << " bin (" << i << ") " << z << ' ' << (ok ? "passed" : "failed") << endl);
155
156 if (!ok) {
157 ++number_of_outliers;
158 }
159 }
160 }
161
162 } else {
163
164 FATAL("Object at " << *input << " is not TH2 nor TGraph2D." << endl);
165 }
166
167
168 cout << (number_of_outliers > numberOfOutliers ? RED : GREEN);
169 NOTICE("Number of outliers \"" << p->GetName() << "\" = " << number_of_outliers << "/" << number_of_events << endl);
170 cout << RESET;
171
172 if (number_of_outliers > numberOfOutliers) {
174 }
175 }
176 }
177 }
178
180
181 return 0;
182}
I/O coloring auxiliaries.
General purpose messaging.
#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:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Auxiliary class to define a range between two values.
int main(int argc, char **argv)
Template definition of a multi-dimensional oscillation probability interpolation table.
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68