#include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TClass.h" #include "TKey.h" #include "TRegexp.h" #include "TH2.h" #include "TGraph2D.h" #include "TProfile2D.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 (x,y) of the maximum of 2D ROOT objects. * The option -f corresponds to \:\. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; vector inputFile; int debug; try { JParser<> zap("Auxiliary program to print (x,y) of the maximum of 2D ROOT objects."); zap['f'] = make_field(inputFile, ":"); 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(); double x = 0.0; double y = 0.0; double zmax = numeric_limits::lowest(); try { TH2& h2 = dynamic_cast(*object); for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) { for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) { double z = h2.GetBinContent(ix,iy); if (z > zmax) { zmax = z; x = h2.GetXaxis()->GetBinCenter(ix); y = h2.GetYaxis()->GetBinCenter(iy); } } } } catch(exception&) {} try { TProfile2D& h2 = dynamic_cast(*object); for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) { for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) { double z = h2.GetBinContent(ix,iy); if (z > zmax) { zmax = z; x = h2.GetXaxis()->GetBinCenter(ix); y = h2.GetYaxis()->GetBinCenter(iy); } } } } catch(exception&) {} try { TGraph2D& g2 = dynamic_cast(*object); for (Int_t i = 0; i != g2.GetN(); ++i) { if (g2.GetZ()[i] > zmax) { zmax = g2.GetZ()[i]; x = g2.GetX()[i]; y = g2.GetY()[i]; } } } catch(exception&) {} if (zmax != numeric_limits::lowest()) { cout << setw(32) << left << key->GetName() << right << ' ' << SCIENTIFIC(15,5) << x << ' ' << SCIENTIFIC(15,5) << y << endl; } } } } }