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 
88  jetquarklabel = CompFactory.Analysis.JetQuarkLabel(
89  "jetquarklabel",
90  McEventCollection = "TruthEvents"
91  )
92  return jetquarklabel
93 
95  jetquarklabel = getJetQuarkLabel()
96  truthpartonlabel = CompFactory.Analysis.JetConeLabeling(
97  "truthpartondr",
98  JetTruthMatchTool = jetquarklabel
99  )
100  return truthpartonlabel
101 
102 
104  """Internal unlity to name labels
105 
106  Returns a dictionary to configure labeling tools. Takes one
107  argument which is prefixed to each label.
108  """
109  return dict(
110  LabelName=f"{prefix}TruthLabelID",
111  DoubleLabelName=f"{prefix}ExtendedTruthLabelID",
112  LabelPtName=f"{prefix}TruthLabelPt",
113  LabelLxyName=f"{prefix}TruthLabelLxy",
114  LabelDRName=f"{prefix}TruthLabelDR",
115  LabelPdgIdName=f"{prefix}TruthLabelPdgId",
116  LabelPositionDPhiName=f"{prefix}TruthLabelPositionDPhi",
117  LabelPositionDEtaName=f"{prefix}TruthLabelPositionDEta",
118  LabelBarcodeName=f"{prefix}TruthLabelBarcode",
119  ChildLxyName=f"{prefix}TruthLabelChildLxy",
120  ChildPtName=f"{prefix}TruthLabelChildPt",
121  ChildPdgIdName=f"{prefix}TruthLabelChildPdgId",
122  ChildPositionDPhiName=f"{prefix}TruthLabelChildPositionDPhi",
123  ChildPositionDEtaName=f"{prefix}TruthLabelChildPositionDEta",
124  )
125 
126 
127 def getJetDeltaRFlavorLabelTool(name='jetdrlabeler', jet_pt_min=5000):
128  """Get the standard flavor tagging delta-R labeling tool
129 
130  Uses cone matching to B, C and tau truth particles.
131  """
132  return CompFactory.ParticleJetDeltaRLabelTool(
133  name,
134  **_getCommonLabelNames("HadronConeExcl"),
135  BLabelName = "ConeExclBHadronsFinal",
136  CLabelName = "ConeExclCHadronsFinal",
137  TauLabelName = "ConeExclTausFinal",
138  BParticleCollection = "TruthLabelBHadronsFinal",
139  CParticleCollection = "TruthLabelCHadronsFinal",
140  TauParticleCollection = "TruthLabelTausFinal",
141  PartPtMin = 5000.,
142  DRMax = 0.3,
143  MatchMode = "MinDR",
144  JetPtMin = jet_pt_min,
145  )
146 
147 
148 def getJetDeltaRLabelTool(jetdef, modspec):
149  """returns a ParticleJetDeltaRLabelTool
150  Cone matching for B, C and tau truth for all but track jets.
151 
152  This function is meant to be used as callback from JetRecConfig where
153  it is called as func(jetdef, modspec). Hence the jetdef argument even if not used in this case.
154  """
155  jetptmin = float(modspec)
156  name = "jetdrlabeler_jetpt{0}GeV".format(int(jetptmin/1000))
157  return getJetDeltaRFlavorLabelTool(name, jetptmin)
158 
159 
160 def getJetGhostFlavorLabelTool(name="jetghostlabeler"):
161  return CompFactory.ParticleJetGhostLabelTool(
162  name,
163  **_getCommonLabelNames('HadronGhost'),
164  GhostBName = "GhostBHadronsFinal",
165  GhostCName = "GhostCHadronsFinal",
166  GhostTauName = "GhostTausFinal",
167  PartPtMin = 5000.0
168  )
169 
170 
171 def getJetGhostLabelTool(jetdef, modspec):
172  """get ghost-based flavor tagging labeling
173 
174  This is a wrapper for JetRecConfig where it's called as
175  func(jetdef, modspec)
176  """
178 
179 
180 def getJetTruthLabelTool(jetdef, modspec):
181 
182  isTruthJet = 'Truth' in jetdef.fullname()
183 
184  if not isinstance(modspec, str):
185  raise ValueError("JetTruthLabelingTool can only be scheduled with str as modspec")
186  else:
187  truthLabel = str(modspec)
188 
189  jetTruthLabelTool = CompFactory.JetTruthLabelingTool('truthlabeler_{0}'.format(truthLabel),
190  RecoJetContainer = jetdef.fullname(),
191  IsTruthJetCollection = isTruthJet,
192  TruthLabelName = truthLabel)
193 
194  return jetTruthLabelTool
195 
196 def getJetPileupLabelTool(jetdef, modspec):
197 
198  jetPileupLabelTool = CompFactory.JetPileupLabelingTool('pileuplabeler',
199  RecoJetContainer = jetdef.fullname(),
200  TruthJetContainer= "AntiKt4TruthDressedWZJets")
201 
202  return jetPileupLabelTool
ParticleJetToolsConfig.getJetGhostLabelTool
def getJetGhostLabelTool(jetdef, modspec)
Definition: ParticleJetToolsConfig.py:171
ParticleJetToolsConfig.getJetTruthLabelTool
def getJetTruthLabelTool(jetdef, modspec)
Definition: ParticleJetToolsConfig.py:180
vtune_athena.format
format
Definition: vtune_athena.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ParticleJetToolsConfig.getJetDeltaRLabelTool
def getJetDeltaRLabelTool(jetdef, modspec)
Definition: ParticleJetToolsConfig.py:148
ParticleJetToolsConfig.getJetDeltaRFlavorLabelTool
def getJetDeltaRFlavorLabelTool(name='jetdrlabeler', jet_pt_min=5000)
Definition: ParticleJetToolsConfig.py:127
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:160
ParticleJetToolsConfig.getJetQuarkLabel
def getJetQuarkLabel()
Definition: ParticleJetToolsConfig.py:87
ParticleJetToolsConfig.getJetConeLabeling
def getJetConeLabeling()
Definition: ParticleJetToolsConfig.py:94
ParticleJetToolsConfig._getCommonLabelNames
def _getCommonLabelNames(prefix)
Definition: ParticleJetToolsConfig.py:103
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:196
ParticleJetToolsConfig.getCopyTruthJetParticles
def getCopyTruthJetParticles(modspec, cflags)
Definition: ParticleJetToolsConfig.py:63