예제 #1
0
def create_table_propagate(dir_name):
    pp.RandomGenerator.get().set_seed(1234)
    with open(dir_name + "Sector_Propagate.txt", "w") as file:
        for particle_def in particle_defs:
            for medium in mediums:
                for cut in cuts:
                    sector_def = pp.SectorDefinition()
                    sector_def.cut_settings = cut
                    sector_def.medium = medium

                    sector = pp.Sector(particle_def, sector_def, interpoldef)

                    for energy in energies:
                        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))

                        p_condition = pp.particle.DynamicData(0)
                        p_condition.position = pp.Vector3D(0, 0, 0)
                        p_condition.direction = pp.Vector3D(0, 0, -1)
                        p_condition.propagated_distance = 0
                        p_condition.energy = energy
                        sec = sector.propagate(p_condition, 1000, 0)

                        buf.append(str(sec.number_of_particles))
                        if (sec.particles[-1].propagated_distance < 999.99):
                            buf.append(
                                str(-sec.particles[-1].propagated_distance))
                        else:
                            buf.append(str(sec.particles[-1].energy))
                        buf.append("\n")
                        file.write("\t".join(buf))
예제 #2
0
def create_table(dir_name):
    """TODO: Docstring for create_table.
    Returns: TODO

    """

    statistics = 10

    prop = pp.Propagator(pp.particle.MuMinusDef(), "resources/config_ice.json")

    mu = pp.particle.DynamicData(pp.particle.Particle_Id.MuMinus)

    mu.energy = 1e8
    mu.propagated_distance = 0
    mu.position = pp.Vector3D(0, 0, 0)
    mu.direction = pp.Vector3D(0, 0, -1)
    pp.RandomGenerator.get().set_seed(1234)

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

        buf = [""]
        buf.append("name")
        buf.append("lenght")
        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(mu.energy))
        buf.append("\n")

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

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

            buf = [""]
            for d in daughters.particles:
                buf.append(str(d.name))
                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 __propagate_particle(self,
                             energy_lepton,
                             lepton_code,
                             lepton_position,
                             lepton_direction,
                             propagation_length,
                             low=1 * pp_PeV):
        """
        Calculates secondary particles using a PROPOSAL propagator. It needs to
        be given a propagators dictionary with particle codes as key

        Parameters
        ----------
        energy_lepton: float
            Energy of the input lepton, in PROPOSAL units (MeV)
        lepton_code: integer
            Input lepton code
        lepton_position: (float, float, float) tuple
            Position of the input lepton, in PROPOSAL units (cm)
        lepton_direction: (float, float, float) tuple
            Lepton direction vector, normalised to 1
        propagation_length: float
            Maximum length the particle is propagated, in PROPOSAL units (cm)
        low: float
            Low energy limit for the propagating particle in Proposal units (MeV)

        Returns
        -------
        secondaries: array of PROPOSAL particles
            Secondaries created by the propagation
        """
        x, y, z = lepton_position
        px, py, pz = lepton_direction

        if (lepton_code == 13):
            particle_def = pp.particle.MuMinusDef()
        elif (lepton_code == -13):
            particle_def = pp.particle.MuPlusDef()
        elif (lepton_code == 15):
            particle_def = pp.particle.TauMinusDef()
        elif (lepton_code == -15):
            particle_def = pp.particle.TauPlusDef()

        initial_condition = pp.particle.DynamicData(particle_def.particle_type)
        initial_condition.position = pp.Vector3D(x, y, z)
        initial_condition.direction = pp.Vector3D(px, py, pz)
        initial_condition.energy = energy_lepton
        initial_condition.propagated_distance = 0

        secondaries = self.__get_propagator(lepton_code).propagate(
            initial_condition, propagation_length,
            minimal_energy=low).particles
        return secondaries
예제 #4
0
def propagate_particle(propagator,
                       position=[-1e5, 0, 1e4],
                       direction=[1, 0, 0],
                       energy=1e9):
    mu_data = pp.particle.DynamicData(propagator.particle_def.particle_type)
    mu_data.position = pp.Vector3D(position[0], position[1], position[2])
    tmp_dir = pp.Vector3D(direction[0], direction[1], direction[2])
    tmp_dir.spherical_from_cartesian()
    mu_data.direction = tmp_dir

    mu_data.energy = energy
    mu_data.propagated_distance = 0
    mu_data.time = 0

    return propagator.propagate(mu_data)
