def test_proposal():

    # =========================================================
    # 	Propagate
    # =========================================================

    # initialize propagator

    args = {
        "particle_def": pp.particle.MuMinusDef(),
        "target": pp.medium.Ice(),
        "interpolate": True,
        "cuts": pp.EnergyCutSettings(500, 0.05)
    }

    cross = pp.crosssection.make_std_crosssection(**args)

    collection = pp.PropagationUtilityCollection()
    collection.displacement = pp.make_displacement(cross, True)
    collection.interaction = pp.make_interaction(cross, True)
    collection.time = pp.make_time(cross, args["particle_def"], True)
    utility = pp.PropagationUtility(collection=collection)

    detector = pp.geometry.Sphere(pp.Cartesian3D(0, 0, 0), 1e20)
    density_distr = pp.density_distribution.density_homogeneous(
        args["target"].mass_density)

    prop = pp.Propagator(args["particle_def"],
                         [(detector, utility, density_distr)])

    # intialize initial state

    statistics = 100

    init_state = pp.particle.ParticleState()
    init_state.energy = 1e8  # initial energy in MeV
    init_state.position = pp.Cartesian3D(0, 0, 0)
    init_state.direction = pp.Cartesian3D(0, 0, -1)
    init_state.time = 0

    pp.RandomGenerator.get().set_seed(1234)
    for i in range(statistics):

        output = prop.propagate(init_state)
        energies = output.track_energies()
        times = output.track_times()

        E_old = init_state.energy
        t_old = init_state.time

        for E, t in zip(energies, times):
            energy_diff = E_old - E
            time_diff = t - t_old
            E_old = E
            t_old = t

            assert (energy_diff >= 0)
            assert (time_diff >= 0)
Пример #2
0
def create_table(dir_name):
    """TODO: Docstring for create_table.
    Returns: TODO

    """

    statistics = 10

    prop = pp.Propagator(pp.particle.MuMinusDef(),
                         "examples/config_minimal.json")

    init_particle = pp.particle.ParticleState()

    init_particle.energy = 1e8
    init_particle.propagated_distance = 0
    init_particle.position = pp.Cartesian3D(0, 0, 0)
    init_particle.direction = pp.Cartesian3D(0, 0, -1)
    init_particle.time = 0
    pp.RandomGenerator.get().set_seed(1234)

    with open(dir_name + "Propagator_propagation.txt", "w") as file:

        buf = [""]
        buf.append("name")
        buf.append("length")
        buf.append("energy")
        buf.append("x")
        buf.append("y")
        buf.append("z")
        buf.append("dx")
        buf.append("dy")
        buf.append("dz")
        buf.append("\n")
        buf.append(str(statistics))
        buf.append(str(init_particle.energy))
        buf.append("\n")

        file.write("\t".join(buf))

        for i in range(statistics):
            daughters = prop.propagate(init_particle)

            buf = [""]
            for d in daughters.stochastic_losses():
                buf.append(str(d.type))
                buf.append(str(d.propagated_distance))
                buf.append(str(d.energy))
                buf.append(str(d.position.x))
                buf.append(str(d.position.y))
                buf.append(str(d.position.z))
                buf.append(str(d.direction.x))
                buf.append(str(d.direction.y))
                buf.append(str(d.direction.z))
                buf.append("\n")

            file.write("\t".join(buf))
Пример #3
0
def get_direction(pos):
    pos = pp.Spherical3D(-pos)
    pos.radius = 1

    rnd1 = np.random.normal(0, np.pi / 20)
    rnd2 = np.random.normal(0, np.pi / 20)

    pos.azimuth = pos.azimuth + rnd1
    pos.zenith = pos.zenith + rnd2

    return pp.Cartesian3D(pos)
