示例#1
0
    def modify_dummy(self):
        """ """

        plugin_dir = os.path.dirname(os.path.realpath(__file__))

        # Add dedicated functions in dummy_fct.f
        files = ["dummy_fct.f"]  #, "pdg2pdf.f", "reweight.f"]
        remove_list = [['get_dummy_x1_x2', 'dummy_boostframe']
                       ]  #,["store_events","write_leshouche"],["setclscales"]]
        for name, to_rm in zip(files, remove_list):
            template = open(pjoin(self.dir_path, "SubProcesses", name),
                            "r").read()
            plugin = open(pjoin(plugin_dir, "Templates", name), "r").read()
            ff = writers.FortranWriter(
                pjoin(self.dir_path, "SubProcesses", name))
            ff.remove_routine(template, to_rm, formatting=False)
            ff.writelines(plugin, formatting=False)
            ff.close()

        # No need of this one automatic with lpp=9
        #cp(pjoin(rootdir, 'pdg2pdf.f'), pjoin(self.dir_path, 'Source','PDF'))
        #cp(pjoin(rootdir, 'reweight.f'), pjoin(self.dir_path, 'SubProcesses'))

        filename = pjoin(self.dir_path, 'Cards', 'me5_configuration.txt')
        self.cmd.do_save('options %s' % filename.replace(' ', '\ '),
                         check=False,
                         to_keep={'mg5_path': MG5DIR})

        #filename = pjoin(self.dir_path,'Cards', 'proc_card_mg5.dat')
        #self.cmd.do_history(filename)

        return
示例#2
0
    def write_inc_file(self, outpath, identpath, default):
        """ write a fortran file which hardcode the param value"""

        fout = file_writers.FortranWriter(outpath)
        defaultcard = ParamCard(default)
        for line in open(identpath):
            if line.startswith('c  ') or line.startswith('ccccc'):
                continue
            split = line.split()
            if len(split) < 3:
                continue
            block = split[0]
            lhaid = [int(i) for i in split[1:-1]]
            variable = split[-1]
            if block in self:
                try:
                    value = self[block].get(tuple(lhaid)).value
                except KeyError:
                    value = defaultcard[block].get(tuple(lhaid)).value
            else:
                value = defaultcard[block].get(tuple(lhaid)).value
            #value = str(value).lower()
            fout.writelines(' %s = %s' % (variable,
                                          ('%e' % value).replace('e', 'd')))
            fout.writelines(' %s%s = %s_16' % (self.mp_prefix, variable,
                                               ('%e' % value)))
示例#3
0
    def write_inc_file(self, outpath, identpath, default):
        """ write a fortran file which hardcode the param value"""

        fout = file_writers.FortranWriter(outpath)
        defaultcard = ParamCard(default)
        for line in open(identpath):
            if line.startswith('c  ') or line.startswith('ccccc'):
                continue
            split = line.split()
            if len(split) < 3:
                continue
            block = split[0]
            lhaid = [int(i) for i in split[1:-1]]
            variable = split[-1]
            if block in self:
                try:
                    value = self[block].get(tuple(lhaid)).value
                except KeyError:
                    value = defaultcard[block].get(tuple(lhaid)).value
                    logger.warning('information about \"%s %s" is missing using default value: %s.' %\
                                   (block, lhaid, value))

            else:
                value = defaultcard[block].get(tuple(lhaid)).value
                logger.warning('information about \"%s %s" is missing (full block missing) using default value: %s.' %\
                                   (block, lhaid, value))
            value = str(value).lower()
            fout.writelines(' %s = %s' %
                            (variable, str(value).replace('e', 'd')))
    def test_write_fortran_error(self):
        """Test that a non-string gives an error"""

        fsock = StringIO.StringIO()

        non_strings = [1.2, ["hej"]]

        writer = writers.FortranWriter(os.devnull)
        for nonstring in non_strings:
            self.assertRaises(AssertionError, writer.write_line, nonstring)
示例#5
0
    def update_couplinc(self, widths, couplinc):
        """update coupl.inc by adding extra lines for the widths to keep"""

        if not widths:
            # so that the code will compile anyway
            width_list = 'MDL_WDUMMY_KEEP'
        else:
            width_list = ','.join(['%s_keep' % w for w in widths])
        lines = '\n      double precision %s\n      common /keep_widths/%s\n' %(width_list, width_list)
        #outfile = open(couplincpjoin(self.dir_path, 'Source', 'coupl.inc'), 'a')
        outfile = writers.FortranWriter(couplinc, 'a')
        outfile.writelines(lines)
        outfile.close()
示例#6
0
    def write_real_matrix_elements(self, matrix_element, fortran_model):
        """writes the matrix_i.f files which contain the real matrix elements
        and the matrix_i_os_j.f which contain eventual on shell subtraction
        terms""" 
        self.os_ids = self.get_os_ids_from_me(matrix_element)

        for n, fksreal in enumerate(matrix_element.real_processes):
            filename = 'matrix_%d.f' % (n + 1)
            self.write_matrix_element_fks(writers.FortranWriter(filename),
                                          fksreal.matrix_element, n + 1, 
                                          fortran_model, 
                                          os_info = {'diags': fksreal.os_diagrams,
                                                     'ids': fksreal.os_ids,
                                                     'dau_pos': fksreal.os_daughter_pos})

            for nos, os_me in enumerate(fksreal.os_matrix_elements):
                suffix = '%d_os_%d' % (n + 1, nos + 1)
                filename = 'matrix_%s.f' % suffix
                self.write_matrix_element_fks(writers.FortranWriter(filename),
                                            os_me, suffix, fortran_model, 
                                            os_info = {'diags': [], 'ids': fksreal.os_ids, 'dau_pos': []})
                filename = 'wrapper_matrix_%s.f' % suffix
                self.write_os_wrapper(writers.FortranWriter(filename),
                        fksreal.matrix_element, os_me, suffix, fortran_model)
