Project
Loading...
Searching...
No Matches
testFilter.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
16
17#define BOOST_TEST_MODULE midFiltering
18#define BOOST_TEST_DYN_LINK
19#include <boost/test/unit_test.hpp>
20
21#include <boost/test/data/test_case.hpp>
22#include <cstdint>
23#include <random>
24#include <string>
25#include <sstream>
26#include <vector>
33
34namespace o2
35{
36namespace mid
37{
38
39std::vector<ColumnData> generateData(size_t nData = 10)
40{
41
42 std::random_device rd;
43 std::mt19937 mt(rd());
44 std::uniform_int_distribution<uint8_t> deIds(0, 71);
45 std::uniform_int_distribution<uint8_t> colIds(0, 6);
46 std::uniform_int_distribution<uint16_t> patterns(0, 0xFFFF);
47
48 std::vector<ColumnData> data;
49 for (size_t idata = 0; idata < nData; ++idata) {
51 col.deId = deIds(mt);
52 col.columnId = colIds(mt);
53 for (int iline = 0; iline < 4; ++iline) {
54 col.setBendPattern(patterns(mt), iline);
55 }
56 col.setNonBendPattern(patterns(mt));
57 data.emplace_back(col);
58 }
59 return data;
60}
61
63{
64 ColumnData col1;
65 col1.deId = 71;
66 col1.columnId = 6;
67 col1.setNonBendPattern(0x8000);
68
69 ChannelMasksHandler masksHandler;
70 masksHandler.switchOffChannels(col1);
71 auto maskVec = masksHandler.getMasks();
72 BOOST_TEST(maskVec.size() == 1);
73 for (auto mask : maskVec) {
74 for (int iline = 0; iline < 4; ++iline) {
75 BOOST_TEST(mask.getBendPattern(iline) == static_cast<uint16_t>(~col1.getBendPattern(iline)));
76 }
77 BOOST_TEST(mask.getNonBendPattern() == static_cast<uint16_t>(~col1.getNonBendPattern()));
78 }
79}
80
82{
83
84 ColumnData col1;
85 col1.deId = 71;
86 col1.columnId = 6;
87 col1.setNonBendPattern(0x8000);
88
90 cs.count(col1);
91 auto sc1 = cs.getScalers();
92 BOOST_REQUIRE(sc1.size() == 1);
93 for (auto& sc : sc1) {
94 BOOST_TEST(cs.getDeId(sc.first) = col1.deId);
95 BOOST_TEST(cs.getColumnId(sc.first) = col1.columnId);
96 BOOST_TEST(cs.getLineId(sc.first) == 0);
97 BOOST_TEST(cs.getCathode(sc.first) == 1);
98 BOOST_TEST(cs.getStrip(sc.first) == 15);
99 }
100 cs.reset();
101
102 ColumnData col2;
103 col2.deId = 25;
104 col2.columnId = 3;
105 col2.setBendPattern(0x0100, 3);
106 cs.count(col2);
107 auto sc2 = cs.getScalers();
108 BOOST_REQUIRE(sc2.size() == 1);
109 for (auto& sc : sc2) {
110 BOOST_TEST(cs.getDeId(sc.first) = col2.deId);
111 BOOST_TEST(cs.getColumnId(sc.first) = col2.columnId);
112 BOOST_TEST(cs.getLineId(sc.first) == 3);
113 BOOST_TEST(cs.getCathode(sc.first) == 0);
114 BOOST_TEST(cs.getStrip(sc.first) == 8);
115 }
116}
117
119{
120 auto data = generateData();
122 std::vector<ColumnData> refMasks{};
123 for (auto col : data) {
124 cs.reset();
125 cs.count(col);
126 auto masks = makeMasks(cs, 1, 0., refMasks);
127 BOOST_TEST(masks.size() == 1);
128 for (auto& mask : masks) {
129 for (int iline = 0; iline < 4; ++iline) {
130 BOOST_TEST(mask.getBendPattern(iline) == static_cast<uint16_t>(~col.getBendPattern(iline)));
131 }
132 BOOST_TEST(mask.getNonBendPattern() == static_cast<uint16_t>(~col.getNonBendPattern()));
133 }
134 }
135}
136
138{
140
141 // Use the masks as FET: all channels should answer
142 auto fets = makeDefaultMasks();
143
144 // We now modify one FET data
145 uint16_t fullPattern = 0xFFFF;
146 for (auto& col : fets) {
147 if (col.deId == 3 && col.columnId == 0) {
148 col.setBendPattern(fullPattern & ~0x1, 0);
149 col.setBendPattern(fullPattern, 1);
150 col.setBendPattern(fullPattern, 2);
151 // The following does not exist in deId 3, col 0
152 col.setBendPattern(fullPattern & ~0x1, 3);
153 col.setNonBendPattern(fullPattern);
154 }
155 }
156
157 FetToDead fetToDead;
158 auto inverted = fetToDead.process(fets);
159
160 BOOST_TEST(inverted.size() == 1);
161 BOOST_TEST(inverted.back().deId == 3);
162 BOOST_TEST(inverted.back().columnId == 0);
163 BOOST_TEST(inverted.back().getBendPattern(0) == 1);
164 BOOST_TEST(inverted.back().getBendPattern(1) == 0);
165 BOOST_TEST(inverted.back().getBendPattern(2) == 0);
166 // Test that the non-existing pattern was not converted
167 // Since the mask in the FET conversion takes care of removing it
168 BOOST_TEST(inverted.back().getBendPattern(3) == 0);
169 BOOST_TEST(inverted.back().getNonBendPattern() == 0);
170}
171
173{
175 FiltererBC filterBC;
176 BunchFilling bcFill;
177 int collBC1 = 100;
178 int collBC2 = 105;
179 int bcDiffLow = -1;
180 int bcDiffHigh = 1;
181 bcFill.setBC(collBC1);
182 bcFill.setBC(collBC2);
183
184 filterBC.setBunchFilling(bcFill);
185 filterBC.setBCDiffLow(bcDiffLow);
186 filterBC.setBCDiffHigh(bcDiffHigh);
187 std::vector<ROFRecord> rofs;
188 int nColBC1_1 = 1;
189 int nColBC1_2 = 2;
190 int nColBC2 = 4;
191
192 // Data compatible with collision BC1
193 InteractionRecord ir(collBC1 + bcDiffLow, 1);
194 rofs.emplace_back(ir, EventType::Standard, 0, nColBC1_1);
195
196 // Data compatible with collision BC1
197 ir.bc = collBC1 + bcDiffHigh;
198 rofs.emplace_back(ir, EventType::Standard, rofs.back().getEndIndex(), nColBC1_2);
199
200 // Data not compatible with collision BC
201 ir.bc = collBC1 + bcDiffHigh + 1;
202 rofs.emplace_back(ir, EventType::Standard, rofs.back().getEndIndex(), 1);
203
204 // Data compatible with collision BC2
205 ir.bc = collBC2;
206 rofs.emplace_back(ir, EventType::Standard, rofs.back().getEndIndex(), nColBC2);
207
208 auto filteredROFs = filterBC.process(rofs);
209
210 BOOST_REQUIRE(filteredROFs.size() == 2);
211
212 // Check that the first two are merged
213 BOOST_TEST(filteredROFs.front().interactionRecord.bc == collBC1);
214 BOOST_TEST(filteredROFs.front().nEntries == nColBC1_1 + nColBC1_2);
215
216 // Check that the last is kept unchanged
217 BOOST_TEST(filteredROFs.back().interactionRecord.bc == collBC2);
218 BOOST_TEST(filteredROFs.back().nEntries == nColBC2);
219}
220
221} // namespace mid
222} // namespace o2
MID channels masks handler.
MID channel scalers.
Strip pattern (aka digits)
unsigned short int uint16_t
Class to convert the FEE test event into dead channels.
BC filterer for MID.
Function to produce the MID masks.
uint32_t col
Definition RawData.h:4
void setBC(int bcID, bool active=true, int dir=-1)
std::vector< ColumnData > getMasks() const
Gets the masks.
void switchOffChannels(const ColumnData &badChannels)
void count(const ColumnData &patterns)
const std::unordered_map< uint32_t, uint32_t > & getScalers() const
Gets the scalers.
uint8_t getCathode(uint32_t uniqueId) const
Gets cathode from unique Id.
uint8_t getLineId(uint32_t uniqueId) const
Gets lineId from unique Id.
void reset()
Resets scalers.
uint8_t getDeId(uint32_t uniqueId) const
Gets deId from unique Id.
uint8_t getColumnId(uint32_t uniqueId) const
Gets columnId from unique Id.
uint8_t getStrip(uint32_t uniqueId) const
Gets strip from unique Id.
std::vector< ColumnData > process(gsl::span< const ColumnData > fetData)
Definition FetToDead.cxx:51
Filtering algorithm for MID.
Definition FiltererBC.h:31
void setBCDiffLow(int bcDiffLow)
Set the maximum BC diff in the lower side.
Definition FiltererBC.h:40
void setBunchFilling(const BunchFilling &bunchFilling)
Sets the bunch filling scheme.
Definition FiltererBC.h:52
std::vector< ROFRecord > process(gsl::span< const ROFRecord > rofRecords)
Filters the data BC.
void setBCDiffHigh(int bcDiffHigh)
Set the maximum BC diff in the upper side.
Definition FiltererBC.h:44
GLint GLuint mask
Definition glcorearb.h:291
std::vector< ColumnData > makeDefaultMasks()
Definition MaskMaker.cxx:62
std::vector< ColumnData > generateData(size_t nData=10)
std::mt19937 mt(rd())
std::vector< ColumnData > makeMasks(const ChannelScalers &scalers, double timeOrTriggers, double threshold, const std::vector< ColumnData > &refMasks={})
Definition MaskMaker.cxx:43
BOOST_TEST(clusters.size()==clusterizer.getClusters().size())
BOOST_AUTO_TEST_CASE(mask)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
uint16_t bc
bunch crossing ID of interaction
Column data structure for MID.
Definition ColumnData.h:29
uint8_t columnId
Column in DE.
Definition ColumnData.h:31
uint16_t getBendPattern(int line) const
Gets the bending plane pattern.
Definition ColumnData.h:37
uint8_t deId
Index of the detection element.
Definition ColumnData.h:30
void setNonBendPattern(uint16_t pattern)
Sets the non-bending plane pattern.
Definition ColumnData.h:40
void setBendPattern(uint16_t pattern, int line)
Sets the bending plane pattern.
Definition ColumnData.h:35
uint16_t getNonBendPattern() const
Gets the non-bending plane pattern.
Definition ColumnData.h:42
o2::InteractionRecord ir(0, 0)
std::random_device rd