Beispiel #1
0
def addAntiKt4TruthJets(algseq):
    '''
    Use the standard AntiKt4TruthJets configuration helpers
    and return the jet finder
    '''
    logger.info('Configuring AntiKt4TruthJets')

    truthtools = []
    from JetRec.JetFlavorAlgs import scheduleCopyTruthParticles
    truthtools += scheduleCopyTruthParticles()
    from JetRec.JetRecStandard import jtm
    truthtools.append(jtm.truthpartcopy)
    from AthenaCommon import CfgMgr
    algseq += CfgMgr.JetAlgorithm("jetalgTruthPartCopy", Tools=truthtools)

    for getter in jtm.gettersMap["truth"]:
        algseq += getter

    from JetRec.JetRecStandard import jtm
    return [
        jtm.addJetFinder("AntiKt4TruthJets",
                         "AntiKt",
                         0.4,
                         "truth",
                         ptmin=5000)
    ]
Beispiel #2
0
def HITruthParticleCopy():
    from JetRec.JetFlavorAlgs import scheduleCopyTruthParticles
    rtools = scheduleCopyTruthParticles()
    #following fixes oversight in schduleCopyTruthParticles
    for ptype in jetFlags.truthFlavorTags():
        toolname = "CopyTruthTag" + ptype
        if toolname in jtm.tools and toolname not in rtools:
            rtools += [jtm.tools[toolname]]
    rtools += [jtm.truthpartcopy]  #, jtm.truthpartcopywz ]
    return rtools
Beispiel #3
0
def addAntiKt4TruthJets(algseq):
    '''
    Use the standard AntiKt4TruthJets configuration helpers
    and return the jet finder
    '''
    logger.info('Configuring AntiKt4TruthJets')

    jtools = []
    from JetRec.JetFlavorAlgs import scheduleCopyTruthParticles
    jtools += scheduleCopyTruthParticles()
    from JetRec.JetRecStandard import jtm
    jtools.append(jtm.truthpartcopy)

    from JetRec.JetRecStandard import jtm
    jtools.append(
        jtm.addJetFinder("AntiKt4TruthJets",
                         "AntiKt",
                         0.4,
                         "truth",
                         ptmin=5000))

    return jtools
Beispiel #4
0
def scheduleRTTJetTests():

    global containerToRebuild

    from JetRec.JetRecFlags import jetFlags
    from RecExConfig.RecFlags import rec
    jetFlags.useTruth = rec.doTruth()

    from JetRec.JetRecStandard import jtm
    from JetRec.JetRecConf import JetAlgorithm
    from JetRec.JetRecUtils import interpretJetName

    from JetRec.JetRecStandardToolManager import calib_topo_ungroomed_modifiers, topo_ungroomed_modifiers

    #calibarg = 'calib' if jetFlags.applyCalibrationName()!="none" else None

    #calibarg = 'calib' if jetFlags.applyCalibrationName!= "none" else "none"

    # arguments to give to addJetFinder
    # format is 'input' : dict_of_args
    inputArgs = {
        'LCTopo': dict(
            gettersin='lctopo',
            modifiersin='calib',
            ghostArea=0.01,
        ),
        'EMTopo': dict(
            gettersin='emtopo',
            modifiersin='calib',
            ghostArea=0.01,
        ),
        'ZTrack': {},
    }

    fullnameArgs = {
        "AntiKt4LCTopoJetsTest": dict(ptminFilter=7000, calibOpt='ar'),
        "AntiKt4EMTopoJetsTest": dict(ptminFilter=5000, calibOpt='ar'),
        "AntiKt10LCTopoJetsTest": dict(ptminFilter=50000, calibOpt='a'),
        "CamKt12LCTopoJetsTest": dict(ptminFilter=50000, calibOpt='a'),
    }

    tools = []
    for jname in containerToRebuild:
        # decompose arg name
        finder, mainParam, input = interpretJetName(jname)

        args = fullnameArgs[jname]
        args.update(inputArgs[input])
        # call addJetFinderArgs with the relavant args for this collection
        t = jtm.addJetFinder(jname, finder, mainParam, ptmin=2000, **args)

        tools.append(t)

    from AthenaCommon.AlgSequence import AlgSequence
    topSequence = AlgSequence()

    if jetFlags.useTruth:
        from JetRec.JetFlavorAlgs import scheduleCopyTruthParticles
        tools = [jtm.truthpartcopy, jtm.truthpartcopywz
                 ] + scheduleCopyTruthParticles() + tools

    topSequence += JetAlgorithm("JetAlgorithmTest",
                                Tools=[
                                    jtm.tracksel,
                                    jtm.tvassoc,
                                ] + tools)
