Exemplo n.º 1
0
    def build_bundle(self, cfg):
        printl_debug('build bundle', cfg.bundle)

        from gna.bundle import execute_bundles
        with nextlevel():
            b = execute_bundles(cfg=cfg, context=self)

        self.executed_bundles.append(b)
Exemplo n.º 2
0
def test_offeq_correction(tmp_path):
    """ Test implementation of off-equilibrium contribution to antineutrino  spectra
    from nuclear fission in commercial reactors. The reason that contribution
    appears is the fact the electron conversion spectra measured at ILL doesn't
    take into account long-lived isotopes. That correction is required for
    precision measurement of oscillation parameters and is uncorrelated
    between reactors. It comes in a form of ratio of true spectra to nominal
    Huber-Mueller.
    """

    _enu = np.linspace(1., 8.0, 500, dtype='d')
    Enu = C.Points(_enu, labels='anue energy')

    indices = [('i', 'isotope', ['U235', 'U238', 'Pu239', 'Pu241']),
               ('r', 'reactor', ['DB1', 'DB2', 'LA1', 'LA2', 'LA3', 'LA4'])]

    cfg = NestedDict(
        bundle=dict(name='reactor_offeq_spectra', version='v03', nidx=indices),
        offeq_data=
        './data/reactor_anu_spectra/Mueller/offeq/mueller_offequilibrium_corr_{isotope}.dat',
    )
    ns = env.globalns('offeq')

    offeq, = execute_bundles(cfg, namespace=ns)
    ns.printparameters(labels=True)

    for iso in offeq.context.inputs.offeq_correction.values():
        try:
            for _input in iso.values():
                Enu >> _input.values()
        except AttributeError:
            Enu >> iso

    fig, ax = plt.subplots()
    for iso in indices[0][2]:
        corrected_spectra = offeq.context.outputs.offeq_correction[iso][
            'DB1'].data()
        ax.plot(Enu.single().data(), corrected_spectra - 1., label=iso)
    ax.set_title("Offequilibrium correction")
    ax.grid()
    ax.legend(loc='best')
    ax.set_xlabel("Antineutrino energy, MeV")
    ax.set_ylabel("(Corrected - nominal) / nominal")

    suffix = 'correction'
    path = os.path.join(str(tmp_path), suffix + '.png')
    savefig(path, dpi=300)
    savefig(path.replace('.png', '.pdf'), dpi=300)
    allure_attach_file(path)

    path = os.path.join(str(tmp_path), suffix + '_graph.png')
    savegraph(offeq.context.outputs.offeq_correction['U235']['DB1'], path)
    allure_attach_file(path)
Exemplo n.º 3
0
def test_geoneutrino_spectrum_v01(tmp_path):
    _enu = np.arange(1., 8.0+1.e-6, 0.01, dtype='d')
    Enu = C.Points(_enu, labels='anue energy')

    cfg = NestedDict(
                bundle = dict(name='geoneutrino_spectrum', version='v01'),
                data   = 'data/data-common/geo-neutrino/2006-sanshiro/geoneutrino-luminosity_{isotope}_truncated.knt'
            )
    ns = env.globalns('geonu')

    geonu, = execute_bundles(cfg, namespace=ns)
    ns.printparameters(labels=True)

    Enu >> geonu.context.inputs.values(nested=True)

    # Dump some info
    print(geonu.context.inputs)
    print(geonu.context.outputs)
    geonu.interp.values()[0].printtransformations()
    geonu.interp.values()[1].printtransformations()

    # Plot figures and graphs
    fig = plt.figure()
    ax = plt.subplot(111, xlabel=r'$E_{\nu}$, MeV', ylabel='N/MeV/s', title='Geo-neutrino luminosity (truncated at 1.7 MeV)')
    ax.minorticks_on()
    ax.grid()

    for k, v in geonu.context.outputs.items():
        ax.plot(_enu, v.data(), label=k)

    ax.legend()
    plt.show()

    savefig(os.path.join(str(tmp_path), '_spectra.png'))
    savegraph(Enu, os.path.join(str(tmp_path), '_graph.png'))

    ns.printparameters(labels=True)
Exemplo n.º 4
0
Arquivo: iav_2.py Projeto: gnafit/gna
parser.add_argument('-s',
                    '--show',
                    action='store_true',
                    help='show the figure')
args = parser.parse_args()

#
# Initialize bundle
#
cfg = NestedDict(bundle='detector_iav_db_root_v01',
                 parname='OffdiagScale.{}',
                 scale=uncertain(1.0, 4, 'percent'),
                 ndiag=1,
                 filename='data/dayabay/tmp/detector_iavMatrix_P14A_LS.root',
                 matrixname='iav_matrix')
b, = execute_bundles(cfg=cfg, namespaces=['AD1', 'AD2', 'AD3'])
(smear1, smear2, smear3) = b.transformations_out.values()