예제 #5
0
def make_propagator(ID, body, xs_model='dipole', granularity=0.5):

    if (ID in [12, -12]):
        return None

    particle_def = getattr(pp.particle, ID_2_name[ID])()
    #define how many layers of constant density we need for the tau
    descs = segment_body(body, granularity)
    #make the sectors
    sec_defs = [
        make_sector(d / units.gr * units.cm**3, s * body.radius / units.meter,
                    e * body.radius / units.meter, xs_model)
        for s, e, d in descs
    ]

    with path('taurunner.resources.proposal_tables', 'tables.txt') as p:
        tables_path = str(p).split('tables.txt')[0]

    #define interpolator
    interpolation_def = pp.InterpolationDef()
    interpolation_def.path_to_tables = tables_path
    interpolation_def.path_to_tables_readonly = tables_path
    interpolation_def.nodes_cross_section = 200

    #define propagator -- takes a particle definition - sector - detector - interpolator
    prop = pp.Propagator(particle_def=particle_def,
                         sector_defs=sec_defs,
                         detector=pp.geometry.Sphere(pp.Vector3D(),
                                                     body.radius / units.cm,
                                                     0),
                         interpolation_def=interpolation_def)

    return prop
예제 #6
0
def muons(energy, statistics, vcut, do_continuous_randomization, dist):

    sec_def = pp.SectorDefinition()
    sec_def.medium = pp.medium.StandardRock(1.0)
    sec_def.geometry = pp.geometry.Sphere(pp.Vector3D(), 1e20, 0)
    sec_def.particle_location = pp.ParticleLocation.inside_detector

    sec_def.scattering_model = pp.scattering.ScatteringModel.Highland
    sec_def.do_continuous_randomization = do_continuous_randomization

    sec_def.cut_settings.ecut = 0
    sec_def.cut_settings.vcut = vcut

    interpolation_def = pp.InterpolationDef()
    interpolation_def.path_to_tables = "~/.local/share/PROPOSAL/tables"
    interpolation_def.path_to_tables_readonly = "~/.local/share/PROPOSAL/tables"

    mu_def = pp.particle.MuMinusDef()
    prop = pp.Propagator(particle_def=mu_def,
                         sector_defs=[sec_def],
                         detector=pp.geometry.Sphere(pp.Vector3D(), 1e20, 0),
                         interpolation_def=interpolation_def)

    mu = pp.particle.DynamicData(mu_def.particle_type)
    mu.position = pp.Vector3D(0, 0, 0)
    mu.direction = pp.Vector3D(0, 0, -1)
    mu.energy = energy
    mu.propagated_distance = 0.
    mu.time = 0.

    mu_energies = []
    pp.RandomGenerator.get().set_seed(1234)

    for i in tqdm(range(statistics)):

        secondaries = prop.propagate(mu, dist * 100)

        mu_energies.append(secondaries.energy[-1])
        # del secondaries

    return mu_energies
예제 #7
0
def muons(energy, statistics, vcut, do_continuous_randomization, dist):

    sec_def = pp.SectorDefinition()
    sec_def.medium = pp.medium.StandardRock(1.0)
    sec_def.geometry = pp.geometry.Sphere(pp.Vector3D(), 1e20, 0)
    sec_def.particle_location = pp.ParticleLocation.inside_detector

    sec_def.scattering_model = pp.scattering.ScatteringModel.Moliere
    sec_def.do_continuous_randomization = do_continuous_randomization

    sec_def.cut_settings.ecut = 0
    sec_def.cut_settings.vcut = vcut

    interpolation_def = pp.InterpolationDef()
    interpolation_def.path_to_tables = ""

    prop = pp.Propagator(particle_def=pp.particle.MuMinusDef.get(),
                         sector_defs=[sec_def],
                         detector=pp.geometry.Sphere(pp.Vector3D(), 1e20, 0),
                         interpolation_def=interpolation_def)

    mu = prop.particle

    mu_energies = []

    for i in range(statistics):

        mu.position = pp.Vector3D(0, 0, 0)
        mu.direction = pp.Vector3D(0, 0, -1)
        mu.energy = energy
        mu.propagated_distance = 0

        d = prop.propagate(dist * 100)

        mu_energies.append(mu.energy)

    return mu_energies