Пример #4
0
def create_table(dir_name,
                 particle_def,
                 init_energy,
                 decay_products,
                 filename,
                 statistics=int(1e6),
                 NUM_bins=50):
    pp.RandomGenerator.get().set_seed(1234)

    init_particle = pp.particle.ParticleState()
    init_particle.energy = init_energy
    products = decay_products
    decay_channels = [
        pp.decay.LeptonicDecayChannelApprox(*products),
        pp.decay.LeptonicDecayChannel(*products),
        pp.decay.ManyBodyPhaseSpace(products, matrix_element_evaluate)
    ]
    decay_names = [
        "LeptonicDecayChannelApprox", "LeptonicDecayChannel", "ManyBody"
    ]

    histrogram_list = []

    v_max = (particle_def.mass**2 + products[0].mass**2) / (2 *
                                                            particle_def.mass)
    gamma = init_particle.energy / particle_def.mass
    betagamma = init_particle.momentum / particle_def.mass
    E_max = gamma * v_max + betagamma * np.sqrt(v_max**2 - products[0].mass**2)

    for channel in decay_channels:
        # print(particle_def.name, init_energy, channel)
        prod_0_energies = []
        prod_1_energies = []
        prod_2_energies = []
        for i in range(statistics):
            init_particle.position = pp.Cartesian3D(0, 0, 0)
            init_particle.direction = pp.Cartesian3D(0, 0, 1)
            init_particle.energy = init_energy
            init_particle.propagated_distance = 0

            decay_prods = channel.decay(particle_def, init_particle)
            for p in decay_prods:
                if p.type == products[0].particle_type:
                    prod_0_energies.append(p.energy)
                elif p.type == products[1].particle_type:
                    prod_1_energies.append(p.energy)
                elif p.type == products[2].particle_type:
                    prod_2_energies.append(p.energy)
                else:
                    assert ("This should never happen")

        histogram = []
        histogram.append(
            np.histogram(prod_0_energies, bins=NUM_bins, range=(0, E_max))[0])
        histogram.append(
            np.histogram(prod_1_energies, bins=NUM_bins, range=(0, E_max))[0])
        histogram.append(
            np.histogram(prod_2_energies, bins=NUM_bins, range=(0, E_max))[0])

        histrogram_list.append(histogram)

    with open(dir_name + filename, "w") as file:
        buf = [""]
        buf.append(str(statistics))
        buf.append(str(NUM_bins))
        buf.append(str(particle_def.name))
        buf.append(str(init_particle.energy))
        buf.append(str(products[0].name))
        buf.append(str(products[1].name))
        buf.append(str(products[2].name))
        buf.append("\n")
        file.write("\t".join(buf))

        for name, hist in zip(decay_names, histrogram_list):
            buf = [""]
            buf.append(name)
            buf.append("\n")
            for prod in hist:
                for bin_value in prod:
                    buf.append(str(bin_value))
                buf.append("\n")

            file.write("\t".join(buf))
Пример #5
0
def get_injection_point():
    phi = 0
    theta = 2 * np.pi * np.random.random()
    pos = pp.Spherical3D(earth_radius + atmosphere_depth, phi, theta)
    return pp.Cartesian3D(pos)
Пример #6
0
    cross = pp.crosssection.make_std_crosssection(**prop_def)
    collection = pp.PropagationUtilityCollection()
    collection.displacement = pp.make_displacement(cross, True)
    collection.interaction = pp.make_interaction(cross, True)
    collection.time = pp.make_time_approximate()

    utilities[f"{target.name}"] = pp.PropagationUtility(collection)

logger.info("utility build")

earth_radius = 6300 * 1e5  # km -> cm
atmosphere_depth = 2000 * 1e5  # km -> cm

geometries = {}

geometries["air"] = pp.geometry.Sphere(pp.Cartesian3D(0, 0, 0), np.Infinity)
geometries["air"].hierarchy = 1
geometries["standardrock"] = pp.geometry.Sphere(pp.Cartesian3D(0, 0, 0),
                                                earth_radius)
geometries["standardrock"].hierarchy = 2

profiles = {}

axis = pp.density_distribution.radial_axis(pp.Cartesian3D(0, 0, 0))
sigma = -5.5 * 1e5  # km -> cm
profiles["air"] = pp.density_distribution.density_homogeneous(
    1e-1 * targets["air"].mass_density)
profiles["standardrock"] = pp.density_distribution.density_homogeneous(
    1e-4 * targets["standardrock"].mass_density)

env = []
    pp.medium.Ice(),
    pp.medium.Hydrogen(),
    pp.medium.Uranium()
]

cuts = [
    pp.EnergyCutSettings(np.inf, 1),
    pp.EnergyCutSettings(500, 1),
    pp.EnergyCutSettings(np.inf, 0.05),
    pp.EnergyCutSettings(500, 0.05)
]

energies = np.logspace(4, 13, num=10)  # MeV
energies_out = np.logspace(3, 12, num=10)
distance = 1000  # cm
position_init = pp.Cartesian3D(0, 0, 0)
direction_init = pp.Cartesian3D(1, 0, 0)

pp.RandomGenerator.get().set_seed(1234)

def create_table(dir_name):

    with open(dir_name + "Scattering_scatter.txt", "w") as file:

        for particle_def in particle_defs:
            for medium in mediums:
                for cut in cuts:
                    for scat_name in scat_names:

                        if scat_name == "HighlandIntegral" and particle_def.name == "MuMinus":
                            args = {
Пример #8
0
    # pp.medium.Uranium()
    ]

cuts = [
    # pp.EnergyCutSettings(-1, -1),
    pp.EnergyCutSettings(500, 1),
    # pp.EnergyCutSettings(-1, 0.05),
    pp.EnergyCutSettings(500, 0.05)
    ]

statistics = 10
energies = np.logspace(4, 13, num=statistics)  # MeV
initial_energy = 1e12 # MeV
distance = 1000  # cm

position = pp.Cartesian3D(0, 0, 0)
direction = pp.Cartesian3D(1, 0, 0)

pp.InterpolationSettings.tables_path = "~/.local/share/PROPOSAL/tables"

def create_table_continous(dir_name):
    pp.RandomGenerator.get().set_seed(1234)
    with open(dir_name + "Sector_ContinousLoss.txt", "w") as file:
        for particle_def in particle_defs:
            for medium in mediums:
                for cut in cuts:

                    args = {
                        "particle_def": particle_def,
                        "target": medium,
                        "interpolate": True,