Jpp  17.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPrintRange1D.cc File Reference

Auxiliary program to print the ranges of x and y values of 1D ROOT objects. More...

#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

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) && isTObject(key)) {
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 << SCIENTIFIC(15,5) << X.getLowerLimit() << ' '
125  << SCIENTIFIC(15,5) << Y.getLowerLimit() << ' '
126  << SCIENTIFIC(15,5) << X.getUpperLimit() << ' '
127  << SCIENTIFIC(15,5) << Y.getUpperLimit() << endl;
128 }
Utility class to parse command line options.
Definition: JParser.hh:1517
Definition: JRoot.hh:19
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
#define ERROR(A)
Definition: JMessage.hh:66
#define FATAL(A)
Definition: JMessage.hh:67
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
no fit printf nominal n $STRING awk v X
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25