~maddevelopers/mg5amcnlo/simple_unlops

« back to all changes in this revision

Viewing changes to madgraph/iolibs/export_v4.py

  • Committer: olivier-mattelaer
  • Date: 2021-11-12 09:29:31 UTC
  • mfrom: (967.1.15 3.3.0)
  • Revision ID: olivier-mattelaer-20211112092931-4ec9qfzgxkeovqog
versionĀ 3.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
import aloha
40
40
 
 
41
import madgraph
41
42
import madgraph.core.base_objects as base_objects
42
43
import madgraph.core.color_algebra as color
43
44
import madgraph.core.helas_objects as helas_objects
55
56
import madgraph.various.banner as banner_mod
56
57
import madgraph.various.process_checks as process_checks
57
58
import madgraph.loop.loop_diagram_generation as loop_diagram_generation
 
59
import madgraph
58
60
import aloha.create_aloha as create_aloha
59
61
import models.import_ufo as import_ufo
60
62
import models.write_param_card as param_writer
67
69
 
68
70
from madgraph import InvalidCmd
69
71
 
 
72
 
70
73
pjoin = os.path.join
71
74
 
72
75
_file_path = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0] + '/'
73
76
logger = logging.getLogger('madgraph.export_v4')
 
77
if madgraph.ordering:
 
78
    set = misc.OrderedSet
 
79
 
74
80
 
75
81
default_compiler= {'fortran': 'gfortran',
76
82
                       'f2py': 'f2py',
174
180
        self.mgme_dir = MG5DIR
175
181
        self.dir_path = dir_path
176
182
        self.model = None
177
 
 
 
183
        self.beam_polarization = [True,True]
 
184
        
178
185
        self.opt = dict(self.default_opt)
179
186
        if opt:
180
187
            self.opt.update(opt)
194
201
        
195
202
        calls = 0
196
203
        if isinstance(matrix_elements, group_subprocs.SubProcessGroupList):
 
204
            # check handling for the polarization
 
205
            for m in matrix_elements:
 
206
                for me in m.get('matrix_elements'):
 
207
                    for p in me.get('processes'):
 
208
                        for beamid in [1,2]:
 
209
                            for pid in p.get_initial_ids(beamid):
 
210
                                spin = p.get('model').get_particle(pid).get('spin')
 
211
                                if spin != 2:
 
212
                                    self.beam_polarization[beamid-1] = False
 
213
                                    break
 
214
 
197
215
            for (group_number, me_group) in enumerate(matrix_elements):
198
216
                calls = calls + self.generate_subprocess_directory(\
199
217
                                          me_group, fortran_model, group_number)
200
218
        else:
 
219
             # check handling for the polarization
 
220
            self.beam_polarization = [True,True]
 
221
            for me in matrix_elements.get_matrix_elements():
 
222
                for p in me.get('processes'):
 
223
                    for beamid in [1,2]:
 
224
                        for pid in p.get_initial_ids(beamid):
 
225
                            spin = p.get('model').get_particle(pid).get('spin')
 
226
                            if spin != 2:
 
227
                                self.beam_polarization[beamid-1] = False
 
228
                                break
201
229
            for me_number, me in enumerate(matrix_elements.get_matrix_elements()):
202
230
                calls = calls + self.generate_subprocess_directory(\
203
231
                                                   me, fortran_model, me_number)    
 
232
 
204
233
                        
205
234
        return calls    
206
235
        
576
605
                shutil.copy2(pjoin(model_path, file), \
577
606
                                     pjoin(self.dir_path, 'Source', 'MODEL'))
578
607
 
 
608
        # add file for EWA 
 
609
        template = open(pjoin(MG5DIR,'madgraph/iolibs/template_files/madevent_electroweakFlux.inc')).read()
 
610
        fsock = open(pjoin(self.dir_path, 'Source', 'ElectroweakFlux.inc'),'w')
 
611
        fsock.write(template % {'MW': 'wmass','MZ':'zmass'})                 
 
612
        fsock.close() 
 
613
        ln(pjoin(self.dir_path, 'Source', 'ElectroweakFlux.inc'), self.dir_path + '/Source/PDF')
 
614
 
579
615
 
580
616
    def make_model_symbolic_link(self):
581
617
        """Make the copy/symbolic links"""
984
1020
                         for process in matrix_element.get('processes')])
985
1021
 
986
1022
 
987
 
    def get_helicity_lines(self, matrix_element,array_name='NHEL'):
 
1023
    def get_helicity_lines(self, matrix_element,array_name='NHEL', add_nb_comb=False):
988
1024
        """Return the Helicity matrix definition lines for this matrix element"""
989
1025
 
990
1026
        helicity_line_list = []
991
 
        i = 0
 
1027
        i = 0            
 
1028
        if add_nb_comb:
 
1029
            spins = matrix_element.get_spin_state()
 
1030
            spins.insert(0, len(spins))
 
1031
            helicity_line_list.append(\
 
1032
                ("DATA ("+array_name+"(I,0),I=1,%d) /" + \
 
1033
                 ",".join(['%2r'] * (len(spins)-1)) + "/") % tuple(spins))
 
1034
            
992
1035
        for helicities in matrix_element.get_helicity_matrix():
993
1036
            i = i + 1
994
1037
            int_list = [i, len(helicities)]
1404
1447
                # the same coefficient (up to a sign), put it in front
1405
1448
                list_fracs = [abs(coefficient[0][1]) for coefficient in coefs]
1406
1449
                common_factor = False
1407
 
                diff_fracs = list(set(list_fracs))
 
1450
                diff_fracs = misc.make_unique(list_fracs)
