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 
27  if (!m_samplingNames.empty()) {
29  }
30  return StatusCode::SUCCESS;
31 }
32 
33 
38 StatusCode CaloThinCellsByClusterAlg::execute (const EventContext& ctx) const
39 {
41  cells.thinAll();
42 
44  if(!clusters.isValid()){
45  ATH_MSG_WARNING( "Collection " << m_clusters.key()<<" is not valid");
46  return StatusCode::SUCCESS;
47  }
48 
49 
51  const CaloDetDescrManager* caloDDMgr = *caloMgrHandle;
52 
53 
54  for (const xAOD::CaloCluster* clust : *clusters) {
55  const CaloClusterCellLink* cellLinks = clust->getCellLinks();
56  if (!cellLinks) {
57  ATH_MSG_WARNING( " Cluster without cell links found in collection: " << m_clusters.key()
58  << " ===> cells cannot be written in AOD as requested ! " );
59  continue;
60  }
61 
62  if (cellLinks->getCellContainerLink().dataID() != m_cells.key()) {
63  ATH_MSG_WARNING( " Cluster points to cell container "
64  << cellLinks->getCellContainerLink().dataID()
65  << " which is different from the cell container being thinned: "
66  << m_cells.key() << "; cluster skipped.");
67  continue;
68  }
69 
70  // nb. not using range-based for here because we don't want to actually
71  // dereference the iterators.
74  for (; it != end; ++it) {
75  if (it.index() >= cells->size()) {
76  ATH_MSG_WARNING( " Cell index " << it.index()
77  << " is larger than the number of cells in "
78  << m_cells.key() << " (" << cells->size() << ")" );
79  continue;
80  }
81  cells.keep (it.index());
82  }
83 
84  // add additional layer cells
85  if (!m_validSamplings.empty()) {
86  double eta = clust->eta();
87  double phi = clust->phi();
88  double deta = clust->getClusterEtaSize() * 0.025;
89  double dphi = clust->getClusterPhiSize() * 0.025;
90  // get cell lists for each sampling we want to add
91  for (int isamp : m_validSamplings) {
92  CaloCellList cell_list (caloDDMgr,cells.cptr());
93  cell_list.select (eta, phi, deta, dphi, isamp);
94 
95  ATH_MSG_DEBUG( "sampling " << isamp
96  << ", size of list = " << cell_list.ncells()
97  << ", eta = " << eta
98  << ", phi = " << phi
99  << ", deta = " << deta
100  << ", dphi = " << dphi );
101 
102  for (const CaloCell* cell : cell_list) {
103  const IdentifierHash cellHash = cell->caloDDE()->calo_hash();
104  int index = cells->findIndex (cellHash);
105  if (index < 0) {
106  ATH_MSG_WARNING( " Cell hash " << cellHash
107  << " not found in cell container "
108  << m_cells.key() );
109  continue;
110  }
111  cells.keep (index);
112  } // end of cell loop
113  } // end of sampling loop
114  } // endif m_addSamplingCells
115  }
116 
117  return StatusCode::SUCCESS;
118 }
119 
120 
125 {
126  for (const std::string& name : m_samplingNames) {
128  if (samp == CaloSampling::Unknown) {
129  ATH_MSG_ERROR ( "Calorimeter sampling" << name
130  << " is not a valid Calorimeter sampling name and will be ignored! " );
131  }
132  else {
133  m_validSamplings.push_back (static_cast<int> (samp));
134  }
135  }
136 
137  std::sort (m_validSamplings.begin(), m_validSamplings.end());
138  auto it = std::unique (m_validSamplings.begin(), m_validSamplings.end());
139  m_validSamplings.erase (it, m_validSamplings.end());
140 
141  return StatusCode::SUCCESS;
142 }
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:271
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:64
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
CaloCellList::select
void select(double eta, double phi, double deta, double dphi)
Definition: CaloCellList.cxx:67
ThinningHandle.h
Handle for requesting thinning for a data object.
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
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:423
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:93
CaloThinCellsByClusterAlg::m_samplingNames
StringArrayProperty m_samplingNames
Definition: CaloThinCellsByClusterAlg.h:72
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
CaloThinCellsByClusterAlg::decodeSamplings
StatusCode decodeSamplings()
Decode the provided list of calorimeter samplings.
Definition: CaloThinCellsByClusterAlg.cxx:124
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:195
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:111
CaloThinCellsByClusterAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Execute the algorithm.
Definition: CaloThinCellsByClusterAlg.cxx:38
ReadHandle.h
Handle class for reading from StoreGate.
IdentifierHash
Definition: IdentifierHash.h:38
CaloThinCellsByClusterAlg::m_validSamplings
std::vector< int > m_validSamplings
Decoded list of samplings.
Definition: CaloThinCellsByClusterAlg.h:78
CaloThinCellsByClusterAlg::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: CaloThinCellsByClusterAlg.h:75