ATLAS Offline Software
Loading...
Searching...
No Matches
LArTTL1Overlay.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "LArTTL1Overlay.h"
6
7// Atlas includes
10
11namespace LVL1
12{
13
14LArTTL1Overlay::LArTTL1Overlay(const std::string& name, ISvcLocator* pSvcLocator)
15 : AthReentrantAlgorithm(name, pSvcLocator) { }
16
18{
19 ATH_MSG_DEBUG("Initialising");
20
21 // StoreGate keys for LAr
22 ATH_CHECK( m_bkgEmTTL1Key.initialize() );
23 ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgEmTTL1Key);
24 ATH_CHECK( m_bkgHadTTL1Key.initialize() );
25 ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgHadTTL1Key);
26 ATH_CHECK( m_signalEmTTL1Key.initialize() );
27 ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalEmTTL1Key);
28 ATH_CHECK( m_signalHadTTL1Key.initialize() );
29 ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalHadTTL1Key);
30 ATH_CHECK( m_outputEmTTL1Key.initialize() );
31 ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_outputEmTTL1Key);
32 ATH_CHECK( m_outputHadTTL1Key.initialize() );
33 ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_outputHadTTL1Key);
34
35 return StatusCode::SUCCESS;
36}
37
39StatusCode LArTTL1Overlay::execute(const EventContext& ctx) const
40{
43
44 return StatusCode::SUCCESS;
45}
46
49 std::map<Identifier, std::vector<const LArTTL1*>> &towerMap) const
50{
51 for (const LArTTL1* tower : *towers) {
52 auto [it, inserted] = towerMap.try_emplace(tower->ttOfflineID());
53 it->second.push_back(tower);
54 }
55
56}
57
59StatusCode LArTTL1Overlay::overlay(const EventContext& ctx,
63 const std::string &label) const
64{
65 // setup maps
66 std::map<Identifier, std::vector<const LArTTL1*>> towerMap;
67
68 // Find LAr towers in TES
69 SG::ReadHandle<LArTTL1Container> bkgTowers(bkgKey, ctx);
70 if (!bkgTowers.isValid()) {
71 ATH_MSG_ERROR("Could not get background " << label << " LArTTL1Container container " << bkgTowers.name() << " from store " << bkgTowers.store());
72 return StatusCode::FAILURE;
73 }
74
77 SG::ReadHandle<LArTTL1Container> signalTowers(signalKey, ctx);
78 if (!signalTowers.isValid()) {
79 ATH_MSG_ERROR("Could not get signal " << label << " LArTTL1Container container " << signalTowers.name() << " from store " << signalTowers.store());
80 return StatusCode::FAILURE;
81 }
82
83 // Group towers by ID
84 groupTowers(bkgTowers.cptr(), towerMap);
85 groupTowers(signalTowers.cptr(), towerMap);
86
87 // Set up output containers
88 SG::WriteHandle<LArTTL1Container> outputContainer(outputKey, ctx);
89 // Register the TTL1 container in the TES
90 ATH_CHECK( outputContainer.record(std::make_unique<LArTTL1Container>()) );
91 ATH_MSG_DEBUG( "Output " << label << " LArTTL1Container registered successfully (" << outputKey.key() << ")" );
92
93 // Make the output collection
94 for (const auto &[dummy, towers] : towerMap) {
95 const LArTTL1 *firstTower = towers.front();
96 HWIdentifier hwId = firstTower->ttOnlineID();
97 Identifier Id = firstTower->ttOfflineID();
98
99 std::vector<float> mergedAmps;
100 for (const LArTTL1 *tower : towers) {
101 if (mergedAmps.empty()) {
102 mergedAmps = tower->samples();
103 } else {
104 std::vector<float> amps = tower->samples();
105 if (amps.size() != mergedAmps.size()) {
106 ATH_MSG_WARNING("LAr " << label << " vectors have different lengths: " << amps.size() << ", " << mergedAmps.size());
107 } else {
108 for (size_t i = 0; i < amps.size(); ++i) {
109 mergedAmps[i] += amps[i];
110 }
111 }
112 }
113 }
114
115 // Create new tower and add to output vector
116 std::unique_ptr<LArTTL1> ttL1 = std::make_unique<LArTTL1>(hwId, Id, mergedAmps);
117 outputContainer->push_back(ttL1.release());
118 }
119
120 return StatusCode::SUCCESS;
121}
122
123} // namespace LVL1
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
An algorithm that can be simultaneously executed in multiple threads.
Container class for LArTTL1.
Liquid Argon TT L1 sum class.
Definition LArTTL1.h:29
const HWIdentifier & ttOnlineID() const
return LArTTChannelID (online Id)
Definition LArTTL1.cxx:14
const Identifier & ttOfflineID() const
return TT offline Identifier
Definition LArTTL1.cxx:18
virtual StatusCode initialize() override final
void groupTowers(const LArTTL1Container *towers, std::map< Identifier, std::vector< const LArTTL1 * > > &towerMap) const
Steps over LAr tower collection and overlays on existing collection.
StatusCode overlay(const EventContext &ctx, const SG::ReadHandleKey< LArTTL1Container > &bkgKey, const SG::ReadHandleKey< LArTTL1Container > &signalKey, const SG::WriteHandleKey< LArTTL1Container > &outputKey, const std::string &label) const
Main algorithm execute.
SG::WriteHandleKey< LArTTL1Container > m_outputHadTTL1Key
SG::WriteHandleKey< LArTTL1Container > m_outputEmTTL1Key
SG::ReadHandleKey< LArTTL1Container > m_bkgHadTTL1Key
SG::ReadHandleKey< LArTTL1Container > m_bkgEmTTL1Key
virtual StatusCode execute(const EventContext &ctx) const override final
Main algorithm execute.
SG::ReadHandleKey< LArTTL1Container > m_signalEmTTL1Key
LArTTL1Overlay(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< LArTTL1Container > m_signalHadTTL1Key
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
std::string store() const
Return the name of the store holding the object we are proxying.
const std::string & name() const
Return the StoreGate ID for the referenced object.
const std::string & key() const
Return the StoreGate ID for the referenced object.
Property holding a SG store/key/clid from which a WriteHandle is made.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
std::string label(const std::string &format, int i)
Definition label.h:19
bool overlay
Definition listroot.cxx:42
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...