ATLAS Offline Software
Loading...
Searching...
No Matches
dRMatchingTool Class Reference

Tool to perform dR-based matching of tracks and truth particles. More...

#include <dRMatchingTool.h>

Inheritance diagram for dRMatchingTool:
Collaboration diagram for dRMatchingTool:

Classes

struct  CacheEntry

Public Member Functions

 dRMatchingTool (const std::string &name)
 Constructor(s).
virtual ~dRMatchingTool ()
 Destructor.
virtual StatusCode initialize () override
 SelectionTool method(s).
virtual StatusCode finalize () override
virtual const asg::AcceptInfogetAcceptInfo () const override
 Declare the interface ID for this pure-virtual interface class to the Athena framework.
virtual asg::AcceptData accept (const xAOD::IParticle *p) const override
 The main accept method: the actual cuts are applied here.
virtual asg::AcceptData acceptLegacy (const xAOD::TrackParticle *p, const xAOD::TruthParticleContainer *truthParticles, bool(*truthSelectionTool)(const xAOD::TruthParticle *)=nullptr) const
 dR-matching specific method(s).
asg::AcceptData accept (const xAOD::TrackParticle *p, const xAOD::TruthParticleContainer *truthParticles, bool(*truthSelectionTool)(const xAOD::TruthParticle *)=nullptr) const
virtual asg::AcceptData acceptLegacy (const xAOD::TruthParticle *p, const xAOD::TrackParticleContainer *trackParticles, bool(*trackSelectionTool)(const xAOD::TrackParticle *)=nullptr) const
asg::AcceptData accept (const xAOD::TruthParticle *p, const xAOD::TrackParticleContainer *trackParticles, bool(*trackSelectionTool)(const xAOD::TrackParticle *)=nullptr) const
float dRmin () const
virtual void print () const
 Print the state of the tool.
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const
Additional helper functions, not directly mimicking Athena
template<class T>
const T * getProperty (const std::string &name) const
 Get one of the tool's properties.
const std::string & msg_level_name () const __attribute__((deprecated))
 A deprecated function for getting the message level's name.
const std::string & getName (const void *ptr) const
 Get the name of an object that is / should be in the event store.
SG::sgkey_t getKey (const void *ptr) const
 Get the (hashed) key of an object that is in the event store.

Protected Member Functions

void checkCacheTrackParticles (const xAOD::TrackParticleContainer *trackParticles, CacheEntry *ent, bool(*trackSelectionTool)(const xAOD::TrackParticle *)=nullptr) const
 Internal method(s).
void checkCacheTruthParticles (const xAOD::TruthParticleContainer *truthParticles, CacheEntry *ent, bool(*truthSelectionTool)(const xAOD::TruthParticle *)=nullptr) const
void clearTrackParticles (CacheEntry *ent) const
void clearTruthParticles (CacheEntry *ent) const
template<class T, class U>
void sortVectors (const T *container, std::vector< const U * > &vec_pt, std::vector< const U * > &vec_eta, std::vector< const U * > &vec_phi, bool(*selectionTool)(const U *)) const
template<class U, class V>
bool sortedMatch (const U *p, std::vector< const V * > &vec_pt, std::vector< const V * > &vec_eta, std::vector< const V * > &vec_phi, float &dRmin) const
void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

 ASG_TOOL_CLASS1 (dRMatchingTool, IAsgSelectionTool)
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

asg::AcceptInfo m_accept {"dRMatching"}
 Data member(s).
std::vector< std::pair< std::string, std::string > > m_cuts
std::atomic< ULong64_t > m_numProcessed {0}
std::atomic< ULong64_t > m_numPassed {0}
std::vector< ULong64_t > m_numPassedCuts ATLAS_THREAD_SAFE
std::mutex m_mutex
FloatProperty m_dRmax {this, "dRmax", -1.}
 Cut vales.
FloatProperty m_pTResMax {this, "pTResMax", -1.}
SG::SlotSpecificObj< CacheEntry > m_cache ATLAS_THREAD_SAFE
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Tool to perform dR-based matching of tracks and truth particles.

The tool can match both a single track to a set of truth particles, and vice versa. As the tool derives from the general IAsgSelectionTool interface, the actual 'accept' methods has to be invoked using (dynamic) type casting, e.g.

