-
Notifications
You must be signed in to change notification settings - Fork 1
/
replace_lifetime_in_LHE.py
executable file
·52 lines (39 loc) · 1.98 KB
/
replace_lifetime_in_LHE.py
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
## edit lines 8 and 11
## run as: python replace_lifetime_in_LHE.py > someOutputFile.py
import array, os, re, math, random, string
from math import *
## set your new ctau value here
ctau_mean_mm = 5.0
## set input file name
filename = "DarkSUSY_mH_125_mGammaD_2000_ctauExp_0_13TeV-madgraph452_bridge224_events80k.lhe"
f = open(filename, 'r')
event_begin = False
event_end = True
for line in f:
if line == '<event>\n':
event_begin = True
event_end = False
if line == '</event>\n':
event_begin = False
event_end = True
new_line = ''
if event_begin == True and event_end == False:
word_n = 0
for word in line.split():
if word == '3000022' or word_n > 0:
word_n = word_n + 1
if word_n < 13:
if word_n == 12:
ctau_mm = '%E' % random.expovariate(1.0/ctau_mean_mm) # exponential distribution
# print "ctau (mm) mean: ", ctau_mean_mm, " actual: ", ctau_mm
new_line = new_line + ctau_mm + ' '
else:
new_line = new_line + word + ' '
else:
new_line = new_line + word + '\n'
word_n = 0
if new_line == '':
print line.rstrip('\n')
else:
print new_line.rstrip('\n')
f.close()