XENONnT / straxen

Streaming analysis for XENON
BSD 3-Clause "New" or "Revised" License
19 stars 33 forks source link

Return the edge closer to the target in `_numeric_derivative` #1355

Closed dachengx closed 3 months ago

dachengx commented 3 months ago

Before you submit this PR: make sure to put all operations-related information in a wiki-note, a PR should be about code and is publicly accessible

What does the code in this PR do / what does it improve?

Try to fix https://github.com/XENONnT/straxen/issues/1354

The change is minor so I will not update the version of plugins.

Can you briefly describe how it works?

Like the MWE in https://github.com/XENONnT/straxen/issues/1354 listed, when

aftobs, aft, s1tot = 1.0, 0.18243408203125003, 2.0

The j_min and j_max are too close (j_min is 0, and j_max is 2.8076670357142592e-05) and the difference between their corresponding y0 and y1 is smaller than err=1e-7. Then before this PR, this line https://github.com/XENONnT/straxen/blob/92bcf54cc236d3de1c86544fa0fd720cb8daf088/straxen/plugins/events/event_pattern_fit.py#L572 will directly return j_max. But in principle, it should return the x which will give the y closer to the target. And in the MWE of https://github.com/XENONnT/straxen/issues/1354, it should return j_min.

Can you give a minimal working example (or illustrate with a figure)?

image The vertical lines are j_min and j_max which are very close.

Please include the following if applicable:

Notes on testing

All italic comments can be removed from this template.

coveralls commented 3 months ago

Coverage Status

coverage: 91.37% (+0.02%) from 91.347% when pulling cf741001205023d9811007e20a4148c24605bf59 on fix_numeric_derivative into 915183eaf3432f8e133f214061e66cadef383f60 on master.