Project
Loading...
Searching...
No Matches
testPedestalData.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#define BOOST_TEST_MODULE test mch calibration pedestal data
13#define BOOST_TEST_DYN_LINK
14#include <boost/test/unit_test.hpp>
15
21#include <random>
22#include <vector>
23
24std::vector<uint16_t> samples(int n)
25{
26 std::vector<uint16_t> v(n);
27 std::uniform_int_distribution<int> distribution(0, 1024);
28 std::mt19937 generator(std::random_device{}());
29 std::generate(v.begin(), v.end(), [&distribution, &generator] {
30 return distribution(generator);
31 });
32 return v;
33}
34
37
40 {
41 // non existing DS : that channel should not appear when iterating on pedestal data
42 digits.emplace_back(721, 23, 13, 1234, 43, samples(13));
43
44 // solarId 721 groupId 5 indexId 1
45 // S721-J5-DS1 (elinkId 26) [ FEE30-LINK1 ] DE708-DS102
46 digits.emplace_back(721, 26, 16, 2345, 46, samples(16));
47
48 // solarId 328 groupId 5 indexId 2
49 // S328-J5-DS2 (elinkId 27) [ FEE32-LINK6 ] DE714-DS108 channel 18
50 digits.emplace_back(328, 27, 18, 3456, 48, samples(18));
51 }
52 std::vector<PedestalDigit> digits;
53};
54
55BOOST_FIXTURE_TEST_SUITE(PedestalDataIterator, PedestalDigits)
56
57BOOST_AUTO_TEST_CASE(TestIteratorOnCompletePedestalData)
58{
59 // build a vector of all possible digits
60 std::vector<PedestalDigit> allDigits;
61
62 auto det2elec = o2::mch::raw::createDet2ElecMapper<o2::mch::raw::ElectronicMapperGenerated>();
63
64 for (auto deId : o2::mch::constants::deIdsForAllMCH) {
65 const auto& seg = o2::mch::mapping::segmentation(deId);
66 seg.forEachPad([&](int padID) {
67 if (seg.isValid(padID)) {
68 auto dsId = seg.padDualSampaId(padID);
69 auto ch = seg.padDualSampaChannel(padID);
70 o2::mch::raw::DsDetId det(deId, dsId);
71 auto elec = det2elec(det).value();
72 auto solarId = elec.solarId();
73 allDigits.emplace_back(solarId, elec.elinkId(), ch, 42, 42, samples(15));
74 }
75 });
76 }
77
78 PedestalData pd;
79 pd.fill(allDigits);
80
81 BOOST_REQUIRE(allDigits.size() == 1063528);
82 int n{0};
83 for (const auto& ped : pd) {
84 ++n;
85 }
86 BOOST_TEST(n == allDigits.size());
87}
88
89BOOST_AUTO_TEST_CASE(TestIteratorEquality)
90{
91 PedestalData pd;
92 pd.fill(digits);
93 auto it1 = pd.begin();
94 auto it2 = pd.begin();
95 BOOST_TEST((it1 == it2));
96}
97
98BOOST_AUTO_TEST_CASE(TestIteratorInequality)
99{
100 PedestalData pd;
101 pd.fill(digits);
102 auto it1 = pd.begin();
103 auto it2 = pd.end();
104 BOOST_TEST((it1 != it2));
105}
106
107BOOST_AUTO_TEST_CASE(TestIteratorPreIncrementable)
108{
109 PedestalData pd;
110 pd.fill(digits);
111 int n{0};
112 for (auto rec : pd) {
113 n++;
114 }
115 BOOST_TEST(n == 2768);
116 // 2768 = 1856 pads in solar 328 + 721 pads in solar 721
117 // Note that solar 328 has 29 dual sampas
118 // solar 721 has 15 dual sampas
119 // But 2768 < (29+15)*64 (=2816) because not all pads are valid ones.
120}
121
122BOOST_AUTO_TEST_CASE(TestIteratorAllReturnedPadAreValidByConstruction)
123{
124 PedestalData pd;
125 pd.fill(digits);
126 auto n = std::count_if(pd.begin(), pd.end(), [](o2::mch::calibration::PedestalChannel& c) {
127 return c.isValid();
128 });
129 auto n1 = std::distance(pd.begin(), pd.end());
130 BOOST_TEST(n == 2768);
131 BOOST_CHECK(n == n1);
132}
133
134BOOST_AUTO_TEST_CASE(TestIteratorInCountIfAlgorithm)
135{
136 PedestalData pd;
137 pd.fill(digits);
138 auto n = std::count_if(pd.begin(), pd.end(), [](o2::mch::calibration::PedestalChannel& c) {
139 return c.mEntries > 0;
140 });
141 BOOST_TEST(n == 2); // 2 and not 3 because one of the digit is on a pad that is not connected (hence invalid, hence not part of the iteration)
142}
143
144BOOST_AUTO_TEST_CASE(IterationOnEmptyDataShouldNotBeAnInfiniteLoop, *boost::unit_test::timeout(10))
145{
146 PedestalData d;
147 auto c = std::distance(d.cbegin(), d.cend());
149}
150BOOST_AUTO_TEST_SUITE_END()
o2::mch::mapping::CathodeSegmentation seg
Compute and store the mean and RMS of the pedestal digit amplitudes.
void fill(const gsl::span< const PedestalDigit > digits)
"Fat" digit for pedestal data.
bool isValid(int catPadIndex) const
Not every integer is a valid catPadIndex. This method will tell if catPadIndex is a valid one.
GLdouble n
Definition glcorearb.h:1982
const GLdouble * v
Definition glcorearb.h:832
GLsizei samples
Definition glcorearb.h:1309
std::array< int, 156 > deIdsForAllMCH
O2MCHMAPPINGIMPL3_EXPORT const Segmentation & segmentation(int detElemId)
GPUReconstruction * rec
std::vector< PedestalDigit > digits
Pedestal mean and sigma for one channel.
BOOST_AUTO_TEST_CASE(TestIteratorOnCompletePedestalData)
BOOST_CHECK_EQUAL(c, 0)
auto c
BOOST_CHECK(tree)
BOOST_TEST(digits==digitsD, boost::test_tools::per_element())
std::vector< Digit > digits