def ApplySubtractionToClusters(**kwargs): if 'event_shape_key' in kwargs.keys(): event_shape_key = kwargs['event_shape_key'] else: from HIGlobal.HIGlobalFlags import jobproperties event_shape_key = jobproperties.HIGlobalFlags.EventShapeKey() if 'cluster_key' in kwargs.keys(): cluster_key = kwargs['cluster_key'] else: cluster_key = HIJetFlags.HIClusterKey() if 'modulator' in kwargs.keys(): mod_tool = kwargs['modulator'] else: mod_tool = GetNullModulator() from HIJetRec.HIJetRecConf import HIClusterSubtraction toolName = 'HIClusterSubtraction' if 'name' in kwargs.keys(): toolName = kwargs['name'] theAlg = HIClusterSubtraction(toolName) theAlg.ClusterKey = cluster_key theAlg.EventShapeKey = event_shape_key theAlg.Subtractor = GetSubtractorTool(**kwargs) theAlg.Modulator = mod_tool do_cluster_moments = False if 'CalculateMoments' in kwargs.keys(): do_cluster_moments = kwargs['CalculateMoments'] if do_cluster_moments: from CaloRec.CaloRecConf import CaloClusterMomentsMaker from CaloTools.CaloNoiseToolDefault import CaloNoiseToolDefault theCaloNoiseTool = CaloNoiseToolDefault() from AthenaCommon.AppMgr import ToolSvc ToolSvc += theCaloNoiseTool HIClusterMoments = CaloClusterMomentsMaker("HIClusterMoments") #HIClusterMoments.MaxAxisAngle = 20*deg HIClusterMoments.CaloNoiseTool = theCaloNoiseTool HIClusterMoments.UsePileUpNoise = False HIClusterMoments.MinBadLArQuality = 4000 HIClusterMoments.MomentsNames = [ "CENTER_MAG", "LONGITUDINAL", "FIRST_ENG_DENS", "SECOND_ENG_DENS", "ENG_FRAC_EM", "ENG_FRAC_MAX", "ENG_FRAC_CORE", "ENG_BAD_CELLS", "N_BAD_CELLS", "N_BAD_CELLS_CORR", "BAD_CELLS_CORR_E", "BADLARQ_FRAC", "ENG_POS", "SIGNIFICANCE", "CELL_SIGNIFICANCE", "CELL_SIG_SAMPLING", "AVG_LAR_Q", "AVG_TILE_Q" ] from IOVDbSvc.CondDB import conddb if not conddb.isOnline: from LArRecUtils.LArHVScaleRetrieverDefault import LArHVScaleRetrieverDefault HIClusterMoments.LArHVScaleRetriever = LArHVScaleRetrieverDefault() HIClusterMoments.MomentsNames += [ "ENG_BAD_HV_CELLS", "N_BAD_HV_CELLS" ] theAlg.ClusterCorrectionTools = [HIClusterMoments] jtm.add(theAlg) jtm.jetrecs += [theAlg] jtm.HIJetRecs += [theAlg]
def GetNullModulator(): tname = 'NullUEModulator' if hasattr(jtm, tname): return getattr(jtm, tname) HIUEModulatorTool = CompFactory.HIUEModulatorTool mod = HIUEModulatorTool(tname) mod.EventShapeKey = 'NULL' for n in [2, 3, 4]: setattr(mod, 'DoV%d' % n, False) jtm.add(mod) return mod
def GetNullModulator(): tname = 'NullUEModulator' if hasattr(jtm, tname): return getattr(jtm, tname) from HIJetRec.HIJetRecConf import HIUEModulatorTool mod = HIUEModulatorTool(tname) mod.EventShapeKey = 'NULL' for n in [2, 3, 4]: setattr(mod, 'DoV%d' % n, False) jtm.add(mod) return mod
def GetSubtractorTool(**kwargs): useClusters = False if 'useClusters' in kwargs.keys(): useClusters = kwargs['useClusters'] elif HIJetFlags.DoCellBasedSubtraction(): useClusters = False else: useClusters = True if useClusters: if not hasattr(jtm, "HIJetClusterSubtractor"): HIJetClusterSubtractorTool = CompFactory.HIJetClusterSubtractorTool jtm.add(HIJetClusterSubtractorTool("HIJetClusterSubtractor")) return jtm.HIJetClusterSubtractor else: if not hasattr(jtm, "HIJetCellSubtractor"): HIJetCellSubtractorTool = CompFactory.HIJetCellSubtractorTool jtm.add(HIJetCellSubtractorTool("HIJetCellSubtractor")) return jtm.HIJetCellSubtractor
def MakeSubtractionTool(shapeKey, moment_name='', momentOnly=False, **kwargs): from HIJetRec.HIJetRecConf import HIJetConstituentSubtractionTool suffix = shapeKey if momentOnly: suffix += '_' + moment_name if 'modulator' in kwargs.keys(): mod_tool = kwargs['modulator'] else: mod_tool = GetNullModulator() subtr = HIJetConstituentSubtractionTool("HICS_" + suffix) subtr.EventShapeKey = shapeKey subtr.Modulator = mod_tool subtr.MomentName = 'JetSubtractedScale%sMomentum' % moment_name subtr.SetMomentOnly = momentOnly subtr.ApplyOriginCorrection = HIJetFlags.ApplyOriginCorrection() subtr.Subtractor = GetSubtractorTool(**kwargs) jtm.add(subtr) return subtr
def AddIteration(seed_container, shape_name, **kwargs): out_shape_name = shape_name if 'suffix' in kwargs.keys(): out_shape_name += '_%s' % kwargs['suffix'] mod_shape_key = out_shape_name + '_Modulate' remodulate = True if 'remodulate' in kwargs.keys(): if not kwargs['remodulate']: mod_tool = GetNullModulator() remodulate = False if remodulate: if 'modulator' in kwargs.keys(): mod_tool = kwargs['modulator'] else: #mod_shape_name=BuildHarmonicName(out_shape_name,**kwargs) mod_tool = MakeModulatorTool(mod_shape_key, **kwargs) if 'map_tool' in kwargs.keys(): map_tool = kwargs['map_tool'] else: from HIEventUtils.HIEventUtilsConf import HIEventShapeMapTool map_tool = HIEventShapeMapTool() assoc_name = jtm.HIJetDRAssociation.AssociationName HIEventShapeJetIteration = CompFactory.HIEventShapeJetIteration iter_tool = HIEventShapeJetIteration('HIJetIteration_%s' % out_shape_name) iter_tool.InputEventShapeKey = shape_name iter_tool.OutputEventShapeKey = out_shape_name iter_tool.AssociationKey = assoc_name iter_tool.CaloJetSeedContainerKey = seed_container iter_tool.Subtractor = GetSubtractorTool(**kwargs) iter_tool.ModulationScheme = HIJetFlags.ModulationScheme() iter_tool.RemodulateUE = HIJetFlags.Remodulate() iter_tool.Modulator = mod_tool iter_tool.ShallowCopy = False iter_tool.ModulationEventShapeKey = mod_shape_key iter_tool.EventShapeMapTool = map_tool if 'track_jet_seeds' in kwargs.keys(): iter_tool.TrackJetSeedContainerKey = kwargs['track_jet_seeds'] jtm.add(iter_tool) jtm.jetrecs += [iter_tool] jtm.HIJetRecs += [iter_tool] return iter_tool
def GetConstituentsModifierTool(**kwargs): #For the cluster key, same exact logic as used for ApplySubtractionToClusters if 'cluster_key' in kwargs.keys(): cluster_key = kwargs['cluster_key'] else: cluster_key = HIJetFlags.HIClusterKey() if 'apply_origin_correction' in kwargs.keys(): apply_origin_correction = kwargs['apply_origin_correction'] else: apply_origin_correction = HIJetFlags.ApplyOriginCorrection() HIJetConstituentModifierTool = CompFactory.HIJetConstituentModifierTool toolName = 'HIJetConstituentModifierTool' if 'name' in kwargs.keys(): toolName = kwargs['name'] cmod = HIJetConstituentModifierTool(toolName) cmod.ClusterKey = cluster_key cmod.Subtractor = GetSubtractorTool(**kwargs) cmod.ApplyOriginCorrection = apply_origin_correction jtm.add(cmod) return cmod
def MakeModulatorTool(mod_key, **kwargs): harmonics = [] if 'harmonics' in kwargs.keys(): harmonics = kwargs['harmonics'] else: harmonics = HIJetFlags.HarmonicsForSubtraction() tname = "Modulator_%s" % BuildHarmonicName(mod_key, harmonics=harmonics) if 'suffix' in kwargs.keys(): tname += '_%s' % kwargs['suffix'] if (len(harmonics) == 0): return GetNullModulator() if hasattr(jtm, tname): return getattr(jtm, tname) HIUEModulatorTool = CompFactory.HIUEModulatorTool mod = HIUEModulatorTool(tname) mod.EventShapeKey = mod_key for n in [2, 3, 4]: val = (n in harmonics) attr_name = 'DoV%d' % n setattr(mod, attr_name, val) jtm.add(mod) return mod
def AddPtAssociationTools(R, doTracks=True): tlist = [] if doTracks and jetFlags.useTracks(): cname = HIJetFlags.TrackJetContainerName() tname = 'hitrackassoc_04' if tname not in jtm.tools: JetPtAssociationTool = CompFactory.JetPtAssociationTool jtm.add( JetPtAssociationTool(tname, InputContainer=cname, AssociationName="GhostTrack")) tlist += [jtm.tools[tname]] if jetFlags.useTruth(): cname = 'AntiKt%dTruthJets' % int(10 * R) tname = 'truthassoc_0%d' % int(10 * R) if tname not in jtm.tools: JetPtAssociationTool = CompFactory.JetPtAssociationTool jtm.add( JetPtAssociationTool(tname, InputContainer=cname, AssociationName="GhostTruth")) tlist += [jtm.tools[tname]] return tlist
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 JetAlgFromTools(rtools, suffix="HI", persistify=True): from HIJetRec.HIJetRecTools import jtm #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] #Now we split in two algorithms to provide input to PseudoJetAlgorithm #rtools=HIJet_exe_tools+rtools from AthenaCommon.AlgSequence import AlgSequence topsequence = AlgSequence() JetToolRunner = CompFactory.JetToolRunner JetAlgorithm = CompFactory.JetAlgorithm if len(HIJet_exe_tools) > 0: jtm += JetToolRunner("jetrunconstit" + suffix, Tools=HIJet_exe_tools, Timer=jetFlags.timeJetToolRunner()) topsequence += JetAlgorithm("jetalgconstit" + suffix, Tools=[jtm.jetrunconstitHI]) # Add the PseudoJetAlgorithm # To avoid massive refactoring and to preserve familiarity, # jet guys kept calling things "getters", but these are already # PseudoJetAlgorithms as they eliminated the wrappers for getter in jtm.allGetters: print('Adding PseudoJetAlgorithm %s' % getter.name) print('Input Container %s' % getter.InputContainer) print('Output Container %s' % getter.OutputContainer) print('Label %s' % getter.Label) topsequence += getter runner = JetToolRunner("jetrun" + suffix, Tools=rtools, Timer=jetFlags.timeJetToolRunner()) jtm.add(runner) theAlg = JetAlgorithm("jetalg" + suffix) theAlg.Tools = [runner] 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
iteration_dict=dict(suffix="iter1") if jetFlags.useTracks() and HIJetFlags.TrackJetSeeds() : iteration_dict['track_jet_seeds']=HIJetFlags.TrackJetContainerName() iter1=AddIteration(seed_container=seeds1.OutputContainer,shape_name=EventShapeKey,**iteration_dict) HIJetFlags.IteratedEventShapeKey=iter1.OutputEventShapeKey modulator1=iter1.Modulator jtm.modulator=modulator1 from HIJetRec.HIJetRecConf import HIClusterSubtraction cluster_update=HIClusterSubtraction('HIClusterUpdate') cluster_update.ClusterKey="HIClusters" cluster_update.EventShapeKey=HIJetFlags.IteratedEventShapeKey() cluster_update.Subtractor=jtm.HIJetClusterSubtractor cluster_update.Modulator=modulator1 cluster_update.UpdateOnly=True jtm.add(cluster_update) jtm.jetrecs += [cluster_update] jtm.HIJetRecs+=[cluster_update] #subtraction BEFORE iteration for moment subtr2=MakeSubtractionTool(HIJetFlags.IteratedEventShapeKey(),modulator=modulator1) ### #subtracted algorithms #make main jets from unsubtr collections w/ same R, add modifiers for subtraction unsubtr_suffix=HIJetFlags.UnsubtractedSuffix() for R in HIJetFlags.AntiKtRValues() : in_name="AntiKt%sHIJets" % int(10*R) copier=jtm.addJetCopier("DF"+in_name,in_name,GetHIModifierList(in_name,[subtr2],[jtm.jetfilHI,jtm.jetsorter]),shallow=False) jtm.HIJetRecs+=[copier]