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

Auxiliary program to print (x) of the maximum of 1D ROOT objects. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <limits>
#include "TROOT.h"
#include "TFile.h"
#include "TClass.h"
#include "TApplication.h"
#include "TKey.h"
#include "TRegexp.h"
#include "TH2.h"
#include "TGraph.h"
#include "TProfile.h"
#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 (x) of the maximum of 1D ROOT objects.

The option -f corresponds to <file name>:<object name>.

Author
mdejong

Definition in file JPrintMaximum1D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 30 of file JPrintMaximum1D.cc.

31 {
32  using namespace std;
33  using namespace JPP;
34 
35  vector<JRootObjectID> inputFile;
36  int debug;
37 
38  try {
39 
40  JParser<> zap("Auxiliary program to print (x) of the maximum of 1D ROOT objects.");
41 
42  zap['f'] = make_field(inputFile, "<input file>:<object name>");
43  zap['d'] = make_field(debug) = 0;
44 
45  zap(argc, argv);
46  }
47  catch(const exception &error) {
48  FATAL(error.what() << endl);
49  }
50 
51 
52  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
53 
54  DEBUG("Input: " << *input << endl);
55 
56  TDirectory* dir = getDirectory(*input);
57 
58  if (dir == NULL) {
59  ERROR("File: " << input->getFullFilename() << " not opened." << endl);
60  continue;
61  }
62 
63  const TRegexp regexp(input->getObjectName());
64 
65  TIter iter(dir->GetListOfKeys());
66 
67  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
68 
69  const TString tag(key->GetName());
70 
71  DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
72 
73  // option match
74 
75  if (tag.Contains(regexp) && isTObject(key)) {
76 
77  TObject* object = key->ReadObj();
78 
79  double x = 0.0;
80  double ymax = numeric_limits<double>::lowest();
81 
82  try {
83 
84  TH1& h1 = dynamic_cast<TH1&>(*object);
85 
86  for (Int_t ix = 1; ix <= h1.GetXaxis()->GetNbins(); ++ix) {
87 
88  double y = h1.GetBinContent(ix);
89 
90  if (y > ymax) {
91  ymax = y;
92  x = h1.GetXaxis()->GetBinCenter(ix);
93  }
94  }
95  }
96  catch(exception&) {}
97 
98  try {
99 
100  TProfile& h1 = dynamic_cast<TProfile&>(*object);
101 
102  for (Int_t ix = 1; ix <= h1.GetXaxis()->GetNbins(); ++ix) {
103 
104  double y = h1.GetBinContent(ix);
105 
106  if (y > ymax) {
107  ymax = y;
108  x = h1.GetXaxis()->GetBinCenter(ix);
109  }
110  }
111  }
112  catch(exception&) {}
113 
114  try {
115 
116  TGraph& g1 = dynamic_cast<TGraph&>(*object);
117 
118  for (Int_t i = 0; i != g1.GetN(); ++i) {
119  if (g1.GetY()[i] > ymax) {
120  ymax = g1.GetY()[i];
121  x = g1.GetX()[i];
122  }
123  }
124  }
125  catch(exception&) {}
126 
127  if (ymax != numeric_limits<double>::lowest()) {
128  cout << setw(32) << left << key->GetName() << right << ' ' << SCIENTIFIC(15,5) << x << endl;
129  }
130  }
131  }
132  }
133 }
Utility class to parse command line options.
Definition: JParser.hh:1514
Definition: JRoot.hh:19
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#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.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:486
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