11from AthenaCommon
import Logging
12jrtlog = Logging.logging.getLogger(
'ParticleJetToolsConfig')
14from AthenaConfiguration.ComponentFactory
import CompFactory
17 from JetRecConfig.JetRecConfig
import isAnalysisRelease
18except ModuleNotFoundError:
25 truthclassif = CompFactory.MCTruthClassifier(
26 "JetMCTruthClassifier"
29 truthclassif.xAODTruthLinkVector=
""
32 if "AtlasProject" in os.environ.keys():
33 if os.environ[
"AtlasProject"]
in [
"Athena",
"AthDerivation"]:
34 truthclassif.ParticleCaloExtensionTool=
""
39 "Partons":{
"ToolType":CompFactory.CopyTruthPartons,
"ptmin":5000},
40 "BosonTop":{
"ToolType":CompFactory.CopyBosonTopLabelTruthParticles,
"ptmin":100000},
41 "FlavourLabel":{
"ToolType":CompFactory.CopyFlavorLabelTruthParticles,
"ptmin":5000},
45 if truthtype ==
"Partons":
46 truthcategory =
"Partons"
47 elif truthtype
in [
"WBosons",
"ZBosons",
"HBosons",
"TQuarksFinal"]:
48 truthcategory =
"BosonTop"
49 toolProperties[
'ParticleType'] = truthtype
51 truthcategory =
"FlavourLabel"
52 toolProperties[
'ParticleType'] = truthtype
54 tooltype = truthpartoptions[truthcategory][
"ToolType"]
55 toolProperties.update( PtMin = truthpartoptions[truthcategory][
"ptmin"],
56 OutputName =
"TruthLabel"+truthtype)
57 ctp = tooltype(
"truthpartcopy_"+truthtype,
66 truthpartcopy = CompFactory.CopyTruthJetParticles(
67 "truthpartcopy"+modspec,
68 OutputName=
"JetInputTruthParticles"+modspec,
69 MCTruthClassifier=truthclassif)
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.DressingDecorationNames=[
'TruthParticles.dressedPhoton_e',
'TruthParticles.dressedPhoton_mu']
82 truthpartcopy.ExtraInputs = {(
'xAOD::TruthParticleContainer' ,
'StoreGateSvc+TruthParticles.dressedPhoton_e' ),
83 (
'xAOD::TruthParticleContainer' ,
'StoreGateSvc+TruthParticles.dressedPhoton_mu' )}
84 if modspec==
"Charged":
85 truthpartcopy.ChargedParticlesOnly=
True
90 """ Build truth constituents as in EVTGEN jobs in the r21 config.
91 IMPORTANT : this is expected to be temporary, only to reproduce the EVTGEN r21 config with the new config. The definitions should be harmonized with reco-level at some point and this function removed.
92 The source for r21 EVTGEN config was in GeneratorFilters/share/common/GenerateTruthJets.py
97 return CompFactory.CopyTruthJetParticles(
"truthpartcopy",
98 OutputName=
"JetInputTruthParticlesGEN",
99 MCTruthClassifier=truthclassif)
100 elif modspec==
"NoWZ":
101 return CompFactory.CopyTruthJetParticles(
"truthpartcopywz",
102 OutputName=
"JetInputTruthParticlesGENNoWZ",
103 MCTruthClassifier=truthclassif,
104 IncludePromptLeptons=
False)
108 """Internal unlity to name labels
110 Returns a dictionary to configure labeling tools. Takes one
111 argument which is prefixed to each label.
114 LabelName=f
"{prefix}TruthLabelID",
115 DoubleLabelName=f
"{prefix}ExtendedTruthLabelID",
116 LabelPtName=f
"{prefix}TruthLabelPt",
117 LabelLxyName=f
"{prefix}TruthLabelLxy",
118 LabelDRName=f
"{prefix}TruthLabelDR",
119 LabelPdgIdName=f
"{prefix}TruthLabelPdgId",
120 LabelPositionDPhiName=f
"{prefix}TruthLabelPositionDPhi",
121 LabelPositionDEtaName=f
"{prefix}TruthLabelPositionDEta",
122 LabelBarcodeName=f
"{prefix}TruthLabelBarcode",
123 ChildLxyName=f
"{prefix}TruthLabelChildLxy",
124 ChildPtName=f
"{prefix}TruthLabelChildPt",
125 ChildPdgIdName=f
"{prefix}TruthLabelChildPdgId",
126 ChildPositionDPhiName=f
"{prefix}TruthLabelChildPositionDPhi",
127 ChildPositionDEtaName=f
"{prefix}TruthLabelChildPositionDEta",
133 """Get the standard flavor tagging delta-R labeling tool
135 Uses cone matching to B, C and tau truth particles.
137 prefix_to_name =
"HadronConeExcl"
138 if collection !=
"Final":
139 prefix_to_name += collection
142 return CompFactory.ParticleJetDeltaRLabelTool(
145 BLabelName =
"ConeExclBHadrons"+collection,
146 CLabelName =
"ConeExclCHadrons"+collection,
147 TauLabelName =
"ConeExclTausFinal",
148 BParticleCollection =
"TruthLabelBHadrons"+collection,
149 CParticleCollection =
"TruthLabelCHadrons"+collection,
150 TauParticleCollection =
"TruthLabelTausFinal",
154 JetPtMin = jet_pt_min,
155 useBarcode=use_barcode,
160 output_label = "QuarkChargeTruthLabelID",
161 hadron_label = "HadronGhostInitialTruthLabelPdgId",
162 parton_label = "PartonExtendedTruthLabelID"):
163 """Get the flavor tagging labeling tool to store the quark charge of a jet
164 It is necessary to have saved before an hadron label and a parton label, otherwise the code will break
167 import ParticleJetTools.quarkChargeMap
as qcMap
168 charge_map = qcMap.hadrons_dict
170 return CompFactory.JetQuarkChargeLabelingTool(
172 HadronDecorationName = hadron_label,
173 PartonDecorationName = parton_label,
174 HadronChargeMap = charge_map,
175 OutputName = output_label,
179 """returns a ParticleJetDeltaRLabelTool
180 Cone matching for B, C and tau truth for all but track jets.
182 This function is meant to be used as callback from JetRecConfig where
183 it is called as func(jetdef, modspec). Hence the jetdef argument even if not used in this case.
185 jetptmin = float(modspec)
186 name =
"jetdrlabeler_jetpt{0}GeV".format(int(jetptmin/1000))
191 """returns a JetQuarkChargeLabelingTool
193 This function is meant to be used as callback from JetRecConfig where
194 it is called as func(jetdef, modspec). Hence the jetdef argument even if not used.
199 outputLabel,hadronLabel,partonLabel = modspec.split(
",")
201 name = f
"jetquarkcharge_{outputLabel}_{hadronLabel}_{partonLabel}"
205 """returns a ParticleJetDeltaRLabelTool
206 Cone matching for B, C and tau truth for all but track jets.
208 This function is meant to be used as callback from JetRecConfig where
209 it is called as func(jetdef, modspec). Hence the jetdef argument even if not used in this case.
211 jetptmin = float(modspec)
212 name =
"jetdrlabeler_jetpt{0}GeV".format(int(jetptmin/1000))
218 name="jetghostlabeler",
222 prefix_to_name =
"HadronGhost"
223 if collection !=
"Final":
224 prefix_to_name += collection
226 return CompFactory.ParticleJetGhostLabelTool(
229 GhostBName =
"GhostBHadrons"+collection,
230 GhostCName =
"GhostCHadrons"+collection,
231 GhostTauName =
"GhostTausFinal",
232 useBarcode = use_barcode,
237 """get ghost-based flavor tagging labeling
239 This is a wrapper for JetRecConfig where it's called as
240 func(jetdef, modspec)
245 """get ghost-based flavor tagging labeling
247 This is a wrapper for JetRecConfig where it's called as
248 func(jetdef, modspec)
254truthLabelSettings = {
256 "R10TruthLabel_R21Precision_2022v1": dict(
257 TruthJetContainer =
"AntiKt10TruthJets",
258 MatchUngroomedParent =
True,
262 "R10TruthLabel_R22v1": dict(
263 TruthJetContainer =
"AntiKt10TruthJets",
264 GetTruthGroomedJetValues =
True,
265 TruthGroomedJetContainer =
"AntiKt10TruthSoftDropBeta100Zcut10Jets",
266 MatchUngroomedParent =
True,
270 "R10WZTruthLabel_R22v1": dict(
271 TruthJetContainer =
"AntiKt10TruthDressedWZJets",
272 GetTruthGroomedJetValues =
True,
273 TruthGroomedJetContainer =
"AntiKt10TruthDressedWZSoftDropBeta100Zcut10Jets",
274 MatchUngroomedParent =
True,
279 "R4TruthLabel": dict(TruthJetContainer =
"AntiKt4TruthJets", dRTruthJet = 0.3, DoLargeRLabels =
False),
280 "R4TruthDressedWZLabel": dict(TruthJetContainer =
"AntiKt4TruthDressedWZJets", dRTruthJet = 0.3, DoLargeRLabels =
False),
281 "R4InTimeTruthLabel": dict(TruthJetContainer =
"InTimeAntiKt4TruthJets", dRTruthJet = 0.3, DoLargeRLabels =
False),
282 "R4OutOfTimeTruthLabel": dict(TruthJetContainer =
"OutOfTimeAntiKt4TruthJets", dRTruthJet = 0.3, DoLargeRLabels =
False),
289 isTruthJet =
'Truth' in jetdef.fullname()
292 if not isinstance(modspec, str):
293 raise ValueError(
"JetTruthLabelingTool can only be scheduled with str as modspec")
296 truthLabel, addopts = modspec.split(
':',1)
300 kwargs = dict(truthLabelSettings[truthLabel])
302 if 'DeltaR' in addopts:
303 kwargs[
'UseGhostJetMatch'] =
False
305 jetTruthLabelTool = CompFactory.JetTruthLabelingTool(
'truthlabeler_{0}'.format(truthLabel),
306 RecoJetContainer = jetdef.fullname(),
307 IsTruthJetCollection = isTruthJet,
308 TruthLabelName = truthLabel,
311 return jetTruthLabelTool
314 labelconfig = modspec
316 labelconfig = modspec.split(
':')[0]
318 if (jetdef._cflags.Input.isMC):
320 "R10WZTruthLabel_R22v1":
"input:AntiKt10TruthDressedWZSoftDropBeta100Zcut10Jets",
321 "R4TruthLabel":
"input:AntiKt4TruthJets",
322 "R4TruthDressedWZLabel":
"input:AntiKt4TruthDressedWZJets",
323 "R4InTimeTruthLabel":
"input:InTimeAntiKt4TruthJets",
324 "R4OutOfTimeTruthLabel":
"input:OutOfTimeAntiKt4TruthJets",
325 "R10TruthLabel_R21Precision_2022v1":
"input:AntiKt10TruthJets",
326 "R10TruthLabel_R22v1":
"input:AntiKt10TruthSoftDropBeta100Zcut10Jets",
332 jetPileupLabelTool = CompFactory.JetPileupLabelingTool(
'pileuplabeler',
333 RecoJetContainer = jetdef.fullname(),
334 TruthJetContainer=
"AntiKt4TruthDressedWZJets")
336 return jetPileupLabelTool
339 """returns the IRCSafe labelling tools, applying four new flavour labelling
340 schemes to truth particle jets and then matching them in terms of deltaR
341 to any type of reconstructed jets (for now the radius of truth jets is
342 set by hand to R = 0.4, so shouldnt really be used for other jets)
345 LabelNameIFN =
"IRCSafeLabelIFN",
346 LabelNameCMP =
"IRCSafeLabelCMP",
347 LabelNameGHS =
"IRCSafeLabelGHS",
348 LabelNameSDF =
"IRCSafeLabelSDF",
349 LabelNameAKT =
"IRCSafeLabelAKT",
350 BParticleCollection =
"TruthLabelBHadronsFinal",
351 CParticleCollection =
"TruthLabelCHadronsFinal",
352 TruthParticleCollection =
"JetInputTruthParticles",
353 EnabledAlgorithms = [
"IFN",
"CMP",
"GHS",
"SDF",
"AKT"],
354 TruthJetPtMin = 5000.0,
359 return CompFactory.JetIRCSafeLabelTool(
"jetircsafelabeler", **tool_kwargs)
getJetTruthLabelToolPrereqs(jetdef, modspec)
getJetGhostLabelTool(jetdef, modspec)
getJetDeltaRLabelTool(jetdef, modspec)
getCopyTruthJetParticlesGEN(modspec, cflags)
getJetQuarkChargeTool(jetdef, modspec)
_getCommonLabelNames(prefix)
getCopyTruthLabelParticles(truthtype)
getJetIRCSafeLabelTool(jetdef, modspec)
getJetDeltaRInitialLabelTool(jetdef, modspec)
getJetPileupLabelTool(jetdef, modspec)
getJetGhostInitialLabelTool(jetdef, modspec)
getCopyTruthJetParticles(modspec, cflags)
getJetQuarkChargeLabelTool(name='jetquarkcharge', output_label="QuarkChargeTruthLabelID", hadron_label="HadronGhostInitialTruthLabelPdgId", parton_label="PartonExtendedTruthLabelID")
getJetDeltaRFlavorLabelTool(name='jetdrlabeler', jet_pt_min=5000, collection="Final", dr_max=0.3, use_barcode=False)
getJetGhostFlavorLabelTool(name="jetghostlabeler", collection="Final", use_barcode=False)
getJetTruthLabelTool(jetdef, modspec)