ATLAS Offline Software
ParticleJetToolsConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 
10 
11 from AthenaCommon import Logging
12 jrtlog = Logging.logging.getLogger('ParticleJetToolsConfig')
13 
14 from AthenaConfiguration.ComponentFactory import CompFactory
15 # workaround for missing JetRecConfig in AthAnalysis
16 try:
17  from JetRecConfig.JetRecConfig import isAnalysisRelease
18 except ModuleNotFoundError:
20  return True
21 
22 # Putting MCTruthClassifier here as we needn't stick jet configs in really foreign packages
24  # Assume mc15 value
25  truthclassif = CompFactory.MCTruthClassifier(
26  "JetMCTruthClassifier"
27  )
28  if not isAnalysisRelease() :
29  truthclassif.xAODTruthLinkVector= ""
30  # Config neessary only for Athena releases
31  import os
32  if "AtlasProject" in os.environ.keys():
33  if os.environ["AtlasProject"] in ["Athena","AthDerivation"]:
34  truthclassif.ParticleCaloExtensionTool=""
35  return truthclassif
36 
37 # Generates truth particle containers for truth labeling
38 truthpartoptions = {
39  "Partons":{"ToolType":CompFactory.CopyTruthPartons,"ptmin":5000},
40  "BosonTop":{"ToolType":CompFactory.CopyBosonTopLabelTruthParticles,"ptmin":100000},
41  "FlavourLabel":{"ToolType":CompFactory.CopyFlavorLabelTruthParticles,"ptmin":5000},
42 }
44  toolProperties = {}
45  if truthtype == "Partons":
46  truthcategory = "Partons"
47  elif truthtype in ["WBosons", "ZBosons", "HBosons", "TQuarksFinal"]:
48  truthcategory = "BosonTop"
49  toolProperties['ParticleType'] = truthtype
50  else:
51  truthcategory = "FlavourLabel"
52  toolProperties['ParticleType'] = truthtype
53 
54  tooltype = truthpartoptions[truthcategory]["ToolType"]
55  toolProperties.update( PtMin = truthpartoptions[truthcategory]["ptmin"],
56  OutputName = "TruthLabel"+truthtype)
57  ctp = tooltype("truthpartcopy_"+truthtype,
58  **toolProperties
59  )
60  return ctp
61 
62 # Generates input truth particle containers for truth jets
63 def getCopyTruthJetParticles(modspec, cflags):
64  truthclassif = getMCTruthClassifier()
65 
66  truthpartcopy = CompFactory.CopyTruthJetParticles(
67  "truthpartcopy"+modspec,
68  OutputName="JetInputTruthParticles"+modspec,
69  MCTruthClassifier=truthclassif)
70  if modspec=="NoWZ":
71  truthpartcopy.IncludePromptLeptons=False
72  truthpartcopy.IncludePromptPhotons=False
73  truthpartcopy.IncludeMuons=True
74  truthpartcopy.IncludeNeutrinos=True
75  if modspec=="DressedWZ":
76  truthpartcopy.IncludePromptLeptons=False
77  truthpartcopy.IncludePromptPhotons=True
78  truthpartcopy.IncludeMuons=True
79  truthpartcopy.IncludeNeutrinos=True
80  truthpartcopy.DressingDecorationName='dressedPhoton'
81 
82  truthpartcopy.ExtraInputs = {( 'xAOD::TruthParticleContainer' , 'StoreGateSvc+TruthParticles.dressedPhoton' )}
83  if modspec=="Charged":
84  truthpartcopy.ChargedParticlesOnly=True
85  return truthpartcopy
86 
87 
89  """Internal unlity to name labels
90 
91  Returns a dictionary to configure labeling tools. Takes one
92  argument which is prefixed to each label.
93  """
94  return dict(
95  LabelName=f"{prefix}TruthLabelID",
96  DoubleLabelName=f"{prefix}ExtendedTruthLabelID",
97  LabelPtName=f"{prefix}TruthLabelPt",
98  LabelLxyName=f"{prefix}TruthLabelLxy",
99  LabelDRName=f"{prefix}TruthLabelDR",
100  LabelPdgIdName=f"{prefix}TruthLabelPdgId",
101  LabelPositionDPhiName=f"{prefix}TruthLabelPositionDPhi",
102  LabelPositionDEtaName=f"{prefix}TruthLabelPositionDEta",
103  LabelBarcodeName=f"{prefix}TruthLabelBarcode",
104  ChildLxyName=f"{prefix}TruthLabelChildLxy",
105  ChildPtName=f"{prefix}TruthLabelChildPt",
106  ChildPdgIdName=f"{prefix}TruthLabelChildPdgId",
107  ChildPositionDPhiName=f"{prefix}TruthLabelChildPositionDPhi",
108  ChildPositionDEtaName=f"{prefix}TruthLabelChildPositionDEta",
109  )
110 
111 
112 def getJetDeltaRFlavorLabelTool(name='jetdrlabeler', jet_pt_min=5000):
113  """Get the standard flavor tagging delta-R labeling tool
114 
115  Uses cone matching to B, C and tau truth particles.
116  """
117  return CompFactory.ParticleJetDeltaRLabelTool(
118  name,
119  **_getCommonLabelNames("HadronConeExcl"),
120  BLabelName = "ConeExclBHadronsFinal",
121  CLabelName = "ConeExclCHadronsFinal",
122  TauLabelName = "ConeExclTausFinal",
123  BParticleCollection = "TruthLabelBHadronsFinal",
124  CParticleCollection = "TruthLabelCHadronsFinal",
125  TauParticleCollection = "TruthLabelTausFinal",
126  PartPtMin = 5000.,
127  DRMax = 0.3,
128  MatchMode = "MinDR",
129  JetPtMin = jet_pt_min,
130  )
131 
132 
133 def getJetDeltaRLabelTool(jetdef, modspec):
134  """returns a ParticleJetDeltaRLabelTool
135  Cone matching for B, C and tau truth for all but track jets.
136 
137  This function is meant to be used as callback from JetRecConfig where
138  it is called as func(jetdef, modspec). Hence the jetdef argument even if not used in this case.
139  """
140  jetptmin = float(modspec)
141  name = "jetdrlabeler_jetpt{0}GeV".format(int(jetptmin/1000))
142  return getJetDeltaRFlavorLabelTool(name, jetptmin)
143 
144 
145 def getJetGhostFlavorLabelTool(name="jetghostlabeler"):
146  return CompFactory.ParticleJetGhostLabelTool(
147  name,
148  **_getCommonLabelNames('HadronGhost'),
149  GhostBName = "GhostBHadronsFinal",
150  GhostCName = "GhostCHadronsFinal",
151  GhostTauName = "GhostTausFinal",
152  PartPtMin = 5000.0
153  )
154 
155 
156 def getJetGhostLabelTool(jetdef, modspec):
157  """get ghost-based flavor tagging labeling
158 
159  This is a wrapper for JetRecConfig where it's called as
160  func(jetdef, modspec)
161  """
163 
164 
165 def getJetTruthLabelTool(jetdef, modspec):
166 
167  isTruthJet = 'Truth' in jetdef.fullname()
168 
169  if not isinstance(modspec, str):
170  raise ValueError("JetTruthLabelingTool can only be scheduled with str as modspec")
171  else:
172  truthLabel = str(modspec)
173 
174  jetTruthLabelTool = CompFactory.JetTruthLabelingTool('truthlabeler_{0}'.format(truthLabel),
175  RecoJetContainer = jetdef.fullname(),
176  IsTruthJetCollection = isTruthJet,
177  TruthLabelName = truthLabel)
178 
179  return jetTruthLabelTool
180 
181 def getJetTruthLabelToolPrereqs(jetdef, modspec):
182  return ["input:AntiKt10TruthDressedWZSoftDropBeta100Zcut10Jets"] if modspec == "R10WZTruthLabel_R22v1" and jetdef._cflags.Input.isMC else []
183 
184 def getJetPileupLabelTool(jetdef, modspec):
185 
186  jetPileupLabelTool = CompFactory.JetPileupLabelingTool('pileuplabeler',
187  RecoJetContainer = jetdef.fullname(),
188  TruthJetContainer= "AntiKt4TruthDressedWZJets")
189 
190  return jetPileupLabelTool
ParticleJetToolsConfig.getJetGhostLabelTool
def getJetGhostLabelTool(jetdef, modspec)
Definition: ParticleJetToolsConfig.py:156
ParticleJetToolsConfig.getJetTruthLabelTool
def getJetTruthLabelTool(jetdef, modspec)
Definition: ParticleJetToolsConfig.py:165
vtune_athena.format
format
Definition: vtune_athena.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ParticleJetToolsConfig.getJetTruthLabelToolPrereqs
def getJetTruthLabelToolPrereqs(jetdef, modspec)
Definition: ParticleJetToolsConfig.py:181
ParticleJetToolsConfig.getJetDeltaRLabelTool
def getJetDeltaRLabelTool(jetdef, modspec)
Definition: ParticleJetToolsConfig.py:133
ParticleJetToolsConfig.getJetDeltaRFlavorLabelTool
def getJetDeltaRFlavorLabelTool(name='jetdrlabeler', jet_pt_min=5000)
Definition: ParticleJetToolsConfig.py:112
ParticleJetToolsConfig.getMCTruthClassifier
def getMCTruthClassifier()
Definition: ParticleJetToolsConfig.py:23
ParticleJetToolsConfig.isAnalysisRelease
def isAnalysisRelease()
Definition: ParticleJetToolsConfig.py:19
ParticleJetToolsConfig.getJetGhostFlavorLabelTool
def getJetGhostFlavorLabelTool(name="jetghostlabeler")
Definition: ParticleJetToolsConfig.py:145
ParticleJetToolsConfig._getCommonLabelNames
def _getCommonLabelNames(prefix)
Definition: ParticleJetToolsConfig.py:88
str
Definition: BTagTrackIpAccessor.cxx:11
ParticleJetToolsConfig.getCopyTruthLabelParticles
def getCopyTruthLabelParticles(truthtype)
Definition: ParticleJetToolsConfig.py:43
readCCLHist.float
float
Definition: readCCLHist.py:83
ParticleJetToolsConfig.getJetPileupLabelTool
def getJetPileupLabelTool(jetdef, modspec)
Definition: ParticleJetToolsConfig.py:184
ParticleJetToolsConfig.getCopyTruthJetParticles
def getCopyTruthJetParticles(modspec, cflags)
Definition: ParticleJetToolsConfig.py:63