bool dRMatched = (bool) dynamic_cast<dRMatchingTool&>(*m_dRMatchingTool) \ .accept(track, truthParticles, &truthSelectionTool);

to match a track to a subset of truth particle, or

bool dRMatched = (bool) dynamic_cast<dRMatchingTool&>(*m_dRMatchingTool) \ .accept(truth, trackParticles);

to match a truth particle to all tracks. The standard accept(const xAOD::IParticle*) method is disabled.

Optional track- and truth particle selection functions are allowed, to perform the matching to only a subset of the respective containers. If these functions are omitted as arguments, the matching is performed to the all particles in the specified container.

The tool is able to perform matching wrt. dR as well relative pT-resolution, i.e. \Delta p_{T}/p_{T} = \frac{|p_{T,this} - p_{T,other}|}{p_{T,this}} The tool is configured such that a successful match means that all set cuts were passed. That means that if only the dR-cut is set, no pT-resoution cut is imposed, and conversely. In particular, if neither cut is set, no particles pass the matching. The cut values are set in the job option as e.g.

from InDetPhysValMonitoring.InDetPhysValMonitoringConf import \ dRMatchingTool dRMatcher = dRMatchingTool() dRMatcher.dRmax = 0.1 # Disabled: -1 dRMatcher.pTResMax = 0.1 # Disabled: -1 ToolSvc += dRMatcher

The main 'accept' methods are implemented using caching and sorting to avoid O(N^2) complexity from what is essentially nested loops. This speeds up performance drastically, at the cost of transparency. To this end, and for validation purposes, 'acceptLegacy' methods are kept in, which are conceptually simpler and more intuitive, but much slower, than the main methods. However, these legacy methods ought not to be used for actual, even just moderately large runs.

Definition at line 84 of file dRMatchingTool.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ dRMatchingTool()

dRMatchingTool::dRMatchingTool ( const std::string & name)

Constructor(s).

Definition at line 94 of file dRMatchingTool.cxx.

94 :
95 asg::AsgTool(name) {
96 declareInterface<IAsgSelectionTool>(this);
97}

◆ ~dRMatchingTool()

dRMatchingTool::~dRMatchingTool ( )
virtualdefault

Destructor.

Member Function Documentation

◆ accept() [1/3]

asg::AcceptData dRMatchingTool::accept ( const xAOD::IParticle * ) const
overridevirtual

The main accept method: the actual cuts are applied here.

Implements IAsgSelectionTool.

Definition at line 150 of file dRMatchingTool.cxx.

150 {
151
153 "accept(...) function called without needed Truth- or TrackParticleContainer. Please use one of the dRMatchingTool-specific accept methods.");
154
155 return asg::AcceptData (&m_accept);
156}
#define ATH_MSG_ERROR(x)
asg::AcceptInfo m_accept
Data member(s).

◆ accept() [2/3]

asg::AcceptData dRMatchingTool::accept ( const xAOD::TrackParticle * p,
const xAOD::TruthParticleContainer * truthParticles,
bool(* truthSelectionTool )(const xAOD::TruthParticle *) = nullptr ) const

Definition at line 364 of file dRMatchingTool.cxx.

366 {
367 asg::AcceptData acceptData (&m_accept);
368
369 std::lock_guard<std::mutex> lock{m_mutex}; // To guard m_numPassedCuts and m_cache
370 const EventContext& ctx{Gaudi::Hive::currentContext()};
371 CacheEntry* ent{m_cache.get(ctx)};
372 ent->check(ctx.evt());
373
374 // Determine whether to cache current truth particle container
375 checkCacheTruthParticles(truthParticles, ent, truthSelectionTool);
376
377 bool passes = sortedMatch<xAOD::TrackParticle,
379 ent->m_truthParticlesSortedPt,
380 ent->m_truthParticlesSortedEta,
381 ent->m_truthParticlesSortedPhi,
382 ent->m_dRmin);
383
384 // Set cut values.
385 if (m_dRmax > -1) {
386 acceptData.setCutResult("dRmax", passes);
387 }
388 if (m_pTResMax > -1) {
389 acceptData.setCutResult("pTResMax", passes);
390 }
391
392 // Book keep cuts
393 for (const auto& cut : m_cuts) {
394 unsigned int pos = acceptData.getCutPosition(cut.first);
395 if (acceptData.getCutResult(pos)) {
396 m_numPassedCuts[pos]++;
397 }
398 }
399
401 if (acceptData) {
402 m_numPassed++;
403 }
404
405 return acceptData;
406}
FloatProperty m_dRmax
Cut vales.
std::atomic< ULong64_t > m_numProcessed
void checkCacheTruthParticles(const xAOD::TruthParticleContainer *truthParticles, CacheEntry *ent, bool(*truthSelectionTool)(const xAOD::TruthParticle *)=nullptr) const
std::atomic< ULong64_t > m_numPassed
bool sortedMatch(const U *p, std::vector< const V * > &vec_pt, std::vector< const V * > &vec_eta, std::vector< const V * > &vec_phi, float &dRmin) const
std::vector< std::pair< std::string, std::string > > m_cuts
std::mutex m_mutex
FloatProperty m_pTResMax
cut
This script demonstrates how to call a C++ class from Python Also how to use PyROOT is shown.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TruthParticle_v1 TruthParticle
Typedef to implementation.
void check(EventContext::ContextEvt_t evt)