1408
1451
                if len(diff_fracs) == 1 and abs(diff_fracs[0]) != 1:
1409
1452
                    common_factor = True
1410
1453
                    global_factor = diff_fracs[0]
4473
4516
        replace_dict['jamp_lines'] = '\n'.join(jamp_lines)
4474
4517
        replace_dict['nb_temp_jamp'] = nb_temp
4475
4518
 
 
4519
        if self.beam_polarization == [True, True]:
 
4520
            replace_dict['beam_polarization'] = """
 
4521
                         DO JJ=1,nincoming
 
4522
               IF(POL(JJ).NE.1d0.AND.NHEL(JJ,I).EQ.INT(SIGN(1d0,POL(JJ)))) THEN
 
4523
                 T=T*ABS(POL(JJ))
 
4524
               ELSE IF(POL(JJ).NE.1d0)THEN
 
4525
                 T=T*(2d0-ABS(POL(JJ)))
 
4526
               ENDIF
 
4527
             ENDDO
 
4528
            """
 
4529
        else:
 
4530
            replace_dict['beam_polarization'] = ""
 
4531
            for i in [0,1]:
 
4532
                if self.beam_polarization[i]:
 
4533
                    replace_dict['beam_polarization'] = """
 
4534
                                   ! handling only one beam polarization here. Second beam can be handle via the pdf.
 
4535
                                   IF(POL(%(bid)i).NE.1d0.AND.NHEL(%(bid)i,I).EQ.INT(SIGN(1d0,POL(%(bid)i)))) THEN
 
4536
                 T=T*ABS(POL(%(bid)i))
 
4537
               ELSE IF(POL(%(bid)i).NE.1d0)THEN
 
4538
                 T=T*(2d0-ABS(POL(%(bid)i)))
 
4539
               ENDIF """ % {'bid': i+1}
 
4540
 
 
4541
 
 
4542
 
 
4543
 
4476
4544
        replace_dict['template_file'] = pjoin(_file_path, \
4477
4545
                          'iolibs/template_files/%s' % self.matrix_file)
4478
4546
        replace_dict['template_file2'] = pjoin(_file_path, \
4584
4652
            replace_dict['define_subdiag_lines'] = ""
4585
4653
            replace_dict['cutsdone'] = "      cutsdone=.false.\n       cutspassed=.false."
4586
4654
 
4587
 
        if not isinstance(self, ProcessExporterFortranMEGroup):
4588
 
            ncomb=matrix_element.get_helicity_combinations()
 
4655
        # extract and replace ncombinations, helicity lines
 
4656
        ncomb=matrix_element.get_helicity_combinations()
 
4657
        replace_dict['ncomb']= ncomb
 
4658
        helicity_lines = self.get_helicity_lines(matrix_element, add_nb_comb=True)
 
4659
        replace_dict['helicity_lines'] = helicity_lines
 
4660
        
 
4661
        if not isinstance(self, ProcessExporterFortranMEGroup):            
4589
4662
            replace_dict['read_write_good_hel'] = self.read_write_good_hel(ncomb)
4590
4663
        else:
4591
4664
            replace_dict['read_write_good_hel'] = ""
4892
4965
            # pass to ping-pong strategy for t-channel for 3 ore more T-channel
4893
4966
            #  this is directly related to change in genps.f
4894
4967
            tstrat = self.opt.get('t_strategy', 0)
 
4968
            if isinstance(self, madgraph.loop.loop_exporters.LoopInducedExporterMEGroup):
 
4969
                tstrat = 2
4895
4970
            tchannels, tchannels_strategy = ProcessExporterFortranME.reorder_tchannels(tchannels, tstrat, self.model)
4896
4971
            
4897
4972
            # For s_and_t_channels (to be used later) use only first config
6393
6468
        self.create_intparam_def(dp=True,mp=False)
6394
6469
        if self.opt['mp']:
6395
6470
            self.create_intparam_def(dp=False,mp=True)
 
6471
        self.create_ewa()
6396
6472
        
6397
6473
        # definition of the coupling.
6398
6474
        self.create_actualize_mp_ext_param_inc()
6760
6836
        self.allCTparameters = [ct.lower() for ct in self.allCTparameters]
6761
6837
        self.usedCTparameters = [ct.lower() for ct in self.usedCTparameters]
6762
6838
        
 
6839
 
 
6840
    def create_ewa(self):
 
6841
        """create electroweakFlux.inc 
 
6842
           this file only need the correct name for the mass for the W and Z
 
6843
        """
 
6844
 
 
6845
        
 
6846
        try:
 
6847
            fsock = self.open(pjoin(self.dir_path,'../PDF/ElectroweakFlux.inc'), format='fortran')
 
6848
        except:
 
6849
            logger.debug('No PDF directory do not cfeate ElectroweakFlux.inc')
 
6850
            return
 
6851
 
 
6852
        masses = {}
 
6853
        for particle in self.model['particles']:
 
6854
            if particle.get('pdg_code') == 24:
 
6855
                masses['MW'] = particle.get('mass')
 
6856
            elif particle.get('pdg_code') == 23:
 
6857
                masses['MZ'] =  particle.get('mass')
 
6858
            if len(masses) == 2:
 
6859
                break
 
6860
 
 
6861
        template = open(pjoin(MG5DIR,'madgraph/iolibs/template_files/madevent_electroweakFlux.inc')).read()
 
6862
        fsock.write(template % masses)                 
 
6863
        fsock.close()
 
6864
 
6763
6865
    def create_intparam_def(self, dp=True, mp=False):
6764
6866
        """ create intparam_definition.inc setting the internal parameters.
6765
6867
        Output the double precision and/or the multiple precision parameters