Esempio n. 1
0
def getJetGroomAlg(jetname,groomdef,pjsin,modlist,monTool=None):
    jetlog.debug("Configuring JetAlgorithm \"jetalg_{0}\"".format(jetname))

    from . import JetRecConfig
    builder = JetRecConfig.getJetBuilder()

    groomer = getJetGroomer(groomdef,pjsin)
    groomer.JetBuilder = builder

    from . import JetModConfig
    mods = []
    # Dependency resolution should be done externally
    for moddef,modspec in modlist:
        mod = JetModConfig.getModifier(groomdef,moddef,modspec)
        mods.append(mod)

    rectool = CompFactory.JetRecTool(jetname,
                                     JetGroomer=groomer,
                                     InputContainer=groomdef.ungroomedname,
                                     OutputContainer=jetname,
                                     JetPseudojetRetriever=CompFactory.JetPseudojetRetriever("jpjretriever"),
                                     JetModifiers=mods)

    if monTool: rectool.MonTool = monTool

    jetalg = CompFactory.JetAlgorithm("jetalg_"+jetname)
    jetalg.Tools = [rectool]

    return jetalg
Esempio n. 2
0
def JetInputCfg(ConfigFlags):
    inputcfg = ComponentAccumulator()
    # Create a sequence that holds a set of algorithms
    # -- mainly for understanding how chunks of the job
    #    relate to each other
    sequencename = "JetInputSeq"

    inputcfg.addSequence(CompFactory.AthSequencer(sequencename))

    from xAODBase.xAODType import xAODType

    # Apply some corrections to the topoclusters
    # Example with property assignments
    jetmodseq = CompFactory.JetConstituentModSequence("JetMod_LCOrigin")
    jetmodseq.InputType = xAODType.CaloCluster
    jetmodseq.InputContainer = "CaloCalTopoClusters"
    jetmodseq.OutputContainer = "LCOriginTopoClusters"

    # Build the list of modifiers to run
    # Configuration with constructor keywords
    modlist = [
        CompFactory.CaloClusterConstituentsOrigin(
            "ClusterOrigin", InputType=xAODType.CaloCluster)
    ]
    jetmodseq.Modifiers = modlist

    # We need a JetAlgorithm to run the modseq, which is a tool
    jetmodalg = CompFactory.JetAlgorithm("JetModAlg_LCOrigin",
                                         Tools=[jetmodseq])

    # Add the alg to the sequence in the ComponentAccumulator
    inputcfg.addEventAlgo(jetmodalg, sequencename)

    # Create a PseudoJetAlgorithm

    constitpjgalg = CompFactory.PseudoJetAlgorithm(
        "pjgalg_LCTopo",
        InputContainer="LCOriginTopoClusters",
        OutputContainer="PseudoJetLCTopo",
        Label="LCTopo",
        SkipNegativeEnergy=True)

    ghostpjgalg = CompFactory.PseudoJetAlgorithm(
        "pjgalg_GhostTruth",
        InputContainer="TruthParticles",
        OutputContainer="PseudoJetGhostTruth",
        Label="GhostTruth",
        SkipNegativeEnergy=True)

    pjcs = [constitpjgalg.OutputContainer, ghostpjgalg.OutputContainer]

    # Add the algs to the sequence in the ComponentAccumulator
    inputcfg.addEventAlgo(constitpjgalg, sequencename)
    inputcfg.addEventAlgo(ghostpjgalg, sequencename)

    return inputcfg, pjcs