◆ accept() [3/3]

asg::AcceptData dRMatchingTool::accept ( const xAOD::TruthParticle * p,
const xAOD::TrackParticleContainer * trackParticles,
bool(* trackSelectionTool )(const xAOD::TrackParticle *) = nullptr ) const

Definition at line 409 of file dRMatchingTool.cxx.

411 {
412 asg::AcceptData acceptData (&m_accept);
413
414 std::lock_guard<std::mutex> lock{m_mutex}; // To guard m_numPassedCuts and m_cache
415 const EventContext& ctx{Gaudi::Hive::currentContext()};
416 CacheEntry* ent{m_cache.get(ctx)};
417 ent->check(ctx.evt());
418
419 // Determine whether to cache current track particle container
420 checkCacheTrackParticles(trackParticles, ent, trackSelectionTool);
421
422 bool passes = sortedMatch<xAOD::TruthParticle,
423 xAOD::TrackParticle>(truth,
424 ent->m_trackParticlesSortedPt,
425 ent->m_trackParticlesSortedEta,
426 ent->m_trackParticlesSortedPhi,
427 ent->m_dRmin);
428
429 // Set cut values.
430 if (m_dRmax > -1) {
431 acceptData.setCutResult("dRmax", passes);
432 }
433 if (m_pTResMax > -1) {
434 acceptData.setCutResult("pTResMax", passes);
435 }
436
437 // Book keep cuts
438 for (const auto& cut : m_cuts) {
439 unsigned int pos = acceptData.getCutPosition(cut.first);
440 if (acceptData.getCutResult(pos)) {
441 m_numPassedCuts[pos]++;
442 }
443 }
444
446 if (acceptData) {
447 m_numPassed++;
448 }
449
450 return acceptData;
451}
void checkCacheTrackParticles(const xAOD::TrackParticleContainer *trackParticles, CacheEntry *ent, bool(*trackSelectionTool)(const xAOD::TrackParticle *)=nullptr) const
Internal method(s).

◆ acceptLegacy() [1/2]

asg::AcceptData dRMatchingTool::acceptLegacy ( const xAOD::TrackParticle * p,
const xAOD::TruthParticleContainer * truthParticles,
bool(* truthSelectionTool )(const xAOD::TruthParticle *) = nullptr ) const
virtual

dR-matching specific method(s).

Definition at line 454 of file dRMatchingTool.cxx.

