ATLAS Offline Software
RpcRdoToRpcPrepDataTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
5 
12 
13 
14 namespace MuonR4{
16  const std::string& name,
17  const IInterface* parent):
18  base_class(type, name, parent) {}
19 
20 
22  ATH_CHECK(m_idHelperSvc.retrieve());
23  ATH_CHECK(m_rdoKey.initialize());
27  ATH_CHECK(m_writeKey.initialize());
29  return StatusCode::SUCCESS;
30  }
31 
32  StatusCode RpcRdoToRpcPrepDataTool::decode(const EventContext& ctx,
33  const std::vector<IdentifierHash>& idVect) const {
34 
35 
37  ATH_CHECK(rdoContainer.isPresent());
38 
40  ATH_CHECK(cablingMap.isValid());
41 
42  const std::unordered_set<IdentifierHash> hashToSelect(idVect.begin(), idVect.end());
43  using RdoPairs = std::array<const xAOD::NRPCRDO*, 2>;
44  std::map<Identifier, RdoPairs, Muon::IdentifierByDetElSorter> sortedRdos{Muon::IdentifierByDetElSorter{m_idHelperSvc.get()}};
45  for (const xAOD::NRPCRDO* rdo : *rdoContainer){
46  /* cabling data conversion */
48  cabling.subDetector = rdo->subdetector();
49  cabling.tdcSector = rdo->tdcsector();
50  cabling.tdc = rdo->tdc();
51  cabling.channelId = rdo->channel();
52 
53 
54  if (!cablingMap->getOfflineId(cabling, msgStream())){
55  return StatusCode::FAILURE;
56  }
57  Identifier offId{};
58  if (!cablingMap->convert(cabling, offId)){
59  ATH_MSG_FATAL("Cabling conversion failed "<<cabling);
60  return StatusCode::FAILURE;
61  }
62  if (hashToSelect.size() && !hashToSelect.count(m_idHelperSvc->moduleHash(offId))) {
63  ATH_MSG_VERBOSE("Skip "<<m_idHelperSvc->toString(offId)<<" due to ROI selection ");
64  continue;
65  }
67  const bool stripSide = cabling.stripSide();
68  sortedRdos[offId][stripSide] = rdo;
69  }
70 
72  ATH_CHECK(stripHandle.record(std::make_unique<xAOD::RpcStripContainer>(),
73  std::make_unique<xAOD::RpcStripAuxContainer>()));
74 
76  if (!m_writeKeyBI.empty()) {
78  ATH_CHECK(strip2DHandle.record(std::make_unique<xAOD::RpcStrip2DContainer>(),
79  std::make_unique<xAOD::RpcStrip2DAuxContainer>()));
80 
81  }
82 
83  const RpcIdHelper& idHelper{m_idHelperSvc->rpcIdHelper()};
84 
85  auto setMeasValues = [&idHelper,this](xAOD::RpcMeasurement* outputMeas,
86  const xAOD::NRPCRDO* rdo,
87  const Identifier& offId){
88 
89  const MuonGMR4::RpcReadoutElement* reElement = m_detMgr->getRpcReadoutElement(offId);
90  outputMeas->setIdentifierHash(m_idHelperSvc->detElementHash(offId));
91  outputMeas->setReadoutElement(reElement);
92  outputMeas->setIdentifier(offId.get_compact());
93  outputMeas->setDoubletPhi(idHelper.doubletPhi(offId));
94  outputMeas->setGasGap(idHelper.gasGap(offId));
95  outputMeas->setStripNumber(idHelper.channel(offId));
96  outputMeas->setTimeOverThreshold(rdo->timeoverthr());
98  outputMeas->setTime(rdo->time());
99  outputMeas->setTimeCovariance(std::pow(m_stripTimeResolution,2));
100  };
101 
103  using CheckVector2D = MuonGMR4::StripDesign::CheckVector2D;
104  for (const auto& [offId, rdoPairs] : sortedRdos) {
105  const MuonGMR4::RpcReadoutElement* reElement = m_detMgr->getRpcReadoutElement(offId);
106 
107  const MuonGMR4::StripDesign& design{reElement->sensorLayout(reElement->measurementHash(offId)).design()};
108 
109  CheckVector2D stripPos = design.center(idHelper.channel(offId));
110  if (!stripPos) {
111  ATH_MSG_WARNING("Failed to fetch a valid stripPosition for "<<m_idHelperSvc->toString(offId));
112  continue;
113  }
114  const double stripLocX = (*stripPos).x();
115  const double stripCovX = std::pow(design.stripPitch(), 2) / std::sqrt(12.);
116 
117  if (m_decode2DStrips && rdoPairs[0] && rdoPairs[1]) {
118  xAOD::RpcStrip2D* measurement = strip2DHandle->push_back(std::make_unique<xAOD::RpcStrip2D>());
119 
122 
123  lPos[0] = stripLocX;
124  lPos[1] = -0.5*m_propagationVelocity *(rdoPairs[0]->time() - rdoPairs[1]->time());
125  lCov(0,0) = stripCovX;
126  lCov(1,1) = M_SQRT1_2 * m_propagationVelocity* m_stripTimeResolution;
128  measurement->setMeasurement<2>(0, lPos, lCov);
129  // CheckVector2D stripPos
130  setMeasValues(measurement, rdoPairs[0], offId);
131  ATH_MSG_VERBOSE("Measurement "<<m_idHelperSvc->toString(offId)<<" "<<lPos.x()<<", "<<lPos.y());
132  continue;
133  }
134 
135  xAOD::RpcStrip* strip = stripHandle->push_back(std::make_unique<xAOD::RpcStrip>());
138  lPos[0] = stripLocX;
139  lCov(0,0) = stripCovX;
140 
141  strip->setMeasuresPhi(idHelper.measuresPhi(offId));
143  strip->setMeasurement<1>(0, lPos, lCov);
144  setMeasValues(strip, rdoPairs[0] ? rdoPairs[0] : rdoPairs[1], offId);
145  }
146  return StatusCode::SUCCESS;
147 
148  }
150  const std::vector<uint32_t>& robIds) const {
152  ATH_CHECK(cablingMap.isValid());
153  return decode(ctx, cablingMap->getChamberHashVec(robIds, msgStream()));
154  }
157  ATH_CHECK(stripHandle.record(std::make_unique<xAOD::RpcStripContainer>(),
158  std::make_unique<xAOD::RpcStripAuxContainer>()));
159 
160  if (!m_writeKeyBI.empty()) {
162  ATH_CHECK(strip2DHandle.record(std::make_unique<xAOD::RpcStrip2DContainer>(),
163  std::make_unique<xAOD::RpcStrip2DAuxContainer>()));
164 
165  }
166  return StatusCode::SUCCESS;
167  }
168 
169 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
RpcStrip2DAuxContainer.h
xAOD::RpcMeasurement_v1
RpcMeasurement_v1: Class storing the geneic.
Definition: RpcMeasurement_v1.h:21
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
MuonGMR4::StripDesign
Definition: StripDesign.h:30
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
MuonR4::RpcRdoToRpcPrepDataTool::decode
StatusCode decode(const EventContext &ctx, const std::vector< IdentifierHash > &idVect) const override final
Definition: RpcRdoToRpcPrepDataTool.cxx:32
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
xAOD::NRPCRDO_v1
Definition: NRPCRDO_v1.h:14
MuonR4::RpcRdoToRpcPrepDataTool::initialize
StatusCode initialize() override final
Definition: RpcRdoToRpcPrepDataTool.cxx:21
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::RpcStrip_v1
Definition: RpcStrip_v1.h:11
MuonGMR4::RpcReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/RpcReadoutElement.h:17
RpcIdHelper
Definition: RpcIdHelper.h:51
MuonR4::RpcRdoToRpcPrepDataTool::RpcRdoToRpcPrepDataTool
RpcRdoToRpcPrepDataTool(const std::string &n, const std::string &p, const IInterface *iface)
Definition: RpcRdoToRpcPrepDataTool.cxx:15
WriteHandle.h
Handle class for recording to StoreGate.
MuonR4::RpcRdoToRpcPrepDataTool::m_decode2DStrips
Gaudi::Property< bool > m_decode2DStrips
Definition: RpcRdoToRpcPrepDataTool.h:64
MuonR4::RpcRdoToRpcPrepDataTool::m_rdoKey
SG::ReadHandleKey< xAOD::NRPCRDOContainer > m_rdoKey
Definition: RpcRdoToRpcPrepDataTool.h:49
MuonR4::RpcRdoToRpcPrepDataTool::m_propagationVelocity
Gaudi::Property< double > m_propagationVelocity
Definition: RpcRdoToRpcPrepDataTool.h:66
xAOD::RpcStrip2D_v1
Definition: RpcStrip2D_v1.h:11
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
NrpcCablingData
Cabling information shipped around the Digi <-> Rdo conversions.
Definition: NrpcCablingData.h:121
MuonR4::RpcRdoToRpcPrepDataTool::m_writeKey
SG::WriteHandleKey< xAOD::RpcStripContainer > m_writeKey
Definition: RpcRdoToRpcPrepDataTool.h:55
MdtMezzExtraction.cablingMap
cablingMap
Definition: MdtMezzExtraction.py:19
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonGMR4::RpcReadoutElement::measurementHash
IdentifierHash measurementHash(const Identifier &measId) const override final
Constructs the identifier hash from the full measurement Identifier.
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
MuonR4::RpcRdoToRpcPrepDataTool::m_geoCtxKey
SG::ReadHandleKey< ActsGeometryContext > m_geoCtxKey
Definition: RpcRdoToRpcPrepDataTool.h:47
xAOD::MeasVector
Eigen::Matrix< float, N, 1 > MeasVector
Abrivation of the Matrix & Covariance definitions.
Definition: MeasurementDefs.h:52
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MuonR4::RpcRdoToRpcPrepDataTool::m_writeKeyBI
SG::WriteHandleKey< xAOD::RpcStrip2DContainer > m_writeKeyBI
Definition: RpcRdoToRpcPrepDataTool.h:58
MuonGMR4::RpcReadoutElement::sensorLayout
const StripLayer & sensorLayout(const IdentifierHash &measHash) const
Access to the StripLayer associated to a given measurement Hash.
RpcMeasurement.h
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
RpcReadoutElement.h
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
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.
MuonR4::RpcRdoToRpcPrepDataTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: RpcRdoToRpcPrepDataTool.h:44
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MuonR4::RpcRdoToRpcPrepDataTool::m_cablingKey
SG::ReadCondHandleKey< MuonNRPC_CablingMap > m_cablingKey
Definition: RpcRdoToRpcPrepDataTool.h:51
MuonR4::RpcRdoToRpcPrepDataTool::provideEmptyContainer
StatusCode provideEmptyContainer(const EventContext &ctx) const override final
Method to create the empty containers.. Only used for seeded decoding.
Definition: RpcRdoToRpcPrepDataTool.cxx:155
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
IdentifierByDetElSorter.h
xAOD::MeasMatrix
Eigen::Matrix< float, N, N > MeasMatrix
Definition: MeasurementDefs.h:54
Muon::IdentifierByDetElSorter
Definition: IdentifierByDetElSorter.h:17
RpcStripAuxContainer.h
MuonR4::RpcRdoToRpcPrepDataTool::m_stripTimeResolution
Gaudi::Property< double > m_stripTimeResolution
Definition: RpcRdoToRpcPrepDataTool.h:69
MuonR4::RpcRdoToRpcPrepDataTool::m_detMgr
const MuonGMR4::MuonDetectorManager * m_detMgr
Definition: RpcRdoToRpcPrepDataTool.h:61
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
MuonGMR4::StripDesign::CheckVector2D
std::optional< Amg::Vector2D > CheckVector2D
Definition: StripDesign.h:82
RpcRdoToRpcPrepDataTool.h
Identifier
Definition: IdentifierFieldParser.cxx:14