Beispiel #5
0
def addJetRecoToAlgSequence(job=None,
                            useTruth=None,
                            eventShapeTools=None,
                            separateJetAlgs=None,
                            debug=None):

    myname = "JetAlgorithm: "

    # We need this to modify the global variable.
    global jetalg

    # Import message level flags.
    from GaudiKernel.Constants import DEBUG

    # Import the jet reconstruction control flags.
    from JetRec.JetRecFlags import jetFlags

    # Import the standard jet tool manager.
    from JetRec.JetRecStandardToolManager import jtm

    # Set sequence and flags as needed.
    if job == None:
        from AthenaCommon.AlgSequence import AlgSequence
        job = AlgSequence()
    if useTruth == None:
        useTruth = jetFlags.useTruth()
    if eventShapeTools == None:
        eventShapeTools = jetFlags.eventShapeTools()
        if eventShapeTools == None:
            eventShapeTools = []
    if separateJetAlgs == None:
        separateJetAlgs = jetFlags.separateJetAlgs()

    # Event shape tools.
    evstools = []
    evsDict = {
        "emtopo": ("EMTopoEventShape", jtm.emget),
        "lctopo": ("LCTopoEventShape", jtm.lcget),
        "empflow": ("EMPFlowEventShape", jtm.empflowget),
        "emcpflow": ("EMCPFlowEventShape", jtm.emcpflowget),
        "lcpflow": ("LCPFlowEventShape", jtm.lcpflowget),
    }

    if jetFlags.useTracks():
        evsDict["emtopo"] = ("EMTopoOriginEventShape", jtm.emoriginget)
        evsDict["lctopo"] = ("LCTopoOriginEventShape", jtm.lcoriginget)
    jetlog.info(myname + "Event shape tools: " + str(eventShapeTools))

    from RecExConfig.AutoConfiguration import IsInInputFile
    for evskey in eventShapeTools:
        from EventShapeTools.EventDensityConfig import configEventDensityTool
        if evskey in evsDict:
            (toolname, getter) = evsDict[evskey]
            if toolname in jtm.tools:
                jetlog.info(myname + "Skipping duplicate event shape: " +
                            toolname)
            else:
                jetlog.info(myname + "Adding event shape " + evskey)
                if not IsInInputFile("xAOD::EventShape", "Kt4" + toolname):
                    jtm += configEventDensityTool(toolname, getter, 0.4)
                    evstools += [jtm.tools[toolname]]
        else:
            jetlog.info(myname + "Invalid event shape key: " + evskey)
            raise Exception

    # Add the tool runner. It runs the jetrec tools.
    rtools = []
    # Add the truth tools.
    if useTruth:
        from JetRec.JetFlavorAlgs import scheduleCopyTruthParticles
        rtools += scheduleCopyTruthParticles()

        # build truth jet input :
        rtools += [jtm.truthpartcopy, jtm.truthpartcopywz]

    ## if jetFlags.useCells():
    ##   rtools += [jtm.missingcells] commented out : incompatible with trigger : ATR-9696
    if jetFlags.useTracks:
        rtools += [
            jtm.tracksel,
            jtm.tvassoc,
            jtm.trackselloose_trackjets,
        ]

    # Add the algorithm. It runs the jetrec tools.
    from JetRec.JetRecConf import JetAlgorithm
    ctools = []
    if jetFlags.useTracks:
        if not IsInInputFile("xAOD::CaloClusterContainer",
                             "LCOriginTopoClusters"):
            ctools += [jtm.JetConstitSeq_LCOrigin]
        if not IsInInputFile("xAOD::CaloClusterContainer",
                             "EMOriginTopoClusters"):
            ctools += [jtm.JetConstitSeq_EMOrigin]
    from JetRec.JetRecConf import JetToolRunner
    runners = []
    if len(ctools) > 0:
        jtm += JetToolRunner("jetconstit",
                             EventShapeTools=[],
                             Tools=ctools,
                             Timer=jetFlags.timeJetToolRunner())
        jtm.jetconstit
        runners = [jtm.jetconstit]

    if jetFlags.separateJetAlgs():

        jtm += JetToolRunner("jetrun",
                             EventShapeTools=evstools,
                             Tools=rtools,
                             Timer=jetFlags.timeJetToolRunner())
        runners += [jetrun]

        job += JetAlgorithm("jetalg")
        jetalg = job.jetalg
        jetalg.Tools = runners

        for t in jtm.jetrecs:
            jalg = JetAlgorithm("jetalg" + t.name())
            jalg.Tools = [t]
            job += jalg

    else:
        from JetRec.JetRecConf import JetToolRunner
        jtm += JetToolRunner("jetrun",
                             EventShapeTools=evstools,
                             Tools=rtools + jtm.jetrecs,
                             Timer=jetFlags.timeJetToolRunner())
        runners += [jtm.jetrun]

        job += JetAlgorithm("jetalg")
        jetalg = job.jetalg
        jetalg.Tools = runners
        if jetFlags.debug > 0:
            jtm.setOutputLevel(jtm.jetrun, DEBUG)
            jetalg.OutputLevel = DEBUG
        if jetFlags.debug > 1:
            for tool in jtm.jetrecs:
                jtm.setOutputLevel(tool, DEBUG)
        if jetFlags.debug > 2:
            for tool in jtm.finders:
                jtm.setOutputLevel(tool, DEBUG)
        if jetFlags.debug > 3:
            jtm.setOutputLevel(jtm.jetBuilderWithArea, DEBUG)
            jtm.setOutputLevel(jtm.jetBuilderWithoutArea, DEBUG)
