ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
MuonAnalysisAlgorithms
Root
MuonContainerMergingAlg.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
// MuonContainerMergingAlg
7
// author Maria Mironova, Simone Pagan Griso, Kehang Bai
9
11
// Generic algorithm for merging a list of muon containers
13
#include "
MuonAnalysisAlgorithms/MuonContainerMergingAlg.h
"
14
#include "
xAODMuon/MuonContainer.h
"
15
#include <
xAODMuon/MuonAuxContainer.h
>
16
#include <
AthContainers/ConstDataVector.h
>
17
#include <
AsgDataHandles/WriteHandle.h
>
18
#include <
xAODBase/IParticleHelpers.h
>
19
20
namespace
CP
{
21
MuonContainerMergingAlg::MuonContainerMergingAlg
(
const
std::string&
name
, ISvcLocator* svcLoc )
22
:
EL
::
AnaReentrantAlgorithm
(
name
, svcLoc ){
23
//nothing to do here
24
}
25
26
StatusCode
MuonContainerMergingAlg::initialize
() {
27
28
// initialize list of muon containters
29
ATH_MSG_DEBUG
(
"Initializing MuonContainerMergingAlg"
);
30
ATH_CHECK
(
m_inputMuonContainers
.initialize() );
31
32
// Default m_outMuonLocationCopy key to the OutputMuonLocation key
33
if
( !
m_createViewCollection
.value() &&
m_outMuonLocationCopy
.key().empty() ) {
m_outMuonLocationCopy
=
m_outMuonLocationView
.key(); }
34
35
// initialize output muon containters
36
ATH_CHECK
(
m_outMuonLocationCopy
.initialize(!
m_createViewCollection
.value()) );
37
ATH_CHECK
(
m_outMuonLocationView
.initialize(
m_createViewCollection
.value()) );
38
39
// Return gracefully:
40
return
StatusCode::SUCCESS;
41
}
42
43
StatusCode
MuonContainerMergingAlg::execute
(
const
EventContext &ctx)
const
{
44
45
// Setup containers for output, to avoid const conversions setup two different kind of containers
46
std::unique_ptr<ConstDataVector<xAOD::MuonContainer>> outputViewCol;
47
std::unique_ptr<xAOD::MuonContainer> outputCol;
48
std::unique_ptr<xAOD::MuonAuxContainer> outputAuxCol;
49
if
(
m_createViewCollection
) {
50
outputViewCol = std::make_unique<ConstDataVector<xAOD::MuonContainer>>(
SG::VIEW_ELEMENTS
);
51
}
else
{
52
outputCol = std::make_unique<xAOD::MuonContainer>();
53
outputAuxCol = std::make_unique<xAOD::MuonAuxContainer>();
54
outputCol->setStore(outputAuxCol.get());
55
}
56
57
// retrieve muons from StoreGate
58
std::vector<const xAOD::MuonContainer*> muonCollections;
59
muonCollections.reserve(
m_inputMuonContainers
.size());
60
size_t
muonCountSum = 0;
61
for
(
const
auto
& mcname :
m_inputMuonContainers
){
62
// Retrieve tracks from StoreGate
63
SG::ReadHandle<xAOD::MuonContainer>
muCol (mcname, ctx);
64
ATH_CHECK
(muCol.
isValid
());
65
muonCollections.push_back(muCol.
cptr
());
66
muonCountSum += muCol->size();
67
}
68
if
(
m_createViewCollection
) {
69
outputViewCol->reserve(muonCountSum);
70
}
else
{
71
outputCol->reserve(muonCountSum);
72
}
73
75
for
(
auto
& mciter : muonCollections) {
76
if
(mciter and !mciter->empty()) {
77
ATH_MSG_DEBUG
(
"Size of muon collection "
<< mciter->size());
79
for
(
const
auto
*
const
muon
: *mciter) {
81
if
(
m_createViewCollection
) {
82
outputViewCol->push_back(
muon
);
83
}
else
{
84
auto
newMuon = std::make_unique<xAOD::Muon>(*
muon
);
85
setOriginalObjectLink
(*
muon
, *newMuon);
86
outputCol->push_back(std::move(newMuon));
87
}
88
}
89
}
90
}
91
92
// write output to SG
93
if
(
m_createViewCollection
) {
94
SG::WriteHandle< ConstDataVector<xAOD::MuonContainer>
> h_write(
m_outMuonLocationView
, ctx);
95
ATH_CHECK
(h_write.
record
(std::move(outputViewCol)));
96
}
97
else
{
98
SG::WriteHandle<xAOD::MuonContainer>
h_write(
m_outMuonLocationCopy
, ctx);
99
ATH_CHECK
(h_write.
record
(std::move(outputCol), std::move(outputAuxCol)));
100
}
101
102
return
StatusCode::SUCCESS;
103
104
}
105
106
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x,...)
Definition
AthMsgStreamMacros.h:43
WriteHandle.h
Handle class for recording to StoreGate.
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
IParticleHelpers.h
MuonAuxContainer.h
MuonContainerMergingAlg.h
MuonContainer.h
CP::MuonContainerMergingAlg::m_outMuonLocationView
SG::WriteHandleKey< ConstDataVector< xAOD::MuonContainer > > m_outMuonLocationView
Output xAOD::MuonContainer for the case of a view container.
Definition
MuonContainerMergingAlg.h:53
CP::MuonContainerMergingAlg::m_inputMuonContainers
SG::ReadHandleKeyArray< xAOD::MuonContainer > m_inputMuonContainers
Private data:
Definition
MuonContainerMergingAlg.h:44
CP::MuonContainerMergingAlg::m_outMuonLocationCopy
SG::WriteHandleKey< xAOD::MuonContainer > m_outMuonLocationCopy
Output xAOD::MuonContainer object.
Definition
MuonContainerMergingAlg.h:49
CP::MuonContainerMergingAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition
MuonContainerMergingAlg.cxx:43
CP::MuonContainerMergingAlg::initialize
StatusCode initialize() override
Definition
MuonContainerMergingAlg.cxx:26
CP::MuonContainerMergingAlg::m_createViewCollection
Gaudi::Property< bool > m_createViewCollection
flag to create a view collection rather than building deep-copies (true by default)
Definition
MuonContainerMergingAlg.h:58
CP::MuonContainerMergingAlg::MuonContainerMergingAlg
MuonContainerMergingAlg(const std::string &name, ISvcLocator *pSvcLocator)
the standard constructor
Definition
MuonContainerMergingAlg.cxx:21
EL::AnaReentrantAlgorithm::AnaReentrantAlgorithm
AnaReentrantAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
constructor with parameters
Definition
AnaReentrantAlgorithm.cxx:29
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:66
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:71
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
CP
Select isolated Photons, Electrons and Muons.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:27
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition
AsgComponentFactories.h:16
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition
OwnershipPolicy.h:18
xAOD::name
name
Definition
TriggerMenuJson_v1.cxx:29
xAOD::setOriginalObjectLink
bool setOriginalObjectLink(const IParticle &original, IParticle ©)
This function should be used by CP tools when they make a deep copy of an object in their correctedCo...
Definition
IParticleHelpers.cxx:30
xAOD::muon
@ muon
Definition
TrackingPrimitives.h:191
Generated on
for ATLAS Offline Software by
1.17.0