Project
Loading...
Searching...
No Matches
testROFTimeClusterFinder.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 MCHRaw ROFFinder
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15
16#include <vector>
17#include <boost/test/unit_test.hpp>
18#include <fmt/format.h>
20
21BOOST_AUTO_TEST_SUITE(o2_mch_raw)
22
23BOOST_AUTO_TEST_SUITE(timeclustering)
24
25using ROFRecord = o2::mch::ROFRecord;
26using ROFVector = std::vector<ROFRecord>;
27
28//static constexpr uint32_t sWinSize = 1000 / 25; // number of BC in 1 us
29//static constexpr uint32_t sBinsInOneWindow = 5; // number of bins in wich the 1 us window is divided for the peak search
30//static constexpr uint32_t sBinWidth = sWinSize / sBinsInOneWindow; // 5 bins in one 1 us window
31
32static ROFVector makeROFs(std::vector<int> binEntries, uint32_t winSize, uint32_t nBinsInOneWindow)
33{
34 uint32_t binWidth = winSize / nBinsInOneWindow;
35 uint32_t orbit = 1;
36 uint32_t tfTime = 0;
37 size_t nBins = binEntries.size();
38 ROFVector rofRecords;
39
40 int firstDigitIdx = 0;
41 for (int bin = 0; bin < nBins; bin++) {
42 // one ROF in each peak search bin, for simplicity
43 // skip empty bins
44 if (binEntries[bin] == 0) {
45 continue;
46 }
47 o2::InteractionRecord ir(tfTime + bin * binWidth, orbit);
48 rofRecords.emplace_back(ir, firstDigitIdx, binEntries[bin], 4);
49 firstDigitIdx += binEntries[bin];
50 }
51 return rofRecords;
52}
53
54//----------------------------------------------------------------------------
55static ROFVector makeTimeROFs(std::vector<int> binEntries, uint32_t winSize, uint32_t nBinsInOneWindow)
56{
57 const auto& rofRecords = makeROFs(binEntries, winSize, nBinsInOneWindow);
58 const std::vector<o2::mch::Digit> digits;
59
60 o2::mch::ROFTimeClusterFinder rofProcessor(rofRecords, digits, winSize, nBinsInOneWindow, false, 1);
61 rofProcessor.process();
62
63 const auto& rofTimeRecords = rofProcessor.getROFRecords();
64
65 return rofTimeRecords;
66}
67
68//----------------------------------------------------------------------------
69static std::vector<int> getBinIntegral(std::vector<int> binEntries)
70{
71 std::vector<int> integral = binEntries;
72 for (size_t i = 1; i < integral.size(); i++) {
73 integral[i] += integral[i - 1];
74 std::cout << fmt::format("bin[{}]={} integral[{}]={}", i, binEntries[i], i, integral[i]) << std::endl;
75 }
76 return integral;
77}
78
79//----------------------------------------------------------------------------
80static void checkROF(const ROFRecord rof, std::vector<int> binEntries, uint32_t winSize, uint32_t nBinsInOneWindow, int start, int width)
81{
82 uint32_t binWidth = winSize / nBinsInOneWindow;
83 uint32_t orbit = 1;
84 uint32_t tfTime = 0;
85 std::vector<int> binIntegral = getBinIntegral(binEntries);
86
87 // checks of indexes and sizes
88 int firstIdx = binIntegral[start] - binEntries[start];
89 int size = binIntegral[start + width - 1] - firstIdx;
90 BOOST_CHECK_EQUAL(rof.getFirstIdx(), firstIdx);
92
93 // checks of interaction records and BC widths
94 o2::InteractionRecord irStart(tfTime + start * binWidth, orbit);
95 BOOST_CHECK_EQUAL(rof.getBCData(), irStart);
96 int bcWidth = (width - 1) * binWidth + 4;
97 BOOST_CHECK_EQUAL(rof.getBCWidth(), bcWidth);
98}
99
100//----------------------------------------------------------------------------
101BOOST_AUTO_TEST_CASE(OneTimeCluster)
102{
103 uint32_t orbit = 1;
104 uint32_t tfTime = 0;
105 uint32_t winSize = 1000 / 25;
106 uint32_t nBins = 5;
107 std::vector<int> binEntries = {1, 2, 5, 1, 2};
108 std::vector<int> binIntegral = getBinIntegral(binEntries);
109
110 const auto& rofTimeRecords = makeTimeROFs(binEntries, winSize, nBins);
111 BOOST_CHECK_EQUAL(rofTimeRecords.size(), 1);
112
113 checkROF(rofTimeRecords[0], binEntries, winSize, nBins, 0, 5);
114}
115
116//----------------------------------------------------------------------------
117BOOST_AUTO_TEST_CASE(OneTimeClusterLargeWin)
118{
119 uint32_t orbit = 1;
120 uint32_t tfTime = 0;
121 uint32_t winSize = 1500 / 25;
122 uint32_t nBins = 5;
123 std::vector<int> binEntries = {1, 2, 5, 1, 2};
124 std::vector<int> binIntegral = getBinIntegral(binEntries);
125
126 const auto& rofTimeRecords = makeTimeROFs(binEntries, winSize, nBins);
127 BOOST_CHECK_EQUAL(rofTimeRecords.size(), 1);
128
129 checkROF(rofTimeRecords[0], binEntries, winSize, nBins, 0, 5);
130}
131
132//----------------------------------------------------------------------------
133BOOST_AUTO_TEST_CASE(OneTimeCluster7bins)
134{
135 uint32_t orbit = 1;
136 uint32_t tfTime = 0;
137 uint32_t winSize = 1200 / 25;
138 uint32_t nBins = 7;
139 std::vector<int> binEntries = {1, 2, 1, 5, 1, 3, 2};
140 std::vector<int> binIntegral = getBinIntegral(binEntries);
141
142 const auto& rofTimeRecords = makeTimeROFs(binEntries, winSize, nBins);
143 BOOST_CHECK_EQUAL(rofTimeRecords.size(), 1);
144
145 checkROF(rofTimeRecords[0], binEntries, winSize, nBins, 0, 7);
146}
147
148//----------------------------------------------------------------------------
149BOOST_AUTO_TEST_CASE(OneTimeClusterEmptyStart)
150{
151 uint32_t orbit = 1;
152 uint32_t tfTime = 0;
153 uint32_t winSize = 1000 / 25;
154 uint32_t nBins = 5;
155 std::vector<int> binEntries = {0, 1, 2, 5, 1};
156 std::vector<int> binIntegral = getBinIntegral(binEntries);
157
158 const auto& rofTimeRecords = makeTimeROFs(binEntries, winSize, nBins);
159 BOOST_CHECK_EQUAL(rofTimeRecords.size(), 1);
160
161 checkROF(rofTimeRecords[0], binEntries, winSize, nBins, 1, 4);
162}
163
164//----------------------------------------------------------------------------
165BOOST_AUTO_TEST_CASE(OneTimeClusterEmptyEnd)
166{
167 uint32_t orbit = 1;
168 uint32_t tfTime = 0;
169 uint32_t winSize = 1000 / 25;
170 uint32_t nBins = 5;
171 std::vector<int> binEntries = {1, 2, 5, 1, 0};
172 std::vector<int> binIntegral = getBinIntegral(binEntries);
173
174 const auto& rofTimeRecords = makeTimeROFs(binEntries, winSize, nBins);
175 BOOST_CHECK_EQUAL(rofTimeRecords.size(), 1);
176
177 checkROF(rofTimeRecords[0], binEntries, winSize, nBins, 0, 4);
178}
179
180//----------------------------------------------------------------------------
181BOOST_AUTO_TEST_CASE(TwoTimeClusters)
182{
183 uint32_t orbit = 1;
184 uint32_t tfTime = 0;
185 uint32_t winSize = 1000 / 25;
186 uint32_t nBins = 5;
187 std::vector<int> binEntries = {1, 2, 5, 1, 2, 2, 1, 6, 3, 1};
188 std::vector<int> binIntegral = getBinIntegral(binEntries);
189
190 const auto& rofTimeRecords = makeTimeROFs(binEntries, winSize, nBins);
191 BOOST_CHECK_EQUAL(rofTimeRecords.size(), 2);
192
193 checkROF(rofTimeRecords[0], binEntries, winSize, nBins, 0, 5);
194 checkROF(rofTimeRecords[1], binEntries, winSize, nBins, 5, 5);
195}
196
197//----------------------------------------------------------------------------
198BOOST_AUTO_TEST_CASE(TwoTimeClustersWithEmptyGap)
199{
200 uint32_t orbit = 1;
201 uint32_t tfTime = 0;
202 uint32_t winSize = 1000 / 25;
203 uint32_t nBins = 5;
204 std::vector<int> binEntries = {1, 2, 5, 1, 2, 0, 2, 1, 6, 3, 1};
205 std::vector<int> binIntegral = getBinIntegral(binEntries);
206
207 const auto& rofTimeRecords = makeTimeROFs(binEntries, winSize, nBins);
208 BOOST_CHECK_EQUAL(rofTimeRecords.size(), 2);
209
210 checkROF(rofTimeRecords[0], binEntries, winSize, nBins, 0, 5);
211 checkROF(rofTimeRecords[1], binEntries, winSize, nBins, 6, 5);
212}
213
214//----------------------------------------------------------------------------
215BOOST_AUTO_TEST_CASE(TwoTimeClustersWithNonEmptyGap)
216{
217 uint32_t orbit = 1;
218 uint32_t winSize = 1000 / 25;
219 uint32_t nBins = 5;
220 std::vector<int> binEntries = {1, 2, 5, 1, 2, 4, 5, 2, 1, 6, 3, 1};
221 std::vector<int> binIntegral = getBinIntegral(binEntries);
222
223 const auto& rofTimeRecords = makeTimeROFs(binEntries, winSize, nBins);
224 BOOST_CHECK_EQUAL(rofTimeRecords.size(), 3);
225
226 checkROF(rofTimeRecords[0], binEntries, winSize, nBins, 0, 5);
227 checkROF(rofTimeRecords[1], binEntries, winSize, nBins, 5, 2);
228 checkROF(rofTimeRecords[2], binEntries, winSize, nBins, 7, 5);
229}
230
231//----------------------------------------------------------------------------
232BOOST_AUTO_TEST_CASE(OneTimeClusterWithGapAtBeginning)
233{
234 uint32_t orbit = 1;
235 uint32_t winSize = 1000 / 25;
236 uint32_t nBins = 5;
237 std::vector<int> binEntries = {1, 2, 5, 1, 6, 4, 5};
238 std::vector<int> binIntegral = getBinIntegral(binEntries);
239
240 const auto& rofTimeRecords = makeTimeROFs(binEntries, winSize, nBins);
241 BOOST_CHECK_EQUAL(rofTimeRecords.size(), 2);
242
243 checkROF(rofTimeRecords[0], binEntries, winSize, nBins, 0, 2);
244 checkROF(rofTimeRecords[1], binEntries, winSize, nBins, 2, 5);
245}
246
247BOOST_AUTO_TEST_SUITE_END()
248BOOST_AUTO_TEST_SUITE_END()
uint64_t orbit
Definition RawEventData.h:6
int32_t i
Class to group the fired pads according to their time stamp.
int getNEntries() const
get the number of associated objects
Definition ROFRecord.h:55
const BCData & getBCData() const
get the interaction record
Definition ROFRecord.h:46
int getFirstIdx() const
get the index of the first associated object
Definition ROFRecord.h:57
int getBCWidth() const
get the time span by this ROF, in BC unit
Definition ROFRecord.h:64
GLsizeiptr size
Definition glcorearb.h:659
GLint GLsizei width
Definition glcorearb.h:270
GLuint start
Definition glcorearb.h:469
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
BOOST_AUTO_TEST_CASE(OneTimeCluster)
std::vector< ROFRecord > ROFVector
o2::InteractionRecord ir(0, 0)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())
std::vector< Digit > digits