ATLAS Offline Software
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 
7 #include "InDetSecVtxTrackCut.h"
8 
9 #include "AsgMessaging/Check.h"
11 #ifndef XAOD_ANALYSIS
12 #include "TrkTrack/Track.h"
13 #include "VxVertex/Vertex.h"
15 #endif
16 
17 #include <memory>
18 
19 InDet::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
31 InDet::InDetSecVtxTrackSelectionTool::~InDetSecVtxTrackSelectionTool() = default;
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 
135 {
136  return m_acceptInfo;
137 }
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
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
241 
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 
InDet::InDetSecVtxTrackSelectionTool::initialize
virtual StatusCode initialize() override
Function initialising the tool.
Definition: InDetSecVtxTrackSelectionTool.cxx:34
Trk::Vertex
Definition: Tracking/TrkEvent/VxVertex/VxVertex/Vertex.h:26
Check.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
asg
Definition: DataHandleTestTool.h:28
InDet::InDetSecVtxTrackSelectionTool::finalize
virtual StatusCode finalize() override
Function finalizing the tool.
Definition: InDetSecVtxTrackSelectionTool.cxx:114
xAOD::numberOfPixelHits
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].
Definition: TrackingPrimitives.h:259
InDet::InDetSecVtxTrackSelectionTool::getAcceptInfo
virtual const asg::AcceptInfo & getAcceptInfo() const override
Get an object describing the "selection steps" of the tool.
Definition: InDetSecVtxTrackSelectionTool.cxx:134
xAOD::numberOfTRTHits
@ numberOfTRTHits
number of TRT hits [unit8_t].
Definition: TrackingPrimitives.h:275
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
InDetSecVtxTrackSelectionTool.h
Track.h
xAOD::TrackParticle
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Definition: Event/xAOD/xAODTracking/xAODTracking/TrackParticle.h:13
InDet::InDetSecVtxTrackSelectionTool::m_minInDetHits
IntegerProperty m_minInDetHits
Definition: InDetSecVtxTrackSelectionTool.h:114
InDet::InDetSecVtxTrackSelectionTool::setCutLevel
virtual void setCutLevel(InDet::CutLevel level, Bool_t overwrite=true) override __attribute__((deprecated("For consistency with the athena interface
Function to set the cut level within standalone ROOT.
Definition: InDetSecVtxTrackSelectionTool.cxx:228
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
asg::AcceptInfo
Definition: AcceptInfo.h:28
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
InDet::InDetSecVtxTrackSelectionTool::m_acceptInfo
asg::AcceptInfo m_acceptInfo
Object used to store the last decision.
Definition: InDetSecVtxTrackSelectionTool.h:108
InDet::InDetSecVtxTrackSelectionTool::m_minD0
DoubleProperty m_minD0
Definition: InDetSecVtxTrackSelectionTool.h:110
BindingsTest.cut
cut
This script demonstrates how to call a C++ class from Python Also how to use PyROOT is shown.
Definition: BindingsTest.py:13
InDet::InDetSecVtxTrackSelectionTool::m_isInitialized
bool m_isInitialized
Definition: InDetSecVtxTrackSelectionTool.h:91
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrackSummary.h
InDet::InDetSecVtxTrackSelectionTool::accept
virtual asg::AcceptData accept(const xAOD::IParticle *) const override
Get the decision using a generic IParticle pointer.
Definition: InDetSecVtxTrackSelectionTool.cxx:141
InDet::InDetSecVtxTrackSelectionTool::m_NPixel0TRT
IntegerProperty m_NPixel0TRT
Definition: InDetSecVtxTrackSelectionTool.h:112
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Vertex.h
InDet::InDetSecVtxTrackSelectionTool::m_warnInit
std::atomic< bool > m_warnInit
Definition: InDetSecVtxTrackSelectionTool.h:92
InDet::InDetSecVtxTrackSelectionTool::m_numTracksProcessed
std::atomic< ULong64_t > m_numTracksProcessed
a counter of the number of tracks proccessed
Definition: InDetSecVtxTrackSelectionTool.h:99
xAOD::JetAttributeAccessor::accessor
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
Definition: JetAccessorMap.h:26
InDet::InDetSecVtxTrackSelectionTool::m_trackAccessors
std::unordered_map< std::string, std::shared_ptr< SecVtxTrackAccessor > > m_trackAccessors
list of the accessors that need to be run for each track
Definition: InDetSecVtxTrackSelectionTool.h:94
asg::AcceptData::setCutResult
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer)
Definition: AcceptData.h:134
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
InDetSecVtxTrackCut.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
compute_lumi.fin
fin
Definition: compute_lumi.py:19
xAOD::numberOfSCTHits
@ numberOfSCTHits
number of hits in SCT [unit8_t].
Definition: TrackingPrimitives.h:268
InDet::minPixelHits
@ minPixelHits
Definition: IInDetEtaDependentCutsSvc.h:15
InDet::InDetSecVtxTrackSelectionTool::m_trackCuts
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.
Definition: InDetSecVtxTrackSelectionTool.h:97
xAOD::numberOfPixelDeadSensors
@ numberOfPixelDeadSensors
number of dead pixel sensors crossed [unit8_t].
Definition: TrackingPrimitives.h:266
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
InDet::InDetSecVtxTrackSelectionTool::m_numTracksPassed
std::atomic< ULong64_t > m_numTracksPassed
a counter of the number of tracks that passed all cuts
Definition: InDetSecVtxTrackSelectionTool.h:100
asg::AcceptData
Definition: AcceptData.h:30
asg::AsgTool::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: AsgTool.h:133
TrackingPrimitives.h
xAOD::numberOfInnermostPixelLayerHits
@ numberOfInnermostPixelLayerHits
these are the hits in the 0th pixel barrel layer
Definition: TrackingPrimitives.h:237
InDet::CutLevel
CutLevel
Definition: IInDetTrackSelectionTool.h:40
asg::AcceptInfo::addCut
int addCut(const std::string &cutName, const std::string &cutDescription)
Add a cut; returning the cut position.
Definition: AcceptInfo.h:53
PlotCalibFromCool.vals
vals
Definition: PlotCalibFromCool.py:474