ATLAS Offline Software
xAODSimHitToMmMeasCnvAlg.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 
10 #include <StoreGate/ReadHandle.h>
12 #include <StoreGate/WriteHandle.h>
13 #include <CLHEP/Random/RandGaussZiggurat.h>
14 // Random Numbers
16 #include <MuonCondData/Defs.h>
17 #include <GaudiKernel/SystemOfUnits.h>
18 
20  ISvcLocator* pSvcLocator):
21  AthReentrantAlgorithm{name, pSvcLocator} {}
22 
24  ATH_CHECK(m_readKey.initialize());
25  ATH_CHECK(m_writeKey.initialize());
26  ATH_CHECK(m_idHelperSvc.retrieve());
29  return StatusCode::SUCCESS;
30 }
32  std::stringstream statstr{};
33  unsigned allHits{0};
34  for (unsigned int g = 0; g < m_allHits.size(); ++g) {
35  allHits += m_allHits[g];
36  statstr<<" *** Layer "<<(g+1)<<" "<<(100.* m_acceptedHits[g] / std::max(1u*m_allHits[g], 1u))
37  <<"% of "<<m_allHits[g]<<std::endl;
38  }
39  if(!allHits) return StatusCode::SUCCESS;
40  ATH_MSG_INFO("Tried to convert "<<allHits<<" hits. Successes rate per layer "<<std::endl<<statstr.str());
41  return StatusCode::SUCCESS;
42 }
43 
44 
45 StatusCode xAODSimHitToMmMeasCnvAlg::execute(const EventContext& ctx) const {
47  if (!simHitContainer.isPresent()){
48  ATH_MSG_FATAL("Failed to retrieve "<<m_readKey.fullKey());
49  return StatusCode::FAILURE;
50  }
51 
53  if (!errorCalibDB.isValid()) {
54  ATH_MSG_FATAL("Failed to retrieve the parameterized errors "<<m_uncertCalibKey.fullKey());
55  return StatusCode::FAILURE;
56  }
57 
59  ATH_CHECK(prdContainer.record(std::make_unique<xAOD::MMClusterContainer>(),
60  std::make_unique<xAOD::MMClusterAuxContainer>()));
61 
62  const MmIdHelper& id_helper{m_idHelperSvc->mmIdHelper()};
63  CLHEP::HepRandomEngine* rndEngine = getRandomEngine(ctx);
64 
65  for(const xAOD::MuonSimHit* simHit : *simHitContainer){
66  const Identifier hitId = simHit->identify();
67  //ignore radiation for now
68  if(std::abs(simHit->pdgId())!=13) continue;
70  const unsigned int hitGapInNsw = (id_helper.multilayer(hitId) -1) * 4 + id_helper.gasGap(hitId) -1;
71  ++m_allHits[hitGapInNsw];
72 
73 
74  const MuonGMR4::MmReadoutElement* readOutEle = m_DetMgr->getMmReadoutElement(hitId);
75  const MuonGMR4::StripDesign& design{readOutEle->stripLayer(hitId).design()};
76  bool isValid{false};
77 
78  const Amg::Vector3D lHitPos{xAOD::toEigen(simHit->localPosition())};
79 
80  int channelNumber = design.stripNumber(lHitPos.block<2,1>(0,0));
81  if(channelNumber<0){
82  if (!design.insideTrapezoid(lHitPos.block<2,1>(0,0))) {
83  ATH_MSG_WARNING("Hit "<<m_idHelperSvc->toString(hitId)<<" "<<Amg::toString(lHitPos)
84  <<" is outside bounds "<<std::endl<<design<<" rejecting it");
85  }
86  continue;
87  }
88  const Identifier clusId = id_helper.channelID(hitId,
89  id_helper.multilayer(hitId),
90  id_helper.gasGap(hitId),
91  channelNumber, isValid);
92  if(!isValid) {
93  ATH_MSG_WARNING("Invalid strip identifier for layer " << m_idHelperSvc->toString(hitId) << " channel " << channelNumber
94  << " lHitPos " << Amg::toString(lHitPos));
95  continue;
96  }
97  ++m_acceptedHits[hitGapInNsw];
98  xAOD::MMCluster* prd = new xAOD::MMCluster();
99  prdContainer->push_back(prd);
100 
101  prd->setChannelNumber(channelNumber);
102  prd->setGasGap(id_helper.gasGap(clusId));
103  prd->setIdentifier(clusId.get_compact());
104 
105  NswErrorCalibData::Input errorCalibInput{};
106  errorCalibInput.stripId = clusId;
107  errorCalibInput.locTheta = M_PI- simHit->localDirection().theta();
108  errorCalibInput.clusterAuthor=66; // cluster time projection method
109  double uncert = errorCalibDB->clusterUncertainty(errorCalibInput);
110  ATH_MSG_VERBOSE("mm hit has theta " << errorCalibInput.locTheta / Gaudi::Units::deg << " and uncertainty " << uncert);
111 
112  double newLocalX = CLHEP::RandGaussZiggurat::shoot(rndEngine, lHitPos.x(), uncert);
113  xAOD::MeasVector<1> lClusterPos{newLocalX};
114  xAOD::MeasMatrix<1> lCov{uncert*uncert};
115  prd->setMeasurement(m_idHelperSvc->detElementHash(clusId) ,lClusterPos, lCov);
116  }
117 
118  return StatusCode::SUCCESS;
119 
120 }
121 
122 
123 
124 
125 CLHEP::HepRandomEngine* xAODSimHitToMmMeasCnvAlg::getRandomEngine(const EventContext& ctx) const {
126  ATHRNG::RNGWrapper* rngWrapper = m_rndmSvc->getEngine(this, m_streamName);
127  std::string rngName = name() + m_streamName;
128  rngWrapper->setSeed(rngName, ctx);
129  return rngWrapper->getEngine(ctx);
130 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAODSimHitToMmMeasCnvAlg::finalize
StatusCode finalize() override final
Definition: xAODSimHitToMmMeasCnvAlg.cxx:31
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
MuonGMR4::MmReadoutElement
Definition: MmReadoutElement.h:20
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
MuonGMR4::StripDesign
Definition: StripDesign.h:30
xAODSimHitToMmMeasCnvAlg::getRandomEngine
CLHEP::HepRandomEngine * getRandomEngine(const EventContext &ctx) const
Definition: xAODSimHitToMmMeasCnvAlg.cxx:125
xAODSimHitToMmMeasCnvAlg.h
xAODSimHitToMmMeasCnvAlg::m_rndmSvc
ServiceHandle< IAthRNGSvc > m_rndmSvc
Definition: xAODSimHitToMmMeasCnvAlg.h:54
max
#define max(a, b)
Definition: cfImp.cxx:41
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::MMCluster_v1
Definition: MMCluster_v1.h:16
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAODSimHitToMmMeasCnvAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: xAODSimHitToMmMeasCnvAlg.h:52
M_PI
#define M_PI
Definition: ActiveFraction.h:11
deg
#define deg
Definition: SbPolyhedron.cxx:17
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:214
xAODSimHitToMmMeasCnvAlg::m_uncertCalibKey
SG::ReadCondHandleKey< NswErrorCalibData > m_uncertCalibKey
Definition: xAODSimHitToMmMeasCnvAlg.h:57
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
ReadCondHandle.h
xAODSimHitToMmMeasCnvAlg::m_readKey
SG::ReadHandleKey< xAOD::MuonSimHitContainer > m_readKey
Definition: xAODSimHitToMmMeasCnvAlg.h:43
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
xAOD::MMCluster_v1::setGasGap
void setGasGap(uint8_t gap)
WriteHandle.h
Handle class for recording to StoreGate.
xAOD::UncalibratedMeasurement_v1::setIdentifier
void setIdentifier(const DetectorIdentType measId)
Sets the full Identifier of the measurement.
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
MMClusterAuxContainer.h
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAODSimHitToMmMeasCnvAlg::m_writeKey
SG::WriteHandleKey< xAOD::MMClusterContainer > m_writeKey
Definition: xAODSimHitToMmMeasCnvAlg.h:46
xAODSimHitToMmMeasCnvAlg::m_DetMgr
const MuonGMR4::MuonDetectorManager * m_DetMgr
Access to the new readout geometry.
Definition: xAODSimHitToMmMeasCnvAlg.h:50
MuonChamber.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::MeasVector
Eigen::Matrix< float, N, 1 > MeasVector
Abrivation of the Matrix & Covariance definitions.
Definition: MeasurementDefs.h:52
NswErrorCalibData::Input::stripId
Identifier stripId
Identifier of the strip.
Definition: NswErrorCalibData.h:27
MuonGMR4::MmReadoutElement::stripLayer
const StripLayer & stripLayer(const Identifier &measId) const
Defs.h
xAODSimHitToMmMeasCnvAlg::initialize
StatusCode initialize() override final
Definition: xAODSimHitToMmMeasCnvAlg.cxx:23
xAOD::MMCluster
MMCluster_v1 MMCluster
Defined the version of the MMCluster.
Definition: MMCluster.h:12
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
xAODSimHitToMmMeasCnvAlg::xAODSimHitToMmMeasCnvAlg
xAODSimHitToMmMeasCnvAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: xAODSimHitToMmMeasCnvAlg.cxx:19
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
xAODSimHitToMmMeasCnvAlg::m_streamName
Gaudi::Property< std::string > m_streamName
Definition: xAODSimHitToMmMeasCnvAlg.h:55
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
MuonGMR4::StripLayer::design
const StripDesign & design() const
Returns the underlying strip design.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
xAOD::UncalibratedMeasurement_v1::setMeasurement
void setMeasurement(const DetectorIDHashType idHash, MeasVector< N > locPos, MeasMatrix< N > locCov)
Sets IdentifierHash, local position and local covariance of the measurement.
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
MmIdHelper
Definition: MmIdHelper.h:54
xAODSimHitToMmMeasCnvAlg::execute
StatusCode execute(const EventContext &ctx) const override final
Definition: xAODSimHitToMmMeasCnvAlg.cxx:45
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::MeasMatrix
Eigen::Matrix< float, N, N > MeasMatrix
Definition: MeasurementDefs.h:54
NswErrorCalibData::Input
Helper struct to be parsed to the object to derive the specific error of the cluster.
Definition: NswErrorCalibData.h:25
ReadHandle.h
Handle class for reading from StoreGate.
xAOD::MMCluster_v1::setChannelNumber
void setChannelNumber(uint16_t strip)
MmReadoutElement.h