Beispiel #6
0
def addTruthJetsIfNotExising(truth_jets_name):
    '''
    Add algorithm to create the truth jets collection unless the
    collection exists already, or a truth jet finder is already running
    '''
    from RecExConfig.AutoConfiguration import IsInInputFile

    # the jet collection name does not exist in the input file
    # add a jet finder algorithm in front of the monitoring if the algorithm
    # does not yet exist.
    if not IsInInputFile('xAOD::JetContainer', truth_jets_name):
        try:
            from AthenaCommon.Logging import logging
            log = logging.getLogger('InDetPhysValMonitoring/addTruthJets.py')

            from PyUtils.MetaReaderPeeker import convert_itemList, metadata
            eventdata_itemsDic = convert_itemList(layout='dict')
            log.info(
                'DEBUG addTruthJetsIfNotExising {} not in {} [file_type={}]'.
                format(truth_jets_name, eventdata_itemsDic,
                       metadata['file_type']))

            if truth_jets_name in eventdata_itemsDic:
                return
        except:
            pass

        # Access the algorithm sequence:
        from AthenaCommon.AlgSequence import AlgSequence, AthSequencer
        topSequence = AlgSequence()

        # extract the jet finder type and main parameter
        import re
        extract_alg = re.search('^([^0-9]+)([0-9]+)TruthJets', truth_jets_name)
        if extract_alg != None:
            alg_type = extract_alg.group(1)
            alg_param_str = extract_alg.group(2)
        else:
            alg_type = 'AntiKt'
            alg_param_str = 4

        jet_finder_alg_name = "jetalg" + alg_type + alg_param_str + 'TruthJets'

        # add the jet finder unless it exists already in the alg sequence
        from InDetPhysValDecoration import findAlg, findMonMan
        alg_pos = findAlg([jet_finder_alg_name])
        if alg_pos == None:
            from JetRec.JetRecStandard import jtm
            mon_man_index = findMonMan()

            # configure truth jet finding ?
            from JetRec.JetRecFlags import jetFlags
            jetFlags.useTruth = True
            jetFlags.useTracks = False
            jetFlags.truthFlavorTags = [
                "BHadronsInitial",
                "BHadronsFinal",
                "BQuarksFinal",
                "CHadronsInitial",
                "CHadronsFinal",
                "CQuarksFinal",
                "TausFinal",
                "Partons",
            ]

            # tool to create truth jet finding inputs
            truth_part_copy_name = 'truthpartcopy'
            dir(jtm)
            create_truth_jet_input = None
            if not hasattr(jtm, truth_part_copy_name):

                from MCTruthClassifier.MCTruthClassifierConfig import firstSimCreatedBarcode
                from MCTruthClassifier.MCTruthClassifierConf import MCTruthClassifier
                truth_classifier_name = 'JetMCTruthClassifier'
                if not hasattr(jtm, truth_classifier_name):
                    from AthenaCommon.AppMgr import ToolSvc
                    if not hasattr(ToolSvc, truth_classifier_name):
                        truthClassifier = MCTruthClassifier(
                            name=truth_classifier_name,
                            barcodeG4Shift=firstSimCreatedBarcode(),
                            ParticleCaloExtensionTool="")
                    else:
                        truthClassifier = getattr(ToolSvc,
                                                  truth_classifier_name)
                        truthClassifier.barcodeG4Shift = firstSimCreatedBarcode(
                        )
                    jtm += truthClassifier
                else:
                    truthClassifier = getattr(jtm, truth_classifier_name)
                    truthClassifier.barcodeG4Shift = firstSimCreatedBarcode()

                from ParticleJetTools.ParticleJetToolsConf import CopyTruthJetParticles
                create_truth_jet_input = CopyTruthJetParticles(
                    truth_part_copy_name,
                    OutputName="JetInputTruthParticles",
                    MCTruthClassifier=truthClassifier)
                jtm += create_truth_jet_input
            else:
                create_truth_jet_input = getattr(jtm, truth_part_copy_name)

            jet_finder_tool = jtm.addJetFinder(truth_jets_name,
                                               alg_type,
                                               float(alg_param_str) / 10.,
                                               "truth",
                                               ptmin=5000)

            jet_tools = []
            from JetRec.JetFlavorAlgs import scheduleCopyTruthParticles
            jet_tools += scheduleCopyTruthParticles()
            jet_tools += [create_truth_jet_input]
            jet_tools += jtm.jetrecs

            # add the jet finder in front of the monitoring
            from JetRec.JetRecConf import JetAlgorithm
            from JetRec.JetRecConf import JetToolRunner
            jtm += JetToolRunner(
                "jetrun",
                Tools=jet_tools,
                EventShapeTools=[],
                # OutputLevel = 1,
                Timer=jetFlags.timeJetToolRunner())

            # jet_finder_alg = JetAlgorithm(jet_finder_alg_name, jet_tools)
            jet_finder_alg = JetAlgorithm(jet_finder_alg_name)
            # jet_finder_alg.OutputLevel = 1
            jet_finder_alg.Tools = [jtm.jetrun]

            if mon_man_index != None:
                topSequence.insert(mon_man_index, jet_finder_alg)
            else:
                topSequence += jet_finder_alg