456 {
457 asg::AcceptData acceptData (&m_accept);
458
459 std::lock_guard<std::mutex> lock{m_mutex}; // To guard m_numPassedCuts and m_cache
460 const EventContext& ctx{Gaudi::Hive::currentContext()};
461 CacheEntry* ent{m_cache.get(ctx)};
462 ent->check(ctx.evt());
463
464 ent->m_dRmin = 9999.;
465
466 // Define variables.
467 const unsigned int Ncuts(m_cuts.size());
468 bool passes(false), passesThis(false);
469
470 // Loop all truth particles.
471 for (const xAOD::TruthParticle* truth : *truthParticles) {
472 // Ignore all truth particles failing the selection.
473 if (truthSelectionTool and !(*truthSelectionTool)(truth)) {
474 continue;
475 }
476
477 // Compute cut variable values.
478 float dR = comp_deltaR(p, truth);
479 float pTRes = std::fabs(pt(truth) / pt(p) - 1.);
480
481 // Initialise cut monitoring objects.
482 std::vector<bool> vecPassesThis(Ncuts, false);
483
484 // Check whether each individual cut passed.
485 unsigned int icut = 0;
486 if (m_dRmax > -1) {
487 vecPassesThis[icut++] = dR < m_dRmax;
488 }
489 if (m_pTResMax > -1) {
490 vecPassesThis[icut++] = pTRes < m_pTResMax;
491 }
492
493 // Check whether all cuts passed.
494 passesThis = std::all_of(vecPassesThis.begin(),
495 vecPassesThis.end(),
496 [](const bool& v) {
497 return v;
498 });
499 passes |= passesThis;
500
501 // If the current truth particle was matched, check minimal dR.
502 if (passesThis) {
503 ent->m_dRmin = (dR < ent->m_dRmin ? dR : ent->m_dRmin);
504 }
505 }
506
507 // Set cut values.
508 if (m_dRmax > -1) {
509 acceptData.setCutResult("dRmax", passes);
510 }
511 if (m_pTResMax > -1) {
512 acceptData.setCutResult("pTResMax", passes);
513 }
514
515 // Book keep cuts
516 for (const auto& cut : m_cuts) {
517 unsigned int pos = acceptData.getCutPosition(cut.first);
518 if (acceptData.getCutResult(pos)) {
519 m_numPassedCuts[pos]++;
520 }
521 }
522
524 if (acceptData) {
525 m_numPassed++;
526 }
527
528 return acceptData;
529}
const size_t Ncuts

◆ acceptLegacy() [2/2]

asg::AcceptData dRMatchingTool::acceptLegacy ( const xAOD::TruthParticle * p,
const xAOD::TrackParticleContainer * trackParticles,
bool(* trackSelectionTool )(const xAOD::TrackParticle *) = nullptr ) const
virtual

Definition at line 532 of file dRMatchingTool.cxx.

534 {
535 // Reset the results.
536 asg::AcceptData acceptData (&m_accept);
537
538 std::lock_guard<std::mutex> lock{m_mutex}; // To guard m_numPassedCuts and m_cache
539 const EventContext& ctx{Gaudi::Hive::currentContext()};
540 CacheEntry* ent{m_cache.get(ctx)};
541 ent->check(ctx.evt());
542
543 ent->m_dRmin = 9999.;
544
545 // Define variables.
546 const unsigned int Ncuts(m_cuts.size());
547 bool passes(false), passesThis(false);
548
549 // Loop all track particles.
550 for (const xAOD::TrackParticle* track : *trackParticles) {
551 // Ignore all tracks failing the selection.
552 if (trackSelectionTool and !(*trackSelectionTool)(track)) {
553 continue;
554 }
555
556 // Compute cut variable values.
557 float dR = comp_deltaR(p, track);
558 float pTRes = std::fabs(pt(track) / pt(p) - 1.);
559
560 // Initialise cut monitoring objects.
561 std::vector<bool> vecPassesThis(Ncuts, false);
562
563 // Check whether each individual cut passed.
564 unsigned int icut = 0;
565 if (m_dRmax > -1) {
566 vecPassesThis[icut++] = dR < m_dRmax;
567 }
568 if (m_pTResMax > -1) {
569 vecPassesThis[icut++] = pTRes < m_pTResMax;
570 }
571
572 // Check whether all cuts passed.
573 passesThis = std::all_of(vecPassesThis.begin(),
574 vecPassesThis.end(),
575 [](const bool& v) {
576 return v;
577 });
578 passes |= passesThis;
579
580 // If the current track particle was matched, check minimal dR.
581 if (passesThis) {
582 ent->m_dRmin = (dR < ent->m_dRmin ? dR : ent->m_dRmin);
583 }
584 }
585
586 // Set cut values.
587 if (m_dRmax > -1) {
588 acceptData.setCutResult("dRmax", passes);
589 }
590 if (m_pTResMax > -1) {
591 acceptData.setCutResult("pTResMax", passes);
592 }
593
594 // Book keep cuts
595 for (const auto& cut : m_cuts) {
596 unsigned int pos = acceptData.getCutPosition(cut.first);
597 if (acceptData.getCutResult(pos)) {
598 m_numPassedCuts[pos]++;
599 }
600 }
601
603 if (acceptData) {
604 m_numPassed++;
605 }
606
607 return acceptData;
608}

