2 from AthenaCommon 
import Logging
 
    3 from AthenaConfiguration.ComponentFactory 
import CompFactory
 
    4 from AthenaConfiguration.ComponentAccumulator 
import ComponentAccumulator
 
    5 ufolog = Logging.logging.getLogger(
'TCCorUFO')
 
   12     if vxContName2 == vxContName1 : 
return vxContName1
 
   13     if "" in [vxContName1, vxContName2] : 
return vxContName1 
or vxContName2
 
   14     raise Exception(
" Error : incompatible VertexContainerName of 2 instance of TrackParticleClusterAssociationAlg : '{}' and '{}'".
format(vxContName1, vxContName2))
 
   30     """Simple helper returning a function to build decoration keys """ 
   31     return lambda d : trackParticleName+
'.'+d+assocPostfix
 
   33 def setupTrackCaloAssoc(flags, caloClusterName="CaloCalTopoClusters",detectorEtaName="default",trackParticleName="InDetTrackParticles", assocPostfix = "TCC", onlyPV0Tracks=False):
 
   34     """ Schedule a TrackParticleClusterAssociationAlg in the top sequence, taking as input clusters and tracks defined  
   35     by the keys caloClusterName and trackParticleName. 
   37     onlyPV0Tracks : calculate associated clusters only for PV0 tracks. Avoids unnecessary calculation (used in the UFO case). 
   38        (IMPORTANT CaloExtensionBuilderAlg does extrapolate all tracks : if too much time consuming, it needs a new option to mask non-PV0 tracks) 
   47     from TrackToCalo.CaloExtensionBuilderAlgCfg 
import CaloExtensionBuilderAlgCfg 
 
   49     caloExtAlg.TrkPartContainerName = trackParticleName
 
   51     components.merge(caloExtAlg)    
 
   53     from TrackVertexAssociationTool.TrackVertexAssociationToolConfig 
import TTVAToolCfg
 
   54     TrackVertexAssoTool = components.popToolsAndMerge(
 
   55         TTVAToolCfg(flags, 
"tvaTool", WorkingPoint=
"Nonprompt_All_MaxWeight"))
 
   57     trackParticleClusterAssociation = CompFactory.TrackParticleClusterAssociationAlg(
 
   58         "TrackParticleClusterAssociationAlg"+assocPostfix,
 
   60         TrackParticleContainerName = trackParticleName,
 
   62         CaloExtensionName = (caloExtAlg.getEventAlgos()[0]).ParticleCache, 
 
   63         CaloClusterLocation = caloClusterName,
 
   64         DetectorEtaName = detectorEtaName 
if detectorEtaName.lower() != 
"default" else (
"DetectorEta" if "Origin" in caloClusterName 
else ""),
 
   65         TrackVertexAssoTool=TrackVertexAssoTool, 
 
   66         VertexContainerName = 
"PrimaryVertices" if onlyPV0Tracks 
else "",
 
   68         AssociatedClusterDecorKey = decorKey(
"AssoClusters"),
 
   69         UseCovariance = flags.UFO.UseCov,
 
   70         DeltaR = flags.UFO.dR,
 
   75     components.addEventAlgo( trackParticleClusterAssociation )
 
   80 def runTCCReconstruction(flags, caloClusterName="CaloCalTopoClusters", detectorEtaName = "default", trackParticleName="InDetTrackParticles",
 
   81                          assocPostfix="TCC", doCombined=False, doCharged=False, doNeutral=True, outputTCCName="TrackCaloClusters"):
 
   83     Create a TrackCaloCluster collection from clusters and tracks (caloClusterName and trackParticleName). 
   84     Depending on options, the collection contains combined, neutral and/or charged TCC. 
   85     This functions schedules 2 TCC specific algs : 
   86        * a TrackCaloClusterInfoAlg to build the TrackCaloClusterInfo object 
   87        * a TrackCaloClusterAlg to build the TCC 
   90     from AthenaConfiguration.ComponentAccumulator 
import ComponentAccumulator
 
   97         setupTrackCaloAssoc(flags, caloClusterName, detectorEtaName, trackParticleName, assocPostfix, onlyPV0Tracks=
False)
 
  102     tccInfoAlg = CompFactory.TrackCaloClusterInfoAlg(
 
  104         TCCInfoName = 
"TCCInfo",
 
  105         InputTracks = trackParticleName,
 
  106         InputClusters = caloClusterName,
 
  107         VertexContainer = 
"PrimaryVertices",
 
  108         AssoClustersDecor = decorKey(
"AssoClusters"),
 
  111     components.addEventAlgo( tccInfoAlg) 
 
  118     from TrackVertexAssociationTool.TrackVertexAssociationToolConfig 
import TTVAToolCfg
 
  120         TrackVertexAssoTool = components.popToolsAndMerge(
 
  121             TTVAToolCfg(flags,
"tvaTool",WorkingPoint=
"Nonprompt_All_MaxWeight")),
 
  122         AssoClustersDecor=decorKey(
"AssoClusters"),            
 
  126         tccCombined = CompFactory.TCCCombinedTool(
"TCCcombined", **commonArgs)
 
  127         tccTools.append(tccCombined)
 
  129         tccCharged = CompFactory.TCCChargedTool(
"TCCCharged", **commonArgs )
 
  130         tccTools.append(tccCharged)
 
  132         tccNeutral = CompFactory.TCCNeutralTool(
"TCCNeutral", **commonArgs )        
 
  133         tccTools.append(tccNeutral)
 
  135     tccAlg = CompFactory.TrackCaloClusterAlg(name = 
"TrackCaloClusterAlg",
 
  136             OutputTCCName = outputTCCName,
 
  141     components.addEventAlgo(tccAlg)
 
  146 def runUFOReconstruction(flags, constits, caloClusterName="CaloCalTopoClusters", detectorEtaName = "default", assocPostfix="UFO", inputFEcontainerkey=""):
 
  148     """Create a UFO collection from PFlow and tracks (PFO retrieved from PFOPrefix and tracks directly from trackParticleName).  
  149     This functions schedules 2 UFO specific algs :  
  150        * a TrackCaloClusterInfoUFOAlg to build the TrackCaloClusterInfo object 
  151        * a TrackCaloClusterAlg to build the UFO 
  153     from JetRecConfig.JetDefinition 
