예제 #1
0
파일: systematics.py 프로젝트: ndawe/hhntup
    def __init__(self, is_up, np=None, **kwargs):

        # *** Set up the uncertainty tools ***
        # Tag assumed: JetUncertainties-00-05-09-02
        super(JES, self).__init__(is_up, **kwargs)

        assert np in self.all_nps and hasattr(self, '_'+np)
        self.np = np
        self.run_np = getattr(self, '_' + np)

        self.jes_tool = None
        if self.year == 2011:
            self.jes_tool = MultijetJESUncertaintyProvider(
                "JES_2011/Final/MultijetJES_2011.config",
                "JES_2011/Final/InsituJES2011_17NP_ByCategory.config",
                "AntiKt4TopoLC",
                "MC11c",
                JetUncertainties.RESOURCE_PATH)
        elif self.year == 2012:
            self.jes_tool = MultijetJESUncertaintyProvider(
                "JES_2012/Moriond2013/MultijetJES_2012.config",
                #"JES_2012/Moriond2013/InsituJES2012_AllNuisanceParameters.config",
                "JES_2012/Moriond2013/InsituJES2012_20NP_ByCategory.config",
                "AntiKt4TopoLC",
                "MC12a",
                JetUncertainties.RESOURCE_PATH)
        else:
            raise ValueError('No JES defined for year %d' % year)
예제 #2
0
    def __init__(self, is_up, np=None, **kwargs):

        # *** Set up the uncertainty tools ***
        # Tag assumed: JetUncertainties-00-05-09-02
        super(JES, self).__init__(is_up, **kwargs)

        assert np in self.all_nps and hasattr(self, '_' + np)
        self.np = np
        self.run_np = getattr(self, '_' + np)

        self.jes_tool = None
        if self.year == 2011:
            self.jes_tool = MultijetJESUncertaintyProvider(
                "JES_2011/Final/MultijetJES_2011.config",
                "JES_2011/Final/InsituJES2011_17NP_ByCategory.config",
                "AntiKt4TopoLC", "MC11c", JetUncertainties.RESOURCE_PATH)
        elif self.year == 2012:
            self.jes_tool = MultijetJESUncertaintyProvider(
                "JES_2012/Moriond2013/MultijetJES_2012.config",
                #"JES_2012/Moriond2013/InsituJES2012_AllNuisanceParameters.config",
                "JES_2012/Moriond2013/InsituJES2012_20NP_ByCategory.config",
                "AntiKt4TopoLC",
                "MC12a",
                JetUncertainties.RESOURCE_PATH)
        else:
            raise ValueError('No JES defined for year %d' % year)
