def reCreatePseudoJets(jetalg, rsize, inputtype): """Return a list of tools (possibly empty) to be run in a jetalg. These tools will make sure PseudoJets will be associated to the container specified by the input arguments. """ from JetRec.JetRecStandard import jtm from JetRec.JetRecUtils import buildJetContName jetContName = buildJetContName(jetalg, rsize, inputtype) # Set default for the arguments to be passd to addJetFinder finderArgs = dict(modifiersin=[], consumers=[], ghostArea=0.01, ptmin=40000) # We do things differently if the container already exists in the input from RecExConfig.ObjKeyStore import cfgKeyStore if cfgKeyStore.isInInputFile("xAOD::JetContainer", jetContName): # yes ! # make sure we don't already have what we need tmpName = "tmp_" + jetContName if tmpName in jtm.tools: return [] # return [jtm.tools[tmpName]] # then we'll have to build a temporary container to re-create the pseudojet # and we recopy this pseudojets to the original collection. This done through # this tool : from JetRec.JetRecConf import JetPseudojetCopier jtm += JetPseudojetCopier( "PJcopierTo" + jetContName, DestinationContainer=jetContName, JetPseudojetRetriever=jtm.jpjretriever ) # prepare args for this case : finderArgs["consumers"] = [jtm.tools["PJcopierTo" + jetContName]] finderArgs["ptmin"] = 20000 else: # no preexisting container # make sure we don't already have what we need tmpName = jetContName if tmpName in jtm.tools: return [] # return [jtm.tools[tmpName]] # no container exist. simply build a new one. if inputtype == "LCTopo": finderArgs["modifiersin"] = "calib" finderArgs["ptmin"] = 2000 finderArgs["ptminFilter"] = 50000 finderArgs["calibOpt"] = "none" finderArgs.pop("modifiersin") # leave the default modifiers. # map the input to the jtm code for PseudoJetGetter getterMap = dict(LCTopo="lctopo", Truth="truth", PV0Track="pv0track") # create the finder for the temporary collection. tmpFinderTool = jtm.addJetFinder( tmpName, jetalg, rsize, getterMap[inputtype], **finderArgs # pass the prepared arguments ) return [tmpFinderTool]
def buildGenericGroomAlg(jetalg, rsize, inputtype, groomedName, jetToolBuilder, includePreTools=False, algseq=None, outputGroup="CustomJets"): algname = "jetalg" + groomedName # add these groomed jets to the output (use setdefault() to constuct the list if not existing yet) OutputJets.setdefault(outputGroup, []).append(groomedName + "Jets") # return if the alg is already scheduled here : if algseq is None: print "No algsequence passed! Will not schedule", algname return elif cfgKeyStore.isInInput("xAOD::JetContainer", groomedName): print "Collection ", algname, "is already in input AOD!" return elif algname in DFJetAlgs: if hasattr(algseq, algname): print " Algsequence", algseq, "already has an instance of", algname else: print " Added", algname, "to sequence", algseq algseq += DFJetAlgs[algname] return DFJetAlgs[algname] from JetRec.JetRecUtils import buildJetContName ungroomedname = buildJetContName(jetalg, rsize, inputtype) # 1. make sure we have pseudo-jet in our original container # this returns a list of the needed tools to do so. jetalgTools = reCreatePseudoJets(jetalg, rsize, inputtype) # 2nd step run the trimming alg. We can re-use the original largeR jet since we reassociated the PseudoJet already. fatjet_trim = jetToolBuilder(groomedName + "Jets", ungroomedname) from JetRec.JetRecConf import JetAlgorithm if includePreTools: # enable track ghost association and JVF jetalgTools = [jtm.tracksel, jtm.tvassoc] + jetalgTools alg = JetAlgorithm(algname, Tools=jetalgTools + [fatjet_trim]) DFJetAlgs[algname] = alg print " Added", algname, "to sequence", algseq algseq += alg return alg
def buildGenericGroomAlg( jetalg, rsize, inputtype, groomedName, jetToolBuilder, includePreTools=False, algseq=None, outputGroup="CustomJets" ): algname = "jetalg" + groomedName # add these groomed jets to the output (use setdefault() to constuct the list if not existing yet) OutputJets.setdefault(outputGroup, []).append(groomedName + "Jets") # return if the alg is already scheduled here : if algseq is None: print "No algsequence passed! Will not schedule", algname return elif cfgKeyStore.isInInput("xAOD::JetContainer", groomedName): print "Collection ", algname, "is already in input AOD!" return elif algname in DFJetAlgs: if hasattr(algseq, algname): print " Algsequence", algseq, "already has an instance of", algname else: print " Added", algname, "to sequence", algseq algseq += DFJetAlgs[algname] return DFJetAlgs[algname] from JetRec.JetRecUtils import buildJetContName ungroomedname = buildJetContName(jetalg, rsize, inputtype) # 1. make sure we have pseudo-jet in our original container # this returns a list of the needed tools to do so. jetalgTools = reCreatePseudoJets(jetalg, rsize, inputtype) # 2nd step run the trimming alg. We can re-use the original largeR jet since we reassociated the PseudoJet already. fatjet_trim = jetToolBuilder(groomedName + "Jets", ungroomedname) from JetRec.JetRecConf import JetAlgorithm if includePreTools: # enable track ghost association and JVF jetalgTools = [jtm.tracksel, jtm.tvassoc] + jetalgTools alg = JetAlgorithm(algname, Tools=jetalgTools + [fatjet_trim]) DFJetAlgs[algname] = alg print " Added", algname, "to sequence", algseq algseq += alg return alg
def reCreatePseudoJets(jetalg, rsize, inputtype): """Return a list of tools (possibly empty) to be run in a jetalg. These tools will make sure PseudoJets will be associated to the container specified by the input arguments. """ from JetRec.JetRecStandard import jtm from JetRec.JetRecUtils import buildJetContName jetContName = buildJetContName(jetalg, rsize, inputtype) # Set default for the arguments to be passd to addJetFinder finderArgs = dict( modifiersin=[], consumers=[], ghostArea=0.01, ptmin=40000, ) # We do things differently if the container already exists in the input from RecExConfig.ObjKeyStore import cfgKeyStore if cfgKeyStore.isInInputFile("xAOD::JetContainer", jetContName): # yes ! # make sure we don't already have what we need tmpName = "tmp_" + jetContName if tmpName in jtm.tools: return [] # return [jtm.tools[tmpName]] # then we'll have to build a temporary container to re-create the pseudojet # and we recopy this pseudojets to the original collection. This done through # this tool : from JetRec.JetRecConf import JetPseudojetCopier jtm += JetPseudojetCopier("PJcopierTo" + jetContName, DestinationContainer=jetContName, JetPseudojetRetriever=jtm.jpjretriever) # prepare args for this case : finderArgs['consumers'] = [jtm.tools["PJcopierTo" + jetContName]] finderArgs['ptmin'] = 20000 else: # no preexisting container # make sure we don't already have what we need tmpName = jetContName if tmpName in jtm.tools: return [] # return [jtm.tools[tmpName]] # no container exist. simply build a new one. if inputtype == "LCTopo": finderArgs['modifiersin'] = "calib" finderArgs['ptmin'] = 2000 finderArgs['ptminFilter'] = 50000 finderArgs['calibOpt'] = "none" finderArgs.pop('modifiersin') # leave the default modifiers. # map the input to the jtm code for PseudoJetGetter getterMap = dict(LCTopo='lctopo', Truth='truth', PV0Track='pv0track') # create the finder for the temporary collection. tmpFinderTool = jtm.addJetFinder( tmpName, jetalg, rsize, getterMap[inputtype], **finderArgs # pass the prepared arguments ) return [tmpFinderTool]
def buildGenericGroomAlg(jetalg, rsize, inputtype, groomedName, jetToolBuilder, includePreTools=False, algseq=None, outputGroup="CustomJets", writeUngroomed=False, variableRMassScale=-1.0, variableRMinRadius=-1.0, constmods=[]): algname = "jetalg" + groomedName[:-4] from RecExConfig.AutoConfiguration import IsInInputFile if algseq is None: dfjetlog.info("No algsequence passed! Will not schedule " + algname) return elif IsInInputFile("xAOD::JetContainer", groomedName): dfjetlog.info("Collection " + groomedName + " is already in input AOD!") return from JetRec.JetRecUtils import buildJetContName constmodstr = "".join(constmods) inputname = inputtype + constmodstr label = inputtype + constmodstr ungroomedName = buildJetContName(jetalg, rsize, inputname, variableRMassScale, variableRMinRadius) ungroomedalgname = "jetalg" + ungroomedName[:-4] # Remove "Jets" from name # add these groomed jets to the output (use setdefault() to constuct the list if not existing yet) OutputJets.setdefault(outputGroup, []).append(groomedName) if writeUngroomed: OutputJets.setdefault(outputGroup, []).append(ungroomedName) dfjetlog.info("Write " + ungroomedName) from JetRec.JetRecConf import JetAlgorithm # return if the alg is already scheduled here : if hasattr(algseq, ungroomedalgname): finderalg = getattr(algseq, ungroomedalgname) dfjetlog.warning("Algsequence " + algseq.name() + " already has an instance of " + ungroomedalgname) elif ungroomedalgname in DFJetAlgs: dfjetlog.info("Added jet finder " + ungroomedalgname + " to sequence" + algseq.name()) finderalg = DFJetAlgs[ungroomedalgname] algseq += DFJetAlgs[ungroomedalgname] else: # 1. make sure we have pseudo-jet in our original container # this returns a list of the needed tools to do so. jetalgTools = reCreatePseudoJets(jetalg, rsize, inputtype, variableRMassScale, variableRMinRadius, algseq, constmods=constmods) if includePreTools and jetFlags.useTracks( ) and not "Truth" in inputtype: # enable track ghost association and JVF jetalgTools = [jtm.tracksel, jtm.tvassoc] + jetalgTools finderalg = JetAlgorithm(ungroomedalgname, Tools=jetalgTools) DFJetAlgs[ungroomedalgname] = finderalg dfjetlog.info("Added jet finder " + ungroomedalgname + " to sequence " + algseq.name()) algseq += finderalg # 2nd step run the trimming alg. We can re-use the original largeR jet since we reassociated the PseudoJet already. fatjet_groom = jetToolBuilder(groomedName, ungroomedName) print(finderalg.Tools) print(ungroomedName) fatjet_rectool = [ t for t in finderalg.Tools if t.name().endswith(ungroomedName) ][0] fatjet_groom.InputPseudoJets = fatjet_rectool.InputPseudoJets # recopy the InputPseudoJets so tools know how to map fastjet constituents with xAOD constituents dfjetlog.info("Added jet groomer " + algname + " to sequence " + algseq.name()) groomeralg = JetAlgorithm(algname, Tools=[fatjet_groom]) DFJetAlgs[algname] = groomeralg algseq += groomeralg return groomeralg
def reCreatePseudoJets(jetalg, rsize, inputtype, variableRMassScale=-1.0, variableRMinRadius=-1.0, algseq=None, constmods=[]): """Return a list of tools (possibly empty) to be run in a jetalg. These tools will make sure PseudoJets will be associated to the container specified by the input arguments. """ from JetRec.JetRecStandard import jtm from JetRec.JetRecUtils import buildJetContName constmodstr = "".join(constmods) inputname = inputtype + constmodstr label = inputtype + constmodstr jetContName = buildJetContName(jetalg, rsize, inputname, variableRMassScale, variableRMinRadius) # Set default for the arguments to be passd to addJetFinder finderArgs = dict( modifiersin=[], consumers=[], ghostArea=0.01, ptmin=40000, constmods=constmods, ) # We do things differently if the container already exists in the input from RecExConfig.AutoConfiguration import IsInInputFile if IsInInputFile("xAOD::JetContainer", jetContName): # yes ! # make sure we don't already have what we need tmpName = "tmp_" + jetContName if tmpName in jtm.tools: return [jtm.tools[tmpName]] # then we'll have to build a temporary container to re-create the pseudojet # and we recopy this pseudojets to the original collection. This done through # this tool : from JetRec.JetRecConf import JetPseudojetCopier jtm += JetPseudojetCopier("PJcopierTo" + jetContName, DestinationContainer=jetContName, JetPseudojetRetriever=jtm.jpjretriever) # prepare args for this case : finderArgs['consumers'] = [jtm.tools["PJcopierTo" + jetContName]] finderArgs['ptmin'] = 20000 else: # no preexisting container # make sure we don't already have what we need tmpName = jetContName if tmpName in jtm.tools: # return [] return [jtm.tools[tmpName]] # no container exist. simply build a new one. if inputtype == "LCTopo" or inputtype == "EMTopo" or inputtype == "EMPFlow" or inputtype == "EMCPFlow": defaultmods = { "EMTopo": "emtopo_ungroomed", "LCTopo": "lctopo_ungroomed", "EMPFlow": "pflow_ungroomed", "EMCPFlow": "pflow_ungroomed", "Truth": "truth_ungroomed", "TruthWZ": "truth_ungroomed", "PV0Track": "track_ungroomed" } finderArgs['modifiersin'] = defaultmods[inputtype] finderArgs['ptmin'] = 2000 finderArgs['ptminFilter'] = 50000 finderArgs['calibOpt'] = "none" elif inputtype == "PV0Track": finderArgs['modifiersin'] = None finderArgs['ptmin'] = 2000 finderArgs['ptminFilter'] = 40000 finderArgs['calibOpt'] = "none" #if not "PFlow" in inputtype: finderArgs.pop('modifiersin') # leave the default modifiers. if (variableRMassScale > 0): finderArgs['variableRMassScale'] = variableRMassScale finderArgs['variableRMinRadius'] = variableRMinRadius #finderArgs['ghostArea'] =0 ## Cannot afford ghost area calculation for variable-R jets (for now) # map the input to the jtm code for PseudoJetGetter getterMap = dict(LCTopo='lctopo', EMTopo='emtopo', EMPFlow='empflow', EMCPFlow='emcpflow', Truth='truth', TruthWZ='truthwz', TruthDressedWZ='truthdressedwz', TruthCharged='truthcharged', PV0Track='pv0track') # create the finder for the temporary collection. getters = getterMap[inputtype] for getter in jtm.gettersMap[getters]: if not hasattr(algseq, getter.name()): algseq += getter if len(constmods) > 0: finderArgs['modifiersin'] = [] from JetRecConfig import ConstModHelpers from JetRecConfig.JetDefinition import xAODType, JetConstit if inputtype == "EMTopo": constit = JetConstit(xAODType.CaloCluster, ["EM", "Origin"]) elif inputtype == "LCTopo": constit = JetConstit(xAODType.CaloCluster, ["LC", "Origin"]) elif inputtype == "EMPFlow": constit = JetConstit(xAODType.ParticleFlow) constit.modifiers += constmods constitalg = ConstModHelpers.getConstitModAlg(constit) if not hasattr(algseq, constitalg.name()): algseq += constitalg from JetRecConfig import JetRecConfig constitpjalg = JetRecConfig.getConstitPJGAlg(constit) if not hasattr(algseq, constitpjalg.name()): algseq += constitpjalg getterbase = inputtype.lower() getters = [constitpjalg] + list(jtm.gettersMap[getterbase])[1:] tmpFinderTool = jtm.addJetFinder( tmpName, jetalg, rsize, getters, **finderArgs # pass the prepared arguments ) return [tmpFinderTool]