Skip to content

Commit 3d6b080

Browse files
pillotalcaliva
authored andcommitted
add functionality and protections in MCH mapping (#12913)
1 parent ea2a224 commit 3d6b080

File tree

6 files changed

+58
-12
lines changed

6 files changed

+58
-12
lines changed

Detectors/MUON/MCH/GlobalMapping/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ o2_add_library(MCHGlobalMapping
2121
PUBLIC_LINK_LIBRARIES O2::MCHRawElecMap
2222
O2::MCHMappingInterface
2323
O2::MCHConditions
24+
O2::Framework
2425
PRIVATE_LINK_LIBRARIES O2::MCHConstants)
2526

2627
o2_target_root_dictionary(MCHGlobalMapping

Detectors/MUON/MCH/GlobalMapping/src/DsIndex.cxx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
#include "MCHGlobalMapping/DsIndex.h"
1313

1414
#include <map>
15+
#include <stdexcept>
1516
#include <vector>
17+
18+
#include "Framework/Logger.h"
1619
#include "MCHMappingInterface/Segmentation.h"
1720

1821
namespace o2::mch
@@ -38,12 +41,16 @@ uint8_t numberOfDualSampaChannels(DsIndex dsIndex)
3841
auto dsId = det.dsId();
3942
auto deId = det.deId();
4043
const auto& seg = o2::mch::mapping::segmentation(deId);
41-
seg.bending().forEachPadInDualSampa(dsId, [&nch](int /*catPadIndex*/) { ++nch; });
42-
seg.nonBending().forEachPadInDualSampa(dsId, [&nch](int /*catPadIndex*/) { ++nch; });
44+
seg.forEachPadInDualSampa(dsId, [&nch](int /*dePadIndex*/) { ++nch; });
4345
channelsPerDS.emplace_back(nch);
4446
}
4547
}
46-
return channelsPerDS[dsIndex];
48+
if (dsIndex < o2::mch::NumberOfDualSampas) {
49+
return channelsPerDS[dsIndex];
50+
} else {
51+
LOGP(error, "invalid Dual Sampa index: {}", dsIndex);
52+
}
53+
return 0;
4754
}
4855

4956
std::map<uint32_t, uint16_t> buildDetId2DsIndexMap()
@@ -72,13 +79,23 @@ std::map<uint32_t, uint16_t> buildDetId2DsIndexMap()
7279
DsIndex getDsIndex(const o2::mch::raw::DsDetId& dsDetId)
7380
{
7481
static std::map<uint32_t, uint16_t> m = buildDetId2DsIndexMap();
75-
return m[encode(dsDetId)];
82+
try {
83+
return m.at(encode(dsDetId));
84+
} catch (const std::exception&) {
85+
LOGP(error, "invalid Dual Sampa Id: {}", raw::asString(dsDetId));
86+
}
87+
return NumberOfDualSampas;
7688
}
7789

7890
o2::mch::raw::DsDetId getDsDetId(DsIndex dsIndex)
7991
{
8092
static std::map<uint16_t, uint32_t> m = inverseMap(buildDetId2DsIndexMap());
81-
return raw::decodeDsDetId(m[dsIndex]);
93+
try {
94+
return raw::decodeDsDetId(m.at(dsIndex));
95+
} catch (const std::exception&) {
96+
LOGP(error, "invalid Dual Sampa index: {}", dsIndex);
97+
}
98+
return raw::DsDetId(0, 0);
8299
}
83100

84101
} // namespace o2::mch

