Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix trapezoid accelerated inside check #2696

Conversation

andiwand
Copy link
Contributor

@andiwand andiwand commented Nov 18, 2023

This bug flagged some points to be inside while they are not. I fixed this by checking against two rectangles instead of just one which is too big.

discovered in #2694

@andiwand andiwand added this to the next milestone Nov 18, 2023
@github-actions github-actions bot added the Component - Core Affects the Core module label Nov 18, 2023
Copy link

codecov bot commented Nov 18, 2023

Codecov Report

Attention: 12 lines in your changes are missing coverage. Please review.

Comparison is base (fd1e0b4) 49.63% compared to head (a6e2432) 49.64%.
Report is 2 commits behind head on main.

Files Patch % Lines
...e/include/Acts/TrackFitting/BetheHeitlerApprox.hpp 57.14% 4 Missing and 2 partials ⚠️
Core/include/Acts/TrackFitting/detail/GsfActor.hpp 16.66% 2 Missing and 3 partials ⚠️
...re/include/Acts/TrackFitting/GaussianSumFitter.hpp 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2696      +/-   ##
==========================================
+ Coverage   49.63%   49.64%   +0.01%     
==========================================
  Files         474      474              
  Lines       26941    26951      +10     
  Branches    12415    12416       +1     
==========================================
+ Hits        13372    13381       +9     
- Misses       4746     4747       +1     
  Partials     8823     8823              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@paulgessinger paulgessinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This surprises me. The way I read the new code it seems to me like it's the same shape but with extra redundant checks. Can you draw a sketch of which points it was previously missing?

Core/src/Surfaces/TrapezoidBounds.cpp Show resolved Hide resolved
Core/src/Surfaces/TrapezoidBounds.cpp Outdated Show resolved Hide resolved
@paulgessinger
Copy link
Member

paulgessinger commented Nov 18, 2023

trap_abs
trap_tol

Here are some MC tests from the current main bounds implementation for a trap like this:

Acts::TrapezoidBounds bounds{halfXnegY: 20, halfXposY: 30, halfY: 20};

This looks correct to me? Am I missing something?

@andiwand
Copy link
Contributor Author

@paulgessinger this test https://github.com/acts-project/acts/blob/main/Tests/UnitTests/Core/Surfaces/TrapezoidBoundsTests.cpp#L203 failed after I changed the RNG in #2694

The reason is that we previously extended the inner rectangle in X and Y direction using tolerance without special treatment of the corners. Not sure what we expect at the corners but the behavior is different in the polygon check and in the quick bounds check

looking at your MC generated image the problem are the corners where we either just inflate the trapezoid or like in your picture we have rectangles overshooting the inflated trapezoid

@paulgessinger
Copy link
Member

paulgessinger commented Nov 18, 2023

Hm, I think that's what we want. By convention, the tolerances are aligned with the local axes not with the slanted edge of the trap.

I need to double check how the polygon code uses the tolerances.

@andiwand
Copy link
Contributor Author

the polygon code will make the trapezoid bigger in x and y so there are no additional edges which seems "more correct" to me

@paulgessinger
Copy link
Member

paulgessinger commented Nov 18, 2023

@andiwand Hm I see. I think the polygon code calculates the minimum distance first and then determines if they're inside tolerance in x and y.

Ultimately it's a choice. I think the current behavior is least surprising given "dumb" tolerances but that's just me.

Btw, with this PR included, the covered shape by the trap with tolerances seems to be exactly unchanged compared to before:

trap_fix1

If this is correct, maybe the unit test failure is because of a floating point edge case and not because of a geometric difference?

@andiwand
Copy link
Contributor Author

hmm I see. now I am confused. I don't think the numbers where small enough for a FP issue but let me check again

this is the error I see in #2694 (reverted the fix there)

/home/andreas/cern/source/acts/acts/git2/Tests/UnitTests/Core/Surfaces/TrapezoidBoundsTests.cpp(204): error: in "Surfaces/TrapezoidInsideCheck/_3459": check bc.isInside({x, y}, vertices) == trapezoidBoundsObject.inside({x, y}, bc) has failed [false != true]
Failure occurred in a following context:
    x = -1.2921219286961447; y = -2.2747078076516623; index = 864; tol = 0.29999999999999999; 

*** 1 failure is detected in the test module "ActsUnitTestTrapezoidBounds"

@paulgessinger
Copy link
Member

paulgessinger commented Nov 18, 2023

@andiwand Hm, the way the test is written (full polygon vs trap inside method) I think your diagnosis should be correct, in that it's the ears of the trap that are just different in the two. 😵‍💫
Especially since the changes in this PR seem to have fixed the unit test failure.

@andiwand
Copy link
Contributor Author

andiwand commented Nov 18, 2023

running on higher stats shows that this happens very rarely and only in one of the corners. happened 52 / 1000000 failures.txt

my code is basically delegating the corners to the polygon code this is why the edge case disappears. maybe there is a problem in the polygon code after all?

@paulgessinger
Copy link
Member

If it's only in one of the corners maybe it's just < vs <= or something like that?

@andiwand
Copy link
Contributor Author

it seems to be a rare numerical problem with the polygon method. I moved not the seed in #2694 so it does not fail

not sure if it is worth trying to make the polygon method more numerical stable

closing for now

@andiwand andiwand closed this Nov 19, 2023
@paulgessinger paulgessinger modified the milestones: next, v31.2.0 Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - Core Affects the Core module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants