22
22
pjoin = os.path.join
24
import madgraph.various.cluster as cluster
25
25
except ImportError:
26
26
import internal.cluster as cluster
27
import internal.misc as misc
29
import madgraph.various.cluster as cluster
30
import madgraph.various.misc as misc
28
32
class OneResult(object):
31
35
"""Initialize all data """
34
39
self.axsec = 0 # Absolute cross section = Sum(abs(wgt))
35
40
self.xsec = 0 # Real cross section = Sum(wgt)
36
41
self.xerru = 0 # uncorrelated error
37
42
self.xerrc = 0 # correlated error
39
self.nw = 0 # Don't know
44
self.nw = 0 # number of events after the primary unweighting
41
46
self.nunwgt = 0 # number of unweighted events
42
47
self.luminosity = 0
46
51
self.yasec_iter = []
48
53
self.maxwgt_iter = []
54
self.maxwgt = 0 # weight used for the secondary unweighting.
55
self.th_maxwgt= 0 # weight that should have been use for secondary unweighting
56
# this can happen if we force maxweight
57
self.th_nunwgt = 0 # associated number of event with th_maxwgt
58
#(this is theoretical do not correspond to a number of written event)
51
@cluster.multiple_try(nb_try=5,sleep=20)
61
#@cluster.multiple_try(nb_try=5,sleep=20)
52
62
def read_results(self, filepath):
53
63
"""read results.dat and fullfill information"""
65
if isinstance(filepath, str):
66
finput = open(filepath)
67
elif isinstance(filepath, file):
70
raise Exception, "filepath should be a path or a file descriptor"
56
for line in open(filepath):
59
78
def secure_float(d):
65
84
return float(m.group(1))*10**(float(m.group(2)))
68
86
data = [secure_float(d) for d in line.split()]
69
87
self.axsec, self.xerru, self.xerrc, self.nevents, self.nw,\
70
self.maxit, self.nunwgt, self.luminosity, self.wgt, self.xsec = data[:10]
88
self.maxit, self.nunwgt, self.luminosity, self.wgt, \
91
self.maxwgt = data[10]
93
self.th_maxwgt, self.th_nunwgt = data[11:13]
71
94
if self.mfactor > 1:
72
95
self.luminosity /= self.mfactor
73
#self.ysec_iter.append(self.axsec)
74
#self.yerr_iter.append(0)
77
98
l, sec, err, eff, maxwgt, asec = line.split()
116
137
self.ysec_iter = ysec
117
138
self.yerr_iter = yerr
142
if name in ['xsec', 'xerru','xerrc']:
143
return getattr(self, name) * self.mfactor
144
elif name in ['luminosity']:
145
#misc.sprint("use unsafe luminosity definition")
147
return getattr(self, name) #/ self.mfactor
148
elif (name == 'eff'):
149
return self.xerr*math.sqrt(self.nevents/(self.xsec+1e-99))
151
return math.sqrt(self.xerru**2+self.xerrc**2)
153
return pjoin(self.parent_name, self.name)
155
return getattr(self, name)
120
157
class Combine_results(list, OneResult):
277
318
'mod_P_link': mod_link,
278
319
'cross': '%.4g' % oneresult.xsec,
279
320
'error': '%.3g' % oneresult.xerru,
280
'events': oneresult.nevents,
321
'events': oneresult.nevents/1000.0,
281
322
'unweighted': oneresult.nunwgt,
282
323
'luminosity': '%.3g' % oneresult.luminosity
327
368
power = int(power) + 1
328
369
return '%.5fE%+03i' %(nb,power)
330
line = '%s %s %s %i %i %i %i %s %s %s\n' % (fstr(self.axsec), fstr(self.xerru),
371
line = '%s %s %s %i %i %i %i %s %s %s %s %s %i\n' % (fstr(self.axsec), fstr(self.xerru),
331
372
fstr(self.xerrc), self.nevents, self.nw, self.maxit, self.nunwgt,
332
fstr(self.luminosity), fstr(self.wgt), fstr(self.xsec))
373
fstr(self.luminosity), fstr(self.wgt), fstr(self.xsec), fstr(self.maxwgt),
374
fstr(self.th_maxwgt), self.th_nunwgt)
333
375
fsock = open(output_path,'w')
334
376
fsock.writelines(line)
335
377
for i in range(len(self.ysec_iter)):
382
def make_all_html_results(cmd, folder_names = []):
383
""" folder_names has been added for the amcatnlo runs """
420
def collect_result(cmd, folder_names):
384
423
run = cmd.results.current['run_name']
385
if not os.path.exists(pjoin(cmd.me_dir, 'HTML', run)):
386
os.mkdir(pjoin(cmd.me_dir, 'HTML', run))
388
unit = cmd.results.unit
390
424
all = Combine_results(run)
393
426
for Pdir in open(pjoin(cmd.me_dir, 'SubProcesses','subproc.mg')):
394
427
Pdir = Pdir.strip()
416
449
dir = folder.replace('*', '_G' + name)
417
450
P_comb.add_results(dir, pjoin(P_path,dir,'results.dat'), mfactor)
419
451
P_comb.compute_values()
420
P_text += P_comb.get_html(run, unit, cmd.me_dir)
421
P_comb.write_results_dat(pjoin(P_path, '%s_results.dat' % run))
422
452
all.append(P_comb)
423
453
all.compute_values()
424
all.write_results_dat(pjoin(cmd.me_dir,'SubProcesses', 'results.dat'))
457
def make_all_html_results(cmd, folder_names = []):
458
""" folder_names has been added for the amcatnlo runs """
459
run = cmd.results.current['run_name']
460
if not os.path.exists(pjoin(cmd.me_dir, 'HTML', run)):
461
os.mkdir(pjoin(cmd.me_dir, 'HTML', run))
463
unit = cmd.results.unit
465
Presults = collect_result(cmd, folder_names=folder_names)
468
for P_comb in Presults:
469
P_text += P_comb.get_html(run, unit, cmd.me_dir)
470
P_comb.compute_values()
471
P_comb.write_results_dat(pjoin(cmd.me_dir, 'SubProcesses', P_comb.name,
472
'%s_results.dat' % run))
475
Presults.write_results_dat(pjoin(cmd.me_dir,'SubProcesses', 'results.dat'))
426
477
fsock = open(pjoin(cmd.me_dir, 'HTML', run, 'results.html'),'w')
427
478
fsock.write(results_header)
428
fsock.write('%s <dl>' % all.get_html(run, unit, cmd.me_dir))
429
fsock.write('%s </dl></body>' % P_text)
433
return all.xsec, all.xerru
479
fsock.write('%s <dl>' % Presults.get_html(run, unit, cmd.me_dir))
480
fsock.write('%s </dl></body>' % P_text)
482
return Presults.xsec, Presults.xerru