示例#7
0
    def update_get_mass_width(self, width_particles, filename):
        """update the get_mass_width to return also the vaule
        of the _keep widhts"""

        done_particles = []

        iflines_width = ''
        for i, part in enumerate(width_particles):

            if part in done_particles: continue
            done_particles.append(part)

            if i == 0:
                ifstring = 'if'
            else:
                ifstring = 'else if'
            if part['self_antipart']:
                iflines_width += '%s (id.eq.%d) then\n' % \
                        (ifstring, part.get_pdg_code())
            else:
                iflines_width += '%s (id.eq.%d.or.id.eq.%d) then\n' % \
                        (ifstring, part.get_pdg_code(), part.get_anti_pdg_code())
            iflines_width += 'get_width_os_from_id=abs(%s_keep)\n' % part.get('width')

        if len(width_particles)==0:
            iflines_width = 'if (.True.) then\n'

        outfile = writers.FortranWriter(filename, 'a')

        text = """
        DOUBLE PRECISION FUNCTION GET_WIDTH_OS_FROM_ID(ID)
IMPLICIT NONE
INTEGER ID
INCLUDE 'coupl.inc'

%sELSE
GET_WIDTH_OS_FROM_ID=0d0
ENDIF
RETURN
END
"""     % iflines_width
        
        outfile.writelines(text)
        outfile.close()

        return
    def test_write_fortran_line(self):
        """Test writing a fortran line"""

        lines = []
        lines.append(
            " call aaaaaa(bbb, ccc, ddd, eee, fff, ggg, hhhhhhhhhhhhhh+asdasd, wspedfteispd)"
        )

        lines.append('  include "test.inc"')
        lines.append(' print *, \'Hej \\"Da\\" Mo\'')
        lines.append("  IF (Test) then")
        lines.append(" if(mutt) call hej")
        lines.append(" else if(test) then")
        lines.append("c Test")
        lines.append("c = hej")
        lines.append(" Call hej")
        lines.append("# Test")
        lines.append("20 else")
        lines.append("bah=2")
        lines.append(" endif")
        lines.append("test")

        goal_string = """      CALL AAAAAA(BBB, CCC, DDD, EEE, FFF, GGG, HHHHHHHHHHHHHH
     $ +ASDASD, WSPEDFTEISPD)
      INCLUDE 'test.inc'
      PRINT *, 'Hej \\'Da\\' Mo'
      IF (TEST) THEN
        IF(MUTT) CALL HEJ
      ELSE IF(TEST) THEN
C       Test
        C = HEJ
        CALL HEJ
C       Test
 20   ELSE
        BAH=2
      ENDIF
      TEST\n"""

        writer = writers.FortranWriter(self.give_pos('fortran_test')).\
                 writelines(lines)

        # Check that the output stays the same
        self.assertFileContains('fortran_test', goal_string)
示例#9
0
    def write_include_file(self, output_path):
        """writing the run_card.inc file"""

        # For FxFx merging, make sure that the following parameters are set correctly:
        true = ['true', 'True', '.true.', 'T', True, 1, 'TRUE']
        if int(self['ickkw']) == 3:
            # 1. Renormalization and factorization (and ellis-sexton scales) are not fixed
            scales = ['fixed_ren_scale', 'fixed_fac_scale', 'fixed_QES_scale']
            for scale in scales:
                if self[scale] in true:
                    logger.info(
                        '''For consistency in the FxFx merging, \'%s\' has been set to false'''
                        % scale, '$MG:color:BLACK')
                    self[scale] = 'F'
                # 2. Use kT algorithm for jets with pseudo-code size R=1.0
            jetparams = ['jetradius', 'jetalgo']
            for jetparam in jetparams:
                if float(self[jetparam]) != 1.0:
                    logger.info(
                        '''For consistency in the FxFx merging, \'%s\' has been set to 1.0'''
                        % jetparam, '$MG:color:BLACK')
                    self[jetparam] = '1.0'

        #ensure that iappl is present in the card!
        self.get_default('iappl', '0', log_level=10)
        # For interface to APPLGRID, need to use LHAPDF and reweighting to get scale uncertainties
        if self['iappl'] != '0' and self['pdlabel'].lower() != 'lhapdf':
            raise self.InvalidCmd(
                'APPLgrid generation only possible with the use of LHAPDF')
        if self['iappl'] != '0' and self['reweight_scale'] not in true:
            raise self.InvalidCmd('APPLgrid generation only possible with including' +\
                                      ' the reweighting to get scale dependence')

        self.fsock = file_writers.FortranWriter(output_path)
        ################################################################################
        #      Writing the lines corresponding to the cuts
        ################################################################################

        self.add_line('maxjetflavor', 'int', 4)
        # minimum pt
        self.add_line('ptj', 'float', 20)
        self.add_line('etaj', 'float', -1.0)
        self.add_line('ptl', 'float', 20)
        self.add_line('etal', 'float', -1.0)
        # minimum delta_r
        self.add_line('drll', 'float', 0.4)
        self.add_line('drll_sf', 'float', 0.4)
        # minimum invariant mass for pairs
        self.add_line('mll', 'float', 0.0)
        self.add_line('mll_sf', 'float', 0.0)
        #inclusive cuts
        # Jet measure cuts
        self.add_line("jetradius", 'float', 0.7, log=10)

        ################################################################################
        #      Writing the lines corresponding to anything but cuts
        ################################################################################
        # seed
        self.add_line('iseed', 'int', 0)
        self.add_line('parton_shower',
                      'str',
                      'HERWIG6',
                      fortran_name='shower_mc')
        self.add_line('nevents', 'int', 10000)
        self.add_line('event_norm',
                      'str',
                      'average',
                      fortran_name='event_norm')
        # Renormalizrion and factorization scales
        self.add_line('fixed_ren_scale', 'bool', True)
        self.add_line('fixed_fac_scale', 'bool', True)
        self.add_line('fixed_QES_scale', 'bool', True)
        self.add_line('muR_ref_fixed', 'float', 91.188)
        self.add_line('muF1_ref_fixed', 'float', 91.188)
        self.add_line('muF2_ref_fixed', 'float', 91.188)
        self.add_line('QES_ref_fixed', 'float', 91.188)
        self.add_line('muR_over_ref', 'float', 1.0)
        self.add_line('muF1_over_ref', 'float', 1.0)
        self.add_line('muF2_over_ref', 'float', 1.0)
        self.add_line('QES_over_ref', 'float', 1.0)
        #reweight block
        self.add_line('reweight_scale',
                      'bool',
                      True,
                      fortran_name='do_rwgt_scale')
        self.add_line('rw_Rscale_up', 'float', 2.0)
        self.add_line('rw_Rscale_down', 'float', 0.5)
        self.add_line('rw_Fscale_up', 'float', 2.0)
        self.add_line('rw_Fscale_down', 'float', 0.5)
        self.add_line('reweight_PDF', 'bool', True, fortran_name='do_rwgt_pdf')
        self.add_line('PDF_set_min', 'int', 21101)
        self.add_line('PDF_set_max', 'int', 21140)
        self.add_line('iappl', 'int', 0)
        # FxFx merging stuff
        self.add_line('ickkw', 'int', 0)
        self.add_line('jetalgo', 'float', 1.0)
        # Collider energy and type
        self.add_line('lpp1', 'int', 1, fortran_name='lpp(1)')
        self.add_line('lpp2', 'int', 1, fortran_name='lpp(2)')
        self.add_line('ebeam1', 'float', 4000, fortran_name='ebeam(1)')
        self.add_line('ebeam2', 'float', 4000, fortran_name='ebeam(2)')
        # BW cutoff (M+/-bwcutoff*Gamma)
        self.add_line('bwcutoff', 'float', 15.0)
        # Photon isolation
        self.add_line('ptgmin', 'float', 10.0)
        self.add_line('etagamma', 'float', -1.0)
        self.add_line('R0gamma', 'float', 0.4)
        self.add_line('xn', 'float', 1.0)
        self.add_line('epsgamma', 'float', 1.0)
        self.add_line('isoEM', 'bool', True)
        #  Collider pdf
        self.add_line('pdlabel', 'str', 'cteq6_m')
        # check validity of the pdf set
        possible_set = [
            'lhapdf', 'mrs02nl', 'mrs02nn', 'mrs0119', 'mrs0117', 'mrs0121',
            'mrs01_j', 'mrs99_1', 'mrs99_2', 'mrs99_3', 'mrs99_4', 'mrs99_5',
            'mrs99_6', 'mrs99_7', 'mrs99_8', 'mrs99_9', 'mrs9910', 'mrs9911',
            'mrs9912', 'mrs98z1', 'mrs98z2', 'mrs98z3', 'mrs98z4', 'mrs98z5',
            'mrs98ht', 'mrs98l1', 'mrs98l2', 'mrs98l3', 'mrs98l4', 'mrs98l5',
            'cteq3_m', 'cteq3_l', 'cteq3_d', 'cteq4_m', 'cteq4_d', 'cteq4_l',
            'cteq4a1', 'cteq4a2', 'cteq4a3', 'cteq4a4', 'cteq4a5', 'cteq4hj',
            'cteq4lq', 'cteq5_m', 'cteq5_d', 'cteq5_l', 'cteq5hj', 'cteq5hq',
            'cteq5f3', 'cteq5f4', 'cteq5m1', 'ctq5hq1', 'cteq5l1', 'cteq6_m',
            'cteq6_d', 'cteq6_l', 'cteq6l1', 'nn23lo', 'nn23lo1', 'nn23nlo'
        ]
        if self['pdlabel'] not in possible_set:
            raise InvalidRunCard, 'Invalid PDF set (argument of pdlabel) possible choice are:\n %s' % ','.join(
                possible_set)

        if self['pdlabel'] == 'lhapdf':
            self.add_line('lhaid', 'int', 21100)
        else:
            self.add_line('lhaid', 'int', 21100, log=10)

        self.fsock.close()
