10 #include "GaudiKernel/PhysicalConstants.h"
11 #include "GaudiKernel/ThreadLocalContext.h"
33 if (std::abs(descriptor->
getStationS()) < std::numeric_limits<double>::epsilon()) {
37 double measuredPerp = std::sqrt(nominalTubePos.perp2() - descriptor->
getStationS()* descriptor->
getStationS());
39 Amg::Vector3D measurePos{tubeSC.
cs * measuredPerp, tubeSC.sn *measuredPerp, nominalTubePos.z()};
49 IdentifierHash mdtHashId = m_idHelperSvc->moduleHash(elementId);
50 if (
static_cast<int>(mdtHashId) == -1) {
51 msg << MSG::ERROR <<
"Module hash creation failed. " << m_idHelperSvc->toString(elementId) <<
endmsg;
55 if (itr != addedCols.end())
return itr->second.get();
59 msg <<
MSG::DEBUG <<
"MdtPrepDataCollection already contained in IDC " << elementId <<
" " << mdtHashId <<
endmsg;
63 std::unique_ptr<MdtPrepDataCollection> newColl = std::make_unique<MdtPrepDataCollection>(mdtHashId);
64 newColl->setIdentifier(m_idHelperSvc->chamberId(elementId));
65 return addedCols.insert(std::make_pair(mdtHashId, std::move(newColl))).first->second.get();
68 for (
auto& to_insert : addedCols) {
69 if (to_insert.second->empty())
continue;
71 if (lock.
addOrDelete(std::move(to_insert.second)).isFailure()) {
72 msg << MSG::ERROR <<
" Failed to add prep data collection " << to_insert.first <<
endmsg;
73 return StatusCode::FAILURE;
76 if (xAODPrd) xAODPrd->lock();
77 return StatusCode::SUCCESS;
80 MdtRdoToPrepDataToolMT::MdtRdoToPrepDataToolMT(
const std::string&
t,
const std::string&
n,
const IInterface*
p) :
81 base_class(
t,
n,
p) {}
94 for (
int i = 0;
i < 2;
i++) {
95 for (
int j = 0; j < 3; j++) {
96 for (
int k = 0;
k < 36;
k++) {
118 ATH_MSG_INFO(
"Processing configuration for layouts with BMG chambers.");
134 std::vector<const MuonGMR4::MdtReadoutElement*> mdtRE =
m_detMgrR4->getAllMdtReadoutElements();
139 for (IdentifierHash dead :
re->getParameters().removedTubes) {
152 return StatusCode::SUCCESS;
160 return StatusCode::FAILURE;
162 return decode(ctx, readCdo->getMultiLayerHashVec(robIds, msgStream()));
167 if (rdoContainerHandle.isValid()) {
169 return rdoContainerHandle.cptr();
180 const std::vector<IdentifierHash>& multiLayerHashInRobs)
const {
181 for (
const IdentifierHash&
hash : multiLayerHashInRobs) {
188 IdentifierHash rdoHash)
const {
191 if (rdoContainer->empty()) {
195 const MdtCsm* rdoColl = rdoContainer->indexFindPtr(rdoHash);
197 ATH_MSG_DEBUG(
"The rdo container does not have the hash " << rdoHash);
200 if (
processCsm(ctx, mdtPrepDataContainer, rdoColl).isFailure()) {
208 const std::vector<IdentifierHash>& idVect)
const {
210 ATH_MSG_DEBUG(
"decodeMdtRDO for " << idVect.size() <<
" offline collections called");
214 if (!mdtPrepDataContainer.
isValid) {
215 return StatusCode::FAILURE;
220 ATH_MSG_DEBUG(
"Stored empty container. Decoding MDT RDO into MDT PrepRawData is switched off");
221 return StatusCode::SUCCESS;
224 if (!idVect.empty()) {
228 std::vector<IdentifierHash> rdoHashes{};
230 if (!rdoContainer || rdoContainer->
empty())
return StatusCode::SUCCESS;
231 rdoHashes.reserve(rdoContainer->
size());
232 for (
const MdtCsm* csm : *rdoContainer) rdoHashes.push_back(csm->identifyHash());
238 return StatusCode::SUCCESS;
247 " because it's masked "<<(calibInput.
isMasked() ?
"si" :
"no") <<
", "
248 <<
"adc: "<<calibInput.
adc()<<
" vs. "<<
m_adcCut<<
", calibration bailed out "
260 <<std::endl<<calibInput<<std::endl<<calibOutput);
269 (
cov)(0, 0) = sigR * sigR;
270 }
else (
cov)(0, 0) = 0;
272 return std::make_unique<MdtPrepData>(calibInput.
identify(),
286 if (!xAODMdtPrepDataContainer || !calibInput.
decriptor() || calibInput.
isMasked() ||
290 <<
" because it's masked " << (calibInput.
isMasked() ?
"si" :
"no")
291 <<
", " <<
"adc: " << calibInput.
adc() <<
" vs. " <<
m_adcCut
296 << calibInput << std::endl << calibOutput);
306 (
cov)(0, 0) = sigR * sigR;
311 xAODMdtPrepDataContainer->
push_back(xprd);
315 const Identifier prdId{calibInput.
identify()};
316 xprd->setIdentifier(calibInput.
identify().get_compact());
318 xprd->setMeasurement(calibInput.
decriptor()
322 xprd->setTdc(calibInput.
tdc());
323 xprd->setAdc(calibInput.
adc());
324 xprd->setTube(id_helper.tube(prdId));
325 xprd->setLayer(id_helper.tubeLayer(prdId));
326 xprd->setStatus(calibOutput.
status());
327 xprd->setReadoutElement(calibInput.
decriptor());
338 Identifier elementId = rdoColl->
identify();
355 << mrodId <<
" / " << csmId);
360 for (
const MdtAmtHit* amtHit : *rdoColl) {
365 std::unique_ptr<MdtDigit> newDigit{
m_mdtDecoder->getDigit(amtHit, subdetId, mrodId, csmId)};
367 ATH_MSG_WARNING(
"Found issue MDT RDO decoder for subdetId/mrodId/csmId "
368 << subdetId <<
"/" << mrodId <<
"/" << csmId <<
" amtHit channelId/tdcId =" << amtHit->channelId() <<
"/"
373 Identifier
channelId = newDigit->identify();
379 if (!driftCircleColl) {
393 int adc = newDigit->adc() / 4;
394 int tdc = newDigit->tdc() / 4;
395 int mask = newDigit->is_masked();
398 <<
" New=" <<
adc <<
" " << tdc);
404 std::unique_ptr<MdtPrepData> newPrepData =
createPrepData(calibIn, calibResult, cache);
406 newPrepData->setHashAndIndex(driftCircleColl->
identifyHash(), driftCircleColl->
size());
407 driftCircleColl->
push_back(std::move(newPrepData));
411 return StatusCode::SUCCESS;
424 <<
" / " << rdoColl->
MrodId() <<
" / " << rdoColl->
CsmId());
432 using twin_digit = std::pair<std::unique_ptr<MdtDigit>, std::unique_ptr<MdtDigit>>;
433 std::map<int, twin_digit> mdtDigitColl;
435 for (
const MdtAmtHit* amtHit : *rdoColl) {
436 std::unique_ptr<MdtDigit> newDigit{
m_mdtDecoder->getDigit(amtHit, subdetId, mrodId, csmId)};
440 << subdetId <<
"/" << mrodId <<
"/" << csmId <<
" amtHit channelId/tdcId =" << amtHit->channelId() <<
"/"
446 Identifier
channelId = newDigit->identify();
456 twinPair = (
tube + 1) / 2;
457 }
else if (
tube % 4 == 3) {
458 twinPair = (
tube - 1) / 2;
459 }
else if (
tube % 4 == 2) {
460 twinPair = (
tube + 2) / 2;
468 pair.first = std::move(newDigit);
469 }
else if (!pair.second) {
470 pair.second = std::move(newDigit);
474 ATH_MSG_VERBOSE(
" TWIN TUBES: found a secondary(not twin) hit in a twin tube");
477 if (!secondPair.first) {
478 secondPair.first = std::move(newDigit);
479 }
else if (!secondPair.second) {
480 secondPair.second = std::move(newDigit);
482 ATH_MSG_VERBOSE(
" TWIN TUBES: found a tertiary hit in a twin tube in one RdoCollection for "
484 <<
" tdc = " << newDigit->tdc());
488 ATH_MSG_DEBUG(
" TWIN TUBES: discarding secondary(non-twin) hit in a twin tube as flag m_discardSecondaryHitTwin is set to true");
494 for (std::pair<const int, twin_digit>& digitPair : mdtDigitColl) {
496 std::unique_ptr<MdtDigit>&
digit = digitPair.second.first;
497 std::unique_ptr<MdtDigit>& second_digit = digitPair.second.second;
501 return StatusCode::FAILURE;
509 if (!driftCircleColl) {
517 if (multilayer == 1) {
529 std::unique_ptr<MdtPrepData> newPrepData =
createPrepData(mdtCalibIn, mdtCalibOut, cache);
531 newPrepData->setHashAndIndex(driftCircleColl->
identifyHash(), driftCircleColl->
size());
532 driftCircleColl->
push_back(std::move(newPrepData));
548 updateClosestApproachTwin(mdtCalib1st);
549 updateClosestApproachTwin(mdtCalib2nd);
561 std::unique_ptr<MdtTwinPrepData> twin_newPrepData = std::make_unique<MdtTwinPrepData>(twinCalib.
primaryID(),
574 Amg::Vector3D gpos_centertube = twin_newPrepData->globalPosition();
580 <<
"local pos center tube w/ TWIN INFO "<<
Amg::toString(locpos_centertube, 2)<<std::endl
583 twin_newPrepData->setHashAndIndex(driftCircleColl->
identifyHash(), driftCircleColl->
size());
584 driftCircleColl->
push_back(std::move(twin_newPrepData));
595 std::unique_ptr<MdtPrepData> newPrepData =
createPrepData(calibInput1st, calibResult1st, cache);
597 newPrepData->setHashAndIndex(driftCircleColl->
identifyHash(), driftCircleColl->
size());
598 driftCircleColl->
push_back(std::move(newPrepData));
603 if (!second_digit)
continue;
612 std::unique_ptr<MdtPrepData> second_newPrepData =
createPrepData(calibInput2nd, calibResult2nd, cache);
613 if (second_newPrepData) {
614 second_newPrepData->setHashAndIndex(driftCircleColl->
identifyHash(), driftCircleColl->
size());
615 driftCircleColl->
push_back(std::move(second_newPrepData));
622 <<
" "<<calibResult2nd);
626 return StatusCode::SUCCESS;
629 PVConstLink cv = mydetEl->getMaterialGeom();
630 int nGrandchildren = cv->getNChildVols();
631 if (nGrandchildren <= 0)
return;
633 std::vector<int> tubes;
634 geoGetIds([&](
int id) { tubes.push_back(
id); }, &*cv);
635 std::sort(tubes.begin(), tubes.end());
637 const Identifier detElId = mydetEl->
identify();
642 int want_id =
layer * maxNTubesPerLayer +
tube;
643 if (
it != tubes.end() && *
it == want_id) {
646 it = std::lower_bound(tubes.begin(), tubes.end(), want_id);
647 if (
it != tubes.end() && *
it == want_id) {
668 if (
status.isFailure() || !handle.isValid()) {
673 cache.legacyPrd = handle.ptr();
682 if (
status.isFailure() || !handle.isValid()) {
688 cache.legacyPrd = handle.ptr();
692 if (!writeHandle.recordNonConst(std::make_unique<xAOD::MdtDriftCircleContainer>(),
693 std::make_unique<xAOD::MdtDriftCircleAuxContainer>()).isSuccess() ||
694 !writeHandle.isValid()) {
698 cache.xAODPrd = writeHandle.ptr();
703 if (!readHandle.isPresent()) {
707 cache.gctx = readHandle.cptr();
712 if (!detMgrHandle.isValid()) {
716 cache.legacyDetMgr = detMgrHandle.cptr();
719 cache.isValid =
true;