MaCh3  2.2.3
Reference Guide
plotting.cpp
Go to the documentation of this file.
1 #include <pybind11/pybind11.h>
2 #include <pybind11/stl.h>
3 
4 #include <vector>
5 #include <string>
6 
11 
12 namespace py = pybind11;
13 
14 
15 void initPlotting(py::module &m){
16 
17  auto m_plotting = m.def_submodule("plotting");
18  m_plotting.doc() = "This is a Python binding of MaCh3s C++ based plotting library.";
19 
20  py::class_<MaCh3Plotting::PlottingManager>(m_plotting, "PlottingManager")
21  .def(
22  py::init<const std::string &>(),
23  "construct a PlottingManager using the specified config file",
24  py::arg("config_file_name")
25  )
26 
27  .def(
28  py::init(),
29  "default constructor, will initialise the PlottingManager with the default plotting config"
30  )
31 
32  .def(
33  "initialise",
35  "initalise this PlottingManager"
36  )
37 
38  .def(
39  "usage",
41  "Print a usage message for the current executable"
42  )
43 
44  .def(
45  "parse_inputs",
47  "Parse command line variables",
48  py::arg("arguments")
49  )
50 
51  .def(
52  "set_exec",
54  "Set the name of the current executable, which will be used when getting executable specific options from the plotting config file",
55  py::arg("exec_name")
56  )
57 
58  .def(
59  "get_file_name",
61  "Get the path to a particular file",
62  py::arg("input_file_id")
63  )
64 
65  .def(
66  "get_file_label",
68  "Get the specified label of a particular input file",
69  py::arg("input_file_id")
70  )
71 
72  .def(
73  "get_draw_options",
75  "Get any additional root drawing options specified by the user"
76  )
77 
78  .def(
79  "get_output_name",
80  py::overload_cast<const std::string &>(&MaCh3Plotting::PlottingManager::getOutputName),
81  "Get the output name specified by the user, can specify an additional *suffix* to append to the file name but before the file extension",
82  py::arg("suffix") = ""
83  )
84 
85  .def(
86  "get_file_names",
88  "Get the list of all file names"
89  )
90 
91  .def(
92  "get_file_labels",
94  "Get the list of all file labels"
95  )
96 
97  .def(
98  "get_n_files",
100  "Get the number of specified files"
101  )
102 
103  .def(
104  "get_split_by_sample",
106  "Get whether or not the user has set the 'split by sample' (-s) option"
107  )
108 
109  .def(
110  "get_plot_ratios",
112  "Get whether or not the user specified the 'plot ratios' (-r) option"
113  )
114 
115  .def(
116  "get_draw_grid",
118  "Get wheter or not the user has specified the 'draw grid' (-g) option"
119  )
120 
121  .def(
122  "style",
123  &MaCh3Plotting::PlottingManager::style, py::return_value_policy::reference,
124  "Get the StyleManager associated with this PlottingManager"
125  )
126 
127  .def(
128  "input",
129  &MaCh3Plotting::PlottingManager::input, py::return_value_policy::reference,
130  "Get the InputManager associated with this PlottingManager"
131  )
132 
133  // EM: I can't figure out how to add the getOption methods as theres not really a way to deduce the return type from yaml so leaving them out for now :/
134  // I think one solution would be to extend the PlottingManager class inside of python (add a pyPlottingManager (or something like that) that derives
135  // from this one and add the functions to that) and then fold that python code into the module somehow. But that is currently beyond my pybinding abilities
136  ;
137 
138  py::class_<MaCh3Plotting::InputManager>(m_plotting, "InputManager")
139  .def(
140  "print",
142  "Print a summary of everything this manager knows"
143  )
144 
145  .def(
146  "get_llh_scan",
148  "Get the LLH scan for a particular parameter from a particular file",
149  py::arg("input_file_id"),
150  py::arg("param_name"),
151  py::arg("LLH_type") = "total"
152  )
153 
154  .def(
155  "get_llh_scan_by_sample",
157  "Get the LLH scan for a particular parameter from a particular file for a particular sample",
158  py::arg("input_file_id"),
159  py::arg("param"),
160  py::arg("sample")
161  )
162 
163  .def(
164  "get_enabled_llh",
166  "Get whether a particular file has LLH scans for a particular parameter",
167  py::arg("input_file_id"),
168  py::arg("param"),
169  py::arg("LLH_type") = "total"
170  )
171 
172  .def(
173  "get_enabled_llh_by_sample",
175  "Get whether a particular file has LLH scans for a particular parameter for a particular sample",
176  py::arg("input_file_id"),
177  py::arg("param"),
178  py::arg("sample")
179  )
180 
181  .def(
182  "get_post_fit_error",
184  "Get the post fit error for a parameter from a particular file",
185  py::arg("input_file_id"),
186  py::arg("param"),
187  py::arg("error_type") = ""
188  )
189 
190  .def(
191  "get_post_fit_value",
193  "Get the post fit value for a parameter from a particular file",
194  py::arg("input_file_id"),
195  py::arg("param"),
196  py::arg("error_type") = ""
197  )
198 
199  .def(
200  "get_known_parameters",
202  "Get all the parameters that this manager knows about. Useful for iterating over"
203  )
204 
205  .def(
206  "get_known_samples",
208  "Get all the samples that this manager knows about. Useful for iterating over"
209  )
210 
211  .def(
212  "get_tagged_parameters",
214  "Get all the parameters whose tags match some specified list",
215  py::arg("tags"),
216  py::arg("check_type") = "all"
217  )
218 
219  .def(
220  "get_tagged_samples",
222  "Get all the samples whose tags match some specified list",
223  py::arg("tags"),
224  py::arg("check_type") = "all"
225  )
226 
227  .def(
228  "get_n_input_files",
230  "Get the number of input files registered with this manager"
231  )
232 
233  .def(
234  "get_known_llh_parameters",
236  "Get all the parameters that a file has LLH scans for",
237  py::arg("file_id")
238  )
239 
240  .def(
241  "get_known_llh_samples",
243  "Get all the samples that a file has individual LLH scans for",
244  py::arg("file_id")
245  )
246 
247  .def(
248  "get_known_post_fit_parameters",
250  "Get all the parameters that a file has post fit values and errors for",
251  py::arg("file_id")
252  )
253 
254  .def(
255  "get_known_MCMC_parameters",
257  "Get all the parameters that a file has MCMC chain entries for",
258  py::arg("file_id")
259  )
260 
261  .def(
262  "get_known_1d_posterior_parameters",
264  "Get all the parameters that a file has processed 1d posteriors for",
265  py::arg("file_id")
266  )
267 
268  .def(
269  "get_MCMC_entry",
271  "Load up a particular step in the MCMC chain for a particular input file",
272  py::arg("file_id"),
273  py::arg("step")
274  )
275 
276  .def(
277  "get_MCMC_value",
279  "Get the value of a particular parameter for the current entry (set by set_MCMC_entry) in the chain for a particular file",
280  py::arg("file_id"),
281  py::arg("param")
282  )
283 
284  .def(
285  "get_n_MCMC_entries",
287  "Get the number of entries in the MCMC chain in a particular file"
288  )
289 
290  .def(
291  "get_1d_posterior",
293  "Get the 1d posterior for a particular parameter from a particular file",
294  py::arg("file_id"),
295  py::arg("param")
296  )
297 
298  ;
299 
300  py::class_<MaCh3Plotting::StyleManager>(m_plotting, "StyleManager")
301  .def(
302  "prettify_parameter_name",
304  "Convert internally used parameter name to a nice pretty name that can be used in plots",
305  py::arg("param")
306  )
307 
308  .def(
309  "prettify_sample_name",
311  "Convert internally used sample name to a nice pretty name that can be used in plots",
312  py::arg("sample")
313  )
314  ;
315 
316 }
const std::vector< std::string > & getKnownParameters() const
Definition: inputManager.h:471
std::vector< std::string > getTaggedSamples(const std::vector< std::string > &tags, std::string checkType="all") const
Get all samples which have some set of tags.
Definition: inputManager.h:493
const std::vector< std::string > & getKnownLLHParameters(int fileId) const
Definition: inputManager.h:504
void getMCMCentry(const int fileNum, const int entry) const
Get the MCMC chain entry in an InputFile.
Definition: inputManager.h:300
double getPostFitError(const int fileNum, const std::string &paramName, std::string errorType="") const
Get the post fit error for a particular parameter from a particular input file.
double getPostFitValue(const int fileNum, const std::string &paramName, std::string errorType="") const
Get the post fit value for a particular parameter from a particular input file.
std::vector< std::string > getTaggedParameters(const std::vector< std::string > &tags, std::string checkType="all") const
Get all parameters which have some set of tags.
Definition: inputManager.h:482
std::vector< std::vector< double > > getLLHScan(const int fileNum, const std::string &paramName, const std::string &LLHType) const
Get the log likelihood scan data for a particular parameter from a particular input file.
Definition: inputManager.h:287
const std::vector< std::string > & getKnownPostFitParameters(int fileId) const
Definition: inputManager.h:510
const std::vector< std::string > & getKnownLLHSamples(int fileId) const
Definition: inputManager.h:507
std::vector< std::vector< double > > get1dPosterior(const int fileNum, const std::string &paramName) const
Get the 1d posterior particular parameter from a particular input file.
Definition: inputManager.h:335
bool getEnabledLLHBySample(const int fileNum, const std::string &paramName, const std::string &sample) const
Get whether or not a particular parameter has an LLH scan in a particular input file for a particular...
Definition: inputManager.h:431
std::vector< std::vector< double > > getSampleSpecificLLHScan(const int fileNum, const std::string &paramName, const std::string &sample) const
Get the log likelihood scan for a particular parameter, for a specific sample, from a particular inpu...
Definition: inputManager.h:384
const std::vector< std::string > & getKnownSamples() const
Definition: inputManager.h:472
bool getEnabledLLH(const int fileNum, const std::string &paramName, std::string LLHType="total") const
Get whether or not a particular parameter has an LLH scan in a particular input file.
Definition: inputManager.h:420
double getMCMCvalue(int fileNum, std::string paramName) const
Get the parameter value for the current step for a particular parameter from a particular input file.
Definition: inputManager.h:320
int getnMCMCentries(const int fileNum) const
Get the number of entries in the MCMC chain in a particular file.
Definition: inputManager.h:347
size_t getNInputFiles() const
Definition: inputManager.h:473
const std::vector< std::string > & getKnown1dPosteriorParameters(int fileId) const
Definition: inputManager.h:516
void print(const std::string &printLevel="summary") const
Print out what this Inputmanager instance knows about.
const std::vector< std::string > & getKnownMCMCParameters(int fileId) const
Definition: inputManager.h:513
const std::string getFileName(int i) const
void initialise()
initalise this PlottingManager.
void setExec(const std::string &execName)
Internally set the name of the executable that manager is being used in.
void parseInputsVec(std::vector< std::string > argv)
Parse vector of command line arguments.
const std::string getFileLabel(int i) const
const InputManager & input() const
Get the InputManager contained within this PlottingManager, for doing input related things.
const std::string getOutputName() const
Get the straight up output file name with no bells or whistles, just the file extension.
void usage()
Print a usage message for the current executable.
const StyleManager & style() const
Get the StyleManager contained within this PlottingManager, for doing style related things.
const std::vector< std::string > getFileNames() const
const std::string getDrawOptions() const
const std::vector< std::string > getFileLabels() const
std::string prettifyParamName(const std::string &origName) const
Convert hideous and vulgar internal parameter name into a beautiful presentable name.
Definition: styleManager.h:39
void initPlotting(py::module &m)
Definition: plotting.cpp:15