Detectors/MUON/MCH/Mapping/Impl4/src/CathodeSegmentationImpl4.cxx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ CathodeSegmentation::CathodeSegmentation(
126126
{
127127
fillRtree();
128128
for (auto dualSampaId : mDualSampaIds) {
129-
mDualSampaId2CatPadIndices.emplace(dualSampaId, getCatPadIndices(dualSampaId));
129+
mDualSampaId2CatPadIndices.emplace(dualSampaId, catPadIndices(dualSampaId));
130130
}
131131
}
132132

133-
std::vector<int> CathodeSegmentation::getCatPadIndices(int dualSampaId) const
133+
std::vector<int> CathodeSegmentation::catPadIndices(int dualSampaId) const
134134
{
135135
std::vector<int> pi;
136136

@@ -147,6 +147,15 @@ std::vector<int> CathodeSegmentation::getCatPadIndices(int dualSampaId) const
147147
return pi;
148148
}
149149

150+
std::vector<int> CathodeSegmentation::getCatPadIndices(int dualSampaId) const
151+
{
152+
auto it = mDualSampaId2CatPadIndices.find(dualSampaId);
153+
if (it == mDualSampaId2CatPadIndices.end()) {
154+
return {};
155+
}
156+
return it->second;
157+
}
158+
150159
std::vector<int> CathodeSegmentation::getCatPadIndices(double xmin, double ymin,
151160
double xmax,
152161
double ymax) const

Detectors/MUON/MCH/Mapping/Impl4/src/CathodeSegmentationImpl4.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class CathodeSegmentation
4848
std::vector<std::pair<float, float>> padSizes);
4949

5050
/// Return the list of catPadIndices for the pads of the given dual sampa.
51-
std::vector<int> getCatPadIndices(int dualSampaIds) const;
51+
std::vector<int> getCatPadIndices(int dualSampaId) const;
5252

5353
/// Return the list of catPadIndices for the pads contained in the box
5454
/// {xmin,ymin,xmax,ymax}.
@@ -105,6 +105,8 @@ class CathodeSegmentation
105105

106106
double squaredDistance(int catPadIndex, double x, double y) const;
107107

108+
std::vector<int> catPadIndices(int dualSampaId) const;
109+
108110
private:
109111
int mSegType;
110112
bool mIsBendingPlane;

Detectors/MUON/MCH/Mapping/Interface/include/MCHMappingInterface/Segmentation.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Segmentation
7878
* Validity of the returned value can be tested using isValid()
7979
*/
8080
///@{
81-
/** Find the pads at position (x,y) (in cm).
81+
/** Find the pads at position (x,y) (in cm).
8282
Returns true is the bpad and nbpad has been filled with a valid dePadIndex,
8383
false otherwise (if position is outside the segmentation area).
8484
@param bpad the dePadIndex of the bending pad at position (x,y)
@@ -116,16 +116,19 @@ class Segmentation
116116
template <typename CALLABLE>
117117
void forEachPad(CALLABLE&& func) const;
118118

119+
template <typename CALLABLE>
120+
void forEachPadInDualSampa(int dualSampaId, CALLABLE&& func) const;
121+
119122
template <typename CALLABLE>
120123
void forEachNeighbouringPad(int dePadIndex, CALLABLE&& func) const;
121124

122125
template <typename CALLABLE>
123126
void forEachPadInArea(double xmin, double ymin, double xmax, double ymax, CALLABLE&& func) const;
124127
///@}
125128

126-
/** @name Access to individual cathode segmentations.
127-
* Not needed in most cases.
128-
*/
129+
/** @name Access to individual cathode segmentations.
130+
* Not needed in most cases.
131+
*/
129132
///@{
130133
const CathodeSegmentation& bending() const;
131134
const CathodeSegmentation& nonBending() const;

Detectors/MUON/MCH/Mapping/Interface/include/MCHMappingInterface/Segmentation.inl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ void Segmentation::forEachPad(CALLABLE&& func) const
121121
});
122122
}
123123

124+
template <typename CALLABLE>
125+
void Segmentation::forEachPadInDualSampa(int dualSampaId, CALLABLE&& func) const
126+
{
127+
bool isBending = dualSampaId < 1024;
128+
if (isBending) {
129+
mBending.forEachPadInDualSampa(dualSampaId, func);
130+
} else {
131+
int offset{mPadIndexOffset};
132+
mNonBending.forEachPadInDualSampa(dualSampaId, [&offset, &func](int catPadIndex) {
133+
func(catPadIndex + offset);
134+
});
135+
}
136+
}
137+
124138
template <typename CALLABLE>
125139
void Segmentation::forEachPadInArea(double xmin, double ymin, double xmax, double ymax, CALLABLE&& func) const
126140
{

0 commit comments

Comments
 (0)