1 |
pivarski |
1.1 |
import sys, re, random
|
2 |
|
|
|
3 |
|
|
mode = sys.argv[1]
|
4 |
|
|
if mode == "electrons": mode = 11
|
5 |
|
|
elif mode == "pions": mode = 211
|
6 |
|
|
else: raise Exception, "Must pass \"electrons\" or \"pions\" as an argument"
|
7 |
|
|
|
8 |
|
|
inevent = False
|
9 |
|
|
event = {}
|
10 |
|
|
i = 0
|
11 |
|
|
for line in sys.stdin:
|
12 |
|
|
if line == "<event>\n": inevent = True
|
13 |
|
|
|
14 |
|
|
# end of an event: modify it and write out
|
15 |
|
|
if line == "</event>\n":
|
16 |
|
|
inevent = False
|
17 |
|
|
|
18 |
|
|
# find the (3 GeV/c^2) Higgs
|
19 |
|
|
higgs = 0
|
20 |
|
|
for j in range(i):
|
21 |
|
|
if event[j][0] == 25:
|
22 |
|
|
higgs = j
|
23 |
|
|
break
|
24 |
|
|
if higgs != 0:
|
25 |
|
|
# find its daughters (1 GeV/c^2 Z bosons)
|
26 |
|
|
Z1 = 0
|
27 |
|
|
Z2 = 0
|
28 |
|
|
for j in range(i):
|
29 |
|
|
if event[j][0] == 23 and event[j][2] == higgs:
|
30 |
|
|
if Z1 == 0: Z1 = j
|
31 |
|
|
else:
|
32 |
|
|
Z2 = j
|
33 |
|
|
break
|
34 |
|
|
|
35 |
|
|
# randomly select one Z to convert to electrons/pions
|
36 |
|
|
if random.randint(0, 1) == 0: Z = Z1
|
37 |
|
|
else: Z = Z2
|
38 |
|
|
|
39 |
|
|
# convert its daughters into electrons/pions
|
40 |
|
|
for j in range(i):
|
41 |
|
|
if event[j][0] == 13 and event[j][2] == Z:
|
42 |
|
|
event[j][0] = mode
|
43 |
|
|
elif event[j][0] == -13 and event[j][2] == Z:
|
44 |
|
|
event[j][0] = -mode
|
45 |
|
|
|
46 |
|
|
# write out the event
|
47 |
|
|
for j in range(i):
|
48 |
|
|
print " ".join(map(str, event[j]))
|
49 |
|
|
event = {}
|
50 |
|
|
i = 0
|
51 |
|
|
|
52 |
|
|
# non-event line
|
53 |
|
|
if not inevent or line == "<event>\n":
|
54 |
|
|
print line,
|
55 |
|
|
|
56 |
|
|
# middle of an event: accumulate the information
|
57 |
|
|
else:
|
58 |
|
|
numbers = re.split(r"\s+", line)
|
59 |
|
|
if i > 0:
|
60 |
|
|
if numbers[0] == "": numbers = numbers[1:]
|
61 |
|
|
numbers[0] = int(numbers[0])
|
62 |
|
|
numbers[2] = int(numbers[2])
|
63 |
|
|
event[i] = numbers
|
64 |
|
|
i += 1
|