5 from JetRecConfig 
import JetRecConfig
 
    6 from AthenaConfiguration.ComponentFactory 
import CompFactory
 
    7 from AthenaConfiguration.ComponentAccumulator 
import ComponentAccumulator
 
    9 from TrigEDMConfig.TriggerEDM 
import recordable
 
   11 from . 
import JetRecoCommon
 
   12 from JetRecConfig.JetDefinition 
import JetModifier
 
   13 from JetRecConfig.JetRecConfig 
import getJetCopyAlg
 
   15 from AthenaCommon.Logging 
import logging
 
   16 logging.getLogger().
info(
"JetHIConfig LOG: Importing %s",__name__)
 
   17 log = logging.getLogger(__name__)
 
   23     jetNamePrefix = JetRecoCommon.getHLTPrefix()
 
   24     clustersKey = JetRecoCommon.getClustersKey(jetRecoDict)
 
   25     jetDef_unsub = JetRecoCommon.defineHIJets(jetRecoDict,clustersKey=clustersKey,prefix=jetNamePrefix,suffix=
"_Unsubtracted")
 
   26     jetDef_unsub._internalAtt[
'finalPJContainer'] = 
"PseudoJet"+clustersKey
 
   27     target_jetReco = f
"_for_{jetRecoDict['jetDefStr']}" 
   30     associationName = 
