ATLAS Offline Software
Loading...
Searching...
No Matches
CaloThinCellsByClusterAlg.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
3 */
10
11
16
17
22{
23 ATH_CHECK( m_cells.initialize (m_streamName) );
24 ATH_CHECK( m_clusters.initialize() );
25 ATH_CHECK(m_caloMgrKey.initialize());
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
41StatusCode 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
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}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Thin calorimeter cells not associated with clusters.
Handle class for reading from StoreGate.
Handle for requesting thinning for a data object.
void select(double eta, double phi, double deta, double dphi)
int ncells() const
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
This class provides the client interface for accessing the detector description information common to...
static CaloSample getSampling(const std::string &name)
Return the sampling code for a given name.
std::vector< int > m_validSamplings
Decoded list of samplings.
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusters
Clusters to read.
SG::ThinningHandleKey< CaloClusterCellLinkContainer > m_clusterCellLinks
Calo Cell links for the clusters we keep cells for.
SG::ThinningHandleKey< CaloCellContainer > m_cells
Cell container to thin.
StringProperty m_streamName
Name of the stream being thinned.
virtual StatusCode initialize() override
Gaudi initialize method.
StatusCode decodeSamplings()
Decode the provided list of calorimeter samplings.
virtual StatusCode execute(const EventContext &ctx) const override
Execute the algorithm.
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
This is a "hash" representation of an Identifier.
void keepAll()
Mark that all elements should be kept (not thinned).
Handle for requesting thinning for a data object.
Definition index.py:1
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.