Geant4 Cross Reference |
1 import h5py 2 import numpy as np 3 4 from core.constants import INIT_DIR, ORIGINAL_ 5 6 7 # preprocess function loads the data and retur 8 def preprocess(): 9 energies_train = [] 10 cond_e_train = [] 11 cond_angle_train = [] 12 cond_geo_train = [] 13 # This example is trained using 2 detector 14 for geo in ["SiW", "SciPb"]: 15 dir_geo = INIT_DIR + geo + "/" 16 # loop over the angles in a step of 10 17 for angle_particle in range(MIN_ANGLE, 18 f_name = f"{geo}_angle_{angle_part 19 f_name = dir_geo + f_name 20 # read the HDF5 file 21 h5 = h5py.File(f_name, "r") 22 # loop over energies from min_ener 23 energy_particle = MIN_ENERGY 24 while energy_particle <= MAX_ENERG 25 # scale the energy of each cel 26 events = np.array(h5[f"{energy 27 energies_train.append(events.r 28 # build the energy and angle c 29 cond_e_train.append([energy_pa 30 cond_angle_train.append([angle 31 # build the geometry condition 32 if geo == "SiW": 33 cond_geo_train.append([[0, 34 if geo == "SciPb": 35 cond_geo_train.append([[1, 36 energy_particle *= 2 37 # return numpy arrays 38 energies_train = np.concatenate(energies_t 39 cond_e_train = np.concatenate(cond_e_train 40 cond_angle_train = np.concatenate(cond_ang 41 cond_geo_train = np.concatenate(cond_geo_t 42 return energies_train, cond_e_train, cond_ 43 44 45 # get_condition_arrays function returns condit 46 # particles 47 """ 48 - geo : name of the calorimeter geometry ( 49 - energy_particle : energy of the primary 50 - nb_events : number of events 51 """ 52 53 54 def get_condition_arrays(geo, energy_particle, 55 cond_e = [energy_particle / MAX_ENERGY] * 56 cond_angle = [energy_particle / MAX_ENERGY 57 if geo == "SiW": 58 cond_geo = [[0, 1]] * nb_events 59 else: # geo == "SciPb" 60 cond_geo = [[1, 0]] * nb_events 61 cond_e = np.array(cond_e) 62 cond_angle = np.array(cond_angle) 63 cond_geo = np.array(cond_geo) 64 return cond_e, cond_angle, cond_geo 65 66 67 # load_showers function loads events from a si 68 """ 69 - init_dir: the name of the directory whic 70 - geo : name of the calorimeter geometry ( 71 - energy_particle : energy of the primary 72 - angle_particle : angle of the primary pa 73 """ 74 75 76 def load_showers(init_dir, geo, energy_particl 77 dir_geo = init_dir + geo + "/" 78 f_name = f"{geo}_angle_{angle_particle}.h5 79 f_name = dir_geo + f_name 80 # read the HDF5 file 81 h5 = h5py.File(f_name, "r") 82 energies = np.array(h5[f"{energy_particle} 83 return energies