ATLAS Offline Software
EGammaCookieCutClusterTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Decorate egamma objects with cluster moments from a cookie-cut cluster
6 
8 
11 
13 
14 namespace {
15  constexpr float cellEtaSize = 0.1;
16  constexpr float cellPhiSize = 0.1;
17 }
18 
19 // Athena initialize
22 {
23  ATH_MSG_VERBOSE("initialize() ...");
24 
26 
27  ATH_MSG_DEBUG("Will store cookie cut clusters in this container "
31 
32  ATH_MSG_DEBUG("Using " << m_SGKey_electrons << " for electrons");
33  ATH_CHECK(m_SGKey_electrons.initialize());
34 
36  ATH_MSG_DEBUG("Initialize nDecor = " << m_nDecor);
38  if (msgLvl(MSG::DEBUG)) {
39  ATH_MSG_DEBUG("Decorations for " << m_SGKey_electrons.key());
40  for (const auto& s : m_SGKey_electrons_decorations)
41  { ATH_MSG_DEBUG(s.key()); }
42  }
43 
44  m_CookieCutPars.maxDelEta = m_maxDelEtaCells * cellEtaSize * 0.5;
45  m_CookieCutPars.maxDelPhi = m_maxDelPhiCells * cellPhiSize * 0.5;
48 
49  // Retrieve cluster moment maker in case we cookie cut and want to recompute
50  if (!m_clusterCorrectionTools.empty()) {
53  }
54 
55  return StatusCode::SUCCESS;
56 }
57 
58 // The decoration itself
61 {
62 
63  // For debug
64  static const std::vector<CaloSampling::CaloSample> s_sam
75 
76  // Create the relevant cluster output and register it.
78  m_outClusterContainerKey,
79  ctx
80  );
82 
83  SG::WriteHandle<CaloClusterCellLinkContainer> outClusterContainerCellLink(
84  m_outClusterContainerCellLinkKey,
85  ctx
86  );
87  ATH_CHECK(outClusterContainerCellLink.record(
88  std::make_unique<CaloClusterCellLinkContainer>())
89  );
90 
91  // Retrieve electron container
93  ctx);
94  const std::size_t nF = electronContainer.ptr()->size();
95  if (nF == 0) {
96  return StatusCode::SUCCESS;
97  }
98 
99  std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>> decoM;
100  decoM.reserve(m_nDecor);
101  for (int i = 0; i < m_nDecor - 1; i++) {
102  decoM.emplace_back(m_SGKey_electrons_decorations[i], ctx);
103  }
104 
105  if (msgLevel(MSG::DEBUG)) {
106  std::call_once(m_Seen, [this,&decoM]() {
107  for (int i = 0; i < m_nDecor - 1; i++) {
108  ATH_MSG_DEBUG("Decor " << i << " out of " << m_nDecor
109  << " " << m_SGKey_electrons_decorations[i].key()
110  << " " << decoM[i].decorKey());
111  }
112  });
113  }
116  decoEl(m_SGKey_electrons_decorations[m_nDecor-1],ctx);
117 
118  // Calorimeter description.
119  SG::ReadCondHandle<CaloDetDescrManager> caloDetDescrMgrHandle{
120  m_caloDetDescrMgrKey, ctx
121  };
122  ATH_CHECK(caloDetDescrMgrHandle.isValid());
123  const CaloDetDescrManager* calodetdescrmgr = *caloDetDescrMgrHandle;
124 
125  // Decorate electrons
126  int iel = 0;
127  std::vector<bool> success(nF,true);
128  ATH_MSG_VERBOSE("Will analyze " << nF << " forward electrons");
129  for (const auto* electron : *electronContainer.ptr()) {
130 
131  const xAOD::CaloCluster *cluster = electron->caloCluster();
132  ATH_MSG_DEBUG("Electron " << electron->index() << " cluster"
133  << " pT = " << cluster->pt()
134  << " eta = " << cluster->eta());
135 
136  const DataLink<CaloCellContainer>& cellCont =
137  cluster->getCellLinks()->getCellContainerLink();
138 
139  std::unique_ptr<xAOD::CaloCluster> newCluster =
140  egammaClusterCookieCut::cookieCut(*cluster, *calodetdescrmgr,
141  cellCont, m_CookieCutPars);
142 
143  if (!newCluster || newCluster->getCellLinks()->size() == 0) {
144  ATH_MSG_DEBUG("No able to build a new cluster for electron "
145  << electron->index()
146  << " pT = " << electron->pt()
147  << " eta = " << electron->eta()
148  << " original cluster " << cluster->index()
149  << " pT = " << cluster->pt()
150  << " eta = " << cluster->eta()
151  << " has EME2 or FCAL0"
152  << " " << cluster->hasSampling(CaloSampling::EME2)
153  << " " << cluster->hasSampling(CaloSampling::FCAL0)
154  << " reason : "
155  << (newCluster ? " no cells in cluster" : " no cluster"));
156  if (!newCluster) {
157  ATH_MSG_VERBOSE("Energies in various samplings :");
158  for (auto s : s_sam)
159  ATH_MSG_VERBOSE("Sampling " << s << " E = " << cluster->eSample(s));
160  }
162  success[iel] = false;
163  }
164 
165  if (success[iel]) {
166  if (newCluster) {
167  ATH_MSG_DEBUG("Cookie cut cluster"
168  << " pT = " << newCluster->pt()
169  << " eta = " << newCluster->eta());
170  }
171  outClusterContainer->push_back(std::move(newCluster));
172  size_t index = outClusterContainer->size() - 1;
174  clusterLink(*outClusterContainer, index, ctx);
175  // Now decorate the electron with the link to cookie cut cluster
176  decoEl(*electron) = clusterLink;
177  }
178 
179  // Eventually decorate the electron with the original moment
180  if (m_storeOrigMom) {
181  for (size_t i = 0; i < m_vecM.size(); i++) {
182  int indexDecor = m_storeCookMom ? 2*i+1 : i;
183  double m = 0.;
184  bool gotM = cluster->retrieveMoment(
185  static_cast<xAOD::CaloCluster::MomentType>(m_vecM[i]), m);
186  if (!gotM) {
187  ATH_MSG_VERBOSE(m_vecMName[i]
188  << " does not exist for the original cluster");
189  }
190  decoM[indexDecor](*electron) = float(m);
191  ATH_MSG_VERBOSE("Decorated electron " << electron->index()
192  << " with original moment "
193  << i << " " << m_vecMName[i]
194  << " = " << m << " (decoration index =" << indexDecor
195  << " key = " << decoM[indexDecor].decorKey() << ")");
196  }
197  }
198  iel++;
199  }
200 
201  if (!m_clusterCorrectionTools.empty()) {
202  ToolHandleArray<CaloClusterCollectionProcessor>::const_iterator
203  toolIt = m_clusterCorrectionTools.begin(),
204  toolIt_e = m_clusterCorrectionTools.end();
205  for (; toolIt != toolIt_e; ++toolIt) {
206  ATH_CHECK((*toolIt)->execute(ctx, outClusterContainer.ptr()));
207  }
208 
209  if (m_storeCookMom) {
210  static const SG::AuxElement::Accessor<
212  cookClusLinkAcc( "cookiecutClusterLink" );
213  iel = 0;
214  for (const auto* electron : *electronContainer.ptr()) {
215  const xAOD::CaloCluster *cluster = nullptr;
216  if (success[iel]) {
218  }
219  if (success[iel] && cluster == nullptr) {
220  ATH_MSG_WARNING("CookieCut cluster was build successfully, but"
221  "could not be retrieved");
222  }
223 
224  for (size_t i = 0; i < m_vecM.size(); i++) {
225  int indexDecor = m_storeOrigMom ? 2*i : i;
226  double m = 0.;
227  if (cluster) {
228  bool gotM = cluster->retrieveMoment(
229  static_cast<xAOD::CaloCluster::MomentType>(m_vecM[i]), m);
230  if (!gotM) {
231  ATH_MSG_VERBOSE(m_vecMName[i]
232  << " does not exist for the new cluster");
233  }
234  }
235  decoM[indexDecor](*electron) = float(m);
236  ATH_MSG_VERBOSE("Decorated electron " << electron->index()
237  << " with new moment "
238  << i << " " << m_vecMName[i]
239  << " = " << m << " (decoration index = " << indexDecor
240  << " key = " << decoM[indexDecor].decorKey() << ")");
241  }
242  iel++;
243  }
244  }
245  }
246 
248  ctx,
249  outClusterContainer,
250  outClusterContainerCellLink);
251 
252  ATH_MSG_DEBUG("Built " << outClusterContainer.ptr()->size()
253  << " cookie cut clusters");
254 
255  return StatusCode::SUCCESS;
256 }
electronContainer
xAOD::ElectronContainer * electronContainer
Definition: TrigGlobEffCorrValidation.cxx:187
CaloClusterStoreHelper::finalizeClusters
static StatusCode finalizeClusters(SG::WriteHandle< CaloClusterCellLinkContainer > &h, xAOD::CaloClusterContainer *pClusterColl)
Finalize clusters (move CaloClusterCellLink to a separate container).
Definition: CaloClusterStoreHelper.cxx:64
CaloCell_ID_FCS::TileExt2
@ TileExt2
Definition: FastCaloSim_CaloCell_ID.h:39
constants.EMB1
int EMB1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:53
SG::ReadCondHandle
Definition: ReadCondHandle.h:40
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
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
egammaClusterCookieCut::CookieCutPars::maxDelR2
double maxDelR2
Definition: egammaClusterCookieCut.h:14
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
index
Definition: index.py:1
DerivationFramework::EGammaCookieCutClusterTool::m_SGKey_electrons_decorations
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > m_SGKey_electrons_decorations
Definition: EGammaCookieCutClusterTool.h:65
CaloCell_ID_FCS::TileExt0
@ TileExt0
Definition: FastCaloSim_CaloCell_ID.h:37
CaloCell_ID_FCS::TileBar1
@ TileBar1
Definition: FastCaloSim_CaloCell_ID.h:32
egammaClusterCookieCut::CookieCutPars::maxDelEta
double maxDelEta
Definition: egammaClusterCookieCut.h:12
egammaClusterCookieCut::CookieCutPars::recomputeMoments
bool recomputeMoments
Definition: egammaClusterCookieCut.h:15
CaloCell_ID_FCS::FCAL1
@ FCAL1
Definition: FastCaloSim_CaloCell_ID.h:41
DerivationFramework::EGammaCookieCutClusterTool::m_clusterCorrectionTools
ToolHandleArray< CaloClusterCollectionProcessor > m_clusterCorrectionTools
Definition: EGammaCookieCutClusterTool.h:141
CaloCell_ID_FCS::HEC2
@ HEC2
Definition: FastCaloSim_CaloCell_ID.h:29
DerivationFramework::EGammaCookieCutClusterTool::m_nDecor
unsigned short m_nDecor
Definition: EGammaCookieCutClusterTool.h:123
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
CaloCell_ID_FCS::TileGap3
@ TileGap3
Definition: FastCaloSim_CaloCell_ID.h:36
xAOD::CaloCluster_v1::MomentType
MomentType
Enums to identify different moments.
Definition: CaloCluster_v1.h:123
DerivationFramework::EGammaCookieCutClusterTool::m_outClusterContainerKey
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_outClusterContainerKey
Output cluster container.
Definition: EGammaCookieCutClusterTool.h:34
DerivationFramework::EGammaCookieCutClusterTool::initialize
virtual StatusCode initialize() override final
Definition: EGammaCookieCutClusterTool.cxx:21
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
egammaClusterCookieCut::CookieCutPars::fixCellWeights
bool fixCellWeights
Definition: egammaClusterCookieCut.h:16
EgammaxAODHelpers.h
DerivationFramework::EGammaCookieCutClusterTool::m_outClusterContainerCellLinkKey
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_outClusterContainerCellLinkKey
Output cluster container cell links: should match output containter name.
Definition: EGammaCookieCutClusterTool.h:42
CaloCell_ID_FCS::HEC1
@ HEC1
Definition: FastCaloSim_CaloCell_ID.h:28
DerivationFramework::EGammaCookieCutClusterTool::m_maxDelR
Gaudi::Property< float > m_maxDelR
Size of cone to cookie cut on FCal.
Definition: EGammaCookieCutClusterTool.h:89
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
xAOD::CaloCluster_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition: CaloCluster_v1.cxx:251
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloCell_ID_FCS::TileBar0
@ TileBar0
Definition: FastCaloSim_CaloCell_ID.h:31
egammaClusterCookieCut::cookieCut
std::unique_ptr< xAOD::CaloCluster > cookieCut(const xAOD::CaloCluster &cluster, const CaloDetDescrManager &mgr, const DataLink< CaloCellContainer > &cellCont, const egammaClusterCookieCut::CookieCutPars &pars)
Definition: egammaClusterCookieCut.cxx:28
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
CaloCell_ID_FCS::TileGap2
@ TileGap2
Definition: FastCaloSim_CaloCell_ID.h:35
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
EGammaCookieCutClusterTool.h
egammaClusterCookieCut::CookieCutPars::maxDelPhi
double maxDelPhi
Definition: egammaClusterCookieCut.h:13
xAOD::EgammaContainer
EgammaContainer_v1 EgammaContainer
Definition of the current "egamma container version".
Definition: EgammaContainer.h:17
constants.EME1
int EME1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:55
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::CaloCluster_v1::retrieveMoment
bool retrieveMoment(MomentType type, double &value) const
Retrieve individual moment.
Definition: CaloCluster_v1.cxx:662
DerivationFramework::EGammaCookieCutClusterTool::m_fixCellWeights
Gaudi::Property< bool > m_fixCellWeights
if true, use cell weights = 1 for cookie-cut cluster
Definition: EGammaCookieCutClusterTool.h:97
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
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
CaloCell_ID_FCS::TileGap1
@ TileGap1
Definition: FastCaloSim_CaloCell_ID.h:34
DerivationFramework::EGammaCookieCutClusterTool::m_maxDelPhiCells
Gaudi::Property< int > m_maxDelPhiCells
Size of maximum search window in phi.
Definition: EGammaCookieCutClusterTool.h:81
xAOD::CaloCluster_v1::getCellLinks
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
Definition: CaloCluster_v1.cxx:829
xAOD::CaloCluster_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle (negative for negative-energy clusters)
Definition: CaloCluster_v1.cxx:247
WriteCellNoiseToCool.nF
nF
Definition: WriteCellNoiseToCool.py:541
CaloCell_ID_FCS::TileExt1
@ TileExt1
Definition: FastCaloSim_CaloCell_ID.h:38
CaloCell_ID_FCS::EME3
@ EME3
Definition: FastCaloSim_CaloCell_ID.h:26
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
DerivationFramework::EGammaCookieCutClusterTool::m_maxDelEtaCells
Gaudi::Property< int > m_maxDelEtaCells
Size of maximum search window in eta.
Definition: EGammaCookieCutClusterTool.h:73
CaloCellContainer.h
CaloCell_ID_FCS::HEC0
@ HEC0
Definition: FastCaloSim_CaloCell_ID.h:27
CaloClusterStoreHelper.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
xAOD::CaloCluster_v1::eSample
float eSample(const CaloSample sampling) const
Definition: CaloCluster_v1.cxx:514
DerivationFramework::EGammaCookieCutClusterTool::m_caloDetDescrMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloDetDescrMgrKey
Calorimeter description.
Definition: EGammaCookieCutClusterTool.h:50
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:469
DerivationFramework::EGammaCookieCutClusterTool::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition: EGammaCookieCutClusterTool.cxx:60
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloCell_ID_FCS::PreSamplerE
@ PreSamplerE
Definition: FastCaloSim_CaloCell_ID.h:23
CaloCell_ID_FCS::PreSamplerB
@ PreSamplerB
Definition: FastCaloSim_CaloCell_ID.h:19
DEBUG
#define DEBUG
Definition: page_access.h:11
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
DerivationFramework::EGammaCookieCutClusterTool::m_SGKey_electrons
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_electrons
Definition: EGammaCookieCutClusterTool.h:57
CaloCell_ID_FCS::FCAL2
@ FCAL2
Definition: FastCaloSim_CaloCell_ID.h:42
DerivationFramework::EGammaCookieCutClusterTool::m_CookieCutPars
egammaClusterCookieCut::CookieCutPars m_CookieCutPars
Definition: EGammaCookieCutClusterTool.h:120
xAOD::CaloCluster_v1::hasSampling
bool hasSampling(const CaloSample s) const
Checks if certain smapling contributes to cluster.
Definition: CaloCluster_v1.h:882
CaloCell_ID_FCS::HEC3
@ HEC3
Definition: FastCaloSim_CaloCell_ID.h:30
CaloCell_ID_FCS::FCAL0
@ FCAL0
Definition: FastCaloSim_CaloCell_ID.h:40
CaloCell_ID_FCS::EMB3
@ EMB3
Definition: FastCaloSim_CaloCell_ID.h:22
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
CaloCell_ID_FCS::TileBar2
@ TileBar2
Definition: FastCaloSim_CaloCell_ID.h:33
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56
python.SystemOfUnits.m
float m
Definition: SystemOfUnits.py:106
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
xAOD::EgammaHelpers::getCluster
const xAOD::CaloCluster * getCluster(const xAOD::Egamma *eg, bool cook=true)
return the associated egamma cluster, that might be cookie-cut cluster (fwd electron)
Definition: EgammaxAODHelpers.cxx:55