Vindaar / TimepixAnalysis

Contains code related to calibration and analysis of Timepix based detector + CAST related code
MIT License
19 stars 6 forks source link

Dynamically determine lower fit bound for Polya fit + highlight in plot #47

Closed Vindaar closed 3 years ago

Vindaar commented 3 years ago

We use a hardcoded lower bound for the polya fit, which by default is at 1200 e⁻:

https://github.com/Vindaar/TimepixAnalysis/blob/master/Analysis/ingrid/calibration/calib_fitting.nim#L605

The reason for a lower bound in the first place are threshold effects showing up in the data, which make the polya not fit very well. This leads to a bad prediction of the gas gain (NOTE: does not directly matter for the following analysis, since we use the mean of the data anyway), which slows down the fitting significantly. Each fit can take up to 1 s instead of ~(20 ms).

An example for a normal polya: gas_gain_run_84_chip_3_current_cut_acceptable

An example for a bad fit due to a too low cut value: gas_gain_run_84_chip_2_current_cut_too_low

And an example that shows data that cuts of very early where we really do not want to try to fit the left edge: gas_gain_run_303_chip_5_cut_off_sharply

Example 2 and 3 here are cases where the left edge would significantly cause a bad fit, due to a sharper than real drop off, because the pixel threshold of the is visible.

We need to dynamically determine the lower bound. Essentially find the maximum of the data and then walk to the left up to maybe once more than 1 consecutive bin (to avoid stat fluctuations mess things up) to be lower than maybe 60% of the max or so.

Finally, also show the actual range of the fit and the extended range that is plotted for the fit line here in the plots. Just draw two geom_line or add a new column before plotting with a label "fit / extended" or something like this.

Vindaar commented 3 years ago

This has been implemented in https://github.com/Vindaar/TimepixAnalysis/commit/7cec6d02e9ba173c126746a464200c8a9f44575d.

The new plots look like this now:

gas_gain_run_164_chip_3_84_30_min_1520353335_good_fit