Skip to content

Commit 222d60d

Browse files
authored
fix: OutOfMemoryError for FTOF and EPICS (#152)
1 parent 4e2784d commit 222d60d

File tree

14 files changed

+148
-325
lines changed

14 files changed

+148
-325
lines changed

bin/environ.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ timeline_groovy_opts=(
4242
-Djava.awt.headless=true
4343
)
4444

45+
# run java with more resources, to mitigate large memory residence for long run periods
46+
timeline_java_opts_highmem=$(echo ${timeline_java_opts[*]} | sed 's;Xmx.*m;Xmx2048m;')
47+
4548
# exports
4649
export CLASSPATH="$(echo "${java_classpath[*]}" | sed 's; ;:;g')${CLASSPATH:+:${CLASSPATH}}"
4750
export JYPATH="$(echo "${groovy_classpath[*]}" | sed 's; ;:;g')${JYPATH:+:${JYPATH}}"
4851
export TIMELINE_JAVA_OPTS="${timeline_java_opts[*]}"
4952
export TIMELINE_GROOVY_OPTS="${timeline_groovy_opts[*]}"
53+
export TIMELINE_JAVA_OPTS_HIGHMEM=$timeline_java_opts_highmem

detectors/src/main/java/org/jlab/clas/timeline/fitter/FTOFFitter.groovy

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,33 @@ class FTOFFitter {
3131
return f1
3232
}
3333

34-
static F1D timefit_p2(H1F h1) {
35-
def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -0.5, 0.5);
36-
double hAmp = h1.getBinContent(h1.getMaximumBin());
37-
double hMean = h1.getAxis().getBinCenter(h1.getMaximumBin());
38-
double hRMS = 0.3;//h1.getRMS(); //ns
39-
double rangeMin = (hMean - 2.5*hRMS);
40-
double rangeMax = (hMean + 2.5*hRMS);
41-
f1.setRange(rangeMin, rangeMax);
42-
f1.setParameter(0, hAmp);
43-
f1.setParameter(1, hMean);
44-
f1.setParameter(2, hRMS);
45-
46-
def makefit = {func->
47-
hMean = func.getParameter(1)
48-
hRMS = func.getParameter(2).abs()
49-
func.setRange(hMean-1.5*hRMS,hMean+1.5*hRMS)
50-
MoreFitter.fit(func,h1,"Q")
51-
return [func.getChiSquare(), (0..<func.getNPars()).collect{func.getParameter(it)}]
52-
}
53-
54-
def fits1 = (0..20).collect{makefit(f1)}
55-
def bestfit = fits1.sort()[0]
56-
f1.setParameters(*bestfit[1])
57-
//makefit(f1)
58-
return f1
59-
}
6034

35+
static F1D timefit_p2(H1F h1) {
36+
def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -0.5, 0.5);
37+
double hAmp = h1.getBinContent(h1.getMaximumBin());
38+
double hMean = h1.getAxis().getBinCenter(h1.getMaximumBin());
39+
double hRMS = 0.3;//h1.getRMS(); //ns
40+
double rangeMin = (hMean - 2.5*hRMS);
41+
double rangeMax = (hMean + 2.5*hRMS);
42+
f1.setRange(rangeMin, rangeMax);
43+
f1.setParameter(0, hAmp);
44+
f1.setParameter(1, hMean);
45+
f1.setParameter(2, hRMS);
46+
47+
def makefit = {func->
48+
hMean = func.getParameter(1)
49+
hRMS = func.getParameter(2).abs()
50+
func.setRange(hMean-1.5*hRMS,hMean+1.5*hRMS)
51+
MoreFitter.fit(func,h1,"Q")
52+
return [func.getChiSquare(), (0..<func.getNPars()).collect{func.getParameter(it)}]
53+
}
54+
55+
def fits1 = (0..20).collect{makefit(f1)}
56+
def bestfit = fits1.sort()[0]
57+
f1.setParameters(*bestfit[1])
58+
//makefit(f1)
59+
return f1
60+
}
6161

