10 #include "GaudiKernel/PhysicalConstants.h"
37 if (std::abs(descriptor->
getStationS()) < std::numeric_limits<double>::epsilon()) {
41 double measuredPerp = std::sqrt(nominalTubePos.perp2() - descriptor->
getStationS()* descriptor->
getStationS());
43 Amg::Vector3D measurePos{tubeSC.
cs * measuredPerp, tubeSC.sn *measuredPerp, nominalTubePos.z()};
53 m_idHelperSvc{idHelperSvc} {
54 addedCols.resize(
m_idHelperSvc->mdtIdHelper().module_hash_max());
59 IdentifierHash mdtHashId =
m_idHelperSvc->moduleHash(elementId);
61 std::unique_ptr<MdtPrepDataCollection>& coll {addedCols[mdtHashId]};
63 coll = std::make_unique<MdtPrepDataCollection>(mdtHashId);
71 for (
unsigned int moduleHash =0; moduleHash < addedCols.size(); ++moduleHash) {
72 std::unique_ptr<MdtPrepDataCollection>& toInsert{addedCols[moduleHash]};
73 if (!toInsert || toInsert->empty())
continue;
76 std::vector<const MdtPrepData*> sortMe{toInsert->begin(), toInsert->end()};
82 if (!xAODTwinPrd|| !twinTubeMap || twinTubeMap->twinId(prdId) == prdId ||
83 prd->dimension() == 1) {
84 dc = xAODPrd->push_back(std::make_unique<xAOD::MdtDriftCircle>());
86 dc = xAODTwinPrd->push_back(std::make_unique<xAOD::MdtTwinDriftCircle>());
90 dc->setTdc(prd->tdc());
91 dc->setAdc(prd->adc());
92 dc->setTube(idHelper.tube(prdId));
93 dc->setLayer(idHelper.tubeLayer(prdId));
94 dc->setStatus(prd->status());
96 dc->setReadoutElement(r4DetMgr->getMdtReadoutElement(prdId));
98 const IdentifierHash detHash{
m_idHelperSvc->detElementHash(prdId)};
102 driftCov = prd->localCovariance()(0,0);
105 const float maxR = r4DetMgr ? dc->readoutElement()->innerTubeRadius()
106 : prd->detectorElement()->innerTubeRadius();
110 if (dc->numDimensions() == 1) {
113 dc->setMeasurement<1>(detHash, std::move(locPos), std::move(locCov));
118 dc->setMeasurement<2>(detHash,
xAOD::toStorage(prd->localPosition()), std::move(locCov));
121 twinDC->setTwinAdc(twinPRD->adcTwin());
122 twinDC->setTwinTdc(twinPRD->tdcTwin());
123 const Identifier twinId = twinTubeMap->twinId(prdId);
124 twinDC->setTwinTube(idHelper.tube(twinId));
125 twinDC->setTwinLayer(idHelper.tubeLayer(twinId));
130 if (lock.
addOrDelete(std::move(toInsert)).isFailure()) {
131 msg << MSG::ERROR <<
" Failed to add prep data collection " << moduleHash <<
endmsg;
132 return StatusCode::FAILURE;
141 return StatusCode::SUCCESS;
145 base_class(
t,
n,
p) {}
166 ATH_MSG_INFO(
"Processing configuration for layouts with BMG chambers.");
168 for (
int phi = 6; phi < 8; phi++) {
169 for (
int eta = 1; eta < 4; eta++) {
172 for (
int roe = 1; roe <= (muDetMgr->
getMuonStation(
"BMG",
side * eta, phi))->nMuonReadoutElements();
182 std::vector<const MuonGMR4::MdtReadoutElement*> mdtRE =
m_detMgrR4->getAllMdtReadoutElements();
187 for (
const IdentifierHash& dead :
re->getParameters().removedTubes) {
201 return StatusCode::SUCCESS;
209 return StatusCode::FAILURE;
211 return decode(ctx, readCdo->getMultiLayerHashVec(robIds, msgStream()));
216 if (rdoContainerHandle.isValid()) {
218 return rdoContainerHandle.cptr();
229 const std::vector<IdentifierHash>& multiLayerHashInRobs)
const {
230 for (
const IdentifierHash&
hash : multiLayerHashInRobs) {
237 IdentifierHash rdoHash)
const {
240 if (rdoContainer->empty()) {
244 const MdtCsm* rdoColl = rdoContainer->indexFindPtr(rdoHash);
246 ATH_MSG_DEBUG(
"The rdo container does not have the hash " << rdoHash);
249 if (
processCsm(ctx, mdtPrepDataContainer, rdoColl).isFailure()) {
257 const std::vector<IdentifierHash>& idVect)
const {
259 ATH_MSG_DEBUG(
"decodeMdtRDO for " << idVect.size() <<
" offline collections called");
263 if (!mdtPrepDataContainer.
isValid) {
264 return StatusCode::FAILURE;
269 ATH_MSG_DEBUG(
"Stored empty container. Decoding MDT RDO into MDT PrepRawData is switched off");
270 return StatusCode::SUCCESS;
273 if (!idVect.empty()) {
277 std::vector<IdentifierHash> rdoHashes{};
279 if (!rdoContainer || rdoContainer->
empty())
return StatusCode::SUCCESS;
280 rdoHashes.reserve(rdoContainer->
size());
281 for (
const MdtCsm* csm : *rdoContainer) rdoHashes.push_back(csm->identifyHash());
287 return StatusCode::SUCCESS;
296 <<
", adc: "<<calibInput.
adc()<<
" vs. "<<
m_adcCut<<
", calibration bailed out "
308 <<std::endl<<calibInput<<std::endl<<calibOutput);
317 (
cov)(0, 0) = sigR * sigR;
320 return std::make_unique<MdtPrepData>(calibInput.
identify(),
347 << mrodId <<
" / " << csmId);
352 for (
const MdtAmtHit* amtHit : *rdoColl) {
357 std::unique_ptr<MdtDigit> newDigit{
m_mdtDecoder->getDigit(ctx, *amtHit, subdetId, mrodId, csmId)};
359 ATH_MSG_WARNING(
"Found issue MDT RDO decoder for subdetId/mrodId/csmId "
360 << subdetId <<
"/" << mrodId <<
"/" << csmId <<
" amtHit channelId/tdcId =" << amtHit->channelId() <<
"/"
372 if (!driftCircleColl) {
386 newDigit->setAdc(newDigit->adc() / 4);
387 newDigit->setTdc(newDigit->tdc() / 4);
393 std::unique_ptr<MdtPrepData> newPrepData =
createPrepData(calibIn, calibResult, cache);
395 newPrepData->setHashAndIndex(driftCircleColl->
identifyHash(), driftCircleColl->
size());
396 driftCircleColl->
push_back(std::move(newPrepData));
399 return StatusCode::SUCCESS;
412 <<
" / " << rdoColl->
MrodId() <<
" / " << rdoColl->
CsmId());
416 std::map<Identifier, std::array<std::unique_ptr<MdtDigit>, 2>> mdtDigitColl{};
418 for (
const MdtAmtHit* amtHit : *rdoColl) {
419 std::unique_ptr<MdtDigit> newDigit{
m_mdtDecoder->getDigit(ctx, *amtHit, subdetId, mrodId, csmId)};
423 << subdetId <<
"/" << mrodId <<
"/" << csmId <<
" amtHit channelId/tdcId =" << amtHit->channelId() <<
"/"
427 std::array<std::unique_ptr<MdtDigit>, 2> & moveTo = mdtDigitColl[newDigit->identify()];
429 moveTo[0] = std::move(newDigit);
431 moveTo[1] = std::move(newDigit);
433 ATH_MSG_VERBOSE(
" TWIN TUBES: found a tertiary hit in a twin tube in one RdoCollection for "
434 <<
m_idHelperSvc->toString(newDigit->identify()) <<
" with adc = " << newDigit->adc()
435 <<
" tdc = " << newDigit->tdc());
439 auto convertTwins = [
this, &cache, &ctx](std::unique_ptr<MdtDigit>
digit,
440 std::unique_ptr<MdtDigit> digit2) {
447 if (!digit2 || digit2->isMasked()) {
458 std::unique_ptr<MdtPrepData> newPrepData =
createPrepData(mdtCalibIn, mdtCalibOut, cache);
459 if (!newPrepData)
return;
461 newPrepData->setHashAndIndex(driftCircleColl->
identifyHash(), driftCircleColl->
size());
462 driftCircleColl->
push_back(std::move(newPrepData));
466 <<
", tdc: "<<
digit->tdc()<<
", adc: "<<
digit->adc()<<
" -- "
468 <<
", tdc: "<<digit2->tdc()<<
", adc: "<<digit2->adc());
475 updateClosestApproachTwin(mdtCalib1st);
476 updateClosestApproachTwin(mdtCalib2nd);
479 std::move(mdtCalib1st),
480 std::move(mdtCalib2nd));
486 cov(0, 1) =
cov(1, 0) = 0;
489 auto twin_newPrepData = std::make_unique<MdtTwinPrepData>(twinCalib.
primaryID(),
503 <<
"local pos center tube w/ TWIN INFO "<<
Amg::toString(twinCalib.
locZ() * Amg::Vector3D::UnitZ(), 2)<<std::endl
506 twin_newPrepData->setHashAndIndex(driftCircleColl->
identifyHash(), driftCircleColl->
size());
507 driftCircleColl->
push_back(std::move(twin_newPrepData));
511 for (
auto &[
id, digits] : mdtDigitColl) {
516 std::array<std::unique_ptr<MdtDigit>, 2>& twinDigits = mdtDigitColl[twinId];
518 convertTwins(std::move(digits[0]), std::move(twinDigits[0]));
520 convertTwins(std::move(digits[1]), std::move(twinDigits[1]));
522 convertTwins(std::move(digits[0]),
nullptr);
523 convertTwins(std::move(digits[1]),
nullptr);
526 return StatusCode::SUCCESS;
529 PVConstLink cv = mydetEl->getMaterialGeom();
530 int nGrandchildren = cv->getNChildVols();
531 if (nGrandchildren <= 0)
return;
533 std::vector<int> tubes;
534 geoGetIds([&](
int id) { tubes.push_back(
id); }, &*cv);
535 std::sort(tubes.begin(), tubes.end());
542 int want_id =
layer * maxNTubesPerLayer +
tube;
543 if (
it != tubes.end() && *
it == want_id) {
546 it = std::lower_bound(tubes.begin(), tubes.end(), want_id);
547 if (
it != tubes.end() && *
it == want_id) {
568 if (
status.isFailure() || !handle.isValid()) {
573 cache.legacyPrd = handle.ptr();
582 if (
status.isFailure() || !handle.isValid()) {
588 cache.legacyPrd = handle.ptr();
592 if (!writeHandle.recordNonConst(std::make_unique<xAOD::MdtTwinDriftCircleContainer>(),
593 std::make_unique<xAOD::MdtTwinDriftCircleAuxContainer>()).isSuccess() ||
594 !writeHandle.isValid()) {
598 cache.xAODTwinPrd = writeHandle.ptr();
602 if (!writeHandle.recordNonConst(std::make_unique<xAOD::MdtDriftCircleContainer>(),
603 std::make_unique<xAOD::MdtDriftCircleAuxContainer>()).isSuccess() ||
604 !writeHandle.isValid()) {
608 cache.xAODPrd = writeHandle.ptr();
613 if (!readHandle.isPresent()) {
617 cache.gctx = readHandle.cptr();
622 if (!detMgrHandle.isValid()) {
626 cache.legacyDetMgr = detMgrHandle.cptr();
630 if (!twinTubeHandle.isValid()) {
634 cache.twinTubeMap = twinTubeHandle.cptr();
638 cache.isValid =
true;