def get_jo(mass=125, mode='VBF'):
    """
    Determine width from yellowhiggs report
    and output a jo file for a given m_H
    """
    best_mass = sorted(masses_yh, key=lambda m: abs(m - float(mass)))[0]
    width = br(best_mass, '2boson')[0]
    print '%s: Mass = %s; Width = %s (calculated with m_H = %s)' % (mode, mass, width, best_mass)
    if mode == 'VBF':
        return vbf.format(mass, width)
    elif mode == 'gg':
        return ggh.format(mass, width)
    else:
        raise RuntimeError('Wrong mode !')
Example #2
0
def get_jo(mass=125, mode='VBF'):
    """
    Determine width from yellowhiggs report
    and output a jo file for a given m_H
    """
    best_mass = sorted(masses_yh, key=lambda m: abs(m - float(mass)))[0]
    width = br(best_mass, '2boson')[0]
    print '%s: Mass = %s; Width = %s (calculated with m_H = %s)' % (
        mode, mass, width, best_mass)
    if mode == 'VBF':
        return vbf.format(mass, width)
    elif mode == 'gg':
        return ggh.format(mass, width)
    else:
        raise RuntimeError('Wrong mode !')
Example #3
0
def BR_YR3(mass, productionmode):
    if productionmode in ("ZH", "ttH") and mass < 300:
        result = BR_fromoldspreadsheet(productionmode, mass)
        if 120 <= mass <= 130:
            result *= YR4data_BR_ZZ[mass] / yellowhiggs.br(mass, "ZZ")[0]
        if productionmode == "ZH":
            result *= filterefficiencyZH[
                mass].nominal_value / oldfilterefficiencyZH
        return result

    mass = int(str(mass))
    try:
        result = yellowhiggs.br(mass, "llll(e,mu,tau)")[0]
    except ValueError:
        return .5 * (BR_YR3(mass + 1, productionmode) +
                     BR_YR3(mass - 1, productionmode))

    if productionmode in ("ggH", "VBF", "WplusH", "WminusH"):
        if 120 <= mass <= 130:
            result *= YR4data_BR_4l[mass] / yellowhiggs.br(
                mass, "llll(e,mu,tau)")[0]
        return result

    if 120 <= mass <= 130: assert False

    #need to get ZZ2l2x BR
    #from the comment here: https://github.com/CJLST/HHZZbb/blob/454fffb5842f470e71e89348a6de7a8d30f4a813/AnalysisStep/test/prod/samples_2016_MC.csv#L5-L6
    #it doesn't say how to get BR(H->ZZ*->2L2nu) or BR(H->WW*->2L2nu)
    #llnunu  = ZZllnunu + WWlnulnu
    #        = ZZllnunu + 9*WWemununu
    #        = ZZllnunu + 9*emununu

    result += yellowhiggs.br(mass, "llqq(e,mu,tau)")[0] + yellowhiggs.br(
        mass,
        "llnunu(e,mu,tau)")[0] - 9 * yellowhiggs.br(mass, "enuemunumu")[0]
    if productionmode == "ZH":
        result *= filterefficiencyZH[mass].nominal_value
    elif productionmode == "ttH":
        result *= filterefficiencyttH[mass].nominal_value
    else:
        assert False, productionmode

    return result
