Use average BaseLine and BaseLineSigma and small changes in peak pos #143
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We had an issue when detecting peaks in TPC signals. The algorithm identifies as peak a bin which is bigger than its neighbours (it can be smaller or equal than 3 to take into account flat peaks). Then the peaks position and amplitude are found by gauss fitting around this bin. Problems can arise when there is a tendency in the signal, if it is a small bump in a decreasing region, when fitting the results will be bad:
Fig 1: A peak was identified in the bin 291. When fitting in this range the peak position is very wrong.
This is corrected by avoiding the gaussFit and using a TripleMaxAverage method. The peak´s amplitude is simply the average of its amplitude and the one of its neighbours.
As for the peak position, the peak´s bin is not simply the peak as we don´t want too close peaks. To avoid those close peaks a peak is not considered if it is within a distance of another one, but again, if let´s say 3 consecutive bins fulfill the peak criteria (in a flat region) only the first one will be considered as peak, introducing a bias to more left peaks.
This is solved by choosing as the actual peak position the bin with the highest amplitude from the peak bin (biased) to the next "distance" bins (lets say 10). The maximum bin in this 10 bins interval is the new peak´s position (and the amplitudes mentioned before are calculated from this bin):
Fig 2: Imporvement in the peak´s positions and amplitudes.
Finally. Sometimes very small peaks are considered. This is because the peak thershold was calculated from the signal´s baseline, but sometimes small baselines can accept peaks with very low amplitudes. This is averaged by using the BaseLine and BaseLineSigma of all the signals and a threshold of "BaseLineMean + BaseLineSigmaMean * 10" is harcoded.
MAYBE THIS 10 SHOULD BE AN INPUT BUT SEEMS TO BE A VERY REASONABLE VALUE.