Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JBinsMap.cc File Reference

Program to test methods of JROOT::JBinsMap. More...

#include <iostream>
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JROOT/JBinsMap.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Program to test methods of JROOT::JBinsMap.

Author
bjung

Definition in file JBinsMap.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 16 of file JBinsMap.cc.

17{
18 using namespace std;
19 using namespace JPP;
20
21 JBinsMap binsMap;
22
23 string outputFile;
24
25 int debug;
26
27 try {
28
29 JParser<> zap("Program to test methods of `JROOT::JBinsMap`");
30
31 zap['@'] = make_field(binsMap);
32 zap['o'] = make_field(outputFile);
33 zap['d'] = make_field(debug);
34
35 zap(argc, argv);
36 }
37 catch(const exception& error) {
38 FATAL(error.what() << endl);
39 }
40
41 for (JBinsMap::const_iterator i = binsMap.cbegin(); i != binsMap.cend(); ++i) {
42
43 unique_ptr<TH1> p;
44
45 if (i->second.find('z') != i->second.cend()) {
46 p = binsMap.getHistogram<TH3D>(i->first);
47 } else if (i->second.find('y') != i->second.cend()) {
48 p = binsMap.getHistogram<TH2D>(i->first);
49 } else if (i->second.find('x') != i->second.cend()) {
50 p = binsMap.getHistogram<TH1D>(i->first);
51 }
52
53 ASSERT(p.get() != NULL);
54
55 const Int_t Ndim = p->GetDimension();
56
57 if (Ndim > 0 && Ndim < 4) {
58
59 const vector<double>& Xbins = i->second.at('x');
60
61 ASSERT(p->GetXaxis()->GetNbins() == (Int_t) Xbins.size()-1);
62
63 for (Int_t n = 1; n <= p->GetXaxis()->GetNbins(); ++n) {
64 DEBUG (p->GetXaxis()->GetBinLowEdge(n) << " =?= " << Xbins[n-1] << endl);
65 ASSERT(p->GetXaxis()->GetBinLowEdge(n) == Xbins[n-1]);
66 }
67
68 if (Ndim > 1) {
69
70 const vector<double>& Ybins = i->second.at('y');
71
72 ASSERT(p->GetYaxis()->GetNbins() == (Int_t) Ybins.size()-1);
73
74 for (Int_t n = 1; n <= p->GetYaxis()->GetNbins(); ++n) {
75 DEBUG (p->GetYaxis()->GetBinLowEdge(n) << " =?= " << Ybins[n-1] << endl);
76 ASSERT(p->GetYaxis()->GetBinLowEdge(n) == Ybins[n-1]);
77 }
78
79 if (Ndim > 2) {
80
81 const vector<double>& Zbins = i->second.at('z');
82
83 ASSERT(p->GetZaxis()->GetNbins() == (Int_t) Zbins.size()-1);
84
85 for (Int_t n = 1; n <= p->GetZaxis()->GetNbins(); ++n) {
86 DEBUG (p->GetZaxis()->GetBinLowEdge(n) << " =?= " << Zbins[n-1] << endl);
87 ASSERT(p->GetZaxis()->GetBinLowEdge(n) == Zbins[n-1]);
88 }
89 }
90 }
91
92 } else {
93 FATAL("Unexpected dimensionality for histogram " << p->GetName());
94 }
95 }
96
97 ofstream ofs(outputFile.c_str());
98
99 ofs << binsMap;
100
101 ofs.close();
102
103 return 0;
104}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Utility class to parse command line options.
Definition JParser.hh:1698
Class for I/O of variable-width binning of multiple histograms.
Definition JBinsMap.hh:42
map_type::const_iterator const_iterator
Definition JBinsMap.hh:53
std::unique_ptr< T > getHistogram(const std::string &name) const
Get histogram with binning corresponding to a given histogram name.
Definition JBinsMap.hh:64
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
const int n
Definition JPolint.hh:791