Example #4
0
    def histfactory(self, sample, category, systematics=False,
                    rec=None, weights=None, mva=False,
                    uniform=False, nominal=None):
        if not systematics:
            return
        if len(self.modes) != 1:
            raise TypeError(
                'histfactory sample only valid for single production mode')
        if len(self.masses) != 1:
            raise TypeError(
                'histfactory sample only valid for single mass point')

        # isolation systematic
        sample.AddOverallSys(
            'ATLAS_ANA_HH_{0:d}_Isolation'.format(self.year),
            1. - 0.06,
            1. + 0.06)

        mode = self.modes[0]

        if mode in ('Z', 'W'):
            _uncert_mode = 'VH'
        else:
            _uncert_mode = self.MODES_WORKSPACE[mode]

        if self.year == 2011:
            energy = 7
        elif self.year == 2012:
            energy = 8
        else:
            raise ValueError(
                "collision energy is unknown for year {0:d}".format(self.year))

        # QCD_SCALE
        for qcd_scale_term, qcd_scale_mode, qcd_scale_category, values in self.QCD_SCALE:
            if qcd_scale_mode == _uncert_mode and qcd_scale_category == category.name:
                high, low = map(float, values.split('/'))
                sample.AddOverallSys(qcd_scale_term, low, high)

        # UE UNCERTAINTY
        for ue_term, ue_mode, ue_category, values in self.UE_UNCERT:
            if ue_mode == _uncert_mode and ue_category == category.name:
                high, low = map(float, values.split('/'))
                sample.AddOverallSys(ue_term, low, high)

        # PDF ACCEPTANCE UNCERTAINTY (OverallSys)
        for pdf_term, pdf_mode, pdf_category, values in self.PDF_ACCEPT_NORM_UNCERT:
            if pdf_mode == _uncert_mode and pdf_category == category.name:
                high, low = map(float, values.split('/'))
                sample.AddOverallSys(pdf_term, low, high)

        sample_nom = sample.hist

        # PDF ACCEPTANCE UNCERTAINTY (HistoSys) ONLY FOR MVA
        if mva:
            for pdf_term, pdf_mode, pdf_category, hist_names in self.PDF_ACCEPT_SHAPE_UNCERT:
                if pdf_mode == _uncert_mode and pdf_category == category.name:
                    high_name, low_name = hist_names.format(energy).split('/')
                    high_shape, low_shape = self.PDF_ACCEPT_file[high_name], self.PDF_ACCEPT_file[low_name]
                    if len(high_shape) != len(sample.hist):
                        log.warning("skipping pdf acceptance shape systematic "
                                    "since histograms are not compatible")
                        continue
                    high = sample_nom.Clone(shallow=True, name=sample_nom.name + '_{0}_UP'.format(pdf_term))
                    low = sample_nom.Clone(shallow=True, name=sample_nom.name + '_{0}_DOWN'.format(pdf_term))
                    high *= high_shape
                    low *= low_shape
                    histsys = histfactory.HistoSys(
                        pdf_term, low=low, high=high)
                    sample.AddHistoSys(histsys)

        #mixing Norms
        if self.SM:
            log.info('adding norm factor')
            sample.AddNormFactor('ATLAS_epsilon', 1., -200., 200., False)
        elif self.BSM:
            log.info('adding norm factor')
            sample.AddNormFactor('ATLAS_epsilon_rejected', 1., -200., 200., False)
        else:
            log.info('no norms for {0}'.format(self.name))



        # BR_tautau
        _, (br_up, br_down) = yellowhiggs.br(
            self.mass, 'tautau', error_type='factor')
        sample.AddOverallSys('ATLAS_BR_tautau', br_down, br_up)

        # <NormFactor Name="mu_BR_tautau" Val="1" Low="0" High="200" />
        sample.AddNormFactor('mu_BR_tautau', 1., 0., 200., True)

        #mu_XS[energy]_[mode]
        #_, (xs_up, xs_down) = yellowhiggs.xs(
        #    energy, self.mass, self.MODES_DICT[self.mode][0],
        #    error_type='factor')
        #sample.AddOverallSys(
        #    'mu_XS{0:d}_{1}'.format(energy, self.MODES_WORKSPACE[self.mode]),
        #    xs_down, xs_up)
        sample.AddNormFactor(
            'mu_XS{0:d}_{1}'.format(energy, self.MODES_WORKSPACE[self.mode]),
            1., 0., 200., True)

        # https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/HSG4Uncertainties
        # pdf uncertainty
        if mode == 'gg':
            if energy == 8:
                sample.AddOverallSys('pdf_Higgs_gg', 0.93, 1.08)
            else: # 7 TeV
                sample.AddOverallSys('pdf_Higgs_gg', 0.92, 1.08)
        else:
            if energy == 8:
                sample.AddOverallSys('pdf_Higgs_qq', 0.97, 1.03)
            else: # 7 TeV
                sample.AddOverallSys('pdf_Higgs_qq', 0.98, 1.03)

        # EWK NLO CORRECTION FOR VBF ONLY
        if mode == 'VBF':
            sample.AddOverallSys('NLO_EW_Higgs', 0.98, 1.02)

        # QCDscale_ggH3in HistoSys ONLY FOR MVA
        # also see ggH3in script
        if mva and mode == 'gg' and category.name == 'vbf':
            Rel_Error_2j = 0.215
            Error_exc = 0.08613046469238815 # Abs error on the exclusive xsec
            xsec_exc = 0.114866523583739 # Exclusive Xsec
            Error_3j = sqrt(Error_exc**2 - (Rel_Error_2j*xsec_exc)**2)
            rel_error = Error_3j / xsec_exc

            dphi = rec['true_dphi_jj_higgs_no_overlap']
            scores = rec['classifier']

            idx_2j = ((pi - dphi) < 0.2) & (dphi >= 0)
            idx_3j = ((pi - dphi) >= 0.2) & (dphi >= 0)

            # get normalization factor
            dphi_2j = weights[idx_2j].sum()
            dphi_3j = weights[idx_3j].sum()

            weight_up = np.ones(len(weights))
            weight_dn = np.ones(len(weights))

            weight_up[idx_2j] -= (dphi_3j / dphi_2j) * rel_error
            weight_dn[idx_2j] += (dphi_3j / dphi_2j) * rel_error

            weight_up[idx_3j] += rel_error
            weight_dn[idx_3j] -= rel_error

            weight_up *= weights
            weight_dn *= weights

            up_hist = nominal.clone(shallow=True, name=sample_nom.name + '_QCDscale_ggH3in_UP')
            up_hist.Reset()
            dn_hist = nominal.clone(shallow=True, name=sample_nom.name + '_QCDscale_ggH3in_DOWN')
            dn_hist.Reset()

            fill_hist(up_hist, scores, weight_up)
            fill_hist(dn_hist, scores, weight_dn)

            if uniform:
                up_hist = uniform_hist(up_hist)
                dn_hist = uniform_hist(dn_hist)

            shape = histfactory.HistoSys('QCDscale_ggH3in',
                low=dn_hist,
                high=up_hist)
            norm, shape = histfactory.split_norm_shape(shape, sample_nom)
            sample.AddHistoSys(shape)
