def parent_flux(cos_theta, parent='D0', pmodel=(pm.HillasGaisser2012, 'H3a'), hadr='SIBYLL2.3c', density=('CORSIKA', ('SouthPole', 'December')), mag=3, ecr=None, particle=None): plt.figure() sv = nuVeto(cos_theta, pmodel, hadr, density=density) gsol = sv.grid_sol(ecr, particle) ### hack to convert list to np array sv.mceq.grid_sol = np.asarray(sv.mceq.grid_sol) ### X_vec = sv.X_vec for idx, x_val in enumerate(X_vec): mceq = sv.mceq.get_solution(parent, mag, grid_idx=idx) mceq[mceq == 0] = np.nan calc = sv.get_solution(parent, gsol, mag, grid_idx=idx) pout = plt.loglog(sv.mceq.e_grid, mceq, label='$X={:.3g}$ km'.format( float(sv.mceq.density_model.X2h(x_val)) / 1e5)) plt.loglog(sv.mceq.e_grid, calc, '--', color=pout[0].get_color()) plt.xlabel(r'$E_p$') plt.ylabel(r'$E_p^{} \Phi_p$'.format(mag)) plt.ylim(ymin=1e-20) plt.legend() plt.title('{} {}'.format(parent, tex(cos_theta))) plt.tight_layout(0.3)
def test_edge(): """ Test edge case where MCEq yields are all <= 0. """ sv = nuVeto(0., pmodel=(pm.ZatsepinSokolskaya, 'pamela'), hadr='DPMJET-III-19.1', density=('MSIS00_IC', ('SouthPole','June'))) _ = sv.get_rescale_phi('D-', 508.0218046913023, 14) assert not np.any(_[:,-1] > 0)
def parent_ratio(cos_theta, parents='pi+ pi-', pmodel=(pm.HillasGaisser2012, 'H3a'), hadr='SIBYLL2.3c', ecr=None, particle=None): plt.figure() sv = nuVeto(cos_theta, pmodel, hadr) gsol = sv.grid_sol(ecr, particle) X_vec = sv.X_vec for idx, x_val in enumerate(X_vec): calc0 = sv.get_solution(parents.split()[0], gsol, grid_idx=idx) calc1 = sv.get_solution(parents.split()[1], gsol, grid_idx=idx) plt.plot(sv.mceq.e_grid, calc0 / calc1, label='X={:.3g} km'.format( float(sv.mceq.density_model.X2h(x_val)) / 1e5)) plt.xlabel(r'$E_p$') plt.ylabel(r'{}/{} flux ratio'.format(*parents.split())) plt.xscale('log') plt.legend() if ecr is None or particle is None: plt.title(r'$\cos \theta = {:.2g}$'.format(cos_theta)) else: plt.title(r'{} at {:.2g} GeV and $\cos \theta = {:.2g}$'.format( particle, ecr, cos_theta))
def test_nonneg(cth, capsys): with capsys.disabled(): sv = nuVeto(cth,debug_level=2) enus = [6.2e6, 1e7] kinds = ['conv nu_mu', 'conv nu_e', 'pr nu_mu', 'pr nu_e'] for enu, kind in product(enus, kinds): n, d = sv.get_fluxes(enu, kind) assert n > 0 and d > 0
def test_nonneg(): cths = [0.9, 1] enus = [6.2e6, 1e7] kinds = ['conv_numu', 'conv_nue', 'pr_numu', 'pr_nue'] for cth in cths: sv = nuVeto(cth) for kind in kinds: for enu in enus: n, d = sv.get_fluxes(enu, kind) assert n > 0 and d > 0
def test_pnmshower(): cths = [0.1, 0.3, 0.8] particle = 14 ecrs = amu(particle) * np.logspace(3, 10, 20) ecrs_fine = amu(particle) * np.logspace(3, 10, 1000) for cth in cths: sv = nuVeto(cth) nmu = [sv.nmu(ecr, particle) for ecr in ecrs] nmufn = interpolate.interp1d(ecrs, nmu, kind='linear', assume_sorted=True, fill_value=(0, np.nan)) pnmshower = np.exp(-nmufn(ecrs_fine)) assert np.all(0 <= pnmshower) and np.all(pnmshower <= 1)
def test_nuflux(): cths = [0.1, 0.3, 0.8] kinds = ['conv_numu', 'conv_nue', 'pr_numu', 'pr_nue'] for cth in cths: sv = nuVeto(cth) sv.grid_sol() for kind in kinds: thres = 1e7 if kind.split('_') == 'pr' else 1e6 ensel = (sv.mceq.e_grid > 1e2) & (sv.mceq.e_grid < thres) theirs = sv.mceq.get_solution(kind)[ensel] mine = np.asarray([ fluxes(en, cth, kind, corr_only=True)[1] for en in sv.mceq.e_grid[ensel] ]) print kind, cth, theirs / mine assert np.all(np.abs(theirs / mine - 1) < 0.09)
def test_nuflux(cth): sv = nuVeto(cth) sv.grid_sol() kinds = ['conv nu_mu', 'conv nu_e', 'pr nu_mu', 'pr nu_e'] for kind in kinds: _c, _d = kind.split() # thres = 1e7 if _c == 'pr' else 1e6 thres = 1e7 ensel = (sv.mceq.e_grid > 1e2) & (sv.mceq.e_grid < thres) theirs = sv.mceq.get_solution(mceq_categ_format(kind))[ensel] mine = np.asarray([fluxes(en, cth, kind, corr_only=True)[1] for en in sv.mceq.e_grid[ensel]]) print(kind, cth, theirs/mine) if _c == 'conv': assert np.all(np.abs(theirs/mine - 1) < 0.2) else: assert np.all(np.abs(theirs/mine - 1) < 0.8)
def nu_flux(cos_theta, kinds='conv nu_mu', pmodel=(pm.HillasGaisser2012, 'H3a'), hadr='SIBYLL2.3c', mag=3, logxlim=(3, 7), corr_only=False): sv = nuVeto(cos_theta, pmodel, hadr) sv.grid_sol() fig, axs = plt.subplots(2, 1) for kind in [_.strip() for _ in kinds.split(',')]: plt.sca(axs[0]) mine = np.asarray([ fluxes(en, cos_theta, kind, pmodel, hadr, corr_only=corr_only)[1] for en in sv.mceq.e_grid ]) pr = plt.plot(sv.mceq.e_grid, mine * sv.mceq.e_grid**mag, label='{} {} {}'.format(hadr, tex(kind), tex(cos_theta))) plt.ylabel(r'$E_\nu^{} \Phi_\nu$'.format(mag)) plt.loglog() plt.xlim(*np.power(10, logxlim)) plt.ylim(ymin=1e-8) plt.legend() try: theirs = sv.mceq.get_solution(mceq_categ_format(kind)) pr = plt.plot(sv.mceq.e_grid, theirs * sv.mceq.e_grid**mag, linestyle='--', color=pr[0].get_color()) plt.sca(axs[1]) plt.plot(sv.mceq.e_grid, theirs / mine) except KeyError: plt.sca(axs[1]) finally: plt.ylabel(r'ratio MCEq/Calc') plt.xscale('log') plt.ylim(0.5, 1.9) plt.xlabel(r'$E_\nu$ [GeV]') plt.xlim(*np.power(10, logxlim))
def prob_nomu(cos_theta, particle=14, pmodel=(pm.HillasGaisser2012, 'H3a'), hadr='SIBYLL2.3c', prpl='ice_allm97_step_1'): """ plot prob_nomu as fn of ecr """ ecrs = amu(particle) * np.logspace(3, 10, 20) ecrs_fine = amu(particle) * np.logspace(3, 10, 1000) sv = nuVeto(cos_theta, pmodel, hadr) nmu = [sv.nmu(ecr, particle, prpl) for ecr in ecrs] nmufn = interpolate.interp1d(ecrs, nmu, kind='linear', assume_sorted=True, fill_value=(0, np.nan)) plt.semilogx(ecrs_fine, np.exp(-nmufn(ecrs_fine)), label='interpolated') plt.semilogx(ecrs, np.exp(-np.asarray(nmu)), 'ko') plt.xlabel(r'$E_{CR} [GeV]$') plt.ylabel(r'$e^{-N_\mu}$') plt.legend()
def dndee(mother, daughter): sv = nuVeto(0) x_range, dNdEE, dNdEE_interp = sv.get_dNdEE(mother, daughter) # print x_range[0], x_range[-1] x_samp = np.logspace(1, -9, 5000) c = plt.plot(x_samp, dNdEE_interp(x_samp), label="Interpolated {} to {}".format(mother, daughter)) plt.plot(x_range, dNdEE, '.', color=c[0].get_color(), label="MCEq {} to {}".format(mother, daughter)) plt.semilogx() plt.xlabel(r"$x=E_\nu/E_p$") plt.ylabel(r"$ \frac{dN}{dE_\nu} E_p$") # plt.ylim(-0.1, 5.1) plt.axvline(1 - ParticleProperties.rr(mother, daughter), linestyle='--', color=c[0].get_color()) plt.legend()
def test_pnmshower(cth): particle = 14 ecrs = amu(particle)*np.logspace(3, 10, 15) sv = nuVeto(cth) nmu = np.asarray([sv.nmu(ecr, particle) for ecr in ecrs]) assert not np.any(nmu < 0)