ATLAS Offline Software
CaloThinCellsByClusterAlg.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
3  */
13 #include "CaloUtils/CaloCellList.h"
15 #include "StoreGate/ReadHandle.h"
16 
17 
22 {
26  if (m_clusterCellLinks.key().empty()) {
27  m_clusterCellLinks = m_clusters.key() + "_links";
28  }
30  if (!m_samplingNames.empty()) {
32  }
33  return StatusCode::SUCCESS;
34 }
35 
36 
41 StatusCode CaloThinCellsByClusterAlg::execute (const EventContext& ctx) const
42 {
44  cells.thinAll();
45 
47  if(!clusters.isValid()){
48  ATH_MSG_WARNING( "Collection " << m_clusters.key()<<" is not valid");
49  return StatusCode::SUCCESS;
50  }
51 
53  clusterCellLinks.keepAll();
54 
56  const CaloDetDescrManager* caloDDMgr = *caloMgrHandle;
57 
58 
59  for (const xAOD::CaloCluster* clust : *clusters) {
60  const CaloClusterCellLink* cellLinks = clust->getCellLinks();
61  if (!cellLinks) {
62  ATH_MSG_WARNING( " Cluster without cell links found in collection: " << m_clusters.key()
63  << " ===> cells cannot be written in AOD as requested ! " );
64  continue;
65  }
66 
67  if (cellLinks->getCellContainerLink().dataID() != m_cells.key()) {
68  ATH_MSG_WARNING( " Cluster points to cell container "
69  << cellLinks->getCellContainerLink().dataID()
70  << " which is different from the cell container being thinned: "
71  << m_cells.key() << "; cluster skipped.");
72  continue;
73  }
74 
75  // nb. not using range-based for here because we don't want to actually
76  // dereference the iterators.
79  for (; it != end; ++it) {
80  if (it.index() >= cells->size()) {
81  ATH_MSG_WARNING( " Cell index " << it.index()
82  << " is larger than the number of cells in "
83  << m_cells.key() << " (" << cells->size() << ")" );
84  continue;
85  }
86  cells.keep (it.index());
87  }
88 
89  // add additional layer cells
90  if (!m_validSamplings.empty()) {
91  double eta = clust->eta();
92  double phi = clust->phi();
93  double deta = clust->getClusterEtaSize() * 0.025;
94  double dphi = clust->getClusterPhiSize() * 0.025;
95  // get cell lists for each sampling we want to add
96  for (int isamp : m_validSamplings) {
97  CaloCellList cell_list (caloDDMgr,cells.cptr());
98  cell_list.select (eta, phi, deta, dphi, isamp);
99 
100  ATH_MSG_DEBUG( "sampling " << isamp
101  << ", size of list = " << cell_list.ncells()
102  << ", eta = " << eta
103  << ", phi = " << phi
104  << ", deta = " << deta
105  << ", dphi = " << dphi );
106 
107  for (const CaloCell* cell : cell_list) {
108  const IdentifierHash cellHash = cell->caloDDE()->calo_hash();
109  int index = cells->findIndex (cellHash);
110  if (index < 0) {
111  ATH_MSG_WARNING( " Cell hash " << cellHash
112  << " not found in cell container "
113  << m_cells.key() );
114  continue;
115  }
116  cells.keep (index);
117  } // end of cell loop
118  } // end of sampling loop
119  } // endif m_addSamplingCells
120  }
121 
122  return StatusCode::SUCCESS;
123 }
124 
125 
130 {
131  for (const std::string& name : m_samplingNames) {
133  if (samp == CaloSampling::Unknown) {
134  ATH_MSG_ERROR ( "Calorimeter sampling" << name
135  << " is not a valid Calorimeter sampling name and will be ignored! " );
136  }
137  else {
138  m_validSamplings.push_back (static_cast<int> (samp));
139  }
140  }
141 
142  std::sort (m_validSamplings.begin(), m_validSamplings.end());
143  auto it = std::unique (m_validSamplings.begin(), m_validSamplings.end());
144  m_validSamplings.erase (it, m_validSamplings.end());
145 
146  return StatusCode::SUCCESS;
147 }
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:281
GetLCDefs::Unknown
@ Unknown
Definition: GetLCDefs.h:21
CaloSampling::getSampling
static CaloSample getSampling(const std::string &name)
Return the sampling code for a given name.
Definition: Calorimeter/CaloGeoHelpers/Root/CaloSampling.cxx:32
CaloThinCellsByClusterAlg::initialize
virtual StatusCode initialize() override
Gaudi initialize method.
Definition: CaloThinCellsByClusterAlg.cxx:21
CaloCellList
Definition: CaloCellList.h:40
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
CaloCellList::select
void select(double eta, double phi, double deta, double dphi)
Definition: CaloCellList.cxx:78
SG::ThinningHandleBase::keepAll
void keepAll()
Mark that all elements should be kept (not thinned).
Definition: ThinningHandleBase.cxx:152
ThinningHandle.h
Handle for requesting thinning for a data object.
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
index
Definition: index.py:1
CaloCellList.h
CaloThinCellsByClusterAlg::m_clusters
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusters
Clusters to read.
Definition: CaloThinCellsByClusterAlg.h:69
skel.it
it
Definition: skel.GENtoEVGEN.py:407
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition: ThinningHandle.h:84
SG::ThinningHandleKey::initialize
StatusCode initialize(const std::string &stream, const std::string &qualifier, bool used=true)
Should be called during the initialize phase.
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:92
CaloThinCellsByClusterAlg::m_samplingNames
StringArrayProperty m_samplingNames
Definition: CaloThinCellsByClusterAlg.h:77
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
CaloThinCellsByClusterAlg::decodeSamplings
StatusCode decodeSamplings()
Decode the provided list of calorimeter samplings.
Definition: CaloThinCellsByClusterAlg.cxx:129
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CaloThinCellsByClusterAlg::m_cells
SG::ThinningHandleKey< CaloCellContainer > m_cells
Cell container to thin.
Definition: CaloThinCellsByClusterAlg.h:65
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
WriteCellNoiseToCool.cellHash
cellHash
Definition: WriteCellNoiseToCool.py:433
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
CaloThinCellsByClusterAlg::m_clusterCellLinks
SG::ThinningHandleKey< CaloClusterCellLinkContainer > m_clusterCellLinks
Calo Cell links for the clusters we keep cells for.
Definition: CaloThinCellsByClusterAlg.h:72
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloThinCellsByClusterAlg.h
Thin calorimeter cells not associated with clusters.
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloThinCellsByClusterAlg::m_streamName
StringProperty m_streamName
Name of the stream being thinned.
Definition: CaloThinCellsByClusterAlg.h:61
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
CaloCellList::ncells
int ncells() const
Definition: CaloCellList.h:112
CaloThinCellsByClusterAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Execute the algorithm.
Definition: CaloThinCellsByClusterAlg.cxx:41
ReadHandle.h
Handle class for reading from StoreGate.
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
CaloThinCellsByClusterAlg::m_validSamplings
std::vector< int > m_validSamplings
Decoded list of samplings.
Definition: CaloThinCellsByClusterAlg.h:83
CaloThinCellsByClusterAlg::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: CaloThinCellsByClusterAlg.h:80