def request_generator(values, init_pos): """ """ text = """/gps/particle ${particle} /gps/number 1 /gps/direction ${dirX} 0.0 ${dirZ} /gps/ene/mono ${energy} MeV /gps/position ${posX} 0. ${posZ} m /run/beamOn ${number} """ template = Template(text) for value in values_from_dict(values): theta = value["theta"] radius = value["radius"] theta = np.deg2rad(theta) shift = value["shift"] posX = radius * np.sin(theta) posZ = radius * np.cos(theta) dirX = -np.sin(theta) dirZ = -np.cos(theta) value["posX"] = posX + init_pos[0] + shift value["posZ"] = posZ + init_pos[2] value["dirX"] = dirX value["dirZ"] = dirZ request = template.substitute(value) yield QueueData(value, request)
def input_generator_critical_energy(): gdml_template = os.path.join(ROOT_PATH, "template", "critical_energy.gdml") macros_template = Template(INPUT_TEMPLATE) count = 0 ratio = 0.03 cep = CriticalEnergyProvider() for h_index, height in enumerate(np.arange(0.0, 16000.0, 1000.0)): # 16000.0 min_field = get_minimal_field(height) for field in np.arange(min_field, min_field * 1.5, min_field * ratio): values_gdml = { 'height': height, 'field': field * 1e-4, } critical_energy = cep.get_critical_energy(height, field * 1e-4) paths, _ = create_gdml(gdml_template, values_gdml, h_index) gdml_path = paths[0] values = { "path": [os.path.join("..", gdml_path)], "physics": ["standard_opt_4"], 'number': [1000], 'min_energy': [critical_energy], } for path, values in zip( dir_name_generator(".", "sim", start=count), values_from_dict(values)): count += 1 text = macros_template.substitute(values) input_data_meta = {"macros": values, "gdml": values_gdml} data = InputData(text=text, path=path, values=Meta(input_data_meta)) yield data
def input_generator_neutron(gdml_path, physics): values = { "path": [gdml_path], "physics": [physics], 'number': [10000 for i in range(10)], 'energy': [100], } macros_template = Template(INPUT_TEMPLATE) for path, values in zip(dir_name_generator(".", "sim"), values_from_dict(values)): text = macros_template.substitute(values) input_data_meta = {"macros": values, "gdml": {}} data = InputData(text=text, path=path, values=Meta(input_data_meta)) yield data
def input_generator_custom_gdml_dwyer2003(meta: Meta, gdml_template_file: str, macros_template: str, gdml_generator: GdmlGenerator): paths, values_gdml = gdml_generator.generate(gdml_template_file) paths = list(map(lambda x: os.path.join("..", x), paths)) meta["macros"]["path"] = paths macros_template = Template(macros_template) for path, values in zip(dir_name_generator(".", "sim"), values_from_dict(meta["macros"])): path_gdml = values["path"] indx = paths.index(path_gdml) gdml = values_gdml[indx] values["posZ"] = gdml["cellHeight"] / 2 - 0.1 text = macros_template.substitute(values) input_data_meta = {"macros": values, "gdml": gdml} data = InputData(text=text, path=path, values=Meta(input_data_meta)) yield data
def input_generator_critical_energy(): gdml_template = os.path.join(ROOT_PATH, "template", "critical_energy.gdml") macros_template = Template(INPUT_TEMPLATE) count = 0 zero_field_min, zero_field_max = 3.0, 11.0 zero_density = atmosphere.ISACalculator.density(0.0) gdml_index = 0 for height in np.arange(0.0, 16000.0, 1000.0): density = atmosphere.ISACalculator.density(height) ratio = zero_density / density field_min = np.floor(zero_field_min / ratio) field_max = np.ceil(zero_field_max / ratio) for field in np.linspace(field_min, field_max, 10): temp = get_critical_energy(height, field) if temp is None or not temp.converged: continue critical_energy = temp.root values_gdml = { 'height': height, 'field': field * 1e-4, } paths, _ = create_gdml(gdml_template, values_gdml, gdml_index) gdml_index += 1 gdml_path = paths[0] values = { "path": [os.path.join("..", gdml_path)], "physics": ["standard_opt_4"], 'number': [1000], 'energy': np.arange(critical_energy, critical_energy * 3, 0.005), 'min_energy': [critical_energy], } for path, values in zip( dir_name_generator(".", "sim", start=count), values_from_dict(values)): count += 1 text = macros_template.substitute(values) input_data_meta = {"macros": values, "gdml": values_gdml} data = InputData(text=text, path=path, values=Meta(input_data_meta)) yield data
def input_generator_satellite(meta: Meta, macros_template: str, init_pos): macros_template = Template(macros_template) for path, values in zip(dir_name_generator(".", "sim"), values_from_dict(meta["macros"])): theta = values["theta"] radius = values["radius"] theta = np.deg2rad(theta) shift = values["shift"] posX = radius * np.sin(theta) posZ = radius * np.cos(theta) dirX = -np.sin(theta) dirZ = -np.cos(theta) values["posX"] = posX + init_pos[0] + shift values["posZ"] = posZ + init_pos[2] values["dirX"] = dirX values["dirZ"] = dirZ text = macros_template.substitute(values) input_data_meta = { "macros": values, } data = InputData(text=text, path=path, values=Meta(input_data_meta)) yield data