ATLAS Offline Software
Loading...
Searching...
No Matches
MuonLRTMergingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
20
21namespace CP{
22 MuonLRTMergingAlg::MuonLRTMergingAlg( const std::string& name, ISvcLocator* svcLoc )
23 : EL::AnaReentrantAlgorithm( name, svcLoc ){
24 //nothing to do here
25 }
26
28
29 // Greet the user:
30 ATH_MSG_INFO( "Initialising" );
31
33 ATH_CHECK( m_promptMuonLocation.initialize() );
34 ATH_CHECK( m_lrtMuonLocation.initialize() );
35 ATH_CHECK( m_outMuonLocation.initialize() );
36 ATH_CHECK( m_promptIsLRTKey.initialize() );
37 ATH_CHECK( m_lrtIsLRTKey.initialize() );
38
40 if (m_overlapRemovalTool.empty()){
41 asg::AsgToolConfig config("CP::MuonLRTOverlapRemovalTool/MuonLRTOverlapRemovalTool");
42 ATH_CHECK(config.setProperty("overlapStrategy",m_ORstrategy.value()));
43 ATH_CHECK(config.setProperty("UseRun3WP",m_useRun3WP.value()));
44 ATH_CHECK(config.makePrivateTool(m_overlapRemovalTool));
45 }
46
47 // Retrieve the tools
48 ATH_CHECK( m_overlapRemovalTool.retrieve() );
49 // Return gracefully:
50 return StatusCode::SUCCESS;
51 }
52
53 StatusCode MuonLRTMergingAlg::execute(const EventContext &ctx) const {
54
55 // Setup containers for output, to avoid const conversions setup two different kind of containers
56 auto outputViewCol = std::make_unique<ConstDataVector<xAOD::MuonContainer>>(SG::VIEW_ELEMENTS);
57 auto outputCol = std::make_unique<xAOD::MuonContainer>();
58
59 std::unique_ptr<xAOD::MuonAuxContainer> outputAuxCol;
61 outputAuxCol = std::make_unique<xAOD::MuonAuxContainer>();
62 outputCol->setStore(outputAuxCol.get());
63 }
64
68 if (!promptCol.isValid()) {
69 ATH_MSG_FATAL("Unable to retrieve xAOD::MuonContainer, \"" << m_promptMuonLocation << "\", cannot run the LRT muon merger!");
70 return StatusCode::FAILURE;
71 }
72 if (!lrtCol.isValid()) {
73 ATH_MSG_FATAL("Unable to retrieve xAOD::MuonContainer, \"" << m_lrtMuonLocation << "\", cannot run the LRT muon merger!");
74 return StatusCode::FAILURE;
75 }
76
77 // Check and resolve overlaps
78 std::vector<bool> writePromptMuon;
79 std::vector<bool> writeLRTMuon;
80 m_overlapRemovalTool->checkOverlap(*promptCol, *lrtCol, writePromptMuon, writeLRTMuon);
81
82 // Decorate the muons with their locations.
83 // 0 if prompt, 1 if LRT
86 for (const xAOD::Muon* mu : *promptCol) promptIsLRT(*mu) = 0;
87 for (const xAOD::Muon* mu : *lrtCol) lrtIsLRT(*mu) = 1;
88
89 // and merge
91 outputViewCol->reserve(promptCol->size() + lrtCol->size());
92 ATH_CHECK(mergeMuon(*promptCol, writePromptMuon, outputViewCol.get()));
93 ATH_CHECK(mergeMuon(*lrtCol, writeLRTMuon, outputViewCol.get()));
94 } else {
95 outputCol->reserve(promptCol->size() + lrtCol->size());
96 ATH_CHECK(mergeMuon(*promptCol, writePromptMuon, outputCol.get()));
97 ATH_CHECK(mergeMuon(*lrtCol, writeLRTMuon, outputCol.get()));
98 }
99
100 // write
103 ATH_CHECK(evtStore()->record(outputViewCol.release(), m_outMuonLocation.key()));
104 }
105 else {
106 ATH_CHECK(h_write.record(std::move(outputCol), std::move(outputAuxCol)));
107 }
108
109 return StatusCode::SUCCESS;
110
111 }
112
114 // Merge muon collections and remove duplicates
116
118 const std::vector<bool> & writeMuon,
119 ConstDataVector<xAOD::MuonContainer>* outputCol) const{
120 // loop over muons, accept them and add them into association tool
121 if(muonCol.empty()) {return StatusCode::SUCCESS;}
122
123 for(const xAOD::Muon* muon : muonCol){
124 // add muon into output
125 if (writeMuon.at(muon->index())){
126 outputCol->push_back(muon);
127 }
128 }
129 return StatusCode::SUCCESS;
130 }
131
133 const std::vector<bool> & writeMuon,
134 xAOD::MuonContainer* outputCol) const{
135 // loop over muons, accept them and add them into association tool
136 if(muonCol.empty()) {return StatusCode::SUCCESS;}
137 static const SG::Decorator<ElementLink<xAOD::MuonContainer>> originalMuonLink("originalMuonLink");
138 for(const xAOD::Muon* muon : muonCol){
139 // add muon into output
140 if (writeMuon.at(muon->index())){
141 xAOD::Muon* newMuon = new xAOD::Muon(*muon);
143 myLink.toIndexedElement(muonCol, muon->index());
144 originalMuonLink(*newMuon) = myLink;
145 setOriginalObjectLink(*muon, *newMuon);
146 static const SG::Accessor <char> isLRT("isLRT");
147 isLRT(*newMuon) = isLRT(*muon);
148 outputCol->push_back(newMuon);
149 }
150 }
151 return StatusCode::SUCCESS;
152 }
153}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
Handle class for adding a decoration to an object.
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
Vector of muon collections to be merged.
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_lrtIsLRTKey
StatusCode initialize() override
Gaudi::Property< bool > m_createViewCollection
Combined muon collection.
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::ReadHandleKey< xAOD::MuonContainer > m_lrtMuonLocation
Vector of muon collections 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.
bool empty() const noexcept
Returns true if the collection is empty.
AnaReentrantAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
constructor with parameters
Helper class to provide type-safe access to aux data.
Definition Decorator.h:59
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.
@ 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".