Adding Additional Parameters to Fluxes
By default simweights makes PDGID, energy, and zenith available to flux models
passed to simweights.Weighter.get_weights()
. Normally that is all you need for most models.
But if you have a more complex model that depends on additional parameters you
can add them with simweights.Weighter.add_weight_column()
.
In the example below, azimuth angle from PolyplopiaPrimary
is added to
so that a model with azimuth angle can be applied. In this case the data was
taken from the same data table but in principle it could be from any source
as long as it is a numpy array of the correct shape.
import simweights
# load the hdf5 file and make the weigher
hdffile = pd.HDFStore("Level2_IC86.2016_NuMu.021217.N100.hdf5", "r")
weighter = simweights.NuGenWeighter(hdffile, nfiles=100)
# add a non-standard weighting column
weighter.add_weight_column("azimuth", weighter.get_column("PolyplopiaPrimary", "azimuth"))
def simple_model(energy: ArrayLike) -> ArrayLike:
"""This function only depends on energy can be used as a flux models
Note that the units are GeV^-1 * cm^-2 * sr^-1 * s^-1 per particle type.
"""
return 1e-8 * energy**-2
def azimuthal_model(energy: ArrayLike, azimuth: ArrayLike) -> ArrayLike:
"""This function that takes azimuth as a parameter. get_weights() will use the name
of the function parameter to know which weighting column to access.
"""
return 1e-8 * plt.cos(azimuth) ** 2 * energy**-2
for flux_function in (simple_model, azimuthal_model):
# get the weights by passing the flux function to the weighter
weights = weighter.get_weights(flux_function)
# We can access our recently created weight column with get_weight_column()
azi = weighter.get_weight_column("azimuth")
# histogram the primary energy with the weights
plt.hist(azi, weights=weights, bins=50, histtype="step", label=flux_function.__name__)