예제 #8
0
def make_sector(density, start, end, xs_model):
    #Define a sector
    sec_def = pp.SectorDefinition()
    components = [pp.component.Hydrogen(2), pp.component.Oxygen()]
    sec_def.medium = pp.medium.Medium('Ice_{}'.format(density), 1, 75.0,
                                      -3.5017, 0.09116, 3.4773, 0.2400, 2.8004,
                                      0, density, components)
    sec_def.geometry = pp.geometry.Sphere(pp.Vector3D(), end, start)
    sec_def.particle_location = pp.ParticleLocation.inside_detector
    sec_def.scattering_model = pp.scattering.ScatteringModel.Moliere
    sec_def.crosssection_defs.brems_def.lpm_effect = True
    sec_def.crosssection_defs.epair_def.lpm_effect = True
    sec_def.cut_settings.ecut = -1.0
    sec_def.cut_settings.vcut = 1e-3
    sec_def.do_continuous_randomization = True

    if (xs_model == 'dipole'):
        sec_def.crosssection_defs.photo_def.parametrization = pp.parametrization.photonuclear.PhotoParametrization.BlockDurandHa
    else:
        sec_def.crosssection_defs.photo_def.parametrization = pp.parametrization.photonuclear.PhotoParametrization.AbramowiczLevinLevyMaor97

    return sec_def
