ATLAS Offline Software
xAODSimHitTosTGCMeasCnvAlg.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 
9 
13 #include <StoreGate/ReadHandle.h>
15 #include <StoreGate/WriteHandle.h>
16 #include <CLHEP/Random/RandGaussZiggurat.h>
17 // Random Numbers
19 #include <MuonCondData/Defs.h>
20 #include <GaudiKernel/SystemOfUnits.h>
23  ISvcLocator* pSvcLocator):
24  AthReentrantAlgorithm{name, pSvcLocator} {}
25 
27  ATH_CHECK(m_readKey.initialize());
29  ATH_CHECK(m_writeKeyStrip.initialize());
30  ATH_CHECK(m_writeKeyPad.initialize());
31  ATH_CHECK(m_writeKeyWire.initialize());
32  ATH_CHECK(m_rndmSvc.retrieve());
33  ATH_CHECK(m_idHelperSvc.retrieve());
36  return StatusCode::SUCCESS;
37 }
38 
39 
40 void xAODSimHitTosTGCMeasCnvAlg::digitizeStrip(const EventContext& ctx,
41  const xAOD::MuonSimHit& simHit,
42  xAOD::sTgcStripContainer& prdContainer,
43  CLHEP::HepRandomEngine* rndEngine) const {
44 
45 
46  const sTgcIdHelper& id_helper{m_idHelperSvc->stgcIdHelper()};
47  const Identifier hitId{simHit.identify()};
48  const MuonGMR4::sTgcReadoutElement* readOutEle = m_DetMgr->getsTgcReadoutElement(hitId);
49 
50  const Amg::Vector3D lHitPos{xAOD::toEigen(simHit.localPosition())};
51 
52  int channelNumber = readOutEle->stripDesign(hitId).stripNumber(lHitPos.block<2,1>(0,0));
53  if(channelNumber==-1){
54  ATH_MSG_WARNING("Strip hit "<<Amg::toString(lHitPos)<<" is outside bounds "<<
55  readOutEle->stripDesign(hitId)<<" rejecting it");
56  return;
57  }
58  bool isValid{false};
59  const Identifier stripId = id_helper.channelID(hitId,
60  id_helper.multilayer(hitId),
61  id_helper.gasGap(hitId),
62  sTgcIdHelper::sTgcChannelTypes::Strip,
63  channelNumber,
64  isValid);
65  if(!isValid) {
66  ATH_MSG_WARNING("Invalid strip identifier for layer " << m_idHelperSvc->toString(hitId)
67  << " channel " << channelNumber << " lHitPos " << Amg::toString(lHitPos));
68  return;
69  }
70  NswErrorCalibData::Input errorCalibInput{};
71  errorCalibInput.stripId= stripId;
72  errorCalibInput.locTheta = M_PI - simHit.localDirection().theta();
73  errorCalibInput.clusterAuthor = 3; // centroid
74 
76  double uncert = errorCalibDB->clusterUncertainty(errorCalibInput);
77 
78  xAOD::sTgcStripCluster* prd = prdContainer.push_back(new xAOD::sTgcStripCluster());
79  prd->setIdentifier(stripId.get_compact());
80 
81  ATH_MSG_VERBOSE ("stgc hit has theta " << errorCalibInput.locTheta / Gaudi::Units::deg << " and uncertainty " << uncert);
82 
83  const double newLocalX = CLHEP::RandGaussZiggurat::shoot(rndEngine, lHitPos.x(), uncert);
84  xAOD::MeasVector<1> lClusterPos{newLocalX};
85  xAOD::MeasMatrix<1> lCov{uncert*uncert};
86  prd->setMeasurement(readOutEle->identHash() ,lClusterPos, lCov);
87  prd->setChannelNumber(channelNumber);
88  prd->setGasGap(id_helper.gasGap(hitId));
89  prd->setReadoutElement(readOutEle);
90 }
91 
92 void xAODSimHitTosTGCMeasCnvAlg::digitizeWire(const EventContext& ctx,
93  const xAOD::MuonSimHit& simHit,
94  xAOD::sTgcWireContainer& prdContainer,
95  CLHEP::HepRandomEngine* rndEngine) const {
96 
97  const sTgcIdHelper& id_helper{m_idHelperSvc->stgcIdHelper()};
98  const Identifier hitId{simHit.identify()};
99  const MuonGMR4::sTgcReadoutElement* readOutEle = m_DetMgr->getsTgcReadoutElement(hitId);
100 
101  const IdentifierHash stripHash{MuonGMR4::sTgcReadoutElement::createHash(id_helper.gasGap(hitId),
102  sTgcIdHelper::sTgcChannelTypes::Strip, 0)};
103 
104  const IdentifierHash wireHash{MuonGMR4::sTgcReadoutElement::createHash(id_helper.gasGap(hitId),
105  sTgcIdHelper::sTgcChannelTypes::Wire, 0)};
106 
108  const Amg::Transform3D layerRot{readOutEle->globalToLocalTrans(*gctx, wireHash) *
109  readOutEle->localToGlobalTrans(*gctx, stripHash)};
110  const Amg::Vector3D lHitPos{layerRot*xAOD::toEigen(simHit.localPosition())};
111 
112  const MuonGMR4::WireGroupDesign& design{readOutEle->wireDesign(hitId)};
113  int channelNumber = design.stripNumber(lHitPos.block<2,1>(0,0));
114  if(channelNumber==-1){
115  ATH_MSG_WARNING("Wire hit "<<Amg::toString(lHitPos)<<" is outside bounds "<<design<<" rejecting it");
116  return;
117  }
118  bool isValid{false};
119  const Identifier wireId = id_helper.channelID(hitId,
120  id_helper.multilayer(hitId),
121  id_helper.gasGap(hitId),
122  sTgcIdHelper::sTgcChannelTypes::Wire,
123  channelNumber,
124  isValid);
125  if(!isValid) {
126  ATH_MSG_WARNING("Invalid wire identifier for layer " << m_idHelperSvc->toString(hitId)
127  << " channel " << channelNumber << " lHitPos " << Amg::toString(lHitPos));
128  return;
129  }
130  const double wireUncert = design.numWiresInGroup(channelNumber) * design.stripPitch() / std::sqrt(12);
131  const double newLocalX = CLHEP::RandGaussZiggurat::shoot(rndEngine, lHitPos.x(), wireUncert);
132 
133  xAOD::sTgcWireHit* prd = prdContainer.push_back(new xAOD::sTgcWireHit());
134  prd->setIdentifier(wireId.get_compact());
135  xAOD::MeasVector<1> lClusterPos{newLocalX};
136  xAOD::MeasMatrix<1> lCov{wireUncert*wireUncert};
137  prd->setMeasurement(readOutEle->identHash() ,lClusterPos, lCov);
138  prd->setChannelNumber(channelNumber);
139  prd->setGasGap(id_helper.gasGap(hitId));
140  prd->setReadoutElement(readOutEle);
141 }
142 
143 
144 void xAODSimHitTosTGCMeasCnvAlg::digitizePad(const EventContext& ctx,
145  const xAOD::MuonSimHit& simHit,
146  xAOD::sTgcPadContainer& prdContainer) const {
147 
148  const sTgcIdHelper& id_helper{m_idHelperSvc->stgcIdHelper()};
149  const Identifier hitId{simHit.identify()};
150  const MuonGMR4::sTgcReadoutElement* readOutEle = m_DetMgr->getsTgcReadoutElement(hitId);
151 
152  const IdentifierHash stripHash{MuonGMR4::sTgcReadoutElement::createHash(id_helper.gasGap(hitId),
153  sTgcIdHelper::sTgcChannelTypes::Strip, 0)};
154 
155  const IdentifierHash padHash{MuonGMR4::sTgcReadoutElement::createHash(id_helper.gasGap(hitId),
156  sTgcIdHelper::sTgcChannelTypes::Pad, 0)};
157 
159  const Amg::Transform3D layerRot{readOutEle->globalToLocalTrans(*gctx, padHash) *
160  readOutEle->localToGlobalTrans(*gctx, stripHash)};
161 
162  const Amg::Vector3D lHitPos{layerRot*xAOD::toEigen(simHit.localPosition())};
163 
165  // const MuonGMR4::PadDesign& design{readOutEle->padDesign(hitId)};
166 
167  xAOD::sTgcPadHit* prd = prdContainer.push_back(new xAOD::sTgcPadHit());
168  prd->setIdentifier(hitId.get_compact());
169  prd->setGasGap(id_helper.gasGap(hitId));
170  prd->setReadoutElement(readOutEle);
171  AmgSymMatrix(2) cov{AmgSymMatrix(2)::Identity()};
172  Amg::Vector2D lPos{lHitPos.block<2,1>(0,0)};
173  prd->setMeasurement(readOutEle->identHash(), xAOD::toStorage(lPos), xAOD::toStorage(cov));
174 
175 
176 }
177 
178 
179 StatusCode xAODSimHitTosTGCMeasCnvAlg::execute(const EventContext& ctx) const {
181  if (!simHitContainer.isPresent()){
182  ATH_MSG_FATAL("Failed to retrieve "<<m_readKey.fullKey());
183  return StatusCode::FAILURE;
184  }
185 
187  if (!errorCalibDB.isValid()) {
188  ATH_MSG_FATAL("Failed to retrieve the parameterized errors "<<m_uncertCalibKey.fullKey());
189  return StatusCode::FAILURE;
190  }
191 
193  ATH_CHECK(stripContainer.record(std::make_unique<xAOD::sTgcStripContainer>(),
194  std::make_unique<xAOD::sTgcStripAuxContainer>()));
195 
197  ATH_CHECK(wireContainer.record(std::make_unique<xAOD::sTgcWireContainer>(),
198  std::make_unique<xAOD::sTgcWireAuxContainer>()));
199 
201  ATH_CHECK(padContainer.record(std::make_unique<xAOD::sTgcPadContainer>(),
202  std::make_unique<xAOD::sTgcPadAuxContainer>()));
203 
204 
205 
206  CLHEP::HepRandomEngine* rndEngine = getRandomEngine(ctx);
207 
208  for(const xAOD::MuonSimHit* simHit : *simHitContainer){
209  //ignore radiation for now
210  if(std::abs(simHit->pdgId())!=13) continue;
211  digitizeStrip(ctx, *simHit, *stripContainer, rndEngine);
212 
213 
214 
215  }
216 
217  return StatusCode::SUCCESS;
218 
219 }
220 CLHEP::HepRandomEngine* xAODSimHitTosTGCMeasCnvAlg::getRandomEngine(const EventContext& ctx) const {
221  ATHRNG::RNGWrapper* rngWrapper = m_rndmSvc->getEngine(this, m_streamName);
222  std::string rngName = name() + m_streamName;
223  rngWrapper->setSeed(rngName, ctx);
224  return rngWrapper->getEngine(ctx);
225 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAODSimHitTosTGCMeasCnvAlg::m_streamName
Gaudi::Property< std::string > m_streamName
Definition: xAODSimHitTosTGCMeasCnvAlg.h:78
xAOD::sTgcMeasurement_v1::setReadoutElement
void setReadoutElement(const MuonGMR4::sTgcReadoutElement *readoutEle)
set the pointer to the sTgcReadoutElement
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
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
MuonGMR4::StripDesign::stripNumber
virtual int stripNumber(const Amg::Vector2D &pos) const
Calculates the number of the strip whose center is closest to the given point.
xAODSimHitTosTGCMeasCnvAlg::m_uncertCalibKey
SG::ReadCondHandleKey< NswErrorCalibData > m_uncertCalibKey
Definition: xAODSimHitTosTGCMeasCnvAlg.h:80
xAOD::sTgcStripCluster_v1
Definition: sTgcStripCluster_v1.h:12
MuonGMR4::WireGroupDesign
Definition: WireGroupDesign.h:23
xAOD::MuonSimHit_v1::identify
Identifier identify() const
Returns the global ATLAS identifier of the SimHit.
Definition: xAODMuonSimHit_V1.cxx:42
xAODSimHitTosTGCMeasCnvAlg::m_writeKeyWire
SG::WriteHandleKey< xAOD::sTgcWireContainer > m_writeKeyWire
Definition: xAODSimHitTosTGCMeasCnvAlg.h:66
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
xAODSimHitTosTGCMeasCnvAlg::xAODSimHitTosTGCMeasCnvAlg
xAODSimHitTosTGCMeasCnvAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: xAODSimHitTosTGCMeasCnvAlg.cxx:22
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MuonGMR4::sTgcReadoutElement::stripDesign
const StripDesign & stripDesign(const Identifier &measId) const
Retrieves the readoutElement Layer given the Identifier/Hash.
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:201
M_PI
#define M_PI
Definition: ActiveFraction.h:11
deg
#define deg
Definition: SbPolyhedron.cxx:17
xAOD::toStorage
MeasVector< N > toStorage(const AmgVector(N)&amgVec)
Converts the double precision of the AmgVector into the floating point storage precision of the MeasV...
Definition: MeasurementDefs.h:68
xAODSimHitTosTGCMeasCnvAlg::digitizeWire
void digitizeWire(const EventContext &ctx, const xAOD::MuonSimHit &simHit, xAOD::sTgcWireContainer &wireContainer, CLHEP::HepRandomEngine *rndEngine) const
Definition: xAODSimHitTosTGCMeasCnvAlg.cxx:92
xAODSimHitTosTGCMeasCnvAlg::digitizePad
void digitizePad(const EventContext &ctx, const xAOD::MuonSimHit &simHit, xAOD::sTgcPadContainer &padContainer) const
Definition: xAODSimHitTosTGCMeasCnvAlg.cxx:144
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
xAODSimHitTosTGCMeasCnvAlg::m_DetMgr
const MuonGMR4::MuonDetectorManager * m_DetMgr
Access to the new readout geometry.
Definition: xAODSimHitTosTGCMeasCnvAlg.h:73
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:214
AmgSymMatrix
#define AmgSymMatrix(dim)
Definition: EventPrimitives.h:52
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
xAODSimHitTosTGCMeasCnvAlg.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
xAODSimHitTosTGCMeasCnvAlg::initialize
StatusCode initialize() override
Definition: xAODSimHitTosTGCMeasCnvAlg.cxx:26
sTgcReadoutElement.h
xAODSimHitTosTGCMeasCnvAlg::m_writeKeyPad
SG::WriteHandleKey< xAOD::sTgcPadContainer > m_writeKeyPad
Definition: xAODSimHitTosTGCMeasCnvAlg.h:68
MuonGMR4::sTgcReadoutElement::wireDesign
const WireGroupDesign & wireDesign(const Identifier &measId) const
Retrieves the readoutElement Layer given the Identifier/Hash.
WriteHandle.h
Handle class for recording to StoreGate.
sTgcWireAuxContainer.h
xAOD::UncalibratedMeasurement_v1::setIdentifier
void setIdentifier(const DetectorIdentType measId)
Sets the full Identifier of the measurement.
xAODSimHitTosTGCMeasCnvAlg::m_geoCtxKey
SG::ReadHandleKey< ActsGeometryContext > m_geoCtxKey
Definition: xAODSimHitTosTGCMeasCnvAlg.h:61
MuonGMR4::sTgcReadoutElement::createHash
static IdentifierHash createHash(const unsigned int gasGap, const unsigned int channelType, const unsigned int channel, const unsigned int wireInGrp=0)
Create a measurement hash from the Identifier fields.
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
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
xAODSimHitTosTGCMeasCnvAlg::m_readKey
SG::ReadHandleKey< xAOD::MuonSimHitContainer > m_readKey
Definition: xAODSimHitTosTGCMeasCnvAlg.h:58
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
MuonChamber.h
xAOD::MuonSimHit_v1::localDirection
ConstVectorMap< 3 > localDirection() const
Returns the local direction of the traversing particle.
Definition: xAODMuonSimHit_V1.cxx:65
sTgcPadAuxContainer.h
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
MuonGMR4::MuonReadoutElement::identHash
IdentifierHash identHash() const
Returns the Identifier has of the Element that is Identical to the detElHash from the id_helper class...
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAODSimHitTosTGCMeasCnvAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: xAODSimHitTosTGCMeasCnvAlg.cxx:179
xAODSimHitTosTGCMeasCnvAlg::m_rndmSvc
ServiceHandle< IAthRNGSvc > m_rndmSvc
Definition: xAODSimHitTosTGCMeasCnvAlg.h:77
xAODSimHitTosTGCMeasCnvAlg::getRandomEngine
CLHEP::HepRandomEngine * getRandomEngine(const EventContext &ctx) const
Definition: xAODSimHitTosTGCMeasCnvAlg.cxx:220
sTgcStripAuxContainer.h
xAODSimHitTosTGCMeasCnvAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: xAODSimHitTosTGCMeasCnvAlg.h:75
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
Defs.h
xAOD::sTgcMeasurement_v1::setChannelNumber
void setChannelNumber(uint16_t channel)
Set the channel number of the measurement.
MuonGMR4::WireGroupDesign::stripNumber
int stripNumber(const Amg::Vector2D &pos) const override
Calculates the number of the strip whose center is closest to the given point.
xAODSimHitTosTGCMeasCnvAlg::m_writeKeyStrip
SG::WriteHandleKey< xAOD::sTgcStripContainer > m_writeKeyStrip
Definition: xAODSimHitTosTGCMeasCnvAlg.h:63
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
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
sTgcIdHelper
Definition: sTgcIdHelper.h:55
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonGMR4::sTgcReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/sTgcReadoutElement.h:21
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
xAODSimHitTosTGCMeasCnvAlg::digitizeStrip
void digitizeStrip(const EventContext &ctx, const xAOD::MuonSimHit &simHit, xAOD::sTgcStripContainer &stripContainer, CLHEP::HepRandomEngine *rndEngine) const
Definition: xAODSimHitTosTGCMeasCnvAlg.cxx:40
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.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::sTgcPadHit_v1
Definition: sTgcPadHit_v1.h:11
xAOD::MuonSimHit_v1::localPosition
ConstVectorMap< 3 > localPosition() const
Returns the local postion of the traversing particle.
Definition: xAODMuonSimHit_V1.cxx:59
GeoPrimitivesToStringConverter.h
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
xAOD::MeasMatrix
Eigen::Matrix< float, N, N > MeasMatrix
Definition: MeasurementDefs.h:54
xAOD::sTgcMeasurement_v1::setGasGap
void setGasGap(uint8_t gap)
Set the associated gas gap of the measurement.
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.
IdentifierHash
Definition: IdentifierHash.h:38
xAOD::sTgcWireHit_v1
Definition: sTgcWireHit_v1.h:11