コード例 #1
0
    def do_the_fit(self):
        options = theta_auto.Options()
        options.set('minimizer', 'strategy', 'robust')
        self.fit_res = theta_auto.mle(
            self.model,
            "data",
            1,
            chi2=True,
            options=options,
            with_covariance=True,
        )[self.template_names[-1]]
        print self.fit_res

        par_values = {
            "beta_signal": self.fit_res["beta_signal"][0][0],
        }
        for tmplt_name in self.template_names[:-1]:
            bg_name = "bg_" + tmplt_name
            par_values[bg_name] = self.fit_res[bg_name][0][0]

        self.val_err = []
        for tmplt_name in self.template_names[:-1]:
            val = self.model.get_coeff("histo", tmplt_name).get_value(
                par_values)
            err = self.fit_res["bg_" + tmplt_name][0][1]
            self.val_err.append((val, err))
        self.val_err.append((
            self.fit_res["beta_signal"][0][0],
            abs(self.fit_res["beta_signal"][0][1])
        ))
コード例 #2
0
ファイル: limits.py プロジェクト: HeinerTholen/Varial
 def __init__(
     self,
     model_func,
     input_path='../HistoLoader',
     input_path_sys='../HistoLoaderSys',
     filter_keyfunc=None,
     hook_loaded_histos=None,
     asymptotic=True,
     limit_func=None,
     cat_key=lambda _: 'histo',  # lambda w: w.category,
     dat_key=lambda w: w.is_data or w.is_pseudo_data,
     sig_key=lambda w: w.is_signal,
     bkg_key=lambda w: w.is_background,
     sys_key=None,
     tex_table_mod_func=tex_table_mod,
     selection=None,
     pvalue_func=None,
     postfit_func=None,
     name=None,
 ):
     super(ThetaLimits, self).__init__(name)
     self.model_func = model_func
     self.input_path = input_path
     self.input_path_sys = input_path_sys
     self.filter_keyfunc = filter_keyfunc
     self.hook_loaded_histos = hook_loaded_histos
     self.cat_key = cat_key
     self.dat_key = dat_key
     self.sig_key = sig_key
     self.bkg_key = bkg_key
     self.sys_key = sys_key
     self.tex_table_mod = tex_table_mod_func
     self.model = None
     self.what = 'all'
     self.with_data = True
     self.pvalue_func = pvalue_func# or (lambda m: theta_auto.zvalue_approx(
                                   #                 m, input='data', n=1)
     self.postfit_func = postfit_func or (lambda m: theta_auto.mle(
                                                     m, input='data', n=1))
     self.selection = selection or self.name
     self.mass_points = []
     self.limit_func = limit_func or (
         theta_auto.asymptotic_cls_limits
         if asymptotic else
         lambda m: theta_auto.bayesian_limits(m, what=self.what)
     )
コード例 #3
0
 def __init__(
     self,
     model_func,
     input_path='../HistoLoader',
     input_path_sys='../HistoLoaderSys',
     filter_keyfunc=None,
     hook_loaded_histos=None,
     asymptotic=True,
     limit_func=None,
     cat_key=lambda _: 'histo',  # lambda w: w.category,
     dat_key=lambda w: w.is_data or w.is_pseudo_data,
     sig_key=lambda w: w.is_signal,
     bkg_key=lambda w: w.is_background,
     sys_key=None,
     tex_table_mod_func=tex_table_mod,
     selection=None,
     pvalue_func=None,
     postfit_func=None,
     name=None,
 ):
     super(ThetaLimits, self).__init__(name)
     self.model_func = model_func
     self.input_path = input_path
     self.input_path_sys = input_path_sys
     self.filter_keyfunc = filter_keyfunc
     self.hook_loaded_histos = hook_loaded_histos
     self.cat_key = cat_key
     self.dat_key = dat_key
     self.sig_key = sig_key
     self.bkg_key = bkg_key
     self.sys_key = sys_key
     self.tex_table_mod = tex_table_mod_func
     self.model = None
     self.what = 'all'
     self.with_data = True
     self.pvalue_func = pvalue_func  # or (lambda m: theta_auto.zvalue_approx(
     #                 m, input='data', n=1)
     self.postfit_func = postfit_func or (
         lambda m: theta_auto.mle(m, input='data', n=1))
     self.selection = selection or self.name
     self.mass_points = []
     self.limit_func = limit_func or (
         theta_auto.asymptotic_cls_limits if asymptotic else
         lambda m: theta_auto.bayesian_limits(m, what=self.what))
コード例 #4
0
 def do_the_fit(self):
     self.fit_res = theta_auto.mle(self.model, "data", 1, chi2=True)
     print self.fit_res
コード例 #5
0
import os
import theta_auto
theta_auto.config.workdir = os.getcwd()
theta_auto.config.report = theta_auto.html_report(os.path.join(theta_auto.config.workdir, 'index.html'))
theta_auto.config.theta_dir = "/afs/cern.ch/work/h/htholen/private/cmsWorkingDir/CMSSW_5_3_11_patch6/theta"
model = theta_auto.build_model_from_rootfile("ThetaHistos.root", include_mc_uncertainties=True)
model.set_signal_processes(["real"])
model.add_lognormal_uncertainty("fake_rate", 1., "fake")
res = theta_auto.mle(model, "data", 1, chi2=True)
print res
par_values = {"beta_signal":res["real"]["beta_signal"][0][0], "fake_rate":res["real"]["fake_rate"][0][0]}
bkg_val = model.get_coeff("chhadiso", "fake").get_value(par_values)
bkg_err = bkg_val * res["real"]["fake_rate"][0][1] / res["real"]["fake_rate"][0][0]
sig_val = res["real"]["beta_signal"][0][0]
sig_err = res["real"]["beta_signal"][0][1]