for more information.

Author: Evan K. Friis, UW Madison

'''

from datacommon import square, cube, quad, picobarns, \
        br_w_leptons, br_z_leptons, query_cli, femtobarns

from data8TeV import datadefs as datadefs52

from string import Template

try:
      from yellowhiggs import xs, br, xsbr
      br(130.,'WW')
except:
      #print "warning: yellowhiggs error"
      #define / override functions to avoid crashes
      def br(*args, **kwargs):
            return -99
      def xs(*args, **kwargs):
            return -99, (-99, 99)
      def xsbr(*args, **kwargs):
            return -99, (-99, 99)


# Figure this out later.
data_name_map = {}

datadefs = {
for more information.

Author: Evan K. Friis, UW Madison

'''

from datacommon import square, cube, quad, picobarns, \
        br_w_leptons, br_z_leptons, query_cli, femtobarns

from data8TeV import datadefs as datadefs52

from string import Template

try:
      from yellowhiggs import xs, br, xsbr
      br(130.,'WW')
except:
      #print "warning: yellowhiggs error"
      #define / override functions to avoid crashes
      def br(*args, **kwargs):
            return -99
      def xs(*args, **kwargs):
            return -99, (-99, 99)
      def xsbr(*args, **kwargs):
            return -99, (-99, 99)


# Figure this out later.
data_name_map = {}

