ATLAS Offline Software
Loading...
Searching...
No Matches
MCTruthClassifier/python/MCTruthClassifierConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3__doc__ = """
4 Tool configuration to instantiate MCTruthClassifier
5 with default configurations."""
6
7from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
8from AthenaConfiguration.ComponentFactory import CompFactory
9from AthenaConfiguration.Enums import LHCPeriod, Project
10
11
12def MCTruthClassifierCfg(flags, name="MCTruthClassifier", **kwargs):
13 """
14 This is the default configuration allowing all options.
15 By default, it does not do calo truth matching.
16 """
17 if flags.Common.Project not in [Project.AthGeneration, Project.AnalysisBase]:
18 kwargs.setdefault("ParticleCaloExtensionTool", "")
19 kwargs.setdefault("CaloDetDescrManager", "")
20 return MCTruthClassifierCaloTruthMatchCfg(flags, name, **kwargs)
21
22
23def MCTruthClassifierCaloTruthMatchCfg(flags, name="MCTruthClassifier", **kwargs):
24 """
25 This is the default configuration allowing all options.
26 By default, it does calo truth matching using a
27 dedicated instance of the ParticleCaloExtensionTool
28 """
29 acc = ComponentAccumulator()
30
31 if flags.Common.Project not in [Project.AthGeneration, Project.AnalysisBase]:
32 if "ParticleCaloExtensionTool" not in kwargs:
33
34 from TrkConfig.AtlasExtrapolatorConfig import (
35 MCTruthClassifierExtrapolatorCfg)
36 extrapolator = acc.popToolsAndMerge(
37 MCTruthClassifierExtrapolatorCfg(flags))
38
39 from TrackToCalo.TrackToCaloConfig import (
40 EMParticleCaloExtensionToolCfg)
41 extension = EMParticleCaloExtensionToolCfg(
42 flags, Extrapolator=extrapolator)
43 kwargs["ParticleCaloExtensionTool"] = acc.popToolsAndMerge(extension)
44
45 kwargs.setdefault("CaloDetDescrManager", "CaloDetDescrManager")
46
47 if flags.Input.Files and set(['StreamEVGEN', 'StreamEVNT']).isdisjoint(set(flags.Input.ProcessingTags)):
48 # Skip if running with no input file or running on EVNT files
49 if flags.GeoModel.Run >= LHCPeriod.Run4:
50 kwargs.setdefault("FwdElectronUseG4Sel", False)
51
52 acc.setPrivateTools(CompFactory.MCTruthClassifier(**kwargs))
53 return acc
54
55
56def DFCommonMCTruthClassifierCfg(flags, name = "DFCommonMCTruthClassifier", **kwargs):
57 """Configure the MCTruthClassifier tool"""
58 if "xAODTruthParticleLinkVector#xAODTruthLinks" not in flags.Input.TypedCollections:
59 kwargs.setdefault("xAODTruthLinkVector", "") # FIXME Make this conditional?
60 return MCTruthClassifierCfg(flags, name, **kwargs)
61
62
63if __name__ == "__main__":
64
65 from AthenaConfiguration.AllConfigFlags import initConfigFlags
66 from AthenaConfiguration.TestDefaults import defaultTestFiles
67 from AthenaCommon.Logging import logging
68
69 from AthenaConfiguration.ComponentAccumulator import printProperties
70
71 flags = initConfigFlags()
72 flags.Input.isMC = True
73 flags.Input.Files = defaultTestFiles.RDO_RUN2
74 flags.lock()
75
76 mlog = logging.getLogger("MCTruthClassifierConfigTest")
77
78 cfg = ComponentAccumulator()
79
80 mlog.info("Configuring standard MCTruthClassifier")
81 printProperties(mlog,
82 cfg.getPrimaryAndMerge(
84 nestLevel=1,
85 printDefaults=True)
86
87 mlog.info("Configuring MCTruthClassifier with calo truth matching")
88 printProperties(mlog,
89 cfg.getPrimaryAndMerge(
91 nestLevel=1,
92 printDefaults=True)
93
94 f = open("mctruthclassifer.pkl", "wb")
95 cfg.store(f)
96 f.close()
STL class.
MCTruthClassifierCfg(flags, name="MCTruthClassifier", **kwargs)
DFCommonMCTruthClassifierCfg(flags, name="DFCommonMCTruthClassifier", **kwargs)
MCTruthClassifierCaloTruthMatchCfg(flags, name="MCTruthClassifier", **kwargs)