aboutsummaryrefslogtreecommitdiff
path: root/macros/snogen
blob: d96a87f5dbb4b65d53d6d4a9d4167890b7409f9e (plain)
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
27pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color:
#!/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))