ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonOverlay
MuonTruthOverlay
src
CscSimDataOverlay.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
7
#include "
CscSimDataOverlay.h
"
8
9
#include "
StoreGate/ReadHandle.h
"
10
#include "
StoreGate/WriteHandle.h
"
11
12
13
14
CscSimDataOverlay::CscSimDataOverlay
(
const
std::string &name, ISvcLocator *pSvcLocator)
15
:
AthReentrantAlgorithm
(name, pSvcLocator) {}
16
17
StatusCode
CscSimDataOverlay::initialize
()
18
{
19
ATH_MSG_DEBUG
(
"Initializing..."
);
20
21
if
(
m_signalInputKey
.key().empty()) {
22
ATH_MSG_ERROR
(
"Missing signal input SDO key."
);
23
return
StatusCode::FAILURE;
24
}
25
26
if
(
m_outputKey
.key().empty()) {
27
ATH_MSG_ERROR
(
"Missing output SDO key."
);
28
return
StatusCode::FAILURE;
29
}
30
31
// Check and initialize keys
32
ATH_CHECK
(
m_bkgInputKey
.initialize(!
m_bkgInputKey
.key().empty()) );
33
ATH_MSG_VERBOSE
(
"Initialized ReadHandleKey: "
<<
m_bkgInputKey
.key());
34
ATH_CHECK
(
m_signalInputKey
.initialize() );
35
ATH_MSG_VERBOSE
(
"Initialized ReadHandleKey: "
<<
m_signalInputKey
.key());
36
ATH_CHECK
(
m_outputKey
.initialize() );
37
ATH_MSG_VERBOSE
(
"Initialized WriteHandleKey: "
<<
m_outputKey
.key());
38
39
return
StatusCode::SUCCESS;
40
}
41
42
43
StatusCode
CscSimDataOverlay::execute
(
const
EventContext& ctx)
const
44
{
45
ATH_MSG_DEBUG
(
"execute() begin"
);
46
47
ATH_MSG_VERBOSE
(
"Retrieving input containers"
);
48
49
const
CscSimDataCollection
*bkgContainerPtr =
nullptr
;
50
if
(!
m_bkgInputKey
.key().empty()) {
51
SG::ReadHandle<CscSimDataCollection>
bkgContainer(
m_bkgInputKey
, ctx);
52
if
(!bkgContainer.
isValid
()) {
53
ATH_MSG_ERROR
(
"Could not get background CscSimDataCollection container "
<< bkgContainer.
name
() <<
" from store "
<< bkgContainer.
store
());
54
return
StatusCode::FAILURE;
55
}
56
bkgContainerPtr = bkgContainer.
cptr
();
57
58
ATH_MSG_DEBUG
(
"Found background CscSimDataCollection container "
<< bkgContainer.
name
() <<
" in store "
<< bkgContainer.
store
());
59
}
60
61
SG::ReadHandle<CscSimDataCollection>
signalContainer(
m_signalInputKey
, ctx);
62
if
(!signalContainer.
isValid
()) {
63
ATH_MSG_ERROR
(
"Could not get signal CscSimDataCollection container "
<< signalContainer.
name
() <<
" from store "
<< signalContainer.
store
());
64
return
StatusCode::FAILURE;
65
}
66
ATH_MSG_DEBUG
(
"Found signal CscSimDataCollection container "
<< signalContainer.
name
() <<
" in store "
<< signalContainer.
store
());
67
68
// Creating output RDO container
69
SG::WriteHandle<CscSimDataCollection>
outputContainer(
m_outputKey
, ctx);
70
ATH_CHECK
(outputContainer.
record
(std::make_unique<CscSimDataCollection>()));
71
if
(!outputContainer.
isValid
()) {
72
ATH_MSG_ERROR
(
"Could not record output CscSimDataCollection container "
<< outputContainer.
name
() <<
" to store "
<< outputContainer.
store
());
73
return
StatusCode::FAILURE;
74
}
75
ATH_MSG_DEBUG
(
"Recorded output CscSimDataCollection container "
<< outputContainer.
name
() <<
" in store "
<< outputContainer.
store
());
76
77
78
// Copy over signal SDO
79
ATH_MSG_VERBOSE
(
"Inserting signal SDO, size = "
<< signalContainer->size());
80
outputContainer->insert(signalContainer->begin(), signalContainer->end());
81
82
// Merge with background
83
if
(!
m_bkgInputKey
.key().empty()) {
84
ATH_MSG_VERBOSE
(
"Inserting background SDO, size = "
<< bkgContainerPtr->size());
85
86
for
(
const
auto
&entry : *bkgContainerPtr) {
87
auto
it = outputContainer->find(entry.first);
88
if
(it != outputContainer->end()) {
89
// merging needed
90
const
CscSimData
&outSimData = it->second;
91
const
std::vector<CscSimData::Deposit> &depositsBkg = entry.second.getdeposits();
92
std::vector<CscSimData::Deposit> depositsVector(outSimData.
getdeposits
());
93
depositsVector.insert(depositsVector.end(), depositsBkg.begin(), depositsBkg.end());
94
// fix charge
95
if
(!depositsVector.empty() && !depositsBkg.empty()) {
96
depositsVector[0].second.setCharge(depositsVector[0].second.charge() + depositsBkg[0].second.charge());
97
depositsVector[outSimData.
getdeposits
().size()].second.setCharge(0);
// clear the first bkg deposit charge
98
}
99
// set the new deposits vector
100
it->second =
CscSimData
(depositsVector);
101
}
else
{
102
outputContainer->insert(entry);
103
}
104
}
105
}
106
107
ATH_MSG_VERBOSE
(
"Output SDO size "
<< outputContainer->size());
108
109
ATH_MSG_DEBUG
(
"execute() end"
);
110
return
StatusCode::SUCCESS;
111
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
CscSimDataOverlay.h
ReadHandle.h
Handle class for reading from StoreGate.
WriteHandle.h
Handle class for recording to StoreGate.
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
CscSimDataCollection
Definition
CscSimDataCollection.h:29
CscSimDataOverlay::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
CscSimDataOverlay.cxx:43
CscSimDataOverlay::m_outputKey
SG::WriteHandleKey< CscSimDataCollection > m_outputKey
Definition
CscSimDataOverlay.h:25
CscSimDataOverlay::CscSimDataOverlay
CscSimDataOverlay(const std::string &name, ISvcLocator *pSvcLocator)
Definition
CscSimDataOverlay.cxx:14
CscSimDataOverlay::initialize
virtual StatusCode initialize() override
Definition
CscSimDataOverlay.cxx:17
CscSimDataOverlay::m_signalInputKey
SG::ReadHandleKey< CscSimDataCollection > m_signalInputKey
Definition
CscSimDataOverlay.h:24
CscSimDataOverlay::m_bkgInputKey
SG::ReadHandleKey< CscSimDataCollection > m_bkgInputKey
Definition
CscSimDataOverlay.h:23
CscSimData
Definition
CscSimData.h:44
CscSimData::getdeposits
const std::vector< Deposit > & getdeposits() const
Definition
CscSimData.h:67
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
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::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition
StoreGate/src/VarHandleBase.cxx:382
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition
AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
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.
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Generated on
for ATLAS Offline Software by
1.17.0