예제 #3
0
파일: systematics.py 프로젝트: ndawe/hhntup
class JES(JetSystematic):
    # All 14 NPs in the 2013 recommendation
    all_nps = [
        'Statistical',
        'Modelling',
        'Detector',
        'Mixed',
        'EtaModelling',
        'EtaMethod',
        'PURho',
        'PUPt',
        'PUNPV',
        'PUMu',
        'FlavComp',
        'FlavResp',
        'BJet',
        'NonClosure',
    ]

    def __init__(self, is_up, np=None, **kwargs):

        # *** Set up the uncertainty tools ***
        # Tag assumed: JetUncertainties-00-05-09-02
        super(JES, self).__init__(is_up, **kwargs)

        assert np in self.all_nps and hasattr(self, '_'+np)
        self.np = np
        self.run_np = getattr(self, '_' + np)

        self.jes_tool = None
        if self.year == 2011:
            self.jes_tool = MultijetJESUncertaintyProvider(
                "JES_2011/Final/MultijetJES_2011.config",
                "JES_2011/Final/InsituJES2011_17NP_ByCategory.config",
                "AntiKt4TopoLC",
                "MC11c",
                JetUncertainties.RESOURCE_PATH)
        elif self.year == 2012:
            self.jes_tool = MultijetJESUncertaintyProvider(
                "JES_2012/Moriond2013/MultijetJES_2012.config",
                #"JES_2012/Moriond2013/InsituJES2012_AllNuisanceParameters.config",
                "JES_2012/Moriond2013/InsituJES2012_20NP_ByCategory.config",
                "AntiKt4TopoLC",
                "MC12a",
                JetUncertainties.RESOURCE_PATH)
        else:
            raise ValueError('No JES defined for year %d' % year)

    def _Statistical(self, jet, event):
        # HACK: use only stat1 for now
        uncs = [0.]
        #for i in range(3):
        uncs[0] = self.jes_tool.getRelUncertComponent(
            "EffectiveNP_Statistical1", jet.pt, jet.eta)
        return uncs

    def _Modelling(self, jet, event):
        # HACK: use only modelling1 for now
        uncs = [0.]
        #for i in range(4):
        uncs[0] = self.jes_tool.getRelUncertComponent(
            "EffectiveNP_Modelling1", jet.pt, jet.eta)
        return uncs

    def _Detector(self, jet, event):
        # HACK: use only detector1 for now
        uncs = [0.]
        #for i in range(3):
        uncs[0] = self.jes_tool.getRelUncertComponent(
            "EffectiveNP_Detector1", jet.pt, jet.eta)
        return uncs

    def _Mixed(self, jet, event):
        uncs = [0., 0.]
        for i in range(2):
            uncs[i] = self.jes_tool.getRelUncertComponent("EffectiveNP_Mixed%d" % (i+1), jet.pt, jet.eta)
        return uncs

    def _EtaModelling(self, jet, event):
        return [ self.jes_tool.getRelUncertComponent("EtaIntercalibration_Modelling", jet.pt, jet.eta) ]

    def _EtaMethod(self, jet, event):
        return [ self.jes_tool.getRelUncertComponent("EtaIntercalibration_StatAndMethod", jet.pt, jet.eta) ]

    def _PURho(self, jet, event):
        return [ self.jes_tool.getRelPileupRhoTopology(jet.pt, jet.eta) ]

    def _PUPt(self, jet, event):
        return [ self.jes_tool.getRelPileupPtTerm(jet.pt, jet.eta, self.tree.nvtxjets, event.averageIntPerXing) ]

    def _PUNPV(self, jet, event):
        return [ self.jes_tool.getRelNPVOffsetTerm(jet.pt, jet.eta, self.tree.nvtxjets) ]

    def _PUMu(self, jet, event):
        return [ self.jes_tool.getRelMuOffsetTerm(jet.pt, jet.eta, event.averageIntPerXing) ]

    def _FlavComp(self, jet, event):
        uncs = [0.]
        is_b = jet.flavor_truth_dRminToB < 0.4
        if not is_b:
            uncs[0] = self.jes_tool.getRelFlavorCompUncert(jet.pt, jet.eta, True)
        return uncs

    def _FlavResp(self, jet, event):
        uncs = [0.]
        is_b = jet.flavor_truth_dRminToB < 0.4
        if not is_b:
            uncs[0] = self.jes_tool.getRelFlavorResponseUncert(jet.pt, jet.eta)
        return uncs

    def _BJet(self, jet, event):
        uncs = [0.]
        is_b = jet.flavor_truth_dRminToB < 0.4
        if not is_b:
            uncs[0] = self.jes_tool.getRelBJESUncert(jet.pt, jet.eta)
        return uncs

    def _NonClosure(self, jet, event):
        uncs = [0., 0.]
        uncs[0] = self.jes_tool.getRelUncertComponent("SingleParticle_HighPt", jet.pt, jet.eta)
        uncs[1] = self.jes_tool.getRelUncertComponent("RelativeNonClosure_Pythia8", jet.pt, jet.eta)
        # TODO: If AFII, use "RelativeNonClosure_AFII" instead
        return uncs

    @JetSystematic.set
    def run(self, jet, event):
        # Safest to assume nothing about the uncertainties on soft jets.
        # These will go into SoftJets anyhow, and so the JES systematics
        # aren't used.
        shift = 0.
        # OLD 2011 code
        #if self.year == 2011:
        #     if jet.pt > 20e3 and jet.pt < 7000e3 and abs(jet.eta) < 4.5:
        #
        #         # delta R cut needed to apply close-by jets uncertainty
        #         drmin=9999
        #         for otherjet in event.jets:
        #             if otherjet.emscale_pt > 7000:
        #                 if jet.index != otherjet.index:
        #                     dr = utils.dR(jet.eta, jet.phi,
        #                                   otherjet.eta,
        #                                   otherjet.phi)
        #                     if dr < drmin:
        #                         drmin = dr
        #
        #         # TODO: shift is symmetric (is_up argument is not needed)
        #         if self.is_up:
        #             shift = self.jes_tool.getRelUncert(
        #                     jet.pt,
        #                     jet.eta,
        #                     drmin,
        #                     True, # is up
        #                     self.sys_util.nvtxjets,
        #                     event.averageIntPerXing,
        #                     False) # is b jet
        #         else:
        #             shift = -1 * self.jes_tool.getRelUncert(
        #                     jet.pt,
        #                     jet.eta,
        #                     drmin,
        #                     False, # is up
        #                     self.sys_util.nvtxjets,
        #                     event.averageIntPerXing,
        #                     False) # is b jet
        if jet.pt > 15e3 and jet.pt < 7000e3 and abs(jet.eta) < 4.5:

            uncs = self.run_np(jet, event)
            if len(uncs) > 1:
                unc = 0.
                for u in uncs:
                    unc += u**2.
                unc = unc**0.5
            else:
                unc = uncs[0]

            if abs(max(uncs)) < abs(min(uncs)):
                unc = -unc; # set total to sign of max
            if self.is_up:
                shift = unc;
            else:
                shift = -unc;
        jet.pt *= 1. + shift
