Commit 20d6fb68 authored by Vincent Rothe's avatar Vincent Rothe
Browse files

v2.2.7

parent 9e23da43
This diff is collapsed.
This diff is collapsed.
# $Id: analysis.sin 6004 2014-07-09 15:46:54Z cweiss $
# Intentionally left empty.
# $Id: auto_components.sin 5038 2014-01-07 07:58:16Z jr_reuter $
# Intentionally left empty.
# $Id: beam_structures.sin 4073 2013-02-12 13:42:18Z jr_reuter $
# Intentionally left empty.
# $Id: beams.sin 6004 2014-07-09 15:46:54Z cweiss $
# Intentionally left empty.
# $Id: cascades.sin 6004 2014-07-09 15:46:54Z cweiss $
# Intentionally left empty.
import re, sys
re_e = re.compile("p\(0:3\) = *([0-9]+\.[0-9]+)")
def energy(line):
try:
return float(re_e.search(line).group(1))
except AttributeError:
print 'Could not find number in this line:'
print line
return 0.0
test = sys.argv[1]
filename = test + '.debug'
inc_energy = 0.0
out_energy = 0.0
line_no = 0
rel_delta = 10.0**-5
abs_delta = 0.002
valid = True
def nearly_equal(a, b):
try:
diff = abs(a - b)
return diff / max([a, b]) < rel_delta or diff < abs_delta
except TypeError:
return False
print 'Start file ' + filename
print (3 * '{:<20s}').format('Line-Nr', 'Incoming-Energy', 'Outgoing-Energy')
with open(filename, 'r') as infile:
for line in infile:
line_no += 1
if 'incoming momenta' in line:
inc_energy = energy(line)
elif 'outgoing momenta' in line:
out_energy = energy(line)
if not nearly_equal(out_energy, inc_energy):
print ("{:<20d}" + 2 *"{:<20.10f}").format(line_no, inc_energy, out_energy)
valid = False
print 'End file ' + filename
returncode = 0 if valid else 1
sys.exit(returncode)
import re, sys
from math import sqrt
re_w = re.compile("E .* (-*\d*\.\d+e\S*)")
re_nums = re.compile("C (\d+\.\d+e\S*) (\d*\.\d+e\S*)")
def xsection(line):
try:
return float(re_nums.search(line).group(1)), float(re_nums.search(line).group(2))
except AttributeError:
print 'Could not find xsection in this line:'
print line
return 0.0
def weight(line):
try:
weight = float(re_w.search(line).group(1))
return weight
except AttributeError:
print 'Could not find number in this line:'
print line
return 0.0
test = sys.argv[1]
filename = test + '.hepmc'
valid = True
xsec = 0.0
error = 0.0
sum_weights = [0.0, 0.0, 0.0]
NN = [0, 0, 0]
line_no = 0
region = 0
regions = range(3)
print 'Start file ' + filename
with open(filename, 'r') as infile:
for line in infile:
if 'C ' in line:
xsec, error = xsection(line)
break
print 'Cross section is', xsec, '+-', error
with open(filename, 'r') as infile:
for line in infile:
line_no += 1
if 'E ' in line:
this_weight = weight(line)
#print 'line', line_no, this_weight
sum_weights[region] += this_weight
NN[region] += 1
region += 1
if region == 3:
region = 0
print 'HepMC'
for region in regions:
mean = sum_weights[region] / NN[region]
print 'region', region
print 'NN', NN[region]
print 'sum_weights', sum_weights[region]
print 'mean', mean
print 50 * '-'
print 'Overall'
mean = sum(sum_weights) / sum(NN)
print 'mean', mean
print 'abs(mean - xsec)', abs(mean-xsec)
pull = abs(mean-xsec) / error
print 'pull', pull
valid = pull < 3
print 'End file ' + filename
returncode = 0 if valid else 1
sys.exit(returncode)
# Intentionally left empty.
# $Id: color.sin 6004 2014-07-09 15:46:54Z cweiss $
# Intentionally left empty.
# $Id: commands.sin 6004 2014-07-09 15:46:54Z cweiss $
# Intentionally left empty.
import re, sys
from math import sqrt
delta = 1E-12
re_nums = re.compile(" +\S+ +(\d+\.\d+E\S*) (\d*\.\d+E\S*)")
re_bin = re.compile(" +(\d*\.\d+E\S*)")
bin_midpoint = lambda line: float(re_bin.search(line).group(1))
numbers = lambda line: (float(re_nums.search(line).group(1)),
float(re_nums.search(line).group(2)))
def pull_and_chi2(line, ref_line):
value, error = numbers(line)
ref_value, ref_error = numbers(ref_line)
error_sum = sqrt (error**2 + ref_error**2)
diff = abs (value - ref_value)
chi2_result = diff ** 2 / ref_value
if abs (error_sum) > delta:
pull_result = diff / error_sum
else:
pull_result = 0.0 if diff < delta else 10.0
return pull_result, chi2_result
process = sys.argv[1]
filename = process + '_hist.dat'
reference = 'ref-output/' + process + '.ref'
pull_max = 0.0
dof = -1
sum_chi2 = 0.0
print (3 * '{:<30s}').format("Bin Midpoint", "Pull", "Chi2")
# In Python 2.7 we could write this in one line
with open(filename, 'r') as infile:
with open(reference, 'r') as ref_file:
for line, ref_line in zip(infile, ref_file):
if '#' not in line and len(line) > 1:
dof += 1
this_pull, this_chi2 = pull_and_chi2(line, ref_line)
sum_chi2 += this_chi2
pull_max = max(pull_max, this_pull)
print (3 * '{:<30.10f}').format(bin_midpoint(line), this_pull, this_chi2)
elif 'Underflow' in line:
break
chi2_per_dof = sum_chi2 / dof
print (4 * '{:<30s}').format("Max Pull", "Chi2", "dof", "Chi2/dof")
print (4 * '{:<30.10f}').format(pull_max, sum_chi2, dof, chi2_per_dof)
returncode = 0 if pull_max < 3 and chi2_per_dof < 2 else 1
print returncode
sys.exit(returncode)
import re, sys
from math import sqrt
re_num = re.compile("\w+\(\w+\) = (\d*\.\d+E.*)")
re_nums = re.compile("\w+ *(\d+\.\d+E*\S*) *(\d*\.\d+E*\S*)")
number = lambda line: float(re_num.search(line).group(1))
numbers = lambda line: (float(re_nums.search(line).group(1)),
float(re_nums.search(line).group(2)))
process = sys.argv[1]
filename = process + '.log'
reference_file = sys.argv[2]
with open(filename, 'r') as infile:
for line in infile:
if 'integral(' in line:
integral = number(line)
if 'error(' in line:
error = number(line)
with open(reference_file, 'r') as infile:
for line in infile:
if process + ' ' in line:
ref_integral, ref_error = numbers(line)
print 'Reference:', ref_integral, '+-', ref_error
try:
print process, integral, '+-', error
error_sum = sqrt (error**2 + ref_error**2)
pull = abs (integral - ref_integral) / error_sum
print 'pull:', pull
valid = pull < 3
except NameError:
print 'Number not found. Run failed.'
valid = False
returncode = 0 if valid else 1
sys.exit(returncode)
# Intentionally left empty.
# Intentionally left empty.
# $Id: decays.sin 4938 2013-12-05 09:47:32Z jr_reuter $
# Intentionally left empty.
# $Id: dispatch.sin 4937 2013-12-05 09:29:17Z jr_reuter $
# Intentionally left empty.
# $Id: eio_ascii.sin 4937 2013-12-05 09:29:17Z jr_reuter $
# Intentionally left empty.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment