Skip to content

Commit 5b7b44d

Browse files
authored
Fix problem with mirror intersections
1 parent e59c6a8 commit 5b7b44d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

source/framework/tools/src/TRestPhysics.cxx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ TVector3 GetParabolicVectorIntersection(const TVector3& pos, const TVector3& dir
101101
if (a != 0) {
102102
Double_t root1 = (-half_b - TMath::Sqrt(half_b * half_b - a * c)) / a;
103103
Double_t root2 = (-half_b + TMath::Sqrt(half_b * half_b - a * c)) / a;
104-
if (pos.Z() + root1 * dir.Z() < 0) {
104+
Double_t int1 = pos.Z() + root1 * dir.Z();
105+
Double_t int2 = pos.Z() + root2 * dir.Z();
106+
if (int1 < 0 and int2 < 0 and int1 > int2) {
105107
return pos + root1 * dir;
106-
} else if (pos.Z() + root2 * dir.Z() < 0) {
108+
} else if (int1 < 0 and int2 < 0 and int1 < int2) {
107109
return pos + root2 * dir;
108110
}
109111
return pos;
@@ -131,12 +133,13 @@ TVector3 GetHyperbolicVectorIntersection(const TVector3& pos, const TVector3& di
131133
Double_t c = pos.X() * pos.X() + pos.Y() * pos.Y() - R3 * R3 + e * pos.Z() - g * pos.Z() * pos.Z();
132134
Double_t root1 = (-half_b - TMath::Sqrt(half_b * half_b - a * c)) / a;
133135
Double_t root2 = (-half_b + TMath::Sqrt(half_b * half_b - a * c)) / a;
134-
if (pos.Z() + root1 * dir.Z() > 0) {
136+
Double_t int1 = pos.Z() + root1 * dir.Z();
137+
Double_t int2 = pos.Z() + root2 * dir.Z();
138+
if (int1 > 0 and int2 > 0 and int1 < int2) {
135139
return pos + root1 * dir;
136-
} else if (pos.Z() + root2 * dir.Z() > 0) {
140+
} else if (int1 > 0 and int2 > 0 and int1 > int2) {
137141
return pos + root2 * dir;
138142
}
139-
140143
return pos;
141144
}
142145

0 commit comments

Comments
 (0)