Package: simweights
SimWeightsPure python library for calculating the weights of Monte Carlo simulation for IceCube.SimWeights was designed with goal of calculating weights for IceCube simulation in a way that it
is easy to combine combine datasets with different generation parameters into a single sample.
It was also designed to be a stand alone project which does not depend on IceTray in any way so that it can
be installed easily on laptops. SimWeights gathers all the information it needs form information in the
hdf5 file so there is no need for access to the simulation production database. SimWeights works with
files produced with corsika-reader, neutrino-generator, and genie-reader.PrerequisitesRequired:numpy,scipyOptional:h5py,pytables,pandas,uproot,nufluxInstallationTo install from pypi run:pip install simweightsAlternatively, if you need to install unreleased code from main you can run:pip install git+https://github.com/icecube/simweights.gitOn certain installs of python on cvmfs you might get the following error:ModuleNotFoundError: No module named 'glob'. If this happens you can add the
following option--no-build-isolationto the above command.If you want to develop simweights you can install directly with flit.
The-soption will symlink the module into site-packages rather than copying it,
so that you can test changes without reinstalling the module:pip install flit
git clone git@github.com:icecube/simweights.git
cd simweights
flit install [--user] -sBasic UsageFor triggered CORSIKA or CORSIKA produced bycorsika-readerwith S-Frames files useCorsikaWeighter()without any additional arguments:>>>importsimweights,pandas>>>simfile=pandas.HDFStore("Level2_IC86.2016_corsika.021889.000000.hdf5","r")>>>flux_model=simweights.GaisserH4a()>>>weight_obj=simweights.CorsikaWeighter(simfile)>>>weights=weight_obj.get_weights(flux_model)>>>print(f"Rate ={weights.sum():5.2f}Hz")Rate = 122.84 HzThe value returned byget_weights()is the rate of events in HzFor traditional CORSIKA files made withcorsika-readeryou will also usesimweights.CorsikaWeighter(), but you need to know the number of.i3files that contributed to create this hdf5 file and pass it as thenfilesparameter.Forneutrino-generatoryou can useNuGenWeighter()which also
requires you to know the number of files.
Flux models fromnufluxcan be used:>>>importnuflux>>>simfile=pandas.HDFStore("Level2_IC86.2016_NuMu.020878.000000.hdf5")>>>flux_model=nuflux.makeFlux("CORSIKA_GaisserH3a_QGSJET-II")>>>weight_obj=simweights.NuGenWeighter(simfile,nfiles=1)>>>weights=weight_obj.get_weights(flux_model)>>>print(f"Rate ={weights.sum():5.2e}Hz")Rate = 1.41e-02 HzTo weight a spectrum with a function you can also pass a callable toget_weights()>>>weights=weight_obj.get_weights(lambdaenergy:7.2e-8*energy**-2.2)>>>print(f"Rate ={weights.sum():5.2e}Hz")Rate = 2.34e-05 HzYou can also pass flux values as a numpy array with the same length as the sample>>>fluxes=7.2e-8*simfile["I3MCWeightDict"]["PrimaryNeutrinoEnergy"]**-2.2>>>weights=weight_obj.get_weights(fluxes)>>>print(f"Rate ={weights.sum():5.2e}Hz")Rate = 2.34e-05 HzYou can also pass a scalar to weight all events with the same flux. Passing
a value of1.0will result in the well known quantity OneWeight divided
by the number of events.>>>OneWeight=weight_obj.get_weights(1.0)>>>OldOneWeight=simfile["I3MCWeightDict"]["OneWeight"]/(simfile["I3MCWeightDict"]["NEvents"]/2)>>>(OneWeight-OldOneWeight).median()0.0Simulation created withgenie-readercan be weighted withGenieWeighter():>>>simfile=pandas.HDFStore("genie_reader_NuE.hdf5")>>>flux_model=nuflux.makeFlux("IPhonda2014_spl_solmax")>>>weight_obj=simweights.GenieWeighter(simfile)>>>weights=weight_obj.get_weights(flux_model)>>>print(f"Rate ={weights.sum():5.2e}Hz")Rate = 3.78e+00 HzAlso note that these examples usepandas. SimWeights will work equally well withpandas,h5py, orpytables.DocumentationFull documentation is available on theIceCube Documentation Server.Getting HelpPlease direct any questions to@kjmon the slack channel#software.ContributingSee thecontributing guide