ATLAS Offline Software
Loading...
Searching...
No Matches
MuonR4::MlMsTrackSeeder Class Reference

#include <MlMsTrackSeeder.h>

Inheritance diagram for MuonR4::MlMsTrackSeeder:
Collaboration diagram for MuonR4::MlMsTrackSeeder:

Classes

struct  Config

Public Member Functions

 MlMsTrackSeeder (const std::string &msgName, Config &&cfg)
const MsTrackSeederbaselineSeeder () const
std::unique_ptr< MsTrackSeedContainerfindTrackSeeds (const EventContext &ctx, const ActsTrk::GeometryContext &gctx, const xAOD::MuonSegmentContainer &segments) const
bool msgLvl (const MSG::Level lvl) const
 Test the output level.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.
void setLevel (MSG::Level lvl)
 Change the current logging level.

Private Member Functions

void initMessaging () const
 Initialize our message level and MessageSvc.

Private Attributes

Config m_cfg {}
MsTrackSeeder m_baselineSeeder
std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels).
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging).

Detailed Description

Definition at line 15 of file MlMsTrackSeeder.h.

Constructor & Destructor Documentation

◆ MlMsTrackSeeder()

MuonR4::MlMsTrackSeeder::MlMsTrackSeeder ( const std::string & msgName,
Config && cfg )

Definition at line 13 of file MlMsTrackSeeder.cxx.

14 : AthMessaging{msgName + ".MlMsTrackSeeder"},
15 m_cfg{std::move(cfg)},
16 m_baselineSeeder{msgName + ".BaselineMsTrackSeeder", MsTrackSeeder::Config{m_cfg.baselineSeeder}} {}
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
MsTrackSeeder m_baselineSeeder

Member Function Documentation

◆ baselineSeeder()

const MsTrackSeeder & MuonR4::MlMsTrackSeeder::baselineSeeder ( ) const
inline

Definition at line 28 of file MlMsTrackSeeder.h.

28{ return m_baselineSeeder; }

◆ findTrackSeeds()

std::unique_ptr< MsTrackSeedContainer > MuonR4::MlMsTrackSeeder::findTrackSeeds ( const EventContext & ctx,
const ActsTrk::GeometryContext & gctx,
const xAOD::MuonSegmentContainer & segments ) const

Definition at line 18 of file MlMsTrackSeeder.cxx.

20 {
21 SG::AuxElement::ConstAccessor<std::vector<unsigned>> acc{m_cfg.candidateDecoration};
22 std::unordered_map<unsigned, std::vector<const xAOD::MuonSegment*>> groups;
23 groups.reserve(segments.size());
24
25 bool sawDecor = false;
26 for (const xAOD::MuonSegment* seg : segments) {
27 if (!seg || !acc.isAvailable(*seg)) continue;
28 sawDecor = true;
29 for (const unsigned id : acc(*seg)) groups[id].push_back(seg);
30 }
31
32 if (!sawDecor) {
33 ATH_MSG_DEBUG("MlMsTrackSeeder: no ML decoration found on any segment."
34 << (m_cfg.fallbackToBaselineIfUndecorated ? " Falling back to baseline seeder." : " Returning empty seed set."));
35 if (m_cfg.fallbackToBaselineIfUndecorated) return m_baselineSeeder.findTrackSeeds(ctx, gctx, segments);
36 return std::make_unique<MsTrackSeedContainer>();
37 }
38
39 ATH_MSG_DEBUG("MlMsTrackSeeder: " << groups.size() << " ML candidate group(s) from "
40 << segments.size() << " segment(s)");
41
42 auto out = std::make_unique<MsTrackSeedContainer>();
43
44 std::vector<unsigned> orderedIds;
45 orderedIds.reserve(groups.size());
46 for (const auto& [id, _] : groups) orderedIds.push_back(id);
47 std::sort(orderedIds.begin(), orderedIds.end());
48
49 struct CandidateResult {
50 unsigned id{0};
51 std::size_t nSegments{0};
52 std::unique_ptr<MsTrackSeedContainer> seeds{};
53 };
54
55 std::vector<CandidateResult> results(orderedIds.size());
56
57 auto runOneCandidate = [&](std::size_t idx) {
58 const unsigned id = orderedIds[idx];
59 auto& segs = groups[id];
60 std::sort(segs.begin(), segs.end());
61 segs.erase(std::unique(segs.begin(), segs.end()), segs.end());
62 results[idx].id = id;
63 results[idx].nSegments = segs.size();
64
65 if (segs.size() < m_cfg.minSegmentsPerCandidate) {
66 return;
67 }
68
69 ConstDataVector<xAOD::MuonSegmentContainer> viewCont{SG::VIEW_ELEMENTS};
70 for (const xAOD::MuonSegment* seg : segs) {
71 viewCont.push_back(seg);
72 }
73 results[idx].seeds = m_baselineSeeder.findTrackSeeds(ctx, gctx, *viewCont.asDataVector());
74 };
75
76 if (m_cfg.runCandidatesInParallel && orderedIds.size() > 1) {
77 tbb::parallel_for(tbb::blocked_range<std::size_t>(0, orderedIds.size()),
78 [&](const tbb::blocked_range<std::size_t>& range) {
79 for (std::size_t idx = range.begin(); idx != range.end(); ++idx) {
80 runOneCandidate(idx);
81 }
82 });
83 } else {
84 for (std::size_t idx = 0; idx < orderedIds.size(); ++idx) {
85 runOneCandidate(idx);
86 }
87 }
88
89 for (CandidateResult& result : results) {
90 const std::size_t nSeeds = result.seeds ? result.seeds->size() : 0;
91 ATH_MSG_DEBUG(" candidate " << result.id << ": "
92 << result.nSegments << " segment(s) -> "
93 << nSeeds << " seed(s)");
94 if (!result.seeds) continue;
95 for (MsTrackSeed& seed : *result.seeds) {
96 out->push_back(std::move(seed));
97 }
98 }
99
100 // Remove exact duplicates induced by overlapping ML candidate IDs.
101 // This is intentionally pointer-based: if two seeds contain the same segment set,
102 // they will drive the same downstream fit attempt.
103 std::set<std::vector<const xAOD::MuonSegment*>> seen;
104 MsTrackSeedContainer uniqueSeeds{};
105 for (MsTrackSeed& seed : *out) {
106 std::vector<const xAOD::MuonSegment*> key = seed.segments();
107 std::sort(key.begin(), key.end());
108 if (!seen.insert(key).second) continue;
109 uniqueSeeds.push_back(std::move(seed));
110 }
111 *out = std::move(uniqueSeeds);
112
113 ATH_MSG_DEBUG("MlMsTrackSeeder: total seeds produced = " << out->size()
114 << (out->empty() && m_cfg.fallbackToBaselineIfNoCandidates ? " — falling back to baseline seeder" : ""));
115 if (out->empty() && m_cfg.fallbackToBaselineIfNoCandidates) return m_baselineSeeder.findTrackSeeds(ctx, gctx, segments);
116 return out;
117}
#define ATH_MSG_DEBUG(x)
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
size_type size() const noexcept
Returns the number of elements in the collection.
std::vector< MsTrackSeed > MsTrackSeedContainer
Definition MsTrackSeed.h:63
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
MuonSegment_v1 MuonSegment
Reference the current persistent version:

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 167 of file AthMessaging.h.

168{
169 MsgStream* ms = m_msg_tls.get();
170 if (!ms) {
171 if (!m_initialized.test_and_set()) initMessaging();
172 ms = new MsgStream(m_imsg,m_nm);
173 m_msg_tls.reset( ms );
174 }
175
176 ms->setLevel (m_lvl);
177 return *ms;
178}
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels).
void initMessaging() const
Initialize our message level and MessageSvc.

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 182 of file AthMessaging.h.

183{ return msg() << lvl; }
MsgStream & msg() const
The standard message stream.

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152{
153 // If user did not set explicit message level we have to initialize
154 // the messaging and retrieve the default via the MessageSvc.
155 if (m_lvl==MSG::NIL && !m_initialized.test_and_set()) initMessaging();
156
157 if (m_lvl <= lvl) {
158 msg() << lvl;
159 return true;
160 } else {
161 return false;
162 }
163}

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29{
30 m_lvl = lvl;
31}

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging).

Definition at line 141 of file AthMessaging.h.

◆ m_baselineSeeder

MsTrackSeeder MuonR4::MlMsTrackSeeder::m_baselineSeeder
private

Definition at line 36 of file MlMsTrackSeeder.h.

◆ m_cfg

Config MuonR4::MlMsTrackSeeder::m_cfg {}
private

Definition at line 35 of file MlMsTrackSeeder.h.

35{};

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels).

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.


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