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 sector_def = pp.SectorDefinition() sector_def.cut_settings = cut sector_def.medium = medium sector = pp.Sector(particle_def, sector_def, interpoldef) 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): loss, interaction_type = sector.make_stochastic_loss( energy) energy -= loss buf.append(str(energy)) buf.append(str(interaction_type)) buf.append( str(pp.RandomGenerator.get().random_double())) buf.append("\n") file.write("\t".join(buf))
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: energy = initial_energy sector_def = pp.SectorDefinition() sector_def.cut_settings = cut sector_def.medium = medium sector = pp.Sector(particle_def, sector_def, interpoldef) 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): energy = max( sector.energy_decay( energy, pp.RandomGenerator.get().random_double()), sector.energy_interaction( energy, pp.RandomGenerator.get().random_double())) buf.append(str(energy)) buf.append("\n") file.write("\t".join(buf))
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))
def create_table_energy_displacement(dir_name): pp.RandomGenerator.get().set_seed(1234) with open(dir_name + "Sector_Energy_Distance.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)) for disp in np.geomspace(1e0, 1e7, statistics): energy_disp = sector.energy_distance(energy, disp) buf.append(str(disp)) buf.append(str(energy_disp)) buf.append("\n") file.write("\t".join(buf))
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
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
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
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"
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
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] )
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],