Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JPrintRange1D.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4
5#include "TROOT.h"
6#include "TFile.h"
7#include "TClass.h"
8#include "TKey.h"
9#include "TRegexp.h"
10#include "TH1.h"
11#include "TGraph.h"
12#include "TProfile.h"
13
14#include "JTools/JRange.hh"
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 the ranges of x and y values 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 typedef JRange<double> JRange_t;
35
36 vector<JRootObjectID> inputFile;
37 JRange_t x;
38 JRange_t y;
39 int debug;
40
41 try {
42
43 JParser<> zap("Auxiliary program to print the ranges of x and y values of 1D ROOT objects.");
44
45 zap['f'] = make_field(inputFile, "<input file>:<object name>");
46 zap['x'] = make_field(x, "x range") = JRange_t();
47 zap['y'] = make_field(y, "y range") = JRange_t();
48 zap['d'] = make_field(debug) = 0;
49
50 zap(argc, argv);
51 }
52 catch(const exception &error) {
53 FATAL(error.what() << endl);
54 }
55
56
57 JRange_t X = JRange_t::DEFAULT_RANGE();
58 JRange_t Y = JRange_t::DEFAULT_RANGE();
59
60 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
61
62 DEBUG("Input: " << *input << endl);
63
64 TDirectory* dir = getDirectory(*input);
65
66 if (dir == NULL) {
67 ERROR("File: " << input->getFullFilename() << " not opened." << endl);
68 continue;
69 }
70
71 const TRegexp regexp(input->getObjectName());
72
73 TIter iter(dir->GetListOfKeys());
74
75 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
76
77 const TString tag(key->GetName());
78
79 DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
80
81 // option match
82
83 if (tag.Contains(regexp) && isTObject(key)) {
84
85 TObject* object = key->ReadObj();
86
87 try {
88
89 TH1& h1 = dynamic_cast<TH1&>(*object);
90
91 X.combine(x.join(JRange_t(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax())));
92 Y.combine(y.join(JRange_t(h1.GetMinimum(), h1.GetMaximum())));
93 }
94 catch(exception&) {}
95
96 try {
97
98 TProfile& h1 = dynamic_cast<TProfile&>(*object);
99
100 X.combine(x.join(JRange_t(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax())));
101 Y.combine(y.join(JRange_t(h1.GetMinimum(), h1.GetMaximum())));
102 }
103 catch(exception&) {}
104
105 try {
106
107 TGraph& g1 = dynamic_cast<TGraph&>(*object);
108
109 for (Int_t i = 0; i != g1.GetN(); ++i) {
110 if (x(g1.GetX()[i]) &&
111 y(g1.GetY()[i])) {
112 X.include(g1.GetX()[i]);
113 Y.include(g1.GetY()[i]);
114 }
115 }
116 }
117 catch(exception&) {}
118 }
119 }
120 }
121
122
123 cout << SCIENTIFIC(15,5) << X.getLowerLimit() << ' '
124 << SCIENTIFIC(15,5) << Y.getLowerLimit() << ' '
125 << SCIENTIFIC(15,5) << X.getUpperLimit() << ' '
126 << SCIENTIFIC(15,5) << Y.getUpperLimit() << endl;
127}
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
Auxiliary class to define a range between two values.
Utility class to parse command line options.
Definition JParser.hh:1698
Range of values.
Definition JRange.hh:42
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