#!/usr/bin/env python # Copyright (c) 2019, Anthony Latorre # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . """ snogen is a script to generate SNOMAN command files. Example: # simulate 100 1 GeV muons $ snogen -n 100 -e 1000 -p mu_minus | /path/to/snoman.exe The output filename can be specified on the command line: $ snogen -o [output filename] By default it will be [particle name]_[energy]_[number of events].zdab. """ from __future__ import print_function, division import string class MyTemplate(string.Template): delimiter = '@' if __name__ == '__main__': import argparse parser = argparse.ArgumentParser("generate a SNOMAN command file") parser.add_argument("-p", "--particle-id", default="e_minus", help="particle id") parser.add_argument("-e", "--mc-energy", default=500.0, type=float, help="total energy") parser.add_argument("-n", "--num-events", default=100, type=int, help="number of events") parser.add_argument("-o", "--output", default=None, help="output file name") args = parser.parse_args() if args.output is None: output = "%s_%.0f_%i.zdab" % (args.particle_id,args.mc_energy,args.num_events) else: output = args.output with open("mc_run_10000_macro.cmd") as f: s = f.read() template = MyTemplate(s) print(template.safe_substitute(particle_id=args.particle_id,mc_energy=args.mc_energy,num_events=args.num_events,output=output))