◆ ASG_TOOL_CLASS1()

dRMatchingTool::ASG_TOOL_CLASS1 ( dRMatchingTool ,
IAsgSelectionTool  )
private

◆ checkCacheTrackParticles()

void dRMatchingTool::checkCacheTrackParticles ( const xAOD::TrackParticleContainer * trackParticles,
CacheEntry * ent,
bool(* trackSelectionTool )(const xAOD::TrackParticle *) = nullptr ) const
protected

Internal method(s).

Definition at line 185 of file dRMatchingTool.cxx.

187 {
188 // Check whether to cache.
189 if (*trackParticles == ent->m_baseTrackContainer) {
190 return;
191 }
192
193 // Clear existing cache.
195
196 // Cache track particles.
198 xAOD::TrackParticle>(trackParticles,
199 ent->m_trackParticlesSortedPt,
200 ent->m_trackParticlesSortedEta,
201 ent->m_trackParticlesSortedPhi,
202 trackSelectionTool);
203
204 // Store copy of base track container.
205 ent->m_baseTrackContainer = *trackParticles;
206}
void clearTrackParticles(CacheEntry *ent) const
void sortVectors(const T *container, std::vector< const U * > &vec_pt, std::vector< const U * > &vec_eta, std::vector< const U * > &vec_phi, bool(*selectionTool)(const U *)) const
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".

◆ checkCacheTruthParticles()

void dRMatchingTool::checkCacheTruthParticles ( const xAOD::TruthParticleContainer * truthParticles,
CacheEntry * ent,
bool(* truthSelectionTool )(const xAOD::TruthParticle *) = nullptr ) const
protected

Definition at line 209 of file dRMatchingTool.cxx.

211 {
212 // Check whether to cache.
213 if (*truthParticles == ent->m_baseTruthContainer) {
214 return;
215 }
216
217 // Clear existing cache.
219
220 // Cache truth particles.
222 xAOD::TruthParticle>(truthParticles,
223 ent->m_truthParticlesSortedPt,
224 ent->m_truthParticlesSortedEta,
225 ent->m_truthParticlesSortedPhi,
226 truthSelectionTool);
227
228 // Store copy of base truth container.
229 ent->m_baseTruthContainer = *truthParticles;
230}
void clearTruthParticles(CacheEntry *ent) const
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.

◆ clearTrackParticles()

void dRMatchingTool::clearTrackParticles ( CacheEntry * ent) const
inlineprotected

Definition at line 180 of file dRMatchingTool.h.

180 {
181 ent->m_trackParticlesSortedPt.clear();
182 ent->m_trackParticlesSortedEta.clear();
183 ent->m_trackParticlesSortedPhi.clear();
184 return;
185 }

◆ clearTruthParticles()

void dRMatchingTool::clearTruthParticles ( CacheEntry * ent) const
inlineprotected

Definition at line 189 of file dRMatchingTool.h.

189 {
190 ent->m_truthParticlesSortedPt.clear();
191 ent->m_truthParticlesSortedEta.clear();
192 ent->m_truthParticlesSortedPhi.clear();
193 return;
194 }

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ dRmin()

float dRMatchingTool::dRmin ( ) const

Definition at line 631 of file dRMatchingTool.cxx.

631 {
632 std::lock_guard<std::mutex> lock{m_mutex}; // To guard m_cache
633 const EventContext& ctx{Gaudi::Hive::currentContext()};
634 CacheEntry* ent{m_cache.get(ctx)};
635 ent->check(ctx.evt());
636
637 return ent->m_dRmin;
638}

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ finalize()

StatusCode dRMatchingTool::finalize ( )
overridevirtual

Definition at line 611 of file dRMatchingTool.cxx.

611 {
612 ATH_MSG_INFO("Finalizing " << name() << "...");
613
614 if (m_numProcessed == 0) {
615 ATH_MSG_INFO("No tracks processed in selection tool.");
616 return StatusCode::SUCCESS;
617 }
618 ATH_MSG_INFO(m_numPassed << " / " << m_numProcessed << " = "
619 << m_numPassed * 100. / m_numProcessed
620 << "% passed all cuts.");
621 for (const auto& cut : m_cuts) {
622 ULong64_t numPassed = m_numPassedCuts.at(m_accept.getCutPosition(cut.first));
623 ATH_MSG_INFO(numPassed << " = " << numPassed * 100. / m_numProcessed
624 << "% passed " << cut.first << " cut.");
625 }
626
627 return StatusCode::SUCCESS;
628}
#define ATH_MSG_INFO(x)

◆ getAcceptInfo()

const asg::AcceptInfo & dRMatchingTool::getAcceptInfo ( ) const
overridevirtual

Declare the interface ID for this pure-virtual interface class to the Athena framework.

Method to get the AcceptInfo to query what cuts are defined.

Implements IAsgSelectionTool.

Definition at line 145 of file dRMatchingTool.cxx.

145 {
146 return m_accept;
147}

◆ getKey()

SG::sgkey_t asg::AsgTool::getKey ( const void * ptr) const
inherited

Get the (hashed) key of an object that is in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::TEvent both provide ways for getting the SG::sgkey_t key for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getName
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The hashed key of the object in the store. If not found, an invalid (zero) key.

Definition at line 119 of file AsgTool.cxx.

119 {
120
121#ifdef XAOD_STANDALONE
122 // In case we use @c xAOD::TEvent, we have a direct function call
123 // for this.
124 return evtStore()->event()->getKey( ptr );
125#else
126 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
127 return ( proxy == nullptr ? 0 : proxy->sgkey() );
128#endif // XAOD_STANDALONE
129 }
ServiceHandle< StoreGateSvc > & evtStore()

◆ getName()

const std::string & asg::AsgTool::getName ( const void * ptr) const
inherited

Get the name of an object that is / should be in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::TEvent both provide ways for getting the std::string name for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getKey
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The string name of the object in the store. If not found, an empty string.

Definition at line 106 of file AsgTool.cxx.

106 {
107
108#ifdef XAOD_STANDALONE
109 // In case we use @c xAOD::TEvent, we have a direct function call
110 // for this.
111 return evtStore()->event()->getName( ptr );
112#else
113 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
114 static const std::string dummy = "";
115 return ( proxy == nullptr ? dummy : proxy->name() );
116#endif // XAOD_STANDALONE
117 }

◆ getProperty()

template<class T>
const T * asg::AsgTool::getProperty ( const std::string & name) const
inherited

Get one of the tool's properties.

◆ initialize()

StatusCode dRMatchingTool::initialize ( void )
overridevirtual

SelectionTool method(s).

If no cuts are enabled, force to have length one, such that it will always return 'false'. This is because we want the dRMatchingTool to be ineffecitive in this case, and not select all tracks.

Reimplemented from asg::AsgTool.

Definition at line 102 of file dRMatchingTool.cxx.

102 {
103 if (asg::AsgTool::initialize().isFailure()) {
104 return StatusCode::FAILURE;
105 }
106
107 ATH_MSG_INFO("Initializing " << name() << "...");
108
109 // Clear cuts container.
110 m_cuts.clear();
111
112 // Define cut names and descriptions.
113 if (m_dRmax > -1) {
114 m_cuts.emplace_back("dRmax", "Cut on maximal dR between track and truth particle.");
115 }
116 if (m_pTResMax > -1) {
117 m_cuts.emplace_back("pTResMax",
118 "Cut on maximal, relativ pT difference between track and truth particle.");
119 }
120
121 // Add cuts to the AcceptOmfp.
122 for (const auto& cut : m_cuts) {
123 if (m_accept.addCut(cut.first, cut.second) < 0) {
124 ATH_MSG_ERROR("Failed to add cut " << cut.first << " because the AcceptInfo object is full.");
125 return StatusCode::FAILURE;
126 }
127 }
128
129 // Initialise counters.
130 m_numPassedCuts.resize(m_accept.getNCuts(), 0);
131
137 if (m_accept.getNCuts() == 0) {
138 m_accept.addCut("nop", "Forcing to have length 1.");
139 }
140
141 return StatusCode::SUCCESS;
142}
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition AsgTool.h:133

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msg_level_name()

const std::string & asg::AsgTool::msg_level_name ( ) const
inherited

A deprecated function for getting the message level's name.

Instead of using this, weirdly named function, user code should get the string name of the current minimum message level (in case they really need it...), with:

MSG::name( msg().level() )

This function's name doesn't follow the ATLAS coding rules, and as such will be removed in the not too distant future.

Returns
The string name of the current minimum message level that's printed