예제 #9
0
def main():
    prop = pp.Propagator(particle_def=pp.particle.MuMinusDef(),
                         config_file="resources/config.json")
    # print('losses inside: ', prop.sector_list[0].sector_def.only_loss_inside_detector)
    pp.RandomGenerator.get().set_seed(1234)

    fig = plt.figure(figsize=(8, 10))
    gs = gridspec.GridSpec(3, 1)
    ax1 = fig.add_subplot(gs[:-1])
    ax2 = fig.add_subplot(gs[-1], sharex=ax1)
    # ax1 = fig.add_subplot(111)

    ax1.plot(
        np.array([
            -prop.detector.radius, prop.detector.radius, prop.detector.radius,
            -prop.detector.radius, -prop.detector.radius
        ]),
        np.array([
            -prop.detector.height, -prop.detector.height, prop.detector.height,
            prop.detector.height, -prop.detector.height
        ]) / 2,
        color='k',
        label='detector')

    ax1.set_xlabel('x coord. / cm')
    ax1.set_ylabel('z coord. / cm')
    ax1.set_xlim([-1e5, 1e5])
    ax1.set_ylim([-1e5, 1e5])

    labels = ['EPair', 'Brems', 'Ioniz', 'NuclInt', r'$e_{\mathrm{decay}}$']

    start_positions = np.array([
        # [-1e5,0,1e4],
        [-1e5, 0, 2e4],
        # [-3e4,0,3e4],
        # [1e4,0,4e4],
        [74428.7, 29332., 69745.]
    ])
    tmp_dir = pp.Vector3D()
    tmp_dir.set_spherical_coordinates(1, 0.181678, 1.94055)
    tmp_dir.cartesian_from_spherical()
    tmp_dir = -tmp_dir
    # print(tmp_dir)
    start_directions = [
        # [1, 0, 0],
        [1, 0, 0],
        # [1, 0, 0],
        # [1, 0, 0],
        [tmp_dir.x, tmp_dir.y, tmp_dir.z]
    ]
    start_energies = [
        # 1e9,
        3e5,
        # 1e5,
        # 1e5,
        158816
    ]

    for jdx in range(len(start_energies)):
        secondary_obj = propagate_particle(prop,
                                           position=start_positions[jdx],
                                           direction=start_directions[jdx],
                                           energy=start_energies[jdx])
        secondarys = secondary_obj.particles

        nsecs = len(secondarys)  # to get rid of the decay neutrinos
        positions = np.empty((nsecs, 3))
        secs_energy = np.empty(nsecs)
        mu_energies = np.empty(nsecs)
        secs_ids = np.empty(nsecs)

        for idx in range(nsecs):
            positions[idx] = np.array([
                secondarys[idx].position.x, secondarys[idx].position.y,
                secondarys[idx].position.z
            ])
            mu_energies[idx] = secondarys[idx].parent_particle_energy
            secs_energy[idx] = secondarys[
                idx].parent_particle_energy - secondarys[idx].energy
            if secondarys[idx].type == int(pp.particle.Interaction_Type.Epair):
                secs_ids[idx] = 0
            elif secondarys[idx].type == int(
                    pp.particle.Interaction_Type.Brems):
                secs_ids[idx] = 1
            elif secondarys[idx].type == int(
                    pp.particle.Interaction_Type.DeltaE):
                secs_ids[idx] = 2
            elif secondarys[idx].type == int(
                    pp.particle.Interaction_Type.NuclInt):
                secs_ids[idx] = 3
            elif secondarys[idx].type == int(
                    pp.particle.Interaction_Type.ContinuousEnergyLoss):
                secs_ids[idx] = 6
            # decay
            elif secondarys[idx].type == int(pp.particle.Particle_Type.EMinus):
                secs_ids[idx] = 4
            elif secondarys[idx].type == int(pp.particle.Particle_Type.NuMu):
                secs_ids[idx] = 5
            elif secondarys[idx].type == int(pp.particle.Particle_Type.NuEBar):
                secs_ids[idx] = 5
            else:
                print('unknown secondary id {}'.format(secondarys[idx].type))

        for idx in range(len(labels)):
            ax2.plot(positions[:, 0][secs_ids == idx],
                     secs_energy[secs_ids == idx] / 1e3,
                     ls='None',
                     marker='.',
                     label=labels[idx])

        last_sec = secondarys[-1]

        end_position = np.array(
            [[last_sec.position.x, last_sec.position.y, last_sec.position.z]])

        # now after ploting the losss, one can add the start position/energy of the muon to plot it
        positions = np.concatenate(
            ([start_positions[jdx]], positions, end_position), axis=0)
        mu_energies = np.concatenate(
            ([start_energies[jdx]], mu_energies, [prop.particle_def.mass]))

        entry_pos = secondary_obj.entry_point.position
        exit_pos = secondary_obj.exit_point.position
        closest_appr_pos = secondary_obj.closest_approach_point.position

        ax2.plot(positions[:, 0], mu_energies / 1e3, label=r'$E_{\mu}$')
        ax2.axhline(0.5, color='r', label='ecut')
        ax2.axvline(entry_pos.x, color='g', ls='-', label='entry/exit')
        ax2.axvline(exit_pos.x, color='g', ls='-')
        ax2.axvline(closest_appr_pos.x,
                    color='b',
                    ls='dotted',
                    label='closest approach')
        ax2.set_yscale('log')
        ax2.set_ylabel('Energy / GeV')
        ax2.set_xlabel('x coord. / cm')
        # ax2.legend()

        plt.subplots_adjust(hspace=.0)
        plt.setp(ax1.get_xticklabels(), visible=False)

        ax1.plot(positions[:, 0], positions[:, 2],
                 label='muon')  # {}'.format(jdx))
        ax1.plot([entry_pos.x, exit_pos.x], [entry_pos.z, exit_pos.z],
                 ls='None',
                 marker='x',
                 label='entry/exit')  # {}'.format(jdx))
        ax1.plot(closest_appr_pos.x,
                 closest_appr_pos.z,
                 ls='None',
                 marker='+',
                 label='closet approach')  # {}'.format(jdx))
        # ax1.plot([entry_pos.x, closest_appr_pos.x, exit_pos.x],
        #          [entry_pos.z, closest_appr_pos.z, exit_pos.z],
        #          ls='dotted', label='approx line')# {}'.format(jdx))

    ax1.legend()

    fig.savefig('entry_exit_points.png')

    plt.show()
예제 #10
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.DynamicData(particle_def.particle_type)
    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.Vector3D(0, 0, 0)
            init_particle.direction = pp.Vector3D(0, 0, -1)
            init_particle.energy = init_energy
            init_particle.propagated_distance = 0

            decay_products = channel.decay(particle_def, init_particle)
            for p in decay_products.particles:
                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))
