MaCh3 2.2.1
Reference Guide
Loading...
Searching...
No Matches
Classes | Functions
fitters.cpp File Reference
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "Fitters/FitterBase.h"
#include "Fitters/mcmc.h"
#include "Fitters/MinuitFit.h"
#include "Fitters/PSO.h"
Include dependency graph for fitters.cpp:

Go to the source code of this file.

Classes

class  PyFitterBase
 EW: As FitterBase is an abstract base class we have to do some gymnastics to get it to get it into python. More...
 
class  PyLikelihoodFit
 EW: As LikelihoodFit is an abstract base class we have to do some gymnastics to get it to get it into python. More...
 

Functions

void initFitters (py::module &m)
 

Function Documentation

◆ initFitters()

void initFitters ( py::module &  m)

Definition at line 55 of file fitters.cpp.

55 {
56
57 auto m_fitters = m.def_submodule("fitters");
58 m_fitters.doc() =
59 "This is a Python binding of MaCh3s C++ fitters library.";
60
61
62 py::class_<FitterBase, PyFitterBase /* <--- trampoline*/>(m_fitters, "FitterBase")
63 .def(py::init<manager* const>())
64
65 .def(
66 "run",
68 "The implementation of the fitter, you should override this with your own desired fitting algorithm"
69 )
70
71 .def(
72 "get_name",
74 " The name of the algorithm, you should override this with something like:: \n"
75 "\n"
76 " return 'mySuperCoolAlgoName' \n"
77 )
78
79 .def(
80 "run_LLH_scan",
82 "Perform a 1D likelihood scan"
83 )
84
85 .def(
86 "get_step_scale_from_LLH_scan",
88 "LLH scan is good first estimate of step scale, this will get the rough estimates for the step scales based on running an LLH scan"
89 )
90
91 .def(
92 "run_2d_LLH_scan",
94 " Perform a 2D likelihood scan. \n"
95 " :param warning: This operation may take a significant amount of time, especially for complex models."
96 )
97
98 .def(
99 "run_sigma_var",
101 " Perform a 2D and 1D sigma var for all samples. \n"
102 " :param warning: Code uses TH2Poly"
103 )
104
105 .def(
106 "drag_race",
108 " Calculates the required time for each sample or covariance object in a drag race simulation. Inspired by Dan's feature \n"
109 " :param NLaps: number of laps, every part of Fitter will be tested with given number of laps and you will get total and average time",
110 py::arg("NLaps") = 100
111 )
112
113 // stuff for registering other objects with the fitter
114
115 .def(
116 "add_sample_handler",
118 " This function adds a sample handler object to the analysis framework. The sample handler object will be utilized in fitting procedures or likelihood scans. \n"
119 " :param sample: A sample handler object derived from SampleHandlerBase. ",
120 py::arg("sample")
121 )
122
123 .def(
124 "add_syst_object",
126 " This function adds a Covariance object to the analysis framework. The Covariance object will be utilized in fitting procedures or likelihood scans. \n"
127 " :param cov: A Covariance object derived from ParameterHandlerBase. ",
128 py::arg("cov")
129 )
130
131 ; // End of FitterBase class binding
132
133 py::class_<mcmc, FitterBase>(m_fitters, "MCMC")
134 .def(py::init<manager* const>())
135
136 .def(
137 "set_chain_length",
139 "Set how long chain should be.",
140 py::arg("length")
141 )
142 ; // end of MCMC class binding
143
144 py::class_<LikelihoodFit, PyLikelihoodFit /* <--- trampoline*/, FitterBase>(m_fitters, "LikelihoodFit")
145 .def(py::init<manager* const>())
146
147 .def(
148 "caluclate_chi2",
149 [](LikelihoodFit &self, const std::vector<double> &parameterVals)
150 {
151 return self.CalcChi2(parameterVals.data());
152 },
153 "Get the Chi2 calculation over all included samples and syst objects for the specified parameter_values \n\
154 :param parameter_valuse: The location to evaluate the chi2 at.",
155 py::arg("parameter_values")
156 )
157
158 .def(
159 "get_n_params",
161 "Get The total number of parameters across all known covariance objects associated with this LikelihoodFit object."
162 )
163 ; // end of LikelihoodFit class binding
164
165 py::class_<MinuitFit, LikelihoodFit>(m_fitters, "MinuitFit")
166 .def(py::init<manager* const>())
167
168 ; // end of MinuitFit class binding
169
170 py::class_<PSO, LikelihoodFit>(m_fitters, "PSO")
171 .def(py::init<manager* const>())
172
173 .def(
174 "init",
175 &PSO::init,
176 "Initialise the fitter"
177 )
178
179 ; // end of PSO class binding
180
181}
Base class for implementing fitting algorithms.
Definition: FitterBase.h:23
void RunLLHScan()
Perform a 1D likelihood scan.
Definition: FitterBase.cpp:507
void AddSystObj(ParameterHandlerBase *cov)
This function adds a Covariance object to the analysis framework. The Covariance object will be utili...
Definition: FitterBase.cpp:267
void AddSampleHandler(SampleHandlerBase *sample)
This function adds a sample PDF object to the analysis framework. The sample PDF object will be utili...
Definition: FitterBase.cpp:246
virtual std::string GetName() const
Get name of class.
Definition: FitterBase.h:66
virtual void RunMCMC()=0
The specific fitting algorithm implemented in this function depends on the derived class....
void GetStepScaleBasedOnLLHScan()
LLH scan is good first estimate of step scale.
Definition: FitterBase.cpp:817
void RunSigmaVar()
Perform a 2D and 1D sigma var for all samples.
void DragRace(const int NLaps=100)
Calculates the required time for each sample or covariance object in a drag race simulation....
Definition: FitterBase.cpp:409
void Run2DLLHScan()
Perform a 2D likelihood scan.
Definition: FitterBase.cpp:866
Implementation of base Likelihood Fit class, it is mostly responsible for likelihood calculation whil...
Definition: LikelihoodFit.h:6
int GetNPars()
Get total number of params, this sums over all covariance objects.
Definition: LikelihoodFit.h:16
virtual double CalcChi2(const double *x)
Chi2 calculation over all included samples and syst objects.
void init()
Definition: PSO.cpp:50
EW: As FitterBase is an abstract base class we have to do some gymnastics to get it to get it into py...
Definition: fitters.cpp:13
EW: As LikelihoodFit is an abstract base class we have to do some gymnastics to get it to get it into...
Definition: fitters.cpp:39
void setChainLength(unsigned int L)
Set how long chain should be.
Definition: mcmc.h:19