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 // multi-threaded version
89 PedestalData pdmt;
90 pdmt.setNThreads(8);
91 pdmt.fill(allDigits);
92
93 int nmt{0};
94 for (const auto& ped : pdmt) {
95 ++nmt;
96 }
97 BOOST_TEST(nmt == allDigits.size());
98}
99
100BOOST_AUTO_TEST_CASE(TestIteratorEquality)
101{
102 PedestalData pd;
103 pd.fill(digits);
104 auto it1 = pd.begin();
105 auto it2 = pd.begin();
106 BOOST_TEST((it1 == it2));
107}
108
109BOOST_AUTO_TEST_CASE(TestIteratorInequality)
110{
111 PedestalData pd;
112 pd.fill(digits);
113 auto it1 = pd.begin();
114 auto it2 = pd.end();
115 BOOST_TEST((it1 != it2));
116}
117
118BOOST_AUTO_TEST_CASE(TestIteratorPreIncrementable)
119{
120 PedestalData pd;
121 pd.fill(digits);
122 int n{0};
123 for (auto rec : pd) {
124 n++;
125 }
126 BOOST_TEST(n == 2768);
127
128 // multi-threaded version
129 PedestalData pdmt;
130 pdmt.setNThreads(8);
131 pdmt.fill(digits);
132 int nmt{0};
133 for (auto rec : pdmt) {
134 nmt++;
135 }
136 BOOST_TEST(nmt == 2768);
137 // 2768 = 1856 pads in solar 328 + 721 pads in solar 721
138 // Note that solar 328 has 29 dual sampas
139 // solar 721 has 15 dual sampas
140 // But 2768 < (29+15)*64 (=2816) because not all pads are valid ones.
141}
142
143BOOST_AUTO_TEST_CASE(TestIteratorAllReturnedPadAreValidByConstruction)
144{
145 PedestalData pd;
146 pd.fill(digits);
147 auto n = std::count_if(pd.begin(), pd.end(), [](o2::mch::calibration::PedestalChannel& c) {
148 return c.isValid();
149 });
150 auto n1 = std::distance(pd.begin(), pd.end());
151 BOOST_TEST(n == 2768);
152 BOOST_CHECK(n == n1);
153}
154
155BOOST_AUTO_TEST_CASE(TestIteratorInCountIfAlgorithm)
156{
157 PedestalData pd;
158 pd.fill(digits);
159 auto n = std::count_if(pd.begin(), pd.end(), [](o2::mch::calibration::PedestalChannel& c) {
160 return c.mEntries > 0;
161 });
162 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)
163}
164
165BOOST_AUTO_TEST_CASE(IterationOnEmptyDataShouldNotBeAnInfiniteLoop, *boost::unit_test::timeout(10))
166{
168 auto c = std::distance(d.cbegin(), d.cend());
170}
171BOOST_AUTO_TEST_SUITE_END()
o2::mch::mapping::CathodeSegmentation seg
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
configStandalone rec
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)
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