ATLAS Offline Software
MuonLRTMergingAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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
18 #include <AsgTools/AsgToolConfig.h>
19 
20 namespace CP{
21  MuonLRTMergingAlg::MuonLRTMergingAlg( const std::string& name, ISvcLocator* svcLoc )
22  : EL::AnaAlgorithm( name, svcLoc ){
23  //nothing to do here
24  }
25 
27 
28  // Greet the user:
29  ATH_MSG_INFO( "Initialising" );
30 
32  ATH_CHECK( m_promptMuonLocation.initialize() );
33  ATH_CHECK( m_lrtMuonLocation.initialize() );
34  ATH_CHECK( m_outMuonLocation.initialize() );
35 
37  if (m_overlapRemovalTool.empty()){
38  asg::AsgToolConfig config("CP::MuonLRTOverlapRemovalTool/MuonLRTOverlapRemovalTool");
39  ATH_CHECK(config.setProperty("overlapStrategy",m_ORstrategy.value()));
40  ATH_CHECK(config.setProperty("UseRun3WP",m_useRun3WP.value()));
41  ATH_CHECK(config.makePrivateTool(m_overlapRemovalTool));
42  }
43 
44  // Retrieve the tools
45  ATH_CHECK( m_overlapRemovalTool.retrieve() );
46  // Return gracefully:
47  return StatusCode::SUCCESS;
48  }
49 
51 
52  const EventContext& ctx = Gaudi::Hive::currentContext();
53 
54  // Setup containers for output, to avoid const conversions setup two different kind of containers
55  auto outputViewCol = std::make_unique<ConstDataVector<xAOD::MuonContainer>>(SG::VIEW_ELEMENTS);
56  auto outputCol = std::make_unique<xAOD::MuonContainer>();
57 
58  std::unique_ptr<xAOD::MuonAuxContainer> outputAuxCol;
60  outputAuxCol = std::make_unique<xAOD::MuonAuxContainer>();
61  outputCol->setStore(outputAuxCol.get());
62  }
63 
67  if (!promptCol.isValid()) {
68  ATH_MSG_FATAL("Unable to retrieve xAOD::MuonContainer, \"" << m_promptMuonLocation << "\", cannot run the LRT muon merger!");
69  return StatusCode::FAILURE;
70  }
71  if (!lrtCol.isValid()) {
72  ATH_MSG_FATAL("Unable to retrieve xAOD::MuonContainer, \"" << m_lrtMuonLocation << "\", cannot run the LRT muon merger!");
73  return StatusCode::FAILURE;
74  }
75 
76  // Check and resolve overlaps
77  std::vector<bool> writePromptMuon;
78  std::vector<bool> writeLRTMuon;
79  m_overlapRemovalTool->checkOverlap(*promptCol, *lrtCol, writePromptMuon, writeLRTMuon);
80 
81  // Decorate the muons with their locations.
82  static const SG::AuxElement::Decorator<char> isLRT("isLRT"); //0 if prompt, 1 if LRT
83  for (const xAOD::Muon* mu : *promptCol) isLRT(*mu) = 0;
84  for (const xAOD::Muon* mu : *lrtCol) isLRT(*mu) = 1;
85 
86  // and merge
88  outputViewCol->reserve(promptCol->size() + lrtCol->size());
89  ATH_CHECK(mergeMuon(*promptCol, writePromptMuon, outputViewCol.get()));
90  ATH_CHECK(mergeMuon(*lrtCol, writeLRTMuon, outputViewCol.get()));
91  } else {
92  outputCol->reserve(promptCol->size() + lrtCol->size());
93  ATH_CHECK(mergeMuon(*promptCol, writePromptMuon, outputCol.get()));
94  ATH_CHECK(mergeMuon(*lrtCol, writeLRTMuon, outputCol.get()));
95  }
96 
97  // write
100  ATH_CHECK(evtStore()->record(outputViewCol.release(), m_outMuonLocation.key()));
101  }
102  else {
103  ATH_CHECK(h_write.record(std::move(outputCol), std::move(outputAuxCol)));
104  }
105 
106  return StatusCode::SUCCESS;
107 
108  }
109 
111  // Merge muon collections and remove duplicates
113 
115  const std::vector<bool> & writeMuon,
116  ConstDataVector<xAOD::MuonContainer>* outputCol) const{
117  // loop over muons, accept them and add them into association tool
118  if(muonCol.empty()) {return StatusCode::SUCCESS;}
119 
120  for(const xAOD::Muon* muon : muonCol){
121  // add muon into output
122  if (writeMuon.at(muon->index())){
123  outputCol->push_back(muon);
124  }
125  }
126  return StatusCode::SUCCESS;
127  }
128 
130  const std::vector<bool> & writeMuon,
131  xAOD::MuonContainer* outputCol) const{
132  // loop over muons, accept them and add them into association tool
133  if(muonCol.empty()) {return StatusCode::SUCCESS;}
134  static const SG::AuxElement::Decorator<ElementLink<xAOD::MuonContainer>> originalMuonLink("originalMuonLink");
135  for(const xAOD::Muon* muon : muonCol){
136  // add muon into output
137  if (writeMuon.at(muon->index())){
138  xAOD::Muon* newMuon = new xAOD::Muon(*muon);
140  myLink.toIndexedElement(muonCol, muon->index());
141  originalMuonLink(*newMuon) = myLink;
142  outputCol->push_back(newMuon);
143  }
144  }
145  return StatusCode::SUCCESS;
146  }
147 }
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CP::MuonLRTMergingAlg::m_overlapRemovalTool
ToolHandle< CP::IMuonLRTOverlapRemovalTool > m_overlapRemovalTool
Definition: MuonLRTMergingAlg.h:52
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
CurrentContext.h
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CP::MuonLRTMergingAlg::m_lrtMuonLocation
SG::ReadHandleKey< xAOD::MuonContainer > m_lrtMuonLocation
Vector of muon collections to be merged.
Definition: MuonLRTMergingAlg.h:47
CP::MuonLRTMergingAlg::m_ORstrategy
Gaudi::Property< int > m_ORstrategy
allows to pass an overlap removal strategy to the underlying removal tool, without manually configuri...
Definition: MuonLRTMergingAlg.h:56
CP::MuonLRTMergingAlg::m_outMuonLocation
SG::WriteHandleKey< xAOD::MuonContainer > m_outMuonLocation
Vector of muon collections to be merged.
Definition: MuonLRTMergingAlg.h:48
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
CP::MuonLRTMergingAlg::initialize
StatusCode initialize() override
Definition: MuonLRTMergingAlg.cxx:26
MuonAuxContainer.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
asg::AsgToolConfig
an object that can create a AsgTool
Definition: AsgToolConfig.h:22
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
CP::MuonLRTMergingAlg::MuonLRTMergingAlg
MuonLRTMergingAlg(const std::string &name, ISvcLocator *pSvcLocator)
the standard constructor
Definition: MuonLRTMergingAlg.cxx:21
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AsgToolConfig.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
MuonLRTMergingAlg.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
CP::MuonLRTMergingAlg::execute
StatusCode execute() override
Definition: MuonLRTMergingAlg.cxx:50
xAOD::Muon
Muon_v1 Muon
Reference the current persistent version:
Definition: Event/xAOD/xAODMuon/xAODMuon/Muon.h:13
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ConstDataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
python.HLT.Muon.MuonRecoSequences.isLRT
def isLRT(name)
Definition: MuonRecoSequences.py:66
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
CP::MuonLRTMergingAlg::mergeMuon
StatusCode mergeMuon(const xAOD::MuonContainer &muonCol, const std::vector< bool > &muonIsGood, ConstDataVector< xAOD::MuonContainer > *outputCol) const
Private methods:
Definition: MuonLRTMergingAlg.cxx:114
config
std::vector< std::string > config
Definition: fbtTestBasics.cxx:72
CP::MuonLRTMergingAlg::m_useRun3WP
Gaudi::Property< bool > m_useRun3WP
Definition: MuonLRTMergingAlg.h:57
CP::MuonLRTMergingAlg::m_promptMuonLocation
SG::ReadHandleKey< xAOD::MuonContainer > m_promptMuonLocation
Private data:
Definition: MuonLRTMergingAlg.h:46
CP::MuonLRTMergingAlg::m_createViewCollection
Gaudi::Property< bool > m_createViewCollection
Combined muon collection.
Definition: MuonLRTMergingAlg.h:51
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.