diff --git a/detectors/src/main/java/org/jlab/clas/timeline/fitter/CTOFFitter.groovy b/detectors/src/main/java/org/jlab/clas/timeline/fitter/CTOFFitter.groovy index fa46461f..a6fe5f98 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/fitter/CTOFFitter.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/fitter/CTOFFitter.groovy @@ -34,103 +34,72 @@ class CTOFFitter { return f1 } - static F1D tdcadcdifffit(H1F h1) { - def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -5.0, 5.0) - double hAmp = h1.getBinContent(h1.getMaximumBin()); - double hMean = h1.getAxis().getBinCenter(h1.getMaximumBin()) - double hRMS = h1.getRMS(); - double factor1 = 3.0 - double factor2 = 1.57 - double rangeMin = (hMean - factor1*0.5); - double rangeMax = (hMean + factor2*0.5); - f1.setRange(rangeMin, rangeMax); - f1.setParameter(0, hAmp); - // f1.setParLimits(0, hAmp*0.8, hAmp*1.2); - f1.setParameter(1, hMean); - // f1.setParLimits(1, 0, 0.5); - f1.setParameter(2, 1); - // f1.setParLimits(2, 0.5*hRMS, 1.5*hRMS); - - def makefit = {func-> - hMean = func.getParameter(1) - hRMS = func.getParameter(2).abs() - func.setRange(hMean-2*hRMS,hMean+2*hRMS) - DataFitter.fit(func,h1,"Q") - return [func.getChiSquare(), (0.. - hMean = func.getParameter(1) - hRMS = func.getParameter(2).abs() - func.setRange(hMean-2*hRMS,hMean+2*hRMS) - DataFitter.fit(func,h1,"Q") - return [func.getChiSquare(), (0.. + def f1 = new F1D("${prefix}:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -5.0, 5.0) + double hAmp = h1.getBinContent(peakbin); + double hMean = h1.getAxis().getBinCenter(peakbin) + double hRMS = h1.getRMS(); + double factor1 = 3.0 + double factor2 = 1.57 + double rangeMin = (hMean - factor1*0.5); + double rangeMax = (hMean + factor2*0.5); + f1.setRange(rangeMin, rangeMax); + f1.setParameter(0, hAmp); + // f1.setParLimits(0, hAmp*0.8, hAmp*1.2); + f1.setParameter(1, hMean); + // f1.setParLimits(1, 0, 0.5); + f1.setParameter(2, 1); + // f1.setParLimits(2, 0.5*hRMS, 1.5*hRMS); + + def makefit = {func-> + hMean = func.getParameter(1) + hRMS = func.getParameter(2).abs() + func.setRange(hMean-2*hRMS,hMean+2*hRMS) + DataFitter.fit(func,h1,"Q") + return [func.getChiSquare(), (0.. - hMean = func.getParameter(1) - hRMS = func.getParameter(2).abs() - func.setRange(hMean-2*hRMS,hMean+2*hRMS) - DataFitter.fit(func,h1,"Q") - return [func.getChiSquare(), (0.. peak1End } + .max{ it[1] }[0] + def func2 = fit_peak(peakbin2,'fit2') + + // decide which fit result is upstream and downstream + def funcs = func1.getParameter(1) < func2.getParameter(1) ? [func1,func2] : [func2,func1] + + // create a summed combination (since the front-end seems to prefer this) + def combinedFunc = new F1D( + "fit:"+h1.getName(), + "[ampUpstream]*gaus(x,[meanUpstream],[sigmaUpstream])+[ampDownstream]*gaus(x,[meanDownstream],[sigmaDownstream])", + funcs[0].getParameter(1) - 3*funcs[0].getParameter(2), + funcs[1].getParameter(1) + 3*funcs[1].getParameter(2)) + [0,1,2].each{ + combinedFunc.setParameter(it, funcs[0].getParameter(it)) + combinedFunc.setParameter(it+3, funcs[1].getParameter(it)) } + funcs.add(combinedFunc) - def fits1 = (0..20).collect{makefit(f1)} - def bestfit = fits1.sort()[0] - f1.setParameters(*bestfit[1]) - //makefit(f1) - return f1 + return funcs // [ upstream fit, downstream fit, combined fit ] } diff --git a/detectors/src/main/java/org/jlab/clas/timeline/run_detectors.groovy b/detectors/src/main/java/org/jlab/clas/timeline/run_detectors.groovy index 7433df03..93662408 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/run_detectors.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/run_detectors.groovy @@ -69,8 +69,7 @@ def engines = [ new cnd.cnd_zdiff()], out_CTOF: [new ctof.ctof_edep(), new ctof.ctof_time(), - new ctof.ctof_tdcadc_left(), - new ctof.ctof_tdcadc_right()], + new ctof.ctof_tdcadc()], out_FT: [new ft.ftc_pi0_mass(), new ft.ftc_time_charged(), new ft.ftc_time_neutral(), diff --git a/detectors/src/main/java/org/jlab/clas/timeline/run_detectors_rgb.groovy b/detectors/src/main/java/org/jlab/clas/timeline/run_detectors_rgb.groovy index 76bac390..e0809db8 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/run_detectors_rgb.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/run_detectors_rgb.groovy @@ -70,8 +70,7 @@ def engines = [ new cnd.cnd_zdiff()], out_CTOF: [new ctof.ctof_edep(), new ctof.ctof_time(), - new ctof.ctof_tdcadc_left(), - new ctof.ctof_tdcadc_right(), + new ctof.ctof_tdcadc(), new particle_mass_ctof_and_ftof.ctof_m2_pim(), new particle_mass_ctof_and_ftof.ctof_m2_pip()], out_FT: [new ft.ftc_pi0_mass(), diff --git a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ctof/ctof_tdcadc.groovy b/detectors/src/main/java/org/jlab/clas/timeline/timeline/ctof/ctof_tdcadc.groovy index d91ca118..6429431f 100644 --- a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ctof/ctof_tdcadc.groovy +++ b/detectors/src/main/java/org/jlab/clas/timeline/timeline/ctof/ctof_tdcadc.groovy @@ -11,9 +11,19 @@ def data = new ConcurrentHashMap() def processDirectory(dir, run) { def h1 = dir.getObject('/ctof/CTOF TDC-ADC Time Difference') - def f1 = CTOFFitter.tdcadcdifffit(h1) - - data[run] = [run:run, h1:h1, f1:f1, mean:f1.getParameter(1), sigma:f1.getParameter(2).abs(), chi2:f1.getChiSquare()] + def f1s = CTOFFitter.tdcadcdifffit(h1) + + data[run] = [ + run: run, + h1: h1, + meanUpstream: f1s[0].getParameter(1), + sigmaUpstream: f1s[0].getParameter(2).abs(), + chi2Upstream: f1s[0].getChiSquare(), + meanDownstream: f1s[1].getParameter(1), + sigmaDownstream: f1s[1].getParameter(2).abs(), + chi2Downstream: f1s[1].getChiSquare(), + f1Combined: f1s[2], + ] } @@ -22,10 +32,13 @@ def close() { ['mean', 'sigma'].each{name-> - def grtl = new GraphErrors(name) - grtl.setTitle("TDC time - FADC time averaged over CTOF counters (" + name +")") - grtl.setTitleY("TDC time - FADC time averaged over CTOF counters (" + name + ") (ns)") - grtl.setTitleX("run number") + def grtlUpstream = new GraphErrors("upstream_${name}") + def grtlDownstream = new GraphErrors("downstream_${name}") + [grtlUpstream,grtlDownstream].each{ grtl -> + grtl.setTitle("TDC time - FADC time averaged over CTOF counters") + grtl.setTitleY("TDC time - FADC time averaged over CTOF counters [ns]") + grtl.setTitleX("run number") + } TDirectory out = new TDirectory() @@ -33,14 +46,16 @@ def close() { out.mkdir('/'+it.run) out.cd('/'+it.run) out.addDataSet(it.h1) - out.addDataSet(it.f1) - grtl.addPoint(it.run, it[name], 0, 0) + out.addDataSet(it.f1Combined) + grtlUpstream.addPoint(it.run, it["${name}Upstream"], 0, 0) + grtlDownstream.addPoint(it.run, it["${name}Downstream"], 0, 0) } out.mkdir('/timelines') out.cd('/timelines') - out.addDataSet(grtl) - out.writeFile('ctof_tdcadc_time_'+name+'.hipo') + out.addDataSet(grtlUpstream) + out.addDataSet(grtlDownstream) + out.writeFile("ctof_tdcadc_time_${name}.hipo") } } } diff --git a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ctof/ctof_tdcadc_left.groovy b/detectors/src/main/java/org/jlab/clas/timeline/timeline/ctof/ctof_tdcadc_left.groovy deleted file mode 100644 index a81cd5cc..00000000 --- a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ctof/ctof_tdcadc_left.groovy +++ /dev/null @@ -1,46 +0,0 @@ -package org.jlab.clas.timeline.timeline.ctof -import java.util.concurrent.ConcurrentHashMap -import org.jlab.groot.data.TDirectory -import org.jlab.groot.data.GraphErrors -import org.jlab.clas.timeline.fitter.CTOFFitter; - -class ctof_tdcadc_left { - - -def data = new ConcurrentHashMap() - -def processDirectory(dir, run) { - def h1 = dir.getObject('/ctof/CTOF TDC-ADC Time Difference') - def f1 = CTOFFitter.tdcadcdifffit_left(h1) - - data[run] = [run:run, h1:h1, f1:f1, mean:f1.getParameter(1), sigma:f1.getParameter(2).abs(), chi2:f1.getChiSquare()] -} - - - -def close() { - - - ['mean', 'sigma'].each{name-> - def grtl = new GraphErrors(name) - grtl.setTitle("TDC time - FADC time averaged over CTOF counters, left peak (" + name +")") - grtl.setTitleY("TDC time - FADC time averaged over CTOF counters, left peak (" + name + ") (ns)") - grtl.setTitleX("run number") - - TDirectory out = new TDirectory() - - data.sort{it.key}.each{run,it-> - out.mkdir('/'+it.run) - out.cd('/'+it.run) - out.addDataSet(it.h1) - out.addDataSet(it.f1) - grtl.addPoint(it.run, it[name], 0, 0) - } - - out.mkdir('/timelines') - out.cd('/timelines') - out.addDataSet(grtl) - out.writeFile('ctof_tdcadc_time_left_'+name+'.hipo') - } -} -} diff --git a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ctof/ctof_tdcadc_right.groovy b/detectors/src/main/java/org/jlab/clas/timeline/timeline/ctof/ctof_tdcadc_right.groovy deleted file mode 100644 index 01d90129..00000000 --- a/detectors/src/main/java/org/jlab/clas/timeline/timeline/ctof/ctof_tdcadc_right.groovy +++ /dev/null @@ -1,46 +0,0 @@ -package org.jlab.clas.timeline.timeline.ctof -import java.util.concurrent.ConcurrentHashMap -import org.jlab.groot.data.TDirectory -import org.jlab.groot.data.GraphErrors -import org.jlab.clas.timeline.fitter.CTOFFitter; - -class ctof_tdcadc_right { - - -def data = new ConcurrentHashMap() - -def processDirectory(dir, run) { - def h1 = dir.getObject('/ctof/CTOF TDC-ADC Time Difference') - def f1 = CTOFFitter.tdcadcdifffit_right(h1) - - data[run] = [run:run, h1:h1, f1:f1, mean:f1.getParameter(1), sigma:f1.getParameter(2).abs(), chi2:f1.getChiSquare()] -} - - - -def close() { - - - ['mean', 'sigma'].each{name-> - def grtl = new GraphErrors(name) - grtl.setTitle("TDC time - FADC time averaged over CTOF counters, right peak (" + name +")") - grtl.setTitleY("TDC time - FADC time averaged over CTOF counters, right peak (" + name + ") (ns)") - grtl.setTitleX("run number") - - TDirectory out = new TDirectory() - - data.sort{it.key}.each{run,it-> - out.mkdir('/'+it.run) - out.cd('/'+it.run) - out.addDataSet(it.h1) - out.addDataSet(it.f1) - grtl.addPoint(it.run, it[name], 0, 0) - } - - out.mkdir('/timelines') - out.cd('/timelines') - out.addDataSet(grtl) - out.writeFile('ctof_tdcadc_time_right_'+name+'.hipo') - } -} -} diff --git a/monitoring/src/main/java/org/jlab/clas12/monitoring/central.java b/monitoring/src/main/java/org/jlab/clas12/monitoring/central.java index ca31abaf..60035076 100644 --- a/monitoring/src/main/java/org/jlab/clas12/monitoring/central.java +++ b/monitoring/src/main/java/org/jlab/clas12/monitoring/central.java @@ -122,7 +122,7 @@ public central(int reqrunNum, String reqOutputDir, boolean reqTimeBased) { H_CTOF_edep_z.setTitle("CTOF PathLCorrected Edep vs z"); H_CTOF_edep_z.setTitleX("z/10 (cm)"); H_CTOF_edep_z.setTitleY("E (MeV)"); - H_CTOF_tdcadc_dt = new H1F("CTOF TDC-ADC Time Difference","CTOF TDC-ADC Time Difference",2250,-10.,80.); + H_CTOF_tdcadc_dt = new H1F("CTOF TDC-ADC Time Difference","CTOF TDC-ADC Time Difference",4750,-10.,180.); H_CTOF_tdcadc_dt.setTitle("CTOF TDC_time-ADC_time"); H_CTOF_tdcadc_dt.setTitleX("Delta_t (ns)"); H_CTOF_tdcadc_dt.setTitleY("counts");