Skip to content
Snippets Groups Projects
Commit d4eb75bc authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

Merge branch 'MdtPrepDataR4' into 'main'

MdtRdoToPrepData - Add option to use the Phase II MuonDetMgr

See merge request !71815
parents a7e0edc5 f82aebf8
No related branches found
No related tags found
28 merge requests!78241Draft: FPGATrackSim: GenScan code refactor,!78236Draft: Switching Streams https://its.cern.ch/jira/browse/ATR-27417,!78056AFP monitoring: new synchronization and cleaning,!78041AFP monitoring: new synchronization and cleaning,!77990Updating TRT chip masks for L1TRT trigger simulation - ATR-28372,!77733Draft: add new HLT NN JVT, augmented with additional tracking information,!77731Draft: Updates to ZDC reconstruction,!77728Draft: updates to ZDC reconstruction,!77522Draft: sTGC Pad Trigger Emulator,!76725ZdcNtuple: Fix cppcheck warning.,!76611L1CaloFEXByteStream: Fix out-of-bounds array accesses.,!76475Punchthrough AF3 implementation in FastG4,!76474Punchthrough AF3 implementation in FastG4,!76343Draft: MooTrackBuilder: Recalibrate NSW hits in refine method,!75729New implementation of ZDC nonlinear FADC correction.,!75703Draft: Update to HI han config for HLT jets,!75184Draft: Update file heavyions_run.config,!74430Draft: Fixing upper bound for Delayed Jet Triggers,!73963Changing the path of the histograms to "Expert" area,!73875updating ID ART reference plots,!73874AtlasCLHEP_RandomGenerators: Fix cppcheck warnings.,!73449Add muon detectors to DarkJetPEBTLA partial event building,!73343Draft: [TrigEgamma] Add photon ringer chains on bootstrap mechanism,!72336Fixed TRT calibration crash,!72176Draft: Improving L1TopoOnline chain that now gets no-empty plots. Activating it by default,!72012Draft: Separate JiveXMLConfig.py into Config files,!71876Fix MET trigger name in MissingETMonitoring,!71815MdtRdoToPrepData - Add option to use the Phase II MuonDetMgr
...@@ -29,29 +29,31 @@ namespace { ...@@ -29,29 +29,31 @@ namespace {
inline void updateClosestApproachTwin(MdtCalibInput & in) { inline void updateClosestApproachTwin(MdtCalibInput & in) {
const MuonGM::MdtReadoutElement* descriptor = in.legacyDescriptor(); const MuonGM::MdtReadoutElement* descriptor = in.legacyDescriptor();
if (std::abs(descriptor->getStationS()) < std::numeric_limits<double>::epsilon()) { if (descriptor) {
return; if (std::abs(descriptor->getStationS()) < std::numeric_limits<double>::epsilon()) {
return;
}
const Amg::Vector3D nominalTubePos = descriptor->tubePos(in.identify());
double measuredPerp = std::sqrt(nominalTubePos.perp2() - descriptor->getStationS()* descriptor->getStationS());
CxxUtils::sincos tubeSC{nominalTubePos.phi()};
Amg::Vector3D measurePos{tubeSC.cs * measuredPerp, tubeSC.sn *measuredPerp, nominalTubePos.z()};
in.setClosestApproach(measurePos);
} }
const Amg::Vector3D nominalTubePos = descriptor->tubePos(in.identify());
double measuredPerp = std::sqrt(nominalTubePos.perp2() - descriptor->getStationS()* descriptor->getStationS());
CxxUtils::sincos tubeSC{nominalTubePos.phi()};
Amg::Vector3D measurePos{tubeSC.cs * measuredPerp, tubeSC.sn *measuredPerp, nominalTubePos.z()};
in.setClosestApproach(measurePos);
} }
} // namespace } // namespace
namespace Muon { namespace Muon {
MdtPrepDataCollection* MdtRdoToPrepDataToolMT::ModfiablePrdColl::createCollection(const Identifier& elementId, MdtPrepDataCollection* MdtRdoToPrepDataToolMT::ConvCache::createCollection(const Identifier& elementId, MsgStream& msg) {
const MdtIdHelper& id_helper, MsgStream& msg) {
IdentifierHash mdtHashId{0}; IdentifierHash mdtHashId = m_idHelperSvc->moduleHash(elementId);
if (id_helper.get_module_hash(elementId, mdtHashId)) { if (static_cast<int>(mdtHashId) == -1) {
msg << MSG::ERROR << "Module hash creation failed. " << elementId << endmsg; msg << MSG::ERROR << "Module hash creation failed. " << m_idHelperSvc->toString(elementId) << endmsg;
return nullptr; return nullptr;
} }
PrdCollMap::iterator itr = addedCols.find(mdtHashId); PrdCollMap::iterator itr = addedCols.find(mdtHashId);
if (itr != addedCols.end()) return itr->second.get(); if (itr != addedCols.end()) return itr->second.get();
MdtPrepDataContainer::IDC_WriteHandle lock = prd_cont->getWriteHandle(mdtHashId); MdtPrepDataContainer::IDC_WriteHandle lock = legacyPrd->getWriteHandle(mdtHashId);
if (lock.alreadyPresent()) { if (lock.alreadyPresent()) {
if (msg.level() <= MSG::DEBUG) { if (msg.level() <= MSG::DEBUG) {
msg << MSG::DEBUG << "MdtPrepDataCollection already contained in IDC " << elementId << " " << mdtHashId << endmsg; msg << MSG::DEBUG << "MdtPrepDataCollection already contained in IDC " << elementId << " " << mdtHashId << endmsg;
...@@ -59,19 +61,20 @@ namespace Muon { ...@@ -59,19 +61,20 @@ namespace Muon {
return nullptr; return nullptr;
} }
std::unique_ptr<MdtPrepDataCollection> newColl = std::make_unique<MdtPrepDataCollection>(mdtHashId); std::unique_ptr<MdtPrepDataCollection> newColl = std::make_unique<MdtPrepDataCollection>(mdtHashId);
newColl->setIdentifier(id_helper.elementID(elementId)); newColl->setIdentifier(m_idHelperSvc->chamberId(elementId));
return addedCols.insert(std::make_pair(mdtHashId, std::move(newColl))).first->second.get(); return addedCols.insert(std::make_pair(mdtHashId, std::move(newColl))).first->second.get();
} }
StatusCode MdtRdoToPrepDataToolMT::ModfiablePrdColl::finalize(std::vector<IdentifierHash>& prdHashes, MsgStream& msg) { StatusCode MdtRdoToPrepDataToolMT::ConvCache::finalize(std::vector<IdentifierHash>& prdHashes, MsgStream& msg) {
for (auto& to_insert : addedCols) { for (auto& to_insert : addedCols) {
if (to_insert.second->empty()) continue; if (to_insert.second->empty()) continue;
MdtPrepDataContainer::IDC_WriteHandle lock = prd_cont->getWriteHandle(to_insert.first); MdtPrepDataContainer::IDC_WriteHandle lock = legacyPrd->getWriteHandle(to_insert.first);
if (lock.addOrDelete(std::move(to_insert.second)).isFailure()) { if (lock.addOrDelete(std::move(to_insert.second)).isFailure()) {
msg << MSG::ERROR << " Failed to add prep data collection " << to_insert.first << endmsg; msg << MSG::ERROR << " Failed to add prep data collection " << to_insert.first << endmsg;
return StatusCode::FAILURE; return StatusCode::FAILURE;
} }
prdHashes.emplace_back(to_insert.first); prdHashes.emplace_back(to_insert.first);
} }
if (xAODPrd) xAODPrd->lock();
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
...@@ -79,9 +82,6 @@ namespace Muon { ...@@ -79,9 +82,6 @@ namespace Muon {
base_class(t, n, p) {} base_class(t, n, p) {}
StatusCode MdtRdoToPrepDataToolMT::initialize() { StatusCode MdtRdoToPrepDataToolMT::initialize() {
ATH_CHECK(AthAlgTool::initialize());
const MuonGM::MuonDetectorManager* muDetMgr = nullptr;
ATH_CHECK(detStore()->retrieve(muDetMgr));
ATH_CHECK(m_calibrationTool.retrieve()); ATH_CHECK(m_calibrationTool.retrieve());
ATH_MSG_VERBOSE("MdtCalibrationTool retrieved with pointer = " << m_calibrationTool); ATH_MSG_VERBOSE("MdtCalibrationTool retrieved with pointer = " << m_calibrationTool);
ATH_CHECK(m_prdContainerCacheKey.initialize(!m_prdContainerCacheKey.key().empty())); ATH_CHECK(m_prdContainerCacheKey.initialize(!m_prdContainerCacheKey.key().empty()));
...@@ -109,7 +109,13 @@ namespace Muon { ...@@ -109,7 +109,13 @@ namespace Muon {
m_BMGid = m_idHelperSvc->mdtIdHelper().stationNameIndex("BMG"); m_BMGid = m_idHelperSvc->mdtIdHelper().stationNameIndex("BMG");
m_BMGpresent = m_BMGid != -1; m_BMGpresent = m_BMGid != -1;
if (m_BMGpresent) { if (m_useNewGeo) {
ATH_CHECK(detStore()->retrieve(m_detMgrR4));
}
if (m_BMGpresent && !m_useNewGeo) {
const MuonGM::MuonDetectorManager* muDetMgr = nullptr;
ATH_CHECK(detStore()->retrieve(muDetMgr));
ATH_MSG_INFO("Processing configuration for layouts with BMG chambers."); ATH_MSG_INFO("Processing configuration for layouts with BMG chambers.");
for (int phi = 6; phi < 8; phi++) { // phi sectors for (int phi = 6; phi < 8; phi++) { // phi sectors
...@@ -125,6 +131,16 @@ namespace Muon { ...@@ -125,6 +131,16 @@ namespace Muon {
} }
} }
} }
} else if (m_useNewGeo) {
std::vector<const MuonGMR4::MdtReadoutElement*> mdtRE = m_detMgrR4->getAllMdtReadoutElements();
for (const MuonGMR4::MdtReadoutElement* re : mdtRE) {
if (re->stationName() != m_BMGid) {
continue;
}
for (IdentifierHash dead : re->getParameters().removedTubes) {
m_DeadChannels.insert(re->measurementId(dead));
}
}
} }
// check if initializing of DataHandle objects success // check if initializing of DataHandle objects success
...@@ -133,6 +149,7 @@ namespace Muon { ...@@ -133,6 +149,7 @@ namespace Muon {
ATH_CHECK(m_readKey.initialize()); ATH_CHECK(m_readKey.initialize());
ATH_CHECK(m_muDetMgrKey.initialize()); ATH_CHECK(m_muDetMgrKey.initialize());
ATH_CHECK(m_mdtxAODKey.initialize(!m_mdtxAODKey.empty())); ATH_CHECK(m_mdtxAODKey.initialize(!m_mdtxAODKey.empty()));
ATH_CHECK(m_geoCtxKey.initialize(m_useNewGeo));
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
...@@ -157,19 +174,15 @@ namespace Muon { ...@@ -157,19 +174,15 @@ namespace Muon {
} }
StatusCode MdtRdoToPrepDataToolMT::provideEmptyContainer(const EventContext& ctx) const{ StatusCode MdtRdoToPrepDataToolMT::provideEmptyContainer(const EventContext& ctx) const{
return setupMdtPrepDataContainer(ctx).prd_cont ? StatusCode::SUCCESS : StatusCode::FAILURE; return setupMdtPrepDataContainer(ctx).isValid ? StatusCode::SUCCESS : StatusCode::FAILURE;
} }
StatusCode MdtRdoToPrepDataToolMT::decode(const EventContext& ctx, const std::vector<IdentifierHash>& multiLayerHashInRobs) const { StatusCode MdtRdoToPrepDataToolMT::decode(const EventContext& ctx, const std::vector<IdentifierHash>& multiLayerHashInRobs) const {
// setup output container // setup output container
ModfiablePrdColl mdtPrepDataContainer = setupMdtPrepDataContainer(ctx); ConvCache mdtPrepDataContainer = setupMdtPrepDataContainer(ctx);
if (!mdtPrepDataContainer.prd_cont) { return StatusCode::FAILURE; } if (!mdtPrepDataContainer.isValid) {
return StatusCode::FAILURE;
SG::WriteHandle<xAOD::MdtDriftCircleContainer> outputContainer;
if (!m_mdtxAODKey.empty()) {
outputContainer = SG::WriteHandle<xAOD::MdtDriftCircleContainer>(m_mdtxAODKey, ctx);
} }
auto mdtxAODPrepDataContainer = setupxAODMdtPrepDataContainer(outputContainer);
if (!m_decodeData) { if (!m_decodeData) {
ATH_MSG_DEBUG("Stored empty container. Decoding MDT RDO into MDT PrepRawData is switched off"); ATH_MSG_DEBUG("Stored empty container. Decoding MDT RDO into MDT PrepRawData is switched off");
...@@ -178,22 +191,21 @@ namespace Muon { ...@@ -178,22 +191,21 @@ namespace Muon {
// left unused, needed by other decode function and further down the code. // left unused, needed by other decode function and further down the code.
std::vector<IdentifierHash> idWithDataVect; std::vector<IdentifierHash> idWithDataVect;
processPRDHashes(ctx, mdtPrepDataContainer, mdtxAODPrepDataContainer, multiLayerHashInRobs); processPRDHashes(ctx, mdtPrepDataContainer, multiLayerHashInRobs);
ATH_CHECK(mdtPrepDataContainer.finalize(idWithDataVect, msgStream())); ATH_CHECK(mdtPrepDataContainer.finalize(idWithDataVect, msgStream()));
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} // end decode } // end decode
void MdtRdoToPrepDataToolMT::processPRDHashes(const EventContext& ctx, ModfiablePrdColl& mdtPrepDataContainer, void MdtRdoToPrepDataToolMT::processPRDHashes(const EventContext& ctx, ConvCache& mdtPrepDataContainer,
xAOD::MdtDriftCircleContainer* xAODMdtPrepDataContainer, const std::vector<IdentifierHash>& multiLayerHashInRobs) const {
const std::vector<IdentifierHash>& multiLayerHashInRobs) const {
for (const IdentifierHash& hash : multiLayerHashInRobs) { for (const IdentifierHash& hash : multiLayerHashInRobs) {
if (!handlePRDHash(ctx, mdtPrepDataContainer, xAODMdtPrepDataContainer, hash)) { ATH_MSG_DEBUG("Failed to process hash " << hash); } if (!handlePRDHash(ctx, mdtPrepDataContainer, hash)) { ATH_MSG_DEBUG("Failed to process hash " << hash); }
} // ends loop over chamberhash } // ends loop over chamberhash
} }
bool MdtRdoToPrepDataToolMT::handlePRDHash(const EventContext& ctx, ModfiablePrdColl& mdtPrepDataContainer, bool MdtRdoToPrepDataToolMT::handlePRDHash(const EventContext& ctx,
xAOD::MdtDriftCircleContainer* xAODMdtPrepDataContainer, ConvCache& mdtPrepDataContainer,
IdentifierHash rdoHash) const { IdentifierHash rdoHash) const {
const MdtCsmContainer* rdoContainer{getRdoContainer(ctx)}; const MdtCsmContainer* rdoContainer{getRdoContainer(ctx)};
if (rdoContainer->empty()) { if (rdoContainer->empty()) {
...@@ -205,13 +217,7 @@ namespace Muon { ...@@ -205,13 +217,7 @@ namespace Muon {
ATH_MSG_DEBUG("The rdo container does not have the hash " << rdoHash); ATH_MSG_DEBUG("The rdo container does not have the hash " << rdoHash);
return true; return true;
} }
SG::ReadCondHandle<MuonGM::MuonDetectorManager> muDetMgr{m_muDetMgrKey, ctx}; if (processCsm(ctx, mdtPrepDataContainer, rdoColl).isFailure()) {
if (!muDetMgr.isValid()) {
ATH_MSG_FATAL("Failed to retrieve the Muon detector manager " << m_muDetMgrKey.fullKey());
return false;
}
if (processCsm(ctx, mdtPrepDataContainer, xAODMdtPrepDataContainer, rdoColl, *muDetMgr).isFailure()) {
ATH_MSG_WARNING("processCsm failed for RDO id " << m_idHelperSvc->toString(rdoColl->identify())); ATH_MSG_WARNING("processCsm failed for RDO id " << m_idHelperSvc->toString(rdoColl->identify()));
return false; return false;
} }
...@@ -226,22 +232,19 @@ namespace Muon { ...@@ -226,22 +232,19 @@ namespace Muon {
ATH_MSG_DEBUG("decodeMdtRDO for " << idVect.size() << " offline collections called"); ATH_MSG_DEBUG("decodeMdtRDO for " << idVect.size() << " offline collections called");
// setup output container // setup output container
ModfiablePrdColl mdtPrepDataContainer = setupMdtPrepDataContainer(ctx); ConvCache mdtPrepDataContainer = setupMdtPrepDataContainer(ctx);
if (!mdtPrepDataContainer.prd_cont) { return StatusCode::FAILURE; } if (!mdtPrepDataContainer.isValid) {
return StatusCode::FAILURE;
SG::WriteHandle<xAOD::MdtDriftCircleContainer> outputContainer;
if (!m_mdtxAODKey.empty()) {
outputContainer = SG::WriteHandle<xAOD::MdtDriftCircleContainer>(m_mdtxAODKey, ctx);
} }
auto mdtxAODPrepDataContainer = setupxAODMdtPrepDataContainer(outputContainer);
if (!m_decodeData) { if (!m_decodeData) {
ATH_MSG_DEBUG("Stored empty container. Decoding MDT RDO into MDT PrepRawData is switched off"); ATH_MSG_DEBUG("Stored empty container. Decoding MDT RDO into MDT PrepRawData is switched off");
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
// seeded or unseeded decoding // seeded or unseeded decoding
if (!idVect.empty()) { if (!idVect.empty()) {
processPRDHashes(ctx, mdtPrepDataContainer, mdtxAODPrepDataContainer, idVect); processPRDHashes(ctx, mdtPrepDataContainer, idVect);
} else { } else {
/// Construct the hashes from the existing RDOs /// Construct the hashes from the existing RDOs
std::vector<IdentifierHash> rdoHashes{}; std::vector<IdentifierHash> rdoHashes{};
...@@ -250,7 +253,7 @@ namespace Muon { ...@@ -250,7 +253,7 @@ namespace Muon {
rdoHashes.reserve(rdoContainer->size()); rdoHashes.reserve(rdoContainer->size());
for (const MdtCsm* csm : *rdoContainer) rdoHashes.push_back(csm->identifyHash()); for (const MdtCsm* csm : *rdoContainer) rdoHashes.push_back(csm->identifyHash());
processPRDHashes(ctx, mdtPrepDataContainer, mdtxAODPrepDataContainer, rdoHashes); processPRDHashes(ctx, mdtPrepDataContainer, rdoHashes);
} }
ATH_CHECK(mdtPrepDataContainer.finalize(idWithDataVect, msgStream())); ATH_CHECK(mdtPrepDataContainer.finalize(idWithDataVect, msgStream()));
...@@ -315,8 +318,9 @@ namespace Muon { ...@@ -315,8 +318,9 @@ namespace Muon {
} }
std::unique_ptr<MdtPrepData> MdtRdoToPrepDataToolMT::createPrepData(const MdtCalibInput& calibInput, std::unique_ptr<MdtPrepData> MdtRdoToPrepDataToolMT::createPrepData(const MdtCalibInput& calibInput,
const MdtCalibOutput& calibOutput) const { const MdtCalibOutput& calibOutput,
if (!calibInput.legacyDescriptor() || calibInput.isMasked() || calibInput.adc() < m_adcCut || ConvCache& cache) const {
if (calibInput.isMasked() || calibInput.adc() < m_adcCut ||
calibOutput.status() == MdtDriftCircleStatus::MdtStatusUnDefined) { calibOutput.status() == MdtDriftCircleStatus::MdtStatusUnDefined) {
ATH_MSG_VERBOSE("Do not create calib hit for "<<m_idHelperSvc->toString(calibInput.identify())<< ATH_MSG_VERBOSE("Do not create calib hit for "<<m_idHelperSvc->toString(calibInput.identify())<<
" because it's masked "<<(calibInput.isMasked() ? "si" : "no") <<", " " because it's masked "<<(calibInput.isMasked() ? "si" : "no") <<", "
...@@ -324,6 +328,13 @@ namespace Muon { ...@@ -324,6 +328,13 @@ namespace Muon {
<<(calibOutput.status() == MdtDriftCircleStatus::MdtStatusUnDefined? "si": "no")); <<(calibOutput.status() == MdtDriftCircleStatus::MdtStatusUnDefined? "si": "no"));
return nullptr; return nullptr;
} }
const MuonGM::MdtReadoutElement* descriptor = calibInput.legacyDescriptor();
if (!descriptor) {
if (!cache.legacyDetMgr) {
return nullptr;
}
descriptor = cache.legacyDetMgr->getMdtReadoutElement(calibInput.identify());
}
ATH_MSG_VERBOSE("Calibrated prepdata "<<m_idHelperSvc->toString(calibInput.identify()) ATH_MSG_VERBOSE("Calibrated prepdata "<<m_idHelperSvc->toString(calibInput.identify())
<<std::endl<<calibInput<<std::endl<<calibOutput); <<std::endl<<calibInput<<std::endl<<calibOutput);
...@@ -337,39 +348,31 @@ namespace Muon { ...@@ -337,39 +348,31 @@ namespace Muon {
(cov)(0, 0) = sigR * sigR; (cov)(0, 0) = sigR * sigR;
} else (cov)(0, 0) = 0; } else (cov)(0, 0) = 0;
return std::make_unique<MdtPrepData>(calibInput.identify(), return std::make_unique<MdtPrepData>(calibInput.identify(),
calibInput.legacyDescriptor()->identifyHash(), descriptor->identifyHash(),
std::move(driftRadius), std::move(driftRadius),
std::move(cov), std::move(cov),
calibInput.legacyDescriptor(), descriptor,
calibInput.tdc(), calibInput.tdc(),
calibInput.adc(), calibInput.adc(),
calibOutput.status()); calibOutput.status());
} }
void MdtRdoToPrepDataToolMT::createxAODPrepData(const MdtCalibInput& calibInput, void MdtRdoToPrepDataToolMT::createxAODPrepData(const MdtCalibInput& calibInput,
const MdtCalibOutput& calibOutput, const MdtCalibOutput& calibOutput,
xAOD::MdtDriftCircleContainer* xAODMdtPrepDataContainer) const { xAOD::MdtDriftCircleContainer* xAODMdtPrepDataContainer) const {
if (!calibInput.legacyDescriptor() || calibInput.isMasked() ||
calibInput.adc() < m_adcCut || if (!xAODMdtPrepDataContainer || !calibInput.decriptor() || calibInput.isMasked() ||
calibOutput.status() == MdtDriftCircleStatus::MdtStatusUnDefined) { calibInput.adc() < m_adcCut || calibOutput.status() == MdtDriftCircleStatus::MdtStatusUnDefined) {
ATH_MSG_VERBOSE( ATH_MSG_VERBOSE("Do not create calib hit for "
"Do not create calib hit for " << m_idHelperSvc->toString(calibInput.identify())
<< m_idHelperSvc->toString(calibInput.identify()) << " because it's masked " << (calibInput.isMasked() ? "si" : "no")
<< " because it's masked " << (calibInput.isMasked() ? "si" : "no") << ", " << "adc: " << calibInput.adc() << " vs. " << m_adcCut
<< ", " << ", calibration bailed out " << (calibOutput.status() == MdtDriftCircleStatus::MdtStatusUnDefined ? "si": "no"));
<< "adc: " << calibInput.adc() << " vs. " << m_adcCut
<< ", calibration bailed out "
<< (calibOutput.status() == MdtDriftCircleStatus::MdtStatusUnDefined
? "si"
: "no"));
return; return;
} }
ATH_MSG_VERBOSE("Calibrated xAOD prepdata " ATH_MSG_VERBOSE("Calibrated xAOD prepdata "<< m_idHelperSvc->toString(calibInput.identify()) << std::endl
<< m_idHelperSvc->toString(calibInput.identify()) << calibInput << std::endl << calibOutput);
<< std::endl
<< calibInput << std::endl
<< calibOutput);
xAOD::MeasVector<1> driftRadius{0.0}; xAOD::MeasVector<1> driftRadius{0.0};
xAOD::MeasMatrix<1> cov{0.0}; xAOD::MeasMatrix<1> cov{0.0};
...@@ -391,23 +394,18 @@ namespace Muon { ...@@ -391,23 +394,18 @@ namespace Muon {
const Identifier prdId{calibInput.identify()}; const Identifier prdId{calibInput.identify()};
xprd->setIdentifier(calibInput.identify().get_identifier32().get_compact()); xprd->setIdentifier(calibInput.identify().get_identifier32().get_compact());
xprd->setMeasurement(calibInput.legacyDescriptor()->identifyHash(), driftRadius, xprd->setMeasurement(calibInput.legacyDescriptor()->identifyHash(), driftRadius, cov);
cov);
xprd->setTdc(calibInput.tdc()); xprd->setTdc(calibInput.tdc());
xprd->setAdc(calibInput.adc()); xprd->setAdc(calibInput.adc());
xprd->setTube(id_helper.tube(prdId)); xprd->setTube(id_helper.tube(prdId));
xprd->setLayer(id_helper.tubeLayer(prdId)); xprd->setLayer(id_helper.tubeLayer(prdId));
xprd->setStatus(calibOutput.status()); xprd->setStatus(calibOutput.status());
// TODO tubePosInStation - but this needs ReadoutElement? xprd->setReadoutElement(calibInput.decriptor());
return; return;
} }
StatusCode MdtRdoToPrepDataToolMT::processCsm(const EventContext& ctx, ModfiablePrdColl& prepDataContainer, StatusCode MdtRdoToPrepDataToolMT::processCsm(const EventContext& ctx, ConvCache& cache, const MdtCsm* rdoColl) const {
xAOD::MdtDriftCircleContainer* xAODMdtPrepDataContainer,
const MdtCsm* rdoColl,
const MuonGM::MuonDetectorManager* muDetMgr) const {
const MdtIdHelper& id_helper = m_idHelperSvc->mdtIdHelper(); const MdtIdHelper& id_helper = m_idHelperSvc->mdtIdHelper();
// first handle the case of twin tubes // first handle the case of twin tubes
if (m_useTwin) { if (m_useTwin) {
...@@ -418,7 +416,7 @@ namespace Muon { ...@@ -418,7 +416,7 @@ namespace Muon {
MuonStationIndex::ChIndex chIndex = m_idHelperSvc->chamberIndex(elementId); MuonStationIndex::ChIndex chIndex = m_idHelperSvc->chamberIndex(elementId);
if (chIndex == MuonStationIndex::BOL && if (chIndex == MuonStationIndex::BOL &&
(m_useAllBOLTwin || (std::abs(id_helper.stationEta(elementId)) == 4 && id_helper.stationPhi(elementId) == 7))) { (m_useAllBOLTwin || (std::abs(id_helper.stationEta(elementId)) == 4 && id_helper.stationPhi(elementId) == 7))) {
return processCsmTwin(ctx, prepDataContainer, xAODMdtPrepDataContainer, rdoColl, muDetMgr); return processCsmTwin(ctx, cache, rdoColl);
} }
} }
...@@ -450,11 +448,11 @@ namespace Muon { ...@@ -450,11 +448,11 @@ namespace Muon {
} }
// Do something with it // Do something with it
Identifier channelId = newDigit->identify(); Identifier channelId = newDigit->identify();
if (deadBMGChannel(channelId)) continue; if (m_DeadChannels.count(channelId)) continue;
// Retrieve the proper PRD container. Note that there are cases where one CSM is either split into 2 chambers (BEE / BIS78 // Retrieve the proper PRD container. Note that there are cases where one CSM is either split into 2 chambers (BEE / BIS78
// legacy) or 2 CSMs are split into one chamber // legacy) or 2 CSMs are split into one chamber
MdtPrepDataCollection* driftCircleColl = prepDataContainer.createCollection(channelId, id_helper, msgStream()); MdtPrepDataCollection* driftCircleColl = cache.createCollection(channelId, msgStream());
if (!driftCircleColl) { if (!driftCircleColl) {
ATH_MSG_DEBUG("Corresponding multi layer " << m_idHelperSvc->toString(channelId) << " is already decoded."); ATH_MSG_DEBUG("Corresponding multi layer " << m_idHelperSvc->toString(channelId) << " is already decoded.");
continue; continue;
...@@ -476,33 +474,20 @@ namespace Muon { ...@@ -476,33 +474,20 @@ namespace Muon {
ATH_MSG_DEBUG("Change HPTDC ADC/TDC " << m_idHelperSvc->toString(channelId) << " Old ADC/TDC=" << adc * 4 << " " << tdc * 4 ATH_MSG_DEBUG("Change HPTDC ADC/TDC " << m_idHelperSvc->toString(channelId) << " Old ADC/TDC=" << adc * 4 << " " << tdc * 4
<< " New=" << adc << " " << tdc); << " New=" << adc << " " << tdc);
} }
const MdtCalibInput calibIn{*newDigit, *muDetMgr}; const MdtCalibInput calibIn = m_useNewGeo ? MdtCalibInput{*newDigit, *m_detMgrR4, *cache.gctx}:
MdtCalibInput{*newDigit, *cache.legacyDetMgr};
const MdtCalibOutput calibResult{m_calibrationTool->calibrate(ctx, calibIn, false)}; const MdtCalibOutput calibResult{m_calibrationTool->calibrate(ctx, calibIn, false)};
std::unique_ptr<MdtPrepData> newPrepData = createPrepData(calibIn, calibResult); std::unique_ptr<MdtPrepData> newPrepData = createPrepData(calibIn, calibResult, cache);
if (!newPrepData) continue; if (newPrepData) {
newPrepData->setHashAndIndex(driftCircleColl->identifyHash(), driftCircleColl->size());
newPrepData->setHashAndIndex(driftCircleColl->identifyHash(), driftCircleColl->size()); driftCircleColl->push_back(std::move(newPrepData));
driftCircleColl->push_back(std::move(newPrepData)); }
createxAODPrepData(calibIn, calibResult, cache.xAODPrd);
if (xAODMdtPrepDataContainer) createxAODPrepData(calibIn, calibResult, xAODMdtPrepDataContainer);
} }
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
bool MdtRdoToPrepDataToolMT::deadBMGChannel(const Identifier& channelId) const { StatusCode MdtRdoToPrepDataToolMT::processCsmTwin(const EventContext& ctx, ConvCache& cache, const MdtCsm* rdoColl) const {
const MdtIdHelper& id_helper = m_idHelperSvc->mdtIdHelper();
if (id_helper.stationName(channelId) != m_BMGid || !m_BMGpresent) return false;
std::map<Identifier, std::set<Identifier>>::const_iterator myIt = m_DeadChannels.find(id_helper.multilayerID(channelId));
if (myIt == m_DeadChannels.end()) { return false; }
if (myIt->second.count(channelId)) {
ATH_MSG_DEBUG("deadBMGChannel : Deleting BMG digit with identifier" << m_idHelperSvc->toString(channelId));
return true;
}
return false;
}
StatusCode MdtRdoToPrepDataToolMT::processCsmTwin(const EventContext& ctx, ModfiablePrdColl& prepDataContainer,
xAOD::MdtDriftCircleContainer* xAODMdtPrepDataContainer, const MdtCsm* rdoColl,
const MuonGM::MuonDetectorManager* muDetMgr) const {
const MdtIdHelper& id_helper = m_idHelperSvc->mdtIdHelper(); const MdtIdHelper& id_helper = m_idHelperSvc->mdtIdHelper();
ATH_MSG_DEBUG(" ***************** Start of processCsmTwin"); ATH_MSG_DEBUG(" ***************** Start of processCsmTwin");
ATH_MSG_DEBUG(" Number of AmtHit in this Csm " << rdoColl->size()); ATH_MSG_DEBUG(" Number of AmtHit in this Csm " << rdoColl->size());
...@@ -536,8 +521,6 @@ namespace Muon { ...@@ -536,8 +521,6 @@ namespace Muon {
// make an Identifier // make an Identifier
Identifier channelId = newDigit->identify(); Identifier channelId = newDigit->identify();
// IdentifierHash channelHash = newDigit->identifyHash();
if (deadBMGChannel(channelId)) continue;
// get tube params // get tube params
int tube = id_helper.tube(channelId); int tube = id_helper.tube(channelId);
...@@ -579,8 +562,7 @@ namespace Muon { ...@@ -579,8 +562,7 @@ namespace Muon {
} }
} // end -- if(!m_discardSecondaryHitTwin){ } // end -- if(!m_discardSecondaryHitTwin){
else { else {
ATH_MSG_DEBUG( ATH_MSG_DEBUG(" TWIN TUBES: discarding secondary(non-twin) hit in a twin tube as flag m_discardSecondaryHitTwin is set to true");
" TWIN TUBES: discarding secondary(non-twin) hit in a twin tube as flag m_discardSecondaryHitTwin is set to true");
} }
} }
} // end for-loop over rdoColl } // end for-loop over rdoColl
...@@ -600,7 +582,7 @@ namespace Muon { ...@@ -600,7 +582,7 @@ namespace Muon {
Identifier channelId = digit->identify(); Identifier channelId = digit->identify();
int multilayer = id_helper.multilayer(channelId); int multilayer = id_helper.multilayer(channelId);
MdtPrepDataCollection* driftCircleColl = prepDataContainer.createCollection(channelId, id_helper, msgStream()); MdtPrepDataCollection* driftCircleColl = cache.createCollection(channelId, msgStream());
if (!driftCircleColl) { if (!driftCircleColl) {
ATH_MSG_DEBUG("Corresponding multi layer " << m_idHelperSvc->toString(channelId) << " is already decoded."); ATH_MSG_DEBUG("Corresponding multi layer " << m_idHelperSvc->toString(channelId) << " is already decoded.");
continue; continue;
...@@ -615,25 +597,31 @@ namespace Muon { ...@@ -615,25 +597,31 @@ namespace Muon {
ATH_MSG_VERBOSE("got digit with id ext / hash " << m_idHelperSvc->toString(channelId) << " / " ATH_MSG_VERBOSE("got digit with id ext / hash " << m_idHelperSvc->toString(channelId) << " / "
<< driftCircleColl->identifyHash()); << driftCircleColl->identifyHash());
const MdtCalibInput mdtCalibIn{*digit, *muDetMgr}; const MdtCalibInput mdtCalibIn = m_useNewGeo ? MdtCalibInput{*digit, *m_detMgrR4, *cache.gctx}:
MdtCalibInput{*digit, *cache.legacyDetMgr};
const MdtCalibOutput mdtCalibOut{m_calibrationTool->calibrate(ctx, mdtCalibIn, false)}; const MdtCalibOutput mdtCalibOut{m_calibrationTool->calibrate(ctx, mdtCalibIn, false)};
// Create new PrepData // Create new PrepData
std::unique_ptr<MdtPrepData> newPrepData = createPrepData(mdtCalibIn, mdtCalibOut); std::unique_ptr<MdtPrepData> newPrepData = createPrepData(mdtCalibIn, mdtCalibOut, cache);
if (!newPrepData) continue; if (newPrepData) {
newPrepData->setHashAndIndex(driftCircleColl->identifyHash(), driftCircleColl->size());
newPrepData->setHashAndIndex(driftCircleColl->identifyHash(), driftCircleColl->size()); driftCircleColl->push_back(std::move(newPrepData));
driftCircleColl->push_back(std::move(newPrepData));
if (xAODMdtPrepDataContainer) createxAODPrepData(mdtCalibIn, mdtCalibOut, xAODMdtPrepDataContainer);
}
createxAODPrepData(mdtCalibIn, mdtCalibOut, cache.xAODPrd);
ATH_MSG_DEBUG(" MADE ORIGINAL PREPDATA " << m_idHelperSvc->toString(channelId) << " " << mdtCalibOut); ATH_MSG_DEBUG(" MADE ORIGINAL PREPDATA " << m_idHelperSvc->toString(channelId) << " " << mdtCalibOut);
continue; continue;
} }
if (digit->is_masked() || second_digit->is_masked()) continue; if (digit->is_masked() || second_digit->is_masked()) {
MdtCalibInput mdtCalib1st{*digit, *muDetMgr}; continue;
MdtCalibInput mdtCalib2nd{*second_digit, *muDetMgr}; }
MdtCalibInput mdtCalib1st = m_useNewGeo ? MdtCalibInput{*digit, *m_detMgrR4, *cache.gctx}
: MdtCalibInput{*digit, *cache.legacyDetMgr};
MdtCalibInput mdtCalib2nd = m_useNewGeo ? MdtCalibInput{*second_digit, *m_detMgrR4, *cache.gctx}
: MdtCalibInput{*second_digit, *cache.legacyDetMgr};
updateClosestApproachTwin(mdtCalib1st); updateClosestApproachTwin(mdtCalib1st);
updateClosestApproachTwin(mdtCalib2nd); updateClosestApproachTwin(mdtCalib2nd);
...@@ -646,7 +634,7 @@ namespace Muon { ...@@ -646,7 +634,7 @@ namespace Muon {
(cov)(0, 1) = 0; (cov)(0, 1) = 0;
(cov)(1, 0) = 0; (cov)(1, 0) = 0;
const MuonGM::MdtReadoutElement* descriptor = mdtCalib1st.legacyDescriptor(); const MuonGM::MdtReadoutElement* descriptor = cache.legacyDetMgr->getMdtReadoutElement(mdtCalib1st.identify());
std::unique_ptr<MdtTwinPrepData> twin_newPrepData = std::make_unique<MdtTwinPrepData>(twinCalib.primaryID(), std::unique_ptr<MdtTwinPrepData> twin_newPrepData = std::make_unique<MdtTwinPrepData>(twinCalib.primaryID(),
descriptor->identifyHash(), descriptor->identifyHash(),
std::move(hitPos), std::move(hitPos),
...@@ -673,35 +661,37 @@ namespace Muon { ...@@ -673,35 +661,37 @@ namespace Muon {
driftCircleColl->push_back(std::move(twin_newPrepData)); driftCircleColl->push_back(std::move(twin_newPrepData));
} // end -- if(multilayer==1) } else {
else if (multilayer == 2) {
// if multilayer=2, then treat every hit as a separate hit, no twin hit should be present here as the hardware is not // if multilayer=2, then treat every hit as a separate hit, no twin hit should be present here as the hardware is not
// installed // installed
const MdtCalibInput calibInput1st{*digit, *muDetMgr}; const MdtCalibInput calibInput1st = m_useNewGeo ? MdtCalibInput{*digit, *m_detMgrR4, *cache.gctx}
: MdtCalibInput{*digit, *cache.legacyDetMgr};
const MdtCalibOutput calibResult1st{m_calibrationTool->calibrate(ctx, calibInput1st, false)}; const MdtCalibOutput calibResult1st{m_calibrationTool->calibrate(ctx, calibInput1st, false)};
// Create new PrepData // Create new PrepData
std::unique_ptr<MdtPrepData> newPrepData = createPrepData(calibInput1st, calibResult1st); std::unique_ptr<MdtPrepData> newPrepData = createPrepData(calibInput1st, calibResult1st, cache);
if (newPrepData) { if (newPrepData) {
newPrepData->setHashAndIndex(driftCircleColl->identifyHash(), driftCircleColl->size()); newPrepData->setHashAndIndex(driftCircleColl->identifyHash(), driftCircleColl->size());
driftCircleColl->push_back(std::move(newPrepData)); driftCircleColl->push_back(std::move(newPrepData));
ATH_MSG_DEBUG(" MADE ORIGINAL PREPDATA " << m_idHelperSvc->toString(channelId) << " "<<calibResult1st); ATH_MSG_DEBUG(" MADE ORIGINAL PREPDATA " << m_idHelperSvc->toString(channelId) << " "<<calibResult1st);
} }
if (xAODMdtPrepDataContainer) createxAODPrepData(calibInput1st, calibResult1st, xAODMdtPrepDataContainer); createxAODPrepData(calibInput1st, calibResult1st, cache.xAODPrd);
if (!second_digit) continue; if (!second_digit) continue;
// Calculate radius // Calculate radius
const MdtCalibInput calibInput2nd{*second_digit, *muDetMgr}; const MdtCalibInput calibInput2nd = m_useNewGeo ? MdtCalibInput{*second_digit, *m_detMgrR4, *cache.gctx}
: MdtCalibInput{*second_digit, *cache.legacyDetMgr};
const MdtCalibOutput calibResult2nd{m_calibrationTool->calibrate(ctx, calibInput2nd, false)}; const MdtCalibOutput calibResult2nd{m_calibrationTool->calibrate(ctx, calibInput2nd, false)};
// second_digit // second_digit
// Create new PrepData // Create new PrepData
std::unique_ptr<MdtPrepData> second_newPrepData = createPrepData(calibInput2nd, calibResult2nd); std::unique_ptr<MdtPrepData> second_newPrepData = createPrepData(calibInput2nd, calibResult2nd, cache);
if (!second_newPrepData) continue; if (second_newPrepData) {
second_newPrepData->setHashAndIndex(driftCircleColl->identifyHash(), driftCircleColl->size()); second_newPrepData->setHashAndIndex(driftCircleColl->identifyHash(), driftCircleColl->size());
driftCircleColl->push_back(std::move(second_newPrepData)); driftCircleColl->push_back(std::move(second_newPrepData));
if (xAODMdtPrepDataContainer) createxAODPrepData(calibInput2nd, calibResult2nd, xAODMdtPrepDataContainer); }
createxAODPrepData(calibInput2nd, calibResult2nd, cache.xAODPrd);
// second_digit // second_digit
ATH_MSG_DEBUG(" MADE ORIGINAL PREPDATA FOR SECOND DIGIT " ATH_MSG_DEBUG(" MADE ORIGINAL PREPDATA FOR SECOND DIGIT "
...@@ -723,7 +713,6 @@ namespace Muon { ...@@ -723,7 +713,6 @@ namespace Muon {
const Identifier detElId = mydetEl->identify(); const Identifier detElId = mydetEl->identify();
const int ml = mydetEl->getMultilayer(); const int ml = mydetEl->getMultilayer();
std::set<Identifier>& deadTubes{m_DeadChannels[detElId]};
std::vector<int>::iterator it = tubes.begin(); std::vector<int>::iterator it = tubes.begin();
for (int layer = 1; layer <= mydetEl->getNLayers(); layer++) { for (int layer = 1; layer <= mydetEl->getNLayers(); layer++) {
for (int tube = 1; tube <= mydetEl->getNtubesperlayer(); tube++) { for (int tube = 1; tube <= mydetEl->getNtubesperlayer(); tube++) {
...@@ -736,7 +725,7 @@ namespace Muon { ...@@ -736,7 +725,7 @@ namespace Muon {
++it; ++it;
} else { } else {
Identifier deadTubeId = m_idHelperSvc->mdtIdHelper().channelID(detElId, ml, layer, tube); Identifier deadTubeId = m_idHelperSvc->mdtIdHelper().channelID(detElId, ml, layer, tube);
deadTubes.insert(deadTubeId); m_DeadChannels.insert(deadTubeId);
ATH_MSG_VERBOSE("adding dead tube "<<m_idHelperSvc->toString(deadTubeId)); ATH_MSG_VERBOSE("adding dead tube "<<m_idHelperSvc->toString(deadTubeId));
} }
} }
...@@ -744,49 +733,68 @@ namespace Muon { ...@@ -744,49 +733,68 @@ namespace Muon {
} }
} }
MdtRdoToPrepDataToolMT::ModfiablePrdColl MdtRdoToPrepDataToolMT::setupMdtPrepDataContainer(const EventContext& ctx) const { MdtRdoToPrepDataToolMT::ConvCache MdtRdoToPrepDataToolMT::setupMdtPrepDataContainer(const EventContext& ctx) const {
SG::WriteHandle<MdtPrepDataContainer> handle{m_mdtPrepDataContainerKey, ctx};
ConvCache cache{m_idHelperSvc.get()};
SG::WriteHandle<MdtPrepDataContainer> handle{m_mdtPrepDataContainerKey, ctx};
// Caching of PRD container // Caching of PRD container
if (m_prdContainerCacheKey.key().empty()) { if (m_prdContainerCacheKey.key().empty()) {
// without the cache we just record the container // without the cache we just record the container
StatusCode status = handle.record(std::make_unique<MdtPrepDataContainer>(m_idHelperSvc->mdtIdHelper().module_hash_max())); StatusCode status = handle.record(std::make_unique<MdtPrepDataContainer>(m_idHelperSvc->mdtIdHelper().module_hash_max()));
if (status.isFailure() || !handle.isValid()) { if (status.isFailure() || !handle.isValid()) {
ATH_MSG_FATAL("Could not record container of MDT PrepData Container at " << m_mdtPrepDataContainerKey.key()); ATH_MSG_FATAL("Could not record container of MDT PrepData Container at " << m_mdtPrepDataContainerKey.key());
return ModfiablePrdColl{}; return cache;
} }
ATH_MSG_DEBUG("Created container " << m_mdtPrepDataContainerKey.key()); ATH_MSG_VERBOSE("Created container " << m_mdtPrepDataContainerKey.key());
cache.legacyPrd = handle.ptr();
} else { } else {
// use the cache to get the container // use the cache to get the container
SG::UpdateHandle<MdtPrepDataCollection_Cache> update{m_prdContainerCacheKey, ctx}; SG::UpdateHandle<MdtPrepDataCollection_Cache> update{m_prdContainerCacheKey, ctx};
if (!update.isValid()) { if (!update.isValid()) {
ATH_MSG_FATAL("Invalid UpdateHandle " << m_prdContainerCacheKey.key()); ATH_MSG_FATAL("Invalid UpdateHandle " << m_prdContainerCacheKey.key());
return ModfiablePrdColl{}; return cache;
} }
StatusCode status = handle.record(std::make_unique<MdtPrepDataContainer>(update.ptr())); StatusCode status = handle.record(std::make_unique<MdtPrepDataContainer>(update.ptr()));
if (status.isFailure() || !handle.isValid()) { if (status.isFailure() || !handle.isValid()) {
ATH_MSG_FATAL("Could not record container of MDT PrepData Container using cache " << m_prdContainerCacheKey.key() << " - " ATH_MSG_FATAL("Could not record container of MDT PrepData Container using cache " << m_prdContainerCacheKey.key() << " - "
<< m_mdtPrepDataContainerKey.key()); << m_mdtPrepDataContainerKey.key());
return ModfiablePrdColl{}; return cache;
}
ATH_MSG_VERBOSE("Created container using cache for " << m_prdContainerCacheKey.key());
cache.legacyPrd = handle.ptr();
}
if (!m_mdtxAODKey.empty()) {
SG::WriteHandle<xAOD::MdtDriftCircleContainer> writeHandle{m_mdtxAODKey, ctx};
if (!writeHandle.recordNonConst(std::make_unique<xAOD::MdtDriftCircleContainer>(),
std::make_unique<xAOD::MdtDriftCircleAuxContainer>()).isSuccess() ||
!writeHandle.isValid()) {
ATH_MSG_FATAL("Failed to write xAOD::MdtPrepDataContainer "<<m_mdtxAODKey.fullKey());
return cache;
} }
ATH_MSG_DEBUG("Created container using cache for " << m_prdContainerCacheKey.key()); cache.xAODPrd = writeHandle.ptr();
}
/// Retrieve the Geometry context if activated
if (!m_geoCtxKey.empty()) {
SG::ReadHandle<ActsGeometryContext> readHandle{m_geoCtxKey, ctx};
if (!readHandle.isPresent()) {
ATH_MSG_FATAL("Failed to retrieve the geometry context "<<m_geoCtxKey.fullKey());
return cache;
}
cache.gctx = readHandle.cptr();
}
/// Retrieve the legacy detector mananger if activated
if (!m_muDetMgrKey.empty()) {
SG::ReadCondHandle<MuonGM::MuonDetectorManager> detMgrHandle{m_muDetMgrKey, ctx};
if (!detMgrHandle.isValid()) {
ATH_MSG_FATAL("Failed to retrieve the detector manager from the conditions store "<<m_muDetMgrKey.fullKey());
return cache;
}
cache.legacyDetMgr = detMgrHandle.cptr();
} }
// Pass the container from the handle // Pass the container from the handle
return ModfiablePrdColl{handle.ptr()}; cache.isValid = true;
} return cache;
xAOD::MdtDriftCircleContainer*
MdtRdoToPrepDataToolMT::setupxAODMdtPrepDataContainer(SG::WriteHandle<xAOD::MdtDriftCircleContainer>& outputContainer) const {
if (!m_mdtxAODKey.empty() &&
outputContainer.record(std::make_unique<xAOD::MdtDriftCircleContainer>(),
std::make_unique<xAOD::MdtDriftCircleAuxContainer>())
.isSuccess()) {
ATH_MSG_DEBUG(
"Recorded xAOD container with key: " << outputContainer.key());
return outputContainer.ptr();
}
return nullptr;
} }
void Muon::MdtRdoToPrepDataToolMT::printPrepData(const EventContext& ctx ) const { void Muon::MdtRdoToPrepDataToolMT::printPrepData(const EventContext& ctx ) const {
......
/* /*
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/ */
#ifndef MUONMdtRdoToPrepDataToolMT_H #ifndef MUONMdtRdoToPrepDataToolMT_H
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "StoreGate/ReadCondHandleKey.h" #include "StoreGate/ReadCondHandleKey.h"
#include "xAODMuonPrepData/MdtDriftCircleContainer.h" #include "xAODMuonPrepData/MdtDriftCircleContainer.h"
#include "MuonReadoutGeometryR4/MuonDetectorManager.h"
class MdtDigit; class MdtDigit;
class MdtCalibHit; class MdtCalibHit;
...@@ -61,75 +63,86 @@ namespace Muon { ...@@ -61,75 +63,86 @@ namespace Muon {
/// method to get the twin tube 2nd coordinate /// method to get the twin tube 2nd coordinate
Muon::MdtDriftCircleStatus getMdtTwinPosition(const MdtDigit& prompt_digit, const MdtDigit& twin_digit, double& radius, Muon::MdtDriftCircleStatus getMdtTwinPosition(const MdtDigit& prompt_digit, const MdtDigit& twin_digit, double& radius,
double& errRadius, double& zTwin, double& errZTwin, bool& twinIsPrompt, double& errRadius, double& zTwin, double& errZTwin, bool& twinIsPrompt) const;
const MuonGM::MuonDetectorManager* muDetMgr) const;
// decode method for Rob based readout // decode method for Rob based readout
StatusCode decode(const EventContext& ctx, const std::vector<IdentifierHash>& multiLayerHashInRobs) const; StatusCode decode(const EventContext& ctx, const std::vector<IdentifierHash>& multiLayerHashInRobs) const;
/// Helper struct to steer which collections were added by /// Helper struct to parse the event data around the tool
/// this tool and which already existed before hand struct ConvCache {
struct ModfiablePrdColl { ConvCache(const Muon::IMuonIdHelperSvc* idHelperSvc):
ModfiablePrdColl() = default; m_idHelperSvc{idHelperSvc}{}
ModfiablePrdColl(Muon::MdtPrepDataContainer* cont) : prd_cont{cont} {}
/// Creates a new MdtPrepDataCollection, if it's neccessary /// Creates a new MdtPrepDataCollection, if it's neccessary
/// and also possible. Nullptr is returned if the collection /// and also possible. Nullptr is returned if the collection
/// cannot be modified /// cannot be modified
MdtPrepDataCollection* createCollection(const Identifier& id, const MdtIdHelper& id_helper, MsgStream& msg); MdtPrepDataCollection* createCollection(const Identifier& id, MsgStream& msg);
/// Copy the non-empty collections into the created prd container. Fill the id_hash vector with /// Copy the non-empty collections into the created prd container. Fill the id_hash vector with
/// the corresponding hashes /// the corresponding hashes
StatusCode finalize(std::vector<IdentifierHash>& id_hash, MsgStream& msg); StatusCode finalize(std::vector<IdentifierHash>& id_hash, MsgStream& msg);
Muon::MdtPrepDataContainer* prd_cont{nullptr}; Muon::MdtPrepDataContainer* legacyPrd{nullptr};
xAOD::MdtDriftCircleContainer* xAODPrd{nullptr};
const Muon::IMuonIdHelperSvc* m_idHelperSvc{nullptr};
/// Detector manager from the conditions store
const MuonGM::MuonDetectorManager* legacyDetMgr{nullptr};
/// Acts Geometry context
const ActsGeometryContext* gctx{nullptr};
/// Flag set to indicate that the complete validation was successful
bool isValid{false};
using PrdCollMap = std::map<IdentifierHash, std::unique_ptr<MdtPrepDataCollection>>; using PrdCollMap = std::unordered_map<IdentifierHash, std::unique_ptr<MdtPrepDataCollection>>;
PrdCollMap addedCols{}; PrdCollMap addedCols{};
}; };
StatusCode processCsm(const EventContext& ctx, ModfiablePrdColl& mdtPrepDataContainer, xAOD::MdtDriftCircleContainer* xAODMdtPrepDataContainer, const MdtCsm* rdoColl, StatusCode processCsm(const EventContext& ctx, ConvCache& mdtPrepDataContainer,
const MuonGM::MuonDetectorManager* muDetMgr) const; const MdtCsm* rdoColl) const;
StatusCode processCsmTwin(const EventContext& ctx, ModfiablePrdColl& mdtPrepDataContainer, xAOD::MdtDriftCircleContainer* xAODMdtPrepDataContainer, const MdtCsm* rdoColll, StatusCode processCsmTwin(const EventContext& ctx,
const MuonGM::MuonDetectorManager* muDetMgr) const; ConvCache& mdtPrepDataContainer,
const MdtCsm* rdoColll) const;
/// Creates the PRD object /// Creates the PRD object
std::unique_ptr<MdtPrepData> createPrepData(const MdtCalibInput& calibInput, std::unique_ptr<MdtPrepData> createPrepData(const MdtCalibInput& calibInput,
const MdtCalibOutput& calibOutput) const; const MdtCalibOutput& calibOutput,
ConvCache& cache) const;
/// Creates the xAOD PRD object /// Creates the xAOD PRD object
void createxAODPrepData(const MdtCalibInput& calibInput, void createxAODPrepData(const MdtCalibInput& calibInput,
const MdtCalibOutput& calibOutput, const MdtCalibOutput& calibOutput,
xAOD::MdtDriftCircleContainer* xAODMdtPrepDataContainer) const; xAOD::MdtDriftCircleContainer* xAODMdtPrepDataContainer) const;
/// Creates the prep data container to be written /// Creates the prep data container to be written
ModfiablePrdColl setupMdtPrepDataContainer(const EventContext& ctx) const; ConvCache setupMdtPrepDataContainer(const EventContext& ctx) const;
/// Creates the xAOD PRD container to be written
xAOD::MdtDriftCircleContainer* setupxAODMdtPrepDataContainer(SG::WriteHandle<xAOD::MdtDriftCircleContainer>& outputContainer) const;
/// Is the identifier disabled due to BMG cut outs
bool deadBMGChannel(const Identifier& channelId) const;
/// Loads the input RDO container from StoreGate /// Loads the input RDO container from StoreGate
const MdtCsmContainer* getRdoContainer(const EventContext& ctx) const; const MdtCsmContainer* getRdoContainer(const EventContext& ctx) const;
void processPRDHashes(const EventContext& ctx, ModfiablePrdColl& mdtPrepDataContainer, void processPRDHashes(const EventContext& ctx, ConvCache& mdtPrepDataContainer,
xAOD::MdtDriftCircleContainer* xAODMdtPrepDataContainer,
const std::vector<IdentifierHash>& chamberHashInRobs) const; const std::vector<IdentifierHash>& chamberHashInRobs) const;
bool handlePRDHash(const EventContext& ctx, ModfiablePrdColl& mdtPrepDataContainer, bool handlePRDHash(const EventContext& ctx, ConvCache& mdtPrepDataContainer,
xAOD::MdtDriftCircleContainer* xAODMdtPrepDataContainer, IdentifierHash rdoHash) const;
IdentifierHash rdoHash) const;
ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc{this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc{this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
/// MDT calibration service /// MDT calibration service
ToolHandle<IMdtCalibrationTool> m_calibrationTool{this, "CalibrationTool", "MdtCalibrationTool"}; ToolHandle<IMdtCalibrationTool> m_calibrationTool{this, "CalibrationTool", "MdtCalibrationTool"};
Gaudi::Property<bool> m_useNewGeo{this, "UseR4DetMgr", false,
"Switch between the legacy and the new geometry"};
const MuonGMR4::MuonDetectorManager* m_detMgrR4{nullptr};
SG::ReadHandleKey<ActsGeometryContext> m_geoCtxKey{this, "AlignmentKey", "ActsAlignment", "Stored alignment"};
/// MdtPrepRawData containers /// MdtPrepRawData containers
SG::WriteHandleKey<Muon::MdtPrepDataContainer> m_mdtPrepDataContainerKey{this, "OutputCollection", "MDT_DriftCircles"}; SG::WriteHandleKey<Muon::MdtPrepDataContainer> m_mdtPrepDataContainerKey{this, "OutputCollection", "MDT_DriftCircles"};
SG::ReadHandleKey<MdtCsmContainer> m_rdoContainerKey{this, "RDOContainer", "MDTCSM"}; SG::ReadHandleKey<MdtCsmContainer> m_rdoContainerKey{this, "RDOContainer", "MDTCSM"};
/** member variables for algorithm properties: */ /** member variables for algorithm properties: */
Gaudi::Property<int> m_adcCut{this, "AdcCut", 50, Gaudi::Property<int> m_adcCut{this, "AdcCut", 50,
...@@ -152,7 +165,7 @@ namespace Muon { ...@@ -152,7 +165,7 @@ namespace Muon {
int m_secondaryHit_twin_chamber[2][3][36]{}; int m_secondaryHit_twin_chamber[2][3][36]{};
// - TWIN TUBE // - TWIN TUBE
std::map<Identifier, std::set<Identifier>> m_DeadChannels{}; std::unordered_set<Identifier> m_DeadChannels{};
void initDeadChannels(const MuonGM::MdtReadoutElement* mydetEl); void initDeadChannels(const MuonGM::MdtReadoutElement* mydetEl);
SG::ReadCondHandleKey<MuonMDT_CablingMap> m_readKey{this, "ReadKey", "MuonMDT_CablingMap", "Key of MuonMDT_CablingMap"}; SG::ReadCondHandleKey<MuonMDT_CablingMap> m_readKey{this, "ReadKey", "MuonMDT_CablingMap", "Key of MuonMDT_CablingMap"};
...@@ -164,7 +177,7 @@ namespace Muon { ...@@ -164,7 +177,7 @@ namespace Muon {
"Optional external cache for the MDT PRD container"}; "Optional external cache for the MDT PRD container"};
// xAOD PRDs // xAOD PRDs
SG::WriteHandleKey<xAOD::MdtDriftCircleContainer> m_mdtxAODKey {this, "MdtxAODKey", "", "If empty, do not produce xAOD, otherwise this is the key of the output xAOD MDT PRD container"}; SG::WriteHandleKey<xAOD::MdtDriftCircleContainer> m_mdtxAODKey{this, "MdtxAODKey", "", "If empty, do not produce xAOD, otherwise this is the key of the output xAOD MDT PRD container"};
}; };
} // namespace Muon } // namespace Muon
......
...@@ -211,8 +211,10 @@ def MdtRDODecodeCfg(flags, name="MdtRdoToMdtPrepData", RDOContainer = None, **kw ...@@ -211,8 +211,10 @@ def MdtRDODecodeCfg(flags, name="MdtRdoToMdtPrepData", RDOContainer = None, **kw
acc.merge(MDTCablingConfigCfg(flags)) acc.merge(MDTCablingConfigCfg(flags))
tool_kwargs = {} tool_kwargs = {}
tool_kwargs["MdtxAODKey"] = "MDT_DriftCircles" if flags.Muon.writexAODPRD else "" tool_kwargs["MdtxAODKey"] = "xAODMdtCircles" if flags.Muon.writexAODPRD or flags.Muon.usePhaseIIGeoSetup else ""
tool_kwargs["UseTwin"] = True ### Disable the twin tubes in the Phase II geometry setup
tool_kwargs["UseTwin"] = not flags.Muon.usePhaseIIGeoSetup
tool_kwargs["UseR4DetMgr"] = flags.Muon.usePhaseIIGeoSetup
tool_kwargs["CalibrationTool"] = acc.popToolsAndMerge(MdtCalibrationToolCfg(flags, TimeWindowSetting = 2, DoPropagationCorrection = False)) tool_kwargs["CalibrationTool"] = acc.popToolsAndMerge(MdtCalibrationToolCfg(flags, TimeWindowSetting = 2, DoPropagationCorrection = False))
if RDOContainer: tool_kwargs["RDOContainer"] = RDOContainer if RDOContainer: tool_kwargs["RDOContainer"] = RDOContainer
# Get the RDO -> PRD tool # Get the RDO -> PRD tool
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment