def do_upper_limits(verbose=False, prefix='upperlim'):
    from scharmfit import utils
    utils.load_susyfit()
    from ROOT import ConfigMgr, Util
    mgr = ConfigMgr.getInstance()
    mgr.m_outputFileName = prefix + '.root'
    mgr.m_nToys = 1
    mgr.m_calcType = 2
    mgr.m_testStatType = 3
    mgr.m_useCLs = True
    mgr.m_nPoints = -1
    if verbose:
        mgr.doUpperLimitAll()
    else:
        with OutputFilter():
            mgr.doUpperLimitAll()
Exemple #2
0
    def do_histfitter_magic(self, input_workspace, verbose=False):
        """
        Here we break into histfitter voodoo. The functions here are pulled
        out of the HistFitter.py script.
        """
        from scharmfit import utils
        utils.load_susyfit()
        from ROOT import ConfigMgr, Util
        mgr = ConfigMgr.getInstance()
        mgr.initialize()
        mgr.setNToys(1)

        # the fit configs seem to need unique names, use random numbers
        import random
        fc_number = 0
        # such a hack... but this is to check if the fit config is unique
        with OutputFilter():
            while mgr.getFitConfig(str(fc_number)):
                fc_number += 1
        fc = mgr.addFitConfig(str(fc_number))
        fc.m_inputWorkspaceFileName = input_workspace
        fc.m_signalSampleName = basename(input_workspace).split('.')[0]

        for chan in self.channels:
            if chan == 'signal':
                continue
            fc.m_bkgConstrainChannels.push_back(chan)
        fc.m_signalChannels.push_back('signal')

        accept_strings = {'ERROR:','WARNING:'} if not verbose else {''}
        # this snapshot error appears to be a hackish check, can ignore
        veto = {'snapshot_paramsVals_initial'}

        with OutputFilter(accept_strings=accept_strings, veto_strings=veto):
            Util.GenerateFitAndPlot(
                fc.m_name,
                "ana_name",
                False, #drawBeforeFit,
                False, #drawAfterFit,
                False, #drawCorrelationMatrix,
                False, #drawSeparateComponents,
                False, #drawLogLikelihood,
                False, #runMinos,
                "", #minosPars
                )
    def do_histfitter_magic(self, ws_dir, verbose=False):
        """
        Here we break into histfitter voodoo. The functions here are pulled
        out of the HistFitter.py script. The input workspace is the one
        produced by the `save_workspace` function above.
        """
        from scharmfit import utils
        utils.load_susyfit()
        from ROOT import ConfigMgr, Util

        ws_name = self._get_ws_name()
        ws_path = join(ws_dir, ws_name)

        # The histfitter authors somehow thought that creating a
        # singleton configuration manager was good design. Maybe it is
        # when you're wrapping ROOT code (with all its global variable
        # glory). In any case, most of the hacking below is to work
        # around this.
        mgr = ConfigMgr.getInstance()
        mgr.initialize()
        mgr.setNToys(1)         # make configurable?

        # such a hack... but this is to check if the fit config is unique
        fc_number = 0
        with OutputFilter():
            # name fig configs '0', '1', '2', '3', etc...
            while mgr.getFitConfig(str(fc_number)):
                fc_number += 1
        fc = mgr.addFitConfig(str(fc_number))

        # had to dig pretty deep into the HistFitter code to find this
        # stuff, but this seems to be how it sets things up.
        fc.m_inputWorkspaceFileName = ws_path
        # HistFitter name convention seems to be that the background only fit
        # is called "Bkg" or "" (empty string).
        fc.m_signalSampleName = self._signal_point or ''

        # HistFitter doesn't seem to distinguish between background
        # and signal channels. The only possible difference is a
        # commented out line that sets 'lumiConst' to true if there
        # are no signal channels. May be worth looking into...
        for chan in self._channels:
            if chan not in self._non_fit_regions:
                fc.m_bkgConstrainChannels.push_back(chan)
            # fc.m_signalChannels.push_back(chan)

        accept_strings = {'ERROR:','WARNING:'} if not verbose else {''}
        # this snapshot error appears to be a hackish check, can ignore
        veto = {'snapshot_paramsVals_initial'}

        with OutputFilter(accept_strings=accept_strings, veto_strings=veto):
            Util.GenerateFitAndPlot(
                fc.m_name,
                "ana_name",
                False, #drawBeforeFit,
                False, #drawAfterFit,
                False, #drawCorrelationMatrix,
                False, #drawSeparateComponents,
                False, #drawLogLikelihood,
                False, #runMinos,
                "", #minosPars
                )