~maddevelopers/mg5amcnlo/3.0.2-alpha0-merged3.2.0

« back to all changes in this revision

Viewing changes to tests/parallel_tests/madevent_comparator.py

  • Committer: olivier-mattelaer
  • Date: 2021-05-06 14:57:23 UTC
  • mfrom: (956.2.9 3.0)
  • Revision ID: olivier-mattelaer-20210506145723-oasykft3zdy37td2
merge with 3.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
formats (txt, tex, ...).
18
18
"""
19
19
 
 
20
from __future__ import absolute_import
 
21
from __future__ import print_function
20
22
import datetime
21
23
import glob
22
24
import itertools
27
29
import subprocess
28
30
import sys
29
31
import time
 
32
import six
 
33
from six.moves import range
30
34
 
31
35
pjoin = os.path.join
32
36
# Get the grand parent directory (mg5 root) of the module real path 
42
46
import madgraph.various.misc as misc
43
47
 
44
48
from madgraph import MadGraph5Error, MG5DIR
45
 
import me_comparator
 
49
from . import me_comparator
46
50
 
47
51
class MadEventComparator(me_comparator.MEComparator):
48
52
    """Base object to run comparison tests. Take standard Runner objects and
52
56
    def run_comparison(self, proc_list, model='sm', orders={}):
53
57
        """Run the codes and store results."""
54
58
 
55
 
        if isinstance(model, basestring):
 
59
        if isinstance(model, six.string_types):
56
60
            model= [model] * len(self.me_runners)
57
61
 
58
62
        self.results = []
125
129
            loc_results = []
126
130
            succeed = True
127
131
            for i in range(len(self.results)):
128
 
                if not self.results[i].has_key(prop):
 
132
                if prop not in self.results[i]:
129
133
                    loc_results.append('not present')
130
134
                    succeed = False
131
135
                else:
282
286
            loc_results = []
283
287
            succeed = True
284
288
            for i in range(len(self.results)):
285
 
                if not self.results[i].has_key(proc):
 
289
                if proc not in self.results[i]:
286
290
                    loc_results.append('not present')
287
291
                    succeed = False
288
292
                else:
485
489
        else:
486
490
            v5_string = "import model %s\n" % model
487
491
        v5_string += "set automatic_html_opening False\n"
488
 
        couplings = me_comparator.MERunner.get_coupling_definitions(orders)
 
492
        if orders == {}:
 
493
            couplings = ' '
 
494
        else:
 
495
            couplings = me_comparator.MERunner.get_coupling_definitions(orders)
489
496
 
490
497
        for i, proc in enumerate(proc_list):
491
498
            v5_string += 'add process ' + proc + ' ' + couplings + \
492
499
                         '@%i' % i + '\n'
 
500
 
493
501
        v5_string += "output %s -f\n" % \
494
502
                     os.path.join(self.mg5_path, self.temp_dir_name)
495
503
        v5_string += "launch -i --multicore\n"
520
528
        numsubProc={}
521
529
        for name in SubProc :
522
530
            tag=name.split('_')[0][1:]
523
 
            if numsubProc.has_key(tag):
 
531
            if tag in numsubProc:
524
532
                numsubProc[tag]+=1
525
533
            else: numsubProc[tag]=1
526
534
 
529
537
 
530
538
        #Part 2: cross section
531
539
        for name in SubProc:
 
540
 
532
541
            if os.path.exists(dir_name+'/SubProcesses/'+name+'/run_01_results.dat'):
533
542
                filepath = dir_name+'/SubProcesses/'+name+'/run_01_results.dat'
534
543
            else:
535
544
                filepath = dir_name+'/SubProcesses/'+name+'/results.dat'
 
545
 
536
546
            if not os.path.exists(filepath):
537
 
                break
538
 
 
539
 
            for line in file(filepath):
540
 
                splitline=line.split()
541
 
                #if len(splitline)==8:
542
 
                output['cross_'+name]=splitline[0]
543
 
                print "found %s %s" % (splitline[0], splitline[1])
 
547
                cross = 0
 
548
                for G in os.listdir(dir_name+'/SubProcesses/'+name):
 
549
                    if os.path.isdir(pjoin(dir_name+'/SubProcesses/'+name,G)):
 
550
                        filepath = pjoin(dir_name+'/SubProcesses/'+name,G,'results.dat')
 
551
                        channel = G[1:]
 
552
                        for line in open(filepath):
 
553
                            splitline=line.split()
 
554
                            cross += float(splitline[9]) 
 
555
                            break
 
556
                output['cross_'+name] = str(cross)
 
557
            else:
 
558
                for line in open(filepath):
 
559
                    splitline=line.split()
 
560
                    #if len(splitline)==8:
 
561
                    output['cross_'+name]=splitline[0]
 
562
                    #print( "found %s %s" % (splitline[0], splitline[1]))
544
563
        else:
545
564
            return output   
546
565
        
551
570
        info = re.findall('id="\#(?P<a1>\w*)" href=\#(?P=a1) onClick="check_link\(\'\#(?P=a1)\',\'\#(?P=a1)\',\'\#(?P=a1)\'\)">\s* ([\d.e+-]*)', text)
552
571
        for name,value in info:
553
572
            output['cross_'+name] = value
554
 
 
555
 
            
556
 
            
557
573
            
558
574
 
559
575