示例#10
0
    def write_include_file(self, output_path):
        """writing the run_card.inc file"""

        self.fsock = file_writers.FortranWriter(output_path)
        ################################################################################
        #      Writing the lines corresponding to the cuts
        ################################################################################
        # Frixione photon isolation
        self.add_line('ptgmin', 'float', 0.0)
        self.add_line('R0gamma', 'float', 0.4)
        self.add_line('xn', 'float', 1.0)
        self.add_line('epsgamma', 'float', 1.0)
        self.add_line('isoEM', 'bool', True)
        # Cut that need to be deactivated in presence of isolation
        if 'ptgmin' in self and float(self['ptgmin']) > 0:
            if float(self['pta']) > 0:
                logger.warning(
                    'pta cut discarded since photon isolation is used')
                self['pta'] = '0'
            if float(self['draj']) > 0:
                logger.warning(
                    'draj cut discarded since photon isolation is used')
                self['draj'] = '0'

        self.add_line('maxjetflavor', 'int', 4)
        if int(self['maxjetflavor']) > 6:
            raise InvalidRunCard, 'maxjetflavor should be lower than 5! (6 is partly supported)'
        self.add_line('auto_ptj_mjj', 'bool', True)
        self.add_line('cut_decays', 'bool', True)
        # minimum pt
        self.add_line('ptj', 'float', 20)
        self.add_line('ptb', 'float', 20)
        self.add_line('pta', 'float', 20)
        self.add_line('ptl', 'float', 20)
        self.add_line('misset', 'float', 0)
        self.add_line('ptonium', 'float', 0.0)
        # maximal pt
        self.add_line('ptjmax', 'float', -1)
        self.add_line('ptbmax', 'float', -1)
        self.add_line('ptamax', 'float', -1)
        self.add_line('ptlmax', 'float', -1)
        self.add_line('missetmax', 'float', -1)
        # maximal rapidity (absolute value)
        self.add_line('etaj', 'float', 4.0)
        self.add_line('etab', 'float', 4.0)
        self.add_line('etaa', 'float', 4.0)
        self.add_line('etal', 'float', 4.0)
        # minimal rapidity (absolute value)
        self.add_line('etajmin', 'float', 0.0)
        self.add_line('etabmin', 'float', 0.0)
        self.add_line('etaamin', 'float', 0.0)
        self.add_line('etalmin', 'float', 0.0)
        self.add_line('etaonium', 'float', 100.0)
        # Minimul E's
        self.add_line('ej', 'float', 0.0)
        self.add_line('eb', 'float', 0.0)
        self.add_line('ea', 'float', 0.0)
        self.add_line('el', 'float', 0.0)
        # Maximum E's
        self.add_line('ejmax', 'float', -1)
        self.add_line('ebmax', 'float', -1)
        self.add_line('eamax', 'float', -1)
        self.add_line('elmax', 'float', -1)
        # minimum delta_r
        self.add_line('drjj', 'float', 0.4)
        self.add_line('drbb', 'float', 0.4)
        self.add_line('drll', 'float', 0.4)
        self.add_line('draa', 'float', 0.4)
        self.add_line('drbj', 'float', 0.4)
        self.add_line('draj', 'float', 0.4)
        self.add_line('drjl', 'float', 0.4)
        self.add_line('drab', 'float', 0.4)
        self.add_line('drbl', 'float', 0.4)
        self.add_line('dral', 'float', 0.4)
        # maximum delta_r
        self.add_line('drjjmax', 'float', -1)
        self.add_line('drbbmax', 'float', -1)
        self.add_line('drllmax', 'float', -1)
        self.add_line('draamax', 'float', -1)
        self.add_line('drbjmax', 'float', -1)
        self.add_line('drajmax', 'float', -1)
        self.add_line('drjlmax', 'float', -1)
        self.add_line('drabmax', 'float', -1)
        self.add_line('drblmax', 'float', -1)
        self.add_line('dralmax', 'float', -1)
        # minimum invariant mass for pairs
        self.add_line('mmjj', 'float', 0.0)
        self.add_line('mmbb', 'float', 0.0)
        self.add_line('mmaa', 'float', 0.0)
        self.add_line('mmll', 'float', 0.0)
        # maximum invariant mall for pairs
        self.add_line('mmjjmax', 'float', -1)
        self.add_line('mmbbmax', 'float', -1)
        self.add_line('mmaamax', 'float', -1)
        self.add_line('mmllmax', 'float', -1)
        #Min Maxi invariant mass for all leptons
        self.add_line("mmnl", 'float', 0.0)
        self.add_line("mmnlmax", 'float', -1)
        #inclusive cuts
        self.add_line("xptj", 'float', 0.0)
        self.add_line("xptb", 'float', 0.0)
        self.add_line("xpta", 'float', 0.0)
        self.add_line("xptl", 'float', 0.0)
        self.add_line("xmtcentral", 'float', 0.0, fortran_name='xmtc', log=10)
        # WBT cuts
        self.add_line("xetamin", 'float', 0.0)
        self.add_line("deltaeta", 'float', 0.0)
        # Jet measure cuts
        self.add_line("xqcut", 'float', 0.0)
        self.add_line("d", 'float', 1.0, log=10)
        # Set min pt of one heavy particle
        self.add_line("ptheavy", 'float', 0.0)
        # Pt of pairs of leptons (CHARGED AND NEUTRALS)
        self.add_line("ptllmin", "float", 0.0)
        self.add_line("ptllmax", "float", -1)
        # Check   the pt's of the jets sorted by pt
        self.add_line("ptj1min", "float", 0.0)
        self.add_line("ptj1max", "float", -1)
        self.add_line("ptj2min", "float", 0.0)
        self.add_line("ptj2max", "float", -1)
        self.add_line("ptj3min", "float", 0.0)
        self.add_line("ptj3max", "float", -1)
        self.add_line("ptj4min", "float", 0.0)
        self.add_line("ptj4max", "float", -1)
        self.add_line("cutuse", "float", 0.0)
        # Check   the pt's of leptons sorted by pt
        self.add_line("ptl1min", "float", 0.0)
        self.add_line("ptl1max", "float", -1)
        self.add_line("ptl2min", "float", 0.0)
        self.add_line("ptl2max", "float", -1)
        self.add_line("ptl3min", "float", 0.0)
        self.add_line("ptl3max", "float", -1)
        self.add_line("ptl4min", "float", 0.0)
        self.add_line("ptl4max", "float", -1)
        # Check  Ht
        self.add_line("ht2min", 'float', 0.0)
        self.add_line("ht3min", 'float', 0.0)
        self.add_line("ht4min", 'float', 0.0)
        self.add_line("ht2max", 'float', -1)
        self.add_line("ht3max", 'float', -1)
        self.add_line("ht4max", 'float', -1)
        self.add_line("htjmin", 'float', 0.0)
        self.add_line("htjmax", 'float', -1)
        self.add_line("ihtmin", 'float', 0.0)
        self.add_line("ihtmax", 'float', -1)
        # kt_ durham
        self.add_line('ktdurham', 'float', -1, fortran_name='kt_durham')
        self.add_line('dparameter', 'float', 0.4, fortran_name='d_parameter')

        ################################################################################
        #      Writing the lines corresponding to anything but cuts
        ################################################################################
        # lhe output format
        self.add_line("lhe_version", "float",
                      2.0)  #if not specify assume old standard
        # seed
        self.add_line("gridpack", "bool", False)
        self.add_line("gridrun", 'bool', False, log=10)
        if str(self['gridrun']) in ['1','T','.true','True'] and \
           str(self['gridpack']) in ['1','T','.true','True']:
            self.add_line('gseed', 'int', 0, fortran_name='iseed')
        else:
            self.add_line('iseed', 'int', 0, fortran_name='iseed')
        #number of events
        self.add_line('nevents', 'int', 10000)
        #self.add_line('gevents', 'int', 2000, log=10)

        # Renormalizrion and factorization scales
        self.add_line('fixed_ren_scale', 'bool', True)
        self.add_line('fixed_fac_scale', 'bool', True)
        self.add_line('scale', 'float', 'float', 91.188)
        self.add_line('dsqrt_q2fact1', 'float', 91.188, fortran_name='sf1')
        self.add_line('dsqrt_q2fact2', 'float', 91.188, fortran_name='sf2')

        self.add_line('use_syst', 'bool', False)
        #if use_syst is True, some parameter are automatically fixed.
        if self['use_syst'] in self.true:
            value = self.format('float',
                                self.get_default('scalefact', 1.0, 30))
            if value != self.format('float', 1.0):
                logger.warning(
                    'Since use_syst=T, We change the value of \'scalefact\' to 1'
                )
                self['scalefact'] = 1.0
        self.add_line('scalefact', 'float', 1.0)

        self.add_line('fixed_couplings', 'bool', True, log=10)
        self.add_line('ickkw', 'int', 0)
        self.add_line('chcluster', 'bool', False)
        self.add_line('ktscheme', 'int', 1)
        self.add_line('asrwgtflavor', 'int', 5)

        #CKKW TREATMENT!
        if int(self['ickkw']) > 0:
            #if use_syst is True, some parameter are automatically fixed.
            if self['use_syst'] in self.true:
                value = self.format('float',
                                    self.get_default('alpsfact', 1.0, 30))
                if value != self.format('float', 1.0):
                    logger.warning(
                        'Since use_syst=T, We change the value of \'alpsfact\' to 1'
                    )
                    self['alpsfact'] = 1.0
            if int(self['maxjetflavor']) == 6:
                raise InvalidRUnCard, 'maxjetflavor at 6 is NOT supported for matching!'
            self.add_line('alpsfact', 'float', 1.0)
            self.add_line('pdfwgt', 'bool', True)
            self.add_line('clusinfo', 'bool', False)
            # check that DRJJ and DRJL are set to 0 and MMJJ
            if self.format('float', self['drjj']) != self.format('float', 0.):
                logger.warning(
                    'Since icckw>0, We change the value of \'drjj\' to 0')
            if self.format('float', self['drjl']) != self.format('float', 0.):
                logger.warning(
                    'Since icckw>0, We change the value of \'drjl\' to 0')
            if self.format('bool', self['auto_ptj_mjj']) == '.false.':
                #ensure formatting
                mmjj = self['mmjj']
                if isinstance(mmjj, str):
                    mmjj = float(mmjj.replace('d', 'e'))
                xqcut = self['xqcut']
                if isinstance(xqcut, str):
                    xqcut = float(xqcut.replace('d', 'e'))

                if mmjj > xqcut:
                    logger.warning(
                        'mmjj > xqcut (and auto_ptj_mjj = F). MMJJ set to 0')
                    self.add_line('mmjj', 'float', 0)

        if int(self['ickkw']) == 2:
            self.add_line('highestmult', 'int', 0, fortran_name='nhmult')
            self.add_line('issgridfile', 'str', 'issudgrid.dat')

        # Collider energy and type
        self.add_line('lpp1', 'int', 1, fortran_name='lpp(1)')
        self.add_line('lpp2', 'int', 1, fortran_name='lpp(2)')
        self.add_line('ebeam1', 'float', 7000, fortran_name='ebeam(1)')
        self.add_line('ebeam2', 'float', 7000, fortran_name='ebeam(2)')
        # Beam polarization
        self.add_line('polbeam1', 'float', 0.0, fortran_name='pb1')
        self.add_line('polbeam2', 'float', 0.0, fortran_name='pb2')
        # BW cutoff (M+/-bwcutoff*Gamma)
        self.add_line('bwcutoff', 'float', 15.0)
        #  Collider pdf
        self.add_line('pdlabel', 'str', 'cteq6l1')

        # check validity of the pdf set
        possible_set = [
            'lhapdf', 'mrs02nl', 'mrs02nn', 'mrs0119', 'mrs0117', 'mrs0121',
            'mrs01_j', 'mrs99_1', 'mrs99_2', 'mrs99_3', 'mrs99_4', 'mrs99_5',
            'mrs99_6', 'mrs99_7', 'mrs99_8', 'mrs99_9', 'mrs9910', 'mrs9911',
            'mrs9912', 'mrs98z1', 'mrs98z2', 'mrs98z3', 'mrs98z4', 'mrs98z5',
            'mrs98ht', 'mrs98l1', 'mrs98l2', 'mrs98l3', 'mrs98l4', 'mrs98l5',
            'cteq3_m', 'cteq3_l', 'cteq3_d', 'cteq4_m', 'cteq4_d', 'cteq4_l',
            'cteq4a1', 'cteq4a2', 'cteq4a3', 'cteq4a4', 'cteq4a5', 'cteq4hj',
            'cteq4lq', 'cteq5_m', 'cteq5_d', 'cteq5_l', 'cteq5hj', 'cteq5hq',
            'cteq5f3', 'cteq5f4', 'cteq5m1', 'ctq5hq1', 'cteq5l1', 'cteq6_m',
            'cteq6_d', 'cteq6_l', 'cteq6l1', 'nn23lo', 'nn23lo1', 'nn23nlo'
        ]
        if self['pdlabel'] not in possible_set:
            raise InvalidRunCard, 'Invalid PDF set (argument of pdlabel) possible choice are:\n %s' % ','.join(
                possible_set)

        if self['pdlabel'] == 'lhapdf':
            self.add_line('lhaid', 'int', 10042)
        else:
            self.add_line('lhaid', 'int', 10042, log=10)

        self.fsock.close()
