ATLAS Offline Software
Loading...
Searching...
No Matches
CaloTopoTowerMaker.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
6//-----------------------------------------------------------------------
7// File and Version Information:
8//
9// Description: see CaloTopoTowerMaker.h
10//
11// Environment:
12// Software developed for the ATLAS Detector at CERN LHC
13//
14// Author List:
15// Sven Menke
16//
17// Modified: Feb 09, 2005 (DLelas)
18// - CaloTopoTowerMaker applies correction type tool on a whole
19// cluster collection now. Needed for Sliding Window
20// cell weights calculation.
21//
22// Modified Feb 2014 (W Lampl)
23// - Migrate to xAOD::CaloCluster(Container)
24// - Move to AthAlgorithm, some simplifications
25//
26// Modified Sep 2020 (T Chowdhury)
27// -
28//-----------------------------------------------------------------------
29
30//-----------------------
31// This Class's Header --
32//-----------------------
33#include "CaloTopoTowerMaker.h"
34
35//---------------
36// C++ Headers --
37//---------------
41
45
46#include "GaudiKernel/IChronoStatSvc.h"
47
49
50#include <memory> // for the std::unique_ptr
51#include <cmath>
52
53//###############################################################################
55 ISvcLocator* pSvcLocator)
56 : AthReentrantAlgorithm(name, pSvcLocator)
57 , m_chrono("ChronoStatSvc", name)
58{
59}
60
61//###############################################################################
62
64= default;
65
66//###############################################################################
67
69{
70
71 // -- retrieve the needed tower maker tool
72 if (m_towerMakerTool.retrieve().isFailure()) {
73 ATH_MSG_ERROR("Failed to retrieve essential tower maker tool"
75 } else {
76 ATH_MSG_DEBUG("Successfully retrieved tower maker tool "
78 }
79
80 // -- retrieve the (optional) list of correction tools
81 if (m_towerCorrectionTools.retrieve().isFailure()) {
82 ATH_MSG_ERROR("Failed to retrieve requested tower correction tools "
84 } else {
85 ATH_MSG_DEBUG("Successfully retrieved tower correction tools "
87 }
88
89 // -- retrieve tower calibrator tool
90 if ( m_useLCWCalibration ) {
91 if ( m_towerCalibratorTool.retrieve().isFailure() ) {
92 ATH_MSG_ERROR("Failed to retrieve requested tower calibrator tool " << m_towerCalibratorTool);
93 } else {
94 ATH_MSG_DEBUG("Sucessfully retrieved requested tower calibrator tool " << m_towerCalibratorTool);
95 }
96 }
97
98 if (m_chronoTools) {
99 msg(MSG::INFO) << "Will use ChronoStatSvc to monitor ClusterMaker and ClusterCorrection tools" << endmsg;
100 ATH_CHECK( m_chrono.retrieve() );
101 }
102
103 ATH_CHECK( m_towerOutput.initialize() );
104
105 if (m_towerCellLinkOutput.key().empty()) {
106 m_towerCellLinkOutput = m_towerOutput.key() + "_links";
107 }
108 ATH_CHECK( m_towerCellLinkOutput.initialize() );
109
110
111 ATH_CHECK(detStore()->retrieve(m_caloCellID,"CaloCell_ID"));
112
113 return StatusCode::SUCCESS;
114}
115
116//###############################################################################
117
119 return StatusCode::SUCCESS;
120}
121
122//###############################################################################
123
124StatusCode CaloTopoTowerMaker::execute (const EventContext& ctx) const
125{
126
127 // make a Cluster Container
130
131 std::string chronoName(this->name()+std::string("_"));
132 if ( !m_useLCWCalibration ) {
133 // fill the towers without preparing for calibratoin
134 if ( m_chronoTools ) { m_chrono->chronoStart(chronoName+m_towerMakerTool->name()); }
135 ATH_CHECK( m_towerMakerTool->execute(ctx,clusColl.ptr(),nullptr) );
136 if ( m_chronoTools ) { m_chrono->chronoStop(chronoName+m_towerMakerTool->name()); }
137 // save original signals bevore corrections and calibrations
138 if ( m_saveSignalState ) {
139 for (xAOD::CaloCluster* fClus : *clusColl) {
140 fClus->setRawE (fClus->e() );
141 fClus->setRawEta(fClus->eta());
142 fClus->setRawPhi(fClus->phi());
143 fClus->setRawM (fClus->m() );
144 }//end loop over clusters
145 }
146 // apply the correction tools (really moment calculators)
147 for ( auto iter(m_towerCorrectionTools.begin()); iter != m_towerCorrectionTools.end(); ++iter ) {
148 if ( m_chronoTools ) { m_chrono->chronoStart(chronoName+iter->name()); }
149 ATH_CHECK( (*iter)->execute(ctx,clusColl.ptr()) );
150 if ( m_chronoTools ) { m_chrono->chronoStop(chronoName+iter->name()); }
151 } // correction tool loop
152 } else {
153 // fill the towers with LCW calibration
154 std::unique_ptr<CaloCellClusterWeights> cellWeights=std::make_unique<CaloCellClusterWeights>(m_caloCellID->calo_cell_hash_max());
155 if ( m_chronoTools ) { m_chrono->chronoStart(chronoName+m_towerMakerTool->name()); }
156 ATH_CHECK( m_towerMakerTool->execute(ctx,clusColl.ptr(),cellWeights.get()) );
157 if ( m_chronoTools ) { m_chrono->chronoStop(chronoName+m_towerMakerTool->name()); }
158 // save original signals bevore corrections and calibrations
159 if ( m_saveSignalState ) {
160 for (xAOD::CaloCluster* fClus : *clusColl) {
161 fClus->setRawE (fClus->e() );
162 fClus->setRawEta(fClus->eta());
163 fClus->setRawPhi(fClus->phi());
164 fClus->setRawM (fClus->m() );
165 }//end loop over clusters
166 }
167 // apply the correction tools (really moment calculators)
168 for ( auto iter(m_towerCorrectionTools.begin()); iter != m_towerCorrectionTools.end(); ++iter ) {
169 if ( m_chronoTools ) { m_chrono->chronoStart(chronoName+iter->name()); }
170 ATH_CHECK( (*iter)->execute(ctx,clusColl.ptr()) );
171 if ( m_chronoTools ) { m_chrono->chronoStop(chronoName+iter->name()); }
172 } // correction tool loop
173 // apply calibration
174 if ( m_chronoTools ) { m_chrono->chronoStart(chronoName+m_towerCalibratorTool->name()); }
175 ATH_CHECK( m_towerCalibratorTool->execute(ctx,clusColl.ptr(),cellWeights.get()) );
176 if ( m_chronoTools ) { m_chrono->chronoStop(chronoName+m_towerCalibratorTool->name()); }
177 } // end of processing blocks
178
179 ATH_MSG_DEBUG("Created tower container (of type xAOD::CaloClusterContainer) with " << clusColl->size() << " towers");
181 ATH_CHECK( cellLinks.record (std::make_unique<CaloClusterCellLinkContainer>()) );
182 CaloClusterStoreHelper::finalizeClusters (ctx, clusColl, cellLinks);
183 return StatusCode::SUCCESS;
184}
185
186
188 return m_towerOutput.key();
189}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
Helpers for checking error return status codes and reporting errors.
const ServiceHandle< StoreGateSvc > & detStore() const
An algorithm that can be simultaneously executed in multiple threads.
static void finalizeClusters(const EventContext &ctx, SG::WriteHandle< xAOD::CaloClusterContainer > &outClusterContainer, SG::WriteHandle< CaloClusterCellLinkContainer > &outClusterContainerCellLink)
Finalize clusters (move CaloClusterCellLink to a separate container).
static StatusCode AddContainerWriteHandle(SG::WriteHandle< xAOD::CaloClusterContainer > &clusColl)
Creates a new xAOD::CaloClusterContainer in the given WriteHandle + CaloClusterAuxContainer and recor...
ToolHandle< CaloTowerCollectionProcessor > m_towerCalibratorTool
Tower calibrator(s).
virtual ~CaloTopoTowerMaker() override
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_towerOutput
the name of the key in StoreGate for the output CaloClusterContainer
ToolHandle< CaloTowerCollectionProcessor > m_towerMakerTool
Tower makers.
const CaloCell_ID * m_caloCellID
Identifier helper.
Gaudi::Property< bool > m_useLCWCalibration
Use LCW calibration for topo-towers (default is true).
virtual StatusCode initialize() override
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_towerCellLinkOutput
the name of the key in StoreGate for the output CaloClusterCellLinkContainer
const std::string & getOutputContainerName() const
CaloTopoTowerMaker(const std::string &name, ISvcLocator *pSvcLocator)
ToolHandleArray< CaloClusterCollectionProcessor > m_towerCorrectionTools
Tower (cluster) moment makers.
virtual StatusCode finalize() override
Gaudi::Property< bool > m_saveSignalState
Keep the individual results of each correction.
Gaudi::Property< bool > m_chronoTools
Use ChronotStatSvc to monitor each tool.
virtual StatusCode execute(const EventContext &ctx) const override
ServiceHandle< IChronoStatSvc > m_chrono
Handle to the ChronoStatSvc.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.