Beispiel #7
0
from GaudiKernel.Constants import DEBUG

# Import the jet reconstruction control flags.
from JetRec.JetRecFlags import jetFlags

# Import the standard jet tool manager.
from JetRec.JetRecStandard import jtm

# Full job is a list of algorithms
from AthenaCommon.AlgSequence import AlgSequence
job = AlgSequence()

# Add the truth tools.
if jetFlags.useTruth:
  from JetRec.JetFlavorAlgs import scheduleCopyTruthParticles
  scheduleCopyTruthParticles(job)

# Event shape tools.
evstools = []
for name in jetFlags.eventShapeTools():
  from EventShapeTools.EventDensityConfig import configEventDensityTool
  if   name == "em":
    jtm += configEventDensityTool("EMTopoEventShape", jtm.emget, 0.4)
    evstools += [jtm.tools["EMTopoEventShape"]]
  elif name == "lc":
    jtm += configEventDensityTool("LCTopoEventShape", jtm.lcget, 0.4)
    evstools += [jtm.tools["LCTopoEventShape"]]
  else:
    print myname + "Invalid event shape key: " + name
    raise Exception
Beispiel #8
0
def addJetRecoToAlgSequence(job =None, useTruth =None, eventShapeTools =None,
                            separateJetAlgs= None, debug =None):

  myname = "JetAlgorithm: "

  # We need this to modify the global variable.
  global jetalg

  # Import message level flags.
  from GaudiKernel.Constants import DEBUG

  # Import the jet reconstruction control flags.
  from JetRec.JetRecFlags import jetFlags

  # Import the standard jet tool manager.
  from JetRec.JetRecStandardToolManager import jtm

  # Set sequence and flags as needed.
  if job == None:
    from AthenaCommon.AlgSequence import AlgSequence
    job = AlgSequence()
  if useTruth == None:
    useTruth = jetFlags.useTruth()
  if eventShapeTools == None:
    eventShapeTools = jetFlags.eventShapeTools()
    if eventShapeTools == None:
      eventShapeTools = []
  if separateJetAlgs == None:
    separateJetAlgs = jetFlags.separateJetAlgs()


  # Event shape tools.
  evstools = []
  evsDict = {
    "emtopo"   : ("EMTopoEventShape",   jtm.emget),
    "lctopo"   : ("LCTopoEventShape",   jtm.lcget),
    "empflow"  : ("EMPFlowEventShape",  jtm.empflowget),
    "emcpflow" : ("EMCPFlowEventShape", jtm.emcpflowget),
    "lcpflow"  : ("LCPFlowEventShape",  jtm.lcpflowget),
  }
  print myname + "Event shape tools: " + str(eventShapeTools)
  for evskey in eventShapeTools:
    from EventShapeTools.EventDensityConfig import configEventDensityTool
    if evskey in evsDict:
      (toolname, getter) = evsDict[evskey]
      if toolname in jtm.tools:
        print myname + "Skipping duplicate event shape: " + toolname
      else:
        print myname + "Adding event shape " + evskey
        jtm += configEventDensityTool(toolname, getter, 0.4)
        evstools += [jtm.tools[toolname]]
    else:
      print myname + "Invalid event shape key: " + evskey
      raise Exception

  # Add the tool runner. It runs the jetrec tools.
  rtools = []
  # Add the truth tools.
  if useTruth:    
    from JetRec.JetFlavorAlgs import scheduleCopyTruthParticles
    rtools += scheduleCopyTruthParticles()
    
    # build truth jet input :
    rtools += [ jtm.truthpartcopy, jtm.truthpartcopywz ]

  ## if jetFlags.useCells():
  ##   rtools += [jtm.missingcells] commented out : incompatible with trigger : ATR-9696
  if jetFlags.useTracks:
    rtools += [jtm.tracksel,
               jtm.tvassoc,
               jtm.trackselloose_trackjets,
               jtm.JetConstitSeq_LCOrigin,
               jtm.JetConstitSeq_EMOrigin,
               ]
    
  # Add the algorithm. It runs the jetrec tools.
  from JetRec.JetRecConf import JetAlgorithm

  if jetFlags.separateJetAlgs():

    from JetRec.JetRecConf import JetToolRunner
    jtm += JetToolRunner("jetrun",
                         EventShapeTools=evstools,
                         Tools=rtools,
                         Timer=jetFlags.timeJetToolRunner()
                         )
    jetrun = jtm.jetrun

    job += JetAlgorithm("jetalg")
    jetalg = job.jetalg
    jetalg.Tools = [jtm.jetrun]

    for t in jtm.jetrecs:
      # from JetRec.JetRecConf import JetToolRunner
      # jetrun_rec = JetToolRunner("jetrun"+t.name(),
      #                            EventShapeTools=[],
      #                            Tools=[t],
      #                            Timer=jetFlags.timeJetToolRunner()
      #                            )
      # jtm += jetrun_rec
      jalg = JetAlgorithm("jetalg"+t.name())
      jalg.Tools = [t]
      job+= jalg

  else:
    from JetRec.JetRecConf import JetToolRunner
    jtm += JetToolRunner("jetrun",
                         EventShapeTools=evstools,
                         Tools=rtools+jtm.jetrecs,
                         Timer=jetFlags.timeJetToolRunner()
                         )
    jetrun = jtm.jetrun

    job += JetAlgorithm("jetalg")
    jetalg = job.jetalg
    jetalg.Tools = [jtm.jetrun]
    if jetFlags.debug > 0:
      jtm.setOutputLevel(jtm.jetrun, DEBUG)
      jetalg.OutputLevel = DEBUG
    if jetFlags.debug > 1:
      for tool in jtm.jetrecs:
        jtm.setOutputLevel(tool, DEBUG)
    if jetFlags.debug > 2:
      for tool in jtm.finders:
        jtm.setOutputLevel(tool, DEBUG)
    if jetFlags.debug > 3:
      jtm.setOutputLevel(jtm.jetBuilderWithArea, DEBUG)
      jtm.setOutputLevel(jtm.jetBuilderWithoutArea, DEBUG)
