ATLAS Offline Software
CaloTopoTowerMaker.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 //-----------------------------------------------------------------------
7 // File and Version Information:
8 // $Id: CaloTopoTowerMaker.cxx,v 1.26 2009-04-18 02:56:18 ssnyder Exp $
9 //
10 // Description: see CaloTopoTowerMaker.h
11 //
12 // Environment:
13 // Software developed for the ATLAS Detector at CERN LHC
14 //
15 // Author List:
16 // Sven Menke
17 //
18 // Modified: Feb 09, 2005 (DLelas)
19 // - CaloTopoTowerMaker applies correction type tool on a whole
20 // cluster collection now. Needed for Sliding Window
21 // cell weights calculation.
22 //
23 // Modified Feb 2014 (W Lampl)
24 // - Migrate to xAOD::CaloCluster(Container)
25 // - Move to AthAlgorithm, some simplifications
26 //
27 // Modified Sep 2020 (T Chowdhury)
28 // -
29 //-----------------------------------------------------------------------
30 
31 //-----------------------
32 // This Class's Header --
33 //-----------------------
34 #include "CaloTopoTowerMaker.h"
35 
36 //---------------
37 // C++ Headers --
38 //---------------
43 
47 
48 #include "GaudiKernel/IChronoStatSvc.h"
49 
51 
52 #include <memory> // for the std::unique_ptr
53 #include <cmath>
54 
55 //###############################################################################
57  ISvcLocator* pSvcLocator)
58  : AthReentrantAlgorithm(name, pSvcLocator)
59  , m_towerOutput("")
60  , m_towerCellLinkOutput("")
61  , m_towerMakerTool(this)
62  , m_towerCorrectionTools(this)
63  , m_towerCalibratorTool(this)
64  , m_chrono("ChronoStatSvc", name)
65 {
66  // Name of Cluster Container to be registered in TDS
67  declareProperty("TowersOutputName",m_towerOutput);
68  declareProperty("TowerCellLinkOutputName",m_towerCellLinkOutput);
69 
70  // Name(s) of Cluster Maker Tools
71  declareProperty("TowerMakerTool",m_towerMakerTool);
72 
73  // Name(s) of Cluster Correction Tools
74  declareProperty("TowerCorrectionTools",m_towerCorrectionTools);
75 
76  // Tower calibrator tool
77  declareProperty("TowerCalibratorTool",m_towerCalibratorTool);
78 
79  // save uncalibrated cluster signal state
80  declareProperty("SaveUncalibratedSignalState",m_saveSignalState);
81 
82  //Make Chrono Auditors for Cluster maker and correction tools
83  declareProperty("ChronoTools", m_chronoTools);
84 
85  // apply LCW calibration for towers
86  declareProperty("UseLCWCalibration",m_useLCWCalibration);
87 }
88 
89 //###############################################################################
90 
92 = default;
93 
94 //###############################################################################
95 
97 {
98 
99  // -- retrieve the needed tower maker tool
100  if (m_towerMakerTool.retrieve().isFailure()) {
101  ATH_MSG_ERROR("Failed to retrieve essential tower maker tool"
102  << m_towerMakerTool);
103  } else {
104  ATH_MSG_DEBUG("Successfully retrieved tower maker tool "
105  << m_towerMakerTool);
106  }
107 
108  // -- retrieve the (optional) list of correction tools
109  if (m_towerCorrectionTools.retrieve().isFailure()) {
110  ATH_MSG_ERROR("Failed to retrieve requested tower correction tools "
112  } else {
113  ATH_MSG_DEBUG("Successfully retrieved tower correction tools "
115  }
116 
117  // -- retrieve tower calibrator tool
118  if ( m_useLCWCalibration ) {
119  if ( m_towerCalibratorTool.retrieve().isFailure() ) {
120  ATH_MSG_ERROR("Failed to retrieve requested tower calibrator tool " << m_towerCalibratorTool);
121  } else {
122  ATH_MSG_DEBUG("Sucessfully retrieved requested tower calibrator tool " << m_towerCalibratorTool);
123  }
124  }
125 
126  if (m_chronoTools) {
127  msg(MSG::INFO) << "Will use ChronoStatSvc to monitor ClusterMaker and ClusterCorrection tools" << endmsg;
128  ATH_CHECK( m_chrono.retrieve() );
129  }
130 
132 
133  if (m_towerCellLinkOutput.key().empty()) {
134  m_towerCellLinkOutput = m_towerOutput.key() + "_links";
135  }
137 
138 
139  ATH_CHECK(detStore()->retrieve(m_caloCellID,"CaloCell_ID"));
140 
141  return StatusCode::SUCCESS;
142 }
143 
144 //###############################################################################
145 
147  return StatusCode::SUCCESS;
148 }
149 
150 //###############################################################################
151 
152 StatusCode CaloTopoTowerMaker::execute (const EventContext& ctx) const
153 {
154 
155  // make a Cluster Container
158 
159  std::string chronoName(this->name()+std::string("_"));
160  if ( !m_useLCWCalibration ) {
161  // fill the towers without preparing for calibratoin
162  if ( m_chronoTools ) { m_chrono->chronoStart(chronoName+m_towerMakerTool->name()); }
163  ATH_CHECK( m_towerMakerTool->execute(ctx,clusColl.ptr(),nullptr) );
164  if ( m_chronoTools ) { m_chrono->chronoStop(chronoName+m_towerMakerTool->name()); }
165  // save original signals bevore corrections and calibrations
166  if ( m_saveSignalState ) {
167  for (xAOD::CaloCluster* fClus : *clusColl) {
168  fClus->setRawE (fClus->e() );
169  fClus->setRawEta(fClus->eta());
170  fClus->setRawPhi(fClus->phi());
171  fClus->setRawM (fClus->m() );
172  }//end loop over clusters
173  }
174  // apply the correction tools (really moment calculators)
175  for ( auto iter(m_towerCorrectionTools.begin()); iter != m_towerCorrectionTools.end(); ++iter ) {
176  if ( m_chronoTools ) { m_chrono->chronoStart(chronoName+iter->name()); }
177  ATH_CHECK( (*iter)->execute(ctx,clusColl.ptr()) );
178  if ( m_chronoTools ) { m_chrono->chronoStop(chronoName+iter->name()); }
179  } // correction tool loop
180  } else {
181  // fill the towers with LCW calibration
182  std::unique_ptr<CaloCellClusterWeights> cellWeights=std::make_unique<CaloCellClusterWeights>(m_caloCellID->calo_cell_hash_max());
183  if ( m_chronoTools ) { m_chrono->chronoStart(chronoName+m_towerMakerTool->name()); }
184  ATH_CHECK( m_towerMakerTool->execute(ctx,clusColl.ptr(),cellWeights.get()) );
185  if ( m_chronoTools ) { m_chrono->chronoStop(chronoName+m_towerMakerTool->name()); }
186  // save original signals bevore corrections and calibrations
187  if ( m_saveSignalState ) {
188  for (xAOD::CaloCluster* fClus : *clusColl) {
189  fClus->setRawE (fClus->e() );
190  fClus->setRawEta(fClus->eta());
191  fClus->setRawPhi(fClus->phi());
192  fClus->setRawM (fClus->m() );
193  }//end loop over clusters
194  }
195  // apply the correction tools (really moment calculators)
196  for ( auto iter(m_towerCorrectionTools.begin()); iter != m_towerCorrectionTools.end(); ++iter ) {
197  if ( m_chronoTools ) { m_chrono->chronoStart(chronoName+iter->name()); }
198  ATH_CHECK( (*iter)->execute(ctx,clusColl.ptr()) );
199  if ( m_chronoTools ) { m_chrono->chronoStop(chronoName+iter->name()); }
200  } // correction tool loop
201  // apply calibration
202  if ( m_chronoTools ) { m_chrono->chronoStart(chronoName+m_towerCalibratorTool->name()); }
203  ATH_CHECK( m_towerCalibratorTool->execute(ctx,clusColl.ptr(),cellWeights.get()) );
204  if ( m_chronoTools ) { m_chrono->chronoStop(chronoName+m_towerCalibratorTool->name()); }
205  } // end of processing blocks
206 
207  ATH_MSG_DEBUG("Created tower container (of type xAOD::CaloClusterContainer) with " << clusColl->size() << " towers");
210  clusColl.ptr()));
211  return StatusCode::SUCCESS;
212 }
213 
214 
215 const std::string& CaloTopoTowerMaker::getOutputContainerName() const {
216  return m_towerOutput.key();
217 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CaloClusterStoreHelper::finalizeClusters
static StatusCode finalizeClusters(SG::WriteHandle< CaloClusterCellLinkContainer > &h, xAOD::CaloClusterContainer *pClusterColl)
Finalize clusters (move CaloClusterCellLink to a separate container).
Definition: CaloClusterStoreHelper.cxx:64
CaloTopoTowerMaker.h
CaloClusterStoreHelper::AddContainerWriteHandle
static StatusCode AddContainerWriteHandle(SG::WriteHandle< xAOD::CaloClusterContainer > &clusColl)
Creates a new xAOD::CaloClusterContainer in the given WriteHandle + CaloClusterAuxContainer and recor...
Definition: CaloClusterStoreHelper.cxx:53
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloTopoTowerMaker::m_caloCellID
const CaloCell_ID * m_caloCellID
Identifier helper.
Definition: CaloTopoTowerMaker.h:111
CaloTopoTowerMaker::m_towerMakerTool
ToolHandle< CaloTowerCollectionProcessor > m_towerMakerTool
Tower makers.
Definition: CaloTopoTowerMaker.h:73
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
CaloClusterAuxContainer.h
CaloTopoTowerMaker::m_chronoTools
bool m_chronoTools
Use ChronotStatSvc to monitor each tool.
Definition: CaloTopoTowerMaker.h:104
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
CaloTopoTowerMaker::m_towerCalibratorTool
ToolHandle< CaloTowerCollectionProcessor > m_towerCalibratorTool
Tower calibrator(s)
Definition: CaloTopoTowerMaker.h:85
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
CaloTopoTowerMaker::CaloTopoTowerMaker
CaloTopoTowerMaker(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CaloTopoTowerMaker.cxx:56
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CaloTopoTowerMaker::initialize
virtual StatusCode initialize() override
Definition: CaloTopoTowerMaker.cxx:96
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
CaloTopoTowerMaker::m_towerOutput
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_towerOutput
the name of the key in StoreGate for the output CaloClusterContainer
Definition: CaloTopoTowerMaker.h:62
CaloTopoTowerMaker::getOutputContainerName
const std::string & getOutputContainerName() const
Definition: CaloTopoTowerMaker.cxx:215
CaloTopoTowerMaker::m_towerCellLinkOutput
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_towerCellLinkOutput
the name of the key in StoreGate for the output CaloClusterCellLinkContainer
Definition: CaloTopoTowerMaker.h:66
CaloTopoTowerMaker::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: CaloTopoTowerMaker.cxx:152
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
CaloClusterStoreHelper.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
CaloTopoClusterFromTowerHelpers.h
CaloTopoTowerMaker::m_useLCWCalibration
bool m_useLCWCalibration
Use LCW calibration for topo-towers (default is true)
Definition: CaloTopoTowerMaker.h:107
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
CaloClusterContainer.h
CaloTopoTowerMaker::m_saveSignalState
bool m_saveSignalState
Keep the individual results of each correction.
Definition: CaloTopoTowerMaker.h:101
CaloClusterSignalState.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
CaloTopoTowerMaker::m_towerCorrectionTools
ToolHandleArray< CaloClusterCollectionProcessor > m_towerCorrectionTools
Tower (cluster) moment makers.
Definition: CaloTopoTowerMaker.h:80
CaloTopoTowerMaker::m_chrono
ServiceHandle< IChronoStatSvc > m_chrono
Handle to the ChronoStatSvc.
Definition: CaloTopoTowerMaker.h:88
CaloTopoTowerMaker::~CaloTopoTowerMaker
virtual ~CaloTopoTowerMaker() override
CaloTopoTowerMaker::finalize
virtual StatusCode finalize() override
Definition: CaloTopoTowerMaker.cxx:146
CaloCell_Base_ID::calo_cell_hash_max
size_type calo_cell_hash_max(void) const
cell 'global' hash table max size
CaloCellClusterWeights.h