Esempio n. 3
0
def JetTrackingSequence(dummyFlags, trkopt, RoIs):
    jetTrkSeq = parOR("JetTrackingSeq_" + trkopt, [])
    tracksname = ""
    verticesname = ""

    if trkopt == "ftf":
        from TrigInDetConfig.InDetSetup import makeInDetAlgsNoView
        # Guess FS rather than making it jet-specific?
        viewAlgs = makeInDetAlgsNoView("JetFS", "FS", rois=recordable(RoIs))
        jetTrkSeq += viewAlgs
        tracksname = recordable("HLT_IDTrack_FS_FTF")
        verticesname = recordable("HLT_IDVertex_FS")

    from TrigInDetConfig.TrigInDetPriVtxConfig import makeVertices
    vtxAlgs = makeVertices("jet", tracksname, verticesname)
    prmVtx = vtxAlgs[-1]
    jetTrkSeq += prmVtx

    tvaname = "JetTrackVtxAssoc_" + trkopt
    trkcolls = {
        "Tracks": tracksname,
        "Vertices": verticesname,
        "TVA": tvaname,
    }

    from JetRecTools.JetRecToolsConfig import trackcollectionmap
    if trkopt not in trackcollectionmap.keys():
        trackcollectionmap[trkopt] = trkcolls

    # Jet track selection
    jettrackselloose = getTrackSelTool(trkopt, doWriteTracks=True)
    jettracksname = jettrackselloose.OutputContainer
    jettvassoc = getTrackVertexAssocTool(trkopt)

    trackcollectionmap[trkopt]["JetTracks"] = jettracksname
    trackcollectionmap[trkopt]["TVA"] = tvaname

    jettrkprepalg = CompFactory.JetAlgorithm("jetalg_TrackPrep")
    jettrkprepalg.Tools = [jettrackselloose, jettvassoc]
    jetTrkSeq += conf2toConfigurable(jettrkprepalg)

    label = "GhostTrack_{}".format(trkopt)
    ghosttracksname = "PseudoJet{}".format(label)

    trackcollectionmap[trkopt]["GhostTracks"] = ghosttracksname
    trackcollectionmap[trkopt]["GhostTracksLabel"] = label

    pjgalg = CompFactory.PseudoJetAlgorithm("pjgalg_" + label,
                                            InputContainer=tracksname,
                                            OutputContainer=ghosttracksname,
                                            Label=label,
                                            SkipNegativeEnergy=True)
    jetTrkSeq += conf2toConfigurable(pjgalg)

    return jetTrkSeq, trkcolls
Esempio n. 4
0
def getJetAlgorithm(jetname, jetdef, pjs, modlist, monTool=None):
    jetlog.debug("Configuring JetAlgorithm \"jetalg_{0}\"".format(jetname))

    builder = getJetBuilder()

    finder = getJetFinder(jetname, jetdef)
    finder.JetBuilder = builder

    from . import JetModConfig
    mods = []
    for moddef, modspec in modlist:
        mod = JetModConfig.getModifier(jetdef, moddef, modspec)
        mods.append(mod)

    rectool = getJetRecTool(jetname, finder, pjs, mods)
    if monTool: rectool.MonTool = monTool

    jetalg = CompFactory.JetAlgorithm("jetalg_" + jetname)
    jetalg.Tools = [rectool]

    return jetalg
Esempio n. 5
0
def getConstitModAlg(constit,
                     suffix="",
                     tvaKey="JetTrackVtxAssoc",
                     vtxKey="PrimaryVertices",
                     monTool=None):
    inputtype = constit.basetype

    # Need to extend to TCC
    if inputtype not in [xAODType.CaloCluster, xAODType.ParticleFlow]:
        constmodlog.error(
            "Only ParticleFlow and CaloCluster currently supported!")
        raise TypeError("Unsupported input type {0}".format(inputtype))

    sequence = list(constit.modifiers)  # Copy, as we may make some additions
    typename = {
        xAODType.CaloCluster: "TopoCluster",
        xAODType.ParticleFlow: "EMPFlow"
    }[inputtype]

    if inputtype == xAODType.ParticleFlow:
        # Always do 4mom corrections first and CHS last
        sequence = ["CorrectPFO"] + sequence + ["CHS"]

    # If no mods are needed, don't give back a tool
    if sequence == []: return None

    modlist = []
    for step in sequence:
        if step == "LC":
            continue  # Nothing to do for LC clusters
        tool = None

        toolname = "ConstitMod{0}_{1}{2}".format(typename, step, suffix)
        tool = ConstModTools[step](toolname, **ConstModConfigs[step])

        # May want to set also for cluster origin correction
        # but so far unused
        if step == "CorrectPFO":
            tool.VertexContainerKey = vtxKey
        if step == "CHS":
            tool.TrackVertexAssociation = tvaKey
            tool.VertexContainerKey = vtxKey

        if inputtype == xAODType.ParticleFlow and step not in [
                "CorrectPFO", "CHS"
        ]:
            tool.IgnoreChargedPFO = True
            tool.ApplyToChargedPFO = False
        tool.InputType = inputtype
        modlist.append(tool)

    sequenceshort = "".join(sequence)
    seqname = "ConstitMod{0}_{1}{2}".format(sequenceshort, typename, suffix)
    inputcontainer = str(constit.rawname)
    outputcontainer = str(constit.inputname)
    if inputtype == xAODType.ParticleFlow:
        # Tweak PF names because ConstModSequence needs to work with
        # up to 4 containers
        def chopPFO(thestring):
            pfostr = "ParticleFlowObjects"
            if thestring.endswith(pfostr):
                return thestring[:-len(pfostr)]
            return thestring

        inputcontainer = chopPFO(inputcontainer)
        outputcontainer = chopPFO(outputcontainer)

    modseq = CompFactory.JetConstituentModSequence(
        seqname,
        InputType=inputtype,
        OutputContainer=outputcontainer,
        InputContainer=inputcontainer,
        Modifiers=modlist,
        MonTool=monTool)

    constitmodalg = CompFactory.JetAlgorithm("jetalg_{0}".format(
        modseq.getName()))
    constitmodalg.Tools = [modseq]

    return constitmodalg
