ATLAS Offline Software
TileCellsMuonDecorator.cxx
Go to the documentation of this file.
1 
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
12 #include "TileCellsMuonDecorator.h"
13 
14 // Athena
16 #include "StoreGate/ReadHandle.h"
18 #include "CaloGeoHelpers/proxim.h"
19 #include "xAODMuon/MuonContainer.h"
20 
21 #include <string>
22 #include <vector>
23 #include <algorithm>
24 
25 namespace DerivationFramework {
26 
28 
29  ATH_CHECK(m_trackInCalo.retrieve());
30  ATH_CHECK(m_tracksInCone.retrieve());
31  ATH_CHECK(m_cellsDecorator.retrieve());
32 
36 
37  const std::string baseName = m_muonContainerKey.key() + ".";
38 
39  m_selectedMuKey = baseName + m_prefix + m_selectedMuKey.key();
40  ATH_CHECK( m_selectedMuKey.initialize() );
41 
42  m_econeMuKey = baseName + m_prefix + m_econeMuKey.key() + std::to_string(int(m_isoCone * 100));
43  ATH_CHECK( m_econeMuKey.initialize() );
44 
45  m_cellsMuonXKey = baseName + m_prefix + m_cellsMuonXKey.key();
46  ATH_CHECK( m_cellsMuonXKey.initialize() );
47 
48  m_cellsMuonYKey = baseName + m_prefix + m_cellsMuonYKey.key();
49  ATH_CHECK( m_cellsMuonYKey.initialize() );
50 
51  m_cellsMuonZKey = baseName + m_prefix + m_cellsMuonZKey.key();
52  ATH_CHECK( m_cellsMuonZKey.initialize() );
53 
54  m_cellsMuonEtaKey = baseName + m_prefix + m_cellsMuonEtaKey.key();
55  ATH_CHECK( m_cellsMuonEtaKey.initialize() );
56 
57  m_cellsMuonPhiKey = baseName + m_prefix + m_cellsMuonPhiKey.key();
58  ATH_CHECK( m_cellsMuonPhiKey.initialize() );
59 
60  m_cellsToMuonDxKey = baseName + m_prefix + m_cellsToMuonDxKey.key();
61  ATH_CHECK( m_cellsToMuonDxKey.initialize() );
62 
63  m_cellsToMuonDyKey = baseName + m_prefix + m_cellsToMuonDyKey.key();
64  ATH_CHECK( m_cellsToMuonDyKey.initialize() );
65 
66  m_cellsToMuonDzKey = baseName + m_prefix + m_cellsToMuonDzKey.key();
67  ATH_CHECK( m_cellsToMuonDzKey.initialize() );
68 
70  ATH_CHECK( m_cellsToMuonDetaKey.initialize() );
71 
73  ATH_CHECK( m_cellsToMuonDphiKey.initialize() );
74 
75  m_cellsMuonDxKey = baseName + m_prefix + m_cellsMuonDxKey.key();
76  ATH_CHECK( m_cellsMuonDxKey.initialize() );
77 
78  m_cellsMuonDeDxKey = baseName + m_prefix + m_cellsMuonDeDxKey.key();
79  ATH_CHECK( m_cellsMuonDeDxKey.initialize() );
80 
82  for (double dr : m_drCones) {
83  m_larEnergyInConeKeyArray.emplace_back(baseName + m_prefix + "elarcone" + std::to_string(int(dr * 100)));
84  }
85  }
87 
88  for (unsigned int layer : m_energyInLayers) {
90  }
91 
92  return StatusCode::SUCCESS;
93  }
94 
95  StatusCode TileCellsMuonDecorator::addBranches(const EventContext& ctx) const {
96 
97 
99  ATH_CHECK( muons.isValid() );
100 
101  const CaloCellContainer* cellContainer = nullptr;
102  if (!m_cellContainerKey.empty()) {
104  ATH_CHECK( caloCells.isValid() );
105  cellContainer = caloCells.cptr();
106  }
107 
108  const xAOD::CaloClusterContainer* clusterContainer = nullptr;
109  if (!m_clusterContainerKey.empty()) {
111  ATH_CHECK( caloClusters.isValid() );
112  clusterContainer = caloClusters.cptr();
113  }
114 
129  std::vector<SG::WriteDecorHandle<xAOD::MuonContainer, float>> larEnergyInCones;
131  larEnergyInCones.emplace_back(key, ctx);
132  }
133 
134  std::map<const xAOD::IParticle*, std::vector<const CaloCell*>> muonCellsMap;
135 
136  for ( const xAOD::Muon* mu : *muons ) {
137 
138  std::vector<const CaloCell*> cells;
139 
140  std::vector< float > cells_mu_x;
141  std::vector< float > cells_mu_y;
142  std::vector< float > cells_mu_z;
143  std::vector< float > cells_mu_eta;
144  std::vector< float > cells_mu_phi;
145 
146  std::vector< float > cells_to_mu_dx;
147  std::vector< float > cells_to_mu_dy;
148  std::vector< float > cells_to_mu_dz;
149  std::vector< float > cells_to_mu_deta;
150  std::vector< float > cells_to_mu_dphi;
151 
152  std::vector< float > cells_mu_dx;
153  std::vector< float > cells_mu_dedx;
154  std::vector< float > lar_energy_in_cones;
155 
156  if (m_selectMuons &&
157  (mu->muonType() != xAOD::Muon::Combined
158  || mu->pt() < m_minPt
159  || std::abs(mu->eta()) > m_maxAbsEta)) {
160 
161  selected_mu(*mu) = 0;
162  continue;
163  }
164 
165  const xAOD::TrackParticle* mu_track = mu->trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
166  const xAOD::CaloCluster* mu_cluster = mu->cluster();
167  if (mu_track && mu_cluster && mu_cluster->getCellLinks()) {
168 
169  float e_trk_in_isocone(0.0);
170  std::vector<const xAOD::TrackParticle*> tracks_in_cone;
171  m_tracksInCone->particlesInCone(mu_track->eta(), mu_track->phi(), m_isoCone, tracks_in_cone);
172  for (const xAOD::TrackParticle* track : tracks_in_cone) {
173  if (track != mu_track) e_trk_in_isocone += track->e();
174  }
175 
176  econe_mu(*mu) = e_trk_in_isocone;
177 
178  if (m_selectMuons && (e_trk_in_isocone > m_maxRelEtrkInIsoCone * mu_track->e())) {
179  selected_mu(*mu) = 0;
180  continue;
181  }
182 
183  selected_mu(*mu) = 1;
184 
185  cells.clear();
186  bool addAdditionalGapCrackCells = false;
187  for (const CaloCell* cell : *mu_cluster) {
188  const CaloDetDescrElement* cell_dde = cell->caloDDE();
189  if ((cell_dde->is_tile())) {
190  if (cellContainer && (cell_dde->getSampling() == CaloCell_ID::TileGap3)) {
191  addAdditionalGapCrackCells = true;
192  continue;
193  }
194  cells.push_back(cell);
195  }
196  }
197 
198  if (addAdditionalGapCrackCells) {
199  std::vector<double> coordinates = m_trackInCalo->getXYZEtaPhiInCellSampling(mu_track, CaloCell_ID::TileGap3);
200  if (coordinates.size() == 5 ) {
201  double eta = coordinates[3];
202  double phi = coordinates[4];
203  for (const CaloCell* cell : *cellContainer) {
204  const CaloDetDescrElement* cell_dde = cell->caloDDE();
205  if (cell_dde->getSampling() == CaloCell_ID::TileGap3) {
206  if (std::fabs(eta - cell->eta()) < m_gapCrackCellsInDeltaEta
207  && std::fabs(KinematicUtils::deltaPhi(phi, cell->phi())) < m_gapCrackCellsInDeltaPhi) {
208  cells.push_back(cell);
209  }
210  }
211  }
212  }
213  }
214 
215  for (const CaloCell* cell : cells) {
216 
217  std::vector<double> coordinates = m_trackInCalo->getXYZEtaPhiInCellSampling(mu_track, cell);
218 
219  if (coordinates.size() == 5 ) {
220 
221  float path_length = m_trackInCalo->getPathInsideCell(mu_track, cell);
222  cells_mu_dx.push_back( path_length );
223  cells_mu_dedx.push_back( (path_length > 0 ? (cell->energy() / path_length) : -1.0) );
224 
225  cells_mu_x.push_back(coordinates[0]);
226  cells_mu_y.push_back(coordinates[1]);
227  cells_mu_z.push_back(coordinates[2]);
228  cells_mu_eta.push_back(coordinates[3]);
229  cells_mu_phi.push_back(coordinates[4]);
230 
231  cells_to_mu_dx.push_back(cell->x() - coordinates[0]);
232  cells_to_mu_dy.push_back(cell->y() - coordinates[1]);
233  cells_to_mu_dz.push_back(cell->z() - coordinates[2]);
234  cells_to_mu_deta.push_back(cell->eta() - coordinates[3]);
235  cells_to_mu_dphi.push_back( KinematicUtils::deltaPhi(coordinates[4], cell->phi()) );
236 
237  } else {
238 
239  cells_mu_dx.push_back( 0.0 );
240  cells_mu_dedx.push_back( -2.0 );
241 
242  cells_mu_x.push_back(0.0);
243  cells_mu_y.push_back(0.0);
244  cells_mu_z.push_back(0.0);
245  cells_mu_eta.push_back(0.0);
246  cells_mu_phi.push_back(0.0);
247 
248  cells_to_mu_dx.push_back(0.0);
249  cells_to_mu_dy.push_back(0.0);
250  cells_to_mu_dz.push_back(0.0);
251  cells_to_mu_deta.push_back(0.0);
252  cells_to_mu_dphi.push_back(0.0);
253 
254  }
255  }
256 
257  muonCellsMap[mu] = cells;
258 
259  if (clusterContainer) {
260  lar_energy_in_cones = m_trackInCalo->getEnergyInCones(mu_track, clusterContainer, m_energyInSamplings, m_drCones, ctx);
261  }
262 
263  } else {
264  selected_mu(*mu) = 0;
265  }
266 
267  cellsMuonX(*mu) = std::move(cells_mu_x);
268  cellsMuonY(*mu) = std::move(cells_mu_y);
269  cellsMuonZ(*mu) = std::move(cells_mu_z);
270  cellsMuonEta(*mu) = std::move(cells_mu_eta);
271  cellsMuonPhi(*mu) = std::move(cells_mu_phi);
272  cellsToMuonDx(*mu) = std::move(cells_to_mu_dx);
273  cellsToMuonDy(*mu) = std::move(cells_to_mu_dy);
274  cellsToMuonDz(*mu) = std::move(cells_to_mu_dz);
275  cellsToMuonDeta(*mu) = std::move(cells_to_mu_deta);
276  cellsToMuonDphi(*mu) = std::move(cells_to_mu_dphi);
277  cellsMuonDx(*mu) = std::move(cells_mu_dx);
278  cellsMuonDeDx(*mu) = std::move(cells_mu_dedx);
279 
280  for (unsigned int icone = 0; icone < larEnergyInCones.size(); ++icone) {
281  larEnergyInCones[icone](*mu) = std::move(lar_energy_in_cones[icone]);
282  }
283 
284  }
285 
286  ATH_CHECK( m_cellsDecorator->decorate(muonCellsMap, ctx) );
287 
288  return StatusCode::SUCCESS;
289  }
290 
291 }
DerivationFramework::TileCellsMuonDecorator::m_cellsMuonPhiKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsMuonPhiKey
Definition: TileCellsMuonDecorator.h:81
DerivationFramework::TileCellsMuonDecorator::m_cellsDecorator
ToolHandle< DerivationFramework::TileCellsDecorator > m_cellsDecorator
Definition: TileCellsMuonDecorator.h:100
SG::WriteDecorHandleKey
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Definition: StoreGate/StoreGate/WriteDecorHandleKey.h:89
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:281
DerivationFramework::TileCellsMuonDecorator::m_cellContainerKey
SG::ReadHandleKey< CaloCellContainer > m_cellContainerKey
Definition: TileCellsMuonDecorator.h:71
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
DerivationFramework::TileCellsMuonDecorator::m_selectedMuKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_selectedMuKey
Definition: TileCellsMuonDecorator.h:74
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
xAOD::TrackParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TrackParticle_v1.cxx:79
DerivationFramework::TileCellsMuonDecorator::m_cellsMuonDeDxKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsMuonDeDxKey
Definition: TileCellsMuonDecorator.h:90
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
DerivationFramework::TileCellsMuonDecorator::m_cellsMuonZKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsMuonZKey
Definition: TileCellsMuonDecorator.h:79
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:111
DerivationFramework::TileCellsMuonDecorator::m_clusterContainerKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterContainerKey
Definition: TileCellsMuonDecorator.h:72
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
MuonR4::to_string
std::string to_string(const SectorProjector proj)
Definition: MsTrackSeeder.cxx:66
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
DerivationFramework::TileCellsMuonDecorator::initialize
virtual StatusCode initialize() override final
Definition: TileCellsMuonDecorator.cxx:27
DerivationFramework::TileCellsMuonDecorator::m_muonContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muonContainerKey
Definition: TileCellsMuonDecorator.h:70
CaloCell_ID_FCS::TileGap3
@ TileGap3
Definition: FastCaloSim_CaloCell_ID.h:36
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
DerivationFramework::TileCellsMuonDecorator::m_trackInCalo
ToolHandle< TileCal::ITrackTools > m_trackInCalo
Definition: TileCellsMuonDecorator.h:94
DerivationFramework::TileCellsMuonDecorator::m_prefix
Gaudi::Property< std::string > m_prefix
Definition: TileCellsMuonDecorator.h:57
DerivationFramework::TileCellsMuonDecorator::m_tracksInCone
ToolHandle< xAOD::ITrackParticlesInConeTool > m_tracksInCone
Definition: TileCellsMuonDecorator.h:97
DerivationFramework::TileCellsMuonDecorator::m_energyInLayers
Gaudi::Property< std::set< unsigned int > > m_energyInLayers
Definition: TileCellsMuonDecorator.h:64
proxim.h
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
DerivationFramework::TileCellsMuonDecorator::m_cellsToMuonDyKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsToMuonDyKey
Definition: TileCellsMuonDecorator.h:84
DerivationFramework::TileCellsMuonDecorator::m_gapCrackCellsInDeltaPhi
Gaudi::Property< double > m_gapCrackCellsInDeltaPhi
Definition: TileCellsMuonDecorator.h:68
DerivationFramework::TileCellsMuonDecorator::m_cellsToMuonDphiKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsToMuonDphiKey
Definition: TileCellsMuonDecorator.h:87
DerivationFramework::TileCellsMuonDecorator::m_cellsToMuonDetaKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsToMuonDetaKey
Definition: TileCellsMuonDecorator.h:86
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
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
DerivationFramework::TileCellsMuonDecorator::m_isoCone
Gaudi::Property< double > m_isoCone
Definition: TileCellsMuonDecorator.h:61
DerivationFramework::TileCellsMuonDecorator::m_selectMuons
Gaudi::Property< bool > m_selectMuons
Definition: TileCellsMuonDecorator.h:58
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework::TileCellsMuonDecorator::m_cellsMuonDxKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsMuonDxKey
Definition: TileCellsMuonDecorator.h:89
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
DerivationFramework::TileCellsMuonDecorator::m_gapCrackCellsInDeltaEta
Gaudi::Property< double > m_gapCrackCellsInDeltaEta
Definition: TileCellsMuonDecorator.h:67
xAOD::CaloCluster_v1::getCellLinks
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
Definition: CaloCluster_v1.cxx:829
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
DerivationFramework::TileCellsMuonDecorator::m_drCones
Gaudi::Property< std::vector< double > > m_drCones
Definition: TileCellsMuonDecorator.h:62
KinematicUtils::deltaPhi
double deltaPhi(double phi1, double phi2)
Definition: D3PDMaker/TileD3PDMaker/src/ITrackTools.h:104
Trk::Combined
@ Combined
Definition: TrackSummaryTool.h:32
DerivationFramework::TileCellsMuonDecorator::m_maxRelEtrkInIsoCone
Gaudi::Property< double > m_maxRelEtrkInIsoCone
Definition: TileCellsMuonDecorator.h:66
CaloDetDescrElement::is_tile
bool is_tile() const
cell belongs to Tile
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:442
DerivationFramework::TileCellsMuonDecorator::m_minPt
Gaudi::Property< double > m_minPt
Definition: TileCellsMuonDecorator.h:59
DerivationFramework::TileCellsMuonDecorator::m_econeMuKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_econeMuKey
Definition: TileCellsMuonDecorator.h:75
errorcheck.h
Helpers for checking error return status codes and reporting errors.
DerivationFramework::TileCellsMuonDecorator::m_cellsToMuonDxKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsToMuonDxKey
Definition: TileCellsMuonDecorator.h:83
DerivationFramework::TileCellsMuonDecorator::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition: TileCellsMuonDecorator.cxx:95
xAOD::TrackParticle_v1::e
virtual double e() const override final
The total energy of the particle.
Definition: TrackParticle_v1.cxx:111
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
MuonContainer.h
DerivationFramework::TileCellsMuonDecorator::m_larEnergyInConeKeyArray
SG::WriteDecorHandleKeyArray< xAOD::MuonContainer > m_larEnergyInConeKeyArray
Definition: TileCellsMuonDecorator.h:91
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
CaloDetDescrElement::getSampling
CaloCell_ID::CaloSample getSampling() const
cell sampling
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:395
DerivationFramework::TileCellsMuonDecorator::m_cellsToMuonDzKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsToMuonDzKey
Definition: TileCellsMuonDecorator.h:85
DerivationFramework::TileCellsMuonDecorator::m_energyInSamplings
std::set< xAOD::CaloCluster::CaloSample > m_energyInSamplings
Definition: TileCellsMuonDecorator.h:103
DerivationFramework::TileCellsMuonDecorator::m_maxAbsEta
Gaudi::Property< double > m_maxAbsEta
Definition: TileCellsMuonDecorator.h:60
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:44
ReadHandle.h
Handle class for reading from StoreGate.
TileCellsMuonDecorator.h
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:51
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:27
xAOD::TrackParticle_v1::phi
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .)
DerivationFramework::TileCellsMuonDecorator::m_cellsMuonYKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsMuonYKey
Definition: TileCellsMuonDecorator.h:78
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
DerivationFramework::TileCellsMuonDecorator::m_cellsMuonEtaKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsMuonEtaKey
Definition: TileCellsMuonDecorator.h:80
DerivationFramework::TileCellsMuonDecorator::m_cellsMuonXKey
SG::WriteDecorHandleKey< xAOD::MuonContainer > m_cellsMuonXKey
Definition: TileCellsMuonDecorator.h:77