Definition at line 101 of file AsgTool.cxx.

101 {
102
103 return MSG::name( msg().level() );
104 }
MsgStream & msg() const
const std::string & name(Level lvl)
Convenience function for translating message levels to strings.
Definition MsgLevel.cxx:19

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ print()

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ sortedMatch()

template<class U, class V>
bool dRMatchingTool::sortedMatch ( const U * p,
std::vector< const V * > & vec_pt,
std::vector< const V * > & vec_eta,
std::vector< const V * > & vec_phi,
float & dRmin ) const
protected

Definition at line 234 of file dRMatchingTool.cxx.

238 {
239 // (Re-)set variables.
240 dRmin = 9999.;
241
242 // Perform search in cached vectors.
243 auto it_pt_lower = m_pTResMax < 0 ? vec_pt.begin() :
244 std::lower_bound(vec_pt.begin(), vec_pt.end(),
245 pt(p) * (1. - m_pTResMax),
246 [](const V* o, const float& val) -> bool {
247 return pt(o) < val;
248 });
249
250 auto it_pt_upper = m_pTResMax < 0 ? vec_pt.end() :
251 std::upper_bound(vec_pt.begin(), vec_pt.end(),
252 pt(p) * (1. + m_pTResMax),
253 [](const float& val, const V* o) -> bool {
254 return val < pt(o);
255 });
256
257 auto it_eta_lower = m_dRmax < 0 ? vec_eta.begin() :
258 std::lower_bound(vec_eta.begin(), vec_eta.end(),
259 eta(p) - m_dRmax,
260 [](const V* o, const float& val) -> bool {
261 return eta(o) < val;
262 });
263
264 auto it_eta_upper = m_dRmax < 0 ? vec_eta.end() :
265 std::upper_bound(vec_eta.begin(), vec_eta.end(),
266 eta(p) + m_dRmax,
267 [](const float& val, const V* o) -> bool {
268 return val < eta(o);
269 });
270
271 // Dealing with cyclic nature of phi: Determining whether phi range wraps
272 // around +-pi.
273 bool wrapLow = phi(p) - m_dRmax < -M_PI;
274 bool wrapHigh = phi(p) + m_dRmax > M_PI;
275 bool wrap = wrapLow or wrapHigh;
276
277 auto it_phi_lower = m_dRmax < 0 ? vec_phi.begin() :
278 std::lower_bound(vec_phi.begin(), vec_phi.end(),
279 phi(p) - m_dRmax + (wrapLow ? 2.*M_PI : 0),
280 [](const V* o, const float& val) -> bool {
281 return phi(o) < val;
282 });
283
284 auto it_phi_upper = m_dRmax < 0 ? vec_phi.end() :
285 std::upper_bound(vec_phi.begin(), vec_phi.end(),
286 phi(p) + m_dRmax + (wrapHigh ? -2.*M_PI : 0),
287 [](const float& val, const V* o) -> bool {
288 return val < phi(o);
289 });
290
291 // Break early if no truth particles passed selection.
292 if (m_pTResMax > 0 and it_pt_upper < it_pt_lower) {
293 return false;
294 } else if (m_dRmax > 0 and it_eta_upper < it_eta_lower) {
295 return false;
296 } else if (m_dRmax > 0 and((!wrap and it_phi_upper < it_phi_lower)or
297 (wrap and it_phi_upper > it_phi_lower))) {
298 return false;
299 }
300
301 // Initialise base set.
302 std::vector< const V* > set(vec_pt);
303
304 // -- Sort, pointer-based; necessary for set_intersection.
305 std::sort(set.begin(), set.end());
306
307 // Compute subset of selected truth particles.
308 std::vector< const V* > subset_pt(it_pt_lower, it_pt_upper);
309 std::vector< const V* > subset_eta(it_eta_lower, it_eta_upper);
310 std::vector< const V* > subset_phi;
311 if (!wrap) {
312 subset_phi = std::vector< const V* >(it_phi_lower, it_phi_upper);
313 } else {
314 subset_phi = std::vector< const V* >(vec_phi.begin(), it_phi_upper);
315 subset_phi.insert(subset_phi.end(), it_phi_lower, vec_phi.end());
316 }
317
318 // Add subsets according to specified cut values.
319 std::vector< std::vector< const V* > > subsets;
320 if (m_pTResMax > 0) {
321 subsets.push_back(subset_pt);
322 }
323 if (m_dRmax > 0) {
324 subsets.push_back(subset_eta);
325 subsets.push_back(subset_phi);
326 }
327
328 // Compute successive intersections between base set and subset.
329 for (std::vector< const V* > subset : subsets) {
330 // -- Sort, pointer-based; necessary for set::set_intersection.
331 std::sort(subset.begin(), subset.end());
332
333 // -- Set intersection.
334 std::vector< const V* > intersection;
335 std::set_intersection(set.begin(), set.end(),
336 subset.begin(), subset.end(),
337 std::back_inserter(intersection));
338
339 // -- Break early if intersection is empty.
340 if (intersection.size() == 0) {
341 return false;
342 }
343
345 }
346
347 // If only pT-matching, we're done.
348 if (m_dRmax < 0) {
349 return set.size() > 0;
350 }
351
352 // Otherwise, compute dR for all remaining particles.
353 bool passes = false;
354 for (const V* other : set) {
355 float dR = comp_deltaR(p, other);
356 dRmin = (dR < dRmin ? dR : dRmin);
357 passes |= dRmin < m_dRmax;
358 }
359
360 return passes;
361}
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
float dRmin() const
std::vector< std::string > intersection(std::vector< std::string > &v1, std::vector< std::string > &v2)
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition bitmask.h:232
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.

