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-2025 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
19
namespace
CP
{
20
MuonContainerMergingAlg::MuonContainerMergingAlg
(
const
std::string&
name
, ISvcLocator* svcLoc )
21
:
EL
::
AnaReentrantAlgorithm
(
name
, svcLoc ){
22
//nothing to do here
23
}
24
25
StatusCode
MuonContainerMergingAlg::initialize
() {
26
27
// initialize list of muon containters
28
ATH_MSG_DEBUG
(
"Initializing MuonContainerMergingAlg"
);
29
ATH_CHECK
(
m_inputMuonContainers
.initialize() );
30
31
// Override m_outMuonLocationCopy key
32
if
( !
m_createViewCollection
.value() ) {
m_outMuonLocationCopy
=
m_outMuonLocationView
.key(); }
33
34
// initialize output muon containters
35
ATH_CHECK
(
m_outMuonLocationCopy
.initialize(!
m_createViewCollection
.value()) );
36
ATH_CHECK
(
m_outMuonLocationView
.initialize(
m_createViewCollection
.value()) );
37
38
// Return gracefully:
39
return
StatusCode::SUCCESS;
40
}
41
42
StatusCode
MuonContainerMergingAlg::execute
(
const
EventContext &ctx)
const
{
43
44
// Setup containers for output, to avoid const conversions setup two different kind of containers
45
auto
outputViewCol = std::make_unique<ConstDataVector<xAOD::MuonContainer>>(
SG::VIEW_ELEMENTS
);
46
auto
outputCol = std::make_unique<xAOD::MuonContainer>();
47
48
std::unique_ptr<xAOD::MuonAuxContainer> outputAuxCol;
49
if
(!
m_createViewCollection
) {
50
outputAuxCol = std::make_unique<xAOD::MuonAuxContainer>();
51
outputCol->setStore(outputAuxCol.get());
52
}
53
54
// retrieve muons from StoreGate
55
std::vector<const xAOD::MuonContainer*> muonCollections;
56
muonCollections.reserve(
m_inputMuonContainers
.size());
57
size_t
muonCountSum = 0;
58
for
(
const
auto
& mcname :
m_inputMuonContainers
){
59
// Retrieve tracks from StoreGate
60
SG::ReadHandle<xAOD::MuonContainer>
muCol (mcname, ctx);
61
muonCollections.push_back(muCol.
cptr
());
62
muonCountSum += muCol->size();
63
}
64
if
(
m_createViewCollection
) {
65
outputViewCol->reserve(muonCountSum);
66
}
else
{
67
outputCol->reserve(muonCountSum);
68
}
69
71
for
(
auto
& mciter : muonCollections) {
72
if
(mciter and !mciter->empty()) {
73
ATH_MSG_DEBUG
(
"Size of muon collection "
<< mciter->size());
75
for
(
const
auto
*
const
muon
: *mciter) {
77
if
(
m_createViewCollection
) {
78
outputViewCol->push_back(
muon
);
79
}
else
{
80
xAOD::Muon
* newMuon =
new
xAOD::Muon
(*
muon
);
81
outputCol->push_back(newMuon);
82
}
83
}
84
}
85
}
86
87
// write output to SG
88
if
(
m_createViewCollection
) {
89
SG::WriteHandle< ConstDataVector<xAOD::MuonContainer>
> h_write(
m_outMuonLocationView
, ctx);
90
ATH_CHECK
(h_write.
record
(std::move(outputViewCol)));
91
}
92
else
{
93
SG::WriteHandle<xAOD::MuonContainer>
h_write(
m_outMuonLocationCopy
, ctx);
94
ATH_CHECK
(h_write.
record
(std::move(outputCol), std::move(outputAuxCol)));
95
}
96
97
return
StatusCode::SUCCESS;
98
99
}
100
101
}
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:29
WriteHandle.h
Handle class for recording to StoreGate.
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
MuonContainer.h
MuonAuxContainer.h
MuonContainerMergingAlg.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
virtual StatusCode execute(const EventContext &ctx) const override
Definition
MuonContainerMergingAlg.cxx:42
CP::MuonContainerMergingAlg::initialize
virtual StatusCode initialize() override
Definition
MuonContainerMergingAlg.cxx:25
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:20
EL::AnaReentrantAlgorithm::AnaReentrantAlgorithm
AnaReentrantAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
constructor with parameters
Definition
AnaReentrantAlgorithm.cxx:29
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
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.
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::Muon
Muon_v1 Muon
Reference the current persistent version:
Definition
Event/xAOD/xAODMuon/xAODMuon/Muon.h:13
xAOD::muon
@ muon
Definition
TrackingPrimitives.h:196
Generated on
for ATLAS Offline Software by
1.17.0