예제 #11
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
예제 #12
0
def propagate():
    """ Propagte muon in ice threw a cylindric detector

    Returns:
        (Particle) Particle representing the start position
        (Geometry) Geometry of the detector
        (list)     List of secondarys particles represeint interactions
    """

    medium = pp.medium.Ice(1.0)
    geo_detector = pp.geometry.Cylinder(pp.Vector3D(), 800, 0, 1600)
    geo_outside = pp.geometry.Box(pp.Vector3D(), 500000, 500000, 500000)

    # Infront

    sec_def_infront = pp.SectorDefinition()
    sec_def_infront.medium = medium
    sec_def_infront.geometry = geo_outside
    sec_def_infront.particle_location = pp.ParticleLocation.infront_detector

    sec_def_infront.scattering_model = pp.scattering.ScatteringModel.Moliere

    sec_def_infront.cut_settings.ecut = -1
    sec_def_infront.cut_settings.vcut = 0.05

    # Inside

    sec_def_inside = pp.SectorDefinition()
    sec_def_inside.medium = medium
    sec_def_inside.geometry = geo_outside
    sec_def_inside.particle_location = pp.ParticleLocation.inside_detector

    sec_def_inside.scattering_model = pp.scattering.ScatteringModel.Moliere

    sec_def_inside.cut_settings.ecut = 500
    sec_def_inside.cut_settings.vcut = -1

    # Behind

    sec_def_behind = pp.SectorDefinition()
    sec_def_behind.medium = medium
    sec_def_behind.geometry = geo_outside
    sec_def_behind.particle_location = pp.ParticleLocation.behind_detector

    sec_def_behind.scattering_model = pp.scattering.ScatteringModel.Moliere

    sec_def_behind.cut_settings.ecut = -1
    sec_def_behind.cut_settings.vcut = 0.05

    # Interpolation defintion

    interpolation_def = pp.InterpolationDef()
    interpolation_def.path_to_tables = "~/.local/share/PROPOSAL/tables"
    interpolation_def.path_to_tables_readonly = "~/.local/share/PROPOSAL/tables"

    # Propagator
    mu_def = pp.particle.MuMinusDef()
    prop = pp.Propagator(
        particle_def=mu_def,
        sector_defs=[sec_def_infront, sec_def_inside, sec_def_behind],
        detector=geo_detector,
        interpolation_def=interpolation_def
    )

    mu = pp.particle.DynamicData(mu_def.particle_type)

    # Set energy and position of the particle

    mu.energy = 9e6
    mu.direction = pp.Vector3D(0, 0, 1)

    pos = mu.position
    pos.set_cartesian_coordinates(0, 0, -1e5)
    mu.position = pos

    # mu_start = pp.particle.Particle(mu)

    secondarys = prop.propagate(mu).particles

    return mu, geo_detector, secondarys
예제 #13
0
import proposal as pp
import matplotlib.pyplot as plt
from tqdm import tqdm

if __name__ == "__main__":

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

    energy = 1e7  # MeV
    statistics = 10000

    sec_def = pp.SectorDefinition()
    sec_def.medium = pp.medium.Ice(1.0)
    sec_def.geometry = pp.geometry.Sphere(pp.Vector3D(), 1e20, 0)
    sec_def.particle_location = pp.ParticleLocation.inside_detector

    sec_def.scattering_model = pp.scattering.ScatteringModel.Moliere
    sec_def.crosssection_defs.brems_def.lpm_effect = False
    sec_def.crosssection_defs.epair_def.lpm_effect = False

    sec_def.cut_settings.ecut = 500
    sec_def.cut_settings.vcut = 0.05

    interpolation_def = pp.InterpolationDef()
    interpolation_def.path_to_tables = "~/.local/share/PROPOSAL/tables"
    interpolation_def.path_to_tables_readonly = "~/.local/share/PROPOSAL/tables"

    prop = pp.Propagator(particle_def=pp.particle.MuMinusDef(),
                         sector_defs=[sec_def],
예제 #14
0
    pp.medium.Ice(1.0),
    pp.medium.Hydrogen(1.0),
    pp.medium.Uranium(1.0)
]

