ATLAS Offline Software
Loading...
Searching...
No Matches
ParticleSelectorConfig.py
Go to the documentation of this file.
2# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3#
4
5'''
6@file ParticleSelectorConfig.py
7@author sutt @ cern.sh
8@date 2026-08-17
9@brief
10'''
11
12from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
13from AthenaConfiguration.ComponentFactory import CompFactory
14
15# This is called ParticleSelector, rather than "TrackSelector",
16# or "OfflineTrackSelector" etc as it selects from TrackParticles,
17# or TruthParticles, and can be used for any tracks, not just
18# "offline" tracks or "Truth" particles
19
20def ParticleSelectorCfg( flags, name="ParticleSelector", **kwargs ) :
21
22 # NB: for this selector, we have changed the way the flags are
23 # controlled so we don't need "offl" or "truth" in front of
24 # the flags to distinguish what type of tool they are meant
25 # for, ie we will want a flags.referenceTracks and testTracks
26 # flags for the track collection names,
27 # and then RefSelector, TestSelector etc to specify
28 # which types of selector we want, and we will want
29 # RefSelector.minPT, TestSelector.minPT etc ( or
30 # maybe, even Reference.minPT without the "Selector")
31 # so the selectors can run on test, or refrence, without
32 # leaking their ultimate use into the names of their flags
33
34 acc = ComponentAccumulator()
35
36 # actually, this setting of some parameters from an offline tool,
37 # and some parameters from some other tool is not very helpful
38 # - why not set all selection parameters consistently ?
39 # pretty much the offline tool should be limited to just setting
40 # the working points, not the other cuts - it is a mess having some
41 # cuts applied in tool X and some others in tool Y, and cuts on
42 # some of the same variables in tools X and Y
43
44 if flags.has("UseOfflineTool") and flags.UseOfflineTool :
45
46 kwargs_InDetTrackSelectionTool = {}
47
48 # print_obj( kwargs_InDetTrackSelectionTool )
49
50 for key, value in flags.InDetSelector.node_flags():
51 kwargs_InDetTrackSelectionTool.setdefault( key, value )
52
53 from InDetTrackSelectionTool.InDetTrackSelectionToolConfig import InDetTrackSelectionToolCfg
54 offlineSelectionTool = acc.popToolsAndMerge( InDetTrackSelectionToolCfg( flags, **kwargs_InDetTrackSelectionTool) )
55
56 kwargs.setdefault( "offlineTool", offlineSelectionTool )
57
58 # any number of ways to set this, eg could base it on whether the Refselector
59 # node itself has a node TruthSelector - as it does for the flags which it is
60 # setting but then we would have to explicitly set some, rather than setting
61 # the six "default" values that we are actually setting in the TruthSelectorBaseCfg
62 # that might actuallky be better than using a custom UseTruthTool flag
63
64 if flags.Input.isMC and ( flags.has("UseTruthTool", True) or flags.hasNode("TruthSelector") ) :
65
66 # TruthSelectionBaseTool properties
67 # ---------------------------------
68 # we shuld NOT have several different ways to select on PT, ie our selection, some
69 # offline tools selection, so truth selection ??? There should be one, and only one
70 # way for any specific selection, eg if the Offline "Offline" or "Truth" selectors
71 # require it, then we should not select it in our tools
72 # of perhaps better, might be to replace all that selection to our tool ...
73
74 kwargs_base = {}
75
76 if flags.hasNode("TruthSelector"):
77 for key, value in flags.TruthSelector.node_flags():
78 kwargs_base.setdefault( key. value )
79
80 # from TrigIDR4Monitoring.SelectorConfig import TruthSelectorBaseCfg
81 from TrigIDR4Monitoring.TruthSelectorBase import TruthSelectorBaseCfg
82
83 # ... for instance here, do we need this external tool ? And if so, why are
84 # we bothering with our own tool to do the same thing ? why aren't we just deferring
85 # the entire selection to that tool
86
87 kwargs.setdefault("truthTool", acc.popToolsAndMerge( TruthSelectorBaseCfg( flags, name="TruthSelector_"+name, **kwargs_base ) ) )
88
89 # now the remaining generic flags ...
90
91 for key, value in flags.node_flags():
92 kwargs.setdefault( key, value )
93
94 acc.setPrivateTools( CompFactory.IDTPM2.ParticleSelector( name, **kwargs ) )
95
96 return acc
97
ParticleSelectorCfg(flags, name="ParticleSelector", **kwargs)