ATLAS Offline Software
PrepDataToSimHitAssocAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
5 
6 #include "StoreGate/ReadHandle.h"
14 namespace MuonR4{
15  template <class ContainerType>
18  const ContainerType*& contToPush) const {
19  contToPush = nullptr;
20  if (key.empty()) {
21  ATH_MSG_VERBOSE("No key has been parsed for object "<< typeid(ContainerType).name());
22  return StatusCode::SUCCESS;
23  }
24  SG::ReadHandle readHandle{key, ctx};
25  ATH_CHECK(readHandle.isPresent());
26  contToPush = readHandle.cptr();
27  return StatusCode::SUCCESS;
28  }
29 
31  ATH_CHECK(m_simHitsKey.initialize());
33  ATH_CHECK(m_decorKey.initialize());
34  ATH_CHECK(m_idHelperSvc.retrieve());
36  return StatusCode::SUCCESS;
37  }
38  StatusCode PrepDataToSimHitAssocAlg::execute(const EventContext & ctx) const {
39  const ActsGeometryContext* gctx{nullptr};
40  const xAOD::MuonSimHitContainer* simHits{nullptr};
41  const xAOD::UncalibratedMeasurementContainer* measurements{nullptr};
44  ATH_CHECK(retrieveContainer(ctx, m_prdHitKey, measurements));
45 
46 
49  for (const xAOD::UncalibratedMeasurement* measurement : *measurements){
51  const xAOD::MuonSimHit* bestSimHit{nullptr};
52 
53  switch (measurement->type()) {
56  const Identifier prdId{xAOD::identify(measurement)};
58  std::ranges::find_if(*simHits,[&prdId](const xAOD::MuonSimHit* hit){
59  return hit->identify() == prdId;
60  });
61  if (mdt_matching != simHits->end()){
62  bestSimHit =(*mdt_matching);
63  }
64  break;
65  }
71 
72  const Identifier prdId{xAOD::identify(measurement)};
73  const MuonGMR4::MuonReadoutElement* readOutEle = xAOD::readoutElement(measurement);
74  const Amg::Transform3D& locToGlob{readOutEle->localToGlobalTrans(*gctx, readOutEle->layerHash(prdId))};
75 
76  const Identifier gasGapId = m_idHelperSvc->gasGapId(prdId);
79  if (measurement->numDimensions() == 1) {
80  locPos = measurement->localPosition<1>().x() * Amg::Vector3D::UnitX();
81  } else {
82  locPos.block<2,1>(0,0) = xAOD::toEigen(measurement->localPosition<2>());
83  }
84  double closestDistance{m_PullCutOff};
85 
87  xAOD::ChamberViewer chambViewer{*simHits, m_idHelperSvc.get(),
89 
90  if (!chambViewer.loadView(gasGapId)) {
91  break;
92  }
93  for ( const xAOD::MuonSimHit* simHit : chambViewer) {
94  if (gasGapId != m_idHelperSvc->gasGapId(simHit->identify())) {
95  continue;
96  }
97  const IdentifierHash simLayHash{readOutEle->layerHash(simHit->identify())};
98  const Amg::Transform3D globToLoc{readOutEle->globalToLocalTrans(*gctx, simLayHash) *locToGlob};
100  const Amg::Vector3D prdPos = globToLoc * locPos;
102  double dist{0.};
103  if (measurement->numDimensions() == 1) {
104  dist = std::abs(prdPos.x() - simHit->localPosition().x())
105  / std::sqrt(measurement->localCovariance<1>()(0,0));
106  } else{
107  const Amg::Vector2D diff = (prdPos - xAOD::toEigen(simHit->localPosition())).block<2,1>(0,0);
108  dist = std::sqrt(diff.dot(xAOD::toEigen(measurement->localCovariance<2>()).inverse() * diff));
109  }
110  if (dist < closestDistance) {
111  closestDistance = dist;
112  bestSimHit = simHit;
113  }
114  }
115  break;
116  } default: {
117  ATH_MSG_FATAL("Non muon measurement is parsed");
118  return StatusCode::FAILURE;
119  }
120  }
121  if (!bestSimHit) {
122  continue;
123  }
124  decorHandle(*measurement) = LinkType{*simHits, bestSimHit->index()};
125  }
126  return StatusCode::SUCCESS;
127  }
128 }
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:61
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
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MuonR4::PrepDataToSimHitAssocAlg::initialize
StatusCode initialize() override final
Definition: PrepDataToSimHitAssocAlg.cxx:30
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
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey< ContainerType >
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:43
MuonR4::PrepDataToSimHitAssocAlg::execute
StatusCode execute(const EventContext &ctx) const override final
Definition: PrepDataToSimHitAssocAlg.cxx:38
xAOD::ChamberViewer
Definition: ChamberViewer.h:65
MuonR4::PrepDataToSimHitAssocAlg::m_geoCtxKey
SG::ReadHandleKey< ActsGeometryContext > m_geoCtxKey
Key to the geometry context.
Definition: PrepDataToSimHitAssocAlg.h:47
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:40
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:45
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::readoutElement
const MuonGMR4::MuonReadoutElement * readoutElement(const UncalibratedMeasurement *meas)
Returns the associated readout element to the measurement.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:42
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:49
MuonR4::PrepDataToSimHitAssocAlg::m_simHitsKey
SG::ReadHandleKey< xAOD::MuonSimHitContainer > m_simHitsKey
Key to the associated simHit container.
Definition: PrepDataToSimHitAssocAlg.h:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
sTgcMeasurement.h
MuonR4::PrepDataToSimHitAssocAlg::retrieveContainer
StatusCode retrieveContainer(const EventContext &ctx, const SG::ReadHandleKey< ContainerType > &key, const ContainerType *&contToPush) const
Helper method to retrieve any kind of container from a ReadHandleKey.
Definition: PrepDataToSimHitAssocAlg.cxx:16
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
ReadHandle.h
Handle class for reading from StoreGate.
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::UncalibMeasType::RpcStripType
@ RpcStripType
xAOD::UncalibMeasType::MdtDriftCircleType
@ MdtDriftCircleType
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
Identifier
Definition: IdentifierFieldParser.cxx:14