Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JScale1D.cc File Reference

Auxiliary program to scale ROOT histograms. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
#include "TROOT.h"
#include "TFile.h"
#include "TObject.h"
#include "TKey.h"
#include "TH1.h"
#include "TString.h"
#include "TRegexp.h"
#include "JTools/JRange.hh"
#include "JGizmo/JRootObjectID.hh"
#include "JGizmo/JGizmoToolkit.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 scale ROOT histograms.

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

The scale factor (option -F <factor>) refers to a ROOT TFormula. The expression may contain member methods of the corresponding object.

Author
mdejong

Definition in file JScale1D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 33 of file JScale1D.cc.

34 {
35  using namespace std;
36  using namespace JPP;
37 
38  typedef JRange<double> JRange_t;
39 
40  vector<JRootObjectID> inputFile;
41  string outputFile;
42  TString formula;
43  JRange_t X;
44  JRange_t Y;
45  string option;
46  int debug;
47 
48  try {
49 
50  JParser<> zap("Auxiliary program to scale ROOT histograms."\
51  "\nNote that the formula may contain method names of the specified object.");
52 
53  zap['f'] = make_field(inputFile, "<input file>:<object name>");
54  zap['o'] = make_field(outputFile, "ROOT file with histogram(s)") = "scale.root";
55  zap['F'] = make_field(formula, "ROOT TFormula (may contain method names of object)");
56  zap['x'] = make_field(X, "abscissa range (only for Integral)") = JRange_t();
57  zap['y'] = make_field(Y, "abscissa range (only for Integral)") = JRange_t();
58  zap['O'] = make_field(option) = "", "nosw2";
59  zap['d'] = make_field(debug) = 0;
60 
61  zap(argc, argv);
62  }
63  catch(const exception &error) {
64  FATAL(error.what() << endl);
65  }
66 
67 
68  TFile out(outputFile.c_str(), "recreate");
69 
70  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
71 
72  DEBUG("Input: " << *input << endl);
73 
74  TDirectory* dir = getDirectory(*input);
75 
76  if (dir == NULL) {
77  ERROR("File: " << input->getFullFilename() << " not opened." << endl);
78  continue;
79  }
80 
81  const TRegexp regexp(input->getObjectName());
82 
83  TIter iter(dir->GetListOfKeys());
84 
85  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
86 
87  const TString tag(key->GetName());
88 
89  DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
90 
91  // option match
92 
93  if (tag.Contains(regexp)) {
94 
95  TObject* object = key->ReadObj();
96 
97  try {
98 
99  TH1& h1 = dynamic_cast<TH1&>(*object);
100 
101  if (X != JRange_t()) { h1.GetXaxis()->SetRangeUser(X.getLowerLimit(), X.getUpperLimit()); }
102  if (Y != JRange_t()) { h1.GetYaxis()->SetRangeUser(Y.getLowerLimit(), Y.getUpperLimit()); }
103 
104  double factor = getResult(formula, object);
105 
106  DEBUG(h1.GetName() << ' ' << formula << ' ' << factor << endl);
107 
108  h1.Scale(factor, option.c_str());
109 
110  out.WriteTObject(&h1);
111  }
112  catch(exception&) {}
113  }
114  }
115  }
116 
117  out.Write();
118  out.Close();
119 }
Utility class to parse command line options.
Definition: JParser.hh:1493
Definition: JRoot.hh:19
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
string outputFile
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
Double_t getResult(const TString &text, TObject *object=NULL)
Get result of given textual formula.
#define ERROR(A)
Definition: JMessage.hh:66
int debug
debug level
Definition: JSirene.cc:61
#define FATAL(A)
Definition: JMessage.hh:67
JRange< Double_t > JRange_t
Definition: JFitToT.hh:34
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62