ATLAS Offline Software
MM_Overlay.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 // Alexandre Laurier <alexandre.laurier@cern.ch>, May 2019
9 
10 #include <MM_Overlay/MM_Overlay.h>
11 
12 #include <StoreGate/ReadHandle.h>
13 #include <StoreGate/WriteHandle.h>
14 
16 
17 
18 //================================================================
19 namespace Overlay
20 {
26  template<>
27  void mergeChannelData(MmDigit& signalDigit,
28  const MmDigit& bkgDigit,
30  {
31  // We want to use the integration window provided by MmOverlay, thus the constraint
32  const MM_Overlay *parent = dynamic_cast<const MM_Overlay *>(algorithm);
33  if (!parent) {
34  throw std::runtime_error("mergeChannelData<MmDigit>() called by a wrong parent algorithm? Must be MM_Overlay.");
35  }
36  float sig_time = signalDigit.stripResponseTime();
37  float bkg_time = bkgDigit.stripResponseTime();
38 
39 
40  // As of now, we need to decide how to overlay MM digits
41  // NEEDS TO BE ADDRESSED
42  // For this preliminary version of July 2019, use only the data from the 1st digit in vector.
44  if ( std::abs(sig_time - bkg_time) > parent->timeIntegrationWindow() && sig_time < bkg_time ) {
45  // do nothing - keep baseDigit.
46  }
48  else if ( std::abs(sig_time - bkg_time) > parent->timeIntegrationWindow() && sig_time > bkg_time ) {
49  // Use the background digit as the final answer
50  signalDigit = bkgDigit;
51  }
54  else if ( std::abs(sig_time - bkg_time) < parent->timeIntegrationWindow() ) {
55  // Use the earliest time
56  // And use all the other values of the signal digit.
57  float time = std::min( sig_time, bkg_time );
58  float charge = signalDigit.stripResponseCharge() + bkgDigit.stripResponseCharge();
59  signalDigit = MmDigit(signalDigit.identify(), time, charge);
60  }
61  }
62 } // namespace Overlay
63 
64 
65 //================================================================
66 MM_Overlay::MM_Overlay(const std::string &name, ISvcLocator *pSvcLocator)
67  : IDC_MuonOverlayBase(name, pSvcLocator)
68 {
69 }
70 
71 //================================================================
73 {
74  ATH_MSG_DEBUG("Initializing...");
75 
76  // Check and initialize keys
78  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgInputKey );
80  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalInputKey );
82  ATH_MSG_VERBOSE("Initialized WriteHandleKey: " << m_outputKey );
83 
84  return StatusCode::SUCCESS;
85 }
86 
87 //================================================================
88 StatusCode MM_Overlay::execute(const EventContext& ctx) const {
89  ATH_MSG_DEBUG("execute() begin");
90 
91 
92  const MmDigitContainer *bkgContainerPtr = nullptr;
93  if (!m_bkgInputKey.empty()) {
95  if (!bkgContainer.isValid()) {
96  ATH_MSG_ERROR("Could not get background MM container " << bkgContainer.name() << " from store " << bkgContainer.store());
97  return StatusCode::FAILURE;
98  }
99  bkgContainerPtr = bkgContainer.cptr();
100 
101  ATH_MSG_DEBUG("Found background MMDigitContainer called " << bkgContainer.name() << " in store " << bkgContainer.store());
102  ATH_MSG_DEBUG("MM Background = " << Overlay::debugPrint(bkgContainer.cptr()));
103  ATH_MSG_VERBOSE("MM background has digit_size " << bkgContainer->digit_size());
104  }
105 
107  if(!signalContainer.isValid() ) {
108  ATH_MSG_ERROR("Could not get signal MM container " << signalContainer.name() << " from store " << signalContainer.store());
109  return StatusCode::FAILURE;
110  }
111  ATH_MSG_DEBUG("Found signal MmDigitContainer called " << signalContainer.name() << " in store " << signalContainer.store());
112  ATH_MSG_DEBUG("MM Signal = " << Overlay::debugPrint(signalContainer.cptr()));
113  ATH_MSG_VERBOSE("MM signal has digit_size " << signalContainer->digit_size());
114 
115  SG::WriteHandle<MmDigitContainer> outputContainer(m_outputKey, ctx);
116  ATH_CHECK(outputContainer.record(std::make_unique<MmDigitContainer>(signalContainer->size())));
117  if (!outputContainer.isValid()) {
118  ATH_MSG_ERROR("Could not record output MmDigitContainer called " << outputContainer.name() << " to store " << outputContainer.store());
119  return StatusCode::FAILURE;
120  }
121  ATH_MSG_DEBUG("Recorded output MmDigitContainer called " << outputContainer.name() << " in store " << outputContainer.store());
122 
123  // Do the actual overlay
124  ATH_CHECK(overlayContainer(bkgContainerPtr, signalContainer.cptr(), outputContainer.ptr()));
125  ATH_MSG_DEBUG("MM Result = " << Overlay::debugPrint(outputContainer.cptr()));
126 
127  ATH_MSG_DEBUG("execute() end");
128 
129  return StatusCode::SUCCESS;
130 }
MmDigitContainer
Use IdentifiableContainer with MmDigitCollection.
Definition: MmDigitContainer.h:50
IDC_OverlayHelpers.h
MM_Overlay.h
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
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
IdentifiableContainerMT::size
size_t size() const
Duplicate of fullSize for backwards compatability.
Definition: IdentifiableContainerMT.h:209
MmDigit
Definition: MmDigit.h:20
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
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
MM_Overlay::initialize
virtual StatusCode initialize() override final
Definition: MM_Overlay.cxx:72
MM_Overlay::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: MM_Overlay.cxx:88
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.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MM_Overlay
Definition: MM_Overlay.h:23
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:379
test_pyathena.parent
parent
Definition: test_pyathena.py:15
MM_Overlay::m_signalInputKey
SG::ReadHandleKey< MmDigitContainer > m_signalInputKey
Definition: MM_Overlay.h:34
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?
min
#define min(a, b)
Definition: cfImp.cxx:40
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
charge
double charge(const T &p)
Definition: AtlasPID.h:494
MM_Overlay::MM_Overlay
MM_Overlay(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MM_Overlay.cxx:66
MuonDigit::identify
Identifier identify() const
Definition: MuonDigit.h:30
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.
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
MM_Overlay::m_bkgInputKey
SG::ReadHandleKey< MmDigitContainer > m_bkgInputKey
Definition: MM_Overlay.h:33
MM_Overlay::m_outputKey
SG::WriteHandleKey< MmDigitContainer > m_outputKey
Definition: MM_Overlay.h:35
Overlay
Helpers for overlaying Identifiable Containers.
Definition: HGTD_Overlay.cxx:11
MmDigit::stripResponseTime
float stripResponseTime() const
strip response info
Definition: MmDigit.h:43
MmDigitContainer::digit_size
size_type digit_size() const
Definition: MmDigitContainer.cxx:54
MmDigit::stripResponseCharge
float stripResponseCharge() const
Return the charge.
Definition: MmDigit.h:45
ReadHandle.h
Handle class for reading from StoreGate.
Overlay::debugPrint
std::string debugPrint(const IDC_Container *container, unsigned numprint=25)
Diagnostic output of Identifiable Containers.