def gen_arrays(selection): print("Selection = ", selection) for event in hepmc_write('events.hepmc', pythia(events=1)): array1 = event.all(selection) for event in hepmc_read('events.hepmc'): array2 = event.all(selection) return np.array(array1), np.array(array2)
def gen_arrays(selection): # Shows how to generate the events and save those to a plaintext # file or load the events in a plaintext file and print("Selection = ", selection) for event in hepmc_write('events.hepmc', pythia(events=num_events)): array1 = event.all(selection) for event in hepmc_read('events.hepmc'): array2 = event.all(selection) print(array1 == array2) return np.array(array1), np.array(array2)
def test_first_example(): pythia = Pythia(get_cmnd('w'), random_state=1) selection = ((STATUS == 1) & ~HAS_END_VERTEX & (ABS_PDG_ID != 12) & (ABS_PDG_ID != 14) & (ABS_PDG_ID != 16)) # generate events while writing to ascii hepmc for event in hepmc_write('events.hepmc', pythia(events=1)): array1 = event.all(selection) # read the same event back from ascii hepmc for event in hepmc_read('events.hepmc'): array2 = event.all(selection) assert_array_equal(array1, array2)
def get_group_events(name, num_events, seed, train): # Generate group of Monte Carlo simulated proton-antiproton collision events # at the LHC, composed by particle readings (px,py,pz,e,m). # Input: name.cmnd config file for Pythia simulator. # generate events while writing to ascii hepmc momentum_four = ['px', 'py', 'pz', 'E'] #'mass', 'pdgid' group_events = [] pythia = Pythia(os.path.join('./data/cfgs/', name + '.cmnd'), random_state=seed) for event in hepmc_write('events.hepmc', pythia(events=num_events)): particles = event.all() if train == True: # If training, then return only background signals, not Higgs reading. particles = particles[particles['pdgid'] != 25] # Filter and transform np structured array to ndarray X = particles[momentum_four].copy() particles = X.view(np.float64).reshape(X.shape + (-1, )) group_events.append(particles) return group_events
from numpythia import Pythia, hepmc_write, hepmc_read from numpythia import STATUS, HAS_END_VERTEX, ABS_PDG_ID from numpythia.testcmnd import get_cmnd from numpy.testing import assert_array_equal pythia = Pythia(get_cmnd('w'), random_state=1) print(pythia.weight_labels) selection = ((STATUS == 1) & ~HAS_END_VERTEX & (ABS_PDG_ID != 12) & (ABS_PDG_ID != 14) & (ABS_PDG_ID != 16)) # generate events while writing to ascii hepmc for event in hepmc_write('events.hepmc', pythia(events=1)): array1 = event.all(selection) print(event.weights) # find W and descendants array_w = event.first(ABS_PDG_ID == 24).descendants(selection) print(array_w) # read the same event back from ascii hepmc for event in hepmc_read('events.hepmc'): array2 = event.all(selection) assert_array_equal(array1, array2)