def addPhysValAODContent(algseq, doJets, doTopoCluster): ''' Schedule the addition of collections needed for validation of primary xAODs: AntiKt4TruthJets and LC/EMOriginTopoClusters ''' logger.info( '****************** Adding content for AOD PhysVal *****************') # Check some flags for steering from RecExConfig.AutoConfiguration import IsInInputFile requiresTruthJets = IsInInputFile( 'xAOD::TruthParticleContainer', 'TruthParticles') and not IsInInputFile('xAOD::JetContainer', 'AntiKt4TruthJets') requiresLCOriginTC = not IsInInputFile('xAOD::CaloClusterContainer', 'LCOriginTopoClusters') requiresEMOriginTC = not IsInInputFile('xAOD::CaloClusterContainer', 'EMOriginTopoClusters') jettools_PhysVal = [] # Truth jets if doJets and requiresTruthJets: jettools_PhysVal += addAntiKt4TruthJets(algseq) # Origin-corrected topoclusters if doTopoCluster and (requiresLCOriginTC or requiresEMOriginTC): jettools_PhysVal += addOriginCorrectedClusters(algseq, requiresLCOriginTC, requiresEMOriginTC) # Only add the algorithm if there is a need for it if jettools_PhysVal: from JetRec.JetRecStandard import jtm from JetRec.JetRecConf import JetToolRunner jtm += JetToolRunner( "jetrun_PhysVal", EventShapeTools=[], Tools=jettools_PhysVal, Timer=0 # No timing information ) from JetRec.JetRecConf import JetAlgorithm algseq += JetAlgorithm("jetalgPhysVal", Tools=[jtm.jetrun_PhysVal]) logger.info( '****************** Done *****************')
def addCHSPFlowObjects(): # Only act if the collection does not already exist from RecExConfig.AutoConfiguration import IsInInputFile if not IsInInputFile("xAOD::PFOContainer", "CHSParticleFlowObjects"): # Check that an alg doing this has not already been inserted from AthenaCommon.AlgSequence import AlgSequence job = AlgSequence() from JetRec.JetRecStandard import jtm if not hasattr(job, "jetalgCHSPFlow") and not hasattr( jtm, "jetconstitCHSPFlow"): from JetRec.JetRecConf import JetToolRunner jtm += JetToolRunner("jetconstitCHSPFlow", EventShapeTools=[], Tools=[jtm.JetConstitSeq_PFlowCHS]) # Add this tool runner to the JetAlgorithm instance "jetalg" # which runs all preparatory tools # This was added by JetCommon job.jetalg.Tools.append(jtm.jetconstitCHSPFlow) extjetlog.info("Added CHS PFlow sequence to \'jetalg\'") extjetlog.info(job.jetalg.Tools)
def JetAlgFromTools(rtools, suffix="HI", persistify=True): #insert exe tools at front of list, e.g. tracksel and tvassoc for HI etc. HIJet_exe_tools = [] from JetRec.JetRecFlags import jetFlags if jetFlags.useTruth() and not jetFlags.Enabled(): HIJet_exe_tools += HITruthParticleCopy() #if jetFlags.useCells(): HIJet_exe_tools += [jtm.missingcells] if HIJetFlags.UseHITracks(): HIJet_exe_tools += [jtm.tracksel_HI, jtm.gtracksel_HI, jtm.tvassoc_HI] rtools = HIJet_exe_tools + rtools from JetRec.JetRecConf import JetToolRunner runner = JetToolRunner("jetrun" + suffix, Tools=rtools, Timer=jetFlags.timeJetToolRunner()) jtm.add(runner) from JetRec.JetRecConf import JetAlgorithm theAlg = JetAlgorithm("jetalg" + suffix) theAlg.Tools = [runner] from AthenaCommon.AlgSequence import AlgSequence topsequence = AlgSequence() topsequence += theAlg from GaudiKernel.Constants import DEBUG if jetFlags.debug > 0: jtm.setOutputLevel(runner, DEBUG) theAlg.OutputLevel = DEBUG if jetFlags.debug > 3: jtm.setOutputLevel(jtm.jetBuilderWithoutArea, DEBUG) if persistify: for t in rtools: if hasattr(t, "OutputContainer"): AddToOutputList(t.OutputContainer) return theAlg
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
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)
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
#Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration # ScheduleCHSPFlowMods.py # # Teng Jian Khoo # July 2017 # # Apply PFlow p4 corrections (nPFO origin & cPFO weights) and # Charged Hadron Subtraction with jet constituent modification tools from JetRec.JetRecStandard import jtm from JetRec.JetRecConf import JetToolRunner jtm += JetToolRunner( "jetconstitCHSPFlow", EventShapeTools=[], Tools=[jtm.JetConstitSeq_PFlowCHS], ) from AthenaCommon.AlgSequence import AlgSequence job = AlgSequence() from JetRec.JetRecConf import JetAlgorithm job += JetAlgorithm("jetalgCHSPFlow", Tools=[jtm.jetconstitCHSPFlow]) from ThinningUtils.ThinningUtilsConf import ThinNegativeEnergyNeutralPFOsAlg CHSnPFOsThinAlg = ThinNegativeEnergyNeutralPFOsAlg( "ThinNegativeEnergyNCHSeutralPFOsAlg", NeutralPFOsKey="CHSNeutralParticleFlowObjects", ThinNegativeEnergyNeutralPFOs=True, StreamName='StreamAOD') job += CHSnPFOsThinAlg
def addTruthJets(kernel=None, decorationDressing=None): # In case it's requested, set up the use of photon decorations from dressing code from JetRec.JetRecStandardToolManager import jtm if decorationDressing is not None and not hasattr(jtm, 'truthpartdressedwz'): # Ensure that we are adding it to something, and that we haven't run it already if kernel is None: from DerivationFrameworkCore.DerivationFrameworkMaster import DerivationFrameworkJob kernel = DerivationFrameworkJob # make sure if we are using EVNT that we don't try to check sim metadata barCodeFromMetadata = 2 if objKeyStore.isInInput("McEventCollection", "GEN_EVENT"): barCodeFromMetadata = 0 from JetRec.JetRecStandardToolManager import jtm from ParticleJetTools.ParticleJetToolsConf import CopyTruthJetParticles if not 'truthpartdressedwz' in jtm.tools: jtm += CopyTruthJetParticles( "truthpartdressedwz", OutputName="JetInputTruthParticlesDressedWZ", MCTruthClassifier=jtm.JetMCTruthClassifier, #IncludePromptLeptons=False,#IncludePromptPhotons=False, #IncludeMuons=True,IncludeNeutrinos=True,BarCodeFromMetadata=barCodeFromMetadata, #FSRPhotonCone=-1. #, DressingDecorationName=decorationDressing ) # Add a jet tool runner for this thing from JetRec.JetRecConf import JetToolRunner, JetAlgorithm, PseudoJetGetter jtm += JetToolRunner("jetdressedwzrun", EventShapeTools=[], Tools=[jtm.truthpartdressedwz], Timer=jetFlags.timeJetToolRunner()) # And an algorithm to run in kernel += JetAlgorithm("jetdressedwzalg") jetdressedwzalg = kernel.jetdressedwzalg jetdressedwzalg.Tools = [jtm.jetdressedwzrun] if not 'truthdressedwzget' in jtm.tools: jtm += PseudoJetGetter( "truthdressedwzget", Label="TruthDressedWZ", InputContainer=jtm.truthpartdressedwz.OutputName, OutputContainer="PseudoJetTruthDressedWZ", GhostScale=0.0, SkipNegativeEnergy=True) jtm.gettersMap['truthdressedwz'] = list(jtm.gettersMap['truth']) jtm.gettersMap['truthdressedwz'][0] = jtm.truthdressedwzget if not hasattr(jtm, 'truthpartcharged'): # Ensure that we are adding it to something, and that we haven't run it already if kernel is None: from DerivationFrameworkCore.DerivationFrameworkMaster import DerivationFrameworkJob kernel = DerivationFrameworkJob # make sure if we are using EVNT that we don't try to check sim metadata barCodeFromMetadata = 2 if objKeyStore.isInInput("McEventCollection", "GEN_EVENT"): barCodeFromMetadata = 0 from JetRec.JetRecStandardToolManager import jtm from ParticleJetTools.ParticleJetToolsConf import CopyTruthJetParticles if not 'truthpartcharged' in jtm.tools: jtm += CopyTruthJetParticles( "truthpartcharged", OutputName="JetInputTruthParticlesCharged", MCTruthClassifier=jtm.JetMCTruthClassifier, #ChargedParticlesOnly=True, #BarCodeFromMetadata=barCodeFromMetadata ) # Add a jet tool runner for this thing from JetRec.JetRecConf import JetToolRunner, JetAlgorithm, PseudoJetGetter jtm += JetToolRunner("jetchargedrun", EventShapeTools=[], Tools=[jtm.truthpartcharged], Timer=jetFlags.timeJetToolRunner()) # And an algorithm to run in kernel += JetAlgorithm("jetchargedalg") jetchargedalg = kernel.jetchargedalg jetchargedalg.Tools = [jtm.jetchargedrun] if not 'truthchargedget' in jtm.tools: jtm += PseudoJetGetter( "truthchargedget", Label="TruthCharged", InputContainer=jtm.truthpartcharged.OutputName, OutputContainer="PseudoJetTruthCharged", GhostScale=0.0, SkipNegativeEnergy=True) jtm.gettersMap['truthcharged'] = [jtm.truthchargedget] # Propagate that downward if dfInputIsEVNT: addTruthJetsEVNT(kernel, decorationDressing) else: addTruthJetsAOD(kernel, decorationDressing)
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