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  declareProperty("minD0", m_minD0, "Minimum transverse separation");
29  declareProperty("minNPixelHitsAtZeroTRT", m_NPixel0TRT , "Minimum number of Pixel hit upon zero TRT hit" ) ;
30  declareProperty("minTotalHits", m_minInDetHits , "Minimum number of Pixel + Sct + TRT hits" ) ;
31 
32 }
33 
34 // we must define the destructor in order to use forward-declaration with unique_ptr
35 InDet::InDetSecVtxTrackSelectionTool::~InDetSecVtxTrackSelectionTool() = default;
36 
39  // Make sure we haven't already been initialized - this would be a sign of improper usage.
40  StatusCode ini = StatusCode::SUCCESS ;
41  if (m_isInitialized) {
42  ATH_MSG_ERROR( "Tool has already been initialized. This is illegitimate." );
43  ATH_MSG_ERROR( "This call to initialize() will do nothing." );
44  return ini;
45  }
46 
47  // Greet the user:
49 
50  // if the CutLevel string is set to something recognizable,
51  // then do a soft set on the cuts (i.e. not overwriting those already set)
52 
53  if ( m_minD0 >= 0 )
54  {
55  ATH_MSG_DEBUG( " Maximum on d0: " << m_minD0 << " mm" );
56  m_trackCuts["D0"].push_back(std::make_unique<D0minCut>(this, m_minD0));
57  }
58 
59  if ( m_NPixel0TRT > 0 )
60  {
61  ATH_MSG_DEBUG( " Minimum number of Pixel hit when TRT has zero hit: " << m_NPixel0TRT );
62 
63  auto minPixelHits = std::make_unique< FuncSummaryValueCut<3> >
64  ( this, std::array<xAOD::SummaryType,3>
65  (
67 // eta acceptance and outliers are ignored for TRT
68  )
69  );
70 
71  minPixelHits->setFunction( [=] (const std::array<uint8_t, 3>& vals )
72  { return ( vals[0] > 0 ) || ( ( vals[1] >= m_NPixel0TRT ) || ( vals[2] >= m_NPixel0TRT ) ) ; }
73  );
74 
75  m_trackCuts["minPixelHits0TRT"].push_back( std::move( minPixelHits ) );
76 
77  }
78 
79  if ( m_minInDetHits > 0 )
80  {
81  ATH_MSG_DEBUG( " Minimum number of Pixel + SCT + TRT hits: " << m_minInDetHits );
82 
83  auto mintotHits = std::make_unique< FuncSummaryValueCut<4> >
84  ( this, std::array<xAOD::SummaryType,4>
85  (
88  )
89  );
90 
91  mintotHits->setFunction( [=] (const std::array<uint8_t, 4>& vals )
92  { return ( vals[0] + vals[1] + vals[2] + vals[3] ) >= m_minInDetHits ; }
93  );
94 
95  m_trackCuts["minTotalHits"].push_back( std::move( mintotHits ) );
96  }
97 
98 
99  // std::lock_guard<std::mutex> lock{m_mutex};
100  for (const auto& cutFamily : m_trackCuts) {
101  for (const auto& cut : cutFamily.second) {
102  ATH_CHECK( cut->initialize() );
103  }
104  const std::string& cutFamilyName = cutFamily.first;
105  // m_numTracksPassedCuts.push_back(0);
106  if (m_acceptInfo.addCut( cutFamilyName, "Selection of SecVtx tracks according to " + cutFamilyName ) < 0) {
107  ATH_MSG_ERROR( "Failed to add cut family " << cutFamilyName << " because the TAccept object is full." );
108  return StatusCode::FAILURE;
109  }
110  ATH_MSG_VERBOSE("Adding cut family " << cutFamilyName);
111  }
112 
113  m_isInitialized = true;
114 
115  return ini ;
116 }
117 
119 {
120  StatusCode fin = StatusCode::SUCCESS ;
121 
122  if (!m_isInitialized) {
123  ATH_MSG_ERROR( "You are attempting to finalize a tool that has not been initialized()." );
124  }
125 
126  if (m_numTracksProcessed == 0) {
127  ATH_MSG_INFO( "No tracks processed in selection tool." );
128  return fin ;
129  }
131  << m_numTracksPassed*100./m_numTracksProcessed << "% passed all cuts." );
132 
133  return fin ;
134 
135 }
136 
137 
139 {
140  return m_acceptInfo;
141 }
142 
143 
146 {
147  asg::AcceptData acceptData(&m_acceptInfo);
148  // Check if this is a track:
149  if( p->type() != xAOD::Type::TrackParticle ) {
150  ATH_MSG_ERROR( "accept(...) Function received a non-track" );
151  return acceptData;
152  }
153 
154  // Cast it to a track (we have already checked its type so we do not have to dynamic_cast):
155  const xAOD::TrackParticle* trk = static_cast< const xAOD::TrackParticle* >( p );
156 
157  // Let the specific function do the work:
158 //#ifndef XAOD_ANALYSIS
159 // m_accept = m_trkFilter->accept( *trk, nullptr );
160 // if ( ! (bool)( m_accept ) ) return m_accept ;
161 //#endif
162 
163  return accept( *trk, nullptr );
164 }
165 
166 
169  const xAOD::Vertex* vtx ) const
170 {
171  if (!m_isInitialized) {
172  if (!m_warnInit) {
173  ATH_MSG_WARNING( "Tool is not initialized! Calling accept() will not be very helpful." );
174  m_warnInit = true;
175  }
176  }
177 
178  asg::AcceptData acceptData(&m_acceptInfo);
179 
180  bool passAll = true;
181 
182  for ( const auto & accessor : m_trackAccessors ) {
183  if( ! accessor.second->access( trk, vtx ).isSuccess() ) {
184  ATH_MSG_WARNING("Track access for " << accessor.first << " unsuccessful.");
185  }
186  }
187 
188  // loop over all cuts
189  UShort_t cutFamilyIndex = 0;
190  for ( const auto& cutFamily : m_trackCuts ) {
191  bool pass = true;
192 
193  for ( const auto& cut : cutFamily.second ) {
194  if (! cut->result() ) {
195  pass = false;
196  passAll = false;
197  break;
198  }
199  }
200  acceptData.setCutResult( cutFamilyIndex, pass );
201  // if (pass) m_numTracksPassedCuts.at(cutFamilyIndex)++; // number of tracks that pass each cut family
202  cutFamilyIndex++;
203  }
204 
205 
206  if (passAll) m_numTracksPassed++;
207 
209 
210  return acceptData;
211 }
212 
228 #ifdef __GNUC__
229 #pragma GCC diagnostic push
230 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
231 #endif
233 {
234 #ifndef XAOD_STANDALONE
235  ATH_MSG_WARNING( "InDetTrackSelectionTool::setCutLevel() is not designed to be called manually in Athena." );
236  ATH_MSG_WARNING( "It may not behave as intended. Instead, configure it in the job options through the CutLevel property." );
237 #endif // XAOD_STANDALONE
238 }
239 #ifdef __GNUC__
240 #pragma GCC diagnostic pop
241 #endif
242 
243 
244 #ifndef XAOD_ANALYSIS
245 
249  const Trk::Vertex* /* vertex */ ) const
250 {
251  if (!m_isInitialized) ATH_MSG_WARNING( "Tool is not initialized! Calling accept() will not be very helpful." );
252 
253  asg::AcceptData acceptData(&m_acceptInfo);
254 
255  bool passAll = true;
256 
257  // for faster lookup in setCutResult we will keep track of the index explicitly
258  UShort_t cutFamilyIndex = 0;
259  for ( const auto& cutFamily : m_trackCuts ) {
260  bool pass = true;
261  for ( const auto& cut : cutFamily.second ) {
262  if (! cut->result() ) {
263  pass = false;
264  passAll = false;
265  break;
266  }
267  }
268  acceptData.setCutResult( cutFamilyIndex, pass );
269  if (pass)
270  cutFamilyIndex++;
271  }
272 
273  if (passAll)
275 
277 
278  return acceptData;
279 }
280 
281 #endif // XAOD_ANALYSIS
282 
InDet::InDetSecVtxTrackSelectionTool::initialize
virtual StatusCode initialize() override
Function initialising the tool.
Definition: InDetSecVtxTrackSelectionTool.cxx:38
Trk::Vertex
Definition: Tracking/TrkEvent/VxVertex/VxVertex/Vertex.h:26
Check.h
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
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:118
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:138
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:40
InDetSecVtxTrackSelectionTool.h
Track.h
xAOD::TrackParticle
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Definition: Event/xAOD/xAODTracking/xAODTracking/TrackParticle.h:13
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:232
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
Double_t m_minD0
Minimum |d0| of tracks.
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_NPixel0TRT
Int_t m_NPixel0TRT
Definition: InDetSecVtxTrackSelectionTool.h:112
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:145
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
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
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
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:17
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
InDet::InDetSecVtxTrackSelectionTool::m_minInDetHits
Int_t m_minInDetHits
< Minimum number of Pixel hits when TRT has no hit
Definition: InDetSecVtxTrackSelectionTool.h:113
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