diff --git a/utils/fluka_to_slcio.py b/utils/fluka_to_slcio.py index 8cdc65e..0e2fd16 100755 --- a/utils/fluka_to_slcio.py +++ b/utils/fluka_to_slcio.py @@ -122,7 +122,7 @@ def bytes_from_file(filename): break # Extracting relevant values from the line - fid,e, x,y,z, cx,cy,cz, toff,toff_mo = (data[n][0] for n in [ + fid,e_kin, x,y,z, cx,cy,cz, toff,toff_mo = (data[n][0] for n in [ 'fid', 'E', 'x','y','z', 'cx', 'cy', 'cz', @@ -143,14 +143,6 @@ def bytes_from_file(filename): if args.t_max is not None and t > args.t_max: continue - # Calculating the components of the momentum vector - mom = np.array([cx, cy, cz], dtype=np.float32) - mom *= e - - # Skipping if it's a neutron with too low kinetic energy - if args.ne_min is not None and abs(pdg) == 2112 and np.linalg.norm(mom) < args.ne_min: - continue - # Getting the charge and mass of the particle if pdg not in PDG_PROPS: print('WARNING! No properties defined for PDG ID: {0:d}'.format(pdg)) @@ -158,6 +150,15 @@ def bytes_from_file(filename): continue charge, mass = PDG_PROPS[pdg] + # Calculating the components of the momentum vector from the kinetic energy + mom_tot = sqrt(e_kin**2 + 2 * e_kin * mass) + mom = np.array([cx, cy, cz], dtype=np.float32) + mom *= mom_tot + + # Skipping if it's a neutron with too low kinetic energy + if args.ne_min is not None and abs(pdg) == 2112 and e_kin < args.ne_min: + continue + # Calculating how many random copies of the particle to create according to the weight nP_frac, nP = math.modf(args.normalization) if nP_frac > 0 and random.random() < nP_frac: