From 8a56f020475bafde5ccade8130652258a11c19fc Mon Sep 17 00:00:00 2001 From: pillot Date: Fri, 22 Mar 2024 12:31:17 +0100 Subject: [PATCH] add functionality and protections in MCH mapping --- .../MUON/MCH/GlobalMapping/CMakeLists.txt | 1 + .../MUON/MCH/GlobalMapping/src/DsIndex.cxx | 27 +++++++++++++++---- .../Impl4/src/CathodeSegmentationImpl4.cxx | 13 +++++++-- .../Impl4/src/CathodeSegmentationImpl4.h | 4 ++- .../MCHMappingInterface/Segmentation.h | 11 +++++--- .../MCHMappingInterface/Segmentation.inl | 14 ++++++++++ 6 files changed, 58 insertions(+), 12 deletions(-) diff --git a/Detectors/MUON/MCH/GlobalMapping/CMakeLists.txt b/Detectors/MUON/MCH/GlobalMapping/CMakeLists.txt index 5191a9ab72713..335f5245a8f29 100644 --- a/Detectors/MUON/MCH/GlobalMapping/CMakeLists.txt +++ b/Detectors/MUON/MCH/GlobalMapping/CMakeLists.txt @@ -21,6 +21,7 @@ o2_add_library(MCHGlobalMapping PUBLIC_LINK_LIBRARIES O2::MCHRawElecMap O2::MCHMappingInterface O2::MCHConditions + O2::Framework PRIVATE_LINK_LIBRARIES O2::MCHConstants) o2_target_root_dictionary(MCHGlobalMapping diff --git a/Detectors/MUON/MCH/GlobalMapping/src/DsIndex.cxx b/Detectors/MUON/MCH/GlobalMapping/src/DsIndex.cxx index faf9949ad6f2d..ac11defff938c 100644 --- a/Detectors/MUON/MCH/GlobalMapping/src/DsIndex.cxx +++ b/Detectors/MUON/MCH/GlobalMapping/src/DsIndex.cxx @@ -12,7 +12,10 @@ #include "MCHGlobalMapping/DsIndex.h" #include +#include #include + +#include "Framework/Logger.h" #include "MCHMappingInterface/Segmentation.h" namespace o2::mch @@ -38,12 +41,16 @@ uint8_t numberOfDualSampaChannels(DsIndex dsIndex) auto dsId = det.dsId(); auto deId = det.deId(); const auto& seg = o2::mch::mapping::segmentation(deId); - seg.bending().forEachPadInDualSampa(dsId, [&nch](int /*catPadIndex*/) { ++nch; }); - seg.nonBending().forEachPadInDualSampa(dsId, [&nch](int /*catPadIndex*/) { ++nch; }); + seg.forEachPadInDualSampa(dsId, [&nch](int /*dePadIndex*/) { ++nch; }); channelsPerDS.emplace_back(nch); } } - return channelsPerDS[dsIndex]; + if (dsIndex < o2::mch::NumberOfDualSampas) { + return channelsPerDS[dsIndex]; + } else { + LOGP(error, "invalid Dual Sampa index: {}", dsIndex); + } + return 0; } std::map buildDetId2DsIndexMap() @@ -72,13 +79,23 @@ std::map buildDetId2DsIndexMap() DsIndex getDsIndex(const o2::mch::raw::DsDetId& dsDetId) { static std::map m = buildDetId2DsIndexMap(); - return m[encode(dsDetId)]; + try { + return m.at(encode(dsDetId)); + } catch (const std::exception&) { + LOGP(error, "invalid Dual Sampa Id: {}", raw::asString(dsDetId)); + } + return NumberOfDualSampas; } o2::mch::raw::DsDetId getDsDetId(DsIndex dsIndex) { static std::map m = inverseMap(buildDetId2DsIndexMap()); - return raw::decodeDsDetId(m[dsIndex]); + try { + return raw::decodeDsDetId(m.at(dsIndex)); + } catch (const std::exception&) { + LOGP(error, "invalid Dual Sampa index: {}", dsIndex); + } + return raw::DsDetId(0, 0); } } // namespace o2::mch diff --git a/Detectors/MUON/MCH/Mapping/Impl4/src/CathodeSegmentationImpl4.cxx b/Detectors/MUON/MCH/Mapping/Impl4/src/CathodeSegmentationImpl4.cxx index d79f953f5b323..e17c5457ca26e 100644 --- a/Detectors/MUON/MCH/Mapping/Impl4/src/CathodeSegmentationImpl4.cxx +++ b/Detectors/MUON/MCH/Mapping/Impl4/src/CathodeSegmentationImpl4.cxx @@ -126,11 +126,11 @@ CathodeSegmentation::CathodeSegmentation( { fillRtree(); for (auto dualSampaId : mDualSampaIds) { - mDualSampaId2CatPadIndices.emplace(dualSampaId, getCatPadIndices(dualSampaId)); + mDualSampaId2CatPadIndices.emplace(dualSampaId, catPadIndices(dualSampaId)); } } -std::vector CathodeSegmentation::getCatPadIndices(int dualSampaId) const +std::vector CathodeSegmentation::catPadIndices(int dualSampaId) const { std::vector pi; @@ -147,6 +147,15 @@ std::vector CathodeSegmentation::getCatPadIndices(int dualSampaId) const return pi; } +std::vector CathodeSegmentation::getCatPadIndices(int dualSampaId) const +{ + auto it = mDualSampaId2CatPadIndices.find(dualSampaId); + if (it == mDualSampaId2CatPadIndices.end()) { + return {}; + } + return it->second; +} + std::vector CathodeSegmentation::getCatPadIndices(double xmin, double ymin, double xmax, double ymax) const diff --git a/Detectors/MUON/MCH/Mapping/Impl4/src/CathodeSegmentationImpl4.h b/Detectors/MUON/MCH/Mapping/Impl4/src/CathodeSegmentationImpl4.h index 3482bf6b3fbee..a20f341a7afb7 100644 --- a/Detectors/MUON/MCH/Mapping/Impl4/src/CathodeSegmentationImpl4.h +++ b/Detectors/MUON/MCH/Mapping/Impl4/src/CathodeSegmentationImpl4.h @@ -48,7 +48,7 @@ class CathodeSegmentation std::vector> padSizes); /// Return the list of catPadIndices for the pads of the given dual sampa. - std::vector getCatPadIndices(int dualSampaIds) const; + std::vector getCatPadIndices(int dualSampaId) const; /// Return the list of catPadIndices for the pads contained in the box /// {xmin,ymin,xmax,ymax}. @@ -105,6 +105,8 @@ class CathodeSegmentation double squaredDistance(int catPadIndex, double x, double y) const; + std::vector catPadIndices(int dualSampaId) const; + private: int mSegType; bool mIsBendingPlane; diff --git a/Detectors/MUON/MCH/Mapping/Interface/include/MCHMappingInterface/Segmentation.h b/Detectors/MUON/MCH/Mapping/Interface/include/MCHMappingInterface/Segmentation.h index dfd0c391f56fa..320742718646c 100644 --- a/Detectors/MUON/MCH/Mapping/Interface/include/MCHMappingInterface/Segmentation.h +++ b/Detectors/MUON/MCH/Mapping/Interface/include/MCHMappingInterface/Segmentation.h @@ -78,7 +78,7 @@ class Segmentation * Validity of the returned value can be tested using isValid() */ ///@{ - /** Find the pads at position (x,y) (in cm). + /** Find the pads at position (x,y) (in cm). Returns true is the bpad and nbpad has been filled with a valid dePadIndex, false otherwise (if position is outside the segmentation area). @param bpad the dePadIndex of the bending pad at position (x,y) @@ -116,6 +116,9 @@ class Segmentation template void forEachPad(CALLABLE&& func) const; + template + void forEachPadInDualSampa(int dualSampaId, CALLABLE&& func) const; + template void forEachNeighbouringPad(int dePadIndex, CALLABLE&& func) const; @@ -123,9 +126,9 @@ class Segmentation void forEachPadInArea(double xmin, double ymin, double xmax, double ymax, CALLABLE&& func) const; ///@} - /** @name Access to individual cathode segmentations. - * Not needed in most cases. - */ + /** @name Access to individual cathode segmentations. + * Not needed in most cases. + */ ///@{ const CathodeSegmentation& bending() const; const CathodeSegmentation& nonBending() const; diff --git a/Detectors/MUON/MCH/Mapping/Interface/include/MCHMappingInterface/Segmentation.inl b/Detectors/MUON/MCH/Mapping/Interface/include/MCHMappingInterface/Segmentation.inl index 717ed8fb72128..76582bdb9b5bf 100644 --- a/Detectors/MUON/MCH/Mapping/Interface/include/MCHMappingInterface/Segmentation.inl +++ b/Detectors/MUON/MCH/Mapping/Interface/include/MCHMappingInterface/Segmentation.inl @@ -121,6 +121,20 @@ void Segmentation::forEachPad(CALLABLE&& func) const }); } +template +void Segmentation::forEachPadInDualSampa(int dualSampaId, CALLABLE&& func) const +{ + bool isBending = dualSampaId < 1024; + if (isBending) { + mBending.forEachPadInDualSampa(dualSampaId, func); + } else { + int offset{mPadIndexOffset}; + mNonBending.forEachPadInDualSampa(dualSampaId, [&offset, &func](int catPadIndex) { + func(catPadIndex + offset); + }); + } +} + template void Segmentation::forEachPadInArea(double xmin, double ymin, double xmax, double ymax, CALLABLE&& func) const {