Skip to content

Commit 218bd10

Browse files
committed
update the peak looking up
1 parent 56e81e1 commit 218bd10

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/main/java/org/jlab/clas/timeline/fitter/ForwardFitter.groovy

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,15 @@ class ForwardFitter{
5555
static F1D fitRGL(H1F h1, double fit_left, double fit_right) {
5656
def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", fit_left, fit_right);
5757

58-
// zoom in to [fit_left, fit_right] to find local max, avoiding the other peak
59-
int nBins = h1.getAxis().getNBins()
60-
h1.getAxis().setRangeUser(fit_left, fit_right)
61-
double hAmp = h1.getBinContent(h1.getMaximumBin())
62-
double hMean = h1.getAxis().getBinCenter(h1.getMaximumBin())
63-
h1.getAxis().setRange(0, nBins + 1) // restore full range
58+
// find local max within [fit_left, fit_right] only, avoiding the other peak
59+
int binLeft = Math.max(0, h1.getAxis().getBin(fit_left))
60+
int binRight = Math.min(h1.getAxis().getNBins() - 1, h1.getAxis().getBin(fit_right))
61+
int maxBin = binLeft
62+
for (int i = binLeft + 1; i <= binRight; i++) {
63+
if (h1.getBinContent(i) > h1.getBinContent(maxBin)) maxBin = i
64+
}
65+
double hAmp = h1.getBinContent(maxBin)
66+
double hMean = h1.getAxis().getBinCenter(maxBin)
6467

6568
f1.setRange(hMean - 2.0, hMean + 2.0);
6669
f1.setParameter(0, hAmp);

0 commit comments

Comments
 (0)