Fork me on GitHub

source: git/validation/FlatGunLHEventProducer.py@ 78d1846

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 78d1846 was 03d2c3f, checked in by Pavel Demin <pavel-demin@…>, 8 years ago

move validation scripts to validation directory

  • Property mode set to 100644
File size: 6.4 KB
Line 
1#!/usr/bin/env python
2################################################################################
3#
4# Requires python v2.7
5#
6# Simple script for generation of a LHE file containing events distributed with a flat (log)pt and eta spectrum.
7#
8# For help type:
9# python FlatSpectrumProducer.py -h
10#
11################################################################################
12
13import os, random, math, argparse, sys
14
15def print_params(args):
16
17 print 'sqrt(s) : ', args.ecm
18 print 'ptmin : ', args.ptmin
19 print 'ptmax : ', args.ptmax
20 print 'etamin : ', args.etamin
21 print 'etamax : ', args.etamax
22 print 'size : ', args.size
23 print 'seed : ', args.seed
24 print 'flat log : ', args.log
25 print 'output : ', args.output
26
27def write_init(args):
28
29 ebeam = args.ecm/2.
30
31 out = open(args.output, "a")
32 out.write('<LesHouchesEvents version="3.0">\n')
33 out.write('<init>\n')
34 out.write('2212 2212 {0} {1} 0 0 1 1 -4 1\n'.format(ebeam, ebeam))
35 out.write('1000. 1. 1000. 1\n')
36 out.write('</init>\n')
37 out.close()
38
39def write_event(args, pt, eta, phi):
40
41 e = pt*math.cosh(eta)
42
43 # compute particles 4-vectors (for massless particles): px, py, pz, e
44
45 p1 = [0., 0., e, e]
46 p2 = [0., 0., -e, e]
47 p3 = [pt*math.cos(phi), pt*math.sin(phi), pt*math.sinh(eta), e]
48 p4 = [- pt*math.cos(phi), - pt*math.sin(phi), - pt*math.sinh(eta), e]
49
50 if args.pdg == 21:
51 pdg = 0
52 else:
53 pdg = args.pdg
54
55 cf_list = []
56
57 ########## quarks
58 if pdg > 0:
59
60 cf_list.append([501, 501, 502, 502])
61 cf_list.append([501, 502, 501, 502])
62
63 color = cf_list[random.randint(0, 1)]
64
65 # assume massless quarks
66 out = open(args.output, "a")
67 out.write('<event>\n')
68 out.write(' 4 1 +1000. {:.8e} 0.78186083E-02 0.11800000E+00\n'.format(2*e))
69 out.write(' 1 -1 0 0 {} 0 {:+.8e} {:+.8e} {:+.8e} {:.8e} {:.8e} 0.0000e+00 1.0000e+00\n'.format(color[0], p1[0], p1[1], p1[2], p1[3], 0.))
70 out.write(' -1 -1 0 0 0 {} {:+.8e} {:+.8e} {:+.8e} {:.8e} {:.8e} 0.0000e+00 -1.0000e+00\n'.format(color[1], p2[0], p2[1], p2[2], p2[3], 0.))
71 out.write(' {} 1 1 2 {} 0 {:+.8e} {:+.8e} {:+.8e} {:.8e} {:.8e} 0.0000e+00 1.0000e+00\n'.format(pdg, color[2], p3[0], p3[1], p3[2], p3[3], 0.))
72 out.write(' -{} 1 1 2 0 {} {:+.8e} {:+.8e} {:+.8e} {:.8e} {:.8e} 0.0000e+00 -1.0000e+00\n'.format(pdg, color[3], p4[0], p4[1], p4[2], p4[3], 0.))
73 out.write('</event>\n')
74
75 ########## gluons
76 else:
77
78 cf_list.append([503, 501, 504, 502, 503, 502, 504, 501])
79 cf_list.append([504, 501, 503, 502, 503, 501, 504, 502])
80
81 color = cf_list[random.randint(0, 1)]
82
83 out = open(args.output, "a")
84 out.write('<event>\n')
85 out.write(' 4 1 +1000. {:.8e} 0.78186083E-02 0.11800000E+00\n'.format(2*e))
86 out.write(' 21 -1 0 0 {} {} {:+.8e} {:+.8e} {:+.8e} {:.8e} {:.8e} 0.0000e+00 1.0000e+00\n'.format(color[0], color[1], p1[0], p1[1], p1[2], p1[3], 0.))
87 out.write(' 21 -1 0 0 {} {} {:+.8e} {:+.8e} {:+.8e} {:.8e} {:.8e} 0.0000e+00 1.0000e+00\n'.format(color[2], color[3], p2[0], p2[1], p2[2], p2[3], 0.))
88 out.write(' 21 1 1 2 {} {} {:+.8e} {:+.8e} {:+.8e} {:.8e} {:.8e} 0.0000e+00 1.0000e+00\n'.format(color[4], color[5], p3[0], p3[1], p3[2], p3[3], 0.))
89 out.write(' 21 1 1 2 {} {} {:+.8e} {:+.8e} {:+.8e} {:.8e} {:.8e} 0.0000e+00 1.0000e+00\n'.format(color[6], color[7], p4[0], p4[1], p4[2], p4[3], 0.))
90 out.write('</event>\n')
91
92
93
94#__________________________________________________________
95
96if __name__=="__main__":
97
98 parser = argparse.ArgumentParser()
99 parser.add_argument("--pdg", type=int, help='available: 1/2/3/4/5/21 i.e: [uubar/ddbar/ssbar/ccbar/bbbar/gg] (default: 1)', default='1')
100 parser.add_argument("--ptmin", type=float, help="minimum pt [GeV] (default: 1.)", default=1.)
101 parser.add_argument("--ptmax", type=float, help="maximum pt [GeV] (default: 50000.)", default=50000.)
102 parser.add_argument("--etamin", type=float, help="minimum eta (default: 6.)", default=-6.)
103 parser.add_argument("--etamax", type=float, help="maximum eta (default: 6.)", default=6.)
104 parser.add_argument("--ecm,", dest='ecm', type=float, help="center of mass energy (default: 13000)", default=13000)
105 parser.add_argument("--size", type=int, help="number of events to generate (default: 1000)", default=1000)
106 parser.add_argument("--seed", type=int, help="random seed (default: 0)", default=0)
107 parser.add_argument('--log', dest='log', help="flat in log pt (default: yes)", action='store_true')
108 parser.add_argument('--nolog', dest='log', help="flat in pt (default: false)", action='store_false')
109 parser.set_defaults(log=True)
110 parser.add_argument("--output", help="output LHE file (default: events.lhe)", default='events.lhe')
111
112 args = parser.parse_args()
113
114 # check if provided pdgCode is allowed
115 allowed_pdgCodes = [1, 2, 3, 4, 5, 21]
116 if args.pdg not in allowed_pdgCodes:
117 print args.pdg ,'Please provide a supported pdgCode : 1, 2, 3, 4, 5 or 21'
118 sys.exit(0)
119
120 # print user-defined parameters
121 print_params(args)
122 print ''
123
124 # intialize file and write LHE file header
125 out = open(args.output, "w+")
126 out.close()
127 write_init(args)
128
129 # initialize random seed
130 random.seed(args.seed)
131
132 print 'Start event generation ...'
133
134 ebeam = args.ecm/2.
135 count = 0
136
137 # start event loop
138 while count < args.size:
139
140 phi = random.uniform(0., math.pi)
141 eta = random.uniform(args.etamin, args.etamax)
142
143 # flat in pt or in logpt
144 if args.log:
145 pt = math.pow(10, random.uniform(math.log10(args.ptmin), math.log10(args.ptmax)))
146 else:
147 pt = random.uniform(args.ptmin, args.ptmax)
148
149 # generating "balanced" collision, i.e x1 = x2 = 2*energy/sqrt(s)
150 e = pt*math.cosh(eta)
151
152 # write event corresponding to required process
153 if e < ebeam/2.:
154 write_event(args, pt, eta, phi)
155 count += 1
156 if (count+1)%1000 == 0:
157 print ' ... processed {} events ...'.format(count+1)
158
159 print ''
160 print 'Event generation completed.'
161 print 'Output file:'
162 print '{}'.format(os.path.abspath(args.output))
163
164
165 out = open(args.output, "a")
166 out.write('</LesHouchesEvents>\n')
167 out.close()
Note: See TracBrowser for help on using the repository browser.