('SA.D2', 3.0), ('SB.D2', 4.0), ('SA.D3', 5.0), ('SB.D3', 6.0), ('SA.D4', 7.0), ('SB.D4', 8.0), ], uncertainty=1.0, mode='percent', ), ) cfg3 = NestedDict(bundle=dict( name='parameters', version='v01', ), parameter='constant', label='some constant', pars=uncertain(-1.0, uncertainty=4.0, mode='percent')) b1 = execute_bundle(cfg1) b2 = execute_bundle(cfg2) b3 = execute_bundle(cfg3) env.globalns.printparameters(labels=True) print('Provides:') print(b1.provides(cfg1)) print(b1.provides(cfg2)) print(b1.provides(cfg3))
pars=uncertaindict([ ('z1.a', (0.0, 'fixed')), ('z1.b', (0.05, 30, 'percent')), ('z1.c', (0.0, 'fixed')), ('z2.a', (0.0, 'fixed')), ('z2.b', (0.10, 30, 'percent')), ('z2.c', (0.0, 'fixed')), ('z3.a', (0.0, 'fixed')), ('z3.b', (0.15, 30, 'percent')), ('z3.c', (0.0, 'fixed')), ]), labels=dict(matrix='Smearing\nmatrix\n{autoindex}', smear='Energy\nresolution\n{autoindex}', parameter='{description} (zone {autoindex})'), split_transformations=True) b = execute_bundle(cfg) env.globalns.printparameters(labels=True) print() # # Prepare inputs # emin, emax = 0.0, 12.0 nbins = 240 edges = np.linspace(emin, emax, nbins + 1, dtype='d') data1 = np.zeros(nbins, dtype='d') data1[20] = 1.0 # 1 MeV data1[120] = 1.0 # 6 MeV data1[200] = 1.0 # 10 MeV data2 = np.zeros(nbins, dtype='d')
def main(opts): global savefig cfg = NestedDict( bundle=dict( name='energy_nonlinearity_birks_cherenkov', version='v01', nidx=[('r', 'reference', ['R1', 'R2'])], major=[], ), stopping_power='stoppingpower.txt', annihilation_electrons=dict( file='input/hgamma2e.root', histogram='hgamma2e_1KeV', scale=1.0 / 50000 # event simulated ), pars=uncertaindict( [ ('birks.Kb0', (1.0, 'fixed')), ('birks.Kb1', (15.2e-3, 0.1776)), # ('birks.Kb2', (0.0, 'fixed')), ("cherenkov.E_0", (0.165, 'fixed')), ("cherenkov.p0", (-7.26624e+00, 'fixed')), ("cherenkov.p1", (1.72463e+01, 'fixed')), ("cherenkov.p2", (-2.18044e+01, 'fixed')), ("cherenkov.p3", (1.44731e+01, 'fixed')), ("cherenkov.p4", (3.22121e-02, 'fixed')), ("Npescint", (1341.38, 0.0059)), ("kC", (0.5, 0.4737)), ("normalizationEnergy", (12.0, 'fixed')) ], mode='relative'), integration_order=2, correlations_pars=['birks.Kb1', 'Npescint', 'kC'], correlations=[1.0, 0.94, -0.97, 0.94, 1.0, -0.985, -0.97, -0.985, 1.0], fill_matrix=True, labels=dict(normalizationEnergy='Pessimistic'), ) ns = env.globalns('energy') quench = execute_bundle(cfg, namespace=ns) ns.printparameters(labels=True) print() normE = ns['normalizationEnergy'].value() # # Input bins # evis_edges_full_input = N.arange(0.0, 15.0 + 1.e-6, 0.025) evis_edges_full_hist = C.Histogram(evis_edges_full_input, labels='Evis bin edges') evis_edges_full_hist >> quench.context.inputs.evis_edges_hist['00'] # # Python energy model interpolation function # from scipy.interpolate import interp1d lsnl_x = quench.histoffset.histedges.points_truncated.data() lsnl_y = quench.positron_model_relative.single().data() lsnl_fcn = interp1d(lsnl_x, lsnl_y, kind='quadratic') # # Energy resolution # def eres_sigma_rel(edep): return 0.03 / edep**0.5 def eres_sigma_abs(edep): return 0.03 * edep**0.5 # # Energy offset # from physlib import pc edep_offset = pc.DeltaNP - pc.ElectronMass # # Oscprob # baselinename = 'L' ns = env.ns("oscprob") import gna.parameters.oscillation gna.parameters.oscillation.reqparameters(ns) ns.defparameter(baselinename, central=52.0, fixed=True, label='Baseline, km') # # Define energy range # enu_input = N.arange(1.8, 15.0, 0.001) edep_input = enu_input - edep_offset edep_lsnl = edep_input * lsnl_fcn(edep_input) # Initialize oscillation variables enu = C.Points(enu_input, labels='Neutrino energy, MeV') component_names = C.stdvector(['comp0', 'comp12', 'comp13', 'comp23']) with ns: R.OscProbPMNSExpressions(R.Neutrino.ae(), R.Neutrino.ae(), component_names, ns=ns) labels = [ 'Oscillation probability|%s' % s for s in ('component 12', 'component 13', 'component 23', 'full', 'probsum') ] oscprob = R.OscProbPMNS(R.Neutrino.ae(), R.Neutrino.ae(), baselinename, labels=labels) enu >> oscprob.full_osc_prob.Enu enu >> (oscprob.comp12.Enu, oscprob.comp13.Enu, oscprob.comp23.Enu) unity = C.FillLike(1, labels='Unity') enu >> unity.fill.inputs[0] with ns: op_sum = C.WeightedSum(component_names, [ unity.fill.outputs[0], oscprob.comp12.comp12, oscprob.comp13.comp13, oscprob.comp23.comp23 ], labels='Oscillation probability sum') psur = op_sum.single().data() from scipy.signal import argrelmin, argrelmax psur_minima, = argrelmin(psur) psur_maxima, = argrelmax(psur) def build_extrema(x): data_min_x = (x[psur_minima][:-1] + x[psur_minima][1:]) * 0.5 data_min_y = (x[psur_minima][1:] - x[psur_minima][:-1]) data_max_x = (x[psur_maxima][:-1] + x[psur_maxima][1:]) * 0.5 data_max_y = (x[psur_maxima][1:] - x[psur_maxima][:-1]) data_ext_x = N.vstack([data_max_x, data_min_x]).T.ravel() data_ext_y = N.vstack([data_max_y, data_min_y]).T.ravel() return data_ext_x, data_ext_y psur_ext_x_enu, psur_ext_y_enu = build_extrema(enu_input) psur_ext_x_edep, psur_ext_y_edep = build_extrema(edep_input) psur_ext_x_edep_lsnl, psur_ext_y_edep_lsnl = build_extrema(edep_lsnl) # # Plots and tests # if opts.output and opts.output.endswith('.pdf'): pdfpages = PdfPages(opts.output) pdfpagesfilename = opts.output savefig_old = savefig pdf = pdfpages.__enter__() def savefig(*args, **kwargs): if opts.individual and args and args[0]: savefig_old(*args, **kwargs) pdf.savefig() else: pdf = None pdfpagesfilename = '' pdfpages = None fig = P.figure() ax = P.subplot(111) ax.minorticks_on() ax.grid() ax.set_xlabel('Edep, MeV') ax.set_ylabel('Evis/Edep') ax.set_title('Positron energy nonlineairty') quench.positron_model_relative.single().plot_vs( quench.histoffset.histedges.points_truncated, label='definition range') quench.positron_model_relative_full.plot_vs( quench.histoffset.histedges.points, '--', linewidth=1., label='full range', zorder=0.5) ax.vlines(normE, 0.0, 1.0, linestyle=':') ax.legend(loc='lower right') ax.set_ylim(0.8, 1.05) savefig(opts.output, suffix='_total_relative') fig = P.figure() ax = P.subplot(111) ax.minorticks_on() ax.grid() ax.set_xlabel('Edep, MeV') ax.set_ylabel(r'$\sigma/E$') ax.set_title('Energy resolution') ax.plot(edep_input, eres_sigma_rel(edep_input), '-') savefig(opts.output, suffix='_eres_rel') fig = P.figure() ax = P.subplot(111) ax.minorticks_on() ax.grid() ax.set_xlabel('Edep, MeV') ax.set_ylabel(r'$\sigma$') ax.set_title('Energy resolution') ax.plot(edep_input, eres_sigma_abs(edep_input), '-') savefig(opts.output, suffix='_eres_abs') fig = P.figure() ax = P.subplot(111) ax.minorticks_on() ax.grid() ax.set_xlabel('Enu, MeV') ax.set_ylabel('Psur') ax.set_title('Survival probability') op_sum.single().plot_vs(enu.single(), label='full') ax.plot(enu_input[psur_minima], psur[psur_minima], 'o', markerfacecolor='none', label='minima') ax.plot(enu_input[psur_maxima], psur[psur_maxima], 'o', markerfacecolor='none', label='maxima') savefig(opts.output, suffix='_psur_enu') fig = P.figure() ax = P.subplot(111) ax.minorticks_on() ax.grid() ax.set_xlabel('Edep, MeV') ax.set_ylabel('Psur') ax.set_title('Survival probability') op_sum.single().plot_vs(edep_input, label='true') op_sum.single().plot_vs(edep_lsnl, label='with LSNL') ax.legend() savefig(opts.output, suffix='_psur_edep') fig = P.figure() ax = P.subplot(111) ax.minorticks_on() ax.grid() ax.set_xlabel('Enu, MeV') ax.set_ylabel('Dist, MeV') ax.set_title('Nearest peaks distance') ax.plot(psur_ext_x_enu, psur_ext_y_enu, 'o-', markerfacecolor='none') savefig(opts.output, suffix='_dist_enu') fig = P.figure() ax = P.subplot(111) ax.minorticks_on() ax.grid() ax.set_xlabel('Edep, MeV') ax.set_ylabel('Dist, MeV') ax.set_title('Nearest peaks distance') ax.plot(psur_ext_x_edep, psur_ext_y_edep, '-', markerfacecolor='none', label='true') ax.plot(psur_ext_x_edep_lsnl, psur_ext_y_edep_lsnl, '-', markerfacecolor='none', label='with LSNL') ax.plot(edep_input, eres_sigma_abs(edep_input), '-', markerfacecolor='none', label=r'$\sigma$') ax.legend(loc='upper left') savefig(opts.output, suffix='_dist') fig = P.figure() ax = P.subplot(111) ax.minorticks_on() ax.grid() ax.set_xlabel('Edep, MeV') ax.set_ylabel(r'Dist/$\sigma$') ax.set_title('Resolution ability') x1, y1 = psur_ext_x_edep, psur_ext_y_edep / eres_sigma_abs(psur_ext_x_edep) x2, y2 = psur_ext_x_edep_lsnl, psur_ext_y_edep_lsnl / eres_sigma_abs( psur_ext_x_edep_lsnl) ax.plot(x1, y1, '-', markerfacecolor='none', label='true') ax.plot(x2, y2, '-', markerfacecolor='none', label='with LSNL') ax.legend(loc='upper left') savefig(opts.output, suffix='_ability') ax.set_xlim(3, 4) ax.set_ylim(5, 8) savefig(opts.output, suffix='_ability_zoom') fig = P.figure() ax = P.subplot(111) ax.minorticks_on() ax.grid() ax.set_xlabel('Edep, MeV') ax.set_ylabel(r'Dist/$\sigma$') ax.set_title('Resolution ability difference (quenching-true)') y2fcn = interp1d(x2, y2) y2_on_x1 = y2fcn(x1) diff = y2_on_x1 - y1 from scipy.signal import savgol_filter diff = savgol_filter(diff, 21, 3) ax.plot(x1, diff) savefig(opts.output, suffix='_ability_diff') if pdfpages: pdfpages.__exit__(None, None, None) print('Write output figure to', pdfpagesfilename) savegraph(quench.histoffset.histedges.points_truncated, opts.graph, namespace=ns) if opts.show: P.show()
def main(opts): global savefig if opts.output and opts.output.endswith('.pdf'): pdfpages = PdfPages(opts.output) pdfpagesfilename=opts.output savefig_old=savefig pdf=pdfpages.__enter__() def savefig(*args, **kwargs): close = kwargs.pop('close', False) if opts.individual and args and args[0]: savefig_old(*args, **kwargs) pdf.savefig() if close: P.close() else: pdf = None pdfpagesfilename = '' pdfpages = None cfg = NestedDict( bundle = dict( name='energy_nonlinearity_birks_cherenkov', version='v01', nidx=[ ('r', 'reference', ['R1', 'R2']) ], major=[], ), stopping_power='data/data_juno/energy_model/2019_birks_cherenkov_v01/stoppingpower.txt', annihilation_electrons=dict( file='data/data_juno/energy_model/2019_birks_cherenkov_v01/hgamma2e.root', histogram='hgamma2e_1KeV', scale=1.0/50000 # events simulated ), pars = uncertaindict( [ ('birks.Kb0', (1.0, 'fixed')), ('birks.Kb1', (15.2e-3, 0.1776)), # ('birks.Kb2', (0.0, 'fixed')), ("cherenkov.E_0", (0.165, 'fixed')), ("cherenkov.p0", ( -7.26624e+00, 'fixed')), ("cherenkov.p1", ( 1.72463e+01, 'fixed')), ("cherenkov.p2", ( -2.18044e+01, 'fixed')), ("cherenkov.p3", ( 1.44731e+01, 'fixed')), ("cherenkov.p4", ( 3.22121e-02, 'fixed')), ("Npescint", (1341.38, 0.0059)), ("kC", (0.5, 0.4737)), ("normalizationEnergy", (11.9999999, 'fixed')) ], mode='relative' ), integration_order = 2, correlations_pars = [ 'birks.Kb1', 'Npescint', 'kC' ], correlations = [ 1.0, 0.94, -0.97, 0.94, 1.0, -0.985, -0.97, -0.985, 1.0 ], fill_matrix=True, labels = dict( normalizationEnergy = 'Pessimistic' ), ) ns = env.globalns('energy') quench = execute_bundle(cfg, namespace=ns) print() normE = ns['normalizationEnergy'].value() # # Input bins # evis_edges_full_input = N.arange(0.0, 15.0+1.e-6, 0.001) evis_edges_full_hist = C.Histogram(evis_edges_full_input, labels='Evis bin edges') evis_edges_full_hist >> quench.context.inputs.evis_edges_hist['00'] # # Python energy model interpolation function # lsnl_x = quench.histoffset.histedges.points_truncated.data() lsnl_y = quench.positron_model_relative.single().data() lsnl_fcn = interp1d(lsnl_x, lsnl_y, kind='quadratic', bounds_error=False, fill_value='extrapolate') # # Energy resolution # def eres_sigma_rel(edep): return 0.03/edep**0.5 def eres_sigma_abs(edep): return 0.03*edep**0.5 # # Oscprob # baselinename='L' ns = env.ns("oscprob") import gna.parameters.oscillation gna.parameters.oscillation.reqparameters(ns) ns.defparameter(baselinename, central=52.0, fixed=True, label='Baseline, km') # # Define energy range # data = Data(N.arange(1.8, 15.0, 0.001), lsnl_fcn=lsnl_fcn, eres_fcn=eres_sigma_abs) # Initialize oscillation variables enu = C.Points(data.enu, labels='Neutrino energy, MeV') component_names = C.stdvector(['comp0', 'comp12', 'comp13', 'comp23']) with ns: R.OscProbPMNSExpressions(R.Neutrino.ae(), R.Neutrino.ae(), component_names, ns=ns) labels=['Oscillation probability|%s'%s for s in ('component 12', 'component 13', 'component 23', 'full', 'probsum')] oscprob = R.OscProbPMNS(R.Neutrino.ae(), R.Neutrino.ae(), baselinename, labels=labels) enu >> oscprob.full_osc_prob.Enu enu >> (oscprob.comp12.Enu, oscprob.comp13.Enu, oscprob.comp23.Enu) unity = C.FillLike(1, labels='Unity') enu >> unity.fill.inputs[0] with ns: op_sum = C.WeightedSum(component_names, [unity.fill.outputs[0], oscprob.comp12.comp12, oscprob.comp13.comp13, oscprob.comp23.comp23], labels='Oscillation probability sum') oscprob.printtransformations() env.globalns.printparameters(labels=True) ns = env.globalns('oscprob') data.set_dm_par(ns['DeltaMSqEE']) data.set_nmo_par(ns['Alpha']) data.set_psur_fcn(op_sum.single().data) data.build() # # Plotting # xmax = 12.0 # # Positron non-linearity # fig = P.figure() ax = P.subplot(111, xlabel='Edep, MeV', ylabel='Evis/Edep', title='Positron energy nonlineairty') ax.minorticks_on(); ax.grid() quench.positron_model_relative.single().plot_vs(quench.histoffset.histedges.points_truncated, label='definition range') quench.positron_model_relative_full.plot_vs(quench.histoffset.histedges.points, '--', linewidth=1., label='full range', zorder=0.5) ax.vlines(normE, 0.0, 1.0, linestyle=':') ax.legend(loc='lower right') ax.set_ylim(0.8, 1.05) ax.set_xlim(0.0, xmax) savefig(opts.output, suffix='_total_relative', close=not opts.show_all) # # Positron non-linearity derivative # fig = P.figure() ax = P.subplot(111, xlabel='Edep, MeV', ylabel='dEvis/dEdep', title='Positron energy nonlineairty derivative') ax.minorticks_on(); ax.grid() e = quench.histoffset.histedges.points_truncated.single().data() f = quench.positron_model_relative.single().data()*e ec = (e[1:] + e[:-1])*0.5 df = (f[1:] - f[:-1]) dedf = (e[1:] - e[:-1])/df ax.plot(ec, dedf) ax.legend(loc='lower right') ax.set_ylim(0.975, 1.01) ax.set_xlim(0.0, xmax) savefig(opts.output, suffix='_total_derivative', close=not opts.show_all) # # Positron non-linearity effect # fig = P.figure() ax = P.subplot(111, xlabel='Edep, MeV', ylabel='Evis/Edep', title='Positron energy nonlineairty') ax.minorticks_on(); ax.grid() es = N.arange(1.0, 3.1, 0.5) esmod = es*lsnl_fcn(es) esmod_shifted = esmod*(es[-1]/esmod[-1]) ax.vlines(es, 0.0, 1.0, linestyle='--', linewidth=2, alpha=0.5, color='green', label='Edep') ax.vlines(esmod, 0.0, 1.0, linestyle='-', color='red', label='Edep quenched') ax.legend() savefig(opts.output, suffix='_quenching_effect_0') ax.vlines(esmod_shifted, 0.0, 1.0, linestyle=':', color='blue', label='Edep quenched, scaled') ax.legend() savefig(opts.output, suffix='_quenching_effect_1', close=not opts.show_all) # # Energy resolution # fig = P.figure() ax = P.subplot(111, xlabel='Edep, MeV', ylabel=r'$\sigma/E$', title='Energy resolution') ax.minorticks_on(); ax.grid() ax.plot(data.edep, eres_sigma_rel(data.edep), '-') ax.set_xlim(0.0, xmax) savefig(opts.output, suffix='_eres_rel', close=not opts.show_all) # # Energy resolution # fig = P.figure() ax = P.subplot(111, xlabel= 'Edep, MeV', ylabel= r'$\sigma$', title='Energy resolution') ax.minorticks_on(); ax.grid() ax.plot(data.edep, eres_sigma_abs(data.edep), '-') ax.set_xlim(0.0, xmax) savefig(opts.output, suffix='_eres_abs', close=not opts.show_all) # # Survival probability vs Enu # fig = P.figure() ax = P.subplot(111, xlabel='Enu, MeV', ylabel='Psur', title='Survival probability') ax.minorticks_on(); ax.grid() ax.plot(data.enu, data.data_no.psur[data.dmmid_idx], label=r'full NO') ax.plot(data.enu, data.data_io.psur[data.dmmid_idx], label=r'full IO') ax.plot(data.data_no.data_enu.psur_e[data.dmmid_idx], data.data_no.data_enu.psur[data.dmmid_idx], '^', markerfacecolor='none') ax.legend() ax.set_xlim(0.0, xmax) savefig(opts.output, suffix='_psur_enu') ax.set_xlim(2.0, 4.5) savefig(opts.output, suffix='_psur_enu_zoom', close=not opts.show_all) # # Survival probability vs Edep # fig = P.figure() ax = P.subplot(111, xlabel='Edep, MeV', ylabel='Psur', title='Survival probability') ax.minorticks_on(); ax.grid() ax.plot(data.edep, data.data_no.psur[data.dmmid_idx], label=r'full NO') ax.plot(data.edep, data.data_io.psur[data.dmmid_idx], label=r'full IO') ax.plot(data.data_no.data_edep.psur_e[data.dmmid_idx], data.data_no.data_edep.psur[data.dmmid_idx], '^', markerfacecolor='none') ax.legend() ax.set_xlim(0.0, xmax) savefig(opts.output, suffix='_psur_edep') ax.set_xlim(1.2, 3.7) savefig(opts.output, suffix='_psur_edep_zoom', close=not opts.show_all) # # Survival probability vs Edep_lsnl # fig = P.figure() ax = P.subplot(111, xlabel='Edep quenched, MeV', ylabel='Psur', title='Survival probability') ax.minorticks_on(); ax.grid() ax.plot(data.edep_lsnl, data.data_no.psur[data.dmmid_idx], label=r'full NO') ax.plot(data.edep_lsnl, data.data_io.psur[data.dmmid_idx], label=r'full IO') ax.plot(data.data_no.data_edep_lsnl.psur_e[data.dmmid_idx], data.data_no.data_edep_lsnl.psur[data.dmmid_idx], '^', markerfacecolor='none') ax.legend() ax.set_xlim(0.0, xmax) savefig(opts.output, suffix='_psur_edep_lsnl') ax.set_xlim(1.2, 3.7) savefig(opts.output, suffix='_psur_edep_lsnl_zoom', close=not opts.show_all) # # Distance between nearest peaks vs Enu, single # fig = P.figure() ax = P.subplot(111, xlabel='Enu, MeV', ylabel='Dist, MeV', title='Nearest peaks distance') ax.minorticks_on(); ax.grid() ax.plot(data.data_no.data_enu.diff_x[data.dmmid_idx], data.data_no.data_enu.diff[data.dmmid_idx], label=r'NO') ax.plot(data.data_io.data_enu.diff_x[data.dmmid_idx], data.data_io.data_enu.diff[data.dmmid_idx], label=r'IO') ax.legend() ax.set_xlim(0.0, xmax) ax.set_ylim(bottom=0.0) savefig(opts.output, suffix='_dist_enu') ax.set_xlim(2.0, 5.0) ax.set_ylim(top=0.5) savefig(opts.output, suffix='_dist_enu_zoom', close=not opts.show_all) # # Distance between nearest peaks vs Edep, single # fig = P.figure() ax = P.subplot(111, xlabel='Edep, MeV', ylabel='Dist, MeV', title='Nearest peaks distance') ax.minorticks_on(); ax.grid() ax.plot(data.data_no.data_edep.diff_x[data.dmmid_idx], data.data_no.data_edep.diff[data.dmmid_idx], label=r'NO') ax.plot(data.data_io.data_edep.diff_x[data.dmmid_idx], data.data_io.data_edep.diff[data.dmmid_idx], label=r'IO') ax.legend() ax.set_xlim(0.0, xmax) ax.set_ylim(bottom=0.0) savefig(opts.output, suffix='_dist_edep') ax.set_xlim(1.2, 4.2) ax.set_ylim(top=0.5) savefig(opts.output, suffix='_dist_edep_zoom', close=not opts.show_all) # # Distance between nearest peaks vs Edep, single # fig = P.figure() ax = P.subplot(111, xlabel='Edep quenched, MeV', ylabel='Dist, MeV', title='Nearest peaks distance') ax.minorticks_on(); ax.grid() ax.plot(data.data_no.data_edep_lsnl.diff_x[data.dmmid_idx], data.data_no.data_edep_lsnl.diff[data.dmmid_idx], label=r'NO') ax.plot(data.data_io.data_edep_lsnl.diff_x[data.dmmid_idx], data.data_io.data_edep_lsnl.diff[data.dmmid_idx], label=r'IO') ax.legend() ax.set_xlim(0.0, xmax) ax.set_ylim(bottom=0.0) savefig(opts.output, suffix='_dist_edep_lsnl') ax.set_xlim(1.2, 4.2) ax.set_ylim(top=0.5) savefig(opts.output, suffix='_dist_edep_lsnl_zoom') poly = N.polynomial.polynomial.Polynomial([0, 1, 0]) x = data.data_no.data_edep_lsnl.diff_x[data.dmmid_idx] pf = poly.fit(x, data.data_no.data_edep_lsnl.diff[data.dmmid_idx], 2) print(pf) ax.plot(x, pf(x), label=r'NO fit') ax.legend() savefig(opts.output, suffix='_dist_edep_lsnl_fit', close=not opts.show_all) # # Distance between nearest peaks vs Edep, multiple # fig = P.figure() ax = P.subplot(111, xlabel='Edep quenched, MeV', ylabel='Dist, MeV', title='Nearest peaks distance') ax.minorticks_on(); ax.grid() ax.plot(data.data_no.data_edep_lsnl.diff_x[data.dmmid_idx], data.data_no.data_edep_lsnl.diff[data.dmmid_idx], label=r'NO') ax.plot(data.data_io.data_edep_lsnl.diff_x[data.dmmid_idx], data.data_io.data_edep_lsnl.diff[data.dmmid_idx], '--', label=r'IO') for idx in (0, 5, 15, 20): ax.plot(data.data_io.data_edep_lsnl.diff_x[idx], data.data_io.data_edep_lsnl.diff[idx], '--') ax.legend() ax.set_xlim(0.0, xmax) savefig(opts.output, suffix='_dist_edep_lsnl_multi', close=not opts.show_all) # # Distance between nearest peaks difference # fig = P.figure() ax = P.subplot(111, xlabel='Edep, MeV', ylabel='Dist(IO) - Dist(NO), MeV', title='Nearest peaks distance diff: IO-NO') ax.minorticks_on(); ax.grid() ax.plot(data.e, data.diffs.edep[data.dmmid_idx], '-', markerfacecolor='none', label='Edep') ax.plot(data.e, data.diffs.edep_lsnl[data.dmmid_idx], '-', markerfacecolor='none', label='Edep quenched') ax.plot(data.e, data.diffs.enu[data.dmmid_idx], '-', markerfacecolor='none', label='Enu') ax.legend() savefig(opts.output, suffix='_dist_diff') ax.plot(data.e, data.eres, '-', markerfacecolor='none', label='Resolution $\\sigma$') ax.legend() savefig(opts.output, suffix='_dist_diff_1') # # Distance between nearest peaks difference relative to sigma # fig = P.figure() ax = P.subplot(111, xlabel='Edep, MeV', ylabel='(Dist(IO) - Dist(NO))/$\\sigma$', title='Nearest peaks distance diff: IO-NO') ax.minorticks_on(); ax.grid() ax.plot(data.e, data.diffs_rel.edep[data.dmmid_idx], '-', markerfacecolor='none', label='Edep') ax.plot(data.e, data.diffs_rel.edep_lsnl[data.dmmid_idx], '-', markerfacecolor='none', label='Edep quenched') i_edep=N.argmax(data.diffs_rel.edep[data.dmmid_idx]) i_edep_lsnl=N.argmax(data.diffs_rel.edep_lsnl[data.dmmid_idx]) ediff = data.e[i_edep] - data.e[i_edep_lsnl] ax.axvline(data.e[i_edep], linestyle='dashed', label='Max location: %.3f MeV'%(data.e[i_edep])) ax.axvline(data.e[i_edep_lsnl], linestyle='dashed', label='Max location: %.3f MeV'%(data.e[i_edep_lsnl])) ax.axvspan(data.e[i_edep], data.e[i_edep_lsnl], alpha=0.2, label='Max location diff: %.3f MeV'%(ediff)) ax.legend() savefig(opts.output, suffix='_dist_diff_rel') # # Distance between nearest peaks difference relative to sigma # fig = P.figure() ax = P.subplot(111, xlabel='Edep, MeV', ylabel='(Dist(IO) - Dist(NO))/$\\sigma$', title='Nearest peaks distance diff: IO-NO') ax.minorticks_on(); ax.grid() ledep = ax.plot(data.e, data.diffs_rel.edep[data.dmmid_idx], '--', markerfacecolor='none', label='Edep')[0] lquench = ax.plot(data.e, data.diffs_rel.edep_lsnl[data.dmmid_idx], '-', color=ledep.get_color(), markerfacecolor='none', label='Edep quenched')[0] kwargs=dict(alpha=0.8, linewidth=1.5, markerfacecolor='none') for idx in (0, 5, 15, 20): l = ax.plot(data.e, data.diffs_rel.edep[idx], '--', **kwargs)[0] ax.plot(data.e, data.diffs_rel.edep_lsnl[idx], '-', color=l.get_color(), **kwargs) ax.legend() savefig(opts.output, suffix='_dist_diff_rel_multi', close=not opts.show_all) # # Distance between nearest peaks difference relative to sigma # fig = P.figure() ax = P.subplot(111, ylabel=r'$\Delta m^2_\mathrm{ee}$', xlabel='Edep quenched, MeV', title='Nearest peaks distance diff: IO-NO/$\\sigma$') ax.minorticks_on(); ax.grid() formatter = ax.yaxis.get_major_formatter() formatter.set_useOffset(False) formatter.set_powerlimits((-2,2)) formatter.useMathText=True c = ax.pcolormesh(data.mesh_e.T, data.mesh_dm.T, data.diffs_rel.edep_lsnl.T) from mpl_tools.helpers import add_colorbar add_colorbar(c, rasterized=True) c.set_rasterized(True) savefig(opts.output, suffix='_dist_diff_rel_heatmap') if pdfpages: pdfpages.__exit__(None,None,None) print('Write output figure to', pdfpagesfilename) # savegraph(quench.histoffset.histedges.points_truncated, opts.graph, namespace=ns) if opts.show or opts.show_all: P.show()
pars=uncertaindict( [ ('SA.D1', 1.0), ('SB.D1', 2.0), ('SA.D2', 3.0), ('SB.D2', 4.0), ('SA.D3', 5.0), ('SB.D3', 6.0), ('SA.D4', 7.0), ('SB.D4', 8.0), ], uncertainty=1.0, mode='percent', ), ) b1 = execute_bundle(cfg1, namespace=env.globalns('bundle1')) env.globalns('bundle1').printparameters(labels=True) print() # # List of parameters 2 # cfg2 = NestedDict( bundle=dict(name='parameters', version='ex02', nidx=[('s', 'source', ['SA', 'SB']), ('d', 'detector', ['D1', 'D2', 'D3']), ('e', 'element', ['e0', 'e1'])], major=('s', 'd')), parameter='rate1', label='Flux normalization {source}->{detector} ({element})',
def main(opts): global savefig cfg = NestedDict( bundle = dict( name='energy_nonlinearity_birks_cherenkov', version='v01', nidx=[ ('r', 'reference', ['R1', 'R2']) ], major=[], ), stopping_power='stoppingpower.txt', annihilation_electrons=dict( file='input/hgamma2e.root', histogram='hgamma2e_1KeV', scale=1.0/50000 # event simulated ), pars = uncertaindict( [ ('birks.Kb0', (1.0, 'fixed')), ('birks.Kb1', (15.2e-3, 0.1776)), # ('birks.Kb2', (0.0, 'fixed')), ("cherenkov.E_0", (0.165, 'fixed')), ("cherenkov.p0", ( -7.26624e+00, 'fixed')), ("cherenkov.p1", ( 1.72463e+01, 'fixed')), ("cherenkov.p2", ( -2.18044e+01, 'fixed')), ("cherenkov.p3", ( 1.44731e+01, 'fixed')), ("cherenkov.p4", ( 3.22121e-02, 'fixed')), ("Npescint", (1341.38, 0.0059)), ("kC", (0.5, 0.4737)), ("normalizationEnergy", (2.505, 'fixed')) # ("normalizationEnergy", (12.0, 'fixed')) ], mode='relative' ), integration_order = 2, correlations_pars = [ 'birks.Kb1', 'Npescint', 'kC' ], correlations = [ 1.0, 0.94, -0.97, 0.94, 1.0, -0.985, -0.97, -0.985, 1.0 ], fill_matrix=True, labels = dict( normalizationEnergy = '60Co total gamma energy, MeV' # normalizationEnergy = 'Pessimistic norm point' ), ) ns = env.globalns('energy') quench = execute_bundle(cfg, namespace=ns) ns.printparameters(labels=True) print() normE = ns['normalizationEnergy'].value() # # Input bins # evis_edges_full_input = N.arange(0.0, 12.0+1.e-6, 0.025) evis_edges_full_hist = C.Histogram(evis_edges_full_input, labels='Evis bin edges') evis_edges_full_hist >> quench.context.inputs.evis_edges_hist['00'] # # HistNonLinearity transformation # reference_histogram1_input = N.zeros(evis_edges_full_input.size-1) reference_histogram2_input = reference_histogram1_input.copy() reference_histogram1_input+=1.0 # reference_histogram2_input[[10, 20, 50, 100, 200, 300, 400]]=1.0 reference_histogram2_input[[10, 20]]=1.0 reference_histogram1 = C.Histogram(evis_edges_full_input, reference_histogram1_input, labels='Reference hist 1') reference_histogram2 = C.Histogram(evis_edges_full_input, reference_histogram2_input, labels='Reference hist 2') reference_histogram1 >> quench.context.inputs.lsnl.R1.values() reference_histogram2 >> quench.context.inputs.lsnl.R2.values() reference_smeared1 = quench.context.outputs.lsnl.R1 reference_smeared2 = quench.context.outputs.lsnl.R2 # # Plots and tests # if opts.output and opts.output.endswith('.pdf'): pdfpages = PdfPages(opts.output) pdfpagesfilename=opts.output savefig_old=savefig pdf=pdfpages.__enter__() def savefig(*args, **kwargs): if opts.individual and args and args[0]: savefig_old(*args, **kwargs) pdf.savefig() else: pdf = None pdfpagesfilename = '' # # Plots and tests # fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'Edep, MeV' ) ax.set_ylabel( 'dE/dx' ) ax.set_title( 'Stopping power' ) quench.birks_quenching_p.points.points.plot_vs(quench.birks_e_p.points.points, '-', markerfacecolor='none', markersize=2.0, label='input') ax.legend(loc='upper right') savefig(opts.output, suffix='_spower') ax.set_xlim(left=0.001) ax.set_xscale('log') savefig(opts.output, suffix='_spower_log') fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'Edep, MeV' ) ax.set_ylabel( '' ) ax.set_title( "Birk's integrand" ) quench.birks_integrand_raw.polyratio.ratio.plot_vs(quench.birks_e_p.points.points, '-o', alpha=0.5, markerfacecolor='none', markersize=2.0, label='raw') # birks_integrand_interpolated.plot_vs(integrator_ekin.points.x, '-', alpha=0.5, markerfacecolor='none', markersize=2.0, label='interpolated') lines=quench.birks_integrand_interpolated.plot_vs(quench.integrator_ekin.points.x, '-', alpha=0.5, markerfacecolor='none', markersize=2.0, label='interpolated') quench.birks_integrand_interpolated.plot_vs(quench.integrator_ekin.points.x, 'o', alpha=0.5, color='black', markersize=0.6) ax.legend(loc='lower right') savefig() ax.set_xlim(left=0.0001) ax.set_ylim(bottom=0.3) # ax.set_yscale('log') ax.set_xscale('log') savefig(opts.output, suffix='_spower_int') fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'Edep, MeV' ) ax.set_ylabel( '' ) ax.set_title( "Birk's integral (bin by bin)" ) quench.birks_integral.plot_hist() savefig() ax.set_xlim(left=0.0001) ax.set_ylim(bottom=0.0) # ax.set_yscale('log') ax.set_xscale('log') ax.set_ylim(auto=True) savefig(opts.output, suffix='_spower_intc') fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'Edep, MeV' ) ax.set_ylabel( 'Evis, MeV' ) ax.set_title( 'Electron energy (Birks)' ) # birks_accumulator.reduction.out.plot_vs(integrator_evis.transformations.hist, '-', markerfacecolor='none', markersize=2.0, label='partial sum') quench.birks_accumulator.reduction.plot_vs(quench.histoffset.histedges.points_offset) ax.plot([0.0, 12.0], [0.0, 12.0], '--', alpha=0.5) savefig(opts.output, suffix='_birks_evis') fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'Edep, MeV' ) ax.set_ylabel( 'Evis/Edep' ) ax.set_title( 'Electron energy (Birks)' ) # birks_accumulator.reduction.out.plot_vs(integrator_evis.transformations.hist, '-', markerfacecolor='none', markersize=2.0, label='partial sum') quench.histoffset.histedges.points_offset.vs_plot(quench.birks_accumulator.reduction.data()/quench.histoffset.histedges.points_offset.data()) ax.set_ylim(0.40, 1.0) savefig(opts.output, suffix='_birks_evis_rel') ax.set_xlim(1.e-3, 2.0) ax.set_xscale('log') savefig() fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'E, MeV' ) ax.set_ylabel( 'Npe' ) ax.set_title( 'Cherenkov photons' ) quench.cherenkov.cherenkov.ch_npe.plot_vs(quench.histoffset.histedges.points_offset) savefig(opts.output, suffix='_cherenkov_npe') ax.set_ylim(bottom=0.1) ax.set_yscale('log') savefig() ax.set_xlim(0.0, 2.0) # ax.set_ylim(0.0, 200.0) savefig() fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'E, MeV' ) ax.set_ylabel( 'Npe' ) ax.set_title( 'Electron model' ) quench.electron_model.single().plot_vs(quench.histoffset.histedges.points_offset) savefig(opts.output, suffix='_electron') fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'E, MeV' ) ax.set_ylabel( 'Npe' ) ax.set_title( 'Electron model (low energy view)' ) annihilation_gamma_evis = quench.npe_positron_offset.normconvolution.result.data()[0] label = 'Annihilation contribution=%.2f Npe'%annihilation_gamma_evis quench.electron_model_lowe.plot_vs(quench.ekin_edges_lowe, 'o', markerfacecolor='none', label='data') quench.electron_model_lowe_interpolated.single().plot_vs(quench.annihilation_electrons_centers.single(), '-', label='interpolation\n%s'%label) ax.legend(loc='upper left') savefig(opts.output, suffix='_electron_lowe') fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'E, MeV' ) ax.set_ylabel( 'Npe' ) ax.set_title( 'Total Npe' ) quench.positron_model.sum.outputs[0].plot_vs(quench.histoffset.histedges.points_truncated) savefig(opts.output, suffix='_total_npe') fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'Edep, MeV' ) ax.set_ylabel( 'Evis, MeV' ) ax.set_title( 'Positron energy model' ) quench.positron_model_scaled.plot_vs(quench.histoffset.histedges.points_truncated, label='definition range') quench.positron_model_scaled_full.plot_vs(quench.histoffset.histedges.points, '--', linewidth=1., label='full range', zorder=0.5) ax.vlines(normE, 0.0, normE, linestyle=':') ax.hlines(normE, 0.0, normE, linestyle=':') ax.legend(loc='upper left') savefig(opts.output, suffix='_total') fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'Edep, MeV' ) ax.set_ylabel( 'Evis/Edep' ) ax.set_title( 'Positron energy nonlineairty' ) quench.positron_model_relative.single().plot_vs(quench.histoffset.histedges.points_truncated, label='definition range') quench.positron_model_relative_full.plot_vs(quench.histoffset.histedges.points, '--', linewidth=1., label='full range', zorder=0.5) ax.vlines(normE, 0.0, 1.0, linestyle=':') ax.legend(loc='lower right') ax.set_ylim(0.85, 1.1) savefig(opts.output, suffix='_total_relative') ax.set_xlim(0.75, 3) savefig(opts.output, suffix='_total_relative1') fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel('Etrue, MeV') ax.set_ylabel('Edep, MeV') ax.set_title( 'Smearing matrix' ) quench.pm_histsmear.matrix.FakeMatrix.plot_matshow(mask=0.0, extent=[evis_edges_full_input.min(), evis_edges_full_input.max(), evis_edges_full_input.max(), evis_edges_full_input.min()], colorbar=True) ax.plot([0.0, 12.0], [0.0, 12.0], '--', alpha=0.5, linewidth=1.0, color='magenta') ax.vlines(normE, 0.0, normE, linestyle=':') ax.hlines(normE, 0.0, normE, linestyle=':') savefig(opts.output, suffix='_matrix') ax.set_xlim(0.8, 3.0) ax.set_ylim(3.0, 0.8) savefig(opts.output, suffix='_matrix_zoom') fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'E, MeV' ) ax.set_ylabel( '' ) ax.set_title( 'Reference histogram 1' ) reference_histogram1.single().plot_hist(linewidth=0.5, alpha=1.0, label='original') reference_smeared1.single().plot_hist( linewidth=0.5, alpha=1.0, label='smeared') ax.legend(loc='upper right') savefig(opts.output, suffix='_refsmear1') fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'E, MeV' ) ax.set_ylabel( '' ) ax.set_title( 'Matrix projections' ) mat = quench.pm_histsmear.matrix.FakeMatrix.data() proj0 = mat.sum(axis=0) proj1 = mat.sum(axis=1) plot_hist(evis_edges_full_input, proj0, alpha=0.7, linewidth=1.0, label='Projection 0: Edep view') plot_hist(evis_edges_full_input, proj1, alpha=0.7, linewidth=1.0, label='Projection 1: Evis') ax.legend(loc='upper right') savefig(opts.output, suffix='_matrix_projections') if opts.mapping: fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'E, MeV' ) ax.set_ylabel( '' ) ax.set_title( 'Mapping' ) positron_model_scaled_data = quench.positron_model_scaled.single().data() for e1, e2 in zip(quench.histoffset.histedges.points_truncated.data(), positron_model_scaled_data): if e2>12.0 or e2<1.022: alpha = 0.05 else: alpha = 0.7 ax.plot( [e1, e2], [1.0, 0.0], '-', linewidth=2.0, alpha=alpha ) ax.axvline(1.022, linestyle='--', linewidth=1.0) ax.axvline(12.0, linestyle='--', linewidth=1.0) fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() # ax.grid() ax.set_xlabel( 'E, MeV' ) ax.set_ylabel( '' ) ax.set_title( 'Mapping' ) positron_model_scaled_data = quench.positron_model_scaled.single().data() for e1, e2 in zip(quench.histoffset.histedges.points_truncated.data(), positron_model_scaled_data): if e2>12.0 or e2<1.022: alpha = 0.05 else: alpha = 0.7 ax.plot( [e1, e2], [1.1, 0.9], '-', linewidth=2.0, alpha=alpha ) for e1 in quench.histoffset.histedges.points.data(): ax.axvline(e1, linestyle=':', linewidth=1.0, color='black') ax.axvline(1.022, linestyle='--', linewidth=1.0) ax.axvline(12.0, linestyle='--', linewidth=1.0) # ax.legend(loc='upper right') savefig(opts.output, suffix='_mapping_bins') fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'E, MeV' ) ax.set_ylabel( '' ) ax.set_title( 'Reference histogram 2' ) reference_histogram2.single().plot_hist(linewidth=0.5, alpha=1.0, label='original') reference_smeared2.single().plot_hist( linewidth=0.5, alpha=1.0, label='smeared') ax.vlines(normE, 0.0, 1.0, linestyle=':') ax.legend(loc='upper right') savefig(opts.output, suffix='_refsmear2') fig = P.figure() ax = P.subplot( 111 ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'E, MeV' ) ax.set_ylabel( 'Entries' ) ax.set_title( 'Annihilation gamma electrons' ) plot_hist(quench.annihilation_electrons_edges_input, quench.annihilation_electrons_p_input) ax.set_yscale('log') savefig(opts.output, suffix='_annihilation_electrons') ax.set_yscale('linear') ax.set_xlim(0.0, 0.1) savefig(opts.output, suffix='_annihilation_electrons_lin') if pdfpages: pdfpages.__exit__(None,None,None) print('Write output figure to', pdfpagesfilename) savegraph(quench.histoffset.histedges.points_truncated, opts.graph, namespace=ns) if opts.show: P.show()