cuts = [
    pp.EnergyCutSettings(-1, -1),
    pp.EnergyCutSettings(500, -1),
    pp.EnergyCutSettings(-1, 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.Vector3D(0, 0, 0)
direction_init = pp.Vector3D(1, 0, 0)
direction_init.spherical_from_cartesian()

interpoldef = pp.InterpolationDef()
pp.RandomGenerator.get().set_seed(1234)


def create_table_scatter(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 idx, parametrization in enumerate(parametrizations):
    return 64 * G_F**2 * p1 * p2


if __name__ == "__main__":

    # =========================================================
    # 	Save energies
    # =========================================================

    statistics = int(1e5)
    binning = np.linspace(0, 0.5, 50)

    pdef = pp.particle.MuMinusDef()
    mu = pp.particle.DynamicData(pdef.particle_type)
    mu.direction = pp.Vector3D(0, 0, -1)

    products = [pp.particle.EMinusDef(), pp.particle.NuMuDef(), pp.particle.NuEBarDef()]

    lep_ME = pp.decay.ManyBodyPhaseSpace(products, evaluate)
    lep = pp.decay.LeptonicDecayChannelApprox(*products)

    E_lep_ME = []
    E_lep = []

    passed_time = 0.0

    for i in tqdm(range(statistics)):
        mu.position = pp.Vector3D(0, 0, 0)
        mu.direction = pp.Vector3D(0, 0, -1)
        mu.energy = pdef.mass
예제 #16
0
 def x_to_pp_pos(self, x: float, rad: float):
     #compute direction and position in proposal body
     phi = 2. * self.theta
     pos_vec = pp.Vector3D(0, 0, x * rad * (1 - self.depth))
     return pos_vec
예제 #17
0
 def x_to_pp_dir(self, x: float):
     dir_vec = pp.Vector3D(0, 0., 1.)
     return dir_vec
def propagate_muons():

    mu_def = pp.particle.MuMinusDef()
    geometry = pp.geometry.Sphere(pp.Vector3D(), 1.e20, 0.0)
    ecut = 500
    vcut = 5e-2

    sector_def = pp.SectorDefinition()
    sector_def.cut_settings = pp.EnergyCutSettings(ecut, vcut)
    sector_def.medium = pp.medium.StandardRock(1.0)
    sector_def.geometry = geometry
    sector_def.scattering_model = pp.scattering.ScatteringModel.NoScattering
    sector_def.crosssection_defs.brems_def.lpm_effect = False
    sector_def.crosssection_defs.epair_def.lpm_effect = False
    # sector_def.crosssection_defs.photo_def.parametrization = pp.parametrization.photonuclear.PhotoParametrization.BezrukovBugaev
    # sector_def.do_stochastic_loss_weighting = True
    # sector_def.stochastic_loss_weighting = -0.1

    detector = geometry

    interpolation_def = pp.InterpolationDef()
    interpolation_def.path_to_tables = "~/.local/share/PROPOSAL/tables"
    interpolation_def.path_to_tables_readonly = "~/.local/share/PROPOSAL/tables"

    prop = pp.Propagator(mu_def, [sector_def], detector, interpolation_def)

    statistics_log = 4
    statistics = int(10**statistics_log)
    propagation_length = 1e4 # cm
    E_min_log = 10.0
    E_max_log = 10.0
    spectral_index = 1.0
    pp.RandomGenerator.get().set_seed(1234)

    # muon_energies = np.logspace(E_min_log, E_max_log, statistics)
    # muon_energies = power_law_sampler(spectral_index, 10**E_min_log, 10**E_max_log, statistics)
    muon_energies = np.ones(statistics)*10**10

    epair_secondary_energy = []
    brems_secondary_energy = []
    ioniz_secondary_energy = []
    photo_secondary_energy = []

    mu_prop = pp.particle.DynamicData(mu_def.particle_type)
    mu_prop.position = pp.Vector3D(0, 0, 0)
    mu_prop.direction = pp.Vector3D(0, 0, -1)
    mu_prop.propagated_distance = 0

    for mu_energy in tqdm(muon_energies):

        mu_prop.energy = mu_energy

        secondarys = prop.propagate(mu_prop, propagation_length)

        for sec in secondarys.particles:
            log_sec_energy = np.log10(sec.parent_particle_energy - sec.energy)

            if sec.type == int(pp.particle.Interaction_Type.Epair):
                epair_secondary_energy.append(log_sec_energy)
            if sec.type == int(pp.particle.Interaction_Type.Brems):
                brems_secondary_energy.append(log_sec_energy)
            if sec.type == int(pp.particle.Interaction_Type.DeltaE):
                ioniz_secondary_energy.append(log_sec_energy)
            if sec.type == int(pp.particle.Interaction_Type.NuclInt):
                photo_secondary_energy.append(log_sec_energy)

    # =========================================================
    #   Write
    # =========================================================

    np.savez(
        'data_sec_dist_{}_{}_Emin_{}_Emax_{}'.format(
            mu_def.name,
            sector_def.medium.name.lower(),
            E_min_log,
            E_max_log,
            ecut,
            vcut),
        brems=brems_secondary_energy,
        epair=epair_secondary_energy,
        photo=photo_secondary_energy,
        ioniz=ioniz_secondary_energy,
        statistics=[statistics],
        E_min=[E_min_log],
        E_max=[E_max_log],
        spectral_index=[spectral_index],
        distance=[propagation_length / 100],
        medium_name=[sector_def.medium.name.lower()],
        particle_name=[mu_def.name],
        ecut=[ecut],
        vcut=[vcut]
    )
    return 4. * (G_F * V_ud * form_factor(q2))**2 * Y


if __name__ == "__main__":

    # =========================================================
    # 	Save energies
    # =========================================================

    statistics = int(1e5)
    binning = 50

    tau_def = pp.particle.TauMinusDef()
    tau = pp.particle.DynamicData(tau_def.particle_type)
    tau.energy = tau_def.mass
    tau.direction = pp.Vector3D(0, 0, -1)

    products = [
        pp.particle.Pi0Def(),
        pp.particle.PiMinusDef(),
        pp.particle.NuTauDef()
    ]

    products_particles = [
        pp.particle.DynamicData(p.particle_type) for p in products
    ]
    for p in products_particles:
        p.direction = pp.Vector3D(0, 0, -1)
        p.energy = 1e2

    print(evaluate(tau, products_particles))
예제 #20
0
파일: chord.py 프로젝트: icecube/TauRunner
 def x_to_pp_pos(self, x: float, rad: float):
     #compute direction and position in proposal body
     pos_vec = pp.Vector3D(
         self._s * rad * self._t * (1 - x), 0,
         -self._c * rad * self._t * (1 - x) + (1 - self.depth) * rad)
     return pos_vec
예제 #21
0
파일: chord.py 프로젝트: icecube/TauRunner
 def x_to_pp_dir(self, x: float):
     direction = [-self._s, 0, self._c]
     dir_vec = pp.Vector3D(direction[0], 0., direction[2])
     return dir_vec
예제 #22
0
def test_proposal():

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

    energy = 1e8  # MeV
    statistics = 100

    sec_def = pp.SectorDefinition()
    sec_def.medium = pp.medium.Ice(1.0)
    sec_def.geometry = pp.geometry.Sphere(pp.Vector3D(), 1e20, 0)
    sec_def.particle_location = pp.ParticleLocation.inside_detector

    sec_def.do_continuous_energy_loss_output = True

    sec_def.scattering_model = pp.scattering.ScatteringModel.HighlandIntegral
    sec_def.crosssection_defs.brems_def.lpm_effect = False
    sec_def.crosssection_defs.epair_def.lpm_effect = False

    sec_def.cut_settings.ecut = 500
    sec_def.cut_settings.vcut = 0.05

    interpolation_def = pp.InterpolationDef()
    interpolation_def.path_to_tables = table_path
    interpolation_def.path_to_tables_readonly = table_path

    mu_def = pp.particle.MuMinusDef()
    prop = pp.Propagator(particle_def=mu_def,
                         sector_defs=[sec_def],
                         detector=pp.geometry.Sphere(pp.Vector3D(), 1e20, 0),
                         interpolation_def=interpolation_def)

    mu = pp.particle.DynamicData(mu_def.particle_type)

    mu.position = pp.Vector3D(0, 0, 0)
    mu.direction = pp.Vector3D(0, 0, -1)
    mu.energy = energy
    mu.propagated_distance = 0

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

        secondaries = prop.propagate(mu).particles

        for idx, sec in enumerate(secondaries[1:-1]):
            if sec.type == int(ContinuousEnergyLoss):
                if (secondaries[idx - 1].type == int(ContinuousEnergyLoss)
                        or secondaries[idx + 1].type
                        == int(ContinuousEnergyLoss)):
                    print("2 Continuous Losses in a row")
                    continue

                energy_diff = secondaries[idx - 1].energy - secondaries[
                    idx + 1].parent_particle_energy
                continuou_energy_lost = sec.parent_particle_energy - sec.energy
                assert energy_diff == approx(continuou_energy_lost,
                                             abs=1e-3), "Energy differs"

                time_diff = secondaries[idx + 1].time - secondaries[idx -
                                                                    1].time
                assert time_diff == approx(sec.time, abs=1e-3), "Time differs"
예제 #23
0
    # pp.medium.Uranium(1.0)
]

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.Vector3D(0, 0, 0)
direction = pp.Vector3D(1, 0, 0)

# stopping_decay = True
# do_continuous_randomization = True
# do_exact_time_calculation = True
interpoldef = pp.InterpolationDef()
interpoldef.path_to_tables = "~/.local/share/PROPOSAL/tables"
interpoldef.path_to_tables_readonly = "~/.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: