Exemplo n.º 1
0
def _getHIJetBuildTool(merge_param,
                       ptmin=20000.,
                       ptminFilter=20000.,
                       jet_calib='jes',
                       cluster_calib='EM',
                       hicluster_name='HICluster',
                       name=''):

    global jtm

    msg = 'Naming convention breaks with merge param %d' % merge_param
    int_merge_param = int(10 * merge_param)
    assert 10 * merge_param == int_merge_param, msg
    assert merge_param > 0.

    if not name:
        name = 'TrigAntiKt%dHIJets' % int_merge_param

    EventShapeKey = "HLT_xAOD__HIEventShapeContainer_TrigHIEventShape"
    ClusterKey = hicluster_name

    # Plug in directly tools from HIJetTools.py e.g. to avoid PseudoJetGetter which is different at HLT and for other reasons
    # -------------------------------------------------------------------------------------------------------------------------

    #jet filters
    from JetRec.JetRecConf import JetFilterTool
    jetfil5 = JetFilterTool("HLT_a" + str(int_merge_param) + "jetfil5",
                            PtMin=5000)
    jtm.add(jetfil5)
    jetfil8 = JetFilterTool("HLT_a" + str(int_merge_param) + "jetfil8",
                            PtMin=8000)
    jtm.add(jetfil8)
    jetfil20 = JetFilterTool("HLT_a" + str(int_merge_param) + "jetfil20",
                             PtMin=20000)
    jtm.add(jetfil20)

    #DR association- form element links for all clusters w/in DR of each jet
    #    DR=HIJetFlags.ClusterDRAssociation()
    #    from HIJetRec.HIJetRecConf import HIJetDRAssociationTool
    #    assoc=HIJetDRAssociationTool("HLT_a"+str(int_merge_param)+"HIJetDRAssociation")
    #    assoc.ContainerKey=ClusterKey
    #    assoc.DeltaR=DR
    #    #assoc.AssociationName="%s_DR%dAssoc" % (ClusterKey,int(10*DR))
    #    assoc.AssociationName="HLT_a"+str(int_merge_param)+"HIClDR%dAssoc" % (int(10*DR))
    #    #assoc.AssociationName="GhostTrack"
    #    jtm.add(assoc)
    #
    #    assoc_name=assoc.AssociationName

    #calculate discriminants as moments
    from HIJetRec.HIJetRecConf import HIJetMaxOverMeanTool
    max_over_mean = HIJetMaxOverMeanTool("HLT_a" + str(int_merge_param) +
                                         "HIJetMaxOverMean")
    jtm.add(max_over_mean)

    #discriminants for jet filtering
    from HIJetRec.HIJetRecConf import HIJetDiscriminatorTool
    discrim = HIJetDiscriminatorTool("HLT_a" + str(int_merge_param) +
                                     "HIJetDiscriminator")
    discrim.MaxOverMeanCut = HIJetFlags.DCutMaxOverMean()
    discrim.MinimumETMaxCut = HIJetFlags.DCutMax()
    jtm.add(discrim)
    #jtm.trigjetrecs += [discr]

    #null modulator
    #tname="HLT_a"+str(int_merge_param)+"NullUEModulator"
    #if hasattr(jtm,tname) : return getattr(jtm,tname)
    from HIJetRec.HIJetRecConf import HIUEModulatorTool
    mod_tool = HIUEModulatorTool("HLT_a" + str(int_merge_param) +
                                 "NullUEModulator")
    mod_tool.EventShapeKey = 'NULL'
    for n in [2, 3, 4]:
        setattr(mod_tool, 'DoV%d' % n, False)
    jtm.add(mod_tool)

    # subtraction
    from HIJetRec.HIJetRecConf import HIJetCellSubtractorTool
    cell_subtr = HIJetCellSubtractorTool("HLT_a" + str(int_merge_param) +
                                         "HIJetSubtractor")
    jtm.add(cell_subtr)

    # calibration
    from JetCalibTools.JetCalibToolsConf import JetCalibrationTool
    #calib_tool=JetCalibrationTool("HLT_a"+str(int_merge_param)+"HICalibTool",JetCollection="AntiKt4TopoEM",ConfigFile="JES_Full2012dataset_Preliminary_Jan13.config",CalibSequence="AbsoluteEtaJES")
    #calib_tool=JetCalibrationTool("HLT_a"+str(int_merge_param)+"HICalibTool",JetCollection="AntiKt4EMTopo",ConfigFile="JES_Full2012dataset_May2014.config",CalibSequence="JetArea_Residual_Origin_EtaJES_GSC",IsData=False)
    #calib_tool=JetCalibrationTool("HLT_a"+str(int_merge_param)+"HICalibTool",JetCollection="AntiKt4EMTopo",ConfigFile="JES_MC15Prerecommendation_April2015.config",CalibSequence="EtaJES", IsData=False)
    calib_tool = JetCalibrationTool(
        "HLT_a" + str(int_merge_param) + "HICalibTool",
        JetCollection="AntiKt4EMTopo",
        ConfigFile="JES_Full2012dataset_Preliminary_Jan13.config",
        CalibSequence="AbsoluteEtaJES",
        IsData=False)

    jtm.add(calib_tool)

    from TrigHLTJetRec.TrigHLTJetRecConfig import _getTriggerPseudoJetGetter

    # -------------------------------------------------------------------------------------------------

    a2_unsubtracted_name = "TrigAntiKt2HIJets_Unsubtracted_a" + str(
        int_merge_param)
    seed_finder = jtm.addJetFinder(
        a2_unsubtracted_name,
        "AntiKt",
        0.2,
        gettersin=[_getTriggerPseudoJetGetter(cluster_calib)],
        #modifiersin=[assoc,max_over_mean,jetfil5], # jtm.modifiersMap['HI_Unsubtr'],	# may think about TrigHI_Unsubtracted with just max_over_mean
        modifiersin=[
            max_over_mean, jetfil5
        ],  # jtm.modifiersMap['HI_Unsubtr'],	# may think about TrigHI_Unsubtracted with just max_over_mean
        #modifiersin=[assoc,max_over_mean,jetfil5,discrim], # jtm.modifiersMap['HI_Unsubtr'],	# may think about TrigHI_Unsubtracted with just max_over_mean
        ghostArea=0.0,
        isTrigger=True,
        ptmin=5000,
        ptminFilter=5000)

    seeds0_name = "TrigAntiKt2HIJets_seeds0_a" + str(int_merge_param)
    seeds0 = jtm.addJetCopier(seeds0_name,
                              a2_unsubtracted_name, [discrim],
                              isTrigger=True,
                              shallow=False)
    #seeds0 = seed_finder

    #from HIJetRec.HIJetRecConf import HIEventShapeJetIterationHLT
    from TrigHIRec.TrigHIRecConf import TrigHIEventShapeJetIteration
    iter0_name = "a" + str(int_merge_param) + "iter0"
    iter0 = TrigHIEventShapeJetIteration(iter0_name)
    iter0.InputEventShapeKey = EventShapeKey
    iter0.OutputEventShapeKey = EventShapeKey + "_" + iter0_name
    #iter0.AssociationKey=assoc_name
    iter0.InputClustersKey = ClusterKey
    #iter0.SeedContainerKeys=[seeds0.OutputContainer]
    iter0.SeedContainerKey = seeds0.OutputContainer
    #if not hasattr(jtm,"HLT_a"+str(int_merge_param)+"HIJetSubtractor") :
    #    from HIJetRec.HIJetRecConf import HIJetCellSubtractorTool
    #    cell_subtr=HIJetCellSubtractorTool("HLT_a"+str(int_merge_param)+"HIJetSubtractor")
    #    jtm.add(cell_subtr)
    #iter0.Subtractor=jtm.HIJetSubtractor
    iter0.Subtractor = cell_subtr
    from HIEventUtils.HIEventUtilsConf import HIEventShapeMapTool
    iter0.EventShapeMapTool = HIEventShapeMapTool()
    jtm.add(iter0)
    jtm.jetrecs += [iter0]

    #subtr1=MakeSubtractionTool(iter0.OutputEventShapeKey,moment_name="subtr1")
    from HIJetRec.HIJetRecConf import HIJetConstituentSubtractionTool
    subtr1 = HIJetConstituentSubtractionTool("HIConstituentSubtractor_%s" %
                                             iter0.OutputEventShapeKey)
    subtr1.EventShapeKey = iter0.OutputEventShapeKey
    subtr1.SetMomentOnly = False
    subtr1.MomentName = "JetSubtractedScaleMomentum"  #"subtr1"
    #subtr1.Subtractor=jtm.HIJetSubtractor
    subtr1.Subtractor = cell_subtr
    subtr1.Modulator = mod_tool
    jtm.add(subtr1)

    seeds1_name = "TrigAntiKt2HIJets_seeds1_a" + str(int_merge_param)
    seeds1 = jtm.addJetCopier(seeds1_name,
                              a2_unsubtracted_name,
                              [subtr1, calib_tool, jetfil8],
                              isTrigger=True,
                              shallow=False)  #add calib tool

    iter1_name = "a" + str(int_merge_param) + "iter1"
    iter1 = TrigHIEventShapeJetIteration(iter1_name)
    iter1.InputEventShapeKey = EventShapeKey
    iter1.OutputEventShapeKey = EventShapeKey + "_" + iter1_name
    #iter1.AssociationKey=assoc_name
    iter1.InputClustersKey = ClusterKey
    #iter1.SeedContainerKeys=[seeds1.OutputContainer]
    iter1.SeedContainerKey = seeds1.OutputContainer
    #iter1.Subtractor=jtm.HIJetSubtractor
    iter1.Subtractor = cell_subtr
    #iter1.ModulationScheme=1;
    #iter1.RemodulateUE=remodulate
    #iter1.Modulator=mod_tool
    #iter1.ModulationEventShapeKey=mod_tool.EventShapeKey
    jtm.add(iter1)
    jtm.jetrecs += [iter1]

    #subtr2=MakeSubtractionTool(iter1.OutputEventShapeKey,moment_name="subtr2")
    from HIJetRec.HIJetRecConf import HIJetConstituentSubtractionTool
    subtr2 = HIJetConstituentSubtractionTool("HIConstituentSubtractor_%s" %
                                             iter1.OutputEventShapeKey)
    subtr2.EventShapeKey = iter1.OutputEventShapeKey
    subtr2.MomentName = "JetSubtractedScaleMomentum"
    subtr2.SetMomentOnly = False
    #subtr2.Subtractor=jtm.HIJetSubtractor
    subtr2.Subtractor = cell_subtr
    subtr2.Modulator = mod_tool
    jtm.add(subtr2)

    finder = jtm.addJetFinder(
        name + "_finder",
        "AntiKt",
        merge_param,
        gettersin=[_getTriggerPseudoJetGetter(cluster_calib)],
        modifiersin=[subtr2, calib_tool],
        ghostArea=0.0,
        rndseed=0,
        isTrigger=True,
        ptmin=ptmin,
        ptminFilter=ptminFilter)

    exe_tools = [seed_finder, seeds0, iter0, seeds1, iter1, finder]
    from JetRec.JetRecConf import JetToolRunner
    runner = JetToolRunner("jetrunHI_a" + str(int_merge_param),
                           Tools=exe_tools)
    jtm.add(runner)

    builder = jtm.addJetCopier(name,
                               name + "_finder", [],
                               isTrigger=True,
                               shallow=False)
    builder.unlock()
    builder.InputTool = runner
    builder.lock()

    jetBuildTool = builder

    ## we could also add to hi_modifiers the calibration as defined below:

    #_is_calibration_supported(int_merge_param, jet_calib, cluster_calib)

    # # tell the offline code which calibration is requested
    #calib_str = {'jes': 'calib:j:triggerNoPileup:HLTKt4',
    #             'subjes': 'calib:aj:trigger:HLTKt4',
    #             'sub': 'calib:a:trigger:HLTKt4'}.get(jet_calib, '')

    #myMods = [calib_str] if calib_str else []

    return jetBuildTool
Exemplo n.º 2
0
    for ptype in jetFlags.truthFlavorTags():
        flavorgetters += [getattr(jtm, "gtruthget_" + ptype)]
    HIgetters_common += flavorgetters

jtm.gettersMap['HI'] = [jtm.get_HI]
jtm.gettersMap['HI'] += HIgetters_common
jtm.gettersMap['HI'] += HIgetters_ghost_track

jtm.gettersMap['HITrack'] = []
if HIJetFlags.UseHITracks() : jtm.gettersMap['HITrack'] += [jtm.trackget_HI]
else : jtm.gettersMap['HITrack'] += [jtm.trackget]
jtm.gettersMap['HITrack'] += HIgetters_common


from JetRec.JetRecConf import JetFilterTool
jetfil5=JetFilterTool("jetfil5", PtMin = 5*Units.GeV)
jtm.add(jetfil5)

jetfilHI=JetFilterTool("jetfilHI", PtMin = HIJetFlags.RecoOutputPtMin() )
jtm.add(jetfilHI)

jetfilHISeeds=JetFilterTool("jetfilHISeeds", PtMin = HIJetFlags.SeedPtMin() )
jtm.add(jetfilHISeeds)

#DR association- form element links for all clusters w/in DR of each jet
DR=HIJetFlags.ClusterDRAssociation()
from HIJetRec.HIJetRecConf import HIJetDRAssociationTool
assoc=HIJetDRAssociationTool("HIJetDRAssociation")
assoc.ContainerKey=ClusterKey
assoc.DeltaR=DR
assoc.AssociationName="%s_DR%dAssoc" % (ClusterKey,int(10*DR))
Exemplo n.º 3
0
    def buildModifiers(self, modifiersin, finder, getters, altname, output,
                       calibOpt):
        from GaudiKernel.Proxy.Configurable import ConfigurableAlgTool
        from JetRec.JetRecConf import JetFinder
        outmods = []
        inmods = self.getModifiers(modifiersin, altname)
        ncalib = 0
        for mod in inmods:
            jetlog.info(self.prefix + "Adding modifier " + str(mod))
            mod0 = ""
            # Split mod = a:b:c... into mod0="a" and modarr = [a, b, c, ...]
            if type(mod) == str:
                if len(mod) == 0: continue
                modarr = mod.split(":")
                mod0 = modarr[0]
            # Fully configured tool.
            if isinstance(mod, ConfigurableAlgTool):
                self.msg(2, "  Adding modifier " + mod.name())
                outmods += [mod]
            # Add jet calibration:
            #   calib:XXX:CALIB - Applies calibration sequence XXX (see JetRecCalibrationFinder)
            #                     using JetCalibrationTool with configuration (or key) CONFIG.
            elif mod0 == "calib":
                ncalib += 1
                alg = finder.JetAlgorithm
                rad = finder.JetRadius
                get = getters[0]
                inp = get.Label
                copt = calibOpt
                if type(calibOpt) == str and len(calibOpt):
                    calargs = calibOpt.split(":")
                else:
                    calargs = modarr[1:]
                if len(calargs) == 0:
                    copt = jetFlags.defaultCalibOpt
                    if type(copt) == str and len(copt):
                        calargs = copt.split(":")
                    else:
                        jetlog.info(
                            self.prefix +
                            'ERROR: If the modifier "calib" is used, then calibOpt or jetFlags.CalibOpt must be a non-blank string.'
                        )
                        jetlog.info(
                            self.prefix +
                            'ERROR: Another alternative is to use the modifier string format "calib:<OPT>", e.g. "calib:a"'
                        )
                        raise Exception
                if len(calargs) == 0 or calargs[0] == "":
                    jetlog.info(self.prefix +
                                "ERROR: Calibration requested without option.")
                    jetlog.info(
                        self.prefix +
                        "       Add calibOpt to tool string, jet build command or to jetFlags.defaultCalibOpt"
                    )
                    raise Exception
                seq = calargs[0]
                if seq == "none":
                    jetlog.info(self.prefix + "Skipping calibration.")
                    continue
                config = ""
                evsprefix = "Kt4"
                if len(calargs) > 1:
                    config = calargs[1]
                if len(calargs) > 2:
                    evsprefix = calargs[2]
                self.msg(
                    0, "  Adding " + seq + " calibration for " + alg + " R=" +
                    str(rad) + " " + inp)
                self.msg(0, "  Configuration key/file: " + config)
                self.msg(0, "  Event shape prefix: " + evsprefix)
                from JetRec.JetRecCalibrationFinder import jrcf
                calmod = jrcf.find(alg, rad, inp, seq, config, evsprefix)
                jetlog.info(self.prefix + "Adding calib modifier " +
                            str(calmod))
                outmods += [calmod]
            # truthassoc - Does truth jet association replacing the input name with "Truth"
            elif mod == "truthassoc":
                sinp = getters[0].Label.split("Origin")[0]
                salg = finder.JetAlgorithm
                srad = str(int(10 * finder.JetRadius))
                cname = output.replace(sinp, "Truth")
                if cname == output:
                    jetlog.info(sinp, cname, output)
                    raise TypeError
                # Check that the building of the association tool has been scheduled.
                if not cname in self.jetcons:
                    jetlog.info(
                        self.prefix +
                        "Truth association skipped because container is missing: "
                        + cname)
                    jetlog.info(
                        self.prefix +
                        "Add to jetcons if input stream is expected to have this."
                    )
                tname = mod + "_" + salg + srad
                if not tname in self.tools:
                    from JetMomentTools.JetMomentToolsConf import JetPtAssociationTool
                    self += JetPtAssociationTool(tname,
                                                 InputContainer=cname,
                                                 AssociationName="GhostTruth")
                outmods += [self.tools[tname]]
            # trackassoc - Does track jet association replacing the input name with "Track"
            elif mod == "trackassoc":
                sinp = getters[0].Label.split("Origin")[0]
                salg = finder.JetAlgorithm
                srad = str(int(10 * finder.JetRadius))
                cname = output.replace(sinp, "PV0Track")
                if cname == output:
                    jetlog.info(sinp, cname, output)
                    raise TypeError
                # Check that the building of the association tool has been scheduled.
                if not cname in self.jetcons:
                    jetlog.info(
                        self.prefix +
                        "Track association skipped because container is missing: "
                        + cname)
                    jetlog.info(
                        self.prefix +
                        "Add to jetcons if input stream is expected to have this."
                    )
                else:
                    tname = mod + "_" + salg + srad
                    if not tname in self.tools:
                        from JetMomentTools.JetMomentToolsConf import JetPtAssociationTool
                        self += JetPtAssociationTool(
                            tname,
                            InputContainer=cname,
                            AssociationName="GhostTrack")
                    outmods += [self.tools[tname]]
            # jetfilter - Filter to remove jets with pT < self.ptminFilter
            elif mod == "jetfilter":
                if self.ptminFilter <= 0:
                    jetlog.info(self.prefix +
                                "Jet filter requested without a threshold.")
                    raise Exception
                tname = "jetpt" + str(self.ptminFilter)
                if not tname in self.tools:
                    from JetRec.JetRecConf import JetFilterTool
                    self.add(JetFilterTool(tname, PtMin=self.ptminFilter))
                outmods += [self.tools[tname]]
            # btag - btagging
            elif mod == "btag":
                from BTagging.BTaggingConfiguration import getConfiguration
                ConfInstance = getConfiguration()
                from AthenaCommon.AppMgr import ToolSvc
                sinp = getters[0].Label
                salg = finder.JetAlgorithm
                srad = str(int(10 * finder.JetRadius))
                bspec = salg + srad + sinp
                jetlog.info(self.prefix + "Scheduling btagging for " + bspec)
                btagger = ConfInstance.setupJetBTaggerTool(ToolSvc, bspec)
                jetlog.info(btagger)
                self.add(btagger)
                outmods += [btagger]
            elif mod == "largeR":
                outmods += jtm.modifiersMap["largeR"]
            else:
                raise TypeError
        # Check calibration.
        if calibOpt != "":
            if ncalib == 0:
                jetlog.info(self.prefix + "Calibration option (" + calibOpt +
                            ") provided without any calibration modifiers.")
            elif ncalib > 1:
                jetlog.info(self.prefix + "Calibration option (" + calibOpt +
                            ") provided with multiple calibration modifiers.")
                raise Exception

        return outmods