Jpp
Functions
JVariance1D.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include "TROOT.h"
#include "TFile.h"
#include "TKey.h"
#include "TH1D.h"
#include "TH1.h"
#include "TString.h"
#include "TRegexp.h"
#include "JTools/JAbstractHistogram.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 histogram bin-by-bin deviations of the contents of one (or more) 1D histogram(s). The option -f corresponds to <file name>:<object name>.

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

In case of multiple histograms, the formula is evaluated stand alone (i.e. without ROOT histogram). If formula equals "first", the bin-by-bin deviations of the contents of the histograms are evaluated with respect to the first histogram.

Author
mdejong

Definition in file JVariance1D.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 44 of file JVariance1D.cc.

45 {
46  using namespace std;
47  using namespace JPP;
48 
49  typedef JAbstractHistogram<Double_t> JHistogram_t;
50 
51  vector<JRootObjectID> inputFile;
52  string outputFile;
53  bool reuse;
54  JHistogram_t X;
55  TString formula;
56  bool reverse;
57  int debug;
58 
59  try {
60 
61  JParser<> zap("Auxiliary program to histogram bin-by-bin deviations of a set of 1D histograms.");
62 
63  zap['f'] = make_field(inputFile, "<input file>:<object name>");
64  zap['o'] = make_field(outputFile, "ROOT file with histogram (possibly I/O, option -r)") = "variance.root";
65  zap['r'] = make_field(reuse, "reuse histogram from existing output file");
66  zap['x'] = make_field(X, "histogram binning");
67  zap['F'] = make_field(formula, "ROOT TFormula (may contain method names of object)") = "0";
68  zap['R'] = make_field(reverse, "reverse sign");
69  zap['d'] = make_field(debug) = 1;
70 
71  zap(argc, argv);
72  }
73  catch(const exception &error) {
74  FATAL(error.what() << endl);
75  }
76 
77 
78  vector<TH1*> listOfHistograms;
79 
80  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
81 
82  TH1* h1 = dynamic_cast<TH1*>(getObject(*input));
83 
84  if (h1 != NULL) {
85  listOfHistograms.push_back(h1);
86  }
87  }
88 
89  if (listOfHistograms.empty()) {
90  FATAL("No histograms." << endl);
91  }
92 
93  if (formula == "") {
94  FATAL("Empty formula." << endl);
95  }
96 
97  TH1* h0 = NULL;
98 
99  if (reuse) {
100  h0 = dynamic_cast<TH1*>(getObject(JRootObjectID(outputFile, "h0")));
101  }
102 
103  if (h0 == NULL) {
104  h0 = new TH1D("h0", NULL,
105  X.getNumberOfBins(), X.getLowerLimit(), X.getUpperLimit());
106  }
107 
108 
109  TH1* h1 = listOfHistograms[0];
110 
111  if (listOfHistograms.size() == 1) {
112 
113  const double y1 = getResult(formula, h1);
114 
115  DEBUG(h1->GetName() << ' ' << formula << ' ' << y1 << endl);
116 
117  for (Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
118 
119  const Double_t yp = h1->GetBinContent(i);
120 
121  h0->Fill(reverse ? y1 - yp : yp - y1);
122  }
123 
124  } else {
125 
126  if (formula == first_t) {
127 
128  for (Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
129 
130  const double y1 = h1->GetBinContent(i);
131 
132  for (vector<TH1*>::const_iterator p = listOfHistograms.begin(); ++p != listOfHistograms.end(); ) {
133 
134  const Double_t yp = (*p)->GetBinContent(i);
135 
136  h0->Fill(reverse ? y1 - yp : yp - y1);
137  }
138  }
139 
140  } else {
141 
142  const double y1 = getResult(formula);
143 
144  for (Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
145 
146  for (vector<TH1*>::const_iterator p = listOfHistograms.begin(); p != listOfHistograms.end(); ++p) {
147 
148  const Double_t yp = (*p)->GetBinContent(i);
149 
150  h0->Fill(reverse ? y1 - yp : yp - y1);
151  }
152  }
153  }
154  }
155 
156 
157  TFile out(outputFile.c_str(), "recreate");
158 
159  h0->Write();
160 
161  out.Write();
162  out.Close();
163 }
JGIZMO::getObject
TObject * getObject(const JRootObjectID &id)
Get TObject.
Definition: JGizmoToolkit.hh:142
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
debug
int debug
debug level
Definition: JSirene.cc:59
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