ATLAS Offline Software
Loading...
Searching...
No Matches
InDetSecVtxTrackSelectionTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4//Author: Lianyou Shan <lianyou.shan@cern.ch>
5
8
11#ifndef XAOD_ANALYSIS
12#include "TrkTrack/Track.h"
13#include "VxVertex/Vertex.h"
15#endif
16
17#include <memory>
18
19InDet::InDetSecVtxTrackSelectionTool::InDetSecVtxTrackSelectionTool(const std::string& name )
20 : asg::AsgTool(name)
21 , m_acceptInfo( "InDetSecVtxTrackSelection" )
22{
23
24#ifndef XAOD_STANDALONE
25 declareInterface<IInDetTrackSelectionTool>(this);
26#endif
27
28}
29
30// we must define the destructor in order to use forward-declaration with unique_ptr
32
35 // Make sure we haven't already been initialized - this would be a sign of improper usage.
36 StatusCode ini = StatusCode::SUCCESS ;
37 if (m_isInitialized) {
38 ATH_MSG_ERROR( "Tool has already been initialized. This is illegitimate." );
39 ATH_MSG_ERROR( "This call to initialize() will do nothing." );
40 return ini;
41 }
42
43 // Greet the user:
45
46 // if the CutLevel string is set to something recognizable,
47 // then do a soft set on the cuts (i.e. not overwriting those already set)
48
49 if ( m_minD0 >= 0 )
50 {
51 ATH_MSG_DEBUG( " Maximum on d0: " << m_minD0 << " mm" );
52 m_trackCuts["D0"].push_back(std::make_unique<D0minCut>(this, m_minD0));
53 }
54
55 if ( m_NPixel0TRT > 0 )
56 {
57 ATH_MSG_DEBUG( " Minimum number of Pixel hit when TRT has zero hit: " << m_NPixel0TRT );
58
59 auto minPixelHits = std::make_unique< FuncSummaryValueCut<3> >
60 ( this, std::array<xAOD::SummaryType,3>
61 (
63// eta acceptance and outliers are ignored for TRT
64 )
65 );
66
67 minPixelHits->setFunction( [=] (const std::array<uint8_t, 3>& vals )
68 { return ( vals[0] > 0 ) || ( ( vals[1] >= m_NPixel0TRT ) || ( vals[2] >= m_NPixel0TRT ) ) ; }
69 );
70
71 m_trackCuts["minPixelHits0TRT"].push_back( std::move( minPixelHits ) );
72
73 }
74
75 if ( m_minInDetHits > 0 )
76 {
77 ATH_MSG_DEBUG( " Minimum number of Pixel + SCT + TRT hits: " << m_minInDetHits );
78
79 auto mintotHits = std::make_unique< FuncSummaryValueCut<4> >
80 ( this, std::array<xAOD::SummaryType,4>
81 (
84 )
85 );
86
87 mintotHits->setFunction( [=] (const std::array<uint8_t, 4>& vals )
88 { return ( vals[0] + vals[1] + vals[2] + vals[3] ) >= m_minInDetHits ; }
89 );
90
91 m_trackCuts["minTotalHits"].push_back( std::move( mintotHits ) );
92 }
93
94
95 // std::lock_guard<std::mutex> lock{m_mutex};
96 for (const auto& cutFamily : m_trackCuts) {
97 for (const auto& cut : cutFamily.second) {
98 ATH_CHECK( cut->initialize() );
99 }
100 const std::string& cutFamilyName = cutFamily.first;
101 // m_numTracksPassedCuts.push_back(0);
102 if (m_acceptInfo.addCut( cutFamilyName, "Selection of SecVtx tracks according to " + cutFamilyName ) < 0) {
103 ATH_MSG_ERROR( "Failed to add cut family " << cutFamilyName << " because the TAccept object is full." );
104 return StatusCode::FAILURE;
105 }
106 ATH_MSG_VERBOSE("Adding cut family " << cutFamilyName);
107 }
108
109 m_isInitialized = true;
110
111 return ini ;
112}
113
115{
116 StatusCode fin = StatusCode::SUCCESS ;
117
118 if (!m_isInitialized) {
119 ATH_MSG_ERROR( "You are attempting to finalize a tool that has not been initialized()." );
120 }
121
122 if (m_numTracksProcessed == 0) {
123 ATH_MSG_INFO( "No tracks processed in selection tool." );
124 return fin ;
125 }
127 << m_numTracksPassed*100./m_numTracksProcessed << "% passed all cuts." );
128
129 return fin ;
130
131}
132
133
138
139
142{
143 asg::AcceptData acceptData(&m_acceptInfo);
144 // Check if this is a track:
145 if( p->type() != xAOD::Type::TrackParticle ) {
146 ATH_MSG_ERROR( "accept(...) Function received a non-track" );
147 return acceptData;
148 }
149
150 // Cast it to a track (we have already checked its type so we do not have to dynamic_cast):
151 const xAOD::TrackParticle* trk = static_cast< const xAOD::TrackParticle* >( p );
152
153 // Let the specific function do the work:
154//#ifndef XAOD_ANALYSIS
155// m_accept = m_trkFilter->accept( *trk, nullptr );
156// if ( ! (bool)( m_accept ) ) return m_accept ;
157//#endif
158
159 return accept( *trk, nullptr );
160}
161
162
165 const xAOD::Vertex* vtx ) const
166{
167 if (!m_isInitialized) {
168 if (!m_warnInit) {
169 ATH_MSG_WARNING( "Tool is not initialized! Calling accept() will not be very helpful." );
170 m_warnInit = true;
171 }
172 }
173
174 asg::AcceptData acceptData(&m_acceptInfo);
175
176 bool passAll = true;
177
178 for ( const auto & accessor : m_trackAccessors ) {
179 if( ! accessor.second->access( trk, vtx ).isSuccess() ) {
180 ATH_MSG_WARNING("Track access for " << accessor.first << " unsuccessful.");
181 }
182 }
183
184 // loop over all cuts
185 UShort_t cutFamilyIndex = 0;
186 for ( const auto& cutFamily : m_trackCuts ) {
187 bool pass = true;
188
189 for ( const auto& cut : cutFamily.second ) {
190 if (! cut->result() ) {
191 pass = false;
192 passAll = false;
193 break;
194 }
195 }
196 acceptData.setCutResult( cutFamilyIndex, pass );
197 // if (pass) m_numTracksPassedCuts.at(cutFamilyIndex)++; // number of tracks that pass each cut family
198 cutFamilyIndex++;
199 }
200
201
202 if (passAll) m_numTracksPassed++;
203
205
206 return acceptData;
207}
208
224#ifdef __GNUC__
225#pragma GCC diagnostic push
226#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
227#endif
228void InDet::InDetSecVtxTrackSelectionTool::setCutLevel(InDet::CutLevel /* level */, Bool_t /* overwrite */)
229{
230#ifndef XAOD_STANDALONE
231 ATH_MSG_WARNING( "InDetTrackSelectionTool::setCutLevel() is not designed to be called manually in Athena." );
232 ATH_MSG_WARNING( "It may not behave as intended. Instead, configure it in the job options through the CutLevel property." );
233#endif // XAOD_STANDALONE
234}
235#ifdef __GNUC__
236#pragma GCC diagnostic pop
237#endif
238
239
240#ifndef XAOD_ANALYSIS
242
245 const Trk::Vertex* /* vertex */ ) const
246{
247 if (!m_isInitialized) ATH_MSG_WARNING( "Tool is not initialized! Calling accept() will not be very helpful." );
248
249 asg::AcceptData acceptData(&m_acceptInfo);
250
251 bool passAll = true;
252
253 // for faster lookup in setCutResult we will keep track of the index explicitly
254 UShort_t cutFamilyIndex = 0;
255 for ( const auto& cutFamily : m_trackCuts ) {
256 bool pass = true;
257 for ( const auto& cut : cutFamily.second ) {
258 if (! cut->result() ) {
259 pass = false;
260 passAll = false;
261 break;
262 }
263 }
264 acceptData.setCutResult( cutFamilyIndex, pass );
265 if (pass)
266 cutFamilyIndex++;
267 }
268
269 if (passAll)
271
273
274 return acceptData;
275}
276
277#endif // XAOD_ANALYSIS
278
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
asg::AcceptInfo m_acceptInfo
Object used to store the last decision.
std::atomic< uint64_t > m_numTracksPassed
a counter of the number of tracks that passed all cuts
virtual StatusCode finalize() override
Function finalizing the tool.
std::unordered_map< std::string, std::shared_ptr< SecVtxTrackAccessor > > m_trackAccessors
list of the accessors that need to be run for each track
std::atomic< uint64_t > m_numTracksProcessed
a counter of the number of tracks proccessed
virtual StatusCode initialize() override
Function initialising the tool.
virtual void setCutLevel(InDet::CutLevel level, bool overwrite=true) override __attribute__((deprecated("For consistency with the athena interface
Function to set the cut level within standalone ROOT.
ASG_TOOL_CLASS2(InDetSecVtxTrackSelectionTool, IAsgSelectionTool, InDet::IInDetTrackSelectionTool) public ~InDetSecVtxTrackSelectionTool()
Create a proper constructor for Athena.
virtual const asg::AcceptInfo & getAcceptInfo() const override
Get an object describing the "selection steps" of the tool.
std::map< std::string, std::vector< std::unique_ptr< SecVtxTrackCut > > > m_trackCuts
First element is the name of the cut family, second element is the set of cuts.
virtual asg::AcceptData accept(const xAOD::IParticle *) const override
Get the decision using a generic IParticle pointer.
This class is a simplest representation of a vertex candidate.
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer)
Definition AcceptData.h:134
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition AsgTool.h:133
Class providing the definition of the 4-vector interface.
@ TrackParticle
The object is a charged track particle.
Definition ObjectType.h:43
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.
@ numberOfTRTHits
number of TRT hits [unit8_t].
@ numberOfSCTHits
number of hits in SCT [unit8_t].
@ numberOfInnermostPixelLayerHits
these are the hits in the 0th pixel barrel layer
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].
@ numberOfPixelDeadSensors
number of dead pixel sensors crossed [unit8_t].