ATLAS Offline Software
MdtOverlay.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Andrei Gaponenko <agaponenko@lbl.gov>, 2006, 2007
6 // Ketevi A. Assamagan <ketevi@bnl.gov>, March 2008
7 // Piyali Banerjee <Piyali.Banerjee@cern.ch>, March 2011
8 
10 
11 #include <StoreGate/ReadHandle.h>
12 #include <StoreGate/WriteHandle.h>
13 
15 
16 
17 //================================================================
18 namespace Overlay
19 {
25  template<>
26  void mergeChannelData(MdtDigit& signalDigit,
27  const MdtDigit& bkgDigit,
29  {
30  // We want to use the integration window provided by MdtOverlay, thus the constraint
31  const MdtOverlay *parent = dynamic_cast<const MdtOverlay *>(algorithm);
32  if (!parent) {
33  throw std::runtime_error("mergeChannelData<MdtDigit>() called by a wrong parent algorithm? Must be MdtOverlay.");
34  }
35 
36  int sig_tdc = signalDigit.tdc();
37  int bkg_tdc = bkgDigit.tdc();
38 
41  if (std::abs(sig_tdc - bkg_tdc) > parent->adcIntegrationWindow() && sig_tdc < bkg_tdc ) {
42  // do nothing - keep baseDigit.
43  }
46  else if (std::abs(sig_tdc - bkg_tdc) > parent->adcIntegrationWindow() && sig_tdc > bkg_tdc ) {
47  // Use the background digit as the final answer
48  signalDigit = bkgDigit;
49  }
54  else if (std::abs(sig_tdc - bkg_tdc) < parent->adcIntegrationWindow() ) {
55  int tdc = std::min( signalDigit.tdc(), bkgDigit.tdc() );
56  int adc = signalDigit.adc() + bkgDigit.adc();
57  signalDigit = MdtDigit(signalDigit.identify(), tdc, adc, false);
58  }
59  }
60 } // namespace Overlay
61 
62 
63 //================================================================
64 MdtOverlay::MdtOverlay(const std::string &name, ISvcLocator *pSvcLocator)
65  : IDC_MuonOverlayBase(name, pSvcLocator)
66 {
67 }
68 
69 //================================================================
71 {
72  ATH_MSG_DEBUG("Initializing...");
73 
74  // Check and initialize keys
76  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgInputKey );
78  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalInputKey );
80  ATH_MSG_VERBOSE("Initialized WriteHandleKey: " << m_outputKey );
81 
82  return StatusCode::SUCCESS;
83 }
84 
85 //================================================================
86 StatusCode MdtOverlay::execute(const EventContext& ctx) const {
87  ATH_MSG_DEBUG("execute() begin");
88 
89 
90  const MdtDigitContainer *bkgContainerPtr = nullptr;
91  if (!m_bkgInputKey.empty()) {
93  if (!bkgContainer.isValid()) {
94  ATH_MSG_ERROR("Could not get background MDT container " << bkgContainer.name() << " from store " << bkgContainer.store());
95  return StatusCode::FAILURE;
96  }
97  bkgContainerPtr = bkgContainer.cptr();
98 
99  ATH_MSG_DEBUG("Found background MdtDigitContainer called " << bkgContainer.name() << " in store " << bkgContainer.store());
100  ATH_MSG_DEBUG("MDT Background = " << Overlay::debugPrint(bkgContainer.cptr()));
101  ATH_MSG_VERBOSE("MDT background has digit_size " << bkgContainer->digit_size());
102  }
103 
105  if(!signalContainer.isValid() ) {
106  ATH_MSG_ERROR("Could not get signal MDT container " << signalContainer.name() << " from store " << signalContainer.store());
107  return StatusCode::FAILURE;
108  }
109  ATH_MSG_DEBUG("Found signal MdtDigitContainer called " << signalContainer.name() << " in store " << signalContainer.store());
110  ATH_MSG_DEBUG("MDT Signal = " << Overlay::debugPrint(signalContainer.cptr()));
111  ATH_MSG_VERBOSE("MDT signal has digit_size " << signalContainer->digit_size());
112 
113  SG::WriteHandle<MdtDigitContainer> outputContainer(m_outputKey, ctx);
114  ATH_CHECK(outputContainer.record(std::make_unique<MdtDigitContainer>(signalContainer->size())));
115  if (!outputContainer.isValid()) {
116  ATH_MSG_ERROR("Could not record output MdtDigitContainer called " << outputContainer.name() << " to store " << outputContainer.store());
117  return StatusCode::FAILURE;
118  }
119  ATH_MSG_DEBUG("Recorded output MdtDigitContainer called " << outputContainer.name() << " in store " << outputContainer.store());
120 
121  // Do the actual overlay
122  ATH_CHECK(overlayContainer(bkgContainerPtr, signalContainer.cptr(), outputContainer.ptr()));
123  ATH_MSG_DEBUG("MDT Result = " << Overlay::debugPrint(outputContainer.cptr()));
124 
125 
126  ATH_MSG_DEBUG("execute() end");
127 
128  return StatusCode::SUCCESS;
129 }
IDC_OverlayHelpers.h
MdtOverlay::m_bkgInputKey
SG::ReadHandleKey< MdtDigitContainer > m_bkgInputKey
Definition: MdtOverlay.h:32
algorithm
std::string algorithm
Definition: hcg.cxx:82
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MdtDigit
Definition: MdtDigit.h:19
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
MdtOverlay.h
IdentifiableContainerMT::size
size_t size() const
Duplicate of fullSize for backwards compatability.
Definition: IdentifiableContainerMT.h:206
SG::WriteHandle::cptr
const_pointer_type cptr() const
Dereference the pointer.
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
MdtOverlay::MdtOverlay
MdtOverlay(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MdtOverlay.cxx:64
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
MdtDigit::adc
int16_t adc() const
Definition: MdtDigit.h:28
IDC_MuonOverlayBase::overlayContainer
StatusCode overlayContainer(const IDC_Container *bkgContainer, const IDC_Container *signalContainer, IDC_Container *outputContainer) const
Definition: IDC_MuonOverlayBase.h:34
Overlay::mergeChannelData
void mergeChannelData(HGTD_RDO &, const HGTD_RDO &, const IDC_OverlayBase *algorithm)
Definition: HGTD_Overlay.cxx:14
WriteHandle.h
Handle class for recording to StoreGate.
MdtDigitContainer::digit_size
size_type digit_size() const
Definition: MdtDigitContainer.cxx:53
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition: StoreGate/src/VarHandleBase.cxx:376
test_pyathena.parent
parent
Definition: test_pyathena.py:15
IDC_MuonOverlayBase
Definition: IDC_MuonOverlayBase.h:27
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?
MdtDigitContainer
Use IdentifiableContainer with MdtDigitCollection.
Definition: MdtDigitContainer.h:50
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MdtOverlay
Definition: MdtOverlay.h:22
MuonDigit::identify
Identifier identify() const
Definition: MuonDigit.h:30
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
MdtOverlay::m_signalInputKey
SG::ReadHandleKey< MdtDigitContainer > m_signalInputKey
Definition: MdtOverlay.h:33
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ReadFloatFromCool.adc
adc
Definition: ReadFloatFromCool.py:48
MdtOverlay::initialize
virtual StatusCode initialize() override final
Definition: MdtOverlay.cxx:70
MdtOverlay::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: MdtOverlay.cxx:86
Overlay
Helpers for overlaying Identifiable Containers.
Definition: HGTD_Overlay.cxx:11
ReadHandle.h
Handle class for reading from StoreGate.
MdtDigit::tdc
int16_t tdc() const
Definition: MdtDigit.h:26
MdtOverlay::m_outputKey
SG::WriteHandleKey< MdtDigitContainer > m_outputKey
Definition: MdtOverlay.h:34
Overlay::debugPrint
std::string debugPrint(const IDC_Container *container, unsigned numprint=25)
Diagnostic output of Identifiable Containers.