ATLAS Offline Software
CaloClusterMaker.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
48 
49 //###############################################################################
51  ISvcLocator* pSvcLocator)
52  : AthReentrantAlgorithm(name, pSvcLocator)
53  , m_clusterOutput("")
54  , m_clusterCellLinkOutput("")
55  , m_clusterMakerTools(this)
56  , m_clusterCorrectionTools(this)
57  , m_chrono("ChronoStatSvc", name)
58  , m_saveSignalState(true)
59  , m_chronoTools(false)
60 {
61 
62  // Name of Cluster Container to be registered in TDS
63  declareProperty("ClustersOutputName",m_clusterOutput);
64  declareProperty("ClusterCellLinkOutputName",m_clusterCellLinkOutput);
65 
66  // Name(s) of Cluster Maker Tools
67  declareProperty("ClusterMakerTools",m_clusterMakerTools);
68 
69  // Name(s) of Cluster Correction Tools
70  declareProperty("ClusterCorrectionTools",m_clusterCorrectionTools);
71 
72  // Name(s) of Cluster Correction Tools (even field) to trigger the
73  // recording of the current cluster container in StoreGate before
74  // its execution and the corresponding container name(s) (odd
75  // fields). This property and KeepEachCorrection are mutually
76  // exclusive
77  //declareProperty("KeepCorrectionToolAndContainerNames", m_keepCorrectionToolAndContainerNames);
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 
86 //###############################################################################
87 
89 = default;
90 
91 //###############################################################################
92 
94 {
95 
96 
97  if (m_clusterMakerTools.retrieve().isFailure()) {
98  ATH_MSG_ERROR("Failed to retrieve maker ToolHandleArray "
100  } else {
101  ATH_MSG_DEBUG("Successfully retrieved maker ToolHandleArray "
103  }
104 
105  if (m_clusterCorrectionTools.retrieve().isFailure()) {
106  ATH_MSG_ERROR("Failed to retrieve correction ToolHandleArray "
108  } else {
109  ATH_MSG_DEBUG("Successfully retrieved correction ToolHandleArray "
111  }
112 
113  if (m_chronoTools) {
114  msg(MSG::INFO) << "Will use ChronoStatSvc to monitor ClusterMaker and ClusterCorrection tools" << endmsg;
115  ATH_CHECK( m_chrono.retrieve() );
116  }
117 
119 
120  if (m_clusterCellLinkOutput.key().empty()) {
122  }
124 
127  }
129 
130  return StatusCode::SUCCESS;
131 }
132 
133 //###############################################################################
134 
136  return StatusCode::SUCCESS;
137 }
138 
139 //###############################################################################
140 
141 StatusCode CaloClusterMaker::execute (const EventContext& ctx) const
142 {
143 
144  // make a Cluster Container
146 
148  ATH_CHECK( clusColl.record(std::make_unique<xAOD::CaloClusterContainer>(),
149  std::make_unique<xAOD::CaloClusterTrigAuxContainer>()) );
150  }
151  else {
153  }
154 
155  ToolHandleArray<CaloClusterCollectionProcessor>::const_iterator toolIt, toolIt_e; //Iterators over Tool handles
156  toolIt=m_clusterMakerTools.begin();
157  toolIt_e=m_clusterMakerTools.end();
158 
159  //Make Clusters: Execute each maker tool
160  //for (CaloClusterCollectionProcessor& tool : m_clusterMakerTools) { //Doesn't work because CaloClusterCollectionProcessor is a base class
161  for(;toolIt!=toolIt_e;++toolIt) {
162  const std::string chronoName = this->name() + "_" +toolIt->name();
163  if (m_chronoTools) m_chrono->chronoStart(chronoName);
164  ATH_CHECK((*toolIt)->execute(ctx, clusColl.ptr()));
165  if (m_chronoTools) m_chrono->chronoStop(chronoName);
166  } //End loop over maker tools
167 
168  // PL set calibrated state
169  if ( m_saveSignalState ) {
170  //Fixme: Maybe this loop would auto-vectorize breaking into four separate loops for each quantity
171  for (xAOD::CaloCluster* fClus : *clusColl) {
172  ATH_MSG_DEBUG( "found cluster with state "<< fClus->signalState());
173  fClus->setRawE(fClus->calE());
174  fClus->setRawEta(fClus->calEta());
175  fClus->setRawPhi(fClus->calPhi());
176  fClus->setRawM(fClus->calM());
177  }//end loop over clusters
178  }
179 
180 
181  //Apply corrections: Exectue each correction tool
182  //for (CaloClusterCollectionProcessor* tool : m_clusterCorrectionTools) { //Doesn't work because CaloClusterCollectionProcessor is a base class
183  toolIt=m_clusterCorrectionTools.begin();
184  toolIt_e=m_clusterCorrectionTools.end();
185  for(;toolIt!=toolIt_e;++toolIt) {
186  const std::string& toolname=(*toolIt).name();
187 
188  ATH_MSG_DEBUG(" Applying correction = " << toolname);
189  const std::string chronoName = this->name() + "_" + toolname;
190  if (m_chronoTools) m_chrono->chronoStart(chronoName);
191  ATH_CHECK((*toolIt)->execute(ctx, clusColl.ptr()));
192  if (m_chronoTools) m_chrono->chronoStop(chronoName);
193  }//End loop over correction tools
194 
197 
198  for (const xAOD::CaloCluster * cl : *clusColl) {
199  const CaloClusterCellLink * cell_links = cl->getCellLinks();
200  if (!cell_links) {
201  decor_handle(*cl) = 0;
202  }
203  else {
204  decor_handle(*cl) = cell_links->size();
205  }
206  }
207  }
208 
209  ATH_MSG_DEBUG("Created cluster container with " << clusColl->size() << " clusters");
212  clusColl.ptr()));
213 
214  return StatusCode::SUCCESS;
215 }
216 
217 
218 const std::string& CaloClusterMaker::getOutputContainerName() const {
219  return m_clusterOutput.key();
220 }
CaloClusterMaker::m_saveSignalState
bool m_saveSignalState
controls saving the uncalibrated signal state just before the first CaloClusterCorrectionTool is invo...
Definition: CaloClusterMaker.h:94
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
CaloClusterTrigAuxContainer.h
CaloClusterMaker::m_chrono
ServiceHandle< IChronoStatSvc > m_chrono
Definition: CaloClusterMaker.h:87
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:73
CaloClusterMaker::CaloClusterMaker
CaloClusterMaker(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CaloClusterMaker.cxx:50
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:84
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:93
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
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
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:97
CaloClusterMaker::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: CaloClusterMaker.cxx:141
python.hypoToolDisplay.toolname
def toolname(tool)
Definition: hypoToolDisplay.py:13
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
CaloClusterMaker::m_mDecor_ncells
SG::WriteDecorHandleKey< xAOD::CaloClusterContainer > m_mDecor_ncells
Key to the handle for writing the number of cells as a decoration.
Definition: CaloClusterMaker.h:106
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:65
CaloClusterMaker::finalize
virtual StatusCode finalize() override
Definition: CaloClusterMaker.cxx:135
CaloClusterMaker::m_writeTriggerSpecificInfo
Gaudi::Property< bool > m_writeTriggerSpecificInfo
If true, writes some trigger-specific decorations.
Definition: CaloClusterMaker.h:102
CaloClusterStoreHelper.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
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:218
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
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:61