diff --git a/src/HEP/Detectors/DetectorChamber.cpp b/src/HEP/Detectors/DetectorChamber.cpp index d093c85..497d4b2 100644 --- a/src/HEP/Detectors/DetectorChamber.cpp +++ b/src/HEP/Detectors/DetectorChamber.cpp @@ -6,8 +6,10 @@ namespace uLib { MuonEvent DetectorChamber::ProjectMuonEvent(const MuonEvent &muon) const { MuonEvent projectedMuon = muon; - HPoint3f P = m_ProjectionPlane.origin; - HVector3f N = m_ProjectionPlane.direction; + // Transform the local projection plane to world coordinates + HLine3f worldPlane = this->GetWorldProjectionPlane(); + HPoint3f P = worldPlane.origin; + HVector3f N = worldPlane.direction; HPoint3f X_in = muon.LineIn().origin; HPoint3f X_out = muon.LineOut().origin; diff --git a/src/HEP/Detectors/DetectorChamber.h b/src/HEP/Detectors/DetectorChamber.h index 248e059..56d71a6 100644 --- a/src/HEP/Detectors/DetectorChamber.h +++ b/src/HEP/Detectors/DetectorChamber.h @@ -45,12 +45,30 @@ class DetectorChamber : public ContainerBox { public: + DetectorChamber() : BaseClass() { + m_ProjectionPlane.origin = HPoint3f(0, 0, 0); + m_ProjectionPlane.direction = HVector3f(0, 0, 1); + } + + DetectorChamber(const Vector3f &size) : BaseClass(size) { + m_ProjectionPlane.origin = HPoint3f(0, 0, 0); + m_ProjectionPlane.direction = HVector3f(0, 0, 1); + } + // set the plane where muons hit is projected - // to be represented with a direction vector + // coordinates are local to the container box void SetProjectionPlane(const HLine3f &normal) { m_ProjectionPlane = normal; } const HLine3f &GetProjectionPlane() const { return m_ProjectionPlane; } + HLine3f GetWorldProjectionPlane() const { + HLine3f worldPlane; + Matrix4f M = this->GetWorldMatrix(); + worldPlane.origin = M * m_ProjectionPlane.origin; + worldPlane.direction = M * m_ProjectionPlane.direction; + return worldPlane; + } + MuonEvent ProjectMuonEvent(const MuonEvent &muon) const; private: diff --git a/src/HEP/Detectors/testing/DetectorChamberTest.cpp b/src/HEP/Detectors/testing/DetectorChamberTest.cpp index d8e6720..c4478bc 100644 --- a/src/HEP/Detectors/testing/DetectorChamberTest.cpp +++ b/src/HEP/Detectors/testing/DetectorChamberTest.cpp @@ -116,5 +116,24 @@ int main() { bool posOk3 = (projected.LineIn().origin - expectedPos).norm() < 1e-5; TEST1(posOk3); + // Test Case 4: Transformed DetectorChamber + DetectorChamber chamber2; + chamber2.SetPosition(Vector3f(0, 0, 100)); // Move chamber to z=100 + // chamber2.GetProjectionPlane has default origin (0,0,0) and direction (0,0,1) + // In world coordinates, this plane is at z = 100 + 0 = 100. + + muon.LineIn().origin = HPoint3f(50, 60, 50); // dist to world plane (z=100) is 50 + muon.LineOut().origin = HPoint3f(50, 60, 200); // dist to world plane (z=100) is 100 + + projected = chamber2.ProjectMuonEvent(muon); + expectedPos = HPoint3f(50, 60, 100); + + std::cout << "\nTest Case 4: Transformed DetectorChamber (active world matrix)" << std::endl; + std::cout << "Projected Position: " << projected.LineIn().origin.transpose() << std::endl; + std::cout << "Expected Position: " << expectedPos.transpose() << std::endl; + + bool posOk4 = (projected.LineIn().origin - expectedPos).norm() < 1e-5; + TEST1(posOk4); + END_TESTING; }