ATLAS Offline Software
Loading...
Searching...
No Matches
InDetTrackSelectionAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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 InDet::TrackSystematicMap.at(InDet::TRK_EFF_TIGHT_COMBINED)
52 };
53 }
54 else if ( m_filterWP=="LOOSE" )
55 {
56 ATH_MSG_INFO( "The TruthFilterTool is set up with the LOOSE selection "
57 "working point. Will run the appropriate systematics" );
58 recommendedSystematics =
59 {
60 InDet::TrackSystematicMap.at(InDet::TRK_FAKE_RATE_LOOSE),
61 InDet::TrackSystematicMap.at(InDet::TRK_EFF_LOOSE_GLOBAL),
62 InDet::TrackSystematicMap.at(InDet::TRK_EFF_LOOSE_IBL),
63 InDet::TrackSystematicMap.at(InDet::TRK_EFF_LOOSE_PP0),
64 InDet::TrackSystematicMap.at(InDet::TRK_EFF_LOOSE_PHYSMODEL),
65 InDet::TrackSystematicMap.at(InDet::TRK_EFF_LOOSE_COMBINED)
66 };
67 }
68 else
69 {
70 ATH_MSG_ERROR( "The TruthFilterTool was requested with the unsupported selection working "
71 "point "+ m_filterWP + ". Please use the cut levels 'Loose' or 'TightPrimary'." );
72 return StatusCode::FAILURE;
73 }
74
75 ANA_CHECK (m_filterTool.retrieve());
76
77 const SystematicSet affectingSystematics = m_filterTool->affectingSystematics();
78 for (auto& sys : recommendedSystematics)
79 {
80 if (affectingSystematics.find(sys.name()) == affectingSystematics.end())
81 {
82 ATH_MSG_ERROR( "Systematic " + sys.name() + " was expected for the FilterTool "
83 "based on the working point " + m_filterWP + " but not found "
84 "in affectingSystematics.");
85 return StatusCode::FAILURE;
86 }
87 }
88 //TODO: The second argument is meant to be 'affecting'. However, this leads
89 // to the registration of both 'Loose' and 'Tight' systematics in each
90 // WP. This may require changes to the underlying methods of the filterTool.
91 ANA_CHECK (m_systematicsList.addSystematics (recommendedSystematics, recommendedSystematics));
92 }
93
97 ANA_CHECK (m_systematicsList.initialize());
98
99 if (!m_selectionTool.empty())
100 {
101 m_acceptInfo = m_selectionTool->getAcceptInfo();
102 if (!m_filterTool.empty())
103 {
104 if (m_acceptInfo.addCut( "truthFilter", "Selection of tracks according to the InDetTrackTruthFilterTool" ) < 0)
105 {
106 ATH_MSG_ERROR( "Failed to add cut 'truthFilter' because the TAccept object is full." );
107 return StatusCode::FAILURE;
108 }
109 }
110 asg::AcceptData blankAccept (&m_acceptInfo);
111 // Just in case this isn't initially set up as a failure clear it this one
112 // time. This only calls reset on the bitset
113 blankAccept.clear();
114 m_setOnFail = selectionFromAccept(blankAccept);
115
116 ANA_CHECK (m_nameSvc.retrieve());
117 ANA_CHECK (m_nameSvc->addAcceptInfo (m_tracksHandle.getNamePattern(),
118 m_selectionHandle.getLabel(), m_acceptInfo) );
119 }
120
121 return StatusCode::SUCCESS;
122 }
123
124
125
126 StatusCode InDetTrackSelectionAlg ::
127 execute ()
128 {
129 for (const auto& sys : m_systematicsList.systematicsVector())
130 {
131 if (!m_filterTool.empty())
132 ANA_CHECK (m_filterTool->applySystematicVariation (sys));
133
134 const xAOD::TrackParticleContainer *tracks = nullptr;
135 ANA_CHECK (m_tracksHandle.retrieve (tracks, sys));
136 for (const xAOD::TrackParticle *track : *tracks)
137 {
138 if (m_preselection.getBool (*track, sys))
139 {
140 if (!m_selectionTool.empty())
141 {
142 asg::AcceptData fullAccept (&m_acceptInfo);
143 asg::AcceptData selectAccept = m_selectionTool->accept(track);
144 for (unsigned int i = 0; i < selectAccept.getNCuts(); i++)
145 {
146 fullAccept.setCutResult (selectAccept.getCutName(i), selectAccept.getCutResult(i));
147 }
148
149 if (!m_filterTool.empty())
150 {
151 fullAccept.setCutResult ("truthFilter", m_filterTool->accept (track));
152 }
153
154 m_selectionHandle.setBits
155 (*track, selectionFromAccept (fullAccept), sys);
156 }
157 else
158 {
159 m_selectionHandle.setBool (*track, true, sys);
160 }
161 }
162 else
163 {
164 if (!m_selectionTool.empty())
165 {
166 m_selectionHandle.setBits (*track, m_setOnFail, sys);
167 }
168 else
169 {
170 m_selectionHandle.setBool (*track, false, sys);
171 }
172 }
173 }
174 }
175
176 return StatusCode::SUCCESS;
177 }
178}
#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".