Skip to content

Commit

Permalink
add method to set plane x-axis explicitly. Add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
lobis committed Jun 13, 2023
1 parent 0fe6b35 commit b244133
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions inc/TRestDetectorReadoutPlane.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class TRestDetectorReadoutPlane {

void SetRotation(Double_t radians);

void SetAxisX(const TVector3& axis);

// Getters
/// Returns an integer with the plane id number.
inline Int_t GetID() const { return fId; }
Expand Down
14 changes: 14 additions & 0 deletions src/TRestDetectorReadoutPlane.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -523,3 +523,17 @@ TVector3 TRestDetectorReadoutPlane::GetPositionInWorld(const TVector2& point, Do
Double_t TRestDetectorReadoutPlane::GetDistanceToPlane(const TVector3& point) const {
return (point - fPosition).Dot(fNormal);
}

void TRestDetectorReadoutPlane::SetAxisX(const TVector3& axis) {
const TVector3 axisInPlane = (axis - axis.Dot(fNormal) * fNormal).Unit();
if (axisInPlane.Mag2() < 1E-6) {
RESTError << "TRestDetectorReadoutPlane::SetAxisX() : "
<< "The X-axis vector must not be parallel to the normal vector." << RESTendl;
exit(1);
}

// compute the angle between the new axis and the old axis
const Double_t angle = fAxisX.Angle(axisInPlane);

SetRotation(fRotation - angle);
}
40 changes: 40 additions & 0 deletions test/src/TRestDetectorReadout.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,43 @@ TEST(TRestDetectorReadout, Axes) {
EXPECT_TRUE(AreEqual(plane.GetAxisY(), {0, 0.99995, -0.0099995}));
}
}

TEST(TRestDetectorReadout, SetAxisX) {
TRestDetectorReadoutPlane plane;
plane.SetNormal({0, 0.5, 1});
plane.SetPosition({10.0, 5.0, 50.0});
plane.SetRotation(TMath::DegToRad() * 32.0);
plane.SetHeight(10.0);
plane.PrintMetadata();
// default values

// axis will be projected into the plane
const TVector3 newXAxis = {1.0, -2.0, 5.0};

plane.SetAxisX(newXAxis);

const TVector3 axisX = plane.GetAxisX();
const TVector3 newXAxisProjected =
(newXAxis - plane.GetNormal() * newXAxis.Dot(plane.GetNormal())).Unit();
cout << "axisX: " << axisX.X() << ", " << axisX.Y() << ", " << axisX.Z() << endl;
cout << "axisXProjected: " << newXAxisProjected.X() << ", " << newXAxisProjected.Y() << ", "
<< newXAxisProjected.Z() << endl;
EXPECT_TRUE(AreEqual(plane.GetAxisX(), newXAxisProjected));
}

TEST(TRestDetectorReadout, Module) {
TRestDetectorReadoutPlane plane;
plane.SetNormal({0, 0, 1});
plane.SetPosition({10.0, 5.0, 50.0});
plane.SetRotation(TMath::DegToRad() * 90.0);
plane.SetHeight(10.0);

plane.PrintMetadata();

const TVector3 worldPoint = {0, 0, 100.0};
const TVector2 local = plane.GetPositionInPlane(worldPoint);
cout << "local: " << local.X() << ", " << local.Y() << endl;

const auto distance = plane.GetDistanceToPlane(worldPoint);
cout << "distance: " << distance << endl;
}

0 comments on commit b244133

Please sign in to comment.