ATLAS Offline Software
PrepDataToSimHitAssocAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
5 
13 namespace MuonR4{
15  ATH_CHECK(m_simHitsKey.initialize());
16  ATH_CHECK(m_prdHitKey.initialize());
17  ATH_CHECK(m_decorKey.initialize());
18  ATH_CHECK(m_idHelperSvc.retrieve());
20  return StatusCode::SUCCESS;
21  }
22  StatusCode PrepDataToSimHitAssocAlg::execute(const EventContext & ctx) const {
23  const ActsGeometryContext* gctx{nullptr};
24  const xAOD::MuonSimHitContainer* simHits{nullptr};
25  const xAOD::UncalibratedMeasurementContainer* measurements{nullptr};
26  ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
27  ATH_CHECK(SG::get(simHits, m_simHitsKey, ctx));
28  ATH_CHECK(SG::get(measurements, m_prdHitKey, ctx));
29 
30 
33  for (const xAOD::UncalibratedMeasurement* measurement : *measurements){
35  const xAOD::MuonSimHit* bestSimHit{nullptr};
36 
37  switch (measurement->type()) {
40  const Identifier prdId{xAOD::identify(measurement)};
42  std::ranges::find_if(*simHits,[&prdId](const xAOD::MuonSimHit* hit){
43  return hit->identify() == prdId;
44  });
45  if (mdt_matching != simHits->end()){
46  bestSimHit =(*mdt_matching);
47  }
48  break;
49  }
55 
56  const Identifier prdId{xAOD::identify(measurement)};
57  const MuonGMR4::MuonReadoutElement* readOutEle = xAOD::muonReadoutElement(measurement);
58  const Amg::Transform3D& locToGlob{readOutEle->localToGlobalTrans(*gctx, readOutEle->layerHash(prdId))};
59 
60  const Identifier gasGapId = m_idHelperSvc->gasGapId(prdId);
63  if (measurement->numDimensions() == 1) {
64  locPos = measurement->localPosition<1>().x() * Amg::Vector3D::UnitX();
65  } else {
66  locPos.block<2,1>(0,0) = xAOD::toEigen(measurement->localPosition<2>());
67  }
68  double closestDistance{m_PullCutOff};
69 
71  xAOD::ChamberViewer chambViewer{*simHits, m_idHelperSvc.get(),
73 
74  if (!chambViewer.loadView(gasGapId)) {
75  break;
76  }
77  for ( const xAOD::MuonSimHit* simHit : chambViewer) {
78  if (gasGapId != m_idHelperSvc->gasGapId(simHit->identify())) {
79  continue;
80  }
81  const IdentifierHash simLayHash{readOutEle->layerHash(simHit->identify())};
82  const Amg::Transform3D globToLoc{readOutEle->globalToLocalTrans(*gctx, simLayHash) *locToGlob};
84  const Amg::Vector3D prdPos = globToLoc * locPos;
86  double dist{0.};
87  if (measurement->numDimensions() == 1) {
88  dist = std::abs(prdPos.x() - simHit->localPosition().x())
89  / std::sqrt(measurement->localCovariance<1>()(0,0));
90  } else{
91  const Amg::Vector2D diff = (prdPos - xAOD::toEigen(simHit->localPosition())).block<2,1>(0,0);
92  dist = std::sqrt(diff.dot(xAOD::toEigen(measurement->localCovariance<2>()).inverse() * diff));
93  }
94  if (dist < closestDistance) {
95  closestDistance = dist;
96  bestSimHit = simHit;
97  }
98  }
99  break;
100  } default: {
101  ATH_MSG_FATAL("Non muon measurement is parsed");
102  return StatusCode::FAILURE;
103  }
104  }
105  if (!bestSimHit) {
106  continue;
107  }
108  decorHandle(*measurement) = LinkType{*simHits, bestSimHit->index()};
109  }
110  return StatusCode::SUCCESS;
111  }
112 }
xAOD::MuonSimHit_v1
Definition: MuonSimHit_v1.h:18
xAOD::identify
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:82
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
UtilFunctions.h
xAOD::MuonSimHit_v1::identify
Identifier identify() const
Returns the global ATLAS identifier of the SimHit.
Definition: xAODMuonSimHit_V1.cxx:42
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
MuonR4::PrepDataToSimHitAssocAlg::initialize
StatusCode initialize() override final
Definition: PrepDataToSimHitAssocAlg.cxx:14
xAOD::UncalibMeasType::MMClusterType
@ MMClusterType
MuonGMR4::MuonReadoutElement
The MuonReadoutElement is an abstract class representing the geometry representing the muon detector.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonReadoutElement.h:38
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
MuonGMR4::MuonReadoutElement::globalToLocalTrans
Amg::Transform3D globalToLocalTrans(const ActsGeometryContext &ctx) const
Transformations to translate between local <-> global coordinates.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:78
MuonGMR4::MuonReadoutElement::layerHash
virtual IdentifierHash layerHash(const Identifier &measId) const =0
xAOD::UncalibMeasType::sTgcStripType
@ sTgcStripType
x
#define x
xAOD::ChamberView::Mode::DetElement
@ DetElement
View ends if the detElementHash changes.
xAOD::UncalibMeasType::TgcStripType
@ TgcStripType
MuonR4::PrepDataToSimHitAssocAlg::m_decorKey
SG::WriteDecorHandleKey< xAOD::UncalibratedMeasurementContainer > m_decorKey
Definition: PrepDataToSimHitAssocAlg.h:35
MuonR4::PrepDataToSimHitAssocAlg::execute
StatusCode execute(const EventContext &ctx) const override final
Definition: PrepDataToSimHitAssocAlg.cxx:22
xAOD::ChamberViewer
Definition: ChamberViewer.h:65
MuonR4::PrepDataToSimHitAssocAlg::m_geoCtxKey
SG::ReadHandleKey< ActsGeometryContext > m_geoCtxKey
Key to the geometry context.
Definition: PrepDataToSimHitAssocAlg.h:39
xAOD::UncalibratedMeasurement_v1
Definition: UncalibratedMeasurement_v1.h:13
MuonR4::PrepDataToSimHitAssocAlg::m_prdHitKey
SG::ReadHandleKey< xAOD::UncalibratedMeasurementContainer > m_prdHitKey
Key to the uncalibrated measurements to decorate.
Definition: PrepDataToSimHitAssocAlg.h:32
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition: ReadCondHandle.h:287
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
WriteDecorHandle.h
Handle class for adding a decoration to an object.
MuonR4::PrepDataToSimHitAssocAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
IdHelperSvc to decode the Identifiers.
Definition: PrepDataToSimHitAssocAlg.h:37
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
TgcStrip.h
MuonR4::PrepDataToSimHitAssocAlg::m_PullCutOff
Gaudi::Property< double > m_PullCutOff
The number of standard deviations a measurement may be pulled apart in order to be associated.
Definition: PrepDataToSimHitAssocAlg.h:41
MuonR4::PrepDataToSimHitAssocAlg::m_simHitsKey
SG::ReadHandleKey< xAOD::MuonSimHitContainer > m_simHitsKey
Key to the associated simHit container.
Definition: PrepDataToSimHitAssocAlg.h:30
sTgcMeasurement.h
RpcMeasurement.h
ChamberViewer.h
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
MuonGMR4::MuonReadoutElement::localToGlobalTrans
const Amg::Transform3D & localToGlobalTrans(const ActsGeometryContext &ctx) const
Returns the local to global transformation into the ATLAS coordinate system.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:81
PrepDataToSimHitAssocAlg.h
MMCluster.h
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
xAOD::muonReadoutElement
const MuonGMR4::MuonReadoutElement * muonReadoutElement(const UncalibratedMeasurement *meas)
Returns the associated readout element to the measurement.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:40
xAOD::UncalibMeasType::RpcStripType
@ RpcStripType
xAOD::UncalibMeasType::MdtDriftCircleType
@ MdtDriftCircleType
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
Identifier
Definition: IdentifierFieldParser.cxx:14