ATLAS Offline Software
LArTTL1Overlay.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 "LArTTL1Overlay.h"
6 
7 // Atlas includes
8 #include "StoreGate/ReadHandle.h"
10 
11 namespace LVL1
12 {
13 
14 LArTTL1Overlay::LArTTL1Overlay(const std::string& name, ISvcLocator* pSvcLocator)
15  : AthReentrantAlgorithm(name, pSvcLocator) { }
16 
18 {
19  ATH_MSG_DEBUG("Initialising");
20 
21  // StoreGate keys for LAr
23  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgEmTTL1Key);
25  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgHadTTL1Key);
27  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalEmTTL1Key);
29  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalHadTTL1Key);
31  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_outputEmTTL1Key);
33  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_outputHadTTL1Key);
34 
35  return StatusCode::SUCCESS;
36 }
37 
39 StatusCode 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 
53  // Obtain identifier
54  Identifier id = tower->ttOfflineID();
55 
56  // Does this tower already exist?
57  std::map<Identifier, std::vector<const LArTTL1*>>::iterator test = towerMap.find( id );
58  // If already exists, add tower to location
59  if (test != towerMap.end()) {
60  // Add this pointer to the vector
61  test->second.push_back(tower);
62  }
63  // Otherwise create new entry in the map
64  else {
65  std::vector<const LArTTL1*> towers;
66  towers.push_back(tower);
67  towerMap.emplace(id, towers);
68  }
69 
70  } // end for loop
71 }
72 
74 StatusCode LArTTL1Overlay::overlay(const EventContext& ctx,
76  const SG::ReadHandleKey<LArTTL1Container> &signalKey,
78  const std::string &label) const
79 {
80  // setup maps
81  std::map<Identifier, std::vector<const LArTTL1*>> towerMap;
82 
83  // Find LAr towers in TES
84  SG::ReadHandle<LArTTL1Container> bkgTowers(bkgKey, ctx);
85  if (!bkgTowers.isValid()) {
86  ATH_MSG_ERROR("Could not get background " << label << " LArTTL1Container container " << bkgTowers.name() << " from store " << bkgTowers.store());
87  return StatusCode::FAILURE;
88  }
89 
92  SG::ReadHandle<LArTTL1Container> signalTowers(signalKey, ctx);
93  if (!signalTowers.isValid()) {
94  ATH_MSG_ERROR("Could not get signal " << label << " LArTTL1Container container " << signalTowers.name() << " from store " << signalTowers.store());
95  return StatusCode::FAILURE;
96  }
97 
98  // Group towers by ID
99  groupTowers(bkgTowers.cptr(), towerMap);
100  groupTowers(signalTowers.cptr(), towerMap);
101 
102  // Set up output containers
103  SG::WriteHandle<LArTTL1Container> outputContainer(outputKey, ctx);
104  // Register the TTL1 container in the TES
105  ATH_CHECK( outputContainer.record(std::make_unique<LArTTL1Container>()) );
106  ATH_MSG_DEBUG( "Output " << label << " LArTTL1Container registered successfully (" << outputKey.key() << ")" );
107 
108  // Make the output collection
109  for (const auto &[dummy, towers] : towerMap) {
110  const LArTTL1 *firstTower = towers.front();
111  HWIdentifier hwId = firstTower->ttOnlineID();
112  Identifier Id = firstTower->ttOfflineID();
113 
114  std::vector<float> mergedAmps;
115  for (const LArTTL1 *tower : towers) {
116  if (mergedAmps.empty()) {
117  mergedAmps = tower->samples();
118  } else {
119  std::vector<float> amps = tower->samples();
120  if (amps.size() != mergedAmps.size()) {
121  ATH_MSG_WARNING("LAr " << label << " vectors have different lengths: " << amps.size() << ", " << mergedAmps.size());
122  } else {
123  for (size_t i = 0; i < amps.size(); ++i) {
124  mergedAmps[i] += amps[i];
125  }
126  }
127  }
128  }
129 
130  // Create new tower and add to output vector
131  std::unique_ptr<LArTTL1> ttL1 = std::make_unique<LArTTL1>(hwId, Id, mergedAmps);
132  outputContainer->push_back(ttL1.release());
133  }
134 
135  return StatusCode::SUCCESS;
136 }
137 
138 } // namespace LVL1
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
LArTTL1Overlay.h
LVL1::LArTTL1Overlay::m_signalHadTTL1Key
SG::ReadHandleKey< LArTTL1Container > m_signalHadTTL1Key
Definition: LArTTL1Overlay.h:60
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
LVL1::LArTTL1Overlay::overlay
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.
Definition: LArTTL1Overlay.cxx:74
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::LArTTL1Overlay::LArTTL1Overlay
LArTTL1Overlay(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArTTL1Overlay.cxx:14
LVL1::LArTTL1Overlay::initialize
virtual StatusCode initialize() override final
Definition: LArTTL1Overlay.cxx:17
TrigInDetValidation_Base.test
test
Definition: TrigInDetValidation_Base.py:146
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey< LArTTL1Container >
HWIdentifier
Definition: HWIdentifier.h:13
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
LVL1::LArTTL1Overlay::m_outputEmTTL1Key
SG::WriteHandleKey< LArTTL1Container > m_outputEmTTL1Key
Definition: LArTTL1Overlay.h:62
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
LVL1::LArTTL1Overlay::m_bkgHadTTL1Key
SG::ReadHandleKey< LArTTL1Container > m_bkgHadTTL1Key
Definition: LArTTL1Overlay.h:57
WriteHandle.h
Handle class for recording to StoreGate.
TileDigitizationConfig.outputKey
outputKey
Definition: TileDigitizationConfig.py:104
LVL1::LArTTL1Overlay::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Main algorithm execute.
Definition: LArTTL1Overlay.cxx:39
LVL1::LArTTL1Overlay::m_signalEmTTL1Key
SG::ReadHandleKey< LArTTL1Container > m_signalEmTTL1Key
Definition: LArTTL1Overlay.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::WriteHandleKey< LArTTL1Container >
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
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::LArTTL1Overlay::groupTowers
void groupTowers(const LArTTL1Container *towers, std::map< Identifier, std::vector< const LArTTL1 * >> &towerMap) const
Steps over LAr tower collection and overlays on existing collection.
Definition: LArTTL1Overlay.cxx:48
python.xAODType.dummy
dummy
Definition: xAODType.py:4
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
LArTTL1Container
Container class for LArTTL1.
Definition: LArTTL1Container.h:24
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrigConf::name
Definition: HLTChainList.h:35
LArTTL1::ttOnlineID
const HWIdentifier & ttOnlineID() const
return LArTTChannelID (online Id)
Definition: LArTTL1.cxx:14
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
LVL1::LArTTL1Overlay::m_outputHadTTL1Key
SG::WriteHandleKey< LArTTL1Container > m_outputHadTTL1Key
Definition: LArTTL1Overlay.h:63
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
LVL1::LArTTL1Overlay::m_bkgEmTTL1Key
SG::ReadHandleKey< LArTTL1Container > m_bkgEmTTL1Key
Definition: LArTTL1Overlay.h:56
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
LArTTL1::ttOfflineID
const Identifier & ttOfflineID() const
return TT offline Identifier
Definition: LArTTL1.cxx:18
ReadHandle.h
Handle class for reading from StoreGate.
LArTTL1
Liquid Argon TT L1 sum class.
Definition: LArTTL1.h:29