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//---------------
42
46
47#include "GaudiKernel/IChronoStatSvc.h"
48
50
51#include <memory> // for the std::unique_ptr
52#include <cmath>
53
54//###############################################################################
56 ISvcLocator* pSvcLocator)
57 : AthReentrantAlgorithm(name, pSvcLocator)
58 , m_towerOutput("")
60 , m_towerMakerTool(this)
63 , m_chrono("ChronoStatSvc", name)
64{
65 // Name of Cluster Container to be registered in TDS
66 declareProperty("TowersOutputName",m_towerOutput);
67 declareProperty("TowerCellLinkOutputName",m_towerCellLinkOutput);
68
69 // Name(s) of Cluster Maker Tools
70 declareProperty("TowerMakerTool",m_towerMakerTool);
71
72 // Name(s) of Cluster Correction Tools
73 declareProperty("TowerCorrectionTools",m_towerCorrectionTools);
74
75 // Tower calibrator tool
76 declareProperty("TowerCalibratorTool",m_towerCalibratorTool);
77
78 // save uncalibrated cluster signal state
79 declareProperty("SaveUncalibratedSignalState",m_saveSignalState);
80
81 //Make Chrono Auditors for Cluster maker and correction tools
82 declareProperty("ChronoTools", m_chronoTools);
83
84 // apply LCW calibration for towers
85 declareProperty("UseLCWCalibration",m_useLCWCalibration);
86}
87
88//###############################################################################
89
91= default;
92
93//###############################################################################
94
96{
97
98 // -- retrieve the needed tower maker tool
99 if (m_towerMakerTool.retrieve().isFailure()) {
100 ATH_MSG_ERROR("Failed to retrieve essential tower maker tool"
102 } else {
103 ATH_MSG_DEBUG("Successfully retrieved tower maker tool "
105 }
106
107 // -- retrieve the (optional) list of correction tools
108 if (m_towerCorrectionTools.retrieve().isFailure()) {
109 ATH_MSG_ERROR("Failed to retrieve requested tower correction tools "
111 } else {
112 ATH_MSG_DEBUG("Successfully retrieved tower correction tools "
114 }
115
116 // -- retrieve tower calibrator tool
117 if ( m_useLCWCalibration ) {
118 if ( m_towerCalibratorTool.retrieve().isFailure() ) {
119 ATH_MSG_ERROR("Failed to retrieve requested tower calibrator tool " << m_towerCalibratorTool);
120 } else {
121 ATH_MSG_DEBUG("Sucessfully retrieved requested tower calibrator tool " << m_towerCalibratorTool);
122 }
123 }
124
125 if (m_chronoTools) {
126 msg(MSG::INFO) << "Will use ChronoStatSvc to monitor ClusterMaker and ClusterCorrection tools" << endmsg;
127 ATH_CHECK( m_chrono.retrieve() );
128 }
129
130 ATH_CHECK( m_towerOutput.initialize() );
131
132 if (m_towerCellLinkOutput.key().empty()) {
133 m_towerCellLinkOutput = m_towerOutput.key() + "_links";
134 }
135 ATH_CHECK( m_towerCellLinkOutput.initialize() );
136
137
138 ATH_CHECK(detStore()->retrieve(m_caloCellID,"CaloCell_ID"));
139
140 return StatusCode::SUCCESS;
141}
142
143//###############################################################################
144
146 return StatusCode::SUCCESS;
147}
148
149//###############################################################################
150
151StatusCode CaloTopoTowerMaker::execute (const EventContext& ctx) const
152{
153
154 // make a Cluster Container
157
158 std::string chronoName(this->name()+std::string("_"));
159 if ( !m_useLCWCalibration ) {
160 // fill the towers without preparing for calibratoin
161 if ( m_chronoTools ) { m_chrono->chronoStart(chronoName+m_towerMakerTool->name()); }
162 ATH_CHECK( m_towerMakerTool->execute(ctx,clusColl.ptr(),nullptr) );
163 if ( m_chronoTools ) { m_chrono->chronoStop(chronoName+m_towerMakerTool->name()); }
164 // save original signals bevore corrections and calibrations
165 if ( m_saveSignalState ) {
166 for (xAOD::CaloCluster* fClus : *clusColl) {
167 fClus->setRawE (fClus->e() );
168 fClus->setRawEta(fClus->eta());
169 fClus->setRawPhi(fClus->phi());
170 fClus->setRawM (fClus->m() );
171 }//end loop over clusters
172 }
173 // apply the correction tools (really moment calculators)
174 for ( auto iter(m_towerCorrectionTools.begin()); iter != m_towerCorrectionTools.end(); ++iter ) {
175 if ( m_chronoTools ) { m_chrono->chronoStart(chronoName+iter->name()); }
176 ATH_CHECK( (*iter)->execute(ctx,clusColl.ptr()) );
177 if ( m_chronoTools ) { m_chrono->chronoStop(chronoName+iter->name()); }
178 } // correction tool loop
179 } else {
180 // fill the towers with LCW calibration
181 std::unique_ptr<CaloCellClusterWeights> cellWeights=std::make_unique<CaloCellClusterWeights>(m_caloCellID->calo_cell_hash_max());
182 if ( m_chronoTools ) { m_chrono->chronoStart(chronoName+m_towerMakerTool->name()); }
183 ATH_CHECK( m_towerMakerTool->execute(ctx,clusColl.ptr(),cellWeights.get()) );
184 if ( m_chronoTools ) { m_chrono->chronoStop(chronoName+m_towerMakerTool->name()); }
185 // save original signals bevore corrections and calibrations
186 if ( m_saveSignalState ) {
187 for (xAOD::CaloCluster* fClus : *clusColl) {
188 fClus->setRawE (fClus->e() );
189 fClus->setRawEta(fClus->eta());
190 fClus->setRawPhi(fClus->phi());
191 fClus->setRawM (fClus->m() );
192 }//end loop over clusters
193 }
194 // apply the correction tools (really moment calculators)
195 for ( auto iter(m_towerCorrectionTools.begin()); iter != m_towerCorrectionTools.end(); ++iter ) {
196 if ( m_chronoTools ) { m_chrono->chronoStart(chronoName+iter->name()); }
197 ATH_CHECK( (*iter)->execute(ctx,clusColl.ptr()) );
198 if ( m_chronoTools ) { m_chrono->chronoStop(chronoName+iter->name()); }
199 } // correction tool loop
200 // apply calibration
201 if ( m_chronoTools ) { m_chrono->chronoStart(chronoName+m_towerCalibratorTool->name()); }
202 ATH_CHECK( m_towerCalibratorTool->execute(ctx,clusColl.ptr(),cellWeights.get()) );
203 if ( m_chronoTools ) { m_chrono->chronoStop(chronoName+m_towerCalibratorTool->name()); }
204 } // end of processing blocks
205
206 ATH_MSG_DEBUG("Created tower container (of type xAOD::CaloClusterContainer) with " << clusColl->size() << " towers");
208 ATH_CHECK( cellLinks.record (std::make_unique<CaloClusterCellLinkContainer>()) );
209 CaloClusterStoreHelper::finalizeClusters (ctx, clusColl, cellLinks);
210 return StatusCode::SUCCESS;
211}
212
213
215 return m_towerOutput.key();
216}
#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.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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.
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
bool m_chronoTools
Use ChronotStatSvc to monitor each tool.
virtual StatusCode execute(const EventContext &ctx) const override
bool m_saveSignalState
Keep the individual results of each correction.
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.