Skip to content

Commit e175df4

Browse files
aphecetchealcaliva
authored andcommitted
MCH: add some getDsIndices convenience functions (#12406)
1 parent 7ad5ac3 commit e175df4

File tree

3 files changed

+113
-41
lines changed

3 files changed

+113
-41
lines changed

Detectors/MUON/MCH/GlobalMapping/include/MCHGlobalMapping/Mapper.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#ifndef O2_MCH_GLOBAL_MAPPING_MAPPER_H_
1313
#define O2_MCH_GLOBAL_MAPPING_MAPPER_H_
1414

15+
#include "MCHConditions/Cathode.h"
16+
#include "MCHConditions/Chamber.h"
17+
#include "MCHConditions/Plane.h"
1518
#include "MCHGlobalMapping/DsIndex.h"
1619
#include <set>
1720
#include <string>
@@ -20,6 +23,17 @@ namespace o2::mch::dcs
2023
{
2124
/** get the list of dual sampa indices corresponding to a given DCS Alias */
2225
std::set<int> aliasToDsIndices(std::string_view alias);
26+
27+
/** get indices of all dual sampas of a set of cathodes (={deId,plane}).
28+
* returned set might be empty if input Cathodes are not valid ones. */
29+
std::set<DsIndex> getDsIndices(const std::set<dcs::Cathode>& cathodes);
30+
31+
/** get indices of all dual sampas of given plane of a chamber */
32+
std::set<DsIndex> getDsIndices(dcs::Chamber ch, dcs::Plane plane);
33+
34+
/** get indices of all dual sampas of a given set of solars */
35+
std::set<DsIndex> getDsIndices(const std::set<int>& solarIds);
36+
2337
} // namespace o2::mch::dcs
2438

2539
#endif

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,58 @@ std::set<int> aliasToDsIndices(std::string_view alias)
5454
return {};
5555
}
5656
}
57+
58+
std::set<DsIndex> getDsIndices(const std::set<dcs::Cathode>& cathodes)
59+
{
60+
std::set<DsIndex> dsIndices;
61+
for (const auto& cathode : cathodes) {
62+
auto deId = cathode.deId;
63+
if (!constants::isValidDetElemId(deId)) {
64+
continue;
65+
}
66+
bool bending = cathode.plane == dcs::Plane::Bending;
67+
bool checkPlane = cathode.plane != dcs::Plane::Both;
68+
if (checkPlane) {
69+
const o2::mch::mapping::Segmentation& seg = o2::mch::mapping::segmentation(deId);
70+
const auto& plane = bending ? seg.bending() : seg.nonBending();
71+
for (auto i = 0; i < plane.nofDualSampas(); i++) {
72+
auto index = o2::mch::getDsIndex({deId, plane.dualSampaId(i)});
73+
dsIndices.emplace(index);
74+
}
75+
} else {
76+
const o2::mch::mapping::Segmentation& seg = o2::mch::mapping::segmentation(deId);
77+
seg.forEachDualSampa([&dsIndices, deId](int dualSampaId) {
78+
auto index = o2::mch::getDsIndex({deId, dualSampaId});
79+
dsIndices.emplace(index);
80+
});
81+
}
82+
}
83+
return dsIndices;
84+
}
85+
86+
std::set<DsIndex> getDsIndices(dcs::Chamber ch, dcs::Plane plane)
87+
{
88+
std::set<dcs::Cathode> cathodes;
89+
for (auto deid : constants::deIdsForAllMCH) {
90+
if (deid / 100 - 1 == toInt(ch)) {
91+
Cathode cathode{deid, plane};
92+
cathodes.insert(cathode);
93+
}
94+
}
95+
return getDsIndices(cathodes);
96+
}
97+
98+
std::set<DsIndex> getDsIndices(const std::set<int>& solarIds)
99+
{
100+
std::set<o2::mch::DsIndex> dualSampas;
101+
for (const auto& solarId : solarIds) {
102+
auto dsDetIds = o2::mch::raw::getDualSampas<o2::mch::raw::ElectronicMapperGenerated>(solarId);
103+
for (const auto& dsDetId : dsDetIds) {
104+
auto index = o2::mch::getDsIndex(dsDetId);
105+
dualSampas.emplace(index);
106+
}
107+
}
108+
return dualSampas;
109+
}
110+
57111
} // namespace o2::mch::dcs

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

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,61 +9,26 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
#include "MCHMappingInterface/CathodeSegmentation.h"
1312
#define BOOST_TEST_MODULE Test MCHGlobalMapping Mapper
1413
#define BOOST_TEST_MAIN
1514
#define BOOST_TEST_DYN_LINK
1615

1716
#include <boost/test/unit_test.hpp>
17+
#include "MCHConditions/Chamber.h"
1818
#include "MCHConditions/DCSAliases.h"
19+
#include "MCHGlobalMapping/DsIndex.h"
1920
#include "MCHGlobalMapping/Mapper.h"
21+
#include "MCHMappingInterface/CathodeSegmentation.h"
2022
#include "MCHMappingInterface/Segmentation.h"
2123
#include "MCHRawElecMap/Mapper.h"
24+
#include <algorithm>
2225

2326
using namespace o2::mch::dcs;
27+
using namespace o2::mch;
2428