示例#11
0
            
            return '\n'.join(formatted_lines)
            
        # Now we define the raw banner text for each style:
        
        return format_banner(
                 cls.get_raw_banner(style.lower())
                 %{'versionref':versionref, 'ref':reference, 'version':version})

# Below we have a small standalone code to test the MadLoop Banner output
if __name__=='__main__':
    import madgraph.iolibs.file_writers as writers
    import os
    import copy
    pjoin = os.path.join
    writer = writers.FortranWriter('test_ML_banner.f')

    styles = copy.copy(MadLoopBannerStyles.get_style_keys())
    styles.append('random')
    # Edit the line above and select here a subset of the available styles to 
    # show. Possibilities are:
    # ['classic','classic2','classic3','big','funky',
    # 'curly','keyboard','bubbles','mario','wiggly',
    # 'printed','fast','isometric','random']
    # styles = ['funky']
    
    f_code = ""
    for style in styles:
        f_code += "\nwrite(*,*) ''\nwrite(*,*) 'Style %s with default options.'\n"%style
        f_code += MadLoopBannerStyles.get_MadLoop_Banner(style=style)
示例#12
0
        n = len(items)
        # We use the fact that
        # (n choose k) = (1 choose 1)(n-1 choose k-1)+(1 choose 0)(n-1 choose k)
        if k == n:
            yield items[:]
        elif k == 0:
            yield []
        elif 0 < k and k < n:
            head = items[0:1]
            tail = items[1:]
            for result in cls.select(tail, k - 1):
                yield head + result
            for result in cls.select(tail, k):
                yield result


