Jpp  15.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JTestRange2D.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 "TH2.h"
#include "TGraph2D.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 JTestRange2D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file JTestRange2D.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  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)) {
94 
95  TObject* p = key->ReadObj();
96 
97 
98  TH2* h2 = NULL;
99  TGraph2D* g2 = NULL;
100 
101  if (h2 == NULL && dynamic_cast<TH2*>(p) != NULL) { h2 = dynamic_cast<TH2*>(p); }
102 
103  if (g2 == NULL && dynamic_cast<TGraph2D*>(p) != NULL) { g2 = dynamic_cast<TGraph2D*>(p); }
104 
105 
106  for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
107 
108  const double value = getResult(i->first, p);
109  const JRange_t& range = i->second;
110 
111  DEBUG("Global test " << i->first << ' ' << (range(value) ? "passed" : "failed") << endl);
112 
113  ASSERT(range(value));
114  }
115 
116 
117  int number_of_events = 0;
118  int number_of_outliers = 0;
119 
120  if (h2 != NULL) {
121 
122  for (Int_t ix = 1; ix <= h2->GetXaxis()->GetNbins(); ++ix) {
123  for (Int_t iy = 1; iy <= h2->GetYaxis()->GetNbins(); ++iy) {
124 
125  const Double_t x = h2->GetXaxis()->GetBinCenter(ix);
126  const Double_t y = h2->GetYaxis()->GetBinCenter(iy);
127  const Double_t z = h2->GetBinContent(ix, iy);
128 
129  if (X(x) == !invertX &&
130  Y(y) == !invertY) {
131 
132  ++number_of_events;
133 
134  const bool ok = (Z(z) == !invertZ);
135 
136  DEBUG("Test outlier " << h2->GetName() << " bin (" << ix << "," << iy << ") " << z << ' ' << (ok ? "passed" : "failed") << endl);
137 
138  if (!ok) {
139  ++number_of_outliers;
140  }
141  }
142  }
143  }
144 
145  } else if (g2 != NULL) {
146 
147  for (Int_t i = 0; i != g2->GetN(); ++i) {
148 
149  const Double_t x = g2->GetX()[i];
150  const Double_t y = g2->GetY()[i];
151  const Double_t z = g2->GetZ()[i];
152 
153  if (X(x) == !invertX &&
154  Y(y) == !invertY) {
155 
156  ++number_of_events;
157 
158  const bool ok = (Z(z) == !invertZ);
159 
160  DEBUG("Test outlier " << h2->GetName() << " bin (" << i << ") " << z << ' ' << (ok ? "passed" : "failed") << endl);
161 
162  if (!ok) {
163  ++number_of_outliers;
164  }
165  }
166  }
167 
168  } else {
169 
170  FATAL("Object at " << *input << " is not TH1 nor TGraph2D." << endl);
171  }
172 
173 
174  cout << (number_of_outliers > numberOfOutliers ? RED : GREEN);
175  NOTICE("Number of outliers \"" << p->GetName() << "\" = " << number_of_outliers << "/" << number_of_events << endl);
176  cout << RESET;
177 
178  if (number_of_outliers > numberOfOutliers) {
179  ++number_of_failures;
180  }
181  }
182  }
183  }
184 
185  ASSERT(number_of_failures == 0);
186 
187  return 0;
188 }
Utility class to parse command line options.
Definition: JParser.hh:1500
Definition: JRoot.hh:19
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Double_t getResult(const TString &text, TObject *object=NULL)
Get result of given textual formula.
#define NOTICE(A)
Definition: JMessage.hh:64
then break fi done getCenter read X Y Z let X
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
do set_variable MODULE getModule a $WORKDIR detector_a datx L $STRING JEditDetector a $WORKDIR detector_a datx M $MODULE setz o $WORKDIR detector_a datx JEditDetector a $WORKDIR detector_b datx M $MODULE setz o $WORKDIR detector_b datx done echo Output stored at $WORKDIR detector_a datx and $WORKDIR tripod_a txt JDrawDetector2D a $WORKDIR detector_a datx a $WORKDIR detector_b datx L BL o detector $FORMAT $BATCH JDrawDetector2D T $WORKDIR tripod_a txt T $WORKDIR tripod_b txt L BL o tripod $FORMAT $BATCH JCompareDetector a $WORKDIR detector_a datx b $WORKDIR detector_b datx o $WORKDIR abc root &dev null for KEY in X Y Z