datadefs = {
Example #7
0
for more information.

Author: Evan K. Friis, UW Madison

'''

from datacommon import square, cube, quad, picobarns, \
        br_w_leptons, br_z_leptons, query_cli, femtobarns

from data8TeV import datadefs as datadefs52

from string import Template

try:
    from yellowhiggs import xs, br, xsbr
    br(130., 'WW')
except:
    #print "warning: yellowhiggs error"
    #define / override functions to avoid crashes
    def br(*args, **kwargs):
        return -99

    def xs(*args, **kwargs):
        return -99, (-99, 99)

    def xsbr(*args, **kwargs):
        return -99, (-99, 99)


# Figure this out later.
data_name_map = {}
Example #8
0
File: higgs.py Project: qbuat/htt
    def histfactory(self, sample, category, systematics=False):
        if not systematics:
            return
        if len(self.modes) != 1:
            raise TypeError(
                'histfactory sample only valid for single production mode')
        if len(self.masses) != 1:
            raise TypeError(
                'histfactory sample only valid for single mass point')
        mode = self.modes[0]

        if mode in ('Z', 'W'):
            _qcd_scale_mode = 'VH'
        else:
            _qcd_scale_mode = self.MODES_WORKSPACE[mode]

        # QCD_SCALE
        for qcd_scale_term, qcd_scale_mode, qcd_scale_category, values in self.QCD_SCALE:
            if qcd_scale_mode == _qcd_scale_mode and qcd_scale_category.lower() in category.name.lower():
                high, low = map(float, values.split('/'))
                sample.AddOverallSys(qcd_scale_term, low, high)

        # GEN_QMASS
        for qmass_term, qmass_mode, qmass_category, values in self.GEN_QMASS:
            if qmass_mode == _qcd_scale_mode and qmass_category.lower() in category.name.lower():
                high, low = map(float, values.split('/'))
                sample.AddOverallSys(qmass_term, low, high)

        # BR_tautau
        _, (br_up, br_down) = yellowhiggs.br(
            self.mass, 'tautau', error_type='factor')
        sample.AddOverallSys('ATLAS_BR_tautau', br_down, br_up)

        # <NormFactor Name="mu_BR_tautau" Val="1" Low="0" High="200" />
        sample.AddNormFactor('mu_BR_tautau', 1., 0., 200., True)

        if self.year == 2011:
            energy = 7
        elif self.year == 2012:
            energy = 8
        else:
            raise ValueError(
                "collision energy is unknown for year {0:d}".format(self.year))

        #mu_XS[energy]_[mode]
        #_, (xs_up, xs_down) = yellowhiggs.xs(
        #    energy, self.mass, self.MODES_DICT[self.mode][0],
        #    error_type='factor')
        #sample.AddOverallSys(
        #    'mu_XS{0:d}_{1}'.format(energy, self.MODES_WORKSPACE[self.mode]),
        #    xs_down, xs_up)
        sample.AddNormFactor(
            'mu_XS{0:d}_{1}'.format(energy, self.MODES_WORKSPACE[self.mode]),
            1., 0., 200., True)

        # https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/HSG4Uncertainties
        # underlying event uncertainty in the VBF category
        if 'vbf' in category.name.lower():
            if mode == 'gg':
                sample.AddOverallSys('ATLAS_UE_gg', 0.7, 1.3)
            elif mode == 'VBF':
                sample.AddOverallSys('ATLAS_UE_qq', 0.94, 1.06)

        # pdf uncertainty
        if mode == 'gg':
            if energy == 8:
                sample.AddOverallSys('pdf_Higgs_gg', 0.93, 1.08)
            else: # 7 TeV
                sample.AddOverallSys('pdf_Higgs_gg', 0.92, 1.08)
        else:
            if energy == 8:
                sample.AddOverallSys('pdf_Higgs_qq', 0.97, 1.03)
            else: # 7 TeV
                sample.AddOverallSys('pdf_Higgs_qq', 0.98, 1.03)
for more information.

Author: Evan K. Friis, UW Madison

"""

from datacommon import square, cube, quad, picobarns, br_w_leptons, br_z_leptons, query_cli

from data8TeV import datadefs as datadefs52

from string import Template

try:
    from yellowhiggs import xs, br, xsbr

    br(130.0, "WW")
except:
    # print "warning: yellowhiggs error"
    # define / override functions to avoid crashes
    def br(*args, **kwargs):
        return -99

    def xs(*args, **kwargs):
        return -99, (-99, 99)

    def xsbr(*args, **kwargs):
        return -99, (-99, 99)


# Figure this out later.
data_name_map = {}
Example #10
0
    def histfactory(self,
                    sample,
                    category,
                    systematics=False,
                    rec=None,
                    weights=None,
                    mva=False,
                    uniform=False,
                    nominal=None):
        if not systematics:
            return
        if len(self.modes) != 1:
            raise TypeError(
                'histfactory sample only valid for single production mode')
        if len(self.masses) != 1:
            raise TypeError(
                'histfactory sample only valid for single mass point')

        # isolation systematic
        sample.AddOverallSys('ATLAS_ANA_HH_{0:d}_Isolation'.format(self.year),
                             1. - 0.06, 1. + 0.06)

        mode = self.modes[0]

        if mode in ('Z', 'W'):
            _uncert_mode = 'VH'
        else:
            _uncert_mode = self.MODES_WORKSPACE[mode]

        if self.year == 2011:
            energy = 7
        elif self.year == 2012:
            energy = 8
        else:
            raise ValueError(
                "collision energy is unknown for year {0:d}".format(self.year))

        # QCD_SCALE
        for qcd_scale_term, qcd_scale_mode, qcd_scale_category, values in self.QCD_SCALE:
            if qcd_scale_mode == _uncert_mode and qcd_scale_category == category.name:
                high, low = map(float, values.split('/'))
                sample.AddOverallSys(qcd_scale_term, low, high)

        # UE UNCERTAINTY
        for ue_term, ue_mode, ue_category, values in self.UE_UNCERT:
            if ue_mode == _uncert_mode and ue_category == category.name:
                high, low = map(float, values.split('/'))
                sample.AddOverallSys(ue_term, low, high)

        # PDF ACCEPTANCE UNCERTAINTY (OverallSys)
        for pdf_term, pdf_mode, pdf_category, values in self.PDF_ACCEPT_NORM_UNCERT:
            if pdf_mode == _uncert_mode and pdf_category == category.name:
                high, low = map(float, values.split('/'))
                sample.AddOverallSys(pdf_term, low, high)

        sample_nom = sample.hist

        # PDF ACCEPTANCE UNCERTAINTY (HistoSys) ONLY FOR MVA
        if mva:
            for pdf_term, pdf_mode, pdf_category, hist_names in self.PDF_ACCEPT_SHAPE_UNCERT:
                if pdf_mode == _uncert_mode and pdf_category == category.name:
                    high_name, low_name = hist_names.format(energy).split('/')
                    high_shape, low_shape = self.PDF_ACCEPT_file[
                        high_name], self.PDF_ACCEPT_file[low_name]
                    if len(high_shape) != len(sample.hist):
                        log.warning("skipping pdf acceptance shape systematic "
                                    "since histograms are not compatible")
                        continue
                    high = sample_nom.Clone(shallow=True,
                                            name=sample_nom.name +
                                            '_{0}_UP'.format(pdf_term))
                    low = sample_nom.Clone(shallow=True,
                                           name=sample_nom.name +
                                           '_{0}_DOWN'.format(pdf_term))
                    high *= high_shape
                    low *= low_shape
                    histsys = histfactory.HistoSys(pdf_term,
                                                   low=low,
                                                   high=high)
                    sample.AddHistoSys(histsys)

        # BR_tautau
        _, (br_up, br_down) = yellowhiggs.br(self.mass,
                                             'tautau',
                                             error_type='factor')
        sample.AddOverallSys('ATLAS_BR_tautau', br_down, br_up)

        # <NormFactor Name="mu_BR_tautau" Val="1" Low="0" High="200" />
        sample.AddNormFactor('mu_BR_tautau', 1., 0., 200., True)

        #mu_XS[energy]_[mode]
        #_, (xs_up, xs_down) = yellowhiggs.xs(
        #    energy, self.mass, self.MODES_DICT[self.mode][0],
        #    error_type='factor')
        #sample.AddOverallSys(
        #    'mu_XS{0:d}_{1}'.format(energy, self.MODES_WORKSPACE[self.mode]),
        #    xs_down, xs_up)
        sample.AddNormFactor(
            'mu_XS{0:d}_{1}'.format(energy, self.MODES_WORKSPACE[self.mode]),
            1., 0., 200., True)

        # https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/HSG4Uncertainties
        # pdf uncertainty
        if mode == 'gg':
            if energy == 8:
                sample.AddOverallSys('pdf_Higgs_gg', 0.93, 1.08)
            else:  # 7 TeV
                sample.AddOverallSys('pdf_Higgs_gg', 0.92, 1.08)
        else:
            if energy == 8:
                sample.AddOverallSys('pdf_Higgs_qq', 0.97, 1.03)
            else:  # 7 TeV
                sample.AddOverallSys('pdf_Higgs_qq', 0.98, 1.03)

        # EWK NLO CORRECTION FOR VBF ONLY
        if mode == 'VBF':
            sample.AddOverallSys('NLO_EW_Higgs', 0.98, 1.02)

        # QCDscale_ggH3in HistoSys ONLY FOR MVA
        # also see ggH3in script
        if mva and mode == 'gg' and category.name == 'vbf':
            Rel_Error_2j = 0.215
            Error_exc = 0.08613046469238815  # Abs error on the exclusive xsec
            xsec_exc = 0.114866523583739  # Exclusive Xsec
            Error_3j = sqrt(Error_exc**2 - (Rel_Error_2j * xsec_exc)**2)
            rel_error = Error_3j / xsec_exc

            dphi = rec['true_dphi_jj_higgs_no_overlap']
            scores = rec['classifier']

            idx_2j = ((pi - dphi) < 0.2) & (dphi >= 0)
            idx_3j = ((pi - dphi) >= 0.2) & (dphi >= 0)

            # get normalization factor
            dphi_2j = weights[idx_2j].sum()
            dphi_3j = weights[idx_3j].sum()

            weight_up = np.ones(len(weights))
            weight_dn = np.ones(len(weights))

            weight_up[idx_2j] -= (dphi_3j / dphi_2j) * rel_error
            weight_dn[idx_2j] += (dphi_3j / dphi_2j) * rel_error

            weight_up[idx_3j] += rel_error
            weight_dn[idx_3j] -= rel_error

            weight_up *= weights
            weight_dn *= weights

            up_hist = nominal.clone(shallow=True,
                                    name=sample_nom.name +
                                    '_QCDscale_ggH3in_UP')
            up_hist.Reset()
            dn_hist = nominal.clone(shallow=True,
                                    name=sample_nom.name +
                                    '_QCDscale_ggH3in_DOWN')
            dn_hist.Reset()

            fill_hist(up_hist, scores, weight_up)
            fill_hist(dn_hist, scores, weight_dn)

            if uniform:
                up_hist = uniform_hist(up_hist)
                dn_hist = uniform_hist(dn_hist)

            shape = histfactory.HistoSys('QCDscale_ggH3in',
                                         low=dn_hist,
                                         high=up_hist)
            norm, shape = histfactory.split_norm_shape(shape, sample_nom)
            sample.AddHistoSys(shape)
Example #11
0
You can query the information in this file at the command line.

Run

python data8TeV.py --help

for more information.

Author: Evan K. Friis, UW Madison

'''

from datacommon import square, cube, quad, picobarns, br_w_leptons, br_z_leptons, query_cli
try:
      from yellowhiggs import xs, br, xsbr
      br(130.,'WW')
except:
      #print "warning: yellowhiggs error"
      #define / override functions to avoid crashes
      def br(*args, **kwargs):
            return -99
      def xs(*args, **kwargs):
            return -99, (-99, 99)
      def xsbr(*args, **kwargs):
            return -99, (-99, 99)

# Figure this out later.
data_name_map = {}

datadefs = {
   'WJetsToLNu_PtW-100_TuneZ2star_8TeV-madgraph' : {