if __name__ == '__main__':
    """I test here the write_golem95_mapping function"""

    max_rank = 6
    FPR = FortranPolynomialRoutines(max_rank)
    print "Output of write_golem95_mapping function for max_rank=%d:\n\n" % max_rank

    import os
    import sys
    root_path = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]
    sys.path.insert(0, os.path.join(root_path, os.path.pardir))
    import madgraph.iolibs.file_writers as writers
    FWriter = writers.FortranWriter("GOLEM95_interface.f")
    FWriter.writelines(FPR.write_golem95_mapping())
示例#13
0
    def write_include_file(self, output_path):
        """writing the run_card.inc file""" 
        
        self.fsock = file_writers.FortranWriter(output_path)    
################################################################################
#      Writing the lines corresponding to the cuts
################################################################################
    
        self.add_line('maxjetflavor', 'int', 4)
        self.add_line('auto_ptj_mjj', 'bool', True)
        self.add_line('cut_decays', 'bool', True)
        # minimum pt
        self.add_line('ptj', 'float', 20)
        self.add_line('ptb', 'float', 20)
        self.add_line('pta', 'float', 20)
        self.add_line('ptl', 'float', 20)
        self.add_line('misset', 'float', 0)
        self.add_line('ptonium', 'float', 0.0)
        # maximal pt
        self.add_line('ptjmax', 'float', -1)
        self.add_line('ptbmax', 'float', -1)
        self.add_line('ptamax', 'float', -1)
        self.add_line('ptlmax', 'float', -1)
        self.add_line('missetmax', 'float', -1)
        # maximal rapidity (absolute value)
        self.add_line('etaj', 'float', 4.0)
        self.add_line('etab', 'float', 4.0)
        self.add_line('etaa', 'float', 4.0)
        self.add_line('etal', 'float', 4.0)
        # minimal rapidity (absolute value)
        self.add_line('etajmin', 'float', 0.0)
        self.add_line('etabmin', 'float', 0.0)
        self.add_line('etaamin', 'float', 0.0)
        self.add_line('etalmin', 'float', 0.0)
        self.add_line('etaonium', 'float', 100.0)
        # Minimul E's
        self.add_line('ej', 'float', 0.0)
        self.add_line('eb', 'float', 0.0)
        self.add_line('ea', 'float', 0.0)
        self.add_line('el', 'float', 0.0)
        # Maximum E's
        self.add_line('ejmax', 'float', -1)
        self.add_line('ebmax', 'float', -1)
        self.add_line('eamax', 'float', -1)
        self.add_line('elmax', 'float', -1)     
        # minimum delta_r
        self.add_line('drjj', 'float', 0.4)     
        self.add_line('drbb', 'float', 0.4)     
        self.add_line('drll', 'float', 0.4)     
        self.add_line('draa', 'float', 0.4)     
        self.add_line('drbj', 'float', 0.4)     
        self.add_line('draj', 'float', 0.4)     
        self.add_line('drjl', 'float', 0.4)     
        self.add_line('drab', 'float', 0.4)     
        self.add_line('drbl', 'float', 0.4)     
        self.add_line('dral', 'float', 0.4)     
        # maximum delta_r
        self.add_line('drjjmax', 'float', -1)
        self.add_line('drbbmax', 'float', -1)
        self.add_line('drllmax', 'float', -1)
        self.add_line('draamax', 'float', -1)
        self.add_line('drbjmax', 'float', -1)
        self.add_line('drajmax', 'float', -1)
        self.add_line('drjlmax', 'float', -1)
        self.add_line('drabmax', 'float', -1)
        self.add_line('drblmax', 'float', -1)
        self.add_line('dralmax', 'float', -1)
        # minimum invariant mass for pairs
        self.add_line('mmjj', 'float', 0.0)
        self.add_line('mmbb', 'float', 0.0)
        self.add_line('mmaa', 'float', 0.0)
        self.add_line('mmll', 'float', 0.0)
        # maximum invariant mall for pairs
        self.add_line('mmjjmax', 'float', -1)
        self.add_line('mmbbmax', 'float', -1)
        self.add_line('mmaamax', 'float', -1)
        self.add_line('mmllmax', 'float', -1)
        #Min Maxi invariant mass for all leptons 
        self.add_line("mmnl", 'float', 0.0)
        self.add_line("mmnlmax", 'float', -1)
        #inclusive cuts
        self.add_line("xptj", 'float', 0.0)
        self.add_line("xptb", 'float', 0.0)
        self.add_line("xpta", 'float', 0.0)
        self.add_line("xptl", 'float', 0.0)
        self.add_line("xmtcentral", 'float', 0.0, fortran_name='xmtc', log=10)
        # WBT cuts
        self.add_line("xetamin", 'float', 0.0)
        self.add_line("deltaeta", 'float', 0.0)
        # Jet measure cuts 
        self.add_line("xqcut", 'float', 0.0)
        self.add_line("d", 'float', 1.0, log=10)
        # Set min pt of one heavy particle 
        self.add_line("ptheavy", 'float', 0.0)
        # Pt of pairs of leptons (CHARGED AND NEUTRALS)
        self.add_line("ptllmin", "float", 0.0)
        self.add_line("ptllmax", "float", -1)
        # Check   the pt's of the jets sorted by pt
        self.add_line("ptj1min", "float", 0.0)
        self.add_line("ptj1max", "float", -1)
        self.add_line("ptj2min", "float", 0.0)
        self.add_line("ptj2max", "float", -1)
        self.add_line("ptj3min", "float", 0.0)
        self.add_line("ptj3max", "float", -1)
        self.add_line("ptj4min", "float", 0.0)
        self.add_line("ptj4max", "float", -1)
        self.add_line("cutuse", "float", 0.0)
        # Check   the pt's of leptons sorted by pt
        self.add_line("ptl1min", "float", 0.0)
        self.add_line("ptl1max", "float", -1)
        self.add_line("ptl2min", "float", 0.0)
        self.add_line("ptl2max", "float", -1)
        self.add_line("ptl3min", "float", 0.0)
        self.add_line("ptl3max", "float", -1)
        self.add_line("ptl4min", "float", 0.0)
        self.add_line("ptl4max", "float", -1)
        # Check  Ht
        self.add_line("ht2min", 'float', 0.0)
        self.add_line("ht3min", 'float', 0.0)
        self.add_line("ht4min", 'float', 0.0)
        self.add_line("ht2max", 'float', -1)
        self.add_line("ht3max", 'float', -1)
        self.add_line("ht4max", 'float', -1)        
        self.add_line("htjmin", 'float', 0.0)
        self.add_line("htjmax", 'float', -1)        
        self.add_line("ihtmin", 'float', 0.0)
        self.add_line("ihtmax", 'float', -1)

