#include #include #include #include #include #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" /** * \file * Auxiliary program to test contents of 3D histograms. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; typedef JRange JRange_t; typedef map map_type; vector inputFile; JRange_t X; JRange_t Y; JRange_t Z; JRange_t C; bool invertX; bool invertY; bool invertZ; bool invertC; int numberOfOutliers; map_type zmap; int debug; try { JParser<> zap("Auxiliary program to test contents of 3D histograms."); zap['f'] = make_field(inputFile, "measurement histogram, e.g: :"); zap['x'] = make_field(X, "accepted x-range values") = JRange_t(); zap['y'] = make_field(Y, "accepted y-range values") = JRange_t(); zap['z'] = make_field(Z, "accepted z-range values") = JRange_t(); zap['c'] = make_field(C, "accepted codomain values") = JRange_t(); zap['X'] = make_field(invertX); zap['Y'] = make_field(invertY); zap['Z'] = make_field(invertZ); zap['C'] = make_field(invertC); zap['N'] = make_field(numberOfOutliers) = 0; zap['H'] = make_field(zmap, "global tests") = JPARSER::initialised(); zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } int number_of_failures = 0; for (vector::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) { DEBUG("Input: " << *input << endl); TDirectory* dir = getDirectory(*input); if (dir == NULL) { FATAL("File: " << input->getFullFilename() << " not opened." << endl); } const TRegexp regexp(input->getObjectName()); TIter iter(dir->GetListOfKeys()); for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) { const TString tag(key->GetName()); DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl); // option match if (tag.Contains(regexp) && isTObject(key)) { TObject* p = key->ReadObj(); TH3* h3 = (dynamic_cast(p) != NULL ? dynamic_cast(p) : NULL); for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) { const double value = getResult(i->first, p); const JRange_t& range = i->second; DEBUG("Global test " << i->first << ' ' << (range(value) ? "passed" : "failed") << endl); ASSERT(range(value)); } int number_of_events = 0; int number_of_outliers = 0; if (h3 != NULL) { for (Int_t ix = 1; ix <= h3->GetXaxis()->GetNbins(); ++ix) { for (Int_t iy = 1; iy <= h3->GetYaxis()->GetNbins(); ++iy) { for (Int_t iz = 1; iz <= h3->GetZaxis()->GetNbins(); ++iz) { const Double_t x = h3->GetXaxis()->GetBinCenter(ix); const Double_t y = h3->GetYaxis()->GetBinCenter(iy); const Double_t z = h3->GetZaxis()->GetBinCenter(iz); const Double_t c = h3->GetBinContent(ix, iy, iz); if (X(x) == !invertX && Y(y) == !invertY && Z(z) == !invertZ) { ++number_of_events; const bool ok = (C(c) == !invertC); 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); if (!ok) { ++number_of_outliers; } } } } } } else { FATAL("Object at " << *input << " is not TH3" << endl); } cout << (number_of_outliers > numberOfOutliers ? RED : GREEN); NOTICE("Number of outliers \"" << p->GetName() << "\" = " << number_of_outliers << "/" << number_of_events << endl); cout << RESET; if (number_of_outliers > numberOfOutliers) { ++number_of_failures; } } } } ASSERT(number_of_failures == 0); return 0; }