#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 "TGraph.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.
 | 
| int  | main (int argc, char **argv) | 
|   | 
Auxiliary program for y-range test of 1D histograms. 
- Author
 - mdejong 
 
Definition in file JTestRange1D.cc.
 
◆ main()
      
        
          | int main  | 
          ( | 
          int  | 
          argc,  | 
        
        
           | 
           | 
          char **  | 
          argv  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Definition at line 30 of file JTestRange1D.cc.
   35   typedef JRange<Double_t>        JRange_t;
 
   49     JParser<> zap(
"Auxiliary program to test contents of 1D histograms.");
 
   51     zap[
'f'] = 
make_field(inputFile,  
"measurement histogram, e.g: <file name>:<object name>");
 
   52     zap[
'x'] = 
make_field(X,          
"accepted x-range values")   = JRange_t();
 
   53     zap[
'y'] = 
make_field(Y,          
"accepted y-range values")   = JRange_t();
 
   62   catch(
const exception &error) {
 
   63     FATAL(error.what() << endl);
 
   67   int number_of_failures = 0;
 
   71     DEBUG(
"Input: " << *input << endl);
 
   76       FATAL(
"File: " << input->getFullFilename() << 
" not opened." << endl);
 
   79     const TRegexp regexp(input->getObjectName());
 
   81     TIter iter(dir->GetListOfKeys());
 
   83     for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
 
   85       const TString tag(key->GetName());
 
   87       DEBUG(
"Key: " << tag << 
" match = " << tag.Contains(regexp) << endl);
 
   91       if (tag.Contains(regexp)) {
 
   99         if (h1 == NULL && dynamic_cast<TProfile*>(p) != NULL) { h1 = dynamic_cast<TProfile*>(p)->ProjectionX(); }
 
  101         if (h1 == NULL && dynamic_cast<TH1*>(p)      != NULL) { h1 = dynamic_cast<TH1*>(p); }
 
  103         if (
g1 == NULL && dynamic_cast<TGraph*>(p)   != NULL) { 
g1 = dynamic_cast<TGraph*>(p); }
 
  106         for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
 
  108           const double    value = 
getResult(i->first, p);
 
  109           const JRange_t& range = i->second;
 
  111           DEBUG(
"Global test " << i->first << 
' ' << (range(value) ? 
"passed" : 
"failed") << endl);
 
  117         int number_of_events   = 0;
 
  118         int number_of_outliers = 0;
 
  122           for (Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
 
  124             const Double_t x = h1->GetBinCenter (i);
 
  125             const Double_t y = h1->GetBinContent(i);
 
  127             if (X(x) == !invertX) {
 
  131               const bool ok = (Y(y) == !invertY);
 
  133               DEBUG(
"Test outlier " << h1->GetName() << 
" bin (" << i << 
") " << y << 
' ' << (ok ? 
"passed" : 
"failed") << endl);
 
  136                 ++number_of_outliers;
 
  141         } 
else if (
g1 != NULL) {
 
  143           for (Int_t i = 0; i != 
g1->GetN(); ++i) {
 
  145             const Double_t x = 
g1->GetX()[i];
 
  146             const Double_t y = 
g1->GetY()[i];
 
  148             if (X(x) == !invertX) {
 
  152               const bool ok = (Y(y) == !invertY);
 
  154               DEBUG(
"Test outlier " << 
g1->GetName() << 
" bin (" << i << 
") " << y << 
' ' << (ok ? 
"passed" : 
"failed") << endl);
 
  157                 ++number_of_outliers;
 
  164           FATAL(
"Object at " << *input << 
" is not TH1 nor TGraph." << endl);
 
  168         cout << (number_of_outliers > numberOfOutliers ? 
RED : 
GREEN);
 
  169         NOTICE(
"Number of outliers \"" << p->GetName() << 
"\" = " << number_of_outliers << 
"/" << number_of_events << endl);
 
  172         if (number_of_outliers > numberOfOutliers) {
 
  173           ++number_of_failures;
 
  179   ASSERT(number_of_failures == 0);