Skip to content

Commit 08fd30a

Browse files
mfasDashahor02
authored andcommittedMay 13, 2024·
[EMCAL-1136] Unit tests for trigger reconstruction
- Unit test for TRUDataHandler - Unit test for FastORTimeSeries - Move unit tests for EMCALReconstruction in correct group
1 parent a79d121 commit 08fd30a

8 files changed

+277
-5
lines changed
 

‎Detectors/EMCAL/reconstruction/CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ o2_add_test(RecoContainer
100100
COMPONENT_NAME emcal
101101
LABELS emcal)
102102

103+
o2_add_test(TRUDataHandler
104+
SOURCES test/testTRUDataHandler.cxx
105+
PUBLIC_LINK_LIBRARIES O2::EMCALReconstruction
106+
COMPONENT_NAME emcal
107+
LABELS emcal)
108+
109+
o2_add_test(FastORTimeSeries
110+
SOURCES test/testFastORTimeSeries.cxx
111+
PUBLIC_LINK_LIBRARIES O2::EMCALReconstruction
112+
COMPONENT_NAME emcal
113+
LABELS emcal)
114+
103115
o2_add_test_root_macro(macros/RawFitterTESTs.C
104116
PUBLIC_LINK_LIBRARIES O2::EMCALReconstruction O2::Headers
105117
LABELS emcal COMPILE_ONLY)

‎Detectors/EMCAL/reconstruction/test/testAltroDecoderError.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
#define BOOST_TEST_MODULE Test EMCAL Calib
12+
#define BOOST_TEST_MODULETest EMCAL Reconstruction
1313
#define BOOST_TEST_MAIN
1414
#define BOOST_TEST_DYN_LINK
1515
#include <boost/test/unit_test.hpp>