env.globalns.printparameters(labels=True)

par1, par2, par3 = (b.common_namespace('OffdiagScale')[s]
                    for s in ('AD1', 'AD2', 'AD3'))
par1.set(1.5)
par2.set(1.0)
par3.set(0.5)


#
# Test bundle
#
def singularities(values, edges):
Exemplo n.º 5
0
    # Bundle name
    bundle=dict(
        name='reactor_baselines',
        version='v01',
        nidx=indices,
        major='rd'  # first for reactor, second for detector
    ),
    # Reactor positions
    reactors=reactors,
    # Detector positions
    detectors=detectors,
    # SNF pools,
    snf_pools=snf_pools,
    unit="meter")
#
# Initialize bundle
#

if args.make_idx:
    cfg_idx = NestedDict(baselines=cfg)
    context = ExpressionContext(cfg_idx, ns=env.globalns)
    a.build(context)
else:
    b, = execute_bundles(cfg=cfg)

env.globalns.printparameters(labels=True)

#
# Test bundle
#
Exemplo n.º 6
0
#
nbins = 240
edges = N.linspace(0.0, 12.0, nbins+1, dtype='d')
points = C.Points(edges)

hists_list = ()
for eset in ( (1.025, 6.025), (2.025, 7.025), (3.025, 8.025) ):
    heights = unit_bins_at( eset, edges )
    hist = C.Histogram( edges, heights )
    hists_list += hist,

#
# Define the chain
#
shared = NestedDict( edges=points.single() )
b, = execute_bundles(cfg=cfg.detector, namespaces=namespaces, shared=shared)

print('Parameters:')
env.globalns.printparameters(labels=True)

#
# Connect inputs
#
for inp, hist in zip(b.inputs.values(), hists_list):
    inp( hist.hist )

print('\nObservables:')
env.globalns.printobservables()

#
# Dump graph
Exemplo n.º 7
0
Arquivo: dummy.py Projeto: gnafit/gna
#!/usr/bin/env python

from load import ROOT as R
R.GNAObject
from gna.bundle import execute_bundles
from gna.env import env
from gna.configurator import NestedDict, uncertain
from collections import OrderedDict

cfg = NestedDict(bundle='dummy',
                 name='dymmubundle',
                 indices=[('n', 'num', ['1', '2', '3']),
                          ('a', 'alph', ['a', 'b', 'c']),
                          ('z', 'zyx', ['X', 'Y', 'Z'])],
                 format='var.{num}.{alph}.{zyx}',
                 input=True,
                 size=10,
                 debug=True)

ns = env.globalns
shared = NestedDict()
b, = execute_bundles(common_namespace=ns, cfg=cfg, shared=shared)

print(shared)
Exemplo n.º 8
0
            name = 'hist_{group}_{det}'.format( group=gr, det=det )
            h = R.TH1D(name, name, 10, 0, 10 )
            h.SetBinContent( it_det, 1 ); it_det+=1
            file.WriteTObject( h )

    print('Generated file contents')
    file.ls()
    file.Close()

make_sample_file( cfg.filename )

ns = env.globalns('testexp')
for det in cfg.detectors:
    detns = ns(det).reqparameter('livetime', central=10, sigma=0.1, fixed=True)

b, = execute_bundles( cfg=bkg, common_namespace=ns )
bfn, = execute_bundles( cfg=bkg.bkg_fn, common_namespace=ns )

print( 'Parameters:' )
env.globalns.printparameters(labels=True)

print( 'Observables:' )
env.globalns.printobservables()

if opts.set:
    for name, value in opts.set:
        value = float(value)
        print( 'Set', name, value )
        var = findname( ns.pathto(name), ns )
        var.set( value )
Exemplo n.º 9
0
    indices = N.digitize(values, edges) - 1
    phist = N.zeros(edges.size - 1)
    phist[indices] = 1.0
    return phist


nbins = 240
edges = N.linspace(0.0, 12.0, nbins + 1, dtype='d')
points = C.Points(edges)
phist = singularities([1.225, 2.225, 4.025, 7.025, 9.025], edges)
hist = C.Histogram(edges, phist)

#
# Initialize bundle
#
b, = execute_bundles(edges=points.single(), cfg=cfg, namespaces=['ad1', 'ad2'])
pars = [p for k, p in b.common_namespace.items() if k.startswith('weight')]
escale1, escale2 = (b.common_namespace('escale')[ns] for ns in ['ad1', 'ad2'])

(nonlin1, nonlin2) = b.objects['nonlinearity'].values()
factor1, factor2 = b.objects['factor'].values()

factor_nominal = factor1.data().copy()
escale1.set(0.98)
escale2.set(1.02)

#
# Plot curves:
#
fig = P.figure()
ax = P.subplot(111)