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 
13 
14 
15 namespace MuonR4{
17  const std::string& name,
18  const IInterface* parent):
19  base_class(type, name, parent) {}
20 
21 
23  ATH_CHECK(m_idHelperSvc.retrieve());
24  ATH_CHECK(m_rdoKey.initialize());
28  ATH_CHECK(m_writeKey.initialize());
30  return StatusCode::SUCCESS;
31  }
32 
33  StatusCode RpcRdoToRpcPrepDataTool::decode(const EventContext& ctx,
34  const std::vector<IdentifierHash>& idVect) const {
35 
36 
37  SG::ReadHandle rdoContainer{m_rdoKey, ctx};
38  ATH_CHECK(rdoContainer.isPresent());
39 
41  ATH_CHECK(cablingMap.isValid());
42 
43  const std::unordered_set<IdentifierHash> hashToSelect(idVect.begin(), idVect.end());
44  using RdoPairs = std::array<const xAOD::NRPCRDO*, 2>;
45  std::map<Identifier, RdoPairs, Muon::IdentifierByDetElSorter> sortedRdos{Muon::IdentifierByDetElSorter{m_idHelperSvc.get()}};
46  for (const xAOD::NRPCRDO* rdo : *rdoContainer){
47  /* cabling data conversion */
49  cabling.subDetector = rdo->subdetector();
50  cabling.tdcSector = rdo->tdcsector();
51  cabling.tdc = rdo->tdc();
52  cabling.channelId = rdo->channel();
53 
54 
55  if (!cablingMap->getOfflineId(cabling, msgStream())){
56  return StatusCode::FAILURE;
57  }
58  Identifier offId{};
59  if (!cablingMap->convert(cabling, offId)){
60  ATH_MSG_FATAL("Cabling conversion failed "<<cabling);
61  return StatusCode::FAILURE;
62  }
63  if (hashToSelect.size() && !hashToSelect.count(m_idHelperSvc->moduleHash(offId))) {
64  ATH_MSG_VERBOSE("Skip "<<m_idHelperSvc->toString(offId)<<" due to ROI selection ");
65  continue;
66  }
68  const bool stripSide = cabling.stripSide();
69  sortedRdos[offId][stripSide] = rdo;
70  }
71 
73  ATH_CHECK(stripHandle.record(std::make_unique<xAOD::RpcStripContainer>(),
74  std::make_unique<xAOD::RpcStripAuxContainer>()));
75 
77  if (!m_writeKeyBI.empty()) {
79  ATH_CHECK(strip2DHandle.record(std::make_unique<xAOD::RpcStrip2DContainer>(),
80  std::make_unique<xAOD::RpcStrip2DAuxContainer>()));
81 
82  }
83 
84  const RpcIdHelper& idHelper{m_idHelperSvc->rpcIdHelper()};
85 
86  auto setMeasValues = [&idHelper,this](xAOD::RpcMeasurement* outputMeas,
87  const xAOD::NRPCRDO* rdo,
88  const Identifier& offId){
89 
90  const MuonGMR4::RpcReadoutElement* reElement = m_detMgr->getRpcReadoutElement(offId);
91  outputMeas->setIdentifierHash(m_idHelperSvc->detElementHash(offId));
92  outputMeas->setReadoutElement(reElement);
93  outputMeas->setIdentifier(offId.get_compact());
94  outputMeas->setDoubletPhi(idHelper.doubletPhi(offId));
95  outputMeas->setGasGap(idHelper.gasGap(offId));
96  outputMeas->setStripNumber(idHelper.channel(offId));
97  outputMeas->setTimeOverThreshold(rdo->timeoverthr());
99  outputMeas->setTime(rdo->time());
100  outputMeas->setTimeCovariance(std::pow(m_stripTimeResolution,2));
101  };
102 
104  using CheckVector2D = MuonGMR4::StripDesign::CheckVector2D;
105  for (const auto& [offId, rdoPairs] : sortedRdos) {
106  const MuonGMR4::RpcReadoutElement* reElement = m_detMgr->getRpcReadoutElement(offId);
107 
108  const MuonGMR4::StripDesign& design{reElement->sensorLayout(reElement->measurementHash(offId)).design()};
109 
110  CheckVector2D stripPos = design.center(idHelper.channel(offId));
111  if (!stripPos) {
112  ATH_MSG_WARNING("Failed to fetch a valid stripPosition for "<<m_idHelperSvc->toString(offId));
113  continue;
114  }
115  const double stripLocX = (*stripPos).x();
116  const double stripCovX = std::pow(design.stripPitch(), 2) / std::sqrt(12.);
117 
118  if (m_decode2DStrips && rdoPairs[0] && rdoPairs[1]) {
119  xAOD::RpcStrip2D* measurement = strip2DHandle->push_back(std::make_unique<xAOD::RpcStrip2D>());
120 
123 
124  lPos[0] = stripLocX;
125  lPos[1] = -0.5*m_propagationVelocity *(rdoPairs[0]->time() - rdoPairs[1]->time());
126  lCov(0,0) = stripCovX;
127  lCov(1,1) = M_SQRT1_2 * m_propagationVelocity* m_stripTimeResolution;
129  measurement->setMeasurement<2>(0, lPos, lCov);
130  // CheckVector2D stripPos
131  setMeasValues(measurement, rdoPairs[0], offId);
132  ATH_MSG_VERBOSE("Measurement "<<m_idHelperSvc->toString(offId)<<" "<<lPos.x()<<", "<<lPos.y());
133  continue;
134  }
135 
136  xAOD::RpcStrip* strip = stripHandle->push_back(std::make_unique<xAOD::RpcStrip>());
139  lPos[0] = stripLocX;
140  lCov(0,0) = stripCovX;
141 
142  strip->setMeasuresPhi(idHelper.measuresPhi(offId));
144  strip->setMeasurement<1>(0, lPos, lCov);
145  setMeasValues(strip, rdoPairs[0] ? rdoPairs[0] : rdoPairs[1], offId);
146  }
147  return StatusCode::SUCCESS;
148 
149  }
151  const std::vector<uint32_t>& robIds) const {
153  ATH_CHECK(cablingMap.isValid());
154  return decode(ctx, cablingMap->getChamberHashVec(robIds, msgStream()));
155  }
158  ATH_CHECK(stripHandle.record(std::make_unique<xAOD::RpcStripContainer>(),
159  std::make_unique<xAOD::RpcStripAuxContainer>()));
160 
161  if (!m_writeKeyBI.empty()) {
163  ATH_CHECK(strip2DHandle.record(std::make_unique<xAOD::RpcStrip2DContainer>(),
164  std::make_unique<xAOD::RpcStrip2DAuxContainer>()));
165 
166  }
167  return StatusCode::SUCCESS;
168  }
169 
170 }
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
RpcCablingData.h
MuonR4::RpcRdoToRpcPrepDataTool::decode
StatusCode decode(const EventContext &ctx, const std::vector< IdentifierHash > &idVect) const override final
Definition: RpcRdoToRpcPrepDataTool.cxx:33
MuonR4::RpcRdoToRpcPrepDataTool::m_cablingKey
SG::ReadCondHandleKey< Muon::RpcCablingMap > m_cablingKey
Definition: RpcRdoToRpcPrepDataTool.h:51
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
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:22
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:16
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
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
Muon::RpcCablingData
Helper struct that is parsed to the cabling map to translate between the offline & online Identifiers...
Definition: RpcCablingData.h:94
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
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::provideEmptyContainer
StatusCode provideEmptyContainer(const EventContext &ctx) const override final
Method to create the empty containers.. Only used for seeded decoding.
Definition: RpcRdoToRpcPrepDataTool.cxx:156
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
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
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