From 741a7e434b85c22fced53b6a773cb31646b5c949 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Tue, 28 Nov 2023 19:21:50 -0500 Subject: [PATCH 01/14] test: `close()` leaks --- detectors/src/main/java/org/jlab/clas/timeline/run.groovy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/detectors/src/main/java/org/jlab/clas/timeline/run.groovy b/detectors/src/main/java/org/jlab/clas/timeline/run.groovy index 12daeb91..0e621b8e 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/run.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/run.groovy @@ -170,7 +170,8 @@ if(eng) { System.exit(100) } } - engine.close() + println("debug: trying to call close()") + engine.close() // leak happens here! println("debug: "+engine.getClass().getSimpleName()+" ended") } else { System.err.println("error: "+args[0]+" not found") From 7a2499325e6d4fb92d1c566fd782ce1d5f159935 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Wed, 29 Nov 2023 21:43:49 -0500 Subject: [PATCH 02/14] fix: limit `epics_xy` MYA payload and stabilize the fits --- .../clas/timeline/fitter/MoreFitter.groovy | 2 +- .../timeline/timeline/epics/MYQuery.groovy | 1 + .../timeline/timeline/epics/epics_xy.groovy | 33 +++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/detectors/src/main/java/org/jlab/clas/timeline/fitter/MoreFitter.groovy b/detectors/src/main/java/org/jlab/clas/timeline/fitter/MoreFitter.groovy index ef896f96..3c0af4cc 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/fitter/MoreFitter.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/fitter/MoreFitter.groovy @@ -42,7 +42,7 @@ class MoreFitter { f1.setParameters(amp,mu,sig) def rng = [mu-2.5*sig, mu+2.5*sig] f1.setRange(*rng) - DataFitter.fit(f1,h1,"Q") + DataFitter.fit(f1,h1,opts) (amp,mu,sig) = (0..x2 || sig>(x2-x1)) return null return [f1.getChiSquare(), [amp,mu,sig], rng] diff --git a/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/MYQuery.groovy b/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/MYQuery.groovy index 8fdae044..67a407b9 100755 --- a/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/MYQuery.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/MYQuery.groovy @@ -14,6 +14,7 @@ class MYQuery { 'd': 'on', // data update events only 'p': 'on', // include prior point 'm': 'history', // MYA deployment + 'l': '', // limit by binning ] // timestamps diff --git a/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/epics_xy.groovy b/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/epics_xy.groovy index b65bacf7..d86cae08 100755 --- a/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/epics_xy.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/epics_xy.groovy @@ -3,6 +3,7 @@ package org.jlab.clas.timeline.timeline.epics import java.text.SimpleDateFormat import org.jlab.groot.data.TDirectory import org.jlab.groot.data.H1F +import org.jlab.groot.math.F1D import org.jlab.groot.data.GraphErrors import org.jlab.clas.timeline.fitter.MoreFitter @@ -14,9 +15,37 @@ class epics_xy { runlist.push(run) } + static F1D gausFit(H1F h1) { + + def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -10, 10); + double hAmp = h1.getBinContent(h1.getMaximumBin()); + double hMean = h1.getAxis().getBinCenter(h1.getMaximumBin()); + double hRMS = Math.min(h1.getRMS(),1.0); + f1.setRange(hMean-2.0*hRMS, hMean+2.0*hRMS); + f1.setParameter(0, hAmp); + f1.setParameter(1, hMean); + f1.setParameter(2, hRMS); + + def makefit = {func-> + hMean = func.getParameter(1) + hRMS = func.getParameter(2).abs() + func.setRange(hMean-2.0*hRMS,hMean+2.0*hRMS) + MoreFitter.fit(func,h1,"Q") + return [func.getChiSquare(), (0.. Date: Wed, 29 Nov 2023 21:44:49 -0500 Subject: [PATCH 03/14] refactor!: remove unused `MoreFitter.gausFit` --- .../clas/timeline/fitter/MoreFitter.groovy | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/detectors/src/main/java/org/jlab/clas/timeline/fitter/MoreFitter.groovy b/detectors/src/main/java/org/jlab/clas/timeline/fitter/MoreFitter.groovy index 3c0af4cc..fdbd2e06 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/fitter/MoreFitter.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/fitter/MoreFitter.groovy @@ -21,42 +21,6 @@ class MoreFitter { } } - static F1D gausFit(H1F h1, String opts) { - def f1 = new F1D('fit:'+h1.getName(), '[amp]*gaus(x,[mean],[sigma])', 0,1) - - def scale = Math.max(h1.getBinContent(h1.getMaximumBin())/500, 1) - def data = (1.. - f1.setParameters(amp,mu,sig) - def rng = [mu-2.5*sig, mu+2.5*sig] - f1.setRange(*rng) - DataFitter.fit(f1,h1,opts) - (amp,mu,sig) = (0..x2 || sig>(x2-x1)) return null - return [f1.getChiSquare(), [amp,mu,sig], rng] - } - - def fits = [norms,mus,sigs].combinations().findResults{makefit(it)} - fits += fits.findResults{makefit(it[1])} - - def best = fits.min{it[0]} ?: [0, [0,x1,x2-x1], [x1,x2]] - f1.setParameters(*best[1]) - f1.setRange(*best[2]) - return f1 - } - static F1D fitgaus(H1F h1) { def f1 = new F1D('fit:'+h1.getName(), '[amp]*gaus(x,[mean],[sigma])', 0,1) f1.setRange(h1.getDataX(0), h1.getDataX(h1.getDataSize(0)-1)) From 0d3efc70853189f951d76077a93a19172104a48e Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Fri, 1 Dec 2023 18:11:50 -0500 Subject: [PATCH 04/14] fix: just use histogram stats rather than attempting a fit --- .../timeline/timeline/epics/epics_xy.groovy | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/epics_xy.groovy b/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/epics_xy.groovy index d86cae08..875c6d16 100755 --- a/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/epics_xy.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/epics_xy.groovy @@ -15,7 +15,7 @@ class epics_xy { runlist.push(run) } - static F1D gausFit(H1F h1) { + static F1D gausFit(H1F h1) { // FIXME: not stable... def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -10, 10); double hAmp = h1.getBinContent(h1.getMaximumBin()); @@ -41,11 +41,23 @@ class epics_xy { } + static F1D justUseStats(H1F h1) { // no fit, just use mean and RMS from the histogram + def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -10, 10); + double hAmp = h1.getBinContent(h1.getMaximumBin()); + double hMean = h1.getMean() + double hRMS = h1.getRMS() + f1.setRange(hMean-2.0*hRMS, hMean+2.0*hRMS); + f1.setParameter(0, hAmp); + f1.setParameter(1, hMean); + f1.setParameter(2, hRMS); + return f1 + } + def close() { def MYQ = new MYQuery() - MYQ.querySettings['l'] = "${100*runlist.size()}" // limit the payload size with less bins than default + MYQ.querySettings['l'] = "${1000*runlist.size()}" // downsample the payload, since it's too big for a full run period def ts = MYQ.getRunTimeStamps(runlist) def epics = [:].withDefault{[:]} @@ -98,12 +110,13 @@ class epics_xy { hy.fill(it[2], it[0]*it[3]/1000) } - def fx = gausFit(hx) - def fy = gausFit(hy) + def fx = justUseStats(hx) + def fy = justUseStats(hy) grx.addPoint(run, fx.getParameter(1), 0,0) gry.addPoint(run, fy.getParameter(1), 0,0) - [hx,hy,fx,fy].each{out.addDataSet(it)} + [hx,hy].each{out.addDataSet(it)} + // [fx,fy].each{out.addDataSet(it)} println("$run done") } From bd7c1126ce77715d9dd71736b4338c145fe234fc Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Fri, 1 Dec 2023 21:09:41 -0500 Subject: [PATCH 05/14] fix: run `run-detectors-timelines.sh` with larger memory allocation pool --- bin/environ.sh | 4 ++++ bin/run-detectors-timelines.sh | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/environ.sh b/bin/environ.sh index 2c72d98f..0ad4b06b 100644 --- a/bin/environ.sh +++ b/bin/environ.sh @@ -42,8 +42,12 @@ timeline_groovy_opts=( -Djava.awt.headless=true ) +# run java with more resources, to mitigate large memory residence for long run periods +timeline_java_opts_highmem=$(echo ${timeline_java_opts[*]} | sed 's;Xmx.*m;Xmx2048m;') + # exports export CLASSPATH="$(echo "${java_classpath[*]}" | sed 's; ;:;g')${CLASSPATH:+:${CLASSPATH}}" export JYPATH="$(echo "${groovy_classpath[*]}" | sed 's; ;:;g')${JYPATH:+:${JYPATH}}" export TIMELINE_JAVA_OPTS="${timeline_java_opts[*]}" export TIMELINE_GROOVY_OPTS="${timeline_groovy_opts[*]}" +export TIMELINE_JAVA_OPTS_HIGHMEM=$timeline_java_opts_highmem diff --git a/bin/run-detectors-timelines.sh b/bin/run-detectors-timelines.sh index 8bcd2627..47158c23 100755 --- a/bin/run-detectors-timelines.sh +++ b/bin/run-detectors-timelines.sh @@ -219,11 +219,11 @@ if ${modes['focus-all']} || ${modes['focus-timelines']}; then [ -n "$singleTimeline" -a "$timelineObj" != "$singleTimeline" ] && continue echo ">>> producing timeline '$timelineObj' ..." if ${modes['debug']}; then - java $TIMELINE_JAVA_OPTS $MAIN $timelineObj $inputDir + java $TIMELINE_JAVA_OPTS_HIGHMEM $MAIN $timelineObj $inputDir echo "PREMATURE EXIT, since --debug option was used" exit else - java $TIMELINE_JAVA_OPTS $MAIN $timelineObj $inputDir > $logFile.out 2> $logFile.err || touch $logFile.fail & + java $TIMELINE_JAVA_OPTS_HIGHMEM $MAIN $timelineObj $inputDir > $logFile.out 2> $logFile.err || touch $logFile.fail & fi if [ $jobCnt -lt $numThreads ]; then let jobCnt++ From 5a6922f9449ca0d64f37671554c8a9415f6a3df1 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Mon, 4 Dec 2023 20:05:15 -0500 Subject: [PATCH 06/14] feat: zoom on a histogram's range of data; needs testing --- .../jlab/clas/timeline/util/HistoUtil.groovy | 25 +++++++++++++++++++ testZoom.groovy | 15 +++++++++++ 2 files changed, 40 insertions(+) create mode 100644 detectors/src/main/java/org/jlab/clas/timeline/util/HistoUtil.groovy create mode 100644 testZoom.groovy diff --git a/detectors/src/main/java/org/jlab/clas/timeline/util/HistoUtil.groovy b/detectors/src/main/java/org/jlab/clas/timeline/util/HistoUtil.groovy new file mode 100644 index 00000000..2254d601 --- /dev/null +++ b/detectors/src/main/java/org/jlab/clas/timeline/util/HistoUtil.groovy @@ -0,0 +1,25 @@ +package org.jlab.clas.timeline.util +import org.jlab.groot.data.H1F + +class HistoUtil { + + // zoom on the range of filled bins of a histogram + static def zoomHisto(H1F inH, int nBufferBins=3) { + + // read input histogram + def nBins = inH.getXaxis().getNBins() + def xData = (0..0 } - nBufferBins, + nBins - xData.reverse().findIndexOf{ it>0 } + nBufferBins + ] + def dataValRange = dataBinRange.collect{ inH.getXaxis().getBinCenter(it) } + def nDataBins = dataBinRange[1] - dataBinRange[0] + + // define and fill the output, zoomed histogram + def outH = new H1F(inH.getName(), inH.getTitle(), nDataBins, dataValRange[0], dataValRange[1]) + nbins.times{ outH.fill( inH.getXaxis().getBinCenter(it), inH.getBinContent(it) } + return outH + } diff --git a/testZoom.groovy b/testZoom.groovy new file mode 100644 index 00000000..b5b83f63 --- /dev/null +++ b/testZoom.groovy @@ -0,0 +1,15 @@ +import org.jlab.groot.data.TDirectory +import org.jlab.groot.data.H1F +import org.jlab.clas.timeline.util + +def inHipo = new TDirectory() +inHipo.readFile("test.hipo") +def h1 = inHipo.getObject("/tof/p2_tdcadc_dt_S1") +def h2 = HistoUtil.zoomHisto(h1) + +def outHipo = new TDirectory() +outHipo.mkdir("/test") +outHipo.cd("/test") +outHipo.addDataSet(h1) +outHipo.addDataSet(h2) +outHipo.write("out.hipo") From 8eef57fb41a34d76dee8c997de651ce6f6ab5664 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Tue, 5 Dec 2023 16:28:31 -0500 Subject: [PATCH 07/14] fix: `histoZoom` result is now consistent with input --- .../jlab/clas/timeline/util/HistoUtil.groovy | 57 +++++++++++++++---- testZoom.groovy | 15 ----- 2 files changed, 46 insertions(+), 26 deletions(-) delete mode 100644 testZoom.groovy diff --git a/detectors/src/main/java/org/jlab/clas/timeline/util/HistoUtil.groovy b/detectors/src/main/java/org/jlab/clas/timeline/util/HistoUtil.groovy index 2254d601..bf77c728 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/util/HistoUtil.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/util/HistoUtil.groovy @@ -3,23 +3,58 @@ import org.jlab.groot.data.H1F class HistoUtil { - // zoom on the range of filled bins of a histogram - static def zoomHisto(H1F inH, int nBufferBins=3) { + /// zoom on the range of filled bins of a histogram + /// @param histIn the input histogram + /// @param threshold the fraction of the max bin to assume valid data (useful for ignoring long tails) + /// @param nBufferBins how many extra bins on each side of the zoomed range + static def zoomHisto(H1F histIn, double threshold=0.0, int nBufferBins=3) { // read input histogram - def nBins = inH.getXaxis().getNBins() - def xData = (0..1 || nBufferBins<0) { + throw new Exception("bad arguments for zoomHisto") + } // find the data range + def minVal = xData.max() * threshold def dataBinRange = [ - xData.findIndexOf{ it>0 } - nBufferBins, - nBins - xData.reverse().findIndexOf{ it>0 } + nBufferBins + [ xData.findIndexOf{ it > minVal } - nBufferBins, 0 ].max(), + [ nBinsIn - xData.reverse().findIndexOf{ it > minVal } + nBufferBins, nBinsIn-1].min() ] - def dataValRange = dataBinRange.collect{ inH.getXaxis().getBinCenter(it) } - def nDataBins = dataBinRange[1] - dataBinRange[0] + def rangeOut = dataBinRange.collect{ histIn.getXaxis().getBinCenter(it) } + rangeOut[0] -= widthIn / 2 + rangeOut[1] += widthIn / 2 + def nBinsOut = dataBinRange[1] - dataBinRange[0] + 1 + def widthOut = (rangeOut[1]-rangeOut[0]) / nBinsOut + + // print some information, for debugging + def printDebug = { + System.err.println """ + histoZoom of histogram '${histIn.getName()}': + nBins: ${nBinsIn} -> ${nBinsOut} + xMin: ${rangeIn[0]} -> ${rangeOut[0]} + xMax: ${rangeIn[1]} -> ${rangeOut[1]} + binWidth: ${widthIn} -> ${widthOut} + """ + } + // printDebug() + + // check that the bin width is correct + if((widthIn-widthOut).abs()>0.0001) { + printDebug() + throw new Exception("bin widths don't match") + } // define and fill the output, zoomed histogram - def outH = new H1F(inH.getName(), inH.getTitle(), nDataBins, dataValRange[0], dataValRange[1]) - nbins.times{ outH.fill( inH.getXaxis().getBinCenter(it), inH.getBinContent(it) } - return outH + def histOut = new H1F(histIn.getName(), histIn.getTitle(), nBinsOut, rangeOut[0], rangeOut[1]) + histOut.setTitleX(histIn.getTitleX()) + histOut.setTitleY(histIn.getTitleY()) + nBinsIn.times{ histOut.fill(histIn.getXaxis().getBinCenter(it), histIn.getBinContent(it)) } + return histOut } +} diff --git a/testZoom.groovy b/testZoom.groovy deleted file mode 100644 index b5b83f63..00000000 --- a/testZoom.groovy +++ /dev/null @@ -1,15 +0,0 @@ -import org.jlab.groot.data.TDirectory -import org.jlab.groot.data.H1F -import org.jlab.clas.timeline.util - -def inHipo = new TDirectory() -inHipo.readFile("test.hipo") -def h1 = inHipo.getObject("/tof/p2_tdcadc_dt_S1") -def h2 = HistoUtil.zoomHisto(h1) - -def outHipo = new TDirectory() -outHipo.mkdir("/test") -outHipo.cd("/test") -outHipo.addDataSet(h1) -outHipo.addDataSet(h2) -outHipo.write("out.hipo") From 7d4e1d78ea2419ec909fad30853f819b5e08654a Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Tue, 5 Dec 2023 16:30:11 -0500 Subject: [PATCH 08/14] fix: revert mempool allocation --- bin/run-detectors-timelines.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/run-detectors-timelines.sh b/bin/run-detectors-timelines.sh index 47158c23..8bcd2627 100755 --- a/bin/run-detectors-timelines.sh +++ b/bin/run-detectors-timelines.sh @@ -219,11 +219,11 @@ if ${modes['focus-all']} || ${modes['focus-timelines']}; then [ -n "$singleTimeline" -a "$timelineObj" != "$singleTimeline" ] && continue echo ">>> producing timeline '$timelineObj' ..." if ${modes['debug']}; then - java $TIMELINE_JAVA_OPTS_HIGHMEM $MAIN $timelineObj $inputDir + java $TIMELINE_JAVA_OPTS $MAIN $timelineObj $inputDir echo "PREMATURE EXIT, since --debug option was used" exit else - java $TIMELINE_JAVA_OPTS_HIGHMEM $MAIN $timelineObj $inputDir > $logFile.out 2> $logFile.err || touch $logFile.fail & + java $TIMELINE_JAVA_OPTS $MAIN $timelineObj $inputDir > $logFile.out 2> $logFile.err || touch $logFile.fail & fi if [ $jobCnt -lt $numThreads ]; then let jobCnt++ From 005d82d2d5608a5b8c6026e507cc2e711945d0ac Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Tue, 5 Dec 2023 16:34:52 -0500 Subject: [PATCH 09/14] refactor!: remove `ftof.*zoomed` timelines --- .../java/org/jlab/clas/timeline/run.groovy | 3 - .../org/jlab/clas/timeline/run_rgb.groovy | 3 - .../ftof/ftof_tdcadc_p1a_zoomed.groovy | 80 ------------------ .../ftof/ftof_tdcadc_p1b_zoomed.groovy | 80 ------------------ .../ftof/ftof_tdcadc_p2_zoomed.groovy | 84 ------------------- 5 files changed, 250 deletions(-) delete mode 100644 detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1a_zoomed.groovy delete mode 100644 detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1b_zoomed.groovy delete mode 100644 detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p2_zoomed.groovy diff --git a/detectors/src/main/java/org/jlab/clas/timeline/run.groovy b/detectors/src/main/java/org/jlab/clas/timeline/run.groovy index 0e621b8e..37e25c0b 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/run.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/run.groovy @@ -100,9 +100,6 @@ def engines = [ new ftof.ftof_tdcadc_p1a(), new ftof.ftof_tdcadc_p1b(), new ftof.ftof_tdcadc_p2(), - // new ftof.ftof_tdcadc_p1a_zoomed(), - // new ftof.ftof_tdcadc_p1b_zoomed(), - // new ftof.ftof_tdcadc_p2_zoomed(), new ftof.ftof_ctof_vtdiff(), new dc.dc_residuals_sec(), new dc.dc_residuals_sec_sl(), diff --git a/detectors/src/main/java/org/jlab/clas/timeline/run_rgb.groovy b/detectors/src/main/java/org/jlab/clas/timeline/run_rgb.groovy index 16dfac0d..0c989730 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/run_rgb.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/run_rgb.groovy @@ -103,9 +103,6 @@ def engines = [ new ftof.ftof_tdcadc_p1a(), new ftof.ftof_tdcadc_p1b(), new ftof.ftof_tdcadc_p2(), - // new ftof.ftof_tdcadc_p1a_zoomed(), - // new ftof.ftof_tdcadc_p1b_zoomed(), - // new ftof.ftof_tdcadc_p2_zoomed(), new ftof.ftof_ctof_vtdiff(), new dc.dc_residuals_sec(), new dc.dc_residuals_sec_sl(), diff --git a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1a_zoomed.groovy b/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1a_zoomed.groovy deleted file mode 100644 index 9163bc41..00000000 --- a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1a_zoomed.groovy +++ /dev/null @@ -1,80 +0,0 @@ -package org.jlab.clas.timeline.timeline.ftof -import java.util.concurrent.ConcurrentHashMap -import org.jlab.groot.data.TDirectory -import org.jlab.groot.data.GraphErrors -import org.jlab.clas.timeline.fitter.FTOFFitter -import org.jlab.groot.data.H1F - -class ftof_tdcadc_p1a_zoomed { - -def data = new ConcurrentHashMap() - -def processDirectory(dir, run) { - def funclist = [] - def meanlist = [] - def sigmalist = [] - def chi2list = [] - def histlist = (0..<6).collect{ - def h1 = dir.getObject('/tof/p1a_tdcadc_dt_S'+(it+1)) - def f1 = FTOFFitter.tdcadcdifffit_p1a(h1) - def peak = f1.getParameter(1) - def sigma = f1.getParameter(2).abs() - def minH = h1.getAxis().min() - def maxH = h1.getAxis().max() - if (peak>minH && peak - TDirectory out = new TDirectory() - out.mkdir('/timelines') - (0..<6).each{ sec-> - def grtl = new GraphErrors('sec'+(sec+1)) - grtl.setTitle("p1a t_tdc-t_fadc (" + name +")") - grtl.setTitleY("p1a t_tdc-t_fadc (" + name +") (ns)") - grtl.setTitleX("run number") - - data.sort{it.key}.each{run,it-> - if (sec==0){ - out.mkdir('/'+it.run) - } - out.cd('/'+it.run) - out.addDataSet(it.hlist[sec]) - out.addDataSet(it.flist[sec]) - grtl.addPoint(it.run, it[name][sec], 0, 0) - } - out.cd('/timelines') - out.addDataSet(grtl) - } - - out.writeFile('ftof_tdcadc_time_p1a_zoomed_' + name + '.hipo') - } -} -} diff --git a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1b_zoomed.groovy b/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1b_zoomed.groovy deleted file mode 100644 index c57d2fcf..00000000 --- a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1b_zoomed.groovy +++ /dev/null @@ -1,80 +0,0 @@ -package org.jlab.clas.timeline.timeline.ftof -import java.util.concurrent.ConcurrentHashMap -import org.jlab.groot.data.TDirectory -import org.jlab.groot.data.GraphErrors -import org.jlab.clas.timeline.fitter.FTOFFitter -import org.jlab.groot.data.H1F - -class ftof_tdcadc_p1b_zoomed { - -def data = new ConcurrentHashMap() - -def processDirectory(dir, run) { - def funclist = [] - def meanlist = [] - def sigmalist = [] - def chi2list = [] - def histlist = (0..<6).collect{ - def h1 = dir.getObject('/tof/p1b_tdcadc_dt_S'+(it+1)) - def f1 = FTOFFitter.tdcadcdifffit_p1b(h1) - def peak = f1.getParameter(1) - def sigma = f1.getParameter(2).abs() - def minH = h1.getAxis().min() - def maxH = h1.getAxis().max() - if (peak>minH && peak - TDirectory out = new TDirectory() - out.mkdir('/timelines') - (0..<6).each{ sec-> - def grtl = new GraphErrors('sec'+(sec+1)) - grtl.setTitle("p1b t_tdc-t_fadc (" + name +")") - grtl.setTitleY("p1b t_tdc-t_fadc (" + name +") (ns)") - grtl.setTitleX("run number") - - data.sort{it.key}.each{run,it-> - if (sec==0){ - out.mkdir('/'+it.run) - } - out.cd('/'+it.run) - out.addDataSet(it.hlist[sec]) - out.addDataSet(it.flist[sec]) - grtl.addPoint(it.run, it[name][sec], 0, 0) - } - out.cd('/timelines') - out.addDataSet(grtl) - } - - out.writeFile('ftof_tdcadc_time_p1b_zoomed_' + name + '.hipo') - } -} -} diff --git a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p2_zoomed.groovy b/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p2_zoomed.groovy deleted file mode 100644 index 3b90d321..00000000 --- a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p2_zoomed.groovy +++ /dev/null @@ -1,84 +0,0 @@ -package org.jlab.clas.timeline.timeline.ftof -import java.util.concurrent.ConcurrentHashMap -import org.jlab.groot.data.TDirectory -import org.jlab.groot.data.GraphErrors -import org.jlab.clas.timeline.fitter.FTOFFitter -import org.jlab.groot.data.H1F - -class ftof_tdcadc_p2_zoomed { - -def data = new ConcurrentHashMap() - -def processDirectory(dir, run) { - def funclist = [] - def meanlist = [] - def sigmalist = [] - def chi2list = [] - def histlist = (0..<6).collect{ - def h1 = dir.getObject('/tof/p2_tdcadc_dt_S'+(it+1)) - def f1 = FTOFFitter.tdcadcdifffit_p2(h1) - def peak = f1.getParameter(1) - def sigma = f1.getParameter(2).abs() - def minX = h1.getAxis().min() - def maxX = h1.getAxis().max() - if (peak>minX && peakmaxX || maxH - TDirectory out = new TDirectory() - out.mkdir('/timelines') - (0..<6).each{ sec-> - def grtl = new GraphErrors('sec'+(sec+1)) - grtl.setTitle("p2 t_tdc-t_fadc (" + name +")") - grtl.setTitleY("p2 t_tdc-t_fadc (" + name +") (ns)") - grtl.setTitleX("run number") - - data.sort{it.key}.each{run,it-> - if (sec==0){ - out.mkdir('/'+it.run) - } - out.cd('/'+it.run) - out.addDataSet(it.hlist[sec]) - out.addDataSet(it.flist[sec]) - grtl.addPoint(it.run, it[name][sec], 0, 0) - } - out.cd('/timelines') - out.addDataSet(grtl) - } - - out.writeFile('ftof_tdcadc_time_p2_zoomed_' + name + '.hipo') - } -} -} From b72f7d50b0c75ca85318846a95e3d63a793dd289 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Tue, 5 Dec 2023 16:39:48 -0500 Subject: [PATCH 10/14] fix: apply zooming to FTOF histograms --- .../jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1a.groovy | 3 ++- .../jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1b.groovy | 3 ++- .../org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p2.groovy | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1a.groovy b/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1a.groovy index a6c5c698..ab2a7812 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1a.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1a.groovy @@ -3,6 +3,7 @@ import java.util.concurrent.ConcurrentHashMap import org.jlab.groot.data.TDirectory import org.jlab.groot.data.GraphErrors import org.jlab.clas.timeline.fitter.FTOFFitter +import org.jlab.clas.timeline.util.HistoUtil class ftof_tdcadc_p1a { @@ -14,7 +15,7 @@ def processDirectory(dir, run) { def sigmalist = [] def chi2list = [] def histlist = (0..<6).collect{ - def h1 = dir.getObject('/tof/p1a_tdcadc_dt_S'+(it+1)) + def h1 = HistoUtil.zoomHisto(dir.getObject('/tof/p1a_tdcadc_dt_S'+(it+1))) def f1 = FTOFFitter.tdcadcdifffit_p1a(h1) funclist.add(f1) diff --git a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1b.groovy b/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1b.groovy index 007ec9d1..7df8f3c3 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1b.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p1b.groovy @@ -3,6 +3,7 @@ import java.util.concurrent.ConcurrentHashMap import org.jlab.groot.data.TDirectory import org.jlab.groot.data.GraphErrors import org.jlab.clas.timeline.fitter.FTOFFitter +import org.jlab.clas.timeline.util.HistoUtil class ftof_tdcadc_p1b { @@ -14,7 +15,7 @@ def processDirectory(dir, run) { def sigmalist = [] def chi2list = [] def histlist = (0..<6).collect{ - def h1 = dir.getObject('/tof/p1b_tdcadc_dt_S'+(it+1)) + def h1 = HistoUtil.zoomHisto(dir.getObject('/tof/p1b_tdcadc_dt_S'+(it+1))) def f1 = FTOFFitter.tdcadcdifffit_p1b(h1) funclist.add(f1) diff --git a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p2.groovy b/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p2.groovy index 8ad98aa0..0d52cae1 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p2.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p2.groovy @@ -3,6 +3,7 @@ import java.util.concurrent.ConcurrentHashMap import org.jlab.groot.data.TDirectory import org.jlab.groot.data.GraphErrors import org.jlab.clas.timeline.fitter.FTOFFitter +import org.jlab.clas.timeline.util.HistoUtil class ftof_tdcadc_p2 { @@ -14,7 +15,7 @@ def processDirectory(dir, run) { def sigmalist = [] def chi2list = [] def histlist = (0..<6).collect{ - def h1 = dir.getObject('/tof/p2_tdcadc_dt_S'+(it+1)) + def h1 = HistoUtil.zoomHisto(dir.getObject('/tof/p2_tdcadc_dt_S'+(it+1))) def f1 = FTOFFitter.tdcadcdifffit_p2(h1) funclist.add(f1) From 23ca2085320ba3dad59c351a6acaba295aeea98b Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Tue, 5 Dec 2023 19:08:27 -0500 Subject: [PATCH 11/14] doc: `FIXME` note about bad fits --- .../jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p2.groovy | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p2.groovy b/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p2.groovy index 0d52cae1..284847ab 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p2.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/timeline/ftof/ftof_tdcadc_p2.groovy @@ -18,6 +18,12 @@ def processDirectory(dir, run) { def h1 = HistoUtil.zoomHisto(dir.getObject('/tof/p2_tdcadc_dt_S'+(it+1))) def f1 = FTOFFitter.tdcadcdifffit_p2(h1) + // FIXME + // FIXME + // these fits are often bad! + // FIXME + // FIXME + funclist.add(f1) meanlist.add(f1.getParameter(1)) sigmalist.add(f1.getParameter(2).abs()) From 62f5e43b4c1e52361d5e7de82a74e1597de36a2c Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Wed, 6 Dec 2023 11:06:31 -0500 Subject: [PATCH 12/14] fix: stabilize `ftof_tdcadc_p2` fits --- .../clas/timeline/fitter/FTOFFitter.groovy | 65 +++++++++---------- .../timeline/ftof/ftof_tdcadc_p2.groovy | 6 -- 2 files changed, 32 insertions(+), 39 deletions(-) diff --git a/detectors/src/main/java/org/jlab/clas/timeline/fitter/FTOFFitter.groovy b/detectors/src/main/java/org/jlab/clas/timeline/fitter/FTOFFitter.groovy index e7326b6f..d4138b98 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/fitter/FTOFFitter.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/fitter/FTOFFitter.groovy @@ -31,33 +31,33 @@ class FTOFFitter { return f1 } - static F1D timefit_p2(H1F h1) { - def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -0.5, 0.5); - double hAmp = h1.getBinContent(h1.getMaximumBin()); - double hMean = h1.getAxis().getBinCenter(h1.getMaximumBin()); - double hRMS = 0.3;//h1.getRMS(); //ns - double rangeMin = (hMean - 2.5*hRMS); - double rangeMax = (hMean + 2.5*hRMS); - f1.setRange(rangeMin, rangeMax); - f1.setParameter(0, hAmp); - f1.setParameter(1, hMean); - f1.setParameter(2, hRMS); - - def makefit = {func-> - hMean = func.getParameter(1) - hRMS = func.getParameter(2).abs() - func.setRange(hMean-1.5*hRMS,hMean+1.5*hRMS) - MoreFitter.fit(func,h1,"Q") - return [func.getChiSquare(), (0.. + hMean = func.getParameter(1) + hRMS = func.getParameter(2).abs() + func.setRange(hMean-1.5*hRMS,hMean+1.5*hRMS) + MoreFitter.fit(func,h1,"Q") + return [func.getChiSquare(), (0.. hMean = func.getParameter(1) hRMS = func.getParameter(2).abs() @@ -88,6 +87,7 @@ class FTOFFitter { return f1 } + static F1D tdcadcdifffit_p1b(H1F h1) { def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -1.0, 1.0); double hAmp = h1.getBinContent(h1.getMaximumBin()); @@ -120,19 +120,18 @@ class FTOFFitter { def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -1.0, 1.0); double hAmp = h1.getBinContent(h1.getMaximumBin()); double hMean = h1.getAxis().getBinCenter(h1.getMaximumBin()); - double hRMS = h1.getRMS(); //ns - double rangeMin = (hMean - 2.5*hRMS); - double rangeMax = (hMean + hRMS); + double hRMS = 1.9//h1.getRMS(); //ns + double rangeMin = (hMean - 1.5*hRMS); + double rangeMax = (hMean + 1.5*hRMS); f1.setRange(rangeMin, rangeMax); f1.setParameter(0, hAmp); f1.setParameter(1, hMean); f1.setParameter(2, hRMS); - def makefit = {func-> hMean = func.getParameter(1) hRMS = func.getParameter(2).abs() - func.setRange(hMean - 1.5*hRMS, hMean + 1.5*hRMS) + func.setRange(hMean-1.5*hRMS,hMean+1.5*hRMS) MoreFitter.fit(func,h1,"Q") return [func.getChiSquare(), (0.. Date: Wed, 6 Dec 2023 11:14:59 -0500 Subject: [PATCH 13/14] fix: remove debug statement --- detectors/src/main/java/org/jlab/clas/timeline/run.groovy | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/detectors/src/main/java/org/jlab/clas/timeline/run.groovy b/detectors/src/main/java/org/jlab/clas/timeline/run.groovy index 37e25c0b..ec22078b 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/run.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/run.groovy @@ -167,8 +167,7 @@ if(eng) { System.exit(100) } } - println("debug: trying to call close()") - engine.close() // leak happens here! + engine.close() println("debug: "+engine.getClass().getSimpleName()+" ended") } else { System.err.println("error: "+args[0]+" not found") From b5830fefdad0cd18425b5c9fda0c186abd1029ff Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Wed, 6 Dec 2023 11:16:09 -0500 Subject: [PATCH 14/14] doc: clarify downsampling option --- .../java/org/jlab/clas/timeline/timeline/epics/MYQuery.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/MYQuery.groovy b/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/MYQuery.groovy index 67a407b9..bbca9a93 100755 --- a/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/MYQuery.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/timeline/epics/MYQuery.groovy @@ -14,7 +14,7 @@ class MYQuery { 'd': 'on', // data update events only 'p': 'on', // include prior point 'm': 'history', // MYA deployment - 'l': '', // limit by binning + 'l': '', // limit by binning (downsample) ] // timestamps