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
95 ANA_CHECK (m_systematicsList.initialize());
96
97 if (!m_selectionTool.empty())
98 {
99 m_acceptInfo = m_selectionTool->getAcceptInfo();
100 if (!m_filterTool.empty())
101 {
102 if (m_acceptInfo.addCut( "truthFilter", "Selection of tracks according to the InDetTrackTruthFilterTool" ) < 0)
103 {
104 ATH_MSG_ERROR( "Failed to add cut 'truthFilter' because the TAccept object is full." );
105 return StatusCode::FAILURE;
106 }
107 }
108 asg::AcceptData blankAccept (&m_acceptInfo);
109 // Just in case this isn't initially set up as a failure clear it this one
110 // time. This only calls reset on the bitset
111 blankAccept.clear();
112 m_setOnFail = selectionFromAccept(blankAccept);
113
114 ANA_CHECK (m_nameSvc.retrieve());
115 ANA_CHECK (m_nameSvc->addAcceptInfo (m_tracksHandle.getNamePattern(),
116 m_selectionHandle.getLabel(), m_acceptInfo) );
117 }
118
119 return StatusCode::SUCCESS;
120 }
121
122
123
124 StatusCode InDetTrackSelectionAlg ::
125 execute ()
126 {
127 for (const auto& sys : m_systematicsList.systematicsVector())
128 {
129 if (!m_filterTool.empty())
130 ANA_CHECK (m_filterTool->applySystematicVariation (sys));
131
132 const xAOD::TrackParticleContainer *tracks = nullptr;
133 ANA_CHECK (m_tracksHandle.retrieve (tracks, sys));
134 for (const xAOD::TrackParticle *track : *tracks)
135 {
136 if (m_preselection.getBool (*track, sys))
137 {
138 if (!m_selectionTool.empty())
139 {
140 asg::AcceptData fullAccept (&m_acceptInfo);
141 asg::AcceptData selectAccept = m_selectionTool->accept(track);
142 for (unsigned int i = 0; i < selectAccept.getNCuts(); i++)
143 {
144 fullAccept.setCutResult (selectAccept.getCutName(i), selectAccept.getCutResult(i));
145 }
146
147 if (!m_filterTool.empty())
148 {
149 fullAccept.setCutResult ("truthFilter", m_filterTool->accept (track));
150 }
151
152 m_selectionHandle.setBits
153 (*track, selectionFromAccept (fullAccept), sys);
154 }
155 else
156 {
157 m_selectionHandle.setBool (*track, true, sys);
158 }
159 }
160 else
161 {
162 if (!m_selectionTool.empty())
163 {
164 m_selectionHandle.setBits (*track, m_setOnFail, sys);
165 }
166 else
167 {
168 m_selectionHandle.setBool (*track, false, sys);
169 }
170 }
171 }
172 }
173
174 return StatusCode::SUCCESS;
175 }
176}
#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
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:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".