################################################################################
#      Writing the lines corresponding to anything but cuts
################################################################################
        # seed
        self.add_line("gridpack","bool", False)
        self.add_line("gridrun",'bool', False, log=10)
        if str(self['gridrun']) in ['1','T','.true','True'] and \
           str(self['gridpack']) in ['1','T','.true','True']:
            self.add_line('gseed', 'int', 0, fortran_name='iseed')
        else:
            self.add_line('iseed', 'int', 0, fortran_name='iseed')
        # Renormalizrion and factorization scales
        self.add_line('fixed_ren_scale', 'bool', True)
        self.add_line('fixed_fac_scale', 'bool', True)
        self.add_line('scale', 'float', 'float', 91.188)
        self.add_line('dsqrt_q2fact1','float', 91.188, fortran_name='sf1')
        self.add_line('dsqrt_q2fact2', 'float', 91.188, fortran_name='sf2')
        self.add_line('scalefact', 'float', 1.0)
        self.add_line('fixed_couplings', 'bool', True, log=10)
        self.add_line('ickkw', 'int', 0)
        self.add_line('chcluster', 'bool', False)
        self.add_line('ktscheme', 'int', 1)
        self.add_line('asrwgtflavor', 'int', 5)
        if int(self['ickkw'])>0:
            self.add_line('alpsfact', 'float', 1.0)
            self.add_line('pdfwgt', 'bool', True)
        if int(self['ickkw'])==2:
            self.add_line('highestmult','int', 0, fortran_name='nhmult')
            self.add_line('issgridfile','str','issudgrid.dat')
        # Collider energy and type
        self.add_line('lpp1', 'int', 1, fortran_name='lpp(1)')
        self.add_line('lpp2', 'int', 1, fortran_name='lpp(2)')
        self.add_line('ebeam1', 'float', 7000, fortran_name='ebeam(1)')
        self.add_line('ebeam2', 'float', 7000, fortran_name='ebeam(2)')
        # Beam polarization
        self.add_line('polbeam1', 'float', 0.0, fortran_name='pb1')
        self.add_line('polbeam2', 'float', 0.0, fortran_name='pb2')
        # BW cutoff (M+/-bwcutoff*Gamma)
        self.add_line('bwcutoff', 'float', 15.0)
        #  Collider pdf
        self.add_line('pdlabel','str','cteq6l1')
        if self['pdlabel'] == 'lhapdf':
            self.add_line('lhaid', 'int', 10042)
        else:
            self.add_line('lhaid', 'int', 10042, log=10)
        
        self.fsock.close()
