|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +""" |
| 4 | +Inspector of the HepMC file |
| 5 | +""" |
| 6 | + |
| 7 | +import pyhepmc_ng as hep |
| 8 | +import argparse |
| 9 | + |
| 10 | + |
| 11 | +poi = {} |
| 12 | +poi_names = {2212: "Proton", -2212: "AntiProton", |
| 13 | + 2112: "Neutron", -2112: "AntiNeutron", |
| 14 | + 3122: "Lambda0", 1000010020: "Deuteron", |
| 15 | + 1000020030: "Triton", 1000020040: "Alpha", |
| 16 | + 1000020030: "Helium3"} |
| 17 | + |
| 18 | +for i in poi_names: |
| 19 | + poi[i] = 0 |
| 20 | + |
| 21 | + |
| 22 | +def main(file_name, min_event, max_event, verbose): |
| 23 | + print("Reading", file_name, "between", |
| 24 | + min_event, "and", max_event, "events") |
| 25 | + |
| 26 | + def print_evt(evt): |
| 27 | + def msg(*m): |
| 28 | + if verbose: |
| 29 | + print(*m) |
| 30 | + msg("event_number:", evt.event_number) |
| 31 | + msg("Units:", "momentum_unit:", evt.momentum_unit, |
| 32 | + "length_unit:", evt.length_unit) |
| 33 | + msg(len(evt.particles), "particles:") |
| 34 | + for i in enumerate(evt.particles): |
| 35 | + pdg = i[1].pid |
| 36 | + if pdg in poi: |
| 37 | + poi[pdg] = poi[pdg]+1 |
| 38 | + pdg = f"{pdg} is of interest!!!" |
| 39 | + msg(i, "PDG code", pdg) |
| 40 | + msg(len(evt.vertices), "vertices:") |
| 41 | + for i in enumerate(evt.vertices): |
| 42 | + msg("Vertex:", i) |
| 43 | + vertex_pdgs = [] |
| 44 | + msg("Input particles") |
| 45 | + for j in i[1].particles_in: |
| 46 | + msg("\t", j, "pdg", j.pid) |
| 47 | + msg("Output particles") |
| 48 | + for j in i[1].particles_out: |
| 49 | + msg("\t", j, "pdg", j.pid) |
| 50 | + vertex_pdgs.append(j.pid) |
| 51 | + if 2212 in vertex_pdgs and 2112 in vertex_pdgs: |
| 52 | + print(evt.event_number, "Has both") |
| 53 | + print(i) |
| 54 | + for j in i[1].particles_out: |
| 55 | + print(j) |
| 56 | + |
| 57 | + with hep.open(file_name) as f: |
| 58 | + while True: |
| 59 | + e = f.read() |
| 60 | + if not e: |
| 61 | + break |
| 62 | + if e.event_number < min_event: |
| 63 | + continue |
| 64 | + print_evt(e) |
| 65 | + if e.event_number >= max_event: |
| 66 | + break |
| 67 | + for i in poi: |
| 68 | + print("Number of", poi_names[i]+"s", poi[i]) |
| 69 | + |
| 70 | + |
| 71 | +if __name__ == "__main__": |
| 72 | + parser = argparse.ArgumentParser(description=__doc__) |
| 73 | + parser.add_argument("hepmcfile", type=str, |
| 74 | + help="Input hepmc file.") |
| 75 | + parser.add_argument("--start", type=int, default=0, |
| 76 | + help="Start of the event counter.") |
| 77 | + parser.add_argument("--stop", type=int, default=100, |
| 78 | + help="Stop of the event counter.") |
| 79 | + parser.add_argument("-v", action="store_true", |
| 80 | + help="Verbose mode.") |
| 81 | + args = parser.parse_args() |
| 82 | + main(args.hepmcfile, min_event=args.start, |
| 83 | + max_event=args.stop, verbose=args.v) |
0 commit comments