~maddevelopers/mg5amcnlo/color_ordering

« back to all changes in this revision

Viewing changes to madgraph/madweight/change_tf.py

  • Committer: olivier-mattelaer
  • Date: 2021-02-21 11:03:42 UTC
  • mfrom: (50.85.73 madgraph5)
  • Revision ID: olivier-mattelaer-20210221110342-wn2nvdefctey5e0k
merge up to 2.8.0 --not python3 compatible

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
#Extension
4
4
 
 
5
from __future__ import absolute_import
 
6
from __future__ import print_function
5
7
import os
6
8
import re
7
9
import string
8
10
import sys
9
11
import xml.sax.handler
 
12
import six
 
13
from six.moves import range
 
14
from six.moves import input
10
15
 
11
16
try:
12
17
    import madgraph.madweight.Cards as Cards
25
30
 
26
31
 
27
32
def create_TF_main(name,make, MW_dir):
28
 
    print "start main program"
 
33
    print("start main program")
29
34
    TF_file=Full_TF(name)
30
35
    TF_file.read_file("./data/TF_"+name+".dat")
31
36
 
32
 
    print "deleting the current TFlib: "
 
37
    print("deleting the current TFlib: ")
33
38
    os.system("rm ../../../lib/libTF.a  >& /dev/null")
34
39
     
35
40
    TF_file.create_ordering_file()
36
 
    print "ordering_file.inc created"
 
41
    print("ordering_file.inc created")
37
42
    list_var=TF_file.create_transfer_functions()
38
 
    print "transfer_function.f created"
 
43
    print("transfer_function.f created")
39
44
    TF_file.create_transfer_card(list_var)
40
 
    print "transfer_card.dat created"
 
45
    print("transfer_card.dat created")
41
46
    create_param_inc(list_var)
42
 
    print "TF_param created"
 
47
    print("TF_param created")
43
48
    create_ident_card(list_var)
44
 
    print "ident_card created"      
 
49
    print("ident_card created")      
45
50
    create_version(name)
46
 
    print 'TransferFunctionVersion created'
 
51
    print('TransferFunctionVersion created')
47
52
    fsock = open('nb_tf.inc','w').write('       integer nb_tf\n      parameter (nb_tf=1)\n')
48
53
    os.chdir('../../../') #go to main
49
54
    
53
58
    for directory in MW_dir:
54
59
        obj=TF_in_SubProcesses(TF_file,directory)
55
60
        obj.write_transfer_function_file() 
56
 
    print 'call_TF.f created in for all Subprocesses'
 
61
    print('call_TF.f created in for all Subprocesses')
57
62
    os.chdir('./Source/MadWeight/transfer_function')
58
63
    update_dir(name,make,MW_dir)
59
 
    print 'generation completed'       
 
64
    print('generation completed')       
60
65
           
61
66
 
62
67
#1 ################################################################################# 
404
409
        label_to_block=self.TF_data.find_label_to_block() #return {label:block}
405
410
        
406
411
        if pid in ['x1','x2']: #treat special case for initial particles
407
 
            if label_to_block.has_key(pid):
 
412
            if pid in label_to_block:
408
413
                return label_to_block[pid]
409
414
            else:
410
415
                return -1
411
416
        pid=abs(int(pid))
412
417
        if pid in particle_class.invisible_list:
413
418
            return -1
414
 
        if label_to_block.has_key(pid_to_label[pid]):
 
419
        if pid_to_label[pid] in label_to_block:
415
420
            return label_to_block[pid_to_label[pid]]
416
421
        else:
417
422
            return 0
446
451
        external_done=[]
447
452
        #add the definition for external function
448
453
        for block in self.blockname_list:
449
 
            if isinstance(block, basestring):
 
454
            if isinstance(block, six.string_types):
450
455
                name_list='width_E_'+block+', width_THETA_'+block+', width_PHI_'+block
451
456
            else:
452
457
                continue
492
497
        text='$B$ START_TRANSFER_FCT $E$\n' 
493
498
        
494
499
        met=0
495
 
        if self.TF_data.label_to_block.has_key('met'):
 
500
        if 'met' in self.TF_data.label_to_block:
496
501
            met = self.TF_data.label_to_block['met']
497
502
            #add new definition
498
503
            text+=' double precision p_met_exp(0:3),p_met_rec(0:3)\n'
507
512
        for i in range(0,len(self.blockname_list)):
508
513
            blockname=self.blockname_list[i]
509
514
            
510
 
            if not isinstance(blockname, basestring):
 
515
            if not isinstance(blockname, six.string_types):
511
516
                if met and blockname == -1 and i>2: #invisible particlule but not the initial part
512
517
                    text+=' do i=0,3\n p_met_rec(i)=p_met_rec(i)+p(i,%s)\n enddo\n' %(i+1)
513
518
                continue
539
544
            text2+='\n'+self.text_tf_E_for_one_part(i)+'\n'
540
545
            blockname=self.blockname_list[i]
541
546
            
542
 
            if not isinstance(blockname, basestring):
 
547
            if not isinstance(blockname, six.string_types):
543
548
                text+=' if(MG_num.eq.%s) then\n tf_E_for_part=1d0\n return\n endif\n' % (i+1)
544
549
            else:
545
550
                text+=' if(MG_num.eq.%s) then\n' %(i+1)
566
571
        text+='$B$ DEF_TF_E_FOR_ONE_PART $E$\n'
567
572
        
568
573
        blockname=self.blockname_list[i]            
569
 
        if not isinstance(blockname, basestring):        
 
574
        if not isinstance(blockname, six.string_types):        
570
575
            text+=' tf_E_for_%s=1d0\n' %(i+1) 
571
576
        else:
572
577
            text+=' tf_E_for_%s=1d0\n' %(i+1)
587
592
 
588
593
 
589
594
    if list_var==[]:
590
 
        print "TF_param created (no input)"
 
595
        print("TF_param created (no input)")
591
596
        return
592
597
    
593
598
    common_text=''
716
721
    """ read the file to find the requested change of variable"""
717
722
    
718
723
    found=0
719
 
    for line in file(filepos):
 
724
    for line in open(filepos):
720
725
        if found:
721
726
            name=line.split()[0] #remove blank spae,end of line,...
722
727
            return name
735
740
    opt=sys.argv
736
741
    if len(opt)<2:
737
742
        listdir=os.listdir('./Source/MadWeight/transfer_function/data')
738
 
        print 'Available TF function:\n   ',
739
 
        print '\n    '.join([content[3:-4] for content in listdir if (content.startswith('TF') and content.endswith('dat'))])
740
 
        name=raw_input('Choose your Transfer Function\n')
 
743
        print('Available TF function:\n   ', end=' ')
 
744
        print('\n    '.join([content[3:-4] for content in listdir if (content.startswith('TF') and content.endswith('dat'))]))
 
745
        name=input('Choose your Transfer Function\n')
741
746
    else:
742
747
        name=opt[1]
743
748
        if name in ['proc_card.dat','auto']:
749
754
    os.chdir('./Source/MadWeight/transfer_function')
750
755
    create_TF_main(name,made_make,MW_dir)
751
756
    
752
 
##    file=raw_input("file: ")
 
757
##    file=six.input("file: ")
753
758
##    ff=open(file,'r')
754
759
##    gg=open(file+'_70.f','w')
755
760
##    text=ff.read()