示例#14
0
    def testIO_Loop_sqso_uux_ddx(self):
        """ target: [loop_matrix(.*)\.f]
        """

        myleglist = base_objects.LegList()
        myleglist.append(base_objects.Leg({'id': 2, 'state': False}))
        myleglist.append(base_objects.Leg({'id': -2, 'state': False}))
        myleglist.append(base_objects.Leg({'id': 1, 'state': True}))
        myleglist.append(base_objects.Leg({'id': -1, 'state': True}))

        fortran_model=\
          helas_call_writers.FortranUFOHelasCallWriterOptimized(self.model,False)

        SO_tests = [({}, ['QCD',
                          'QED'], {}, {}, ['QCD',
                                           'QED'], 'QCDQEDpert_default'),
                    ({}, ['QCD'], {}, {}, ['QCD'], 'QCDpert_default'),
                    ({}, ['QED'], {}, {}, ['QED'], 'QEDpert_default'),
                    ({}, ['QCD', 'QED'], {
                        'QCD': 4
                    }, {
                        'QCD': '=='
                    }, ['QCD', 'QED'], 'QCDQEDpert_QCDsq_eq_4'),
                    ({}, ['QCD', 'QED'], {
                        'QED': 4
                    }, {
                        'QCD': '<='
                    }, ['QCD', 'QED'], 'QCDQEDpert_QEDsq_le_4'),
                    ({}, ['QCD', 'QED'], {
                        'QCD': 4
                    }, {
                        'QCD': '>'
                    }, ['QCD', 'QED'], 'QCDQEDpert_QCDsq_gt_4'),
                    ({
                        'QED': 2
                    }, ['QCD', 'QED'], {
                        'QCD': 0,
                        'QED': 2
                    }, {
                        'QCD': '>',
                        'QED': '>'
                    }, ['QCD',
                        'QED'], 'QCDQEDpert_QCDsq_gt_0_QEDAmpAndQEDsq_gt_2'),
                    ({
                        'QED': 2
                    }, ['QCD', 'QED'], {
                        'WEIGHTED': 10,
                        'QED': 2
                    }, {
                        'WEIGHTED': '<=',
                        'QED': '>'
                    }, ['WEIGHTED', 'QCD',
                        'QED'], 'QCDQEDpert_WGTsq_le_10_QEDAmpAndQEDsq_gt_2')]

        for orders, pert_orders, sq_orders , sq_orders_type, split_orders, name \
                                                                    in SO_tests:
            myproc = base_objects.Process({
                'legs': myleglist,
                'model': self.model,
                'orders': orders,
                'squared_orders': sq_orders,
                'perturbation_couplings': pert_orders,
                'sqorders_types': sq_orders_type,
                'split_orders': split_orders
            })

            myloopamp = loop_diagram_generation.LoopAmplitude(myproc)
            matrix_element=loop_helas_objects.LoopHelasMatrixElement(\
                                                myloopamp,optimized_output=True)
            writer = writers.FortranWriter(\
                                     pjoin(self.IOpath,'loop_matrix_%s.f'%name))

            # It is enough here to generate and check the filer loop_matrix.f
            # only here. For that we must initialize the general replacement
            # dictionary first (The four functions below are normally directly
            # called from the write_matrix_element function in the exporter
            # [but we don't call it here because we only want the file
            # loop_matrix.f]).
            matrix_element.rep_dict = self.exporter.\
                                   generate_general_replace_dict(matrix_element)

            # and for the same reason also force the computation of the analytical
            # information in the Helas loop diagrams.
            matrix_element.compute_all_analytic_information(
                self.exporter.get_aloha_model(self.model))

            # Finally the entries specific to the optimized output
            self.exporter.set_optimized_output_specific_replace_dict_entries(\
                                                                 matrix_element)

            # We can then finally write out 'loop_matrix.f'
            self.exporter.write_loopmatrix(writer,
                                           matrix_element,
                                           fortran_model,
                                           noSplit=True,
                                           write_auxiliary_files=False)
示例#15
0
    def write_include_file(self, output_path):
        """writing the run_card.inc file""" 
        
        self.fsock = file_writers.FortranWriter(output_path)    
################################################################################
#      Writing the lines corresponding to the cuts
################################################################################
    
        self.add_line('maxjetflavor', 'int', 4)
        # minimum pt
        self.add_line('ptj', 'float', 20)
        self.add_line('etaj', 'float', -1.0)
        self.add_line('ptl', 'float', 20)
        self.add_line('etal', 'float', -1.0)
        # minimum delta_r
        self.add_line('drll', 'float', 0.4)     
        self.add_line('drll_sf', 'float', 0.4)     
        # minimum invariant mass for pairs
        self.add_line('mll', 'float', 0.0)
        self.add_line('mll_sf', 'float', 0.0)
        #inclusive cuts
        # Jet measure cuts 
        self.add_line("jetradius", 'float', 0.7, log=10)

