ATLAS Offline Software
Loading...
Searching...
No Matches
InDetTrackSelectionAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8
9//
10// includes
11//
12
14
17
18//
19// method implementations
20//
21
22namespace CP
23{
24
25 StatusCode InDetTrackSelectionAlg ::
26 initialize ()
27 {
28 if (!m_selectionTool.empty())
29 ANA_CHECK (m_selectionTool.retrieve());
30 if (!m_filterTool.empty())
31 {
32 if (m_selectionTool.empty())
33 {
34 ATH_MSG_ERROR( "The TruthFilterTool was requested without initializing the SelectionTool. "
35 "This is not supported. Please check that the SelectionTool is used." );
36 return StatusCode::FAILURE;
37 }
38
39 CP::SystematicSet recommendedSystematics;
40 if ( m_filterWP=="TIGHT" )
41 {
42 ATH_MSG_INFO( "The TruthFilterTool is set up with the TIGHT selection "
43 "working point. Will run the appropriate systematics" );
44 recommendedSystematics =
45 {
46 InDet::TrackSystematicMap.at(InDet::TRK_FAKE_RATE_TIGHT),
47 InDet::TrackSystematicMap.at(InDet::TRK_EFF_TIGHT_GLOBAL),
48 InDet::TrackSystematicMap.at(InDet::TRK_EFF_TIGHT_IBL),
49 InDet::TrackSystematicMap.at(InDet::TRK_EFF_TIGHT_PP0),
50 InDet::TrackSystematicMap.at(InDet::TRK_EFF_TIGHT_PHYSMODEL),
51 };
52 }
53 else if ( m_filterWP=="LOOSE" )
54 {
55 ATH_MSG_INFO( "The TruthFilterTool is set up with the LOOSE selection "
56 "working point. Will run the appropriate systematics" );
57 recommendedSystematics =
58 {
59 InDet::TrackSystematicMap.at(InDet::TRK_FAKE_RATE_LOOSE),
60 InDet::TrackSystematicMap.at(InDet::TRK_EFF_LOOSE_GLOBAL),
61 InDet::TrackSystematicMap.at(InDet::TRK_EFF_LOOSE_IBL),
62 InDet::TrackSystematicMap.at(InDet::TRK_EFF_LOOSE_PP0),
63 InDet::TrackSystematicMap.at(InDet::TRK_EFF_LOOSE_PHYSMODEL),
64 };
65 }
66 else
67 {
68 ATH_MSG_ERROR( "The TruthFilterTool was requested with the unsupported selection working "
69 "point "+ m_filterWP + ". Please use the cut levels 'Loose' or 'TightPrimary'." );
70 return StatusCode::FAILURE;
71 }
72
73 ANA_CHECK (m_filterTool.retrieve());
74
75 const SystematicSet affectingSystematics = m_filterTool->affectingSystematics();
76 for (auto& sys : recommendedSystematics)
77 {
78 if (affectingSystematics.find(sys.name()) == affectingSystematics.end())
79 {
80 ATH_MSG_ERROR( "Systematic " + sys.name() + " was expected for the FilterTool "
81 "based on the working point " + m_filterWP + " but not found "
82 "in affectingSystematics.");
83 return StatusCode::FAILURE;
84 }
85 }
86 //TODO: The second argument is meant to be 'affecting'. However, this leads
87 // to the registration of both 'Loose' and 'Tight' systematics in each
88 // WP. This may require changes to the underlying methods of the filterTool.
89 ANA_CHECK (m_systematicsList.addSystematics (recommendedSystematics, recommendedSystematics));
90 }
91
93 if (!m_vertexContainerKey.empty())
94 ANA_CHECK (m_vertexContainerKey.initialize());
95
98 ANA_CHECK (m_systematicsList.initialize());
99
100 if (!m_selectionTool.empty())
101 {
102 m_acceptInfo = m_selectionTool->getAcceptInfo();
103 if (!m_filterTool.empty())
104 {
105 if (m_acceptInfo.addCut( "truthFilter", "Selection of tracks according to the InDetTrackTruthFilterTool" ) < 0)
106 {
107 ATH_MSG_ERROR( "Failed to add cut 'truthFilter' because the TAccept object is full." );
108 return StatusCode::FAILURE;
109 }
110 }
111 asg::AcceptData blankAccept (&m_acceptInfo);
112 // Just in case this isn't initially set up as a failure clear it this one
113 // time. This only calls reset on the bitset
114 blankAccept.clear();
115 m_setOnFail = selectionFromAccept(blankAccept);
116
117 ANA_CHECK (m_nameSvc.retrieve());
118 ANA_CHECK (m_nameSvc->addAcceptInfo (m_tracksHandle.getNamePattern(),
119 m_selectionHandle.getLabel(), m_acceptInfo) );
120 }
121
122 return StatusCode::SUCCESS;
123 }
124
125
126
127 StatusCode InDetTrackSelectionAlg ::
128 execute ()
129 {
130 for (const auto& sys : m_systematicsList.systematicsVector())
131 {
132 if (!m_filterTool.empty())
133 ANA_CHECK (m_filterTool->applySystematicVariation (sys));
134
135 const xAOD::Vertex *primary_vertex = nullptr;
136 if (!m_vertexContainerKey.key().empty())
137 {
139 primary_vertex = vertices->at(0);
140 }
141
142 const xAOD::TrackParticleContainer *tracks = nullptr;
143 ANA_CHECK (m_tracksHandle.retrieve (tracks, sys));
144 for (const xAOD::TrackParticle *track : *tracks)
145 {
146 if (m_preselection.getBool (*track, sys))
147 {
148 if (!m_selectionTool.empty())
149 {
150 asg::AcceptData fullAccept (&m_acceptInfo);
151 asg::AcceptData selectAccept (&m_acceptInfo);
152 if (primary_vertex)
153 {
154 selectAccept = m_selectionTool->accept(*track, primary_vertex);
155 }
156 else
157 {
158 selectAccept = m_selectionTool->accept(track);
159 }
160
161 for (unsigned int i = 0; i < selectAccept.getNCuts(); i++)
162 {
163 fullAccept.setCutResult (selectAccept.getCutName(i), selectAccept.getCutResult(i));
164 }
165
166 if (!m_filterTool.empty())
167 fullAccept.setCutResult ("truthFilter", m_filterTool->accept (track));
168
169 m_selectionHandle.setBits
170 (*track, selectionFromAccept (fullAccept), sys);
171 }
172 else
173 {
174 m_selectionHandle.setBool (*track, true, sys);
175 }
176 }
177 else
178 {
179 if (!m_selectionTool.empty())
180 m_selectionHandle.setBits (*track, m_setOnFail, sys);
181 else
182 m_selectionHandle.setBool (*track, false, sys);
183 }
184 }
185 }
186
187 return StatusCode::SUCCESS;
188 }
189}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ANA_CHECK(EXP)
check whether the given expression was successful
ServiceHandle< ISelectionNameSvc > m_nameSvc
the ISelectionNameSvc
SysReadHandle< xAOD::TrackParticleContainer > m_tracksHandle
the track collection we run on
ToolHandle< InDet::IInDetTrackSelectionTool > m_selectionTool
the smearing tool
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerKey
the vertex collection to use for the selection (optional)
SysWriteSelectionHandle m_selectionHandle
the decoration for the asg selection
SysReadSelectionHandle m_preselection
the preselection we apply to our input
Gaudi::Property< std::string > m_filterWP
SelectionType m_setOnFail
the bits to set for an object failing the preselection
SysListHandle m_systematicsList
the systematics list we run
ToolHandle< InDet::IInDetTrackTruthFilterTool > m_filterTool
the filter tool
Class to wrap a set of SystematicVariations.
const_iterator end() const
description: const iterator to the end of the set
iterator find(const SystematicVariation &sys) const
description: find an element in the set
unsigned int getNCuts() const
Get the number of cuts defined.
Definition AcceptData.h:64
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer).
Definition AcceptData.h:134
const std::string & getCutName(unsigned int cutPosition) const
Get the name of a cut, based on the cut position (slow, avoid usage).
Definition AcceptData.h:78
void clear()
Clear all bits.
Definition AcceptData.h:54
bool getCutResult(const std::string &cutName) const
Get the result of a cut, based on the cut name (safer).
Definition AcceptData.h:98
Select isolated Photons, Electrons and Muons.
SelectionType selectionFromAccept(const asg::AcceptData &accept)
the selection decoration made from the given AcceptData object
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".