ATLAS Offline Software
STGC_Overlay.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 // Alexandre Laurier <alexandre.laurier@cern.ch>, May 2019
9 
11 
12 #include <StoreGate/ReadHandle.h>
13 #include <StoreGate/WriteHandle.h>
14 
16 
17 
18 //================================================================
19 namespace Overlay
20 {
26  template<>
27  void mergeChannelData(sTgcDigit& signalDigit,
28  const sTgcDigit& bkgDigit,
30  {
31  // We want to use the integration window provided by sTgcOverlay, thus the constraint
32  const STGC_Overlay *parent = dynamic_cast<const STGC_Overlay *>(algorithm);
33  if (!parent) {
34  throw std::runtime_error("mergeChannelData<sTgcDigit>() called by a wrong parent algorithm? Must be STGC_Overlay.");
35  }
36 
37  float sig_time = signalDigit.time();
38  float bkg_time = bkgDigit.time();
39 
41  if ( abs(sig_time - bkg_time) > parent->timeIntegrationWindow() && sig_time < bkg_time ) {
42  // do nothing - keep baseDigit.
43  }
45  else if ( abs(sig_time - bkg_time) > parent->timeIntegrationWindow() && sig_time > bkg_time ) {
46  // Use the background digit as the final answer
47  signalDigit = bkgDigit;
48  }
51  else if ( abs(sig_time - bkg_time) < parent->timeIntegrationWindow() ) {
52  // Use the earliest time
53  float time = std::min( signalDigit.time(), bkgDigit.time() );
54  float charge = signalDigit.charge() + bkgDigit.charge();
55  //signalDigit = sTgcDigit(signalDigit.identify(), time, charge);
56  signalDigit = sTgcDigit(signalDigit.identify(), signalDigit.bcTag(), time, charge, signalDigit.isDead(), signalDigit.isPileup());
57  }
58  }
59 } // namespace Overlay
60 
61 
62 //================================================================
63 STGC_Overlay::STGC_Overlay(const std::string &name, ISvcLocator *pSvcLocator)
64  : IDC_MuonOverlayBase(name, pSvcLocator)
65 {
66 }
67 
68 //================================================================
70 {
71  ATH_MSG_DEBUG("Initializing...");
72 
73  // Check and initialize keys
75  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgInputKey );
77  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalInputKey );
79  ATH_MSG_VERBOSE("Initialized WriteHandleKey: " << m_outputKey );
80 
81  return StatusCode::SUCCESS;
82 }
83 
84 //================================================================
85 StatusCode STGC_Overlay::execute(const EventContext& ctx) const {
86  ATH_MSG_DEBUG("execute() begin");
87 
88 
89  const sTgcDigitContainer *bkgContainerPtr = nullptr;
90  if (!m_bkgInputKey.empty()) {
92  if (!bkgContainer.isValid()) {
93  ATH_MSG_ERROR("Could not get background sTGC container " << bkgContainer.name() << " from store " << bkgContainer.store());
94  return StatusCode::FAILURE;
95  }
96  bkgContainerPtr = bkgContainer.cptr();
97 
98  ATH_MSG_DEBUG("Found background sTGCDigitContainer called " << bkgContainer.name() << " in store " << bkgContainer.store());
99  ATH_MSG_DEBUG("sTGC Background = " << Overlay::debugPrint(bkgContainer.cptr()));
100  ATH_MSG_VERBOSE("sTGC background has digit_size " << bkgContainer->digit_size());
101  }
102 
104  if(!signalContainer.isValid() ) {
105  ATH_MSG_ERROR("Could not get signal sTgc container " << signalContainer.name() << " from store " << signalContainer.store());
106  return StatusCode::FAILURE;
107  }
108  ATH_MSG_DEBUG("Found signal sTgcDigitContainer called " << signalContainer.name() << " in store " << signalContainer.store());
109  ATH_MSG_DEBUG("sTGC Signal = " << Overlay::debugPrint(signalContainer.cptr()));
110  ATH_MSG_VERBOSE("sTGC signal has digit_size " << signalContainer->digit_size());
111 
112  SG::WriteHandle<sTgcDigitContainer> outputContainer(m_outputKey, ctx);
113  ATH_CHECK(outputContainer.record(std::make_unique<sTgcDigitContainer>(signalContainer->size())));
114  if (!outputContainer.isValid()) {
115  ATH_MSG_ERROR("Could not record output sTgcDigitContainer called " << outputContainer.name() << " to store " << outputContainer.store());
116  return StatusCode::FAILURE;
117  }
118  ATH_MSG_DEBUG("Recorded output sTgcDigitContainer called " << outputContainer.name() << " in store " << outputContainer.store());
119 
120  // Do the actual overlay
121  ATH_CHECK(overlayContainer(bkgContainerPtr, signalContainer.cptr(), outputContainer.ptr()));
122  ATH_MSG_DEBUG("sTGC Result = " << Overlay::debugPrint(outputContainer.cptr()));
123 
124  ATH_MSG_DEBUG("execute() end");
125 
126  return StatusCode::SUCCESS;
127 }
sTgcDigitContainer
Use IdentifiableContainer with sTgcDigitCollection.
Definition: sTgcDigitContainer.h:50
IDC_OverlayHelpers.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
sTgcDigit::isDead
bool isDead() const
Definition: sTgcDigit.cxx:38
sTgcDigit::bcTag
uint16_t bcTag() const
Definition: sTgcDigit.cxx:34
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
IDC_MuonOverlayBase::overlayContainer
StatusCode overlayContainer(const IDC_Container *bkgContainer, const IDC_Container *signalContainer, IDC_Container *outputContainer) const
Definition: IDC_MuonOverlayBase.h:34
sTgcDigit
Definition: sTgcDigit.h:20
Overlay::mergeChannelData
void mergeChannelData(HGTD_RDO &, const HGTD_RDO &, const IDC_OverlayBase *algorithm)
Definition: HGTD_Overlay.cxx:14
STGC_Overlay.h
WriteHandle.h
Handle class for recording to StoreGate.
STGC_Overlay::m_outputKey
SG::WriteHandleKey< sTgcDigitContainer > m_outputKey
Definition: STGC_Overlay.h:35
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
sTgcDigit::charge
float charge() const
Definition: sTgcDigit.cxx:46
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
sTgcDigit::time
float time() const
Definition: sTgcDigit.cxx:61
STGC_Overlay::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: STGC_Overlay.cxx:85
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
sTgcDigitContainer::digit_size
size_type digit_size() const
Definition: sTgcDigitContainer.cxx:55
STGC_Overlay::m_bkgInputKey
SG::ReadHandleKey< sTgcDigitContainer > m_bkgInputKey
Definition: STGC_Overlay.h:33
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
STGC_Overlay
Definition: STGC_Overlay.h:23
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
Overlay
Helpers for overlaying Identifiable Containers.
Definition: HGTD_Overlay.cxx:11
STGC_Overlay::m_signalInputKey
SG::ReadHandleKey< sTgcDigitContainer > m_signalInputKey
Definition: STGC_Overlay.h:34
STGC_Overlay::STGC_Overlay
STGC_Overlay(const std::string &name, ISvcLocator *pSvcLocator)
Definition: STGC_Overlay.cxx:63
STGC_Overlay::initialize
virtual StatusCode initialize() override final
Definition: STGC_Overlay.cxx:69
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.
sTgcDigit::isPileup
bool isPileup() const
Definition: sTgcDigit.cxx:42