15#define BOOST_TEST_DYN_LINK
17#include <boost/test/unit_test.hpp>
19#include <boost/format.hpp>
24#include <boost/test/data/monomorphic.hpp>
25#include <boost/test/data/monomorphic/generators/xrange.hpp>
26#include <boost/test/data/test_case.hpp>
33namespace bdata = boost::unit_test::data;
35using Point = std::pair<double, double>;
37BOOST_AUTO_TEST_SUITE(o2_mch_mapping)
38BOOST_AUTO_TEST_SUITE(cathode_segmentation_long)
42 std::ofstream out(fileName);
49 w.svgGroupStart(
"testpoints");
50 w.points(points, 0.1);
59 std::vector<Point> gaps;
63 if (env.size() != 1) {
64 throw std::runtime_error(
"assumption env contour = one polygon is not verified");
67 for (
double x =
bbox.xmin() - xstep;
x <=
bbox.xmax() + xstep;
x += xstep) {
68 for (
double y =
bbox.ymin() - ystep;
y <=
bbox.ymax() + ystep;
y += ystep) {
69 double distanceToEnveloppe =
71 bool withinEnveloppe = env.contains(
x,
y) && (distanceToEnveloppe > 1E-5);
73 gaps.emplace_back(
x,
y);
80BOOST_TEST_DECORATOR(*boost::unit_test::label(
"long"))
82 boost::unit_test::
data::make({100, 300, 500, 501, 502, 503, 504, 600, 601, 602, 700,
83 701, 702, 703, 704, 705, 706, 902, 903, 904, 905}) *
84 boost::unit_test::data::make({
true,
false}),
98 return std::fabs(
b -
a) < 1E-4;
106 double x = tp[
"x"].GetDouble();
107 double y = tp[
"y"].GetDouble();
110 bool isOutside{
false};
112 if (tp.HasMember(
"isoutside")) {
113 isOutside = (tp[
"isoutside"].GetString() == std::string(
"true"));
117 std::cerr <<
"found a pad where I was not expecting one" << std::endl;
120 if (!
seg.
isValid(catPadIndex) && !isOutside) {
121 std::cerr <<
"did not find a pad where I was expecting one" << std::endl;
126 return comp(
seg, catPadIndex, tp);
137 if (filepath.empty()) {
138 BOOST_TEST(
true,
"skipping test as no --testpos given");
143 rapidjson::Value& test_positions =
data.document()[
"testpositions"];
151 for (
auto& tp : test_positions.GetArray()) {
152 int detElemId = tp[
"de"].GetInt();
153 bool isBendingPlane = (tp[
"bending"].GetString() == std::string(
"true"));
158 std::cout << ntested <<
" tested for " <<
msg <<
": " << notok <<
" found not ok\n";
164BOOST_TEST_DECORATOR(*boost::unit_test::label(
"long"))
168 int catPadIndex, rapidjson::Value& tp) ->
int {
171 double ex = tp[
"px"].GetDouble();
172 double ey = tp[
"py"].GetDouble();
174 std::cout <<
"got different positions here : got px,py=" << px <<
"," << py <<
" vs expected x,y=" << ex <<
","
183BOOST_TEST_DECORATOR(*boost::unit_test::label(
"long"))
189 int catPadIndex, rapidjson::Value& tp)
194 if (
params.isTestFileInManuNumbering &&
params.isSegmentationRun3) {
195 dsch = ds2manu(tp[
"de"].GetInt(), dsch);
198 if (!
params.isTestFileInManuNumbering && !
params.isSegmentationRun3) {
199 dsch = manu2ds(tp[
"de"].GetInt(), dsch);
202 int eid = tp[
"dsid"].GetInt();
203 int ech = tp[
"dsch"].GetInt();
205 std::cout <<
"got different channel numbering for de " << tp[
"de"].GetInt() <<
" (dsid,dsch) " << dsid <<
"," << dsch <<
" vs expected =" << eid <<
"," << ech << std::endl;
210 "channel numbering");
213BOOST_TEST_DECORATOR(*boost::unit_test::label(
"long"))
217 for (
auto plane : {
true,
false }) {
219 int pmin = std::numeric_limits<int>::max();
222 catseg.forEachPad([&
n,&pmin,&pmax](
int dePadIndex) {
224 pmin = std::min(pmin,dePadIndex);
225 pmax = std::max(pmax,dePadIndex);
233BOOST_AUTO_TEST_SUITE_END()
234BOOST_AUTO_TEST_SUITE_END()
o2::mch::mapping::CathodeSegmentation seg
void dumpToFile(std::string fileName, const CathodeSegmentation &seg, const std::vector< Point > &points)
std::vector< Point > checkGaps(const CathodeSegmentation &seg, double xstep=1.0, double ystep=1.0)
int testOne(const o2::mch::mapping::CathodeSegmentation &seg, rapidjson::Value &tp, Comparator comp)
void TestWithComparator(Comparator comp, const char *msg)
bool areEqual(double a, double b)
std::pair< double, double > Point
BOOST_AUTO_TEST_CASE(TestPositions)
BOOST_DATA_TEST_CASE(NoGapWithinPads, boost::unit_test::data::make({100, 300, 500, 501, 502, 503, 504, 600, 601, 602, 700, 701, 702, 703, 704, 705, 706, 902, 903, 904, 905}) *boost::unit_test::data::make({true, false}), detElemId, isBendingPlane)
std::function< int(const o2::mch::mapping::CathodeSegmentation &, int, rapidjson::Value &)> Comparator
A CathodeSegmentation lets you find pads on a given plane (cathode) of a detection element and then i...
int padDualSampaChannel(int catPadIndex) const
int padDualSampaId(int catPadIndex) const
int findPadByPosition(double x, double y) const
double padPositionY(int catPadIndex) const
double padPositionX(int catPadIndex) const
bool isValid(int catPadIndex) const
Not every integer is a valid catPadIndex. This method will tell if catPadIndex is a valid one.
GLboolean GLboolean GLboolean b
GLenum const GLfloat * params
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLboolean GLboolean GLboolean GLboolean a
GLubyte GLubyte GLubyte GLubyte w
auto squaredDistancePointToPolygon(const Vertex< T > &point, const Polygon< T > &polygon) -> decltype(point.x *point.x)
int detElemId(Chamber chamber, Side side, int number)
std::string svgCathodeSegmentationDefaultStyle()
void svgCathodeSegmentation(const CathodeSegmentation &seg, o2::mch::contour::SVGWriter &writer, bool showdes, bool showdualsampas, bool showpads, bool showpadchannels)
void forOneDetectionElementOfEachSegmentationType(CALLABLE &&func)
o2::mch::contour::BBox< double > getBBox(const CathodeSegmentation &seg)
o2::mch::contour::Contour< double > getEnvelop(const CathodeSegmentation &seg)
Defining DataPointCompositeObject explicitly as copiable.
std::string to_string(gsl::span< T, Size > span)
BOOST_TEST(digits==digitsD, boost::test_tools::per_element())
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())
uint64_t const void const *restrict const msg