◆ sortVectors()

template<class T, class U>
void dRMatchingTool::sortVectors ( const T * container,
std::vector< const U * > & vec_pt,
std::vector< const U * > & vec_eta,
std::vector< const U * > & vec_phi,
bool(* selectionTool )(const U *) ) const
protected

Definition at line 160 of file dRMatchingTool.cxx.

164 {
165 // Look all particles in container.
166 for (const U* p : *container) {
167 // Ignore particles not passing the selection, if applicable.
168 if (selectionTool and !(*selectionTool)(p)) {
169 continue;
170 }
171
172 // Append passing particles to cached vectors.
173 vec_pt.push_back(p);
174 vec_eta.push_back(p);
175 vec_phi.push_back(p);
176 }
177
178 // Sort vectors.
179 std::sort(vec_pt.begin(), vec_pt.end(), sort_pt <U>);
180 std::sort(vec_eta.begin(), vec_eta.end(), sort_eta<U>);
181 std::sort(vec_phi.begin(), vec_phi.end(), sort_phi<U>);
182}

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, AthCheckedComponent<::AthAlgTool >, and DerivationFramework::CfAthAlgTool.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/2]

std::vector<ULong64_t> m_numPassedCuts dRMatchingTool::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 223 of file dRMatchingTool.h.

◆ ATLAS_THREAD_SAFE [2/2]

SG::SlotSpecificObj<CacheEntry> m_cache dRMatchingTool::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 233 of file dRMatchingTool.h.

◆ m_accept

asg::AcceptInfo dRMatchingTool::m_accept {"dRMatching"}
private

Data member(s).

Definition at line 216 of file dRMatchingTool.h.

216{"dRMatching"};

◆ m_cuts

std::vector<std::pair<std::string, std::string> > dRMatchingTool::m_cuts
private

Definition at line 218 of file dRMatchingTool.h.

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_dRmax

FloatProperty dRMatchingTool::m_dRmax {this, "dRmax", -1.}
private

Cut vales.

Definition at line 228 of file dRMatchingTool.h.

228{this, "dRmax", -1.};

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_mutex

std::mutex dRMatchingTool::m_mutex
mutableprivate

Definition at line 224 of file dRMatchingTool.h.

◆ m_numPassed

std::atomic<ULong64_t> dRMatchingTool::m_numPassed {0}
mutableprivate

Definition at line 222 of file dRMatchingTool.h.

222{0}; // !< a counter of the number of tracks that passed all cuts

◆ m_numProcessed

std::atomic<ULong64_t> dRMatchingTool::m_numProcessed {0}
mutableprivate

Definition at line 221 of file dRMatchingTool.h.

221{0}; // !< a counter of the number of tracks proccessed

◆ m_pTResMax

FloatProperty dRMatchingTool::m_pTResMax {this, "pTResMax", -1.}
private

Definition at line 230 of file dRMatchingTool.h.

230{this, "pTResMax", -1.};

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


The documentation for this class was generated from the following files: