ATLAS Offline Software
Loading...
Searching...
No Matches
MuonLRTMergingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// MuonLRTMergingAlg
7// author Sagar Addepalli: sagara17@SPAMNOT_CERN.CH
9
11// Muon merger algorirthm is a wrapper algorithm around MuonMerger
12// to be used downstream for combining LRTmuons and standard muons
22
23namespace CP{
24 MuonLRTMergingAlg::MuonLRTMergingAlg( const std::string& name, ISvcLocator* svcLoc )
25 : EL::AnaReentrantAlgorithm( name, svcLoc ){
26 //nothing to do here
27 }
28
30
31 // Greet the user:
32 ATH_MSG_DEBUG( "Initialising" );
33
35 ATH_CHECK( m_promptMuonLocation.initialize() );
36 ATH_CHECK( m_lrtMuonLocation.initialize() );
37 ATH_CHECK( m_outMuonLocation.initialize() );
40 ATH_CHECK( m_promptIsLRTKey.initialize() );
41 ATH_CHECK( m_lrtIsLRTKey.initialize() );
42
44 if (m_overlapRemovalTool.empty()){
45 asg::AsgToolConfig config("CP::MuonLRTOverlapRemovalTool/MuonLRTOverlapRemovalTool");
46 ATH_CHECK(config.setProperty("overlapStrategy",m_ORstrategy.value()));
47 ATH_CHECK(config.setProperty("UseRun3WP",m_useRun3WP.value()));
48 ATH_CHECK(config.makePrivateTool(m_overlapRemovalTool));
49 }
50
51 // Retrieve the tools
52 ATH_CHECK( m_overlapRemovalTool.retrieve() );
53 // Return gracefully:
54 return StatusCode::SUCCESS;
55 }
56
57 StatusCode MuonLRTMergingAlg::execute(const EventContext &ctx) const {
58
59 // Setup containers for output, to avoid const conversions setup two different kind of containers
60 std::unique_ptr<ConstDataVector<xAOD::MuonContainer>> outputViewCol;
61 std::unique_ptr<xAOD::MuonContainer> outputCol;
62 std::unique_ptr<xAOD::MuonAuxContainer> outputAuxCol;
64 outputViewCol = std::make_unique<ConstDataVector<xAOD::MuonContainer>>(SG::VIEW_ELEMENTS);
65 } else {
66 outputCol = std::make_unique<xAOD::MuonContainer>();
67 outputAuxCol = std::make_unique<xAOD::MuonAuxContainer>();
68 outputCol->setStore(outputAuxCol.get());
69 }
70
74 if (!promptCol.isValid()) {
75 ATH_MSG_FATAL("Unable to retrieve xAOD::MuonContainer, \"" << m_promptMuonLocation << "\", cannot run the LRT muon merger!");
76 return StatusCode::FAILURE;
77 }
78 if (!lrtCol.isValid()) {
79 ATH_MSG_FATAL("Unable to retrieve xAOD::MuonContainer, \"" << m_lrtMuonLocation << "\", cannot run the LRT muon merger!");
80 return StatusCode::FAILURE;
81 }
82
83 // Check and resolve overlaps
84 std::vector<bool> writePromptMuon;
85 std::vector<bool> writeLRTMuon;
86 m_overlapRemovalTool->checkOverlap(*promptCol, *lrtCol, writePromptMuon, writeLRTMuon);
87
88 // Decorate the muons with their locations.
89 // 0 if prompt, 1 if LRT
92 for (const xAOD::Muon* mu : *promptCol) promptIsLRT(*mu) = 0;
93 for (const xAOD::Muon* mu : *lrtCol) lrtIsLRT(*mu) = 1;
94
95 // and merge
97 outputViewCol->reserve(promptCol->size() + lrtCol->size());
98 ATH_CHECK(mergeMuon(*promptCol, writePromptMuon, outputViewCol.get()));
99 ATH_CHECK(mergeMuon(*lrtCol, writeLRTMuon, outputViewCol.get()));
100 } else {
101 outputCol->reserve(promptCol->size() + lrtCol->size());
102 ATH_CHECK(mergeMuon(*promptCol, writePromptMuon, outputCol.get()));
103 ATH_CHECK(mergeMuon(*lrtCol, writeLRTMuon, outputCol.get()));
104 }
105
106 // write
109 ATH_CHECK(h_write.record(std::move(outputViewCol)));
110 }
111 else {
113 ATH_CHECK(h_write.record(std::move(outputCol), std::move(outputAuxCol)));
114 }
115
116 return StatusCode::SUCCESS;
117
118 }
119
121 // Merge muon collections and remove duplicates
123
125 const std::vector<bool> & writeMuon,
126 ConstDataVector<xAOD::MuonContainer>* outputCol) const{
127 // loop over muons, accept them and add them into association tool
128 for(const xAOD::Muon* muon : muonCol){
129 // add muon into output
130 if (writeMuon.at(muon->index())){
131 outputCol->push_back(muon);
132 }
133 }
134 return StatusCode::SUCCESS;
135 }
136
138 const std::vector<bool> & writeMuon,
139 xAOD::MuonContainer* outputCol) const{
140 // loop over muons, accept them and add them into association tool
141 static const SG::Decorator<ElementLink<xAOD::MuonContainer>> originalMuonLink("originalMuonLink");
142 for(const xAOD::Muon* muon : muonCol){
143 // add muon into output
144 if (writeMuon.at(muon->index())){
145 auto newMuon = std::make_unique<xAOD::Muon>(*muon);
147 myLink.toIndexedElement(muonCol, muon->index());
148 originalMuonLink(*newMuon) = myLink;
149 setOriginalObjectLink(*muon, *newMuon);
150 static const SG::Accessor <char> isLRT("isLRT");
151 isLRT(*newMuon) = isLRT(*muon);
152 outputCol->push_back(std::move(newMuon));
153 }
154 }
155 return StatusCode::SUCCESS;
156 }
157}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_FATAL(x,...)
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
Handle class for recording to StoreGate.
DataVector adapter that acts like it holds const pointers.
ToolHandle< CP::IMuonLRTOverlapRemovalTool > m_overlapRemovalTool
MuonLRTMergingAlg(const std::string &name, ISvcLocator *pSvcLocator)
the standard constructor
SG::WriteHandleKey< xAOD::MuonContainer > m_outMuonLocation
Combined muon collection.
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_lrtIsLRTKey
StatusCode initialize() override
Gaudi::Property< bool > m_createViewCollection
flag to create a view collection rather than building deep-copies (true by default)
StatusCode mergeMuon(const xAOD::MuonContainer &muonCol, const std::vector< bool > &muonIsGood, ConstDataVector< xAOD::MuonContainer > *outputCol) const
Private methods:
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_promptIsLRTKey
SG::WriteHandleKey< ConstDataVector< xAOD::MuonContainer > > m_outMuonViewLocation
Combined muon view collection, set from m_outMuonLocation in initialize().
SG::ReadHandleKey< xAOD::MuonContainer > m_lrtMuonLocation
LRT muon collection to be merged.
SG::ReadHandleKey< xAOD::MuonContainer > m_promptMuonLocation
Private data:
StatusCode execute(const EventContext &ctx) const override
Gaudi::Property< bool > m_useRun3WP
Gaudi::Property< int > m_ORstrategy
allows to pass an overlap removal strategy to the underlying removal tool, without manually configuri...
DataVector adapter that acts like it holds const pointers.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
AnaReentrantAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
constructor with parameters
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
an object that can create a AsgTool
Select isolated Photons, Electrons and Muons.
This module defines the arguments passed from the BATCH driver to the BATCH worker.
SG::Decorator< T, ALLOC > Decorator
Helper class to provide type-safe access to aux data, specialized for JaggedVecElt.
Definition AuxElement.h:576
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
bool setOriginalObjectLink(const IParticle &original, IParticle &copy)
This function should be used by CP tools when they make a deep copy of an object in their correctedCo...
Muon_v1 Muon
Reference the current persistent version:
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".