Beispiel #9
0
from DerivationFrameworkCore.DerivationFrameworkMaster import *

#====================================================================
# ATTACH THE RECONSTRUCTION TO THE SEQUENCER
#====================================================================

#from DerivationFrameworkJetEtMiss.JetEtMissCommon import *
# Add translator from EVGEN input to xAOD-like truth here
from RecExConfig.ObjKeyStore import objKeyStore
from xAODTruthCnv.xAODTruthCnvConf import xAODMaker__xAODTruthCnvAlg
if objKeyStore.isInInput("McEventCollection", "GEN_EVENT"):
    DerivationFrameworkJob += xAODMaker__xAODTruthCnvAlg(
        "GEN_EVNT2xAOD", AODContainerName="GEN_EVENT")

from JetRec.JetFlavorAlgs import scheduleCopyTruthParticles
scheduleCopyTruthParticles(DerivationFrameworkJob)
# Set jet flags
from JetRec.JetRecFlags import jetFlags
jetFlags.useTruth = True
jetFlags.useTracks = False
# Add jet algorithms
from JetRec.JetRecStandard import jtm
from JetRec.JetRecConf import JetAlgorithm
# Standard truth jets
akt4 = jtm.addJetFinder("AntiKt4TruthJets",
                        "AntiKt",
                        0.4,
                        "truth",
                        ptmin=25000)
