From a14a719df92230d88ed67445ac6a13a9921103d5 Mon Sep 17 00:00:00 2001 From: mjlarson Date: Thu, 29 Aug 2024 14:18:41 -0500 Subject: [PATCH] Test the volscale line, even if we're only assuming a volume scale of 1.0. --- tests/test_genie_weighter.py | 75 ++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/tests/test_genie_weighter.py b/tests/test_genie_weighter.py index 49cf716..48669c5 100755 --- a/tests/test_genie_weighter.py +++ b/tests/test_genie_weighter.py @@ -33,42 +33,49 @@ def test_genie(self): c1 = simweights.CircleInjector(300, 0, 1) p1 = simweights.PowerLaw(0, 1e3, 1e4) - weight = np.zeros(nevents, dtype=result_dtype) - weight["neu"] = pdgid - weight["pzv"] = coszen - weight["Ev"] = p1.ppf(np.linspace(0, 1, nevents)) - for event_weight in [1e-6, 1e-3, 1]: - weight["wght"] = event_weight - for nfiles in [1, 5, 50]: - rows = nfiles * [ - ( - pdgid, - nevents, - 1, - c1.radius, - np.arccos(c1.cos_zen_max), - np.arccos(c1.cos_zen_min), - p1.a, - p1.b, - p1.g, - ), - ] - info = np.array(rows, dtype=info_dtype) - d = {"I3GenieResult": weight, "I3GenieInfo": info} - - for flux in [0.1, 1, 10]: - wobj = simweights.GenieWeighter(d) - w = wobj.get_weights(flux) - np.testing.assert_allclose( - w.sum(), - flux * event_weight * c1.etendue * p1.integral / nfiles, - ) - E = d["I3GenieResult"]["Ev"] - y, x = np.histogram(E, weights=w, bins=51, range=[p1.a, p1.b]) - Ewidth = np.ediff1d(x) - np.testing.assert_allclose(y, flux * event_weight * Ewidth * c1.etendue / nfiles, 5e-3) + for include_volscale in [True, False]: + result_dtype = [("neu", np.int32), ("pzv", np.float64), ("Ev", np.float64), ("wght", np.float64)] + if include_volscale: + result_dtype.append(("volscale", np.float64)) + + weight = np.zeros(nevents, dtype=result_dtype) + weight["neu"] = pdgid + weight["pzv"] = coszen + weight["Ev"] = p1.ppf(np.linspace(0, 1, nevents)) + weight["wght"] = event_weight + + if include_volscale: + weight["volscale"] = 1 + + rows = nfiles * [ + ( + pdgid, + nevents, + 1, + c1.radius, + np.arccos(c1.cos_zen_max), + np.arccos(c1.cos_zen_min), + p1.a, + p1.b, + p1.g, + ), + ] + info = np.array(rows, dtype=info_dtype) + d = {"I3GenieResult": weight, "I3GenieInfo": info} + + for flux in [0.1, 1, 10]: + wobj = simweights.GenieWeighter(d) + w = wobj.get_weights(flux) + np.testing.assert_allclose( + w.sum(), + flux * event_weight * c1.etendue * p1.integral / nfiles, + ) + E = d["I3GenieResult"]["Ev"] + y, x = np.histogram(E, weights=w, bins=51, range=[p1.a, p1.b]) + Ewidth = np.ediff1d(x) + np.testing.assert_allclose(y, flux * event_weight * Ewidth * c1.etendue / nfiles, 5e-3) with self.assertRaises(TypeError): simweights.GenieWeighter(d, nfiles=10)