Jpp
Functions
JScale1D.cc File Reference
#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

◆ main()

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  int debug;
46 
47  try {
48 
49  JParser<> zap("Auxiliary program to scale ROOT histograms."\
50  "\nNote that the formula may contain method names of the specified object.");
51 
52  zap['f'] = make_field(inputFile, "<input file>:<object name>");
53  zap['o'] = make_field(outputFile, "ROOT file with histogram(s)") = "scale.root";
54  zap['F'] = make_field(formula, "ROOT TFormula (may contain method names of object)");
55  zap['x'] = make_field(X, "abscissa range (only for Integral)") = JRange_t();
56  zap['y'] = make_field(Y, "abscissa range (only for Integral)") = JRange_t();
57  zap['d'] = make_field(debug) = 0;
58 
59  zap(argc, argv);
60  }
61  catch(const exception &error) {
62  FATAL(error.what() << endl);
63  }
64 
65 
66  TFile out(outputFile.c_str(), "recreate");
67 
68  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
69 
70  DEBUG("Input: " << *input << endl);
71 
72  TDirectory* dir = getDirectory(*input);
73 
74  if (dir == NULL) {
75  ERROR("File: " << input->getFullFilename() << " not opened." << endl);
76  continue;
77  }
78 
79  const TRegexp regexp(input->getObjectName());
80 
81  TIter iter(dir->GetListOfKeys());
82 
83  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
84 
85  const TString tag(key->GetName());
86 
87  DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
88 
89  // option match
90 
91  if (tag.Contains(regexp)) {
92 
93  TObject* object = key->ReadObj();
94 
95  try {
96 
97  TH1& h1 = dynamic_cast<TH1&>(*object);
98 
99  if (X != JRange_t()) { h1.GetXaxis()->SetRangeUser(X.getLowerLimit(), X.getUpperLimit()); }
100  if (Y != JRange_t()) { h1.GetYaxis()->SetRangeUser(Y.getLowerLimit(), Y.getUpperLimit()); }
101 
102  double factor = getResult(formula, object);
103 
104  DEBUG(h1.GetName() << ' ' << formula << ' ' << factor << endl);
105 
106  h1.Scale(factor);
107 
108  out.WriteTObject(&h1);
109  }
110  catch(exception&) {}
111  }
112  }
113  }
114 
115  out.Write();
116  out.Close();
117 }
TObject
Definition: JRoot.hh:19
JGIZMO::getResult
Double_t getResult(const TString &text, TObject *object=NULL)
Get result of given textual formula.
Definition: JGizmoToolkit.hh:212
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
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37