‎Detectors/EMCAL/reconstruction/test/testCaloRawFitterError.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
#define BOOST_TEST_MODULE Test EMCAL Calib
12+
#define BOOST_TEST_MODULE Test EMCAL Reconstruction
1313
#define BOOST_TEST_MAIN
1414
#define BOOST_TEST_DYN_LINK
1515
#include <boost/test/unit_test.hpp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
#define BOOST_TEST_MODULE Test EMCAL Reconstruction
12+
#define BOOST_TEST_MAIN
13+
#define BOOST_TEST_DYN_LINK
14+
#include <boost/test/unit_test.hpp>
15+
#include <vector>
16+
#include <tuple>
17+
#include <TRandom.h>
18+
#include <EMCALReconstruction/FastORTimeSeries.h>
19+
20+
namespace o2
21+
{
22+
23+
namespace emcal
24+
{
25+
26+
void printBunch(const gsl::span<const uint16_t> adcs)
27+
{
28+
bool first = true;
29+
for (auto& adc : adcs) {
30+
if (!first) {
31+
std::cout << ", ";
32+
} else {
33+
first = false;
34+
}
35+
std::cout << adc;
36+
}
37+
std::cout << " (size " << adcs.size() << ")" << std::endl;
38+
}
39+
40+
std::vector<uint16_t> getReversed(const std::vector<uint16_t>& original)
41+
{
42+
std::vector<uint16_t> reversed(13);
43+
for (std::size_t sample = 0; sample < 13; sample++) {
44+
reversed[12 - sample] = original[sample];
45+
}
46+
return reversed;
47+
}
48+
49+
std::tuple<uint8_t, std::vector<uint16_t>, std::vector<uint16_t>> generatePulseTimeReversed()
50+
{
51+
std::vector<uint16_t> pulse(13);
52+
std::fill(pulse.begin(), pulse.end(), 0);
53+
// calculate forward pulse
54+
auto peak_signal = static_cast<uint16_t>(gRandom->Uniform(0, 1024));
55+
pulse[4] = peak_signal;
56+
auto last = peak_signal;
57+
for (std::size_t sample = 5; sample < 13; sample++) {
58+
if (last == 0) {
59+
break;
60+
}
61+
auto current = static_cast<uint16_t>(gRandom->Uniform(0, last));
62+
pulse[sample] = current;
63+
last = current;
64+
}
65+
last = peak_signal;
66+
for (std::size_t sample = 3; sample > 0; sample--) {
67+
if (last == 0) {
68+
break;
69+
}
70+
auto current = static_cast<uint16_t>(gRandom->Uniform(0, last));
71+
pulse[sample] = current;
72+
last = current;
73+
}
74+
// find start time
75+
uint8_t starttime = 12;
76+
for (std::size_t currenttime = 12; currenttime > 0; currenttime--) {
77+
starttime = currenttime;
78+
if (pulse[currenttime]) {
79+
break;
80+
}
81+
}
82+
// time-reverse pulse
83+
auto reversed = getReversed(pulse);
84+
// zero-suppress time series
85+
std::vector<uint16_t> zerosuppressed;
86+
bool bunchstart = false;
87+
for (std::size_t sample = 0; sample < 13; sample++) {
88+
if (reversed[sample] == 0) {
89+
if (!bunchstart) {
90+
continue;
91+
}
92+
break;
93+
}
94+
bunchstart = true;
95+
zerosuppressed.push_back(reversed[sample]);
96+
}
97+
return std::make_tuple(starttime, zerosuppressed, pulse);
98+
}
99+
100+
uint16_t calculateTimesum(const std::vector<uint16_t> samplesOrdered, uint8_t l0time)
101+
{
102+
uint16_t timesum = 0;
103+
uint8_t starttime = l0time - 4;
104+
for (uint8_t sample = starttime; sample < starttime + 4; sample++) {
105+
timesum += samplesOrdered[sample];
106+
}
107+
return timesum;
108+
}
109+
110+
std::vector<uint16_t> generateSmallBunch(uint8_t bunchlength)
111+
{
112+
std::vector<uint16_t> bunch(bunchlength);
113+
auto peak_signal = static_cast<uint16_t>(gRandom->Uniform(0, 1024));
114+
bunch[bunchlength - 2] = peak_signal;
115+
bunch[bunchlength - 1] = static_cast<uint16_t>(gRandom->Uniform(0, peak_signal));
116+
auto last = peak_signal;
117+
for (int sample = bunchlength - 3; sample >= 0; sample--) {
118+
auto current = static_cast<uint16_t>(gRandom->Uniform(0, last));
119+
bunch[sample] = current;
120+
last = current;
121+
}
122+
return bunch;
123+
}
124+
125+
void add_bunch_to_buffer(std::vector<uint16_t>& buffer, const std::vector<uint16_t>& bunch, uint8_t starttime)
126+
{
127+
for (int sample = 0; sample < bunch.size(); sample++) {
128+
buffer[starttime - sample] = bunch[bunch.size() - 1 - sample];
129+
}
130+
}
131+
132+
BOOST_AUTO_TEST_CASE(FastORTimeSeries_test)
133+
{
134+
// test fill and integral
135+
for (int itest = 0; itest < 500; itest++) {
136+
auto [starttime, zerosuppressed, reference] = generatePulseTimeReversed();
137+
FastORTimeSeries testcase(13, zerosuppressed, starttime);
138+
auto adcs = testcase.getADCs();
139+
BOOST_CHECK_EQUAL_COLLECTIONS(adcs.begin(), adcs.end(), reference.begin(), reference.end());
140+
BOOST_CHECK_EQUAL(testcase.calculateL1TimeSum(8), calculateTimesum(reference, 8));
141+
}
142+
return;
143+
144+
// test adding 2 bunches
145+
for (int itest = 0; itest < 500; itest++) {
146+
auto length_bunch1 = static_cast<int>(gRandom->Uniform(3, 5)),
147+
length_bunch2 = static_cast<int>(gRandom->Uniform(3, 5));
148+
auto sumbunchlength = length_bunch1 + length_bunch2;
149+
auto offset_bunch1 = static_cast<int>(gRandom->Uniform(0, 13 - sumbunchlength)),
150+
offset_bunch2 = static_cast<int>(gRandom->Uniform(0, 13 - sumbunchlength - offset_bunch1));
151+
auto bunch1 = generateSmallBunch(length_bunch1),
152+
bunch2 = generateSmallBunch(length_bunch2);
153+
auto starttime_bunch1 = offset_bunch1 + length_bunch1,
154+
starttime_bunch2 = starttime_bunch1 + offset_bunch2 + length_bunch2;
155+
std::vector<uint16_t> buffer_reversed{13};
156+
add_bunch_to_buffer(buffer_reversed, bunch2, starttime_bunch2);
157+
add_bunch_to_buffer(buffer_reversed, bunch1, starttime_bunch1);
158+
FastORTimeSeries testcase(13, bunch2, starttime_bunch2);
159+
testcase.setTimeSamples(bunch1, starttime_bunch1);
160+
auto adcs_timeordered = getReversed(buffer_reversed);
161+
auto adcs_timeseries_reversed = testcase.getADCs();
162+
BOOST_CHECK_EQUAL_COLLECTIONS(adcs_timeseries_reversed.begin(), adcs_timeseries_reversed.end(), adcs_timeordered.begin(), adcs_timeordered.end());
163+
}
164+
}
165+
166+
} // namespace emcal
167+
168+
} // namespace o2

‎Detectors/EMCAL/reconstruction/test/testMinorAltroDecodingError.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
#define BOOST_TEST_MODULE Test EMCAL Calib
12+
#define BOOST_TEST_MODULE Test EMCAL Reconstruction
1313
#define BOOST_TEST_MAIN
1414
#define BOOST_TEST_DYN_LINK
1515
#include <boost/test/unit_test.hpp>

‎Detectors/EMCAL/reconstruction/test/testRawDecodingError.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
#define BOOST_TEST_MODULE Test EMCAL Calib
12+
#define BOOST_TEST_MODULE Test EMCAL Reconstruction
1313
#define BOOST_TEST_MAIN
1414
#define BOOST_TEST_DYN_LINK
1515
#include <boost/test/unit_test.hpp>

‎Detectors/EMCAL/reconstruction/test/testRecoContainer.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// In applying this license CERN does not waive the privileges and immunities
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
11-
#define BOOST_TEST_MODULE Test EMCAL Calib
11+
#define BOOST_TEST_MODULE Test EMCAL Reconstruction
1212
#define BOOST_TEST_MAIN
1313
#define BOOST_TEST_DYN_LINK
1414
#include <boost/test/unit_test.hpp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
#define BOOST_TEST_MODULE Test EMCAL Reconstruction
12+
#define BOOST_TEST_MAIN
13+
#define BOOST_TEST_DYN_LINK
14+
#include <boost/test/unit_test.hpp>
15+
#include <set>
16+
#include <TRandom.h>
17+
#include <EMCALBase/TriggerMappingV2.h>
18+
#include <EMCALReconstruction/TRUDataHandler.h>
19+
20+
namespace o2
21+
{
22+
namespace emcal
23+
{
24+
25+
BOOST_AUTO_TEST_CASE(TRUDataHandler_test)
26+
{
27+
o2::emcal::TRUDataHandler testhandler;
28+
29+
// no patch set
30+
BOOST_CHECK_EQUAL(testhandler.hasAnyPatch(), false);
31+
for (int ipatch = 0; ipatch < o2::emcal::TriggerMappingV2::PATCHESINTRU; ipatch++) {
32+
BOOST_CHECK_EQUAL(testhandler.hasPatch(ipatch), false);
33+
}
34+
35+
// set all patches with L0 time 8
36+
for (int ipatch = 0; ipatch < o2::emcal::TriggerMappingV2::PATCHESINTRU; ipatch++) {
37+
testhandler.setPatch(ipatch, 8);
38+
}
39+
BOOST_CHECK_EQUAL(testhandler.hasAnyPatch(), true);
40+
for (int ipatch = 0; ipatch < o2::emcal::TriggerMappingV2::PATCHESINTRU; ipatch++) {
41+
BOOST_CHECK_EQUAL(testhandler.hasPatch(ipatch), true);
42+
BOOST_CHECK_EQUAL(testhandler.getPatchTime(ipatch), 8);
43+
}
44+
45+
// test reset
46+
testhandler.reset();
47+
BOOST_CHECK_EQUAL(testhandler.hasAnyPatch(), false);
48+
for (int ipatch = 0; ipatch < o2::emcal::TriggerMappingV2::PATCHESINTRU; ipatch++) {
49+
BOOST_CHECK_EQUAL(testhandler.hasPatch(ipatch), false);
50+
}
51+
52+
// test error handling
53+
for (int8_t index = o2::emcal::TriggerMappingV2::PATCHESINTRU; index < CHAR_MAX; index++) {
54+
BOOST_CHECK_EXCEPTION(testhandler.hasPatch(index), o2::emcal::TRUDataHandler::PatchIndexException, [index](const o2::emcal::TRUDataHandler::PatchIndexException& e) { return e.getIndex() == index; });
55+
BOOST_CHECK_EXCEPTION(testhandler.setPatch(index, 8), o2::emcal::TRUDataHandler::PatchIndexException, [index](const o2::emcal::TRUDataHandler::PatchIndexException& e) { return e.getIndex() == index; });
56+
}
57+
58+
for (int iiter = 0; iiter < 100; iiter++) {
59+
// For 100 iterations simulate patch index and time
60+
std::map<uint8_t, uint8_t> patchtimes;
61+
int npatches_expect = static_cast<int>(gRandom->Uniform(0, o2::emcal::TriggerMappingV2::PATCHESINTRU));
62+
while (patchtimes.size() < npatches_expect) {
63+
auto patchindex = static_cast<int>(gRandom->Uniform(0, o2::emcal::TriggerMappingV2::PATCHESINTRU));
64+
if (patchtimes.find(patchindex) == patchtimes.end()) {
65+
auto patchtime = static_cast<int>(gRandom->Gaus(8, 1));
66+
if (patchtime >= 12) {
67+
patchtime = 11;
68+
}
69+
patchtimes[patchindex] = patchtime;
70+
}
71+
}
72+
o2::emcal::TRUDataHandler iterhandler;
73+
iterhandler.setFired(npatches_expect > 0);
74+
for (auto [patchindex, patchtime] : patchtimes) {
75+
iterhandler.setPatch(patchindex, patchtime);
76+
}
77+
78+
BOOST_CHECK_EQUAL(iterhandler.isFired(), npatches_expect > 0);
79+
BOOST_CHECK_EQUAL(iterhandler.hasAnyPatch(), npatches_expect > 0);
80+
for (auto ipatch = 0; ipatch < o2::emcal::TriggerMappingV2::PATCHESINTRU; ipatch++) {
81+
auto hasPatch = patchtimes.find(ipatch) != patchtimes.end();
82+
BOOST_CHECK_EQUAL(iterhandler.hasPatch(ipatch), hasPatch);
83+
if (hasPatch) {
84+
BOOST_CHECK_EQUAL(iterhandler.getPatchTime(ipatch), patchtimes[ipatch]);
85+
}
86+
}
87+
}
88+
}
89+
90+
} // namespace emcal
91+
92+
} // namespace o2

0 commit comments

Comments
 (0)
Please sign in to comment.