Skip to content

Commit a7e0452

Browse files
committed
add command line options to the ImpactsTable program
1 parent d3c11de commit a7e0452

File tree

1 file changed

+77
-27
lines changed

1 file changed

+77
-27
lines changed

CombineHarvester/CombineTools/test/ImpactsTable.cpp

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <vector>
44
#include "boost/format.hpp"
55
#include "boost/algorithm/string/replace.hpp"
6+
#include "boost/program_options.hpp"
67
#include "TTree.h"
78
#include "TFile.h"
89
/*
@@ -12,6 +13,7 @@ to configure its behaviour without modifying the code directly.
1213

1314
using namespace std;
1415
using boost::format;
16+
namespace po = boost::program_options;
1517

1618
// Struct holds info on each column in the table
1719
struct Vals {
@@ -35,7 +37,25 @@ struct Vals {
3537

3638

3739
int main(int argc, char* argv[]) {
38-
TFile f("impact.root");
40+
string input_file = "";
41+
unsigned max = 99999;
42+
bool do_latex = false;
43+
bool do_text = false;
44+
45+
po::variables_map vm;
46+
po::notify(vm);
47+
po::options_description config("configuration");
48+
config.add_options()
49+
("input,i", po::value<string>(&input_file)->required())
50+
("max,m", po::value<unsigned>(&max)->default_value(max))
51+
("latex,l", po::value<bool>(&do_latex)->implicit_value(true))
52+
("text,t", po::value<bool>(&do_text)->implicit_value(true));
53+
po::store(po::command_line_parser(argc, argv)
54+
.options(config).allow_unregistered().run(), vm);
55+
po::notify(vm);
56+
57+
58+
TFile f(input_file.c_str());
3959
TTree *t = (TTree*)f.Get("impact");
4060

4161
Vals reader;
@@ -61,45 +81,75 @@ int main(int argc, char* argv[]) {
6181
t->GetEntry(i);
6282
reader.parameter = *param_str;
6383
val_vec.push_back(reader);
64-
std::cout << val_vec.back().parameter << "\n";
6584
}
6685

67-
unsigned max = 30;
6886
string fmt = "& %-5.2f & %-5.2f";
6987

88+
if (do_text) {
89+
cout << format("%-70s %-15s | %-15s | %-15s | %-13s | "
90+
"%-13s | %-13s\n")
91+
% "Parameter"
92+
% "Best (obs)"
93+
% "Best (post)"
94+
% "Best (pre)"
95+
% "Impact (obs)"
96+
% "Impact (post)"
97+
% "Impact (pre)";
98+
99+
for (unsigned i = 0; i < max && i < val_vec.size(); ++i) {
100+
Vals &val = val_vec[i];
101+
102+
cout << format(
103+
"%-70s %7.2f %7.2f | %7.2f %7.2f | %7.2f %7.2f | %7.3f %5i | "
104+
"%7.3f %5i | %7.3f %5i\n")
105+
% val.parameter
106+
% val.par_best
107+
% ((val.par_hi - val.par_lo)/2.)
108+
% val.par_best_post
109+
% ((val.par_hi_post - val.par_lo_post)/2.)
110+
% val.par_best_pre
111+
% ((val.par_hi_pre - val.par_lo_pre)/2.)
112+
% val.impact % val.rank_impact
113+
% val.impact_post % val.rank_impact_post
114+
% val.impact_pre % val.rank_impact_pre;
115+
}
116+
}
117+
70118
// Here we'll make use of C++11 "string literals", to avoid having to escape
71119
// all the latex '\' characters. More info on the format here:
72120
// https://solarianprogrammer.com/2011/10/16/cpp-11-raw-strings-literals-tutorial/
73-
cout << R"(\small)";
74-
cout << R"(\begin{tabular}{l)";
75-
cout << R"(r@{$ \,\,\pm\,\, $}l)";
76-
cout << R"(r@{$ \,\,\pm\,\, $}l)";
77-
cout << R"(rrrr)";
78-
cout << R"(})" << "\n";
121+
if (do_latex) {
122+
cout << R"(\small)";
123+
cout << R"(\begin{tabular}{l)";
124+
cout << R"(r@{$ \,\,\pm\,\, $}l)";
125+
cout << R"(r@{$ \,\,\pm\,\, $}l)";
126+
cout << R"(rrrr)";
127+
cout << R"(})" << "\n";
79128

80129

81-
cout << format("%-60s") % "Nuisance Parameter"
82-
<< R"(& \multicolumn{2}{c}{$\hat{\theta}$ (obs)})"
83-
<< R"(& \multicolumn{2}{c}{$\hat{\theta}$ (asimov)})"
84-
<< R"(& $\Delta\hat{\mu}$ (obs) & Rank)"
85-
<< R"(& $\Delta\hat{\mu}$ (asimov) & Rank)"
86-
<< R"(\\)" << "\n" << R"(\hline)" << "\n";
130+
cout << format("%-60s") % "Nuisance Parameter"
131+
<< R"(& \multicolumn{2}{c}{$\hat{\theta}$ (obs)})"
132+
<< R"(& \multicolumn{2}{c}{$\hat{\theta}$ (asimov)})"
133+
<< R"(& $\Delta\hat{\mu}$ (obs) & Rank)"
134+
<< R"(& $\Delta\hat{\mu}$ (asimov) & Rank)"
135+
<< R"(\\)" << "\n" << R"(\hline)" << "\n";
87136

88137

89-
for (unsigned i = 0; i < max && i < val_vec.size(); ++i) {
90-
Vals & val = val_vec[i];
138+
for (unsigned i = 0; i < max && i < val_vec.size(); ++i) {
139+
Vals & val = val_vec[i];
91140

92-
boost::replace_all(val.parameter, "_", "\\_");
141+
boost::replace_all(val.parameter, "_", "\\_");
93142

94-
cout << format("%-60s") % val.parameter
95-
<< format(fmt) % val.par_best % ((val.par_hi - val.par_lo)/2.)
96-
<< format(fmt) % val.par_best_post % ((val.par_hi_post - val.par_lo_post)/2.)
97-
<< format("& %-5.3f & %-4i") % val.impact % val.rank_impact
98-
<< format("& %-5.3f & %-4i") % val.impact_post % val.rank_impact_post
99-
<< R"(\\)" << "\n";
100-
}
143+
cout << format("%-60s") % val.parameter
144+
<< format(fmt) % val.par_best % ((val.par_hi - val.par_lo)/2.)
145+
<< format(fmt) % val.par_best_post % ((val.par_hi_post - val.par_lo_post)/2.)
146+
<< format("& %-5.3f & %-4i") % val.impact % val.rank_impact
147+
<< format("& %-5.3f & %-4i") % val.impact_post % val.rank_impact_post
148+
<< R"(\\)" << "\n";
149+
}
101150

102-
cout << R"(\hline)" << "\n";
103-
cout << R"(\end{tabular})" << "\n";
151+
cout << R"(\hline)" << "\n";
152+
cout << R"(\end{tabular})" << "\n";
153+
}
104154
return 0;
105155
}

0 commit comments

Comments
 (0)