예제 #4
0
class JES(JetSystematic):
    # All 14 NPs in the 2013 recommendation
    all_nps = [
        'Statistical',
        'Modelling',
        'Detector',
        'Mixed',
        'EtaModelling',
        'EtaMethod',
        'PURho',
        'PUPt',
        'PUNPV',
        'PUMu',
        'FlavComp',
        'FlavResp',
        'BJet',
        'NonClosure',
    ]

    def __init__(self, is_up, np=None, **kwargs):

        # *** Set up the uncertainty tools ***
        # Tag assumed: JetUncertainties-00-05-09-02
        super(JES, self).__init__(is_up, **kwargs)

        assert np in self.all_nps and hasattr(self, '_' + np)
        self.np = np
        self.run_np = getattr(self, '_' + np)

        self.jes_tool = None
        if self.year == 2011:
            self.jes_tool = MultijetJESUncertaintyProvider(
                "JES_2011/Final/MultijetJES_2011.config",
                "JES_2011/Final/InsituJES2011_17NP_ByCategory.config",
                "AntiKt4TopoLC", "MC11c", JetUncertainties.RESOURCE_PATH)
        elif self.year == 2012:
            self.jes_tool = MultijetJESUncertaintyProvider(
                "JES_2012/Moriond2013/MultijetJES_2012.config",
                #"JES_2012/Moriond2013/InsituJES2012_AllNuisanceParameters.config",
                "JES_2012/Moriond2013/InsituJES2012_20NP_ByCategory.config",
                "AntiKt4TopoLC",
                "MC12a",
                JetUncertainties.RESOURCE_PATH)
        else:
            raise ValueError('No JES defined for year %d' % year)

    def _Statistical(self, jet, event):
        # HACK: use only stat1 for now
        uncs = [0.]
        #for i in range(3):
        uncs[0] = self.jes_tool.getRelUncertComponent(
            "EffectiveNP_Statistical1", jet.pt, jet.eta)
        return uncs

    def _Modelling(self, jet, event):
        # HACK: use only modelling1 for now
        uncs = [0.]
        #for i in range(4):
        uncs[0] = self.jes_tool.getRelUncertComponent("EffectiveNP_Modelling1",
                                                      jet.pt, jet.eta)
        return uncs

    def _Detector(self, jet, event):
        # HACK: use only detector1 for now
        uncs = [0.]
        #for i in range(3):
        uncs[0] = self.jes_tool.getRelUncertComponent("EffectiveNP_Detector1",
                                                      jet.pt, jet.eta)
        return uncs

    def _Mixed(self, jet, event):
        uncs = [0., 0.]
        for i in range(2):
            uncs[i] = self.jes_tool.getRelUncertComponent(
                "EffectiveNP_Mixed%d" % (i + 1), jet.pt, jet.eta)
        return uncs

    def _EtaModelling(self, jet, event):
        return [
            self.jes_tool.getRelUncertComponent(
                "EtaIntercalibration_Modelling", jet.pt, jet.eta)
        ]

    def _EtaMethod(self, jet, event):
        return [
            self.jes_tool.getRelUncertComponent(
                "EtaIntercalibration_StatAndMethod", jet.pt, jet.eta)
        ]

    def _PURho(self, jet, event):
        return [self.jes_tool.getRelPileupRhoTopology(jet.pt, jet.eta)]

    def _PUPt(self, jet, event):
        return [
            self.jes_tool.getRelPileupPtTerm(jet.pt, jet.eta,
                                             self.tree.nvtxjets,
                                             event.averageIntPerXing)
        ]

    def _PUNPV(self, jet, event):
        return [
            self.jes_tool.getRelNPVOffsetTerm(jet.pt, jet.eta,
                                              self.tree.nvtxjets)
        ]

    def _PUMu(self, jet, event):
        return [
            self.jes_tool.getRelMuOffsetTerm(jet.pt, jet.eta,
                                             event.averageIntPerXing)
        ]

    def _FlavComp(self, jet, event):
        uncs = [0.]
        is_b = jet.flavor_truth_dRminToB < 0.4
        if not is_b:
            uncs[0] = self.jes_tool.getRelFlavorCompUncert(
                jet.pt, jet.eta, True)
        return uncs

    def _FlavResp(self, jet, event):
        uncs = [0.]
        is_b = jet.flavor_truth_dRminToB < 0.4
        if not is_b:
            uncs[0] = self.jes_tool.getRelFlavorResponseUncert(jet.pt, jet.eta)
        return uncs

    def _BJet(self, jet, event):
        uncs = [0.]
        is_b = jet.flavor_truth_dRminToB < 0.4
        if not is_b:
            uncs[0] = self.jes_tool.getRelBJESUncert(jet.pt, jet.eta)
        return uncs

    def _NonClosure(self, jet, event):
        uncs = [0., 0.]
        uncs[0] = self.jes_tool.getRelUncertComponent("SingleParticle_HighPt",
                                                      jet.pt, jet.eta)
        uncs[1] = self.jes_tool.getRelUncertComponent(
            "RelativeNonClosure_Pythia8", jet.pt, jet.eta)
        # TODO: If AFII, use "RelativeNonClosure_AFII" instead
        return uncs

    @JetSystematic.set
    def run(self, jet, event):
        # Safest to assume nothing about the uncertainties on soft jets.
        # These will go into SoftJets anyhow, and so the JES systematics
        # aren't used.
        shift = 0.
        # OLD 2011 code
        #if self.year == 2011:
        #     if jet.pt > 20e3 and jet.pt < 7000e3 and abs(jet.eta) < 4.5:
        #
        #         # delta R cut needed to apply close-by jets uncertainty
        #         drmin=9999
        #         for otherjet in event.jets:
        #             if otherjet.emscale_pt > 7000:
        #                 if jet.index != otherjet.index:
        #                     dr = utils.dR(jet.eta, jet.phi,
        #                                   otherjet.eta,
        #                                   otherjet.phi)
        #                     if dr < drmin:
        #                         drmin = dr
        #
        #         # TODO: shift is symmetric (is_up argument is not needed)
        #         if self.is_up:
        #             shift = self.jes_tool.getRelUncert(
        #                     jet.pt,
        #                     jet.eta,
        #                     drmin,
        #                     True, # is up
        #                     self.sys_util.nvtxjets,
        #                     event.averageIntPerXing,
        #                     False) # is b jet
        #         else:
        #             shift = -1 * self.jes_tool.getRelUncert(
        #                     jet.pt,
        #                     jet.eta,
        #                     drmin,
        #                     False, # is up
        #                     self.sys_util.nvtxjets,
        #                     event.averageIntPerXing,
        #                     False) # is b jet
        if jet.pt > 15e3 and jet.pt < 7000e3 and abs(jet.eta) < 4.5:

            uncs = self.run_np(jet, event)
            if len(uncs) > 1:
                unc = 0.
                for u in uncs:
                    unc += u**2.
                unc = unc**0.5
            else:
                unc = uncs[0]

            if abs(max(uncs)) < abs(min(uncs)):
                unc = -unc
                # set total to sign of max
            if self.is_up:
                shift = unc
            else:
                shift = -unc
        jet.pt *= 1. + shift