ATLAS Offline Software
MuonSimDataOverlay.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 "MuonSimDataOverlay.h"
8 
9 #include "StoreGate/ReadHandle.h"
10 #include "StoreGate/WriteHandle.h"
11 
12 
13 
14 MuonSimDataOverlay::MuonSimDataOverlay(const std::string &name, ISvcLocator *pSvcLocator)
15  : AthReentrantAlgorithm(name, pSvcLocator) {}
16 
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
33  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgInputKey.key());
35  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalInputKey.key());
37  ATH_MSG_VERBOSE("Initialized WriteHandleKey: " << m_outputKey.key());
38 
39  return StatusCode::SUCCESS;
40 }
41 
42 
43 StatusCode MuonSimDataOverlay::execute(const EventContext& ctx) const
44 {
45  ATH_MSG_DEBUG("execute() begin");
46 
47  ATH_MSG_VERBOSE("Retrieving input containers");
48 
49  const MuonSimDataCollection *bkgContainerPtr = nullptr;
50  if (!m_bkgInputKey.key().empty()) {
52  if (!bkgContainer.isValid()) {
53  ATH_MSG_ERROR("Could not get background MuonSimDataCollection container " << bkgContainer.name() << " from store " << bkgContainer.store());
54  return StatusCode::FAILURE;
55  }
56  bkgContainerPtr = bkgContainer.cptr();
57 
58  ATH_MSG_DEBUG("Found background MuonSimDataCollection container " << bkgContainer.name() << " in store " << bkgContainer.store());
59  }
60 
62  if (!signalContainer.isValid()) {
63  ATH_MSG_ERROR("Could not get signal MuonSimDataCollection container " << signalContainer.name() << " from store " << signalContainer.store());
64  return StatusCode::FAILURE;
65  }
66  ATH_MSG_DEBUG("Found signal MuonSimDataCollection container " << signalContainer.name() << " in store " << signalContainer.store());
67 
68  // Creating output RDO container
70  ATH_CHECK(outputContainer.record(std::make_unique<MuonSimDataCollection>()));
71  if (!outputContainer.isValid()) {
72  ATH_MSG_ERROR("Could not record output MuonSimDataCollection container " << outputContainer.name() << " to store " << outputContainer.store());
73  return StatusCode::FAILURE;
74  }
75  ATH_MSG_DEBUG("Recorded output MuonSimDataCollection 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  if (it->second.getTime() < entry.second.getTime()) {
90  // We take the earlier in time
91  continue;
92  }
93 
94  ATH_MSG_VERBOSE("Replacing signal SDO, time = " << it->second.getTime() << ", "
95  << "with background SDO, time = " << entry.second.getTime());
96 
97  MuonSimData tempSDO(entry.second.getdeposits(), 0);
98  tempSDO.setPosition(entry.second.globalPosition());
99  tempSDO.setTime(entry.second.getTime());
100 
101  it->second = std::move(tempSDO);
102  } else {
103  outputContainer->insert(entry);
104  }
105  }
106  }
107 
108  ATH_MSG_VERBOSE("Output SDO size " << outputContainer->size());
109 
110  ATH_MSG_DEBUG("execute() end");
111  return StatusCode::SUCCESS;
112 }
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
MuonSimData::setPosition
void setPosition(const Amg::Vector3D &pos)
Definition: MuonSimData.h:106
skel.it
it
Definition: skel.GENtoEVGEN.py:423
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
MuonSimData::setTime
void setTime(const float &time)
Definition: MuonSimData.h:119
MuonSimDataOverlay::m_outputKey
SG::WriteHandleKey< MuonSimDataCollection > m_outputKey
Definition: MuonSimDataOverlay.h:25
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
WriteHandle.h
Handle class for recording to StoreGate.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MuonSimDataOverlay::MuonSimDataOverlay
MuonSimDataOverlay(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MuonSimDataOverlay.cxx:14
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MuonSimDataCollection
Definition: MuonSimDataCollection.h:21
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition: StoreGate/src/VarHandleBase.cxx:379
MuonSimDataOverlay::m_bkgInputKey
SG::ReadHandleKey< MuonSimDataCollection > m_bkgInputKey
Definition: MuonSimDataOverlay.h:23
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MuonSimDataOverlay::m_signalInputKey
SG::ReadHandleKey< MuonSimDataCollection > m_signalInputKey
Definition: MuonSimDataOverlay.h:24
MuonSimDataOverlay.h
MuonSimData
Definition: MuonSimData.h:62
MuonSimDataOverlay::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: MuonSimDataOverlay.cxx:43
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.
MuonSimDataOverlay::initialize
virtual StatusCode initialize() override
Definition: MuonSimDataOverlay.cxx:17
ReadHandle.h
Handle class for reading from StoreGate.