Skip to content

Commit

Permalink
fix: widen CTOF tdcadc time distribution (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks authored Aug 2, 2024
1 parent b53e43c commit f9a2487
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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..<func.getNPars()).collect{func.getParameter(it)}]
}

def fits1 = (0..20).collect{makefit(f1)}
def bestfit = fits1.sort()[0]
f1.setParameters(*bestfit[1])
//makefit(f1)
return f1
}


static F1D tdcadcdifffit_right(H1F h1) {
def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -5.0, 5.0)
def peakbin = (1000..1500).max{h1.getBinContent(it)}
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..<func.getNPars()).collect{func.getParameter(it)}]
static def tdcadcdifffit(H1F h1) {

def fit_peak = { peakbin, prefix ->
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..<func.getNPars()).collect{func.getParameter(it)}]
}

def fits1 = (0..20).collect{makefit(f1)}
def bestfit = fits1.sort()[0]
f1.setParameters(*bestfit[1])
//makefit(f1)
return f1
}

def fits1 = (0..20).collect{makefit(f1)}
def bestfit = fits1.sort()[0]
f1.setParameters(*bestfit[1])
//makefit(f1)
return f1
}

static F1D tdcadcdifffit_left(H1F h1) {
def f1 = new F1D("fit:"+h1.getName(), "[amp]*gaus(x,[mean],[sigma])", -5.0, 5.0)
def peakbin = (400..900).max{h1.getBinContent(it)}
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..<func.getNPars()).collect{func.getParameter(it)}]
// find the highest peak, and fit it
def bins = (1..h1.getAxis().getNBins())
def peakbin1 = bins.max{h1.getBinContent(it)}
def func1 = fit_peak(peakbin1,'fit1')

// find the 2nd highest peak by excluding the region around the 1st highest
// peak, and searching for the new highest max, then fit it
def peak1Start = func1.getParameter(1) - 2*func1.getParameter(2)
def peak1End = func1.getParameter(1) + 2*func1.getParameter(2)
def peakbin2 = bins
.collect{ [ it, h1.getBinContent(it) ] }
.findAll{ h1.getAxis().getBinCenter(it[0]) < peak1Start || h1.getAxis().getBinCenter(it[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 ]
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
]
}


Expand All @@ -22,25 +32,30 @@ 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()

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.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")
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit f9a2487

Please sign in to comment.