Skip to content

Commit

Permalink
Fix problem with mirror intersections
Browse files Browse the repository at this point in the history
  • Loading branch information
jovoy authored Feb 20, 2024
1 parent e59c6a8 commit 5b7b44d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions source/framework/tools/src/TRestPhysics.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ TVector3 GetParabolicVectorIntersection(const TVector3& pos, const TVector3& dir
if (a != 0) {
Double_t root1 = (-half_b - TMath::Sqrt(half_b * half_b - a * c)) / a;
Double_t root2 = (-half_b + TMath::Sqrt(half_b * half_b - a * c)) / a;
if (pos.Z() + root1 * dir.Z() < 0) {
Double_t int1 = pos.Z() + root1 * dir.Z();
Double_t int2 = pos.Z() + root2 * dir.Z();
if (int1 < 0 and int2 < 0 and int1 > int2) {
return pos + root1 * dir;
} else if (pos.Z() + root2 * dir.Z() < 0) {
} else if (int1 < 0 and int2 < 0 and int1 < int2) {
return pos + root2 * dir;
}
return pos;
Expand Down Expand Up @@ -131,12 +133,13 @@ TVector3 GetHyperbolicVectorIntersection(const TVector3& pos, const TVector3& di
Double_t c = pos.X() * pos.X() + pos.Y() * pos.Y() - R3 * R3 + e * pos.Z() - g * pos.Z() * pos.Z();
Double_t root1 = (-half_b - TMath::Sqrt(half_b * half_b - a * c)) / a;
Double_t root2 = (-half_b + TMath::Sqrt(half_b * half_b - a * c)) / a;
if (pos.Z() + root1 * dir.Z() > 0) {
Double_t int1 = pos.Z() + root1 * dir.Z();
Double_t int2 = pos.Z() + root2 * dir.Z();
if (int1 > 0 and int2 > 0 and int1 < int2) {
return pos + root1 * dir;
} else if (pos.Z() + root2 * dir.Z() > 0) {
} else if (int1 > 0 and int2 > 0 and int1 > int2) {
return pos + root2 * dir;
}

return pos;
}

Expand Down

0 comments on commit 5b7b44d

Please sign in to comment.