#include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TKey.h" #include "TH2.h" #include "TProfile2D.h" #include "TString.h" #include "TRegexp.h" #include "JGizmo/JRootObjectID.hh" #include "JGizmo/JGizmoToolkit.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * Auxiliary program to convert 2D histograms to PDFs. * The option -f corresponds to \:\. * * Possible operations (option -O \: * - NXY\n * make 2D PDF; * - NX\n * make PDF along x-axis; * - NY\n * make PDF along y-axis; * - WXY\n * divide bin contents by width of x- and y-bin; * - WX\n * divide bin contents by width of x-bin; * - WY\n * divide bin contents by width of y-bin; * - E\n * apply operation also to bin errors; * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; vector inputFile; string outputFile; string option; int debug; try { JParser<> zap("Auxiliary program to convert 2D histograms to PDFs."); zap['f'] = make_field(inputFile, ":"); zap['O'] = make_field(option); zap['o'] = make_field(outputFile, "ROOT file with histogram(s)") = "pdf.root"; zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } vector listOfObjects; 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(); TH2* h2 = dynamic_cast(object); try { h2 = dynamic_cast(*object).ProjectionXY(); } catch(exception&) {} if (h2 != NULL) { listOfObjects.push_back(h2); } else { ERROR("Incompatible object " << object->GetName() << endl); } } } } TFile out(outputFile.c_str(), "recreate"); for (vector::iterator h2 = listOfObjects.begin(); h2 != listOfObjects.end(); ++h2) { convertToPDF(**h2, option); (*h2)->Write(); } out.Write(); out.Close(); }