Jpp
Functions
JPrintRange1D.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TClass.h"
#include "TApplication.h"
#include "TKey.h"
#include "TRegexp.h"
#include "TH1.h"
#include "TGraph.h"
#include "TProfile.h"
#include "JTools/JRange.hh"
#include "JGizmo/JRootObjectID.hh"
#include "JGizmo/JGizmoToolkit.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to print the ranges of x and y values of 1D ROOT objects. The option -f corresponds to <file name>:<object name>.

Author
mdejong

Definition in file JPrintRange1D.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 30 of file JPrintRange1D.cc.

31 {
32  using namespace std;
33  using namespace JPP;
34 
35  typedef JRange<double> JRange_t;
36 
37  vector<JRootObjectID> inputFile;
38  JRange_t x;
39  JRange_t y;
40  int debug;
41 
42  try {
43 
44  JParser<> zap("Auxiliary program to print the ranges of x and y values of 1D ROOT objects.");
45 
46  zap['f'] = make_field(inputFile, "<input file>:<object name>");
47  zap['x'] = make_field(x, "x range") = JRange_t();
48  zap['y'] = make_field(y, "y range") = JRange_t();
49  zap['d'] = make_field(debug) = 0;
50 
51  zap(argc, argv);
52  }
53  catch(const exception &error) {
54  FATAL(error.what() << endl);
55  }
56 
57 
58  JRange_t X = JRange_t::DEFAULT_RANGE;
59  JRange_t Y = JRange_t::DEFAULT_RANGE;
60 
61  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
62 
63  DEBUG("Input: " << *input << endl);
64 
65  TDirectory* dir = getDirectory(*input);
66 
67  if (dir == NULL) {
68  ERROR("File: " << input->getFullFilename() << " not opened." << endl);
69  continue;
70  }
71 
72  const TRegexp regexp(input->getObjectName());
73 
74  TIter iter(dir->GetListOfKeys());
75 
76  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
77 
78  const TString tag(key->GetName());
79 
80  DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
81 
82  // option match
83 
84  if (tag.Contains(regexp)) {
85 
86  TObject* object = key->ReadObj();
87 
88  try {
89 
90  TH1& h1 = dynamic_cast<TH1&>(*object);
91 
92  X.combine(x.join(JRange_t(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax())));
93  Y.combine(y.join(JRange_t(h1.GetMinimum(), h1.GetMaximum())));
94  }
95  catch(exception&) {}
96 
97  try {
98 
99  TProfile& h1 = dynamic_cast<TProfile&>(*object);
100 
101  X.combine(x.join(JRange_t(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax())));
102  Y.combine(y.join(JRange_t(h1.GetMinimum(), h1.GetMaximum())));
103  }
104  catch(exception&) {}
105 
106  try {
107 
108  TGraph& g1 = dynamic_cast<TGraph&>(*object);
109 
110  for (Int_t i = 0; i != g1.GetN(); ++i) {
111  if (x(g1.GetX()[i]) &&
112  y(g1.GetY()[i])) {
113  X.include(g1.GetX()[i]);
114  Y.include(g1.GetY()[i]);
115  }
116  }
117  }
118  catch(exception&) {}
119  }
120  }
121  }
122 
123 
124  cout << FIXED(15,3) << X.getLowerLimit() << ' '
125  << FIXED(15,3) << Y.getLowerLimit() << ' '
126  << FIXED(15,3) << X.getUpperLimit() << ' '
127  << FIXED(15,3) << Y.getUpperLimit() << endl;
128 }
TObject
Definition: JRoot.hh:19
FIXED
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
g1
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25
std::vector
Definition: JSTDTypes.hh:12
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
ERROR
#define ERROR(A)
Definition: JMessage.hh:66
debug
int debug
debug level
Definition: JSirene.cc:59
JGIZMO::getDirectory
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
Definition: JGizmoToolkit.hh:121
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
FATAL
#define FATAL(A)
Definition: JMessage.hh:67