ATLAS Offline Software
CaloClusterMaker.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: CaloClusterMaker.cxx,v 1.26 2009-04-18 02:56:18 ssnyder Exp $
9 //
10 // Description: see CaloClusterMaker.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 // - CaloClusterMaker 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 
28 //-----------------------
29 // This Class's Header --
30 //-----------------------
31 #include "CaloClusterMaker.h"
32 
33 //---------------
34 // C++ Headers --
35 //---------------
39 
43 
44 #include "GaudiKernel/IChronoStatSvc.h"
45 
46 //###############################################################################
48  ISvcLocator* pSvcLocator)
49  : AthReentrantAlgorithm(name, pSvcLocator)
50  , m_clusterOutput("")
51  , m_clusterCellLinkOutput("")
52  , m_clusterMakerTools(this)
53  , m_clusterCorrectionTools(this)
54  , m_chrono("ChronoStatSvc", name)
55  , m_saveSignalState(true)
56  , m_chronoTools(false)
57 {
58 
59  // Name of Cluster Container to be registered in TDS
60  declareProperty("ClustersOutputName",m_clusterOutput);
61  declareProperty("ClusterCellLinkOutputName",m_clusterCellLinkOutput);
62 
63  // Name(s) of Cluster Maker Tools
64  declareProperty("ClusterMakerTools",m_clusterMakerTools);
65 
66  // Name(s) of Cluster Correction Tools
67  declareProperty("ClusterCorrectionTools",m_clusterCorrectionTools);
68 
69  // Name(s) of Cluster Correction Tools (even field) to trigger the
70  // recording of the current cluster container in StoreGate before
71  // its execution and the corresponding container name(s) (odd
72  // fields). This property and KeepEachCorrection are mutually
73  // exclusive
74  //declareProperty("KeepCorrectionToolAndContainerNames", m_keepCorrectionToolAndContainerNames);
75 
76  // save uncalibrated cluster signal state
77  declareProperty("SaveUncalibratedSignalState",m_saveSignalState);
78 
79  //Make Chrono Auditors for Cluster maker and correction tools
80  declareProperty("ChronoTools", m_chronoTools);
81 }
82 
83 //###############################################################################
84 
86 = default;
87 
88 //###############################################################################
89 
91 {
92 
93 
94  if (m_clusterMakerTools.retrieve().isFailure()) {
95  ATH_MSG_ERROR("Failed to retrieve maker ToolHandleArray "
97  } else {
98  ATH_MSG_DEBUG("Successfully retrieved maker ToolHandleArray "
100  }
101 
102  if (m_clusterCorrectionTools.retrieve().isFailure()) {
103  ATH_MSG_ERROR("Failed to retrieve correction ToolHandleArray "
105  } else {
106  ATH_MSG_DEBUG("Successfully retrieved correction ToolHandleArray "
108  }
109 
110  if (m_chronoTools) {
111  msg(MSG::INFO) << "Will use ChronoStatSvc to monitor ClusterMaker and ClusterCorrection tools" << endmsg;
112  ATH_CHECK( m_chrono.retrieve() );
113  }
114 
116 
117  if (m_clusterCellLinkOutput.key().empty()) {
119  }
121 
122  return StatusCode::SUCCESS;
123 }
124 
125 //###############################################################################
126 
128  return StatusCode::SUCCESS;
129 }
130 
131 //###############################################################################
132 
133 StatusCode CaloClusterMaker::execute (const EventContext& ctx) const
134 {
135 
136  // make a Cluster Container
139 
140  ToolHandleArray<CaloClusterCollectionProcessor>::const_iterator toolIt, toolIt_e; //Iterators over Tool handles
141  toolIt=m_clusterMakerTools.begin();
142  toolIt_e=m_clusterMakerTools.end();
143 
144  //Make Clusters: Execute each maker tool
145  //for (CaloClusterCollectionProcessor& tool : m_clusterMakerTools) { //Doesn't work because CaloClusterCollectionProcessor is a base class
146  for(;toolIt!=toolIt_e;++toolIt) {
147  const std::string chronoName = this->name() + "_" +toolIt->name();
148  if (m_chronoTools) m_chrono->chronoStart(chronoName);
149  ATH_CHECK((*toolIt)->execute(ctx, clusColl.ptr()));
150  if (m_chronoTools) m_chrono->chronoStop(chronoName);
151  } //End loop over maker tools
152 
153  // PL set calibrated state
154  if ( m_saveSignalState ) {
155  //Fixme: Maybe this loop would auto-vectorize breaking into four separate loops for each quantity
156  for (xAOD::CaloCluster* fClus : *clusColl) {
157  ATH_MSG_DEBUG( "found cluster with state "<< fClus->signalState());
158  fClus->setRawE(fClus->calE());
159  fClus->setRawEta(fClus->calEta());
160  fClus->setRawPhi(fClus->calPhi());
161  fClus->setRawM(fClus->calM());
162  }//end loop over clusters
163  }
164 
165 
166  //Apply corrections: Exectue each correction tool
167  //for (CaloClusterCollectionProcessor* tool : m_clusterCorrectionTools) { //Doesn't work because CaloClusterCollectionProcessor is a base class
168  toolIt=m_clusterCorrectionTools.begin();
169  toolIt_e=m_clusterCorrectionTools.end();
170  for(;toolIt!=toolIt_e;++toolIt) {
171  const std::string& toolname=(*toolIt).name();
172 
173  ATH_MSG_DEBUG(" Applying correction = " << toolname);
174  const std::string chronoName = this->name() + "_" + toolname;
175  if (m_chronoTools) m_chrono->chronoStart(chronoName);
176  ATH_CHECK((*toolIt)->execute(ctx, clusColl.ptr()));
177  if (m_chronoTools) m_chrono->chronoStop(chronoName);
178  }//End loop over correction tools
179 
180  ATH_MSG_DEBUG("Created cluster container with " << clusColl->size() << " clusters");
183  clusColl.ptr()));
184 
185  return StatusCode::SUCCESS;
186 }
187 
188 
189 const std::string& CaloClusterMaker::getOutputContainerName() const {
190  return m_clusterOutput.key();
191 }
CaloClusterMaker::m_saveSignalState
bool m_saveSignalState
controls saving the uncalibrated signal state just before the first CaloClusterCorrectionTool is invo...
Definition: CaloClusterMaker.h:92
CaloClusterStoreHelper::finalizeClusters
static StatusCode finalizeClusters(SG::WriteHandle< CaloClusterCellLinkContainer > &h, xAOD::CaloClusterContainer *pClusterColl)
Finalize clusters (move CaloClusterCellLink to a separate container).
Definition: CaloClusterStoreHelper.cxx:64
CaloClusterMaker.h
CaloClusterMaker::m_chrono
ServiceHandle< IChronoStatSvc > m_chrono
Definition: CaloClusterMaker.h:85
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
CaloClusterMaker::m_clusterMakerTools
ToolHandleArray< CaloClusterCollectionProcessor > m_clusterMakerTools
a list of names for tools to make clusters
Definition: CaloClusterMaker.h:71
CaloClusterMaker::CaloClusterMaker
CaloClusterMaker(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CaloClusterMaker.cxx:47
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
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
CaloClusterMaker::m_clusterCorrectionTools
ToolHandleArray< CaloClusterCollectionProcessor > m_clusterCorrectionTools
the actual list of tools corresponding to above names
Definition: CaloClusterMaker.h:82
CaloClusterMaker::~CaloClusterMaker
virtual ~CaloClusterMaker() override
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloClusterMaker::initialize
virtual StatusCode initialize() override
Definition: CaloClusterMaker.cxx:90
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
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
CaloClusterMaker::m_chronoTools
bool m_chronoTools
Use ChronotStatSvc to monitor each tool.
Definition: CaloClusterMaker.h:95
CaloClusterMaker::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: CaloClusterMaker.cxx:133
python.hypoToolDisplay.toolname
def toolname(tool)
Definition: hypoToolDisplay.py:13
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
CaloClusterMaker::m_clusterCellLinkOutput
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_clusterCellLinkOutput
the name of the key in StoreGate for the output CaloClusterCellLinkContainer
Definition: CaloClusterMaker.h:63
CaloClusterMaker::finalize
virtual StatusCode finalize() override
Definition: CaloClusterMaker.cxx:127
CaloClusterStoreHelper.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
CaloClusterContainer.h
CaloClusterSignalState.h
CaloClusterMaker::getOutputContainerName
const std::string & getOutputContainerName() const
Definition: CaloClusterMaker.cxx:189
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
CaloClusterMaker::m_clusterOutput
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_clusterOutput
the name of the key in StoreGate for the output CaloClusterContainer
Definition: CaloClusterMaker.h:59