import JetDefinition
 
  154     from AthenaConfiguration.ComponentAccumulator 
import ComponentAccumulator
 
  157     if isinstance(constits, JetDefinition):
 
  159         constits = jdef.inputdef
 
  160         trackParticleName = jdef._contextDic[
'Tracks'] 
 
  162         trackParticleName = 
"InDetTrackParticles" 
  164     pfoVariant= constits.label.split(
"PFlow")[-1] 
 
  171         setupTrackCaloAssoc(flags, caloClusterName, detectorEtaName, trackParticleName, assocPostfix, onlyPV0Tracks=
False) 
 
  175     from TrackVertexAssociationTool.TrackVertexAssociationToolConfig 
import TTVAToolCfg
 
  177         TrackVertexAssoTool = components.popToolsAndMerge(
 
  178             TTVAToolCfg(flags,
"tvaTool",WorkingPoint=
"Nonprompt_All_MaxWeight")),
 
  179         AssoClustersDecor=decorKey(
"AssoClusters"),
 
  183     inputFEcontainerkey = inputFEcontainerkey 
or constits.containername
 
  186     UFOInfoAlg = CompFactory.TrackCaloClusterInfoUFOAlg(f
"UFOInfoAlg{pfoVariant}",
 
  187                                                         TCCInfoName = pfoVariant+
"UFOInfo",
 
  188                                                         InputTracks = trackParticleName,
 
  189                                                         InputClusters = caloClusterName,
 
  190                                                         VertexContainer = 
"PrimaryVertices",
 
  191                                                         InputPFO=inputFEcontainerkey, 
 
  192                                                         OriginPFO=
'originalObjectLink',
 
  198     components.addEventAlgo( UFOInfoAlg) 
 
  200     tccUFO = CompFactory.UFOTool(f
"UFOtool{pfoVariant}",
 
  201                                  ClusterECut = UFOInfoAlg.ClusterECut,                     
 
  202                                  InputPFO=inputFEcontainerkey, 
 
  203                                  OriginPFO=
'originalObjectLink',
 
  207     UFOAlg = CompFactory.TrackCaloClusterAlg(name = f
"TrackCaloClusterAlgUFO{pfoVariant}",
 
  208                                              OutputTCCName = f
"UFO{pfoVariant}",
 
  209                                              TCCInfo = UFOInfoAlg.TCCInfoName ,
 
  210                                              TCCTools = [tccUFO,],
 
  215     components.addEventAlgo( UFOAlg)