MaCh3  2.5.0
Reference Guide
plotting.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #include <pybind11/pybind11.h>
7 #include <pybind11/stl.h>
8 
9 #include <vector>
10 #include <string>
11 
12 #include "Plotting/PlottingUtils/PlottingUtils.h"
13 #include "Plotting/PlottingUtils/PlottingManager.h"
14 #include "Plotting/PlottingUtils/StyleManager.h"
15 #include "Plotting/PlottingUtils/InputManager.h"
16 
17 namespace py = pybind11;
18 
19 
20 void initPlottingModule(py::module &m_plotting){
21 
22  py::class_<MaCh3Plotting::PlottingManager>(m_plotting, "PlottingManager")
23  .def(
24  py::init<const std::string &>(),
25  "construct a PlottingManager using the specified config file",
26  py::arg("config_file_name")
27  )
28 
29  .def(
30  py::init(),
31  "default constructor, will initialise the PlottingManager with the default plotting config"
32  )
33 
34  .def(
35  "initialise",
36  &MaCh3Plotting::PlottingManager::initialise,
37  "initalise this PlottingManager"
38  )
39 
40  .def(
41  "usage",
43  "Print a usage message for the current executable"
44  )
45 
46  .def(
47  "parse_inputs",
48  &MaCh3Plotting::PlottingManager::parseInputsVec,
49  "Parse command line variables",
50  py::arg("arguments")
51  )
52 
53  .def(
54  "set_exec",
55  &MaCh3Plotting::PlottingManager::setExec,
56  "Set the name of the current executable, which will be used when getting executable specific options from the plotting config file",
57  py::arg("exec_name")
58  )
59 
60  .def(
61  "get_file_name",
62  &MaCh3Plotting::PlottingManager::getFileName,
63  "Get the path to a particular file",
64  py::arg("input_file_id")
65  )
66 
67  .def(
68  "get_file_label",
69  &MaCh3Plotting::PlottingManager::getFileLabel,
70  "Get the specified label of a particular input file",
71  py::arg("input_file_id")
72  )
73 
74  .def(
75  "get_draw_options",
76  &MaCh3Plotting::PlottingManager::getDrawOptions,
77  "Get any additional root drawing options specified by the user"
78  )
79 
80  .def(
81  "get_output_name",
82  py::overload_cast<const std::string &>(&MaCh3Plotting::PlottingManager::getOutputName),
83  "Get the output name specified by the user, can specify an additional *suffix* to append to the file name but before the file extension",
84  py::arg("suffix") = ""
85  )
86 
87  .def(
88  "get_file_names",
89  &MaCh3Plotting::PlottingManager::getFileNames,
90  "Get the list of all file names"
91  )
92 
93  .def(
94  "get_file_labels",
95  &MaCh3Plotting::PlottingManager::getFileLabels,
96  "Get the list of all file labels"
97  )
98 
99  .def(
100  "get_n_files",
101  &MaCh3Plotting::PlottingManager::getNFiles,
102  "Get the number of specified files"
103  )
104 
105  .def(
106  "get_split_by_sample",
107  &MaCh3Plotting::PlottingManager::getSplitBySample,
108  "Get whether or not the user has set the 'split by sample' (-s) option"
109  )
110 
111  .def(
112  "get_plot_ratios",
113  &MaCh3Plotting::PlottingManager::getPlotRatios,
114  "Get whether or not the user specified the 'plot ratios' (-r) option"
115  )
116 
117  .def(
118  "get_draw_grid",
119  &MaCh3Plotting::PlottingManager::getDrawGrid,
120  "Get wheter or not the user has specified the 'draw grid' (-g) option"
121  )
122 
123  .def(
124  "style",
125  &MaCh3Plotting::PlottingManager::style, py::return_value_policy::reference,
126  "Get the StyleManager associated with this PlottingManager"
127  )
128 
129  .def(
130  "input",
131  &MaCh3Plotting::PlottingManager::input, py::return_value_policy::reference,
132  "Get the InputManager associated with this PlottingManager"
133  )
134 
135  // 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 :/
136  // I think one solution would be to extend the PlottingManager class inside of python (add a pyPlottingManager (or something like that) that derives
137  // 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
138  ;
139 
140  py::class_<MaCh3Plotting::InputManager>(m_plotting, "InputManager")
141  .def(
142  "print",
143  &MaCh3Plotting::InputManager::print,
144  "Print a summary of everything this manager knows"
145  )
146 
147  .def(
148  "get_llh_scan",
149  &MaCh3Plotting::InputManager::getLLHScan,
150  "Get the LLH scan for a particular parameter from a particular file",
151  py::arg("input_file_id"),
152  py::arg("param_name"),
153  py::arg("LLH_type") = "total"
154  )
155 
156  .def(
157  "get_llh_scan_by_sample",
158  &MaCh3Plotting::InputManager::getSampleSpecificLLHScan,
159  "Get the LLH scan for a particular parameter from a particular file for a particular sample",
160  py::arg("input_file_id"),
161  py::arg("param"),
162  py::arg("sample")
163  )
164 
165  .def(
166  "get_enabled_llh",
167  &MaCh3Plotting::InputManager::getEnabledLLH,
168  "Get whether a particular file has LLH scans for a particular parameter",
169  py::arg("input_file_id"),
170  py::arg("param"),
171  py::arg("LLH_type") = "total"
172  )
173 
174  .def(
175  "get_enabled_llh_by_sample",
176  &MaCh3Plotting::InputManager::getEnabledLLHBySample,
177  "Get whether a particular file has LLH scans for a particular parameter for a particular sample",
178  py::arg("input_file_id"),
179  py::arg("param"),
180  py::arg("sample")
181  )
182 
183  .def(
184  "get_post_fit_error",
185  &MaCh3Plotting::InputManager::getPostFitError,
186  "Get the post fit error for a parameter from a particular file",
187  py::arg("input_file_id"),
188  py::arg("param"),
189  py::arg("error_type") = ""
190  )
191 
192  .def(
193  "get_post_fit_value",
194  &MaCh3Plotting::InputManager::getPostFitValue,
195  "Get the post fit value for a parameter from a particular file",
196  py::arg("input_file_id"),
197  py::arg("param"),
198  py::arg("error_type") = ""
199  )
200 
201  .def(
202  "get_known_parameters",
203  &MaCh3Plotting::InputManager::getKnownParameters,
204  "Get all the parameters that this manager knows about. Useful for iterating over"
205  )
206 
207  .def(
208  "get_known_samples",
209  &MaCh3Plotting::InputManager::getKnownSamples,
210  "Get all the samples that this manager knows about. Useful for iterating over"
211  )
212 
213  .def(
214  "get_tagged_parameters",
215  &MaCh3Plotting::InputManager::getTaggedParameters,
216  "Get all the parameters whose tags match some specified list",
217  py::arg("tags"),
218  py::arg("check_type") = "all"
219  )
220 
221  .def(
222  "get_tagged_samples",
223  &MaCh3Plotting::InputManager::getTaggedSamples,
224  "Get all the samples whose tags match some specified list",
225  py::arg("tags"),
226  py::arg("check_type") = "all"
227  )
228 
229  .def(
230  "get_n_input_files",
231  &MaCh3Plotting::InputManager::getNInputFiles,
232  "Get the number of input files registered with this manager"
233  )
234 
235  .def(
236  "get_known_llh_parameters",
237  &MaCh3Plotting::InputManager::getKnownLLHParameters,
238  "Get all the parameters that a file has LLH scans for",
239  py::arg("file_id")
240  )
241 
242  .def(
243  "get_known_llh_samples",
244  &MaCh3Plotting::InputManager::getKnownLLHSamples,
245  "Get all the samples that a file has individual LLH scans for",
246  py::arg("file_id")
247  )
248 
249  .def(
250  "get_known_post_fit_parameters",
251  &MaCh3Plotting::InputManager::getKnownPostFitParameters,
252  "Get all the parameters that a file has post fit values and errors for",
253  py::arg("file_id")
254  )
255 
256  .def(
257  "get_known_MCMC_parameters",
258  &MaCh3Plotting::InputManager::getKnownMCMCParameters,
259  "Get all the parameters that a file has MCMC chain entries for",
260  py::arg("file_id")
261  )
262 
263  .def(
264  "get_known_1d_posterior_parameters",
265  &MaCh3Plotting::InputManager::getKnown1dPosteriorParameters,
266  "Get all the parameters that a file has processed 1d posteriors for",
267  py::arg("file_id")
268  )
269 
270  .def(
271  "get_MCMC_entry",
272  &MaCh3Plotting::InputManager::getMCMCentry,
273  "Load up a particular step in the MCMC chain for a particular input file",
274  py::arg("file_id"),
275  py::arg("step")
276  )
277 
278  .def(
279  "get_MCMC_value",
280  &MaCh3Plotting::InputManager::getMCMCvalue,
281  "Get the value of a particular parameter for the current entry (set by set_MCMC_entry) in the chain for a particular file",
282  py::arg("file_id"),
283  py::arg("param")
284  )
285 
286  .def(
287  "get_n_MCMC_entries",
288  &MaCh3Plotting::InputManager::getnMCMCentries,
289  "Get the number of entries in the MCMC chain in a particular file"
290  )
291 
292  .def(
293  "get_1d_posterior",
294  &MaCh3Plotting::InputManager::get1dPosterior,
295  "Get the 1d posterior for a particular parameter from a particular file",
296  py::arg("file_id"),
297  py::arg("param")
298  )
299  ;
300 
301  py::class_<MaCh3Plotting::StyleManager>(m_plotting, "StyleManager")
302  .def(
303  "prettify_parameter_name",
304  &MaCh3Plotting::StyleManager::prettifyParamName,
305  "Convert internally used parameter name to a nice pretty name that can be used in plots",
306  py::arg("param")
307  )
308 
309  .def(
310  "prettify_sample_name",
311  &MaCh3Plotting::StyleManager::prettifyParamName,
312  "Convert internally used sample name to a nice pretty name that can be used in plots",
313  py::arg("sample")
314  )
315  ;
316 }
void usage()
void initPlottingModule(py::module &m_plotting)
Definition: plotting.h:20