FairRoot/PandaRoot
test_SensorAligner.cxx
Go to the documentation of this file.
1 // Define Boost test module
2 #define BOOST_TEST_MODULE LmdSensorAlignment
3 
4 #include <vector>
5 
6 #include <boost/test/unit_test.hpp>
7 
8 #include "TGeoMatrix.h"
9 #include "TRandom3.h"
10 
11 #include "PndLmdHitPair.h"
12 #include "PndLmdSensorAligner.h"
13 
14 BOOST_AUTO_TEST_SUITE(LmdSensorAlignment)
15 
16 TVector3 createRandomPoint() {
17  TVector3 point;
18  double scale(0.2);
19  point.SetX(gRandom->Uniform(scale));
20  point.SetY(gRandom->Uniform(scale));
21  point.SetZ(0.0);
22  return point;
23 }
24 
25 BOOST_AUTO_TEST_CASE(SimpleICPTest_Double) {
26  PndLmdSensorAligner aligner;
27 
28  gRandom = new TRandom3();
29 
30  std::vector<TVector3> original_points;
31  unsigned int num_points(100);
32  for (unsigned int i = 0; i < num_points; ++i) {
33  original_points.push_back(createRandomPoint());
34  }
35 
36  TGeoCombiTrans ideal_matrix;
37  double angle(2.1);
38  ideal_matrix.RotateZ(angle);
39  double shiftx(0.05);
40  double shifty(-0.03);
41  ideal_matrix.SetTranslation(shiftx, shifty, 0.0);
42 
43  PndLmdHitPair pair;
44  for (auto const& point : original_points) {
45  pair.setHit1(point);
46  double a[3] = { point.X(), point.Y(), point.Z() };
47  double b[3];
48  ideal_matrix.MasterToLocal(a, b);
49  pair.setHit2(TVector3(b[0], b[1], b[2]));
50  aligner.addSimplePair(pair); //returns true if addPair succeeded
51  }
52 
53  aligner.calculateMatrix();
54  Matrix result = aligner.getResultMatrix();
55  //std::cout<<result<<std::endl;
56  double sinangle = std::sin(TMath::Pi() * angle / 180);
57  double tolerance(1e-10); //relative
58  BOOST_CHECK_CLOSE(result.val[0][1], -sinangle, tolerance);
59  BOOST_CHECK_CLOSE(result.val[1][0], sinangle, tolerance);
60  BOOST_CHECK_CLOSE(result.val[0][3], shiftx, tolerance);
61  BOOST_CHECK_CLOSE(result.val[1][3], shifty, tolerance);
62 }
63 
64 BOOST_AUTO_TEST_CASE(SimpleICPTest_Float) {
65  PndLmdSensorAligner aligner;
66 
67  gRandom = new TRandom3();
68 
69  std::vector<TVector3> original_points;
70  unsigned int num_points(50);
71  for (unsigned int i = 0; i < num_points; ++i) {
72  original_points.push_back(createRandomPoint());
73  }
74 
75  TGeoRotation lmd_rot("lmd_rot");
76  lmd_rot.RotateX(0.0);
77  lmd_rot.RotateY(0.04 / 3.14 * 180.);
78  lmd_rot.RotateZ(0.0);
79  TGeoCombiTrans simple_trafo_to_lmd;
80  simple_trafo_to_lmd.SetRotation(lmd_rot);
81  simple_trafo_to_lmd.SetTranslation(7.0, 3.0, 1100.0);
82 
83  TGeoCombiTrans ideal_matrix;
84  double angle(2.0);
85  ideal_matrix.RotateZ(angle);
86  double shiftx(0.01);
87  double shifty(-0.03);
88  ideal_matrix.SetTranslation(shiftx, shifty, 0.0);
89 
90  PndLmdHitPair pair;
91  for (auto const& point : original_points) {
92  double a[3] = { point.X(), point.Y(), point.Z() };
93  double b[3];
94  ideal_matrix.MasterToLocal(a, b);
95  // now transform points to pnd global frame
96  double newa[3];
97  simple_trafo_to_lmd.LocalToMaster(a, newa);
98  double newb[3];
99  simple_trafo_to_lmd.LocalToMaster(b, newb);
100  // reduce precision
101  for(unsigned i = 0; i < 3; ++i) {
102  newa[i] = (float)newa[i];
103  newb[i] = (float)newb[i];
104  }
105  // and now transform back to lmd
106  simple_trafo_to_lmd.MasterToLocal(newa, a);
107  simple_trafo_to_lmd.MasterToLocal(newb, b);
108 
109  pair.setHit1(TVector3(a[0], a[1], a[2]));
110  pair.setHit2(TVector3(b[0], b[1], b[2]));
111  aligner.addSimplePair(pair);
112  }
113 
114  aligner.calculateMatrix();
115  Matrix result = aligner.getResultMatrix();
116  //std::cout<<result<<std::endl;
117  double sinangle = std::sin(TMath::Pi() * angle / 180);
118  double tolerance(1e-5); //absolute
119  BOOST_CHECK_SMALL(std::fabs(result.val[0][1] + sinangle), tolerance);
120  BOOST_CHECK_SMALL(std::fabs(result.val[1][0]- sinangle), tolerance);
121  BOOST_CHECK_SMALL(std::fabs(result.val[0][3] - shiftx), tolerance);
122  BOOST_CHECK_SMALL(std::fabs(result.val[1][3]- shifty) , tolerance);
123 }
124 
125 BOOST_AUTO_TEST_SUITE_END()
void setHit2(const TVector3 &hit2)
Definition: PndLmdHitPair.h:93
void setHit1(const TVector3 &hit1)
Definition: PndLmdHitPair.h:83
TVector3 createRandomPoint()
Int_t i
Definition: run_full.C:25
TTree * b
friend F32vec4 sin(const F32vec4 &a)
Definition: P4_F32vec4.h:111
bool addSimplePair(const PndLmdHitPair &pair)
BOOST_AUTO_TEST_CASE(SimpleICPTest_Double)
Int_t a
Definition: anaLmdDigi.C:126
TClonesArray * point
Definition: anaLmdDigi.C:29
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
Definition: matrix.h:50
Double_t angle
Double_t Pi
const Matrix & getResultMatrix() const
FLOAT ** val
Definition: matrix.h:138