ATLAS Offline Software
Loading...
Searching...
No Matches
TileCellsMuonDecorator.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5*/
6
7// TileCellsMuonDecorator.cxx
8// Implementation file for class TileCellsMuonDecorator
10
11// Tile includes
13
14// Athena
20
21#include <string>
22#include <vector>
23#include <algorithm>
24
25namespace DerivationFramework {
26
28
29 ATH_CHECK(m_trackInCalo.retrieve());
30 ATH_CHECK(m_tracksInCone.retrieve());
31 ATH_CHECK(m_cellsDecorator.retrieve());
32
33 ATH_CHECK( m_muonContainerKey.initialize() );
36
37 ATH_CHECK( m_selectedMuKey.initialize() );
38 ATH_CHECK( m_econeMuKey.initialize() );
39 ATH_CHECK( m_cellsMuonXKey.initialize() );
40 ATH_CHECK( m_cellsMuonYKey.initialize() );
41 ATH_CHECK( m_cellsMuonZKey.initialize() );
42 ATH_CHECK( m_cellsMuonEtaKey.initialize() );
43 ATH_CHECK( m_cellsMuonPhiKey.initialize() );
44 ATH_CHECK( m_cellsToMuonDxKey.initialize() );
45 ATH_CHECK( m_cellsToMuonDyKey.initialize() );
46 ATH_CHECK( m_cellsToMuonDzKey.initialize() );
47 ATH_CHECK( m_cellsToMuonDetaKey.initialize() );
48 ATH_CHECK( m_cellsToMuonDphiKey.initialize() );
49 ATH_CHECK( m_cellsMuonDxKey.initialize() );
50 ATH_CHECK( m_cellsMuonDeDxKey.initialize() );
52
53 for (unsigned int layer : m_energyInLayers) {
54 m_energyInSamplings.emplace(static_cast<xAOD::CaloCluster::CaloSample>(layer));
55 }
56
57 return StatusCode::SUCCESS;
58 }
59
60 StatusCode TileCellsMuonDecorator::addBranches(const EventContext& ctx) const {
61
62
64 ATH_CHECK( muons.isValid() );
65
66 const CaloCellContainer* cellContainer = nullptr;
67 if (!m_cellContainerKey.empty()) {
69 ATH_CHECK( caloCells.isValid() );
70 cellContainer = caloCells.cptr();
71 }
72
73 const xAOD::CaloClusterContainer* clusterContainer = nullptr;
74 if (!m_clusterContainerKey.empty()) {
76 ATH_CHECK( caloClusters.isValid() );
77 clusterContainer = caloClusters.cptr();
78 }
79
94 std::vector<SG::WriteDecorHandle<xAOD::MuonContainer, float>> larEnergyInCones;
96 larEnergyInCones.emplace_back(key, ctx);
97 }
98
99 std::map<const xAOD::IParticle*, std::vector<const CaloCell*>> muonCellsMap;
100
101 for ( const xAOD::Muon* mu : *muons ) {
102
103 std::vector<const CaloCell*> cells;
104
105 std::vector< float > cells_mu_x;
106 std::vector< float > cells_mu_y;
107 std::vector< float > cells_mu_z;
108 std::vector< float > cells_mu_eta;
109 std::vector< float > cells_mu_phi;
110
111 std::vector< float > cells_to_mu_dx;
112 std::vector< float > cells_to_mu_dy;
113 std::vector< float > cells_to_mu_dz;
114 std::vector< float > cells_to_mu_deta;
115 std::vector< float > cells_to_mu_dphi;
116
117 std::vector< float > cells_mu_dx;
118 std::vector< float > cells_mu_dedx;
119 std::vector< float > lar_energy_in_cones;
120
121 if (m_selectMuons &&
122 (mu->muonType() != xAOD::Muon::Combined
123 || mu->pt() < m_minPt
124 || std::abs(mu->eta()) > m_maxAbsEta)) {
125
126 selected_mu(*mu) = 0;
127 continue;
128 }
129
130 const xAOD::TrackParticle* mu_track = mu->trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
131 const xAOD::CaloCluster* mu_cluster = mu->cluster();
132 if (mu_track && mu_cluster && mu_cluster->getCellLinks()) {
133
134 float e_trk_in_isocone(0.0);
135 std::vector<const xAOD::TrackParticle*> tracks_in_cone;
136 m_tracksInCone->particlesInCone(mu_track->eta(), mu_track->phi(), m_isoCone, tracks_in_cone);
137 for (const xAOD::TrackParticle* track : tracks_in_cone) {
138 if (track != mu_track) e_trk_in_isocone += track->e();
139 }
140
141 econe_mu(*mu) = e_trk_in_isocone;
142
143 if (m_selectMuons && (e_trk_in_isocone > m_maxRelEtrkInIsoCone * mu_track->e())) {
144 selected_mu(*mu) = 0;
145 continue;
146 }
147
148 selected_mu(*mu) = 1;
149
150 cells.clear();
151 bool addAdditionalGapCrackCells = false;
152 for (const CaloCell* cell : *mu_cluster) {
153 const CaloDetDescrElement* cell_dde = cell->caloDDE();
154 if ((cell_dde->is_tile())) {
155 if (cellContainer && (cell_dde->getSampling() == CaloCell_ID::TileGap3)) {
156 addAdditionalGapCrackCells = true;
157 continue;
158 }
159 cells.push_back(cell);
160 }
161 }
162
163 if (addAdditionalGapCrackCells) {
164 std::vector<double> coordinates = m_trackInCalo->getXYZEtaPhiInCellSampling(mu_track, CaloCell_ID::TileGap3);
165 if (coordinates.size() == 5 ) {
166 double eta = coordinates[3];
167 double phi = coordinates[4];
168 for (const CaloCell* cell : *cellContainer) {
169 const CaloDetDescrElement* cell_dde = cell->caloDDE();
170 if (cell_dde->getSampling() == CaloCell_ID::TileGap3) {
171 if (std::fabs(eta - cell->eta()) < m_gapCrackCellsInDeltaEta
172 && std::fabs(KinematicUtils::deltaPhi(phi, cell->phi())) < m_gapCrackCellsInDeltaPhi) {
173 cells.push_back(cell);
174 }
175 }
176 }
177 }
178 }
179
180 for (const CaloCell* cell : cells) {
181
182 std::vector<double> coordinates = m_trackInCalo->getXYZEtaPhiInCellSampling(mu_track, cell);
183
184 if (coordinates.size() == 5 ) {
185
186 float path_length = m_trackInCalo->getPathInsideCell(mu_track, cell);
187 cells_mu_dx.push_back( path_length );
188 cells_mu_dedx.push_back( (path_length > 0 ? (cell->energy() / path_length) : -1.0) );
189
190 cells_mu_x.push_back(coordinates[0]);
191 cells_mu_y.push_back(coordinates[1]);
192 cells_mu_z.push_back(coordinates[2]);
193 cells_mu_eta.push_back(coordinates[3]);
194 cells_mu_phi.push_back(coordinates[4]);
195
196 cells_to_mu_dx.push_back(cell->x() - coordinates[0]);
197 cells_to_mu_dy.push_back(cell->y() - coordinates[1]);
198 cells_to_mu_dz.push_back(cell->z() - coordinates[2]);
199 cells_to_mu_deta.push_back(cell->eta() - coordinates[3]);
200 cells_to_mu_dphi.push_back( KinematicUtils::deltaPhi(coordinates[4], cell->phi()) );
201
202 } else {
203
204 cells_mu_dx.push_back( 0.0 );
205 cells_mu_dedx.push_back( -2.0 );
206
207 cells_mu_x.push_back(0.0);
208 cells_mu_y.push_back(0.0);
209 cells_mu_z.push_back(0.0);
210 cells_mu_eta.push_back(0.0);
211 cells_mu_phi.push_back(0.0);
212
213 cells_to_mu_dx.push_back(0.0);
214 cells_to_mu_dy.push_back(0.0);
215 cells_to_mu_dz.push_back(0.0);
216 cells_to_mu_deta.push_back(0.0);
217 cells_to_mu_dphi.push_back(0.0);
218
219 }
220 }
221
222 muonCellsMap[mu] = cells;
223
224 if (clusterContainer) {
225 lar_energy_in_cones = m_trackInCalo->getEnergyInCones(mu_track, clusterContainer, m_energyInSamplings, m_drCones, ctx);
226 }
227
228 } else {
229 selected_mu(*mu) = 0;
230 }
231
232 cellsMuonX(*mu) = std::move(cells_mu_x);
233 cellsMuonY(*mu) = std::move(cells_mu_y);
234 cellsMuonZ(*mu) = std::move(cells_mu_z);
235 cellsMuonEta(*mu) = std::move(cells_mu_eta);
236 cellsMuonPhi(*mu) = std::move(cells_mu_phi);
237 cellsToMuonDx(*mu) = std::move(cells_to_mu_dx);
238 cellsToMuonDy(*mu) = std::move(cells_to_mu_dy);
239 cellsToMuonDz(*mu) = std::move(cells_to_mu_dz);
240 cellsToMuonDeta(*mu) = std::move(cells_to_mu_deta);
241 cellsToMuonDphi(*mu) = std::move(cells_to_mu_dphi);
242 cellsMuonDx(*mu) = std::move(cells_mu_dx);
243 cellsMuonDeDx(*mu) = std::move(cells_mu_dedx);
244
245 if (!larEnergyInCones.empty() && lar_energy_in_cones.empty()) {
246 lar_energy_in_cones.resize(larEnergyInCones.size(), 0.F);
247 }
248
249 for (unsigned int icone = 0; icone < larEnergyInCones.size(); ++icone) {
250 larEnergyInCones[icone](*mu) = lar_energy_in_cones[icone];
251 }
252
253 }
254
255 ATH_CHECK( m_cellsDecorator->decorate(muonCellsMap, ctx) );
256
257 return StatusCode::SUCCESS;
258 }
259
260}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
Helpers for checking error return status codes and reporting errors.
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
Container class for CaloCell.
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
This class groups all DetDescr information related to a CaloCell.
CaloCell_ID::CaloSample getSampling() const
cell sampling
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsMuonDxKey
ToolHandle< DerivationFramework::TileCellsDecorator > m_cellsDecorator
SG::WriteDecorHandleKeyArray< xAOD::MuonContainer > m_larEnergyInConeKeyArray
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsMuonZKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsMuonPhiKey
ToolHandle< TileCal::ITrackTools > m_trackInCalo
ToolHandle< xAOD::ITrackParticlesInConeTool > m_tracksInCone
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsToMuonDetaKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsMuonDeDxKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsToMuonDyKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_econeMuKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsMuonXKey
Gaudi::Property< std::set< unsigned int > > m_energyInLayers
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsToMuonDphiKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsMuonYKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsToMuonDzKey
virtual StatusCode initialize() override final
virtual StatusCode addBranches(const EventContext &ctx) const override final
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_selectedMuKey
std::set< xAOD::CaloCluster::CaloSample > m_energyInSamplings
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsMuonEtaKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterContainerKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsToMuonDxKey
Gaudi::Property< std::vector< double > > m_drCones
SG::ReadHandleKey< xAOD::MuonContainer > m_muonContainerKey
SG::ReadHandleKey< CaloCellContainer > m_cellContainerKey
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Handle class for adding a decoration to an object.
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
CaloSampling::CaloSample CaloSample
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .)
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
virtual double e() const override final
The total energy of the particle.
THE reconstruction tool.
double deltaPhi(double phi1, double phi2)
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Muon_v1 Muon
Reference the current persistent version:
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.