7 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
8 from AthenaConfiguration.ComponentFactory
import CompFactory
9 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthDecayCollectionMakerCfg
13 theTruthMetaDataWriter = CompFactory.DerivationFramework.TruthMetaDataWriter(name)
14 acc.addPublicTool(theTruthMetaDataWriter)
15 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
16 acc.addEventAlgo(CommonAugmentation(f
"{name}Kernel", AugmentationTools = [theTruthMetaDataWriter]))
20 """Conversion of HepMC to xAOD truth"""
24 if flags.Input.isMC
is False:
25 raise RuntimeError(
"Common MC truth building requested for non-MC input")
32 if "EventInfo#McEventInfo" in flags.Input.TypedCollections
and "xAOD::EventInfo#EventInfo" not in flags.Input.TypedCollections:
33 from xAODEventInfoCnv.xAODEventInfoCnvConfig
import EventInfoCnvAlgCfg
34 acc.merge(
EventInfoCnvAlgCfg(flags, inputKey=
"McEventInfo", outputKey=
"EventInfo", disableBeamSpot=
True))
38 from xAODTruthCnv.xAODTruthCnvConfig
import GEN_EVNT2xAODCfg
39 if "McEventCollection#GEN_EVENT" in flags.Input.TypedCollections:
40 acc.merge(
GEN_EVNT2xAODCfg(flags,name=
"GEN_EVNT2xAOD",AODContainerName=
"GEN_EVENT"))
43 elif "McEventCollection#TruthEvent" in flags.Input.TypedCollections:
44 acc.merge(
GEN_EVNT2xAODCfg(flags,name=
"GEN_EVNT2xAOD",AODContainerName=
"TruthEvent"))
48 elif "xAOD::TruthEventContainer#TruthEvents" in flags.Input.TypedCollections:
51 raise RuntimeError(
"No recognised HepMC truth information found in the input")
54 if "TruthMetaDataContainer#TruthMetaData" not in flags.Input.TypedCollections
and not isEVNT:
66 from JetRecConfig.StandardSmallRJets
import AntiKt4Truth,AntiKt4TruthWZ,AntiKt4TruthDressedWZ,AntiKtVRTruthCharged
67 from JetRecConfig.StandardLargeRJets
import AntiKt10TruthSoftDrop
68 from JetRecConfig.JetRecConfig
import JetRecCfg
70 inputCollections =
set(flags.Input.Collections)
71 jetList = [AntiKt4Truth,AntiKt4TruthWZ,AntiKt4TruthDressedWZ,AntiKtVRTruthCharged,
72 AntiKt10TruthSoftDrop]
76 expectedName = jd.fullname().
encode(
"utf-8")
77 if expectedName
in inputCollections:
89 if (
"MissingETContainer#MET_Truth")
not in flags.Input.TypedCollections:
90 from METReconstruction.METTruth_Cfg
import METTruth_Cfg
100 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import DFCommonTruthClassificationToolCfg
101 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(name =
"MCTruthClassificationKernel",
111 augmentationToolsList = []
116 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import ( DFCommonTruthElectronDressingToolCfg,
117 DFCommonTruthMuonDressingToolCfg, DFCommonTruthMuonToolCfg, DFCommonTruthElectronToolCfg,
118 DFCommonTruthPhotonToolSimCfg, DFCommonTruthNeutrinoToolCfg, DFCommonTruthBottomToolCfg, DFCommonTruthTopToolCfg,
119 DFCommonTruthBosonToolCfg, DFCommonTruthBSMToolCfg, DFCommonTruthForwardProtonToolCfg, DFCommonTruthElectronIsolationTool1Cfg,
120 DFCommonTruthElectronIsolationTool2Cfg, DFCommonTruthMuonIsolationTool1Cfg, DFCommonTruthMuonIsolationTool2Cfg,
121 DFCommonTruthPhotonIsolationTool1Cfg, DFCommonTruthPhotonIsolationTool2Cfg, DFCommonTruthPhotonIsolationTool3Cfg )
124 for item
in [ DFCommonTruthMuonToolCfg, DFCommonTruthElectronToolCfg,
125 DFCommonTruthPhotonToolSimCfg, DFCommonTruthNeutrinoToolCfg, DFCommonTruthBottomToolCfg, DFCommonTruthTopToolCfg,
126 DFCommonTruthBosonToolCfg, DFCommonTruthBSMToolCfg, DFCommonTruthElectronIsolationTool1Cfg,
127 DFCommonTruthElectronIsolationTool2Cfg, DFCommonTruthMuonIsolationTool1Cfg, DFCommonTruthMuonIsolationTool2Cfg,
128 DFCommonTruthPhotonIsolationTool1Cfg, DFCommonTruthPhotonIsolationTool2Cfg, DFCommonTruthPhotonIsolationTool3Cfg]:
129 augmentationToolsList.append(acc.getPrimaryAndMerge(
item(flags)))
132 if 'decorationDressing' in kwargs:
136 for i, tool
in enumerate(augmentationToolsList):
137 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(name =
"MCTruthCommonPreJetKernelNo{num}".
format(num = i+1), AugmentationTools = [tool]))
148 from DerivationFrameworkTau.TauTruthCommonConfig
import TauTruthToolsCfg
150 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import DFCommonTruthTauDressingToolCfg
154 from DerivationFrameworkMCTruth.GenFilterToolConfig
import GenFilterToolCfg
156 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import DFCommonTruthDressedWZQGLabelToolCfg
157 augmentationToolsList += [ acc.getPrimaryAndMerge(
GenFilterToolCfg(flags)) ,
161 from DerivationFrameworkSUSY.DecorateSUSYProcessConfig
import IsSUSYSignalRun3
163 from DerivationFrameworkSUSY.DecorateSUSYProcessConfig
import SUSYSignalTaggerCfg
164 augmentationToolsList += [ acc.getPrimaryAndMerge(
SUSYSignalTaggerCfg(flags,
'MCTruthCommon')) ]
166 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
167 for i, tool
in enumerate(augmentationToolsList):
168 acc.addEventAlgo(CommonAugmentation(name =
"MCTruthCommonPostJetKernelNo{num}".
format(num = i+1),
169 AugmentationTools = [tool]))
173 from DerivationFrameworkSUSY.SUSYWeightMetadataConfig
import AddSUSYWeightsCfg
180 decorationDressing='dressedPhoton',
181 includeTausInDressingPhotonRemoval=False,
182 navInputCollections = ["TruthElectrons", "TruthMuons", "TruthPhotons", "TruthTaus", "TruthNeutrinos", "TruthBSM", "TruthBottom", "TruthTop", "TruthBoson"],
192 if "McEventCollection#GEN_EVENT" in flags.Input.TypedCollections: isEVNT =
True
201 if includeTausInDressingPhotonRemoval:
202 acc.getPublicTool(
"DFCommonTruthTauDressingTool").decorationName=decorationDressing+
"_tau"
222 collection_prefix=None,
223 rejectHadronChildren=False):
224 """Configure tools for adding immediate parents and descendants"""
226 collection_name=collection_prefix+
'WithDecay' if collection_prefix
is not None else 'Truth'+prefix+
'WithDecay'
229 name =
'DFCommon'+prefix+
'AndDecaysTool',
230 NewParticleKey = collection_name+
'Particles',
231 NewVertexKey = collection_name+
'Vertices',
232 PDGIDsToKeep = parents,
233 Generations = generations,
234 RejectHadronChildren = rejectHadronChildren))
235 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
236 kernel_name =
'MCTruthCommon'+prefix+
'AndDecaysKernel'
237 acc.addEventAlgo(CommonAugmentation(kernel_name, AugmentationTools = [collection_maker] ))
260 rejectHadronChildren=False):
261 """Add bosons and downstream particles (not photons/gluons)"""
263 generations = generations,
264 parents = [23,24,25],
266 rejectHadronChildren = rejectHadronChildren)
271 rejectHadronChildren=False):
272 """Add top quarks and downstream particles"""
274 generations=generations,
277 rejectHadronChildren=rejectHadronChildren)
281 rejectHadronChildren=False):
282 """Add tau and downstream particles"""
284 generations=generations,
287 rejectHadronChildren=rejectHadronChildren)
309 """Add b/c-hadrons and their downstream particles"""
310 kwargs.setdefault(
"addB",
True)
311 kwargs.setdefault(
"addC",
True)
312 kwargs.setdefault(
"generations",-1)
313 kwargs.setdefault(
"prefix",
'')
316 collection_name = kwargs[
'prefix']+
"TruthHFWithDecay"
319 name=kwargs[
'prefix']+
"DFCommonHFAndDecaysTool",
320 NewParticleKey = collection_name+
'Particles',
321 NewVertexKey = collection_name+
'Vertices',
322 KeepBHadrons=kwargs[
'addB'],
323 KeepCHadrons=kwargs[
'addC'],
324 Generations=kwargs[
'generations']))
325 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
326 kwargs[
'prefix']+
"MCTruthCommonHFAndDecaysKernel",
327 AugmentationTools = [DFCommonHFAndDecaysTool] ))
333 """Add a one-vertex-per event "primary vertex" container"""
336 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthPVCollectionMakerCfg
339 name=
"DFCommonTruthPVCollTool",
340 NewCollectionName=
"TruthPrimaryVertices"))
341 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
342 "MCTruthCommonTruthPVCollKernel",
343 AugmentationTools = [DFCommonTruthPVCollTool] ))
349 """Tool to add navigation decorations on the truth collections"""
351 if len(TruthCollections)==0:
return
353 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthNavigationDecoratorCfg
355 name = prefix+
'DFCommonTruthNavigationDecorator',
356 InputCollections = TruthCollections))
357 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
358 acc.addEventAlgo(CommonAugmentation(prefix+
"MCTruthNavigationDecoratorKernel",
359 AugmentationTools = [DFCommonTruthNavigationDecorator] ))
364 """Add BSM particles and their downstream particles in a special collection"""
367 collection_name =
"TruthBSMWithDecay"
369 name =
"DFCommonBSMAndDecaysTool",
370 NewParticleKey = collection_name+
'Particles',
371 NewVertexKey = collection_name+
'Vertices',
373 Generations = generations))
374 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
375 acc.addEventAlgo(CommonAugmentation(name =
"MCTruthCommonBSMAndDecaysKernel",
376 AugmentationTools = [DFCommonBSMAndDecaysTool] ))
381 """Add born leptons as a mini collection"""
384 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthBornLeptonCollectionMakerCfg
386 name =
"DFCommonBornLeptonCollTool",
387 NewCollectionName =
"BornLeptons"))
388 CommonAugmentation = CompFactory.DerivationFramework.CommonAugmentation
389 acc.addEventAlgo(CommonAugmentation(
"MCTruthCommonBornLeptonsKernel", AugmentationTools = [DFCommonBornLeptonCollTool] ))
393 """Add large-R jet D2 variable"""
396 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthD2DecoratorCfg
398 name =
"TruthD2Decorator",
399 JetContainerKey =
"AntiKt10TruthSoftDropBeta100Zcut10Jets",
400 DecorationName =
"D2"))
401 TruthD2DecoratorKernel = CompFactory.DerivationFramework.CommonAugmentation
402 acc.addEventAlgo(TruthD2DecoratorKernel(
"TRUTHD2Kernel", AugmentationTools = [theTruthD2Decorator] ))
407 """Truth energy density tools"""
409 from EventShapeTools.EventDensityConfig
import configEventDensityTool
410 from JetRecConfig.StandardJetConstits
import stdConstitDic
as cst
411 EventDensityAthAlg = CompFactory.EventDensityAthAlg
416 AbsRapidityMax = 1.5,
417 OutputContainer =
"TruthIsoCentralEventShape",
419 acc.addPublicTool(DFCommonTruthCentralEDTool)
420 acc.addEventAlgo(
EventDensityAthAlg(
"DFCommonTruthCentralEDAlg", EventDensityTool = DFCommonTruthCentralEDTool ))
424 AbsRapidityMin = 1.5,
425 AbsRapidityMax = 3.0,
426 OutputContainer =
"TruthIsoForwardEventShape",
428 acc.addPublicTool(DFCommonTruthForwardEDTool)
429 acc.addEventAlgo(
EventDensityAthAlg(
"DFCommonTruthForwardEDAlg", EventDensityTool = DFCommonTruthForwardEDTool ))
432 DFCommonTruthEDDecorator = CompFactory.DerivationFramework.TruthEDDecorator(
"DFCommonTruthEDDecorator",
433 EventInfoName=
"EventInfo",
434 EventShapeKeys=[
"TruthIsoCentralEventShape",
"TruthIsoForwardEventShape"],
435 DecorationSuffix=
"_rho"
437 acc.addPublicTool(DFCommonTruthEDDecorator)
439 DFCommonTruthEDKernel = CompFactory.DerivationFramework.CommonAugmentation
440 acc.addEventAlgo(DFCommonTruthEDKernel(
"DFCommonTruthEDKernel", AugmentationTools = [DFCommonTruthEDDecorator] ))
446 """Tool to move pointers to new mini truth collections"""
448 kwargs.setdefault(
"doElectrons",
True)
449 kwargs.setdefault(
"doPhotons",
True)
450 kwargs.setdefault(
"doMuons",
True)
452 from DerivationFrameworkMCTruth.TruthDerivationToolsConfig
import TruthLinkRepointToolCfg
453 if kwargs[
'doElectrons']:
456 name=
"ElMiniCollectionTruthLinkTool",
457 RecoCollection=
"Electrons",
458 TargetCollections=[
"TruthMuons",
"TruthPhotons",
"TruthElectrons"]))
459 aug_tools += [ electron_relink ]
460 if kwargs[
'doPhotons']:
463 name=
"PhMiniCollectionTruthLinkTool",
464 RecoCollection=
"Photons",
465 TargetCollections=[
"TruthMuons",
"TruthPhotons",
"TruthElectrons"]))
466 aug_tools += [ photon_relink ]
467 if kwargs[
'doMuons']:
470 name=
"MuMiniCollectionTruthLinkTool",
471 RecoCollection=
"Muons",
472 TargetCollections=[
"TruthMuons",
"TruthPhotons",
"TruthElectrons"]))
473 aug_tools += [ muon_relink ]
474 for i, tool
in enumerate(aug_tools):
475 acc.addEventAlgo(CompFactory.DerivationFramework.CommonAugmentation(
476 "MiniCollectionTruthLinkKernelNo{num}".
format(num=i+1),
477 AugmentationTools = [tool] ))
481 slimmer.AllVariables += [
492 "TruthForwardProtons",
494 "TruthBosonsWithDecayParticles",
495 "TruthBosonsWithDecayVertices",
496 "TruthBSMWithDecayParticles",
497 "TruthBSMWithDecayVertices",
499 slimmer.ExtraVariables += [
500 "AntiKt4TruthDressedWZJets.GhostCHadronsFinalCount.GhostBHadronsFinalCount.pt.HadronConeExclTruthLabelID.PartonTruthLabelID.TrueFlavor",
501 "AntiKt10TruthSoftDropBeta100Zcut10Jets.pt.Tau1_wta.Tau2_wta.Tau3_wta.D2",
502 "TruthEvents.Q.XF1.XF2.PDGID1.PDGID2.PDFID1.PDFID2.X1.X2.crossSection"]