コード例 #1
0
def get_neutrino_flux_model(model):
    flux = None
    if model in nuflux_models:
        flux = nuflux.makeFlux(model)
    elif model in custom_nu_models.keys():
        flux = custom_nu_models[model]
    else:
        raise NotImplementedError(
            'Flux model {} is not implemented'.format(model))
    return flux
コード例 #2
0
ファイル: test_fluxes.py プロジェクト: austinschneider/nuflux
    def compare_fluxes(self, data, energies):
        self.N = 0

        coszeniths = [-1, -.5, 0, .5, 1]
        for model, x in data.items():
            flux = nuflux.makeFlux(model)
            for knee, y in x.items():
                flux.knee_reweighting_model = knee
                print("testing ", model, knee)
                for nu, z in y.items():
                    particle = nuflux.ParticleType.names[nu]
                    for i, cz in enumerate(coszeniths):
                        for j, E in enumerate(energies):
                            self.compare(z[i][j],
                                         flux.getFlux(particle, E, cz))

        print("{} passed comparisons".format(self.N))
コード例 #3
0
ファイル: test_weighter.py プロジェクト: icecube/simweights
    def test_nuflux(self):
        try:
            import nuflux
        except ImportError:
            self.skipTest("nuflux not found")

        N1 = 15
        data1 = dict(
            I3Weight=dict(
                type=np.full(N1, 14),
                energy=np.linspace(5e5, 5e6, N1),
                zenith=np.full(N1, np.pi / 4),
            )
        )
        s1 = N1 * generation_surface(14, self.p1, self.c1)
        weighter1 = Weighter([(data1, self.m1)], s1)

        honda = nuflux.makeFlux("honda2006")
        w = weighter1.get_weights(honda)
        fluxval = honda.getFlux(14, data1["I3Weight"]["energy"], np.cos(data1["I3Weight"]["zenith"]))
        oneweight = weighter1.get_weights(1)
        np.testing.assert_allclose(w, fluxval * oneweight)
        self.assertEqual(float(weighter1.tostring(honda).split("*")[0].strip()), N1)
コード例 #4
0
    def compare_fluxes(self, data, energies):
        coszeniths = [-1, -.5, 0, .5, 1]
        E, cz = np.meshgrid(energies, coszeniths)

        for model, x in data.items():
            flux = nuflux.makeFlux(model)
            emin, emax = flux.energy_range
            geomE = (emin * emax)**.5
            for knee, y in x.items():
                flux.knee_reweighting_model = knee
                print("testing ", model, knee)
                for nu_str, nu in nuflux.ParticleType.names.items():
                    with self.subTest(model=model, knee=knee, nu=nu_str):
                        if nu_str in y:
                            np.testing.assert_allclose(y[nu_str],
                                                       flux.getFlux(nu, E, cz),
                                                       rtol=1e-13)
                        else:
                            np.testing.assert_array_equal(
                                0, flux.getFlux(nu, E, cz))
                        self.assertEqual(
                            flux.getFlux(nu, np.nextafter(emin, -np.inf), 0),
                            0)
                        self.assertEqual(
                            flux.getFlux(nu, np.nextafter(emax, +np.inf), 0),
                            0)
                        self.assertEqual(
                            flux.getFlux(nu, geomE, -1.0000000000000002), 0)
                        self.assertEqual(
                            flux.getFlux(nu, geomE, +1.0000000000000002), 0)
                for nu in [11, 13, 15, 17, 22, 2212, 1000260560]:
                    with self.subTest(model=model, knee=knee, nu=nu_str):
                        with self.assertRaises(Exception):
                            flux.getFlux(nu, geomE, 0)
                        with self.assertRaises(Exception):
                            flux.getFlux(-nu, geomE, 0)
コード例 #5
0
parser.add_argument("-f", type=str, nargs='+',
	dest="input_files", required=True,
	help="paths to input files (absolute or relative)")
args = parser.parse_args()
files = args.input_files

primary_energy = np.asarray([])
weights = np.asarray([])

# weighter = None

def power_law(energy):
	# https://pos.sissa.it/301/1005/pdf
	return 1.01e-18 * np.power(energy/1e5,-2.19)

cr_model = nuflux.makeFlux('H3a_SIBYLL23C')

for file in files:
	file_in = pd.HDFStore(file, 'r')
	loc_weighter = simweights.NuGenWeighter(file_in, nfiles=10)

	# if weighter is None:
	# 	weighter = loc_weighter
	# else:
	# 	weighter += loc_weighter
	
	local_primary_energy = loc_weighter.get_column('PolyplopiaPrimary', 'energy')
	# local_weights = loc_weighter.get_weights(power_law)
	local_weights = loc_weighter.get_weights(cr_model)
	
	primary_energy = np.concatenate((primary_energy, local_primary_energy))
コード例 #6
0
    ("sub_run_id", np.uint32),
    ("event_id", np.uint32),
    ("sub_event_id", np.uint32),
])

event_dtype = np.dtype([
    ('id', id_dtype),
    ("energy", np.float32),
    ("qtot", np.float32),
    ("ptype", np.uint32),
    #        ("weight_c", np.float32),
    ("weight_p", np.float32),
])

#flux_conv=nuflux.makeFlux('honda2006').getFlux
flux_prompt = nuflux.makeFlux('BERSS_H3p_central').getFlux
#flux_conv=nuflux.makeFlux('H3a_SIBYLL23C').getFlux
#flux_prompt = nuflux.makeFlux('H3a_SIBYLL21').getFlux
weight_name = 'weight'
#weight_name = 'weight_dict'
events = []
count = 0
for file_name in f:
    print(file_name)
    try:
        x = np.load(file_name, mmap_mode="r")['arr_0']
    except Exception:
        print(file_name)
        pass

    for e in x:
コード例 #7
0
                    get_most_energetic_muon(frame["MMCTrackList"]))
                for k in weight_keys:
                    I3MCWeightDict[k].append(frame["I3MCWeightDict"][k])

nfiles = len(filelist)
wobj = simweights.NuGenWeighter({"I3MCWeightDict": I3MCWeightDict},
                                nfiles=nfiles)

# check that what we got matches what is in OneWeight
np.testing.assert_allclose(
    wobj.get_weights(1),
    np.array(I3MCWeightDict["OneWeight"]) /
    (0.5 * I3MCWeightDict["NEvents"][0] * nfiles),
)

conventional = nuflux.makeFlux("honda2006")
conventional.knee_reweighting_model = "gaisserH3a_elbert"
weights_simweights = wobj.get_weights(conventional)

erange = wobj.surface.get_energy_range(None)
czrange = wobj.surface.get_cos_zenith_range(None)
print(wobj.surface)
print("Number of files  : {:8d}".format(nfiles))
print("Number of Events : {:8d}".format(weights_simweights.size))
print("Effective Area   : {:8.6g} m²".format(
    wobj.effective_area(erange, czrange)[0][0]))
print("Event Rate       : {:8.6g} Hz".format(weights_simweights.sum()))
print("Livetime         : {:8.6g} s".format(weights_simweights.sum() /
                                            (weights_simweights**2).sum()))

fig, ax = plt.subplots(figsize=(12, 6))
コード例 #8
0
bins = plt.geomspace(1e2, 1e8, 50)
primary_energy = weighter.get_column("PolyplopiaPrimary", "energy")


# create an function to represent the IceCube northern track limit
# Note that the units are GeV^-1 * cm^-2 * sr^-1 * s^-1 per particle type
def NorthernTrack(energy):
    return 1.44e-18 / 2 * (energy / 1e5)**-2.2


NorthernTrack.name = "Northern Track 9.5 year"

# Create models and put them in a list so we can iterate over them
models = [
    NorthernTrack,
    nuflux.makeFlux("CORSIKA_GaisserH3a_average"),
    nuflux.makeFlux("H3a_SIBYLL23C"),
    nuflux.makeFlux("honda2006"),
    nuflux.makeFlux("BERSS_H3p_central"),
    nuflux.makeFlux("sarcevic_std"),
]

for flux_model in models:
    # get the weights by passing the flux to the weighter
    weights = weighter.get_weights(flux_model)

    # print the total rate of each model
    print("{:26} {:8.2f} mHz".format(flux_model.name, 1e6 * weights.sum()))

    # histogram the primary energy with the weights
    plt.hist(primary_energy,
コード例 #9
0
import simweights, nuflux, pandas

simfile = pandas.HDFStore('genie_reader_NuE_C_corr.hdf5')
flux_model = nuflux.makeFlux('IPhonda2014_spl_solmax')
weight_obj = simweights.GenieWeighter(simfile)
weights = weight_obj.get_weights(flux_model)
print('Rate', weights.sum(), 'Hz')
コード例 #10
0
    ("BERSS_H3p_central", 'C4', '-'),
    ("BERSS_H3p_upper", 'C4', '-.'),
    ("BERSS_H3p_lower", 'C4', '--'),
    ("sarcevic_std", 'C5', '-'),
    ("sarcevic_max", 'C5', '-.'),
    ("sarcevic_min", 'C5', '--'),
    ("H3a_SIBYLL21", 'C6', '-'),
    ("H3a_SIBYLL23C", 'C6', '--'),
]

gamma = 3
fig = plt.figure(figsize=[9.6, 4.8])
ax = plt.subplot(111)

for model, color, line in models:
    flux = nuflux.makeFlux(model)
    erange = flux.energy_range

    nu_type = nuflux.NuMu
    nu_cos_zenith = 0
    nu_energy = np.geomspace(erange[0], min(1e9, erange[1]), 100)

    fluxvalues = flux.getFlux(nu_type, nu_energy, nu_cos_zenith)

    ax.plot(nu_energy,
            nu_energy**gamma * fluxvalues,
            label=model,
            color=color,
            ls=line)

ax.set_ylim(1e-6, 1e-1)