#include #include #include #include "TROOT.h" #include "TFile.h" #include "TObject.h" #include "TKey.h" #include "TH1D.h" #include "TString.h" #include "TRegexp.h" #include "JGizmo/JRootObjectID.hh" #include "JGizmo/JGizmoToolkit.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Auxiliary program to print quantiles from 1D histogram. * The option -f corresponds to \:\. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; vector inputFile; vector Q; bool reverse; int debug; try { JParser<> zap("Auxiliary program to print quantiles from 1D histogram."); zap['f'] = make_field(inputFile); zap['Q'] = make_field(Q); zap['R'] = make_field(reverse); zap['d'] = make_field(debug) = 0; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } if (Q.empty()) { FATAL("No quantiles." << endl); } for (vector::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) { DEBUG("Input: " << *input << endl); TDirectory* dir = getDirectory(*input); if (dir == NULL) { ERROR("File: " << input->getFullFilename() << " not opened." << endl); continue; } 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* object = key->ReadObj(); try { TH1& h1 = dynamic_cast(*object); Double_t W = 0.0; for (Int_t i = 0; i <= h1.GetXaxis()->GetNbins() + 1; ++i) { W += h1.GetBinContent(i); } if (W != 0.0) { Double_t w = 0.0; if (!reverse) { for (int i = 0, k = 0; i <= h1.GetXaxis()->GetNbins() + 1; ++i) { w += h1.GetBinContent(i); for ( ; k != (int) Q.size() && w >= Q[k]*W; ++k) { cout << h1.GetName() << ' ' << FIXED(4,2) << Q[k] << ' ' << FIXED(20,10) << h1.GetXaxis()->GetBinCenter(i) << endl; } } } else { for (int i = h1.GetXaxis()->GetNbins() + 1, k = 0; i >= 0; --i) { w += h1.GetBinContent(i); for ( ; k != (int) Q.size() && w >= Q[k]*W; ++k) { cout << h1.GetName() << ' ' << FIXED(4,2) << Q[k] << ' ' << FIXED(20,10) << h1.GetXaxis()->GetBinCenter(i) << endl; } } } } } catch(exception&) { ERROR("Not available for other objects than 1D histograms." << endl); } } } } }