#include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TKey.h" #include "TH3.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 3D histograms to PDFs. * The option -f corresponds to \:\. * * Possible operations (option -O \: * - NXYZ\n * make 3D PDF; * - NXY\n * make 2D PDF along x- and y-axis; * - NXZ\n * make 2D PDF along x- and z-axis; * - NYZ\n * make 2D PDF along y- and z-axis; * - NX\n * make PDF along x-axis; * - NY\n * make PDF along y-axis; * - NZ\n * make PDF along z-axis; * - WXYZ\n * divide bin contents by width of x-, y- and z-bin; * - WXY\n * divide bin contents by width of x- and y-bin; * - WXZ\n * divide bin contents by width of x- and z-bin; * - WYZ\n * divide bin contents by width of y- and z-bin; * - WX\n * divide bin contents by width of x-bin; * - WY\n * divide bin contents by width of y-bin; * - WZ\n * divide bin contents by width of z-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(); TH3* h3 = dynamic_cast(object); if (h3 != NULL) { listOfObjects.push_back(h3); } else { ERROR("Incompatible object " << object->GetName() << endl); } } } } TFile out(outputFile.c_str(), "recreate"); for (vector::iterator h3 = listOfObjects.begin(); h3 != listOfObjects.end(); ++h3) { convertToPDF(**h3, option); (*h3)->Write(); } out.Write(); out.Close(); }