"%s_DR8Assoc" % (clustersKey)
 
   31     jetDef_seed0 = jetDef_unsub.clone()
 
   32     jetDef_seed0.suffix = jetDef_unsub.suffix.replace(
"Unsubtracted", 
"seed0"+target_jetReco)
 
   33     jetDef_seed0.radius = 0.2
 
   34     jetsFullName_seed0 = jetDef_seed0.fullname()
 
   37     stdJetModifiers.update(
 
   39         HLTHIJetAssoc = JetModifier(
"HIJetDRAssociationTool",
"HIJetDRAssociation", ContainerKey=clustersKey, DeltaR=0.8, AssociationName=associationName),
 
   43     jetDef_seed0.modifiers=[
 
   45         JetModifier(
"HIJetMaxOverMeanTool",
"HIJetMaxOverMean"+target_jetReco, JetContainer = jetsFullName_seed0),
 
   46         JetModifier(
"HIJetDiscriminatorTool",
"HIJetDiscriminator", MaxOverMeanCut = 4, MinimumETMaxCut=3000),
 
   52     if jetRecoDict[
"jetCalib"].endswith(
"IS") 
and not flags.Input.isMC:
 
   54          calib_seq += 
"_Insitu" 
   58     if jetRecoDict[
"ionopt"] == 
"ionp":
 
   62     jetDef_seed1 = jetDef_unsub.clone()
 
   63     jetDef_seed1.suffix = jetDef_seed0.suffix.replace(
"_seed0",
"_seed1")
 
   64     jetDef_seed1.radius = 0.2
 
   65     jetDef_seed1.modifiers=[
"HLTHIJetAssoc", 
"HLTHIJetConstSub_iter0:iter0", 
"HLTHIJetSeedCalib:{}___{}".
format(calib_seq, JES_is_data), 
"Filter:{}".
format(SeedPtMin)]
 
   68     RecoOutputPtMin = 20000
 
   69     if jetRecoDict[
"ionopt"] == 
"ionp":
 
   70         RecoOutputPtMin = 10000
 
   71     jetDef_final = jetDef_unsub.clone()
 
   72     jetDef_final.suffix = jetDef_unsub.suffix.replace(
"_Unsubtracted",
"")
 
   73     jetDef_final.modifiers=[
"HLTHIJetConstSub_iter1:iter1", 
"HLTHIJetJetConstMod_iter1", 
"HLTHIJetCalib:{}___{}".
format(calib_seq, JES_is_data), 
"Sort", 
"Filter:{}".
format(RecoOutputPtMin)]
 
   76         "unsub": (jetDef_unsub.fullname(), jetDef_unsub),
 
   77         "seed0": (jetDef_seed0.fullname(), jetDef_seed0),
 
   78         "seed1": (jetDef_seed1.fullname(), jetDef_seed1),
 
   79         "final": (jetDef_final.fullname(), jetDef_final),
 
   87     eventShapeMapToolKey=
"HLTHIEventShapeMapTool" 
   88     theMapTool=CompFactory.HIEventShapeMapTool(eventShapeMapToolKey)
 
   91     EventShapeKey=
'HLTHIEventShapeWeighted' 
   92     ESAlg_W=CompFactory.HIEventShapeMaker(
"ESAlg_W")
 
   93     ESAlg_W.OutputContainerKey=EventShapeKey
 
   94     ESAlg_W.InputTowerKey=clustersKey
 
   95     ESAlg_W.NaviTowerKey=towerKey
 
   98     ESFiller=CompFactory.HIEventShapeFillerTool(
"WeightedFiller")
 
   99     ESFiller.UseClusters=
True 
  102     TWTool=CompFactory.HITowerWeightTool()
 
  103     TWTool.ApplyCorrection={
"ion": 
True, 
"ionp": 
False}.
get(jetRecoDict[
"ionopt"])
 
  104     TWTool.ConfigDir=
'HIJetCorrection/' 
  105     from HIJetRec.HIJetRecUtilsCA 
import getHIClusterGeoWeightFile
 
  108     ESFiller.TowerWeightTool=TWTool
 
  109     ESFiller.EventShapeMapTool=theMapTool
 
  111     ESAlg_W.HIEventShapeFillerTool=ESFiller
 
  112     acc.addEventAlgo(ESAlg_W)
 
  114     return acc, EventShapeKey, theMapTool
 
  118 from JetRecConfig.StandardJetMods 
import stdJetModifiers
 
  119 stdJetModifiers.update(
 
  120     HLTHIJetCalib = JetModifier(
"JetCalibrationTool",
 
  121                                 "HLTHICalibTool_{modspec}",
 
  122                                 JetCollection=
lambda _, modspec: modspec.split(
'___')[2] 
if len(modspec.split(
'___')) > 2 
else "AntiKt4HI",
 
  123                                 PrimaryVerticesContainerName=
"",
 
  124                                 ConfigFile=
'JES_MC16_HI_Jan2021_5TeV.config',
 
  125                                 CalibSequence=
lambda _, modspec: modspec.split(
'___')[0],
 
  126                                 IsData=
lambda _, modspec: modspec.split(
'___')[1] == 
'True'),
 
  129 stdJetModifiers.update(
 
  130     HLTHIJetSeedCalib = JetModifier(
"JetCalibrationTool",
 
  131                                 "HLTHISeedCalibTool_{modspec}",
 
  132                                 JetCollection=
"AntiKt2HI",
 
  133                                 PrimaryVerticesContainerName=
"",
 
  134                                 ConfigFile=
'JES_MC16_HI_Jan2021_5TeV.config',
 
  135                                 CalibSequence=
lambda _, modspec: modspec.split(
'___')[0],
 
  136                                 IsData=
lambda _, modspec: modspec.split(
'___')[1] == 
'True'),
 
  140     """This build the standard heavy ion style jet. 
  142     This is similar to JetRecConfig.getJetDefAlgs(). However due to how the alg flow is organized in the 
  143     chain steps, we can't use this function directly. 
  145       - construct a JetDefinition 
  146       - use lower-level function in JetRecConfig with this JetDefinition to get the necessary algs and build our sequence manually. 
  151     if jetRecoDict[
"ionopt"] == 
"noion":
 
  152          raise ValueError(
"Jet reco for heavy ion called without a ion option!")
 
  154     dataSource = 
"mc" if configFlags.Input.isMC 
else "data" 
  156     jetHIEvtShapeSequence, eventShapeKey, eventShapeMapTool = 
jetHIEventShapeSequenceCA(configFlags, clustersKey=clustersKey, towerKey=towerKey, **jetRecoDict)
 
  157     acc.merge(jetHIEvtShapeSequence)
 
  159     jetNamePrefix = JetRecoCommon.getHLTPrefix()
 
  160     jetDef = JetRecoCommon.defineHIJets(jetRecoDict,clustersKey=clustersKey,prefix=jetNamePrefix,suffix=
"_Unsubtracted")
 
  161     jetsFullName_Unsub = jetDef.fullname()
 
  164     jet_collection_name = jetsFullName_Unsub.split(
'_')[1].
replace(
"Jets", 
"")
 
  167     pjgalg = CompFactory.PseudoJetAlgorithm(
 
  169         InputContainer = clustersKey,
 
  170         OutputContainer = 
"PseudoJet"+clustersKey,
 
  172         SkipNegativeEnergy = 
False,
 
  173         TreatNegativeEnergyAsGhost=
True 
  175     acc.addEventAlgo(pjgalg)
 
  176     finalpjs = 
str(pjgalg.OutputContainer)
 
  179     jetDef._internalAtt[
'finalPJContainer'] = finalpjs
 
  182     from JetRec 
import JetOnlineMon
 
  186     jetRecAlg = 
getHIJetRecAlg(jetDef, jetsFullName_Unsub, monTool=monTool)
 
  187     acc.addEventAlgo(jetRecAlg)
 
  189     associationName = 
"%s_DR8Assoc" % (clustersKey)
 
  191     jetsInUnsub = jetsFullName_Unsub
 
  195     if jetRecoDict[
"jetCalib"].endswith(
"IS") 
and (dataSource==
"data"):
 
  197          calib_seq += 
"_Insitu" 
  199     target_jetReco = f
'_for_{jetRecoDict["jetDefStr"]}' 
  202     vnharmonics = [2,3,4]
 
  203     if jetRecoDict[
"ionopt"] == 
"ionp":
 
  208     jetDef_seed0 = jetDef.clone()
 
  209     jetDef_seed0.suffix = jetDef.suffix.replace(
"Unsubtracted", 
"seed0"+target_jetReco)
 
  210     jetDef_seed0.radius = 0.2
 
  211     jetsFullName_seed0 = jetDef_seed0.fullname()
 
  212     jetDef_seed0.modifiers=[
 
  213         JetModifier(
"HIJetDRAssociationTool",
"HIJetDRAssociation", ContainerKey=clustersKey, DeltaR=0.8, AssociationName=associationName),
 
  214         JetModifier(
"HIJetMaxOverMeanTool",
"HIJetMaxOverMean"+target_jetReco, JetContainer = jetsFullName_seed0),
 
  215         JetModifier(
"HIJetDiscriminatorTool",
"HIJetDiscriminator", MaxOverMeanCut = 4, MinimumETMaxCut=3000),
 
  219     copySeed0Alg = 
getJetCopyAlg(jetsin=jetsInUnsub,jetsoutdef=jetDef_seed0,decorations=[],shallowcopy=
False,shallowIO=
False,monTool=monTool)
 
  220     acc.addEventAlgo(copySeed0Alg)
 
  223     iter0=
HLTAddIteration(configFlags, jetsFullName_seed0, eventShapeKey, clustersKey, map_tool=eventShapeMapTool, assoc_name=associationName, suffix=
"iter0"+target_jetReco, harmonics = vnharmonics) 
 
  224     acc.addEventAlgo(
HLTRunTools([iter0], 
"jetalgHI_iter0"+target_jetReco))
 
  225     modulator0=iter0.Modulator
 
  226     subtractor0=iter0.Subtractor
 
  228     HLTMakeSubtractionTool(configFlags, iter0.OutputEventShapeKey, Modulator=modulator0, EventShapeMapTool=eventShapeMapTool, Subtractor=subtractor0, label=
"HLTHIJetConstSub_iter0"+target_jetReco)
 
  230     cluster_key_iter0_deep=clustersKey+
"_iter0_temp"+target_jetReco
 
  231     happy_iter0_Tool = 
ApplySubtractionToClustersHLT(configFlags, EventShapeKey=
"HLTHIEventShapeWeighted_iter0"+target_jetReco, ClusterKey=clustersKey, OutClusterKey=cluster_key_iter0_deep, Modulator=modulator0, EventShapeMapTool=eventShapeMapTool, Subtractor=subtractor0, SetMoments=
False, ApplyOriginCorrection=
False)
 
  232     acc.addEventAlgo(
HLTRunTools([happy_iter0_Tool], 
"jetalgHI_clusterSub_iter0"+target_jetReco))
 
  234     GetConstituentsModifierToolHLT(configFlags, name=
"HIJetConstituentModifierTool", ClusterKey=cluster_key_iter0_deep, ApplyOriginCorrection=
False, label=
"HLTHIJetJetConstMod_iter0"+target_jetReco)
 
  238     jetDef_seed1 = jetDef.clone()
 
  239     jetDef_seed1.suffix = jetDef_seed0.suffix.replace(
"_seed0",
"_seed1")
 
  240     jetDef_seed1.radius = 0.2
 
  241     jetDef_seed1.modifiers=[
"HLTHIJetAssoc", f
"HLTHIJetConstSub_iter0{target_jetReco}:iter0", 
"HLTHIJetSeedCalib:{}___{}".
format(calib_seq, JES_is_data), 
"Filter:{}".
format(SeedPtMin)]
 
  242     jetsFullName_seed1 = jetDef_seed1.fullname()
 
  243     copySeed1Alg = 
getJetCopyAlg(jetsin=jetsInUnsub,jetsoutdef=jetDef_seed1,decorations=[],shallowcopy=
False,shallowIO=
False,monTool=monTool)
 
  244     acc.addEventAlgo(copySeed1Alg)
 
  246     iter1=
HLTAddIteration(configFlags, jetsFullName_seed1, eventShapeKey, clustersKey, map_tool=eventShapeMapTool, assoc_name=associationName, sub_tool=subtractor0, suffix=
"iter1"+target_jetReco, harmonics = vnharmonics)
 
  247     iter1.OutputEventShapeKey=
"HLTHIEventShape_iter1"+target_jetReco
 
  248     modulator1=iter1.Modulator
 
  249     subtractor1=iter1.Subtractor
 
  251     HLTMakeSubtractionTool(configFlags, iter1.OutputEventShapeKey, Modulator=modulator1, EventShapeMapTool=eventShapeMapTool, label=
"HLTHIJetConstSub_iter1"+target_jetReco)
 
  253     acc.addEventAlgo(
HLTRunTools([iter1], 
"jetalgHI_clusterSub_egamma"+target_jetReco))
 
  256     cluster_key_final_deep=clustersKey+
"_final"+target_jetReco
 
  257     subToClusterTool = 
ApplySubtractionToClustersHLT(configFlags, EventShapeKey=
"HLTHIEventShape_iter1"+target_jetReco, ClusterKey=clustersKey, OutClusterKey=cluster_key_final_deep, Modulator=modulator1, EventShapeMapTool=eventShapeMapTool, Subtractor=subtractor1, SetMoments=
False, ApplyOriginCorrection=
False)
 
  258     acc.addEventAlgo(
HLTRunTools([subToClusterTool], 
"jetalgHI_clusterSub"+target_jetReco))
 
  260     GetConstituentsModifierToolHLT(configFlags, name=
"HIJetConstituentModifierTool", ClusterKey=cluster_key_final_deep, ApplyOriginCorrection=
False, label=
"HLTHIJetJetConstMod_iter1"+target_jetReco)
 
  262     RecoOutputPtMin = 20000
 
  263     if jetRecoDict[
"ionopt"] == 
"ionp":
 
  264         RecoOutputPtMin = 10000
 
  265     jetDef_final = jetDef.clone()
 
  266     jetDef_final.suffix = jetDef.suffix.replace(
"_Unsubtracted",
"")
 
  267     jetDef_final.modifiers=[f
"HLTHIJetConstSub_iter1{target_jetReco}:iter1", 
"HLTHIJetJetConstMod_iter1"+target_jetReco, 
"HLTHIJetCalib:{}___{}___{}".
format(calib_seq, JES_is_data, jet_collection_name), 
"Sort", 
"Filter:{}".
format(RecoOutputPtMin)]
 
  268     copyAlg_final= 
getJetCopyAlg(jetsin=jetsInUnsub,jetsoutdef=jetDef_final,decorations=[],shallowcopy=
False,shallowIO=
False,monTool=monTool)
 
  269     acc.addEventAlgo(copyAlg_final)
 
  271     jetsFinal = 
recordable(jetDef_final.fullname())
 
  275     return acc, jetsOut, jetDef_final
 
  279     theAlg = CompFactory.JetAlgorithm(algoName)
 
  280     theAlg.Tools = toollist 
 
  285     """Returns the configured HIJetRecAlg instance corresponding to jetdef 
  287     IMPORTANT : jetdef must have its dependencies solved (i.e. it must result from solveDependencies() ) 
  289     pjContNames = jetdef._internalAtt[
'finalPJContainer']
 
  290     jclust = CompFactory.JetClusterer(
 
  292         JetAlgorithm = jetdef.algorithm,
 
  293         JetRadius = jetdef.radius,
 
  294         PtMin = jetdef.ptmin,
 
  295         InputPseudoJets = pjContNames,
 
  297         JetInputType = 
int(jetdef.inputdef.jetinputtype),
 
  301     mods = JetRecConfig.getJetModifierTools(jetdef)
 
  304     jra = CompFactory.JetRecAlg(
 
  305         "jetrecalg_"+jetname,
 
  308         OutputContainer = jetname,
 
  312         jra.MonTool = monTool
 
  318     out_shape_name=shape_name
 
  319     if 'suffix' in kwargs.keys() : out_shape_name+=
'_' + kwargs[
'suffix']
 
  320     mod_shape_key=out_shape_name+
'_Modulate' 
  323         if 'modulator' in kwargs.keys() : mod_tool=kwargs[
'modulator']
 
  325             log.info( 
"In HLTAddIteration function, HIUEModulatorTool is created using HLTMakeModulatorTool with mod_shape_key = {}".
format(mod_shape_key) )
 
  328     if 'map_tool' in kwargs.keys() : map_tool=kwargs[
'map_tool']
 
  330         map_tool=CompFactory.HIEventShapeMapTool()
 
  332     if 'sub_tool' in kwargs.keys() : sub_tool=kwargs[
'sub_tool']
 
  334         from HIJetRec.HIJetRecUtilsCA 
import getHIClusterGeoWeightFile
 
  337         HIJetClusterSubtractorTool=CompFactory.HIJetClusterSubtractorTool
 
  339         sub_tool.UseSamplings=
False 
  341     if 'assoc_name' in kwargs.keys() : assoc_name=kwargs[
'assoc_name']
 
  343         log.info( 
"In HLTAddIteration function, HIJetDRAssociationTool is created with clustersKey= {}".
format(clustersKey) )
 
  344         assoc=CompFactory.HIJetDRAssociationTool(
"HIJetDRAssociation")
 
  345         assoc.ContainerKey=clustersKey
 
  347         assoc.AssociationName=
"%s_DR8Assoc" % (clustersKey)
 
  348         assoc_name=assoc.AssociationName
 
  350     HIEventShapeJetIteration=CompFactory.HIEventShapeJetIteration
 
  353     iter_tool.InputEventShapeKey=shape_name
 
  354     iter_tool.OutputEventShapeKey=out_shape_name
 
  355     iter_tool.AssociationKey=assoc_name
 
  356     iter_tool.CaloJetSeedContainerKey=seed_container
 
  357     iter_tool.Subtractor=sub_tool
 
  358     iter_tool.ModulationScheme=1
 
  359     iter_tool.RemodulateUE=
True 
  360     iter_tool.Modulator=mod_tool
 
  361     iter_tool.ShallowCopy=
False 
  362     iter_tool.ModulationEventShapeKey=mod_shape_key
 
  363     iter_tool.EventShapeMapTool=map_tool
 
  369     if 'harmonics' in kwargs.keys() :
 
  370         for n 
in kwargs[
'harmonics'] :
 
  371             tname = 
str(tname) + 
str(
'_V%d' % n)
 
  375     tname=
'NullUEModulator' 
  376     HIUEModulatorTool=CompFactory.HIUEModulatorTool
 
  379     for n 
in [2,3,4] : setattr(mod,
'DoV%d' % n,
False)
 
  383     harmonics = kwargs.pop(
'harmonics', [2, 3, 4])
 
  386     if 'suffix' in kwargs.keys():
 
  387         tname += 
'_' + kwargs[
'suffix']
 
  389     if len(harmonics) == 0:
 
  392     HIUEModulatorTool=CompFactory.HIUEModulatorTool
 
  394     mod.EventShapeKey=mod_key
 
  398         attr_name=
'DoV%d' % n
 
  399         setattr(mod,attr_name,val)  
 
  401     if 'label' in kwargs.keys():
 
  402         label = kwargs[
'label']
 
  403         stdJetModifiers[label] = JetModifier(
 
  409             EventShapeKey=mod_key)
 
  414     from HIJetRec.HIJetRecUtilsCA 
import getHIClusterGeoWeightFile
 
  417     HIJetClusterSubtractorTool = CompFactory.HIJetClusterSubtractorTool
 
  419     sub_tool.UseSamplings = 
False 
  427         'EventShapeKey': shapeKey,
 
  429         'EventShapeMapTool': CompFactory.HIEventShapeMapTool(),
 
  431         'MomentName': 
'HLTJetSubtractedScale{}Momentum'.
format(moment_name),
 
  432         'SetMomentOnly': momentOnly,
 
  433         'ApplyOriginCorrection': 
True,
 
  436     suffix = shapeKey.toStringProperty()
 
  437     if momentOnly 
is True:
 
  438         suffix += 
'_' + moment_name
 
  440     alg_props.update(kwargs)
 
  442     label = alg_props.pop(
'label', 
None)
 
  444     HIJetConstituentSubtractionTool = CompFactory.HIJetConstituentSubtractionTool
 
  447     stdJetModifiers[label] = JetModifier(
 
  448         "HIJetConstituentSubtractionTool",
 
  449         "HLTHICS_HLTHIEventShapeWeighted_{modspec}",
 
  450         Modulator=subtr.Modulator,
 
  451         EventShapeMapTool=subtr.EventShapeMapTool,
 
  452         Subtractor=subtr.Subtractor,
 
  453         EventShapeKey=subtr.EventShapeKey,
 
  454         MomentName=subtr.MomentName,
 
  455         SetMomentOnly=subtr.SetMomentOnly,
 
  456         ApplyOriginCorrection=
True)
 
  460 def HLTHIClusterGetter(dummyFlags, tower_key="CombinedTower", cell_key="AllCalo", cluster_key="HLT_HIClusters") :
 
  461     """Function to equip HLT HI cluster builder from towers and cells, adds to output AOD stream""" 
  463     HIClusterMaker=CompFactory.HIClusterMaker
 
  465     theAlg.InputTowerKey=tower_key
 
  466     theAlg.CaloCellContainerKey=cell_key
 
  467     theAlg.OutputContainerKey=cluster_key
 
  475         'EventShapeKey': 
"HLTHIEventShape_iter1",
 
  476         'ClusterKey': 
"HLT_HIClusters",
 
  478         'EventShapeMapTool': CompFactory.HIEventShapeMapTool(),
 
  480         'ApplyOriginCorrection': 
True,
 
  485     alg_props.update(kwargs)
 
  487     toolName = alg_props.pop(
'toolName', 
'HIClusterSubtraction')
 
  489     HIClusterSubtraction = CompFactory.HIClusterSubtraction
 
  498         'ClusterKey': 
"HLT_HIClusters",
 
  499         'ApplyOriginCorrection': 
True,
 
  503     alg_props.update(kwargs)
 
  505     toolName = alg_props.pop(
'name', 
'HIJetConstituentModifierTool')
 
  506     label = alg_props.pop(
'label', 
None)
 
  508     HIJetConstituentModifierTool = CompFactory.HIJetConstituentModifierTool
 
  511     stdJetModifiers[label] = JetModifier(
 
  512         "HIJetConstituentModifierTool",
 
  513         "HLTHIJetConstituentModifierTool_{modspec}",
 
  514         ClusterKey=cmod.ClusterKey,
 
  515         Subtractor=cmod.Subtractor,
 
  516         ApplyOriginCorrection=cmod.ApplyOriginCorrection)