Skip to content

Commit efe0d28

Browse files
committed
A flexible python script to create Pythia8 configurations
1 parent ef925f8 commit efe0d28

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#! /usr/bin/env python3
2+
3+
### @author: Roberto Preghenella
4+
### @email: preghenella@bo.infn.it
5+
6+
import argparse
7+
8+
parser = argparse.ArgumentParser(description='Make Pythia8 cofiguration',
9+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
10+
11+
parser.add_argument('--seed', type=int, default=None,
12+
help='The random seed')
13+
14+
parser.add_argument('--idA', type=int, default='2212',
15+
help='PDG code of projectile beam')
16+
17+
parser.add_argument('--idB', type=int, default='2212',
18+
help='PDG code of target beam')
19+
20+
parser.add_argument('--eCM', type=float, default='13000.',
21+
help='Centre-of-mass energy')
22+
23+
parser.add_argument('--process', default='inel', choices=['none', 'inel', 'ccbar', 'bbbar', 'heavy'],
24+
help='Process to switch on')
25+
26+
parser.add_argument('--ptHatMin', type=float,
27+
help='The minimum invariant pT')
28+
29+
parser.add_argument('--ptHatMax', type=float,
30+
help='The maximum invariant pT')
31+
32+
parser.add_argument('--output', default='pythia8.cfg',
33+
help='Where to write the configuration')
34+
35+
parser.add_argument('--include', action='append', default=None,
36+
help='Include files at the top of the configuration')
37+
38+
parser.add_argument('--append', action='append', default=None,
39+
help='Include files at the bottom of the configuration')
40+
41+
parser.add_argument('--command', action='append', default=None,
42+
help='User specified commands at the end of the configuration')
43+
44+
args = parser.parse_args()
45+
46+
### open output file
47+
fout = open(args.output, 'w')
48+
49+
### included files
50+
if args.include is not None :
51+
for i in args.include :
52+
fout.write('### --> included from %s \n' % (i))
53+
fin = open(i, 'r')
54+
data = fin.read()
55+
fin.close()
56+
fout.write('\n')
57+
fout.write(data)
58+
fout.write('\n')
59+
fout.write('### <-- included from %s \n' % (i))
60+
fout.write('\n')
61+
62+
fout.write('### --> generated by mkpy8cfg.py \n')
63+
fout.write('\n')
64+
65+
### random
66+
if args.seed is not None:
67+
fout.write('### random \n')
68+
fout.write('Random:setSeet = on \n')
69+
fout.write('Random:seed = %d \n' % (args.seed))
70+
fout.write('\n')
71+
72+
### beams
73+
fout.write('### beams \n')
74+
fout.write('Beams:idA = %d \n' % (args.idA))
75+
fout.write('Beams:idB = %d \n' % (args.idB))
76+
fout.write('Beams:eCM = %f \n' % (args.eCM))
77+
fout.write('\n')
78+
79+
### processes
80+
fout.write('### processes \n')
81+
if args.process == 'inel':
82+
fout.write('SoftQCD:inelastic = on \n')
83+
if args.process == 'ccbar' or args.process == 'heavy':
84+
fout.write('HardQCD:hardccbar = on \n')
85+
if args.process == 'bbbar' or args.process == 'heavy':
86+
fout.write('HardQCD:hardbbbar = on \n')
87+
fout.write('\n')
88+
89+
### phase space cuts
90+
fout.write('### phase space cuts \n')
91+
if args.ptHatMin is not None :
92+
fout.write('PhaseSpace:pTHatMin = %f \n' % (args.ptHatMin))
93+
if args.ptHatMax is not None :
94+
fout.write('PhaseSpace:pTHatMax = %f \n' % (args.ptHatMax))
95+
fout.write('\n')
96+
97+
fout.write('### <-- generated by mkpy8cfg.py \n')
98+
fout.write('\n')
99+
100+
### appended files
101+
if args.append is not None :
102+
for i in args.append :
103+
fout.write('### --> included from %s \n' % (i))
104+
fin = open(i, 'r')
105+
data = fin.read()
106+
fin.close()
107+
fout.write('\n')
108+
fout.write(data)
109+
fout.write('\n')
110+
fout.write('### <-- included from %s \n' % (i))
111+
fout.write('\n')
112+
113+
### user commands
114+
if args.command is not None :
115+
fout.write('### --> user commands \n')
116+
fout.write('\n')
117+
for i in args.command :
118+
fout.write(i)
119+
fout.write('\n')
120+
fout.write('\n')
121+
fout.write('### <-- user commands \n')
122+
123+
### close outout file
124+
fout.close()

0 commit comments

Comments
 (0)