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)
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,
                        "cuts": cut
                    }
                    cross = pp.crosssection.make_std_crosssection(**args)
                    int_calc = pp.make_interaction(cross, True)
                    dec_calc = pp.make_decay(cross, particle_def, True)

                    energy = initial_energy

                    buf = [""]
                    buf.append(str(particle_def.name))
                    buf.append(str(medium.name))
                    buf.append(str(cut.ecut))
                    buf.append(str(cut.vcut))
                    buf.append(str(energy))

                    for i in range(statistics):
                        rndd = pp.RandomGenerator.get().random_double()
                        rndi = pp.RandomGenerator.get().random_double()

                        energy = max(
                            dec_calc.energy_decay(energy, rndd, medium.mass_density),
                            int_calc.energy_interaction(energy, rndi)
                        )
                        buf.append(str(energy))

                    buf.append("\n")
                    file.write("\t".join(buf))
def create_table_stochastic(dir_name):
    pp.RandomGenerator.get().set_seed(1234)
    with open(dir_name + "Sector_StochasticLoss.txt", "w") as file:
        for particle_def in particle_defs:
            for medium in mediums:
                for cut in cuts:
                    energy = initial_energy

                    args = {
                        "particle_def": particle_def,
                        "target": medium,
                        "interpolate": True,
                        "cuts": cut
                    }
                    cross = pp.crosssection.make_std_crosssection(**args)
                    int_calc = pp.make_interaction(cross, True)

                    buf = [""]
                    buf.append(str(particle_def.name))
                    buf.append(str(medium.name))
                    buf.append(str(cut.ecut))
                    buf.append(str(cut.vcut))
                    buf.append(str(initial_energy))

                    for i in range(statistics):
                        rnd = pp.RandomGenerator.get().random_double()
                        int_loss = int_calc.sample_loss(
                            energy, int_calc.rates(energy), rnd
                        )
                        energy = energy * (1 - int_loss.v_loss)
                        buf.append(str(energy))
                        buf.append(str(int_loss.type))
                        buf.append(str(rnd))

                    buf.append("\n")
                    file.write("\t".join(buf))
Example #4
0
def propagate_deflected_muons(initial_energies,
                              minimum_energies,
                              inter_type,
                              deflection_type='continuous+stochastic',
                              e_cut=500,
                              v_cut=0.05,
                              cont_rand=False,
                              scattering_method="highlandintegral",
                              beta=1.0,
                              rnd_seed=1337,
                              initial_direction=[0, 0, 1]):
    '''Propagate muon tracks with deflection. Scaling of Bremsstrahlung opening angle can be done by beta.
    
    Parameters
    ----------
    initial_energies: list of energies
    minimum_energs: list of energies, lower propagation limit
    inter_type: list of interaction types for propagation/deflection
    deflection_type: string, choose one:
            1. 'contiuous+stochastic'
            2. 'continuous'
            3. 'stochastic'
    beta: scaling factor for Bremsstrahlung
    e_cut, v_cut, cont_rand: usual PROPOSAL energy cut settings
    initial_direction: list of initial direction (cartesian coordinates)
    '''
    pp.RandomGenerator.get().set_seed(rnd_seed)
    args = {
        "particle_def": pp.particle.MuMinusDef(),
        "target": pp.medium.Ice(),
        "interpolate": True,
        "cuts": pp.EnergyCutSettings(e_cut, v_cut, cont_rand)
    }

    cross = pp.crosssection.make_std_crosssection(**args)
    multiple_scatter = pp.make_multiple_scattering(scattering_method,
                                                   args["particle_def"],
                                                   args["target"], cross, True)
    stochastic_deflect = pp.make_default_stochastic_deflection(
        inter_type, args["particle_def"], args["target"])

    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)
    collection.decay = pp.make_decay(cross, args["particle_def"], True)

    if deflection_type == 'stochastic':
        print('stochastic deflection')
        if pp.particle.Interaction_Type.brems in inter_type:
            collection.scattering = pp.scattering.ScatteringMultiplier(
                stochastic_deflect,
                [(pp.particle.Interaction_Type.brems, beta)])
        else:
            collection.scattering = pp.scattering.ScatteringMultiplier(
                stochastic_deflect, [(inter_type[0], 1.0)])
    elif deflection_type == 'continuous':
        print('continuous deflection')
        collection.scattering = pp.scattering.ScatteringMultiplier(
            multiple_scatter, 1.0)
    elif deflection_type == 'continuous+stochastic':
        print('continuous and stochastic deflection')
        if pp.particle.Interaction_Type.brems in inter_type:
            collection.scattering = pp.scattering.ScatteringMultiplier(
                multiple_scatter, stochastic_deflect, 1.0,
                [(pp.particle.Interaction_Type.brems, beta)])
        else:
            collection.scattering = pp.scattering.ScatteringMultiplier(
                multiple_scatter, stochastic_deflect, 1.0,
                [(inter_type[0], 1.0)])

    utility = pp.PropagationUtility(collection=collection)
    detector = pp.geometry.Sphere(pp.Vector3D(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)])

    init_state = pp.particle.ParticleState()
    init_state.position = pp.Vector3D(0, 0, 0)
    init_state.direction = pp.Vector3D(initial_direction[0],
                                       initial_direction[1],
                                       initial_direction[2])

    tracks = []
    for E_i, E_min in zip(tqdm(initial_energies), minimum_energies):
        init_state.energy = E_i  # initial energy in MeV
        track = prop.propagate(init_state, max_distance=1e9, min_energy=E_min)
        tracks.append(track)

    return tracks
Example #5
0
targets = {"air": pp.medium.Air(), "standardrock": pp.medium.StandardRock()}

utilities = {}
for target in targets.values():

    prop_def = {
        "particle_def": pp.particle.MuMinusDef(),
        "cuts": pp.EnergyCutSettings(500, 1, False),
        "target": target,
        "interpolate": True,
    }

    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)