ATLAS Offline Software
xAODSimHitToMdtMeasCnvAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
11 #include <StoreGate/ReadHandle.h>
13 #include <StoreGate/WriteHandle.h>
14 #include <CLHEP/Random/RandGaussZiggurat.h>
15 // Random Numbers
17 namespace{
18  static constexpr double timeToTdcCnv = 1./ IMdtCalibrationTool::tdcBinSize;
19 }
21  ISvcLocator* pSvcLocator):
22  AthReentrantAlgorithm{name, pSvcLocator} {}
23 
25  ATH_CHECK(m_readKey.initialize());
26  ATH_CHECK(m_writeKey.initialize());
27  ATH_CHECK(m_idHelperSvc.retrieve());
30  return StatusCode::SUCCESS;
31 }
32 StatusCode xAODSimHitToMdtMeasCnvAlg::execute(const EventContext& ctx) const {
34  if (!simHitContainer.isPresent()){
35  ATH_MSG_FATAL("Failed to retrieve "<<m_readKey.fullKey());
36  return StatusCode::FAILURE;
37  }
38 
40  if (!mdtCalibData.isValid()) {
41  ATH_MSG_FATAL("Failed to retrieve calibration data "<<m_calibDbKey.fullKey());
42  return StatusCode::FAILURE;
43  }
44 
46  ATH_CHECK(prdContainer.record(std::make_unique<xAOD::MdtDriftCircleContainer>(),
47  std::make_unique<xAOD::MdtDriftCircleAuxContainer>()));
48 
49  const MdtIdHelper& id_helper{m_idHelperSvc->mdtIdHelper()};
50  CLHEP::HepRandomEngine* rndEngine = getRandomEngine(ctx);
51  for (const xAOD::MuonSimHit* simHit : *simHitContainer) {
52  const Identifier hitId = simHit->identify();
53  // ignore radiation for now
54  if (std::abs(simHit->pdgId()) != 13) continue;
55 
56 
58  prdContainer->push_back(prd);
59  prd->setIdentifier(hitId.get_compact());
60  prd->setIdentifierHash(m_idHelperSvc->detElementHash(hitId));
61  prd->setLayer(id_helper.tubeLayer(hitId));
62  prd->setTube(id_helper.tube(hitId));
64  const MuonGMR4::MdtReadoutElement* readOutEle = m_DetMgr->getMdtReadoutElement(hitId);
65  prd->setReadoutElement(readOutEle);
66 
68  bool bound{false};
69  const MuonCalib::MdtFullCalibData* tubeContants = mdtCalibData->getCalibData(hitId, msgStream());
70  const MuonCalib::MdtTubeCalibContainer::SingleTubeCalib& tubeCalib{*tubeContants->tubeCalib->getCalib(hitId)};
71  const Amg::Vector3D lHitPos{xAOD::toEigen(simHit->localPosition())};
73  const double driftTime = tubeContants->rtRelation->tr()->tFromR(lHitPos.perp(), bound);
74  const double resol = tubeContants->rtRelation->rtRes()->resolution(driftTime);
75  // Smear the hit using the best known uncertainties
76  const double targetRadius = std::clamp(1.*CLHEP::RandGaussZiggurat::shoot(rndEngine, lHitPos.perp(), resol),
77  0., readOutEle->innerTubeRadius());
78 
80  const double sigPropTime = tubeCalib.inversePropSpeed*std::abs(0.5*readOutEle->getParameters().readoutSide*readOutEle->activeTubeLength(prd->measurementHash()) - lHitPos.z());
83  const double tdcTime = targetRadius * targetRadius + sigPropTime;
84  prd->setDriftRadius(std::sqrt(tdcTime));
85  prd->setDriftRadCov(resol*resol);
89  const uint16_t tdcCounts = (tdcTime + simHit->globalTime()) * timeToTdcCnv* (m_idHelperSvc->hasHPTDC(hitId) ? 4. : 1.);
90  prd->setTdc(tdcCounts);
91 
92  }
93  return StatusCode::SUCCESS;
94 }
95 
96 CLHEP::HepRandomEngine* xAODSimHitToMdtMeasCnvAlg::getRandomEngine(const EventContext& ctx) const {
97  ATHRNG::RNGWrapper* rngWrapper = m_rndmSvc->getEngine(this, m_streamName);
98  std::string rngName = name() + m_streamName;
99  rngWrapper->setSeed(rngName, ctx);
100  return rngWrapper->getEngine(ctx);
101 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ATHRNG::RNGWrapper::setSeed
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition: RNGWrapper.h:169
xAOD::MuonSimHit_v1
Definition: MuonSimHit_v1.h:18
xAOD::MdtDriftCircle_v1::setTdc
void setTdc(int16_t tdc)
Setter methods.
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAODSimHitToMdtMeasCnvAlg::xAODSimHitToMdtMeasCnvAlg
xAODSimHitToMdtMeasCnvAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: xAODSimHitToMdtMeasCnvAlg.cxx:20
xAODSimHitToMdtMeasCnvAlg::m_writeKey
SG::WriteHandleKey< xAOD::MdtDriftCircleContainer > m_writeKey
Definition: xAODSimHitToMdtMeasCnvAlg.h:44
xAOD::MdtDriftCircle_v1::measurementHash
IdentifierHash measurementHash() const
Returns the hash of the measurement channel (tube (x) layer)
Definition: MdtDriftCircle_v1.cxx:28
MuonCalib::MdtFullCalibData::rtRelation
RtRelationPtr rtRelation
Definition: MdtFullCalibData.h:21
MuonGMR4::MdtReadoutElement::activeTubeLength
double activeTubeLength(const IdentifierHash &hash) const
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MdtReadoutElement.cxx:179
xAODSimHitToMdtMeasCnvAlg::m_rndmSvc
ServiceHandle< IAthRNGSvc > m_rndmSvc
Definition: xAODSimHitToMdtMeasCnvAlg.h:52
bound
@ bound
Definition: L1CaloPprPlotManager.h:74
MdtDriftCircleAuxContainer.h
MuonCalib::MdtFullCalibData
class which holds the full set of calibration constants for a given tube
Definition: MdtFullCalibData.h:15
xAODSimHitToMdtMeasCnvAlg::getRandomEngine
CLHEP::HepRandomEngine * getRandomEngine(const EventContext &ctx) const
Definition: xAODSimHitToMdtMeasCnvAlg.cxx:96
ReadCondHandle.h
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
MuonGMR4::MdtReadoutElement::parameterBook::readoutSide
double readoutSide
Is the readout chip at positive or negative Z?
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:62
xAODSimHitToMdtMeasCnvAlg::m_calibDbKey
SG::ReadCondHandleKey< MuonCalib::MdtCalibDataContainer > m_calibDbKey
Definition: xAODSimHitToMdtMeasCnvAlg.h:55
WriteHandle.h
Handle class for recording to StoreGate.
xAOD::UncalibratedMeasurement_v1::setIdentifier
void setIdentifier(const DetectorIdentType measId)
Sets the full Identifier of the measurement.
xAODSimHitToMdtMeasCnvAlg::m_DetMgr
const MuonGMR4::MuonDetectorManager * m_DetMgr
Access to the new readout geometry.
Definition: xAODSimHitToMdtMeasCnvAlg.h:48
xAOD::MdtDriftCircle
MdtDriftCircle_v1 MdtDriftCircle
Defined the version of the MdtDriftCircle.
Definition: MdtDriftCircle.h:12
xAODSimHitToMdtMeasCnvAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: xAODSimHitToMdtMeasCnvAlg.h:50
MuonCalib::MdtFullCalibData::tubeCalib
TubeContainerPtr tubeCalib
Definition: MdtFullCalibData.h:22
TRT::Hit::driftTime
@ driftTime
Definition: HitInfo.h:43
xAOD::UncalibratedMeasurement_v1::setIdentifierHash
void setIdentifierHash(const DetectorIDHashType idHash)
Sets the IdentifierHash of the measurement (corresponds to the detector element IdentifierHash)
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAODSimHitToMdtMeasCnvAlg.h
MdtIdHelper
Definition: MdtIdHelper.h:61
MuonChamber.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAODSimHitToMdtMeasCnvAlg::initialize
StatusCode initialize() override
Definition: xAODSimHitToMdtMeasCnvAlg.cxx:24
MuonGMR4::MdtReadoutElement::innerTubeRadius
double innerTubeRadius() const
Returns the inner tube radius.
MdtCalibHit.h
MuonGMR4::MdtReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:19
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition: RNGWrapper.h:56
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
ATHRNG::RNGWrapper::getEngine
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition: RNGWrapper.h:134
RNGWrapper.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
xAOD::MdtDriftCircle_v1::setReadoutElement
void setReadoutElement(const MuonGMR4::MdtReadoutElement *readoutEle)
set the pointer to the MdtReadoutElement
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
MdtReadoutElement.h
xAOD::MdtDriftCircle_v1::setLayer
void setLayer(uint8_t layer_n)
Sets the layer number.
xAODSimHitToMdtMeasCnvAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: xAODSimHitToMdtMeasCnvAlg.cxx:32
MuonCalib::MdtTubeCalibContainer::SingleTubeCalib
Definition: MdtTubeCalibContainer.h:18
xAODSimHitToMdtMeasCnvAlg::m_readKey
SG::ReadHandleKey< xAOD::MuonSimHitContainer > m_readKey
Definition: xAODSimHitToMdtMeasCnvAlg.h:41
MuonGMR4::MdtReadoutElement::getParameters
const parameterBook & getParameters() const
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MdtReadoutElement.cxx:44
xAODSimHitToMdtMeasCnvAlg::m_streamName
Gaudi::Property< std::string > m_streamName
Definition: xAODSimHitToMdtMeasCnvAlg.h:53
ReadHandle.h
Handle class for reading from StoreGate.
xAOD::MdtDriftCircle_v1
https://gitlab.cern.ch/atlas/athena/-/blob/master/MuonSpectrometer/MuonReconstruction/MuonRecEvent/Mu...
Definition: MdtDriftCircle_v1.h:18
IMdtCalibrationTool::tdcBinSize
static constexpr double tdcBinSize
Conversion to go from tdc counts -> drift Time.
Definition: IMdtCalibrationTool.h:34
xAOD::MdtDriftCircle_v1::setDriftRadCov
void setDriftRadCov(float cov)
Sets the covariance on the drift circle.
Definition: MdtDriftCircle_v1.cxx:46
xAOD::MdtDriftCircle_v1::setDriftRadius
void setDriftRadius(float r)
Sets the drift radius of the drift circle.
Definition: MdtDriftCircle_v1.cxx:43
xAOD::MdtDriftCircle_v1::setTube
void setTube(uint16_t tube_n)
Sets the tube number.