#include #include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TKey.h" #include "TH3.h" #include "TProfile3D.h" #include "TString.h" #include "TRegexp.h" #include "JGizmo/JRootObjectID.hh" #include "JGizmo/JGizmoToolkit.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" #include "Jeep/JPrint.hh" /** * \file * Auxiliary program to project 3D histograms. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; vector inputFile; string outputFile; char project; int debug; try { JParser<> zap("Auxiliary program to project 3D histograms."); zap['f'] = make_field(inputFile, ":"); zap['P'] = make_field(project, "projection") = ' ', 'x', 'X', 'y', 'Y', 'z', 'Z'; zap['o'] = make_field(outputFile, "ROOT file with histogram(s)") = "project.root"; zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } const bool px = (project == 'x' || project == 'X'); // projection on x-axis const bool py = (project == 'y' || project == 'Y'); // projection on y-axis const bool pz = (project == 'z' || project == 'Z'); // projection on z-axis if ((px ? 1 : 0) + (py ? 1 : 0) + (pz ? 1 : 0) != 1) { FATAL("Invalid operation: " << (px ? "" : "no") << " X projection " << " and " << (py ? "" : "no") << " Y projection " << " and " << (pz ? "" : "no") << " Z projection " << 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)) { TH3* h3 = dynamic_cast(key->ReadObj()); if (h3 != NULL) { if (px) listOfObjects.push_back(h3->ProjectionX(MAKE_CSTRING(h3->GetName() << "_px"))); else if (py) listOfObjects.push_back(h3->ProjectionY(MAKE_CSTRING(h3->GetName() << "_py"))); else if (pz) listOfObjects.push_back(h3->ProjectionZ(MAKE_CSTRING(h3->GetName() << "_pz"))); } } } } if (!listOfObjects.empty()) { TFile out(outputFile.c_str(), "recreate"); for (vector::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) { (*i)->Write(); } out.Write(); out.Close(); } }