2529
namespace
2630
{
2731

28-
/* Build the list of expected dual sampa indices from a set of Cathodes */
29-
std::set<int> getExpectedDualSampas(const std::set<Cathode>& cathodes)
30-
{
31-
std::set<int> expectedDualSampas;
32-
for (const auto& expectedCathode : cathodes) {
33-
auto deId = expectedCathode.deId;
34-
bool bending = expectedCathode.plane == Plane::Bending;
35-
bool checkPlane = expectedCathode.plane != Plane::Both;
36-
if (checkPlane) {
37-
o2::mch::mapping::CathodeSegmentation cathode(deId, bending);
38-
for (auto i = 0; i < cathode.nofDualSampas(); i++) {
39-
int index = o2::mch::getDsIndex({deId, cathode.dualSampaId(i)});
40-
expectedDualSampas.emplace(index);
41-
}
42-
} else {
43-
const o2::mch::mapping::Segmentation& seg = o2::mch::mapping::segmentation(deId);
44-
seg.forEachDualSampa([&expectedDualSampas, deId](int dualSampaId) {
45-
int index = o2::mch::getDsIndex({deId, dualSampaId});
46-
expectedDualSampas.emplace(index);
47-
});
48-
}
49-
}
50-
return expectedDualSampas;
51-
}
52-
53-
/* Build the list of expected dual sampa indices from a set of solar Ids */
54-
std::set<int> getExpectedDualSampas(const std::set<int>& solarIds)
55-
{
56-
std::set<int> expectedDualSampas;
57-
for (const auto& solarId : solarIds) {
58-
auto dsDetIds = o2::mch::raw::getDualSampas<o2::mch::raw::ElectronicMapperGenerated>(solarId);
59-
for (const auto& dsDetId : dsDetIds) {
60-
int index = o2::mch::getDsIndex(dsDetId);
61-
expectedDualSampas.emplace(index);
62-
}
63-
}
64-
return expectedDualSampas;
65-
}
66-
6732
std::string expandAlias(std::string_view shortAlias)
6833
{
6934
std::string alias = shortAlias.find("Left") != std::string::npos ? "MchHvLvLeft" : "MchHvLvRight";
@@ -86,7 +51,7 @@ void compareToExpectation(const std::map<std::string, std::set<T>>& expected)
8651
// this is the function we are testing
8752
auto dsix = o2::mch::dcs::aliasToDsIndices(alias);
8853

89-
std::set<int> expectedDualSampas = getExpectedDualSampas(e.second);
54+
std::set<o2::mch::DsIndex> expectedDualSampas = getDsIndices(e.second);
9055

9156
BOOST_TEST_CONTEXT(fmt::format("alias {}", alias))
9257
{
@@ -100,6 +65,45 @@ void compareToExpectation(const std::map<std::string, std::set<T>>& expected)
10065

10166
} // namespace
10267

68+
BOOST_AUTO_TEST_CASE(IncorrectCathodeShouldGetZeroIndices)
69+
{
70+
BOOST_CHECK_EQUAL(getDsIndices({{10, Plane::Both}}).size(), 0);
71+
}
72+
73+
BOOST_AUTO_TEST_CASE(CheckDsIndexRangePerChamberPlane)
74+
{
75+
// note that indices in ranges might overlap, this is not an error
76+
std::vector<std::tuple<int, int, int, int>> vexpected = {
77+
{0, 1578, 226, 1803}, // chamber 1, min_bending, max_bending, min_nonBending, max_nonBending
78+
{1804, 3382, 2030, 3607}, // chamber 2
79+
{3608, 5154, 3829, 5375}, // chamber 3
80+
{5376, 6922, 5597, 7143}, // chamber 4
81+
{7144, 8312, 7190, 8351}, // chamber 5
82+
{8352, 9539, 8399, 9579}, // chamber 6
83+
{9580, 11253, 9630, 11299}, // chamber 7
84+
{11300, 12973, 11350, 13019}, // chamber 8
85+
{13020, 14873, 13070, 14919}, // chamber 9
86+
{14920, 16773, 14970, 16819}, // chamber 10
87+
};
88+
for (auto chamberId = 0; chamberId < 10; chamberId++) {
89+
BOOST_TEST_CONTEXT(fmt::format("chamberId {}", chamberId))
90+
{
91+
auto ch = chamber(chamberId).value();
92+
const auto b = getDsIndices(ch, Plane::Bending);
93+
const auto nb = getDsIndices(ch, Plane::NonBending);
94+
BOOST_REQUIRE(b.size() > 0);
95+
BOOST_REQUIRE(nb.size() > 0);
96+
const auto [bmin, bmax] = std::minmax_element(b.begin(), b.end());
97+
const auto [nbmin, nbmax] = std::minmax_element(nb.begin(), nb.end());
98+
const auto expected = vexpected[chamberId];
99+
BOOST_REQUIRE_EQUAL(*bmin, std::get<0>(expected));
100+
BOOST_REQUIRE_EQUAL(*bmax, std::get<1>(expected));
101+
BOOST_REQUIRE_EQUAL(*nbmin, std::get<2>(expected));
102+
BOOST_REQUIRE_EQUAL(*nbmax, std::get<3>(expected));
103+
}
104+
}
105+
}
106+
103107
BOOST_AUTO_TEST_CASE(HVSlatIDToDsIndex)
104108
{
105109
std::map<std::string, std::set<Cathode>> expected = {

0 commit comments

Comments
 (0)