ATLAS Offline Software
Loading...
Searching...
No Matches
CaloClusterMaker.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 CaloClusterMaker.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// - CaloClusterMaker 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
27//-----------------------
28// This Class's Header --
29//-----------------------
30#include "CaloClusterMaker.h"
31
32//---------------
33// C++ Headers --
34//---------------
38
42
43#include "GaudiKernel/IChronoStatSvc.h"
44
47
48//###############################################################################
49CaloClusterMaker::CaloClusterMaker(const std::string& name,
50 ISvcLocator* pSvcLocator)
51 : AthReentrantAlgorithm(name, pSvcLocator)
52 , m_clusterOutput("")
56 , m_chrono("ChronoStatSvc", name)
57 , m_saveSignalState(true)
58 , m_chronoTools(false)
59{
60
61 // Name of Cluster Container to be registered in TDS
62 declareProperty("ClustersOutputName",m_clusterOutput);
63 declareProperty("ClusterCellLinkOutputName",m_clusterCellLinkOutput);
64
65 // Name(s) of Cluster Maker Tools
66 declareProperty("ClusterMakerTools",m_clusterMakerTools);
67
68 // Name(s) of Cluster Correction Tools
69 declareProperty("ClusterCorrectionTools",m_clusterCorrectionTools);
70
71 // Name(s) of Cluster Correction Tools (even field) to trigger the
72 // recording of the current cluster container in StoreGate before
73 // its execution and the corresponding container name(s) (odd
74 // fields). This property and KeepEachCorrection are mutually
75 // exclusive
76 //declareProperty("KeepCorrectionToolAndContainerNames", m_keepCorrectionToolAndContainerNames);
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
85//###############################################################################
86
88= default;
89
90//###############################################################################
91
93{
94
95
96 if (m_clusterMakerTools.retrieve().isFailure()) {
97 ATH_MSG_ERROR("Failed to retrieve maker ToolHandleArray "
99 } else {
100 ATH_MSG_DEBUG("Successfully retrieved maker ToolHandleArray "
102 }
103
104 if (m_clusterCorrectionTools.retrieve().isFailure()) {
105 ATH_MSG_ERROR("Failed to retrieve correction ToolHandleArray "
107 } else {
108 ATH_MSG_DEBUG("Successfully retrieved correction ToolHandleArray "
110 }
111
112 if (m_chronoTools) {
113 msg(MSG::INFO) << "Will use ChronoStatSvc to monitor ClusterMaker and ClusterCorrection tools" << endmsg;
114 ATH_CHECK( m_chrono.retrieve() );
115 }
116
117 ATH_CHECK( m_clusterOutput.initialize() );
118
119 if (m_clusterCellLinkOutput.key().empty()) {
120 m_clusterCellLinkOutput = m_clusterOutput.key() + "_links";
121 }
122 ATH_CHECK( m_clusterCellLinkOutput.initialize() );
123
125 m_mDecor_ncells = m_clusterOutput.key() + "." + m_mDecor_ncells.key();
126 }
128
129 return StatusCode::SUCCESS;
130}
131
132//###############################################################################
133
135 return StatusCode::SUCCESS;
136}
137
138//###############################################################################
139
140StatusCode CaloClusterMaker::execute (const EventContext& ctx) const
141{
142
143 // make a Cluster Container
145
147 ATH_CHECK( clusColl.record(std::make_unique<xAOD::CaloClusterContainer>(),
148 std::make_unique<xAOD::CaloClusterTrigAuxContainer>()) );
149 }
150 else {
152 }
153
154 ToolHandleArray<CaloClusterCollectionProcessor>::const_iterator toolIt, toolIt_e; //Iterators over Tool handles
155 toolIt=m_clusterMakerTools.begin();
156 toolIt_e=m_clusterMakerTools.end();
157
158 //Make Clusters: Execute each maker tool
159 //for (CaloClusterCollectionProcessor& tool : m_clusterMakerTools) { //Doesn't work because CaloClusterCollectionProcessor is a base class
160 for(;toolIt!=toolIt_e;++toolIt) {
161 const std::string chronoName = this->name() + "_" +toolIt->name();
162 if (m_chronoTools) m_chrono->chronoStart(chronoName);
163 ATH_CHECK((*toolIt)->execute(ctx, clusColl.ptr()));
164 if (m_chronoTools) m_chrono->chronoStop(chronoName);
165 } //End loop over maker tools
166
167 // PL set calibrated state
168 if ( m_saveSignalState ) {
169 //Fixme: Maybe this loop would auto-vectorize breaking into four separate loops for each quantity
170 for (xAOD::CaloCluster* fClus : *clusColl) {
171 ATH_MSG_DEBUG( "found cluster with state "<< fClus->signalState());
172 fClus->setRawE(fClus->calE());
173 fClus->setRawEta(fClus->calEta());
174 fClus->setRawPhi(fClus->calPhi());
175 fClus->setRawM(fClus->calM());
176 }//end loop over clusters
177 }
178
179
180 //Apply corrections: Exectue each correction tool
181 //for (CaloClusterCollectionProcessor* tool : m_clusterCorrectionTools) { //Doesn't work because CaloClusterCollectionProcessor is a base class
182 toolIt=m_clusterCorrectionTools.begin();
183 toolIt_e=m_clusterCorrectionTools.end();
184 for(;toolIt!=toolIt_e;++toolIt) {
185 const std::string& toolname=(*toolIt).name();
186
187 ATH_MSG_DEBUG(" Applying correction = " << toolname);
188 const std::string chronoName = this->name() + "_" + toolname;
189 if (m_chronoTools) m_chrono->chronoStart(chronoName);
190 ATH_CHECK((*toolIt)->execute(ctx, clusColl.ptr()));
191 if (m_chronoTools) m_chrono->chronoStop(chronoName);
192 }//End loop over correction tools
193
196
197 for (const xAOD::CaloCluster * cl : *clusColl) {
198 const CaloClusterCellLink * cell_links = cl->getCellLinks();
199 if (!cell_links) {
200 decor_handle(*cl) = 0;
201 }
202 else {
203 decor_handle(*cl) = cell_links->size();
204 }
205 }
206 }
207
208 ATH_MSG_DEBUG("Created cluster container with " << clusColl->size() << " clusters");
210 ATH_CHECK( cellLinks.record (std::make_unique<CaloClusterCellLinkContainer>()) );
211 CaloClusterStoreHelper::finalizeClusters (ctx, clusColl, cellLinks);
212
213 return StatusCode::SUCCESS;
214}
215
216
218 return m_clusterOutput.key();
219}
#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.
Handle class for adding a decoration to an object.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
An algorithm that can be simultaneously executed in multiple threads.
virtual StatusCode initialize() override
CaloClusterMaker(const std::string &name, ISvcLocator *pSvcLocator)
ToolHandleArray< CaloClusterCollectionProcessor > m_clusterCorrectionTools
the actual list of tools corresponding to above names
bool m_chronoTools
Use ChronotStatSvc to monitor each tool.
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_clusterOutput
the name of the key in StoreGate for the output CaloClusterContainer
bool m_saveSignalState
controls saving the uncalibrated signal state just before the first CaloClusterCorrectionTool is invo...
ToolHandleArray< CaloClusterCollectionProcessor > m_clusterMakerTools
a list of names for tools to make clusters
virtual ~CaloClusterMaker() override
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_clusterCellLinkOutput
the name of the key in StoreGate for the output CaloClusterCellLinkContainer
virtual StatusCode finalize() override
ServiceHandle< IChronoStatSvc > m_chrono
const std::string & getOutputContainerName() const
Gaudi::Property< bool > m_writeTriggerSpecificInfo
If true, writes some trigger-specific decorations.
SG::WriteDecorHandleKey< xAOD::CaloClusterContainer > m_mDecor_ncells
Key to the handle for writing the number of cells as a decoration.
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...
Handle class for adding a decoration to an object.
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.