ATLAS Offline Software
TileTTL1Overlay.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TileTTL1Overlay.h"
6 
7 // Atlas includes
8 #include "StoreGate/ReadHandle.h"
10 
11 namespace LVL1
12 {
13 
14 TileTTL1Overlay::TileTTL1Overlay(const std::string& name, ISvcLocator* pSvcLocator)
15  : AthReentrantAlgorithm(name, pSvcLocator) { }
16 
18 {
19  ATH_MSG_DEBUG("Initialising");
20 
21  // StoreGate keys for Tile
22  ATH_CHECK( m_bkgTileTTL1Key.initialize() );
23  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgTileTTL1Key);
25  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgTileMBTSTTL1Key);
26  ATH_CHECK( m_signalTileTTL1Key.initialize() );
27  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalTileTTL1Key);
29  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalTileMBTSTTL1Key);
30  ATH_CHECK( m_outputTileTTL1Key.initialize() );
31  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_outputTileTTL1Key);
33  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_outputTileMBTSTTL1Key);
34 
35  return StatusCode::SUCCESS;
36 }
37 
39 StatusCode TileTTL1Overlay::execute(const EventContext& ctx) const
40 {
42  if (!m_outputTileMBTSTTL1Key.empty()) {
44  }
45 
46  return StatusCode::SUCCESS;
47 }
48 
51  std::map<Identifier, std::vector<const TileTTL1*>> &towerMap) const
52 {
53  // Step over all towers
54  for (const TileTTL1 *tower : *towers) {
55 
56  // Obtain identifier
57  Identifier id = tower->TTL1_ID();
58 
59  // Is this one already in the map
60  std::map<Identifier, std::vector<const TileTTL1*>>::iterator test = towerMap.find( id );
61  // If already exists, add tower to location
62  if (test != towerMap.end()) {
63  // Add this pointer to the vector
64  test->second.push_back(tower);
65  }
66  // Otherwise create new entry in the map
67  else {
68  std::vector<const TileTTL1*> towers;
69  towers.push_back(tower);
70  towerMap.emplace(id, towers);
71  }
72 
73  } // end for loop
74 
75  return;
76 }
77 
79 StatusCode TileTTL1Overlay::overlay(const EventContext& ctx,
81  const SG::ReadHandleKey<TileTTL1Container> &signalKey,
83  const std::string &label) const
84 {
85  // setup map
86  std::map<Identifier, std::vector<const TileTTL1*>> towerMap;
87 
88  // Find Tile towers in TES
89  SG::ReadHandle<TileTTL1Container> bkgTowers(bkgKey, ctx);
90  if (!bkgTowers.isValid()) {
91  ATH_MSG_ERROR("Could not get background " << label << " TileTTL1Container container " << bkgTowers.name() << " from store " << bkgTowers.store());
92  return StatusCode::FAILURE;
93  }
94 
97  SG::ReadHandle<TileTTL1Container> signalTowers(signalKey, ctx);
98  if (!signalTowers.isValid()) {
99  ATH_MSG_ERROR("Could not get signal " << label << " TileTTL1Container container " << signalTowers.name() << " from store " << signalTowers.store());
100  return StatusCode::FAILURE;
101  }
102 
103  // Group towers by ID
104  groupTowers(bkgTowers.cptr(), towerMap);
105  groupTowers(signalTowers.cptr(), towerMap);
106 
107  SG::WriteHandle<TileTTL1Container> outputContainer(outputKey, ctx);
108  // Register the TTL1 container in the TES
109  ATH_CHECK( outputContainer.record(std::make_unique<TileTTL1Container>()) );
110  ATH_MSG_DEBUG( "Output " << label << " TileTTL1Container registered successfully (" << outputKey.key() << ")" );
111 
112  // Then the process Tile TTL1 collection
113  for (const auto &[dummy, towers] : towerMap) {
114  Identifier Id = towers.front()->TTL1_ID();
115 
116  std::vector<float> mergedAmps;
117  for (const TileTTL1 *tower : towers) {
118  if (mergedAmps.empty()) {
119  mergedAmps = tower->fsamples();
120  } else {
121  std::vector<float> amps = tower->fsamples();
122  if (amps.size() != mergedAmps.size()) {
123  ATH_MSG_WARNING("Tile " << label << " vectors have different lengths: " << amps.size() << ", " << mergedAmps.size());
124  } else {
125  for (size_t i = 0; i < amps.size(); ++i) {
126  mergedAmps[i] += amps[i];
127  }
128  }
129  }
130  }
131 
132  // Create new tower and add to output vector
133  std::unique_ptr<TileTTL1> ttL1 = std::make_unique<TileTTL1>(Id, mergedAmps);
134  outputContainer->push_back(ttL1.release());
135  }
136 
137  return StatusCode::SUCCESS;
138 }
139 
140 } // namespace LVL1
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
LVL1::TileTTL1Overlay::TileTTL1Overlay
TileTTL1Overlay(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TileTTL1Overlay.cxx:14
LVL1::TileTTL1Overlay::groupTowers
void groupTowers(const TileTTL1Container *towers, std::map< Identifier, std::vector< const TileTTL1 * >> &towerMap) const
Real Tile overlay towers and overlay on existing event.
Definition: TileTTL1Overlay.cxx:50
LVL1::TileTTL1Overlay::m_signalTileMBTSTTL1Key
SG::ReadHandleKey< TileTTL1Container > m_signalTileMBTSTTL1Key
Definition: TileTTL1Overlay.h:60
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
LVL1::TileTTL1Overlay::m_outputTileTTL1Key
SG::WriteHandleKey< TileTTL1Container > m_outputTileTTL1Key
Definition: TileTTL1Overlay.h:62
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
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
LVL1::TileTTL1Overlay::m_outputTileMBTSTTL1Key
SG::WriteHandleKey< TileTTL1Container > m_outputTileMBTSTTL1Key
Definition: TileTTL1Overlay.h:63
TileTTL1
Definition: TileTTL1.h:26
TrigInDetValidation_Base.test
test
Definition: TrigInDetValidation_Base.py:146
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
LVL1::TileTTL1Overlay::m_signalTileTTL1Key
SG::ReadHandleKey< TileTTL1Container > m_signalTileTTL1Key
Definition: TileTTL1Overlay.h:59
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
LVL1::TileTTL1Overlay::overlay
StatusCode overlay(const EventContext &ctx, const SG::ReadHandleKey< TileTTL1Container > &bkgKey, const SG::ReadHandleKey< TileTTL1Container > &signalKey, const SG::WriteHandleKey< TileTTL1Container > &outputKey, const std::string &label) const
Main algorithm execute.
Definition: TileTTL1Overlay.cxx:79
WriteHandle.h
Handle class for recording to StoreGate.
TileDigitizationConfig.outputKey
outputKey
Definition: TileDigitizationConfig.py:104
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::WriteHandleKey
Property holding a SG store/key/clid from which a WriteHandle is made.
Definition: StoreGate/StoreGate/WriteHandleKey.h:40
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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
LVL1::TileTTL1Overlay::m_bkgTileMBTSTTL1Key
SG::ReadHandleKey< TileTTL1Container > m_bkgTileMBTSTTL1Key
Definition: TileTTL1Overlay.h:57
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
LVL1::TileTTL1Overlay::m_bkgTileTTL1Key
SG::ReadHandleKey< TileTTL1Container > m_bkgTileTTL1Key
Definition: TileTTL1Overlay.h:56
python.xAODType.dummy
dummy
Definition: xAODType.py:4
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrigConf::name
Definition: HLTChainList.h:35
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
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.
RunTileMonitoring.towers
towers
Definition: RunTileMonitoring.py:133
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TileTTL1Overlay.h
LVL1::TileTTL1Overlay::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Main algorithm execute.
Definition: TileTTL1Overlay.cxx:39
ReadHandle.h
Handle class for reading from StoreGate.
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
TileContainer
Definition: TileContainer.h:38
LVL1::TileTTL1Overlay::initialize
virtual StatusCode initialize() override final
Definition: TileTTL1Overlay.cxx:17