def no_gdmL_input_generator(meta: Meta, macros_template: str): macros_template = Template(macros_template) for path, values in zip(dir_name_generator(".", "sim"), values_from_dict(meta)): text = macros_template.substitute(values) data = InputData(text=text, path=path, values=Meta(values)) yield data
def test_run(): logging.basicConfig(filename="run.log") logging.root.setLevel(logging.DEBUG) gdml_template = os.path.join(ROOT_PATH, "..", "..", "simulation_scripts", "thunderstorm", "template", "dwyer2003.gdml") print(gdml_template) values_gdml = { 'height': [5000, 6000], 'fieldValueZ': [2e-4, 1e-4], } values_macros = { 'number': [int(1e2)], 'energy': [i for i in range(1, 3)], 'posZ': [49.5], 'direction': ['0 0 -1', '0.5 0 -0.5'], 'particle': 'e-' } meta = Meta({"macros": values_macros, "gdml": values_gdml}) input_data = general_input_generator(meta, gdml_template, INPUT_TEMPLATE) command = "../build/thunderstorm/geant4-thunderstorm.exe" readers = READERS_CYLINDER_DATA + READERS_TXT multirun_command(input_data, command, post_processor=get_convertor(readers, "./result.hdf5")) return 0
def main(): logging.basicConfig(filename="run.log") logging.root.setLevel(logging.DEBUG) gdml_template = os.path.join(ROOT_PATH, "template", "cylinder.gdml") values_gdml = { 'height': [0], 'cellHeight': [600], 'fieldValueZ': [0, 3e-4, 10e-4], } values_macros = { "physics": [ "standard", "standard_opt_1", "standard_opt_2", "standard_opt_3", "standard_opt_4", "penelopa", "livermore", "emlowepphysics" ], 'number': [int(1000)], 'energy': [10], 'posZ': [299.9], 'direction': ['0 0 -1'], 'particle': 'e-' } meta = Meta({"macros": values_macros, "gdml": values_gdml}) input_data = general_input_generator(meta, gdml_template, INPUT_TEMPLATE) command = "../build/thunderstorm/geant4-thunderstorm.exe" readers = READERS_CYLINDER_DATA + READERS_TXT multirun_command(input_data, command, post_processor=get_convertor(readers, "./result.hdf5", clear=False)) return 0
def main(): logging.basicConfig(filename="run.log") logging.root.setLevel(logging.DEBUG) values_macros = { "type": ["pie"], "physics": ["FTFP_BERT_opt4"], "high": [4225], "low": [3225], "cut": [0.05], 'number': [10], 'posZ': [499.5], 'particle': ['mu-', 'mu+'], 'field_z': [0.0, 200.0, 220.0], } meta = Meta(values_macros) input_data = no_gdmL_input_generator(meta, INPUT_TEMPLATE) command = "../../build/thunderstorm/geant4-thunderstorm.exe" readers = [ ProtoSetReader("particle_detector.bin", ParticleDetectorProtoSet) ] multirun_command(input_data, command, post_processor=get_convertor(readers, "./result.hdf5", clear=True)) return 0
def main(): logging.basicConfig(filename="run.log") logging.root.setLevel(logging.DEBUG) gdml_template = os.path.join(ROOT_PATH, "template", "cylinder.gdml") values_macros = { "cut": [0.05], 'number': [10], 'energy': [1.0], 'direction': ['0 0 -1'], 'particle': 'e-' } meta = Meta({ "macros": values_macros, }) input_data = input_generator_custom_gdml_dwyer2003(meta, gdml_template, INPUT_TEMPLATE, gdml_generator) command = "../../build/thunderstorm/geant4-thunderstorm.exe" readers = READERS_CYLINDER_ID_DATA + READERS_TXT + READER_TREE_SOCKET_DATA multirun_command(input_data, command, post_processor=get_convertor(readers, "./result.hdf5", clear=True)) return 0
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 main(): logging.basicConfig(filename="run.log") logging.root.setLevel(logging.DEBUG) gdml_template = os.path.join(ROOT_PATH, "template", "cylinder.gdml") values_gdml = { 'height': [0], 'cellHeight': [600], 'fieldValueZ': [10e-4], #np.arange(2,11)*1e-4, } values_macros = { "physics": ["standard_opt_4"], "cut": [0.005], 'number': [int(10)], 'energy': np.arange(), 'posZ': [200], 'direction': ['0 0 -1'], 'particle': 'e-' } meta = Meta({"macros": values_macros, "gdml": values_gdml}) input_data = general_input_generator(meta, gdml_template, INPUT_TEMPLATE) command = "../../build/thunderstorm/geant4-thunderstorm.exe" readers = [ProtoSetReader("stacking_simple.bin", CylinderProtoSet)] multirun_command(input_data, command, post_processor=get_convertor(readers, "./result.hdf5", clear=False)) return 0
def find_group_by_meta(filename, **kwargs): result = [] with open_file(filename) as h5file: for group in h5file.root: meta = h5file.get_node(group, "meta") meta = Meta(meta) flag = True for key, value in kwargs: if meta[key] != value: flag = False break if flag: result.append(group._v_pathname) return result
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(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"])): text = macros_template.substitute(values) path_gdml = values["path"] indx = paths.index(path_gdml) input_data_meta = {"macros": values, "gdml": values_gdml[indx]} data = InputData(text=text, path=path, values=Meta(input_data_meta)) yield data
def find_group_by_meta(filename, **kwargs): result = [] with tables.open_file(filename) as h5file: for group in h5file.root: meta = h5file.get_node(group, "meta").read() meta = Meta(json.loads(meta)) flag = True for key, value in kwargs.items(): name = Name.from_string(key.replace("_", ".")) if meta[name] != value: flag = False break if flag: result.append(group._v_pathname) return result
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 main(): logging.basicConfig(filename="run.log") logging.root.setLevel(logging.DEBUG) gdml_template = os.path.join(ROOT_PATH, "template", "cylinder.gdml") values_macros = { "cut": [0.05], "physics": ["standard_opt_4"], 'number': [2], 'energy': [1.0], 'direction': ['0 0 -1'], 'particle': 'e-' } meta = Meta({ "macros": values_macros, }) # fields = [10e-4, 7e-4, 6.0e-4, 5.5e-4, 5.0e-4, 4.5e-4, 4.0e-4] # heights = [200, 300, 400, 400, 500, 700, 1000] fields = [10e-4, 7e-4] heights = [200, 300] ggfh = GGFieldHeigth(fields, heights) input_data = input_generator_custom_gdml_dwyer2003(meta, gdml_template, INPUT_TEMPLATE, ggfh) command = "../../build/thunderstorm/geant4-thunderstorm.exe" readers = [ ProtoSetReader("treeTracking.bin", CylinderProtoSet), ProtoSetReader("gammaSeed.bin", CylinderProtoSet), ProtoSetReader("positronSeed.bin", CylinderProtoSet), ProtoSetReader("histogram.bin", HistogramProtoSet) ] multirun_command(input_data, command, post_processor=get_convertor(readers, "./result.hdf5", clear=True)) return 0
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
def main(): logging.basicConfig(filename="run.log") logging.root.setLevel(logging.DEBUG) OUTPUT_FILE = "result.hdf5" values_macros = { "mode": "single", # or "sum" Сожранение или всех симуляций или среднего значения. "radius": 0.15, # "shift": [0.0, 0.005, 0.016], # "theta": [0.0, 10.0, 20., 30.0, 50.0, 70.0], "shift": 0.0, # Сдвиг относительно центральной оси, может быть списком "theta": 0.0, # Отклонение от центральной оси, может быть списком "theta_unit": "degree", 'energy': np.arange(10.0, 15.1, 1.0), # Набор энергий для симуляции 'number': [100], # Число событий в одной симуляции # 'particle': 'e-' 'particle': 'proton' # Запускаемая частица } meta = Meta({ "macros": values_macros, }) input_data = input_generator_satellite(meta, INPUT_TEMPLATE, init_pos=[0.0, 0.0, 0.1]) command = "../../build/satellite/geant4-satellite.exe" readers = [ ProtoReader("deposit.proto.bin", proto_convertor=convert_satellite_proto) ] multirun_command(input_data, command, post_processor=get_convertor(readers, OUTPUT_FILE, clear=True)) return 0
def to_meta(self) -> 'Meta': return Meta({ "path": self.path, "text": self.text, "values": self.values })