Skip to content

Commit

Permalink
Merge pull request #56 from SNEWS2/JostMigenda/JUNOOutputFile
Browse files Browse the repository at this point in the history
JUNO: don’t write secondary file in verbose mode
  • Loading branch information
JostMigenda authored May 3, 2024
2 parents 3553a7e + 0e65947 commit 967f71e
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions src/sntools/genevts.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,28 @@ def main():

# Sort events by time and write them to an output file
events.sort(key=lambda evt: evt.time)
with open(args.output, "w") as outfile:
if args.verbose: # write parameters to file as a comment
outfile.write(f"# Generated on {datetime.now()} with the options:\n")
outfile.write(f"# {args}\n")
if args.mcformat == 'NUANCE':
for (i, evt) in enumerate(events):
evt.vertex = args.detector.generate_random_vertex()
outfile.write(evt.nuance_string(i))
outfile.write("$ stop\n")
if args.mcformat == 'RATPAC':
for (i, evt) in enumerate(events):
evt.vertex = args.detector.generate_random_vertex()
outfile.write(evt.ratpac_string(i, events))
if args.mcformat == 'ROOT_JUNO':
fname = args.output+".root"
root_outfile = uproot.recreate(fname)
root_outfile.mktree("SNEvents",{"nparticles": "uint64", "origPDGID":"int32", "nuE":"double", "pdgid": ("int32",(2,)),"t": ("float64",(2,)),
"px": ("float64",(2,)),"py":("float64",(2,)),"pz":("float64",(2,)),"m":("float64",(2,)), "channel": "int64"})
for (i, evt) in enumerate(events):
evt.vertex = args.detector.generate_random_vertex()
evt.juno_string(i, root_outfile)
for evt in events:
evt.vertex = args.detector.generate_random_vertex()

if args.mcformat in ('NUANCE', 'RATPAC'):
with open(args.output, "w") as outfile:
if args.verbose: # write parameters to file as a comment
outfile.write(f"# Generated on {datetime.now()} with the options:\n")
outfile.write(f"# {args}\n")
if args.mcformat == 'NUANCE':
for (i, evt) in enumerate(events):
outfile.write(evt.nuance_string(i))
outfile.write("$ stop\n")
if args.mcformat == 'RATPAC':
for (i, evt) in enumerate(events):
outfile.write(evt.ratpac_string(i, events))
if args.mcformat == 'ROOT_JUNO':
fname = args.output+".root"
root_outfile = uproot.recreate(fname)
root_outfile.mktree("SNEvents",{"nparticles": "uint64", "origPDGID":"int32", "nuE":"double", "pdgid": ("int32",(2,)),"t": ("float64",(2,)),
"px": ("float64",(2,)),"py":("float64",(2,)),"pz":("float64",(2,)),"m":("float64",(2,)), "channel": "int64"})
for (i, evt) in enumerate(events):
evt.juno_string(i, root_outfile)

def parse_command_line_options():
"""Define and parse command line options."""
Expand Down

0 comments on commit 967f71e

Please sign in to comment.