Project
Loading...
Searching...
No Matches
testO2TPCIDCAverageGroup.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 Test TPC O2TPCIDCAverageGroup class
18#define BOOST_TEST_MAIN
19#define BOOST_TEST_DYN_LINK
20#include <boost/test/unit_test.hpp>
22#include <vector>
23#include <algorithm>
24
25namespace o2
26{
27namespace tpc
28{
29
30static constexpr unsigned short MAXGRPAD = 10; // maximum number of pads grouped
31static constexpr unsigned short MAXGRROW = 4; // maximum number of pads grouped
32static constexpr unsigned short MAXGRTHR = 2; // maximum number of pads grouped
33static constexpr unsigned int MAXGRSECEDGE = 4; // maximum number of pads grouped
34static constexpr unsigned int NINTEGRATIONINTERVALS = 3; // maximum number of pads grouped
35static constexpr const int MAXGROUPS = 4; // maximum number of pads at the sector edges which are grouped
36static constexpr const int NITER = 2; // number of iterations performed for the testing
37
38unsigned int genRand(const int maxVal)
39{
40 return rand() % maxVal;
41}
42
43unsigned int genRandSecEdge()
44{
45 unsigned int groupPadsSectorEdges = genRand(MAXGRSECEDGE);
46 for (int i = 0; i < MAXGROUPS - 1; ++i) {
47 groupPadsSectorEdges *= 10;
48 groupPadsSectorEdges += genRand(MAXGRSECEDGE) + 1;
49 }
50 return groupPadsSectorEdges;
51}
52
53std::vector<float> getIDCs(const int region)
54{
55 const int nIDCs = Mapper::PADSPERREGION[region];
56 std::vector<float> idcsTmp(nIDCs);
57 std::iota(std::begin(idcsTmp), std::end(idcsTmp), 0);
58
59 std::vector<float> idcs;
60 for (unsigned int i = 0; i < NINTEGRATIONINTERVALS; ++i) {
61 idcs.insert(idcs.end(), idcsTmp.begin(), idcsTmp.end());
62 }
63 return idcs;
64}
65
66std::vector<float> getIDCsSide()
67{
68 std::vector<float> idcs;
69
70 std::array<std::vector<float>, Mapper::NREGIONS> idcsPerRegion;
71 for (int region = 0; region < Mapper::NREGIONS; ++region) {
72 const int nIDCs = Mapper::PADSPERREGION[region];
73 auto& idc = idcsPerRegion[region];
74 idc.resize(nIDCs);
75 std::iota(std::begin(idc), std::end(idc), 0);
76 }
77
78 for (unsigned int i = 0; i < NINTEGRATIONINTERVALS; ++i) {
79 for (int sector = 0; sector < SECTORSPERSIDE; ++sector) {
80 for (int region = 0; region < Mapper::NREGIONS; ++region) {
81 const auto& idc = idcsPerRegion[region];
82 idcs.insert(idcs.end(), idc.begin(), idc.end());
83 }
84 }
85 }
86 return idcs;
87}
88
89BOOST_AUTO_TEST_CASE(AverageGroupSector_test)
90{
91 std::srand(std::time(nullptr));
92
93 const static auto& paramIDCGroup = ParameterIDCGroup::Instance();
94 BOOST_CHECK(paramIDCGroup.method == AveragingMethod::FAST);
95
96 // create some random IDCs for one TPC side
97 const auto idcsPerSide = getIDCsSide();
98
99 std::array<std::vector<float>, Mapper::NREGIONS> idcsRegion;
100 for (int i = 0; i < Mapper::NREGIONS; ++i) {
101 idcsRegion[i] = getIDCs(i);
102 }
103
104 // get the total sum of the reference IDCs (consider rounding of floats)
105 unsigned long refSumIDCs = 0;
106 for (const auto val : idcsPerSide) {
107 refSumIDCs += static_cast<unsigned long>(val + 0.1f);
108 }
109 refSumIDCs *= 2;
110
111 // converting the IDCs to IDCDelta object which is used forthe averating and grouping
112 IDCDelta<float> idcs;
113 idcs.getIDCDelta() = idcsPerSide;
114
115 for (int iter = 0; iter < NITER; ++iter) {
116 // type=0: do nothing special for grouping at sector edges, typ1=1: do group pads at sector edges in pad direction, typ1=2: group pads at sector edges in pad+row direction
117 for (int type = 0; type < 3; ++type) {
118 const unsigned char grPadTmp = genRand(MAXGRPAD) + 1;
119 const unsigned char grRowTmp = genRand(MAXGRROW) + 1;
120 const unsigned char grRowThrTmp = genRand(MAXGRTHR);
121 const unsigned char grPadThrTmp = genRand(MAXGRTHR);
122 const unsigned int groupPadsSectorEdges = type == 0 ? 0 : 10 * genRandSecEdge() + type - 1;
123 std::array<unsigned char, Mapper::NREGIONS> grPad{};
124 std::fill(grPad.begin(), grPad.end(), grPadTmp);
125 std::array<unsigned char, Mapper::NREGIONS> grRow{};
126 std::fill(grRow.begin(), grRow.end(), grRowTmp);
127 std::array<unsigned char, Mapper::NREGIONS> grRowThr{};
128 std::fill(grRowThr.begin(), grRowThr.end(), grRowThrTmp);
129 std::array<unsigned char, Mapper::NREGIONS> grPadThr{};
130 std::fill(grPadThr.begin(), grPadThr.end(), grPadThrTmp);
131
132 // perform the grouping
133 IDCAverageGroup<IDCAverageGroupTPC> idcaverage(grPad, grRow, grRowThr, grPadThr, groupPadsSectorEdges);
134 idcaverage.setIDCs(idcs, Side::A);
135 idcaverage.processIDCs();
136
137 std::array<IDCAverageGroup<IDCAverageGroupCRU>, Mapper::NREGIONS> idcaverageCRU{
138 IDCAverageGroup<IDCAverageGroupCRU>(grPadTmp, grRowTmp, grRowThrTmp, grPadThrTmp, groupPadsSectorEdges, 0),
139 IDCAverageGroup<IDCAverageGroupCRU>(grPadTmp, grRowTmp, grRowThrTmp, grPadThrTmp, groupPadsSectorEdges, 1),
140 IDCAverageGroup<IDCAverageGroupCRU>(grPadTmp, grRowTmp, grRowThrTmp, grPadThrTmp, groupPadsSectorEdges, 2),
141 IDCAverageGroup<IDCAverageGroupCRU>(grPadTmp, grRowTmp, grRowThrTmp, grPadThrTmp, groupPadsSectorEdges, 3),
142 IDCAverageGroup<IDCAverageGroupCRU>(grPadTmp, grRowTmp, grRowThrTmp, grPadThrTmp, groupPadsSectorEdges, 4),
143 IDCAverageGroup<IDCAverageGroupCRU>(grPadTmp, grRowTmp, grRowThrTmp, grPadThrTmp, groupPadsSectorEdges, 5),
144 IDCAverageGroup<IDCAverageGroupCRU>(grPadTmp, grRowTmp, grRowThrTmp, grPadThrTmp, groupPadsSectorEdges, 6),
145 IDCAverageGroup<IDCAverageGroupCRU>(grPadTmp, grRowTmp, grRowThrTmp, grPadThrTmp, groupPadsSectorEdges, 7),
146 IDCAverageGroup<IDCAverageGroupCRU>(grPadTmp, grRowTmp, grRowThrTmp, grPadThrTmp, groupPadsSectorEdges, 8),
147 IDCAverageGroup<IDCAverageGroupCRU>(grPadTmp, grRowTmp, grRowThrTmp, grPadThrTmp, groupPadsSectorEdges, 9)};
148
149 for (unsigned int region = 0; region < Mapper::NREGIONS; ++region) {
150 idcaverageCRU[region].setIDCs(idcsRegion[region]);
151 idcaverageCRU[region].processIDCs();
152 }
153
154 // get the total sum of the grouped IDCs (consider rounding of floats)
155 unsigned long sumGroupedIDCs = 0;
156 unsigned long sumGroupedIDCsCRU = 0;
157 std::vector<unsigned long> sumGroupedIDCsSector(NINTEGRATIONINTERVALS * Mapper::NSECTORS);
158 for (unsigned int i = 0; i < NINTEGRATIONINTERVALS; ++i) {
159 for (unsigned int sector = 0; sector < Mapper::NSECTORS; ++sector) {
160 const int index = sector + i * Mapper::NSECTORS;
161 for (unsigned int region = 0; region < Mapper::NREGIONS; ++region) {
162 for (unsigned int irow = 0; irow < Mapper::ROWSPERREGION[region]; ++irow) {
163 for (unsigned int ipad = 0; ipad < Mapper::PADSPERROW[region][irow]; ++ipad) {
164 const auto valSector = static_cast<unsigned long>(idcaverage.getUngroupedIDCDeltaVal(sector, region, irow, ipad, i) + 0.1f);
165 const auto valCRU = static_cast<unsigned long>(idcaverageCRU[region].getUngroupedIDCValLocal(irow, ipad, i) + 0.1f);
166 sumGroupedIDCsSector[index] += valSector;
167 sumGroupedIDCsCRU += valCRU;
168 BOOST_CHECK(valSector == valCRU);
169 }
170 }
171 }
172 sumGroupedIDCs += sumGroupedIDCsSector[i];
173 }
174 }
175
176 // comparing the sum from the reference IDCs to the sum of the grouped IDCs
177 BOOST_CHECK(refSumIDCs == sumGroupedIDCs);
178 BOOST_CHECK(refSumIDCs == sumGroupedIDCsCRU);
179
180 // comparing the reference sum of IDCs per sector with the grouped IDCs per sector
181 for (const auto idcsSec : sumGroupedIDCsSector) {
182 BOOST_CHECK(refSumIDCs / sumGroupedIDCsSector.size() == idcsSec);
183 }
184 }
185 }
186}
187
188} // namespace tpc
189} // namespace o2
int32_t i
class for averaging and grouping of IDCs
void processIDCs(const CalDet< PadFlags > *padStatusFlags=nullptr)
static const std::vector< unsigned int > PADSPERROW[NREGIONS]
number of pads per row in region
Definition Mapper.h:567
static constexpr unsigned int ROWSPERREGION[NREGIONS]
number of pad rows for region
Definition Mapper.h:532
static constexpr unsigned int NSECTORS
total number of sectors in the TPC
Definition Mapper.h:526
static constexpr unsigned int NREGIONS
total number of regions in one sector
Definition Mapper.h:527
static constexpr unsigned int PADSPERREGION[NREGIONS]
number of pads per CRU
Definition Mapper.h:530
GLuint index
Definition glcorearb.h:781
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLuint GLfloat * val
Definition glcorearb.h:1582
std::vector< float > getIDCsSide()
BOOST_AUTO_TEST_CASE(ClusterHardware_test1)
constexpr unsigned char SECTORSPERSIDE
Definition Defs.h:40
unsigned int genRandSecEdge()
@ A
Definition Defs.h:35
std::vector< float > getIDCs(const int region)
@ FAST
no outlier filtering performed. Only averaging
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
struct to access and set Delta IDCs
const auto & getIDCDelta() const
BOOST_CHECK(tree)