6262

6363
static F1D tdcadcdifffit_p1a(H1F h1) {
@@ -72,7 +72,6 @@ class FTOFFitter {
7272
f1.setParameter(1, hMean);
7373
f1.setParameter(2, hRMS);
7474

75-
7675
def makefit = {func->
7776
hMean = func.getParameter(1)
7877
hRMS = func.getParameter(2).abs()
@@ -88,6 +87,7 @@ class FTOFFitter {
8887
return f1
8988
}
9089

90+
9191
static F1D tdcadcdifffit_p1b(H1F h1) {
9292
def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -1.0, 1.0);
9393
double hAmp = h1.getBinContent(h1.getMaximumBin());
@@ -120,27 +120,26 @@ class FTOFFitter {
120120
def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -1.0, 1.0);
121121
double hAmp = h1.getBinContent(h1.getMaximumBin());
122122
double hMean = h1.getAxis().getBinCenter(h1.getMaximumBin());
123-
double hRMS = h1.getRMS(); //ns
124-
double rangeMin = (hMean - 2.5*hRMS);
125-
double rangeMax = (hMean + hRMS);
123+
double hRMS = 1.9//h1.getRMS(); //ns
124+
double rangeMin = (hMean - 1.5*hRMS);
125+
double rangeMax = (hMean + 1.5*hRMS);
126126
f1.setRange(rangeMin, rangeMax);
127127
f1.setParameter(0, hAmp);
128128
f1.setParameter(1, hMean);
129129
f1.setParameter(2, hRMS);
130130

131-
132131
def makefit = {func->
133132
hMean = func.getParameter(1)
134133
hRMS = func.getParameter(2).abs()
135-
func.setRange(hMean - 1.5*hRMS, hMean + 1.5*hRMS)
134+
func.setRange(hMean-1.5*hRMS,hMean+1.5*hRMS)
136135
MoreFitter.fit(func,h1,"Q")
137136
return [func.getChiSquare(), (0..<func.getNPars()).collect{func.getParameter(it)}]
138137
}
139138

140139
def fits1 = (0..20).collect{makefit(f1)}
141140
def bestfit = fits1.sort()[0]
142141
f1.setParameters(*bestfit[1])
143-
f1.setRange(rangeMin, rangeMax)
142+
//makefit(f1)
144143
return f1
145144
}
146145

detectors/src/main/java/org/jlab/clas/timeline/fitter/MoreFitter.groovy

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,6 @@ class MoreFitter {
2121
}
2222
}
2323

24-
static F1D gausFit(H1F h1, String opts) {
25-
def f1 = new F1D('fit:'+h1.getName(), '[amp]*gaus(x,[mean],[sigma])', 0,1)
26-
27-
def scale = Math.max(h1.getBinContent(h1.getMaximumBin())/500, 1)
28-
def data = (1..<h1.getDataSize(0)).collectMany{[h1.getDataX(it)]*(h1.getBinContent(it)/scale as int)}
29-
int nlen = data.size()
30-
if(nlen==0) {
31-
f1.setParameters(0,h1.getDataX(0),0)
32-
return f1
33-
}
34-
35-
def (q1,q2,q3) = [data[nlen/4 as int], data[nlen/2 as int], data[nlen*3/4 as int]]
36-
def (x1,x2) = [1, h1.getDataSize(0)-1].collect{h1.getDataX(it)}
37-
def norms = [h1.getBinContent(h1.getMaximumBin())]
38-
def mus = [h1.getAxis().getBinCenter(h1.getMaximumBin()), h1.getMean(), q2, h1.getDataX(h1.getDataSize(0)/2 as int)]
39-
def sigs = [h1.getRMS()/2, (q3-q1)/1.35]
40-
41-
def makefit = {amp,mu,sig->
42-
f1.setParameters(amp,mu,sig)
43-
def rng = [mu-2.5*sig, mu+2.5*sig]
44-
f1.setRange(*rng)
45-
DataFitter.fit(f1,h1,"Q")
46-
(amp,mu,sig) = (0..<f1.getNPars()).collect{f1.getParameter(it)}
47-
if(mu<x1 || mu>x2 || sig>(x2-x1)) return null
48-
return [f1.getChiSquare(), [amp,mu,sig], rng]
49-
}
50-
51-
def fits = [norms,mus,sigs].combinations().findResults{makefit(it)}
52-
fits += fits.findResults{makefit(it[1])}
53-
54-
def best = fits.min{it[0]} ?: [0, [0,x1,x2-x1], [x1,x2]]
55-
f1.setParameters(*best[1])
56-
f1.setRange(*best[2])
57-
return f1
58-
}
59-
6024
static F1D fitgaus(H1F h1) {
6125
def f1 = new F1D('fit:'+h1.getName(), '[amp]*gaus(x,[mean],[sigma])', 0,1)
6226
f1.setRange(h1.getDataX(0), h1.getDataX(h1.getDataSize(0)-1))

detectors/src/main/java/org/jlab/clas/timeline/run.groovy

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ def engines = [
100100
new ftof.ftof_tdcadc_p1a(),
101101
new ftof.ftof_tdcadc_p1b(),
102102
new ftof.ftof_tdcadc_p2(),
103-
// new ftof.ftof_tdcadc_p1a_zoomed(),
104-
// new ftof.ftof_tdcadc_p1b_zoomed(),
105-
// new ftof.ftof_tdcadc_p2_zoomed(),
106103
new ftof.ftof_ctof_vtdiff(),
107104
new dc.dc_residuals_sec(),
108105
new dc.dc_residuals_sec_sl(),

detectors/src/main/java/org/jlab/clas/timeline/run_rgb.groovy

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ def engines = [
103103
new ftof.ftof_tdcadc_p1a(),
104104
new ftof.ftof_tdcadc_p1b(),
105105
new ftof.ftof_tdcadc_p2(),
106-
// new ftof.ftof_tdcadc_p1a_zoomed(),
107-
// new ftof.ftof_tdcadc_p1b_zoomed(),
108-
// new ftof.ftof_tdcadc_p2_zoomed(),
109106
new ftof.ftof_ctof_vtdiff(),
110107
new dc.dc_residuals_sec(),
111108
new dc.dc_residuals_sec_sl(),

detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/MYQuery.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class MYQuery {
1414
'd': 'on', // data update events only
1515
'p': 'on', // include prior point
1616
'm': 'history', // MYA deployment
17+
'l': '', // limit by binning (downsample)
1718
]
1819

1920
// timestamps

detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/epics_xy.groovy

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.jlab.clas.timeline.timeline.epics
33
import java.text.SimpleDateFormat
44
import org.jlab.groot.data.TDirectory
55
import org.jlab.groot.data.H1F
6+
import org.jlab.groot.math.F1D
67
import org.jlab.groot.data.GraphErrors
78
import org.jlab.clas.timeline.fitter.MoreFitter
89

@@ -14,9 +15,49 @@ class epics_xy {
1415
runlist.push(run)
1516
}
1617

18+
static F1D gausFit(H1F h1) { // FIXME: not stable...
19+
20+
def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -10, 10);
21+
double hAmp = h1.getBinContent(h1.getMaximumBin());
22+
double hMean = h1.getAxis().getBinCenter(h1.getMaximumBin());
23+
double hRMS = Math.min(h1.getRMS(),1.0);
24+
f1.setRange(hMean-2.0*hRMS, hMean+2.0*hRMS);
25+
f1.setParameter(0, hAmp);
26+
f1.setParameter(1, hMean);
27+
f1.setParameter(2, hRMS);
28+
29+
def makefit = {func->
30+
hMean = func.getParameter(1)
31+
hRMS = func.getParameter(2).abs()
32+
func.setRange(hMean-2.0*hRMS,hMean+2.0*hRMS)
33+
MoreFitter.fit(func,h1,"Q")
34+
return [func.getChiSquare(), (0..<func.getNPars()).collect{func.getParameter(it)}]
35+
}
36+
37+
def fits1 = (0..20).collect{makefit(f1)}
38+
def bestfit = fits1.sort()[0]
39+
f1.setParameters(*bestfit[1])
40+
return f1
41+
42+
}
43+
44+
static F1D justUseStats(H1F h1) { // no fit, just use mean and RMS from the histogram
45+
def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -10, 10);
46+
double hAmp = h1.getBinContent(h1.getMaximumBin());
47+
double hMean = h1.getMean()
48+
double hRMS = h1.getRMS()
49+
f1.setRange(hMean-2.0*hRMS, hMean+2.0*hRMS);
50+
f1.setParameter(0, hAmp);
51+
f1.setParameter(1, hMean);
52+
f1.setParameter(2, hRMS);
53+
return f1
54+
}
55+
56+
1757
def close() {
1858

1959
def MYQ = new MYQuery()
60+
MYQ.querySettings['l'] = "${1000*runlist.size()}" // downsample the payload, since it's too big for a full run period
2061
def ts = MYQ.getRunTimeStamps(runlist)
2162

2263
def epics = [:].withDefault{[:]}
@@ -69,12 +110,13 @@ class epics_xy {
69110
hy.fill(it[2], it[0]*it[3]/1000)
70111
}
71112

72-
def fx = MoreFitter.gausFit(hx, "Q")
73-
def fy = MoreFitter.gausFit(hy, "Q")
113+
def fx = justUseStats(hx)
114+
def fy = justUseStats(hy)
74115
grx.addPoint(run, fx.getParameter(1), 0,0)
75116
gry.addPoint(run, fy.getParameter(1), 0,0)
76117

77-
[hx,hy,fx,fy].each{out.addDataSet(it)}
118+
[hx,hy].each{out.addDataSet(it)}
119+
// [fx,fy].each{out.addDataSet(it)}
78120
println("$run done")
79121
}
80122

detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1a.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import java.util.concurrent.ConcurrentHashMap
33
import org.jlab.groot.data.TDirectory
44
import org.jlab.groot.data.GraphErrors
55
import org.jlab.clas.timeline.fitter.FTOFFitter
6+
import org.jlab.clas.timeline.util.HistoUtil
67

78
class ftof_tdcadc_p1a {
89

@@ -14,7 +15,7 @@ def processDirectory(dir, run) {
1415
def sigmalist = []
1516
def chi2list = []
1617
def histlist = (0..<6).collect{
17-
def h1 = dir.getObject('/tof/p1a_tdcadc_dt_S'+(it+1))
18+
def h1 = HistoUtil.zoomHisto(dir.getObject('/tof/p1a_tdcadc_dt_S'+(it+1)))
1819
def f1 = FTOFFitter.tdcadcdifffit_p1a(h1)
1920

2021
funclist.add(f1)

detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1a_zoomed.groovy

Lines changed: 0 additions & 80 deletions
This file was deleted.

detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1b.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import java.util.concurrent.ConcurrentHashMap
33
import org.jlab.groot.data.TDirectory
44
import org.jlab.groot.data.GraphErrors
55
import org.jlab.clas.timeline.fitter.FTOFFitter
6+
import org.jlab.clas.timeline.util.HistoUtil
67

78
class ftof_tdcadc_p1b {
89

@@ -14,7 +15,7 @@ def processDirectory(dir, run) {
1415
def sigmalist = []
1516
def chi2list = []
1617
def histlist = (0..<6).collect{
17-
def h1 = dir.getObject('/tof/p1b_tdcadc_dt_S'+(it+1))
18+
def h1 = HistoUtil.zoomHisto(dir.getObject('/tof/p1b_tdcadc_dt_S'+(it+1)))
1819
def f1 = FTOFFitter.tdcadcdifffit_p1b(h1)
1920

2021
funclist.add(f1)

0 commit comments

Comments
 (0)