Skip to content

Commit d24a586

Browse files
committed
Test CI; Does this fail too??
1 parent 23c411f commit d24a586

1 file changed

Lines changed: 22 additions & 159 deletions

File tree

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

Lines changed: 22 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -40,168 +40,31 @@ class ALERTFitter{
4040
return f1
4141
}
4242

43-
static F1D tdc_minus_start_time_fitter(H1F h1, int component){
44-
if(component>9){//bars
45-
def f1 =new F1D("fit:"+h1.getName(),"[amp]*gaus(x,[mean],[sigma])+[cst]", -5.0, 5.0);
46-
f1.setLineColor(33);
47-
f1.setLineWidth(10);
48-
f1.setOptStat("1111");
49-
double maxz = h1.getBinContent(h1.getMaximumBin());
50-
double peak_location = h1.getAxis().getBinCenter(h1.getMaximumBin());
51-
f1.setRange(peak_location - 5, peak_location + 5);
52-
f1.setParameter(0,maxz-h1.getBinContent(0));
53-
f1.setParameter(1, peak_location);
54-
f1.setParameter(2, 1.0);
55-
f1.setParameter(3, h1.getBinContent(0));
56-
if (maxz>0) f1.setParLimits(0, maxz*0.9,maxz*1.1);
57-
f1.setParLimits(3, 0.0, 0.1*maxz);
58-
59-
double hMean, hRMS
60-
def originalOut = System.out
61-
System.setOut(new PrintStream(OutputStream.nullOutputStream())) // Java 11+
62-
63-
// Code that prints to System.out
64-
DataFitter.fit(f1, h1, "");
65-
66-
System.setOut(originalOut) // Restore the original output
67-
68-
return f1
69-
}
70-
else {
71-
double height_fit_set = 0
72-
double mean_fit_set = 0
73-
double sigma_fit_set = 0
74-
double step = 2
75-
76-
if (h1.getEntries() < 10) return null
77-
78-
// ----- Clone & analyze primary peak -----
79-
H1F hpy = h1.histClone("hpy_zoom")
80-
int maxBin = hpy.getMaximumBin()
81-
double maxY = hpy.getBinContent(maxBin)
82-
double peak = hpy.getXaxis().getBinCenter(maxBin)
83-
double sigma0 = Math.min(step, getRestrictedRMS(hpy, peak - step, peak + step))
84-
85-
// ----- Primary Gaussian Fit -----
86-
F1D fgaus = new F1D("fgaus", "[amp]*gaus(x,[mean],[sigma])",
87-
peak - step, peak + step)
88-
89-
fgaus.setParameter(0, maxY)
90-
fgaus.setParameter(1, peak)
91-
fgaus.setParameter(2, sigma0 > 0 ? sigma0 : 0.8)
92-
fgaus.setParLimits(0, 0, 1.2 * maxY)
93-
fgaus.setParLimits(1, peak - step, peak + step)
94-
fgaus.setParLimits(2, 0, step)
95-
96-
PrintStream original = System.out
97-
System.setOut(new PrintStream(OutputStream.nullOutputStream()))
98-
DataFitter.fit(fgaus, hpy, "RQ")
99-
System.setOut(original)
100-
101-
double height = fgaus.getParameter(0)
102-
double mean = fgaus.getParameter(1)
103-
double sigma = fgaus.getParameter(2)
104-
double entriesTotal = hpy.integral()
105-
106-
// -------------------------------------------------------------------------
107-
// Utility closure to fit a left-side peak after cutting the histogram
108-
// -------------------------------------------------------------------------
109-
def fitLeftPeak = { H1F h, double prevMean, double prevSigma ->
110-
// Cut histogram to the left of the previous peak
111-
H1F hcut = h.histClone("hcut")
112-
int cutBin = hcut.getXaxis().getBin(prevMean - prevSigma * 2)
113-
for (int b = cutBin; b <= hcut.getXaxis().getNBins(); b++) {
114-
hcut.setBinContent(b, 0)
115-
hcut.setBinError(b, 0)
116-
}
117-
118-
if (hcut.integral() < 3) return null
119-
120-
int mb = hcut.getMaximumBin()
121-
if (mb >= cutBin - 2) return null // ensure left-side peak
122-
123-
double pk = hcut.getXaxis().getBinCenter(mb)
124-
double amp0 = hcut.getBinContent(mb)
125-
126-
F1D ftmp = new F1D("fgaus_left",
127-
"[amp]*gaus(x,[mean],[sigma])",
128-
pk - step, pk + step)
129-
130-
ftmp.setParameter(0, amp0)
131-
ftmp.setParameter(1, pk)
132-
ftmp.setParameter(2, 0.8)
133-
134-
ftmp.setParLimits(0, 0, 1.2 * amp0)
135-
ftmp.setParLimits(1, pk - step, pk + step)
136-
ftmp.setParLimits(2, 0, step)
137-
138-
System.setOut(new PrintStream(OutputStream.nullOutputStream()))
139-
DataFitter.fit(ftmp, hcut, "RQ")
140-
System.setOut(original)
141-
142-
double A = ftmp.getParameter(0)
143-
double M = ftmp.getParameter(1)
144-
double S = ftmp.getParameter(2)
145-
146-
// validation conditions
147-
if (A > maxY * 0.3 &&
148-
S < step && S > 0.1 &&
149-
M < prevMean - prevSigma &&
150-
hcut.integral() > 0.05 * entriesTotal)
151-
{
152-
return [A, M, S]
153-
}
154-
return null
155-
}
156-
157-
// -------------------------------------------------------------------------
158-
// Peak 1 (primary) already known: height, mean, sigma
159-
// Try Peak 2 (first left peak)
160-
// -------------------------------------------------------------------------
161-
def p2 = fitLeftPeak(hpy, mean, sigma)
162-
163-
// If Peak 2 exists, try Peak 3 (second left peak)
164-
def p3 = p2 ? fitLeftPeak(hpy, p2[1], p2[2]) : null
165-
166-
// If Peak 3 exists, try Peak 4 (third left peak)
167-
def p4 = p3 ? fitLeftPeak(hpy, p3[1], p3[2]) : null
168-
169-
// -------------------------------------------------------------------------
170-
// Choose deepest detected peak on the left: p4 > p3 > p2 > primary
171-
// -------------------------------------------------------------------------
172-
if (p4) {
173-
height_fit_set = p4[0]
174-
mean_fit_set = p4[1]
175-
sigma_fit_set = p4[2]
176-
} else if (p3) {
177-
height_fit_set = p3[0]
178-
mean_fit_set = p3[1]
179-
sigma_fit_set = p3[2]
180-
} else if (p2) {
181-
height_fit_set = p2[0]
182-
mean_fit_set = p2[1]
183-
sigma_fit_set = p2[2]
184-
} else {
185-
height_fit_set = height
186-
mean_fit_set = mean
187-
sigma_fit_set = sigma
188-
}
189-
190-
// Return final selected Gaussian
191-
F1D fout = new F1D("fit:" + h1.getName(),
192-
"[amp]*gaus(x,[mean],[sigma])",
193-
mean_fit_set - step * 2, mean_fit_set + step * 2)
194-
195-
fout.setParameter(0, height_fit_set)
196-
fout.setParameter(1, mean_fit_set)
197-
fout.setParameter(2, sigma_fit_set)
43+
static F1D tdc_minus_start_time_fitter(H1F h1){
44+
def f1 =new F1D("fit:"+h1.getName(),"[amp]*gaus(x,[mean],[sigma])+[cst]", -5.0, 5.0);
45+
f1.setLineColor(33);
46+
f1.setLineWidth(10);
47+
f1.setOptStat("1111");
48+
double maxz = h1.getBinContent(h1.getMaximumBin());
49+
double peak_location = h1.getAxis().getBinCenter(h1.getMaximumBin());
50+
f1.setRange(peak_location - 5, peak_location + 5);
51+
f1.setParameter(0,maxz-h1.getBinContent(0));
52+
f1.setParameter(1, peak_location);
53+
f1.setParameter(2, 1.0);
54+
f1.setParameter(3, h1.getBinContent(0));
55+
if (maxz>0) f1.setParLimits(0, maxz*0.9,maxz*1.1);
56+
f1.setParLimits(3, 0.0, 0.1*maxz);
19857

199-
fout.setLineColor(33)
200-
fout.setLineWidth(10)
58+
double hMean, hRMS
59+
def originalOut = System.out
60+
System.setOut(new PrintStream(OutputStream.nullOutputStream())) // Java 11+
61+
62+
// Code that prints to System.out
63+
DataFitter.fit(f1, h1, "");
20164

202-
return fout
203-
}
65+
System.setOut(originalOut) // Restore the original output
20466

67+
return f1
20568
}
20669

20770

0 commit comments

Comments
 (0)