Project
Loading...
Searching...
No Matches
testMapping.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 midBaseMapping
13#define BOOST_TEST_DYN_LINK
14#include <boost/test/unit_test.hpp>
15// Keep this separate or clang format will sort the include
16// thus breaking compilation
17#include <boost/test/data/monomorphic.hpp>
18#include <boost/test/data/monomorphic/generators/xrange.hpp>
19#include <boost/test/data/test_case.hpp>
20#include <iostream>
21#include <sstream>
22#include "MIDBase/Mapping.h"
23#include "MIDBase/MpArea.h"
24
25namespace bdata = boost::unit_test::data;
26
27namespace o2
28{
29namespace mid
30{
32{
33 public:
35};
36
37bool areEqual(const Mapping::MpStripIndex& strip1, const Mapping::MpStripIndex& strip2, int cathode)
38{
39 bool sameColStrip = (strip1.column == strip2.column && strip1.strip == strip2.strip);
40 if (cathode == 1) {
41 return sameColStrip;
42 }
43 return (sameColStrip && strip1.line == strip2.line);
44}
45
46bool findInNeighbours(const Mapping::MpStripIndex& refStrip, const std::vector<Mapping::MpStripIndex>& neighbours,
47 int cathode)
48{
49 for (auto const& neigh : neighbours) {
50 if (areEqual(refStrip, neigh, cathode)) {
51 return true;
52 }
53 }
54 std::cerr << "Cannot find " << refStrip.strip << " line " << refStrip.line << " column " << refStrip.column
55 << std::endl;
56 return false;
57}
58
59int findInNeighbours(float xPos, float yPos, int cathode, int deId, bool checkUpDown,
60 const std::vector<Mapping::MpStripIndex>& neighbours, const Mapping& mapping)
61{
62 int found = 0;
63 float delta = checkUpDown ? 0.1 : 0;
64 Mapping::MpStripIndex refStrip = mapping.stripByPosition(xPos, yPos + delta, cathode, deId, false);
65 if (!refStrip.isValid()) {
66 return found;
67 }
68
69 if (!findInNeighbours(refStrip, neighbours, cathode)) {
70 return -1;
71 }
72 ++found;
73
74 if (checkUpDown) {
75 Mapping::MpStripIndex upRef = mapping.stripByPosition(xPos, yPos - delta, cathode, deId, false);
76 if (!areEqual(refStrip, upRef, cathode)) {
77 if (!findInNeighbours(refStrip, neighbours, cathode)) {
78 return -2;
79 }
80 ++found;
81 }
82 }
83 return found;
84}
85
86bool areNeighboursOk(const Mapping::MpStripIndex& stripIndex, const std::vector<Mapping::MpStripIndex>& neighbours,
87 const Mapping& mapping, int cathode, int deId)
88{
89 MpArea stripArea =
90 mapping.stripByLocation(stripIndex.strip, cathode, stripIndex.line, stripIndex.column, deId, false);
91
92 std::stringstream ss;
93 ss << "Strip " << stripIndex.strip << " cathode " << cathode << " line " << stripIndex.line << " column "
94 << stripIndex.column;
95
96 bool isOk = true;
97
98 double xPos[3] = {stripArea.getXmin() - 0.1, stripArea.getCenterX(), stripArea.getXmax() + 0.1};
99 double yPos[3] = {stripArea.getYmin() - 0.1, stripArea.getCenterY(), stripArea.getYmax() + 0.1};
100
101 int nMatched = 0;
102 bool checkUpDown = false;
103 for (int ix = 0; ix < 3; ++ix) {
104 for (int iy = 0; iy < 3; ++iy) {
105 if ((ix - 1) * (iy - 1) != 0 || ix == iy) {
106 continue;
107 }
108 if (cathode == 0) {
109 checkUpDown = (ix == 1) ? false : true;
110 } else if (iy != 1) {
111 continue;
112 }
113
114 int nFound = findInNeighbours(xPos[ix], yPos[iy], cathode, deId, checkUpDown, neighbours, mapping);
115 if (nFound < 0) {
116 ss << " err: (" << ix - 1 << ", " << iy - 1 << ")";
117 isOk = false;
118 } else {
119 nMatched += nFound;
120 }
121 }
122 }
123
124 if (nMatched != neighbours.size()) {
125 isOk = false;
126 ss << " matched " << nMatched << " != " << neighbours.size();
127 }
128
129 if (!isOk) {
130 std::cerr << ss.str() << ". Neighbours: " << std::endl;
131 for (auto const& neigh : neighbours) {
132 std::cerr << " strip " << neigh.strip << " line " << neigh.line << " column " << neigh.column << std::endl;
133 }
134 }
135
136 return isOk;
137}
138
139BOOST_DATA_TEST_CASE_F(MyFixture, MID_Mapping_NeighboursNBP, boost::unit_test::data::xrange(72))
140{
141 int deId = sample;
142 for (int icolumn = mapping.getFirstColumn(deId); icolumn < 7; ++icolumn) {
143 int firstLineBP = mapping.getFirstBoardBP(icolumn, deId);
144 int lastLineBP = mapping.getLastBoardBP(icolumn, deId);
145 for (int icathode = 0; icathode < 2; ++icathode) {
146 int firstLine = firstLineBP;
147 int lastLine = lastLineBP;
148 if (icathode == 1) {
149 // When generating the neighbours in the non-bending plane
150 // we look at the y position as well (given by the "line")
151 // In the RPCs "cut", we can find or not a neighbour depending
152 // on the line.
153 // When we perform the tests here, we search for neighbours basing on the
154 // x, y position of the center of the strip.
155 // If we want to have consistent results we therefore need to attribute a line
156 // close to the center for the non-bending plane
157 firstLine = lastLine = (firstLine + lastLine) / 2;
158 }
159 int nStrips = (icathode == 0) ? 16 : mapping.getNStripsNBP(icolumn, deId);
160 for (int iline = firstLine; iline <= lastLine; ++iline) {
161 for (int istrip = 0; istrip < nStrips; ++istrip) {
162 Mapping::MpStripIndex stripIndex;
163 stripIndex.column = icolumn;
164 stripIndex.line = iline;
165 stripIndex.strip = istrip;
166 std::vector<Mapping::MpStripIndex> neighbours = mapping.getNeighbours(stripIndex, icathode, deId);
167 BOOST_TEST(areNeighboursOk(stripIndex, neighbours, mapping, icathode, deId));
168 } // loop on strips
169 } // loop on lines
170 } // loop on cathode
171 } // loop on column
172}
173
174} // namespace mid
175} // namespace o2
Mapping for MID.
Mapping area for MID.
MpStripIndex stripByPosition(double xPos, double yPos, int cathode, int deId, bool warn=true) const
Definition Mapping.cxx:592
MpArea stripByLocation(int strip, int cathode, int line, int column, int deId, bool warn=true) const
Definition Mapping.cxx:487
double getXmax() const
Get x max.
Definition MpArea.h:49
double getCenterY() const
Definition MpArea.cxx:40
double getYmin() const
Get y min.
Definition MpArea.h:51
double getYmax() const
Get y max.
Definition MpArea.h:53
double getCenterX() const
Definition MpArea.cxx:33
double getXmin() const
Get x min.
Definition MpArea.h:47
bool findInNeighbours(const Mapping::MpStripIndex &refStrip, const std::vector< Mapping::MpStripIndex > &neighbours, int cathode)
bool areEqual(const Mapping::MpStripIndex &strip1, const Mapping::MpStripIndex &strip2, int cathode)
BOOST_TEST(clusters.size()==clusterizer.getClusters().size())
bool areNeighboursOk(const Mapping::MpStripIndex &stripIndex, const std::vector< Mapping::MpStripIndex > &neighbours, const Mapping &mapping, int cathode, int deId)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Indexes required to define a strip in the detection element.
Definition Mapping.h:34
int strip
Line of the local board in the column.
Definition Mapping.h:39
bool isValid()
Check if Strip is Valid.
Definition Mapping.h:36
int line
Column in the DE.
Definition Mapping.h:38