Project
Loading...
Searching...
No Matches
testGeometry.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
14
15#define BOOST_TEST_MODULE Test MID simulation
16#define BOOST_TEST_DYN_LINK
17
18#include <boost/test/unit_test.hpp>
19
20// #include "boost/format.hpp"
21// #include <boost/test/data/monomorphic.hpp>
22// #include <boost/test/data/monomorphic/generators/xrange.hpp>
23#include <boost/test/data/test_case.hpp>
24#include <fstream>
25#include <iostream>
26#include "MathUtils/Cartesian.h"
27#include "TGeoManager.h"
30
31BOOST_AUTO_TEST_SUITE(o2_mid_simulation)
32
34{
36 if (gGeoManager && gGeoManager->GetTopVolume()) {
37 std::cerr << "Can only call this function with an empty geometry, i.e. gGeoManager==nullptr "
38 << " or gGeoManager->GetTopVolume()==nullptr\n";
39 }
40 TGeoManager* gm = new TGeoManager("MID-ONLY", "ALICE MID Standalone Geometry");
41 TGeoMaterial* mat = new TGeoMaterial("Vacuum", 0, 0, 0);
42 TGeoMedium* med = new TGeoMedium("Vacuum", 1, mat);
43 TGeoVolume* top = gGeoManager->MakeBox(name, med, 2000.0, 2000.0, 3000.0);
44 gm->SetTopVolume(top);
46}
47
48struct LocalPoint {
49 LocalPoint(int ide, double x, double y) : deId(ide), xPos(x), yPos(y) {}
50 int deId;
51 double xPos;
52 double yPos;
53};
54
55std::vector<LocalPoint> getPositions(int npoints)
56{
57 std::random_device rd;
58 std::mt19937 mt(rd());
59 std::uniform_real_distribution<double> distX(-127.5, 127.5);
60 std::uniform_real_distribution<double> distY(-40., 40.);
61 std::uniform_int_distribution<int> distDE(0, 71);
62
63 std::vector<LocalPoint> localPoints;
64
65 for (int ipt = 0; ipt < npoints; ++ipt) {
66 localPoints.emplace_back(distDE(mt), distX(mt), distY(mt));
67 }
68 return localPoints;
69}
70
71bool areEqual(double a, double b)
72{
73 return std::fabs(b - a) < 1E-4; // 1E-4 cm = 1 micron
74}
75
77{
78 if (!areEqual(p1.x(), p2.x())) {
79 return false;
80 }
81 if (!areEqual(p1.y(), p2.y())) {
82 return false;
83 }
84 if (!areEqual(p1.z(), p2.z())) {
85 return false;
86 }
87 return true;
88}
89
90int testOnePosition(const LocalPoint& localPt, const o2::mid::GeometryTransformer& geoTrans, const o2::mid::GeometryTransformer& geoTransFromManager)
91{
92 int deId = localPt.deId;
93 auto p1 = geoTrans.localToGlobal(deId, localPt.xPos, localPt.yPos);
94 auto p2 = geoTransFromManager.localToGlobal(deId, localPt.xPos, localPt.yPos);
95 if (!areEqual(p1, p2)) {
96 std::cout << "got different positions for deId " << deId << " : got (" << p1.x() << ", " << p1.y() << ", " << p1.z() << ") expected (" << p2.x() << ", " << p2.y() << ", " << p2.z() << ")\n";
97 return 1;
98 }
99 return 0;
100}
101
102BOOST_AUTO_TEST_CASE(TestTransformations)
103{
106
108
109 auto positions = getPositions(1000);
110
111 int notok = 0;
112
113 for (auto& tp : positions) {
114 notok += testOnePosition(tp, geoTrans, geoTransFromManager);
115 }
116 BOOST_TEST(notok == 0);
117}
118
119BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(Geometry_test)
Geometry transformer for MID.
constexpr int p2()
constexpr int p1()
constexpr to accelerate the coordinates changing
Implementation of the trigger-stations geometry.
std::vector< LocalPoint > getPositions(int npoints)
int testOnePosition(const LocalPoint &localPt, const o2::mid::GeometryTransformer &geoTrans, const o2::mid::GeometryTransformer &geoTransFromManager)
void createStandaloneGeometry(const char *name)
bool areEqual(double a, double b)
math_utils::Point3D< T > localToGlobal(int deId, const math_utils::Point3D< T > &position) const
GLint GLenum GLint x
Definition glcorearb.h:403
GLdouble GLdouble GLdouble GLdouble top
Definition glcorearb.h:4077
GLuint const GLchar * name
Definition glcorearb.h:781
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GeometryTransformer createTransformationFromManager(const TGeoManager *geoManager)
void createGeometry(TGeoVolume &topVolume)
create MID geometry and attach it to existing topVolume
Definition Geometry.cxx:347
GeometryTransformer createDefaultTransformer()
LocalPoint(int ide, double x, double y)
std::random_device rd
BOOST_TEST(digits==digitsD, boost::test_tools::per_element())