Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JPrintMaximum1D.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 "TGraph.h"
13#include "TProfile.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) of the maximum of 1D 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) of the maximum of 1D 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 ymax = numeric_limits<double>::lowest();
80
81 try {
82
83 TH1& h1 = dynamic_cast<TH1&>(*object);
84
85 for (Int_t ix = 1; ix <= h1.GetXaxis()->GetNbins(); ++ix) {
86
87 double y = h1.GetBinContent(ix);
88
89 if (y > ymax) {
90 ymax = y;
91 x = h1.GetXaxis()->GetBinCenter(ix);
92 }
93 }
94 }
95 catch(exception&) {}
96
97 try {
98
99 TProfile& h1 = dynamic_cast<TProfile&>(*object);
100
101 for (Int_t ix = 1; ix <= h1.GetXaxis()->GetNbins(); ++ix) {
102
103 double y = h1.GetBinContent(ix);
104
105 if (y > ymax) {
106 ymax = y;
107 x = h1.GetXaxis()->GetBinCenter(ix);
108 }
109 }
110 }
111 catch(exception&) {}
112
113 try {
114
115 TGraph& g1 = dynamic_cast<TGraph&>(*object);
116
117 for (Int_t i = 0; i != g1.GetN(); ++i) {
118 if (g1.GetY()[i] > ymax) {
119 ymax = g1.GetY()[i];
120 x = g1.GetX()[i];
121 }
122 }
123 }
124 catch(exception&) {}
125
126 if (ymax != numeric_limits<double>::lowest()) {
127 cout << setw(32) << left << key->GetName() << right << ' ' << SCIENTIFIC(15,5) << x << endl;
128 }
129 }
130 }
131 }
132}
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.
Double_t g1(const Double_t x)
Function.
Definition JQuantiles.cc:25
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