Esempio n. 6
0
def JetInputCfg(inputdeps, configFlags, sequenceName, evsprefix=""):
    jetlog.info("Setting up jet inputs.")
    components = ComponentAccumulator(sequenceName)

    jetlog.info("Inspecting input file contents")
    filecontents = [i for i in configFlags.Input.Collections]

    constit = inputdeps[0]
    # Truth and track particle inputs are handled later
    if constit.basetype not in [
            xAODType.TruthParticle, xAODType.TrackParticle
    ] and constit.inputname != constit.rawname:
        # Protection against reproduction of existing containers
        if constit.inputname in filecontents:
            jetlog.debug(
                "Input container {0} for label {1} already in input file.".
                format(constit.inputname, constit.label))
        else:
            jetlog.debug(
                "Preparing Constit Mods for label {0} from {1}".format(
                    constit.label, constit.inputname))
            # May need to generate constituent modifier sequences to
            # produce the input collection
            from . import ConstModHelpers
            constitalg = ConstModHelpers.getConstitModAlg(constit)
            if constitalg:
                components.addEventAlgo(constitalg)

    # Schedule the constituent PseudoJetAlg
    constitpjalg = getConstitPJGAlg(constit)
    constitpjkey = constitpjalg.OutputContainer
    # Mark the constit PJGAlg as the primary so that the caller
    # can access the output container name
    components.addEventAlgo(constitpjalg, primary=True)

    # Track selection and vertex association kind of go hand in hand, though it's not
    # completely impossible that one might want one and not the other
    if "JetSelectedTracks" in inputdeps or "JetTrackVtxAssoc" in inputdeps:
        jetlog.debug(
            "Setting up input track containers and track-vertex association")
        from JetRecTools import JetRecToolsConfig
        # Jet track selection
        jettrackselloose = JetRecToolsConfig.getTrackSelTool(
            doWriteTracks=True)
        jettvassoc = JetRecToolsConfig.getTrackVertexAssocTool()

        jettrkprepalg = CompFactory.JetAlgorithm("jetalg_TrackPrep")
        jettrkprepalg.Tools = [jettrackselloose, jettvassoc]
        components.addEventAlgo(jettrkprepalg)

    # Resolve the rest of the input dependencies
    for dep in inputdeps[1:]:
        # Generate prequisite truth particle collections
        # There may be more than one.
        if dep.startswith("JetInputTruthParticles"):
            # Special conditions e.g. "WZ" are set as a suffix preceded by ":"
            truthmod = ''
            if ":" in dep:
                truthmod = dep.split(':')[1]
            tpcname = "truthpartcopy" + truthmod
            jetlog.debug(
                "Setting up input truth particle container JetInputTruthParticles{0}"
                .format(truthmod))

            from ParticleJetTools.ParticleJetToolsConfig import getCopyTruthJetParticles
            tpc = getCopyTruthJetParticles(truthmod)

            tpcalg = CompFactory.JetAlgorithm("jetalg_{0}".format(tpcname))
            tpcalg.Tools = [tpc]
            components.addEventAlgo(tpcalg)

        # Truth particles specifically for truth labels
        elif dep.startswith("TruthLabel"):
            truthlabel = dep[10:]
            tpcname = "truthpartcopy_" + truthlabel

            jetlog.debug(
                "Setting up input truth particle container TruthLabel{0}".
                format(truthlabel))
            from ParticleJetTools.ParticleJetToolsConfig import getCopyTruthLabelParticles
            tpc = getCopyTruthLabelParticles(truthlabel)

            tpcalg = CompFactory.JetAlgorithm("jetalg_{0}".format(tpcname))
            tpcalg.Tools = [tpc]
            components.addEventAlgo(tpcalg)

        # Calculate the event density for jet area subtraction taking the
        # jet constituents as input
        # Possibly not needed if constituent suppression has been applied.
        # Will want to update the standalone ED python for other uses,
        # e.g. isolation or rho from constituents that are not used to
        # build a particular jet collection (e.g. neutral PFOs)
        #
        # Needs protection against reproduction of existing containers
        elif dep == "EventDensity":
            rhokey = "Kt4" + constit.label + "EventShape"
            if rhokey in filecontents:
                jetlog.info(
                    "Event density {0} for label {1} already in input file.".
                    format(rhokey, constit.label))
            else:
                components.addEventAlgo(
                    getEventShapeAlg(constit, constitpjkey, evsprefix))

    return components