Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JPrintMaximum2D.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <limits>
5
6#include "TROOT.h"
7#include "TFile.h"
8#include "TClass.h"
9#include "TKey.h"
10#include "TRegexp.h"
11#include "TH2.h"
12#include "TGraph2D.h"
13#include "TProfile2D.h"
14
17
18#include "Jeep/JPrint.hh"
19#include "Jeep/JParser.hh"
20#include "Jeep/JMessage.hh"
21
22
23/**
24 * \file
25 * Auxiliary program to print (x,y) of the maximum of 2D ROOT objects.
26 * The option <tt>-f</tt> corresponds to <tt><file name>:<object name></tt>.
27 * \author mdejong
28 */
29int main(int argc, char **argv)
30{
31 using namespace std;
32 using namespace JPP;
33
34 vector<JRootObjectID> inputFile;
35 int debug;
36
37 try {
38
39 JParser<> zap("Auxiliary program to print (x,y) of the maximum of 2D ROOT objects.");
40
41 zap['f'] = make_field(inputFile, "<input file>:<object name>");
42 zap['d'] = make_field(debug) = 0;
43
44 zap(argc, argv);
45 }
46 catch(const exception &error) {
47 FATAL(error.what() << endl);
48 }
49
50
51 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
52
53 DEBUG("Input: " << *input << endl);
54
55 TDirectory* dir = getDirectory(*input);
56
57 if (dir == NULL) {
58 ERROR("File: " << input->getFullFilename() << " not opened." << endl);
59 continue;
60 }
61
62 const TRegexp regexp(input->getObjectName());
63
64 TIter iter(dir->GetListOfKeys());
65
66 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
67
68 const TString tag(key->GetName());
69
70 DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
71
72 // option match
73
74 if (tag.Contains(regexp) && isTObject(key)) {
75
76 TObject* object = key->ReadObj();
77
78 double x = 0.0;
79 double y = 0.0;
80 double zmax = numeric_limits<double>::lowest();
81
82 try {
83
84 TH2& h2 = dynamic_cast<TH2&>(*object);
85
86 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
87 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
88
89 double z = h2.GetBinContent(ix,iy);
90
91 if (z > zmax) {
92 zmax = z;
93 x = h2.GetXaxis()->GetBinCenter(ix);
94 y = h2.GetYaxis()->GetBinCenter(iy);
95 }
96 }
97 }
98 }
99 catch(exception&) {}
100
101 try {
102
103 TProfile2D& h2 = dynamic_cast<TProfile2D&>(*object);
104
105 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
106 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
107
108 double z = h2.GetBinContent(ix,iy);
109
110 if (z > zmax) {
111 zmax = z;
112 x = h2.GetXaxis()->GetBinCenter(ix);
113 y = h2.GetYaxis()->GetBinCenter(iy);
114 }
115 }
116 }
117 }
118 catch(exception&) {}
119
120 try {
121
122 TGraph2D& g2 = dynamic_cast<TGraph2D&>(*object);
123
124 for (Int_t i = 0; i != g2.GetN(); ++i) {
125 if (g2.GetZ()[i] > zmax) {
126 zmax = g2.GetZ()[i];
127 x = g2.GetX()[i];
128 y = g2.GetY()[i];
129 }
130 }
131 }
132 catch(exception&) {}
133
134 if (zmax != numeric_limits<double>::lowest()) {
135 cout << setw(32) << left << key->GetName() << right << ' ' << SCIENTIFIC(15,5) << x << ' ' << SCIENTIFIC(15,5) << y << endl;
136 }
137 }
138 }
139 }
140}
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ERROR(A)
Definition JMessage.hh:66
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int main(int argc, char **argv)
I/O formatting auxiliaries.
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:488