#include #include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TObject.h" #include "TKey.h" #include "TH1.h" #include "TGraph.h" #include "TRegexp.h" #include "JTools/JQuantile.hh" #include "JGizmo/JRootObjectID.hh" #include "JGizmo/JGizmoToolkit.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" #include "Jeep/JPrint.hh" /** * \file * * Auxiliary program to print quantiles from ROOT histograms or graphs. * The option -f corresponds to \:\. * * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; vector inputFile; vector Q; int debug; try { JParser<> zap("Auxiliary program to print quantiles from ROOT histograms."); zap['f'] = make_field(inputFile, ":"); zap['Q'] = make_field(Q, "quantiles"); zap['d'] = make_field(debug) = 0; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << 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(); vector X(Q.size(), 0.0); try { TH1& h1 = dynamic_cast(*object); h1.GetQuantiles(Q.size(), X.data(), Q.data()); } catch(const exception&) {} try { TGraph& g1 = dynamic_cast(*object); JQuantile Q1("", true); for (Int_t i = 0; i != g1.GetN(); ++i) { Q1.put(g1.GetX()[i], g1.GetY()[i]); } for (size_t i = 0; i != Q.size(); ++i) { X[i] = Q1.getQuantile(Q[i]); } } catch(const exception&) {} for (vector::const_iterator i = X.begin(); i != X.end(); ++i) { cout << ' ' << *i; } cout << endl; } } } }