akt4alg = JetAlgorithm("jetalgAntiKt4TruthJets", Tools=[akt4])
DerivationFrameworkJob += akt4alg
Beispiel #10
0
def addJetRecoToAlgSequence(job=None,
                            useTruth=None,
                            eventShapeTools=None,
                            separateJetAlgs=None,
                            debug=None):

    myname = "JetAlgorithm: "

    # We need this to modify the global variable.
    global jetalg

    # Import message level flags.
    from GaudiKernel.Constants import DEBUG

    # Import the jet reconstruction control flags.
    from JetRec.JetRecFlags import jetFlags

    # Import the standard jet tool manager.
    from JetRec.JetRecStandard import jtm

    # Set sequence and flags as needed.
    if job == None:
        from AthenaCommon.AlgSequence import AlgSequence
        job = AlgSequence()
    if useTruth == None:
        useTruth = jetFlags.useTruth()
    if eventShapeTools == None:
        eventShapeTools = jetFlags.eventShapeTools()
        if eventShapeTools == None:
            eventShapeTools = []
    if separateJetAlgs == None:
        separateJetAlgs = jetFlags.separateJetAlgs()

    # Event shape tools.
    evsDict = {
        "emtopo": ("EMTopoEventShape", jtm.emget),
        "lctopo": ("LCTopoEventShape", jtm.lcget),
        "empflow": ("EMPFlowEventShape", jtm.empflowget),
    }

    if jetFlags.useTracks():
        if jetFlags.useVertices():
            evsDict["emtopo"] = ("EMTopoOriginEventShape", jtm.emoriginget)
            evsDict["lctopo"] = ("LCTopoOriginEventShape", jtm.lcoriginget)
        else:
            evsDict["emtopo"] = ("EMTopoOriginEventShape", jtm.emget)
            evsDict["lctopo"] = ("LCTopoOriginEventShape", jtm.lcget)
    jetlog.info(myname + "Event shape tools: " + str(eventShapeTools))

    from RecExConfig.AutoConfiguration import IsInInputFile
    for evskey in eventShapeTools:
        from EventShapeTools.EventDensityConfig import configEventDensityTool
        if evskey in evsDict:
            (toolname, getter) = evsDict[evskey]
            if toolname in jtm.tools:
                jetlog.info(myname + "Skipping duplicate event shape: " +
                            toolname)
            else:
                jetlog.info(myname + "Adding event shape " + evskey)
                if not IsInInputFile("xAOD::EventShape", toolname):
                    jtm += configEventDensityTool(toolname, getter.Label, 0.4)
                    jtm.allEDTools += [jtm.tools[toolname]]
        else:
            jetlog.info(myname + "Invalid event shape key: " + evskey)
            raise Exception

    # Add the tool runner. It runs the jetrec tools.
    ctools = []
    # Add the truth tools.
    if useTruth:
        from JetRec.JetFlavorAlgs import scheduleCopyTruthParticles
        ctools += scheduleCopyTruthParticles()

        # build truth jet input :
        ctools += [jtm.truthpartcopy, jtm.truthpartcopywz]

    ## if jetFlags.useCells():
    ##   ctools += [jtm.missingcells] commented out : incompatible with trigger : ATR-9696
    if jetFlags.useTracks:
        ctools += [jtm.tracksel, jtm.trackselloose_trackjets]
        if jetFlags.useVertices:
            ctools += [jtm.tvassoc]

    # LCOriginTopoClusters and EMOriginTopoClusters are shallow copies
    # of CaloCalTopoClusters.  This means that if CaloCalTopoClusters gets
    # thinned on output, the the two derived containers need to be thinned
    # in the same way, else they'll be corrupted in the output.
    # FIXME: this should be automatic somehow.
    postalgs = []
    thinneg = False
    from RecExConfig.RecFlags import rec
    if rec.doWriteAOD() and not rec.readAOD():
        from ParticleBuilderOptions.AODFlags import AODFlags
        if AODFlags.ThinNegativeEnergyCaloClusters:
            thinneg = True

    if jetFlags.useTracks and jetFlags.useVertices:
        if not IsInInputFile("xAOD::CaloClusterContainer",
                             "LCOriginTopoClusters"):
            ctools += [jtm.JetConstitSeq_LCOrigin]
            if thinneg:
                from ThinningUtils.ThinningUtilsConf import ThinNegativeEnergyCaloClustersAlg
                postalgs.append(
                    ThinNegativeEnergyCaloClustersAlg(
                        'ThinNegLCOriginTopoClusters',
                        ThinNegativeEnergyCaloClusters=True,
                        CaloClustersKey='LCOriginTopoClusters',
                        StreamName='StreamAOD'))
        if not IsInInputFile("xAOD::CaloClusterContainer",
                             "EMOriginTopoClusters"):
            ctools += [jtm.JetConstitSeq_EMOrigin]
            if thinneg:
                from ThinningUtils.ThinningUtilsConf import ThinNegativeEnergyCaloClustersAlg
                postalgs.append(
                    ThinNegativeEnergyCaloClustersAlg(
                        'ThinNegEMOriginTopoClusters',
                        ThinNegativeEnergyCaloClusters=True,
                        CaloClustersKey='EMOriginTopoClusters',
                        StreamName='StreamAOD'))
        if not IsInInputFile("xAOD::PFOContainer", "CHSParticleFlowObjects"):
            if not hasattr(job, "jetalgCHSPFlow"):
                ctools += [jtm.JetConstitSeq_PFlowCHS]
                if thinneg:
                    from ThinningUtils.ThinningUtilsConf import ThinNegativeEnergyNeutralPFOsAlg
                    CHSnPFOsThinAlg = ThinNegativeEnergyNeutralPFOsAlg(
                        "ThinNegativeEnergyCHSNeutralPFOsAlg",
                        NeutralPFOsKey="CHSNeutralParticleFlowObjects",
                        ThinNegativeEnergyNeutralPFOs=True,
                        StreamName='StreamAOD')
                    postalgs.append(CHSnPFOsThinAlg)

    from JetRec.JetRecConf import JetToolRunner
    from JetRec.JetRecConf import JetAlgorithm
    runners = []
    if len(ctools) > 0:
        jtm += JetToolRunner("jetconstit",
                             EventShapeTools=[],
                             Tools=ctools,
                             Timer=jetFlags.timeJetToolRunner())
        job += JetAlgorithm("jetalgConstituents", Tools=[jtm.jetconstit])

    # Add all the PseudoJetAlgorithms now
    # To avoid massive refactoring and to preserve familiarity,
    # kept calling things "getters", but these are already
    # PseudoJetAlgorithms as we eliminated the wrappers
    for getter in jtm.allGetters:
        job += getter

    # Then, add all event shape tools in separate algs
    for evstool in jtm.allEDTools:
        from EventShapeTools.EventShapeToolsConf import EventDensityAthAlg
        job += EventDensityAthAlg("edalg_" + evstool.OutputContainer,
                                  EventDensityTool=evstool)

    if separateJetAlgs:

        for t in jtm.jetrecs:
            jalg = JetAlgorithm("jetalg" + t.name(), Tools=[t])
            job += jalg

    else:
        from JetRec.JetRecConf import JetToolRunner
        jtm += JetToolRunner("jetrun",
                             EventShapeTools=[],
                             Tools=rtools + jtm.jetrecs,
                             Timer=jetFlags.timeJetToolRunner())
        runners += [jtm.jetrun]

    job += JetAlgorithm("jetalg")
    jetalg = job.jetalg
    jetalg.Tools = runners
    if jetFlags.debug > 0:
        # jtm.setOutputLevel(jtm.jetrun, DEBUG)
        jetalg.OutputLevel = DEBUG
    if jetFlags.debug > 1:
        for tool in jtm.jetrecs:
            jtm.setOutputLevel(tool, DEBUG)
    if jetFlags.debug > 2:
        for tool in jtm.finders:
            jtm.setOutputLevel(tool, DEBUG)
    if jetFlags.debug > 3:
        jtm.setOutputLevel(jtm.jetBuilderWithArea, DEBUG)
        jtm.setOutputLevel(jtm.jetBuilderWithoutArea, DEBUG)

    for postalg in postalgs:
        job += postalg