~madteam/mg5amcnlo/series2.0

« back to all changes in this revision

Viewing changes to madgraph/madweight/write_MadWeight.py

  • Committer: olivier-mattelaer
  • Date: 2020-08-21 09:16:56 UTC
  • mfrom: (284.2.24 python3)
  • Revision ID: olivier-mattelaer-20200821091656-iizux2mj94tkssuo
pass to 2.8.0 (and move to python3 branch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
##### -*- coding: cp1252 -*-
3
3
 
4
4
#Extension
 
5
from __future__ import absolute_import
 
6
from __future__ import print_function
5
7
import os
 
8
import six
 
9
from six.moves import map
 
10
from six.moves import range
6
11
 
7
12
try:
8
13
    from madgraph.madweight.MW_fct import *
25
30
    template = mod_file.Mod_file(rule_file='./Source/MadWeight/mod_file/mod_main_code')
26
31
    # load MadWeight option
27
32
    for MW_dir in MW_info.MW_listdir:
28
 
        print 'treating', MW_dir, 'directory'
 
33
        print('treating', MW_dir, 'directory')
29
34
        diag = MG_diagram('./SubProcesses/' + MW_dir, 'param_card_1.dat', './Source/MadWeight/transfer_function/ordering_file.inc', i, MW_info)
30
35
        diag.create_all_fortran_code()
31
36
        diag.write_code(template)
61
66
            self.clear_solution()
62
67
            self.define_Constraint_sector()
63
68
            self.solve_blob_sector()
64
 
            print self
 
69
            print(self)
65
70
            num_sol = self.load_fortran_code(num_sol)
66
71
            
67
72
        for unaligned in all_pos:
70
75
 
71
76
            self.define_Constraint_sector()
72
77
            self.solve_blob_sector()
73
 
            print self
 
78
            print(self)
74
79
            num_sol = self.load_fortran_code(num_sol)
75
80
            
76
81
        self.create_permutation_weight_functions_caller()
227
232
                continue
228
233
            i+=1        
229
234
            text+=' double precision local_%s \n' % (i)
230
 
            if isinstance(unaligned, basestring):
 
235
            if isinstance(unaligned, six.string_types):
231
236
                name = 'tf_E_for_part\n'
232
237
            elif unaligned.external:
233
238
                name= 'tf_E_for_%s \n'% (unaligned.MG)
252
257
        def write_call_for_peak(obj,peak):
253
258
            """ return the text on how to return the weight associted to this peak """
254
259
            
255
 
            if isinstance(peak, basestring):
 
260
            if isinstance(peak, six.string_types):
256
261
                text = 'tf_E_for_part(%s)' % ( peak )
257
262
            elif peak.external:
258
263
                text = 'tf_E_for_%s() '% (peak.MG)
270
275
            for unaligned,nb in all_peak.items():
271
276
                if nb == 0: 
272
277
                    continue
273
 
                if unaligned not in unaligned_peak.keys():                
 
278
                if unaligned not in list(unaligned_peak.keys()):                
274
279
                    text+=' * local_%s' %(peak_to_prov[unaligned])
275
280
            return text 
276
281
        
294
299
            if isinstance(self.MWparam['mw_gen']['restrict_channel'], list):
295
300
                allowed_channel = [int(i)-1 for i in self.MWparam['mw_gen']['restrict_channel']]
296
301
            elif self.MWparam['mw_gen']['restrict_channel'] in ['','0','F']:
297
 
                allowed_channel = range(0,len(peak_by_channel))
 
302
                allowed_channel = list(range(0,len(peak_by_channel)))
298
303
            else:
299
304
                allowed_channel = [int(self.MWparam['mw_gen']['restrict_channel'])-1]
300
305
        else:
301
 
            allowed_channel = range(0,len(peak_by_channel))
302
 
        for j in xrange(0,len(peak_by_channel)):
 
306
            allowed_channel = list(range(0,len(peak_by_channel)))
 
307
        for j in range(0,len(peak_by_channel)):
303
308
            if j in allowed_channel:
304
309
                den_text += ' + '+product_of_peak(peak_by_channel[j],all_peak,peak_to_prov)
305
310
                if j == label:
407
412
                        break
408
413
                    if type(particle.MG) == int:
409
414
                        line += str(particle.MG) + ','
410
 
                    elif isinstance(particle.MG, basestring):
411
 
                        if self.fuse_dict.has_key(particle.MG):
 
415
                    elif isinstance(particle.MG, six.string_types):
 
416
                        if particle.MG in self.fuse_dict:
412
417
                            line += str(self.fuse_dict[particle.MG]) + ','
413
418
                            del self.fuse_dict[particle.MG]
414
419
                        else:
439
444
            else:
440
445
                line=' call class_' + ECS.chgt_var.lower() + '(x,'
441
446
            for particle in block.order_content:
442
 
                if particle.MG < 0:
443
 
                    self.use_propa.add(particle.MG)
 
447
 
444
448
                if type(particle.MG) == int:
 
449
                    if particle.MG < 0:
 
450
                        self.use_propa.add(particle.MG)                    
445
451
                    line += str(particle.MG) + ','
446
 
                elif isinstance(particle.MG, basestring):
447
 
                    if self.fuse_dict.has_key(particle.MG):
 
452
                elif isinstance(particle.MG, six.string_types):
 
453
                    if particle.MG in self.fuse_dict:
448
454
                        line += str(self.fuse_dict[particle.MG]) + ','
449
455
                        del self.fuse_dict[particle.MG]
450
456
                    else:
699
705
            if isinstance(self.MWparam['mw_gen']['restrict_channel'], list):
700
706
                allowed_channel = [int(i) for i in self.MWparam['mw_gen']['restrict_channel']]
701
707
            elif self.MWparam['mw_gen']['restrict_channel'] in ['','0','F']:
702
 
                allowed_channel = range(1,len(self.allowed_channel)+1)
 
708
                allowed_channel = list(range(1,len(self.allowed_channel)+1))
703
709
            else:
704
710
                allowed_channel = [int(self.MWparam['mw_gen']['restrict_channel'])]
705
711
            full = allowed_channel + [0] * (len(self.code) - len(allowed_channel))
706
712
            dico['values'] = ','.join(map(str, full))
707
713
        else:
708
 
            dico['values'] = ','.join(map(str, range(1, len(self.code)+1)))
 
714
            dico['values'] = ','.join(map(str, list(range(1, len(self.code)+1))))
709
715
            
710
716
        write_data += put_in_fortran_format("""
711
717
C+-----------------------------------------------------------------------+
1086
1092
                    add_peaks(unaligned, one_peak)
1087
1093
                return
1088
1094
            
1089
 
            if unaligned.has_key(peak):
 
1095
            if peak in unaligned:
1090
1096
                unaligned[peak] += 1
1091
1097
            else:
1092
1098
                if isinstance(peak, str) or peak.external:
1260
1266
        for one_sol in list_local:
1261
1267
            local_mg={}
1262
1268
            for peak, value in one_sol.items():
1263
 
                if isinstance(peak,basestring):
 
1269
                if isinstance(peak,six.string_types):
1264
1270
                    value2=peak.split('_')[-2:]
1265
1271
                    list_d.append(value2)
1266
1272
                else:
1273
1279
        nb_sol = len(list_local)
1274
1280
        for peak, value in dict_all.items():
1275
1281
            if value == nb_sol:
1276
 
                if isinstance(peak,basestring):
1277
 
                    print 'WARNING a peak associated to a visible particle is never '+ \
1278
 
                          'aligned. This will slow down the integration'
 
1282
                if isinstance(peak,six.string_types):
 
1283
                    print('WARNING a peak associated to a visible particle is never '+ \
 
1284
                          'aligned. This will slow down the integration')
1279
1285
                elif peak.MG<0 and peak.external == 0 and peak.channel.startswith('S'):
1280
 
                    print 'WARNING a peak associated to '+str(peak.MG)+' is never '+ \
1281
 
                           'aligned. This will slow down the integration '
 
1286
                    print('WARNING a peak associated to '+str(peak.MG)+' is never '+ \
 
1287
                           'aligned. This will slow down the integration ')
1282
1288
                dict_all[peak] = 0
1283
1289
                for list_peak in list_local:
1284
1290
                    del list_peak[peak]
1289
1295
            except:
1290
1296
                continue
1291
1297
            for one_sol in list_local:
1292
 
                if one_sol.has_key(peak1) and one_sol.has_key(peak2):
 
1298
                if peak1 in one_sol and peak2 in one_sol:
1293
1299
                    del one_sol[peak1]
1294
1300
                    del one_sol[peak2]
1295
1301
                    name1, name2= 'first_d_%s_%s' % (peak1_MG,peak2_MG),'second_d_%s_%s' % (peak1_MG,peak2_MG)
1298
1304
                    dict_all[peak1] -=1
1299
1305
                    dict_all[peak2] -=1
1300
1306
                    dict_all[name1] +=1
1301
 
                    if dict_all.has_key(name2):
 
1307
                    if name2 in dict_all:
1302
1308
                        dict_all[name2] +=1
1303
1309
                    else:
1304
1310
                        dict_all[name2] =1