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 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/parameterisations/Par04/training/utils/preprocess.py (Version 11.3.0) and /examples/extended/parameterisations/Par04/training/utils/preprocess.py (Version 9.5.p1)


  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