REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
Loading...
Searching...
No Matches
test/src/TRestDetectorReadout.cxx
1
2#include <TRestDetectorReadoutPlane.h>
3#include <gtest/gtest.h>
4
5#include <filesystem>
6
7namespace fs = std::filesystem;
8
9using namespace std;
10
11const auto filesPath = fs::path(__FILE__).parent_path().parent_path() / "files";
12
13constexpr double tolerance = 1E-6;
14
15bool AreEqual(const TVector3& a, const TVector3& b) { return (a - b).Mag2() < tolerance; }
16
17TEST(TRestDetectorReadout, TestFiles) {
18 cout << "FrameworkCore test files path: " << filesPath << endl;
19
20 // Check dir exists and is a directory
21 EXPECT_TRUE(fs::is_directory(filesPath));
22 // Check it's not empty
23 EXPECT_TRUE(!fs::is_empty(filesPath));
24}
25
26TEST(TRestDetectorReadout, Axes) {
27 {
29 plane.PrintMetadata();
30 // default values
31
32 EXPECT_TRUE(AreEqual(plane.GetNormal(), {0, 0, 1}));
33 EXPECT_TRUE(AreEqual(plane.GetAxisX(), {1, 0, 0}));
34 EXPECT_TRUE(AreEqual(plane.GetAxisY(), {0, 1, 0}));
35 }
36
37 {
39 plane.SetNormal({0, 0, -1});
40 plane.PrintMetadata();
41
42 EXPECT_TRUE(AreEqual(plane.GetNormal(), {0, 0, -1}));
43 EXPECT_TRUE(AreEqual(plane.GetAxisX(), {0, -1, 0}));
44 EXPECT_TRUE(AreEqual(plane.GetAxisY(), {-1, 0, 0}));
45 }
46
47 {
49 plane.SetNormal({0, 0.01, 1});
50 plane.PrintMetadata();
51
52 EXPECT_TRUE(AreEqual(plane.GetNormal(), {0, 0.0099995, 0.99995}));
53 EXPECT_TRUE(AreEqual(plane.GetAxisX(), {1, 0, 0}));
54 EXPECT_TRUE(AreEqual(plane.GetAxisY(), {0, 0.99995, -0.0099995}));
55 }
56}
57
58TEST(TRestDetectorReadout, SetAxisX) {
60 plane.SetNormal({0, 0.5, 1});
61 plane.SetPosition({10.0, 5.0, 50.0});
62 plane.SetRotation(TMath::DegToRad() * 32.0);
63 plane.SetHeight(10.0);
64 plane.PrintMetadata();
65 // default values
66
67 // axis will be projected into the plane
68 const TVector3 newXAxis = {1.0, -2.0, 5.0};
69
70 plane.SetAxisX(newXAxis);
71
72 const TVector3 axisX = plane.GetAxisX();
73 const TVector3 newXAxisProjected =
74 (newXAxis - plane.GetNormal() * newXAxis.Dot(plane.GetNormal())).Unit();
75 cout << "axisX: " << axisX.X() << ", " << axisX.Y() << ", " << axisX.Z() << endl;
76 cout << "axisXProjected: " << newXAxisProjected.X() << ", " << newXAxisProjected.Y() << ", "
77 << newXAxisProjected.Z() << endl;
78 EXPECT_TRUE(AreEqual(plane.GetAxisX(), newXAxisProjected));
79}
80
81TEST(TRestDetectorReadout, Module) {
83 plane.SetNormal({0, 0, 1});
84 plane.SetPosition({10.0, 5.0, 50.0});
85 plane.SetRotation(TMath::DegToRad() * 90.0);
86 plane.SetHeight(10.0);
87
88 plane.PrintMetadata();
89
90 const TVector3 worldPoint = {0, 0, 100.0};
91 const TVector2 local = plane.GetPositionInPlane(worldPoint);
92 cout << "local: " << local.X() << ", " << local.Y() << endl;
93
94 const auto distance = plane.GetDistanceToPlane(worldPoint);
95 cout << "distance: " << distance << endl;
96}
void SetPosition(const TVector3 &position)
Sets the readout plane position.
void SetNormal(const TVector3 &normal)
It updates the value of the normal vector and recalculates the corresponding X and Y axis.
TVector3 GetNormal() const
Returns a TVector3 with a vector normal to the readout plane.
TVector3 GetAxisY() const
Returns a TVector3 with a vector that defines the Y-axis plane coordinate system.
void PrintMetadata()
Prints the readout plane description.
TVector3 GetAxisX() const
Returns a TVector3 with a vector that defines the X-axis plane coordinate system.
void SetHeight(Double_t d)
Used to define the height of the readout volume with sign crosscheck.
A metadata class to generate/store a readout description.