1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#!/usr/bin/env python
# Copyright (c) 2019, Anthony Latorre <tlatorre at uchicago>
#
# 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 <https://www.gnu.org/licenses/>.
"""
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))
|