Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
17 #include <AsgTools/AsgToolConfig.h>
20 
21 namespace 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 
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::AuxElement::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::AuxElement::Accessor <char> isLRT("isLRT");
147  isLRT(*newMuon) = isLRT(*muon);
148  outputCol->push_back(newMuon);
149  }
150  }
151  return StatusCode::SUCCESS;
152  }
153 }
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:196
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
CP::MuonLRTMergingAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: MuonLRTMergingAlg.cxx:53
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
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
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
CP::MuonLRTMergingAlg::m_lrtMuonLocation
SG::ReadHandleKey< xAOD::MuonContainer > m_lrtMuonLocation
Vector of muon collections to be merged.
Definition: MuonLRTMergingAlg.h:47
python.base_data.config
config
Definition: base_data.py:21
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:49
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:27
CP::MuonLRTMergingAlg::m_promptIsLRTKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_promptIsLRTKey
Definition: MuonLRTMergingAlg.h:75
MuonAuxContainer.h
AthCommonDataStore< AthCommonMsg< Gaudi::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:59
CP::MuonLRTMergingAlg::MuonLRTMergingAlg
MuonLRTMergingAlg(const std::string &name, ISvcLocator *pSvcLocator)
the standard constructor
Definition: MuonLRTMergingAlg.cxx:22
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
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
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
WriteDecorHandle.h
Handle class for adding a decoration to an object.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
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:228
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:73
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:65
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
xAOD::setOriginalObjectLink
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...
Definition: IParticleHelpers.cxx:30
CP::MuonLRTMergingAlg::mergeMuon
StatusCode mergeMuon(const xAOD::MuonContainer &muonCol, const std::vector< bool > &muonIsGood, ConstDataVector< xAOD::MuonContainer > *outputCol) const
Private methods:
Definition: MuonLRTMergingAlg.cxx:117
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
IParticleHelpers.h
CP::MuonLRTMergingAlg::m_lrtIsLRTKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_lrtIsLRTKey
Definition: MuonLRTMergingAlg.h:77
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.