################################################################################
#      Writing the lines corresponding to anything but cuts
################################################################################
        # seed
        self.add_line('iseed', 'int', 0)
        self.add_line('parton_shower', 'str', 'HERWIG6', fortran_name='shower_mc')
        self.add_line('nevents', 'int', 10000)
        self.add_line('event_norm', 'str', 'average', fortran_name='event_norm')
        # Renormalizrion and factorization scales
        self.add_line('fixed_ren_scale', 'bool', True)
        self.add_line('fixed_fac_scale', 'bool', True)
        self.add_line('fixed_QES_scale', 'bool', True)
        self.add_line('muR_ref_fixed', 'float', 91.188)
        self.add_line('muF1_ref_fixed','float', 91.188)
        self.add_line('muF2_ref_fixed', 'float', 91.188)
        self.add_line('QES_ref_fixed', 'float', 91.188)
        self.add_line('muR_over_ref', 'float', 1.0)
        self.add_line('muF1_over_ref', 'float', 1.0)
        self.add_line('muF2_over_ref', 'float', 1.0)
        self.add_line('QES_over_ref', 'float', 1.0)
        #reweight block
        self.add_line('reweight_scale', 'bool', True, fortran_name='do_rwgt_scale')
        self.add_line('rw_Rscale_up', 'float', 2.0)
        self.add_line('rw_Rscale_down', 'float', 0.5)
        self.add_line('rw_Fscale_up', 'float', 2.0)
        self.add_line('rw_Fscale_down', 'float', 0.5)
        self.add_line('reweight_PDF', 'bool', True, fortran_name='do_rwgt_pdf')
        self.add_line('PDF_set_min', 'int', 21101)
        self.add_line('PDF_set_max', 'int', 21140)
        # FxFx merging stuff
        self.add_line('ickkw', 'int', 0)
        # self.add_line('fixed_couplings', 'bool', True, log=10)
        self.add_line('jetalgo', 'float', 1.0)
        # Collider energy and type
        self.add_line('lpp1', 'int', 1, fortran_name='lpp(1)')
        self.add_line('lpp2', 'int', 1, fortran_name='lpp(2)')
        self.add_line('ebeam1', 'float', 4000, fortran_name='ebeam(1)')
        self.add_line('ebeam2', 'float', 4000, fortran_name='ebeam(2)')
        # BW cutoff (M+/-bwcutoff*Gamma)
        self.add_line('bwcutoff', 'float', 15.0)
        # Photon isolation
        self.add_line('ptgmin', 'float', 10.0)
        self.add_line('etagamma', 'float', -1.0)
        self.add_line('R0gamma', 'float', 0.4)
        self.add_line('xn', 'float', 1.0)
        self.add_line('epsgamma', 'float', 1.0)
        self.add_line('isoEM', 'bool', True)
        #  Collider pdf
        self.add_line('pdlabel','str','cteq6_m')
        if self['pdlabel'] == 'lhapdf':
            self.add_line('lhaid', 'int', 21100)
        else:
            self.add_line('lhaid', 'int', 21100, log=10)
        
        self.fsock.close()
示例#16
0
    def ML5export(self, nojpeg=False, main_file_name=""):
        """Export a generated amplitude to file"""
        def generate_matrix_elements(self):
            """Helper function to generate the matrix elements before exporting"""

            # Sort amplitudes according to number of diagrams,
            # to get most efficient multichannel output
            self._curr_amps.sort(lambda a1, a2: a2.get_number_of_diagrams() - \
                                 a1.get_number_of_diagrams())

            cpu_time1 = time.time()
            ndiags = 0
            if not self._curr_matrix_elements.get_matrix_elements():
                self._curr_matrix_elements = \
                    loop_helas_objects.LoopHelasProcess(self._curr_amps,
                    optimized_output = self.options['loop_optimized_output'])
                ndiags = sum([len(me.get('diagrams')) for \
                              me in self._curr_matrix_elements.\
                              get_matrix_elements()])
                # assign a unique id number to all process
                uid = 0
                for me in self._curr_matrix_elements.get_matrix_elements():
                    uid += 1  # update the identification number
                    me.get('processes')[0].set('uid', uid)

            cpu_time2 = time.time()
            return ndiags, cpu_time2 - cpu_time1

        # Start of the actual routine
        ndiags, cpu_time = generate_matrix_elements(self)

        calls = 0

        path = self._export_dir
        if self._export_format in self.supported_ML_format:
            path = pjoin(path, 'SubProcesses')

        cpu_time1 = time.time()

        # Pick out the matrix elements in a list
        matrix_elements = \
                        self._curr_matrix_elements.get_matrix_elements()

        # Fortran MadGraph5_aMC@NLO Standalone
        if self._export_format in self.supported_ML_format:
            for me in matrix_elements:
                calls = calls + \
                        self._curr_exporter.generate_subprocess_directory_v4(\
                            me, self._curr_fortran_model)
            # If all ME's do not share the same maximum loop vertex rank and the
            # same loop maximum wavefunction size, we need to set the maximum
            # in coef_specs.inc of the HELAS Source. The SubProcesses/P* directory
            # all link this file, so it should be properly propagated
            if self.options['loop_optimized_output'] and len(
                    matrix_elements) > 1:
                max_lwfspins = [m.get_max_loop_particle_spin() for m in \
                                                                matrix_elements]
                max_loop_vert_ranks = [me.get_max_loop_vertex_rank() for me in \
                                                                matrix_elements]
                if len(set(max_lwfspins)) > 1 or len(
                        set(max_loop_vert_ranks)) > 1:
                    self._curr_exporter.fix_coef_specs(max(max_lwfspins),\
                                                       max(max_loop_vert_ranks))

        # Just the matrix.f files
        if self._export_format == 'matrix':
            for me in matrix_elements:
                filename = pjoin(path, 'matrix_' + \
                           me.get('processes')[0].shell_string() + ".f")
                if os.path.isfile(filename):
                    logger.warning("Overwriting existing file %s" % filename)
                else:
                    logger.info("Creating new file %s" % filename)
                calls = calls + self._curr_exporter.write_matrix_element_v4(\
                    writers.FortranWriter(filename),\
                    me, self._curr_fortran_model)

        cpu_time2 = time.time() - cpu_time1

        logger.info(("Generated helas calls for %d subprocesses " + \
              "(%d diagrams) in %0.3f s") % \
              (len(matrix_elements),
               ndiags, cpu_time))

        if calls:
            if "cpu_time2" in locals():
                logger.info("Wrote files for %d OPP calls in %0.3f s" % \
                            (calls, cpu_time2))
            else:
                logger.info("Wrote files for %d OPP calls" % \
                            (calls))

        # Replace the amplitudes with the actual amplitudes from the
        # matrix elements, which allows proper diagram drawing also of
        # decay chain processes
        self._curr_amps = diagram_generation.AmplitudeList(\
               [me.get('base_amplitude') for me in \
                matrix_elements])