Esempio n. 1
0
    def make_stdHep():
        print "Compiling StdHEP in %s."%str(os.path.join(MG5DIR, 'vendor', 'StdHEP'))
        # this is for 64-bit systems
        if sys.maxsize > 2**32:
            path = os.path.join(MG5DIR, 'vendor', 'StdHEP', 'src', 'make_opts')
            text = open(path).read()
            text = text.replace('MBITS=32','MBITS=64')
            open(path, 'w').writelines(text)
        # Set the correct fortran compiler
        if 'FC' not in os.environ or not os.environ['FC']:
            if misc.which('gfortran'):
                compiler = 'FC=gfortran'
            elif misc.which('g77'):
                compiler = 'FC=g77'
            else:
                raise self.InvalidCmd('Require g77 or Gfortran compiler')
        else:
            compiler = '#FC=gfortran'

        base_compiler= ['FC=g77','FC=gfortran','#FC=g77','#FC=gfortran']
        path = None            
        path = os.path.join(MG5DIR, 'vendor', 'StdHEP', 'src', 'make_opts')
        text = open(path).read()
        for base in base_compiler:
            text = text.replace(base,compiler)
        open(path, 'w').writelines(text)

        misc.compile(cwd = os.path.join(MG5DIR, 'vendor', 'StdHEP'))
Esempio n. 2
0
    def launch_program(self):
        """launch the main program"""

        # Make pythia8
        print "Running make for pythia8 directory"
        if self.model_dir:
            print "Running make in %s" % self.model_dir
            misc.compile(cwd=self.model_dir, mode='cpp')
        # Finally run make for executable
        makefile = self.executable.replace("main_", "Makefile_")
        print "Running make with %s" % makefile
        misc.compile(arg=['-f', makefile], cwd=self.running_dir, mode='cpp')

        print "Running " + self.executable

        output = open(os.path.join(self.running_dir, self.name), 'w')
        if not self.executable.startswith('./'):
            self.executable = os.path.join(".", self.executable)
        subprocess.call([self.executable],
                        stdout=output,
                        stderr=output,
                        cwd=self.running_dir)

        # Display the cross-section to the screen
        path = os.path.join(self.running_dir, self.name)
        pydoc.pager(open(path).read())

        print "Output of the run is found at " + \
              os.path.realpath(os.path.join(self.running_dir, self.name))
Esempio n. 3
0
    def make_stdHep():
        print "Compiling StdHEP in %s." % str(
            os.path.join(MG5DIR, 'vendor', 'StdHEP'))
        # this is for 64-bit systems
        if sys.maxsize > 2**32:
            path = os.path.join(MG5DIR, 'vendor', 'StdHEP', 'src', 'make_opts')
            text = open(path).read()
            text = text.replace('MBITS=32', 'MBITS=64')
            open(path, 'w').writelines(text)
        # Set the correct fortran compiler
        if 'FC' not in os.environ or not os.environ['FC']:
            if misc.which('gfortran'):
                compiler = 'FC=gfortran'
            elif misc.which('g77'):
                compiler = 'FC=g77'
            else:
                raise self.InvalidCmd('Require g77 or Gfortran compiler')
        else:
            compiler = '#FC=gfortran'

        base_compiler = ['FC=g77', 'FC=gfortran', '#FC=g77', '#FC=gfortran']
        path = None
        path = os.path.join(MG5DIR, 'vendor', 'StdHEP', 'src', 'make_opts')
        text = open(path).read()
        for base in base_compiler:
            text = text.replace(base, compiler)
        open(path, 'w').writelines(text)

        misc.compile(cwd=os.path.join(MG5DIR, 'vendor', 'StdHEP'))
Esempio n. 4
0
    def generate(self, process, model):
        """Create a process"""

        try:
            shutil.rmtree(self.run_dir)
        except Exception as error:
            pass
        interface = MGCmd.MasterCmd()
        interface.no_notification()
        interface.run_cmd('import model %s' % model)
        if isinstance(process, str):
            interface.run_cmd('generate %s' % process)
        else:
            for p in process:
                interface.run_cmd('add process %s' % p)

        if logging.getLogger('madgraph').level <= 20:
            stdout = None
            stderr = None
        else:
            devnull = open(os.devnull, 'w')
            stdout = devnull
            stderr = devnull

        if not os.path.exists(pjoin(MG5DIR, 'pythia-pgs')):
            print("install pythia-pgs")
            p = subprocess.Popen([pjoin(MG5DIR, 'bin', 'mg5')],
                                 stdin=subprocess.PIPE,
                                 stdout=stdout,
                                 stderr=stderr)
            out = p.communicate('install pythia-pgs'.encode())
        misc.compile(cwd=pjoin(MG5DIR, 'pythia-pgs'))
        if not os.path.exists(pjoin(MG5DIR, 'MadAnalysis')):
            print("install MadAnalysis")
            p = subprocess.Popen([pjoin(MG5DIR, 'bin', 'mg5')],
                                 stdin=subprocess.PIPE,
                                 stdout=stdout,
                                 stderr=stderr)
            out = p.communicate('install MadAnalysis4'.encode())
        misc.compile(cwd=pjoin(MG5DIR, 'MadAnalysis'))

        if not misc.which('root'):
            raise Exception('root is require for this test')
        interface.exec_cmd('set pythia-pgs_path %s --no_save' %
                           pjoin(MG5DIR, 'pythia-pgs'))
        interface.exec_cmd('set madanalysis_path %s --no_save' %
                           pjoin(MG5DIR, 'MadAnalysis'))
        interface.onecmd('output madevent %s -f' % self.run_dir)

        if os.path.exists(pjoin(interface.options['syscalc_path'],
                                'sys_calc')):
            shutil.rmtree(interface.options['syscalc_path'])
            #print "install SysCalc"
            #interface.onecmd('install SysCalc')

        self.cmd_line = MECmd.MadEventCmdShell(me_dir=self.run_dir)
        self.cmd_line.no_notification()
        self.cmd_line.options['syscalc_path'] = pjoin(MG5DIR, 'SysCalc')
Esempio n. 5
0
    def calculate_matrix_element(self, event, hypp_id):
        """routine to return the matrix element"""

        tag, order = event.get_tag_and_order()
        orig_order, Pdir = self.id_to_path[tag]

        run_id = (tag, hypp_id)

        if run_id in self.calculator:
            external = self.calculator[run_id]
            self.calculator_nbcall[run_id] += 1
        else:
            # create the executable for this param_card            

            tmpdir = pjoin(self.me_dir,'rw_me', 'SubProcesses', Pdir)
            executable_prod="./check"
            if not os.path.exists(pjoin(tmpdir, 'check')):
                misc.compile( cwd=tmpdir)
            external = Popen(executable_prod, stdout=PIPE, stdin=PIPE, 
                                                      stderr=STDOUT, cwd=tmpdir)
            self.calculator[run_id] = external 
            self.calculator_nbcall[run_id] = 1       
            # set the param_card
            if hypp_id == 1:
                external.stdin.write('param_card.dat\n')
            elif hypp_id == 0:
                external.stdin.write('param_card_orig.dat\n')
        #import the value of alphas
        external.stdin.write('%g\n' % event.aqcd)
        stdin_text = event.get_momenta_str(orig_order)
        external.stdin.write(stdin_text)
        me_value = external.stdout.readline()
        try: 
            me_value = float(me_value)
        except Exception:
            print 'ZERO DETECTED'
            print stdin_text
            print me_value
            os.system('lsof -p %s' % external.pid)
            me_value = 0
        
        if len(self.calculator) > 100:
            logger.debug('more than 100 calculator. Perform cleaning')
            nb_calls = self.calculator_nbcall.values()
            nb_calls.sort()
            cut = max([nb_calls[len(nb_calls)//2], 0.001 * nb_calls[-1]])
            for key, external in list(self.calculator.items()):
                nb = self.calculator_nbcall[key]
                if nb < cut:
                    external.stdin.close()
                    external.stdout.close()
                    external.terminate()
                    del self.calculator[key]
                    del self.calculator_nbcall[key]
                else:
                    self.calculator_nbcall[key] = self.calculator_nbcall[key] //10
        
        return me_value
Esempio n. 6
0
 def launch_program(self):
     """launch the main program"""
     sub_path = os.path.join(self.running_dir, 'SubProcesses')
     for path in os.listdir(sub_path):
         if path.startswith('P') and \
                                os.path.isdir(os.path.join(sub_path, path)):
             cur_path = os.path.join(sub_path, path)
             # make
             misc.compile(cwd=cur_path, mode='unknown')
             # check
             subprocess.call(['./check'], cwd=cur_path)
Esempio n. 7
0
 def launch_program(self):
     """launch the main program"""
     sub_path = os.path.join(self.running_dir, 'SubProcesses')
     for path in os.listdir(sub_path):
         if path.startswith('P') and \
                                os.path.isdir(os.path.join(sub_path, path)):
             cur_path =  os.path.join(sub_path, path)
             # make
             misc.compile(cwd=cur_path, mode='unknown')
             # check
             subprocess.call(['./check'], cwd=cur_path)
Esempio n. 8
0
    def compile(self):
        """ Compile all contributions and the global ME7 resources (e.g. MODEL)"""

        # Compile the MODEL first
        if os.path.isdir(pjoin(self.export_dir, 'Source', 'MODEL')):
            logger.info("Compiling global ME7 Model")
            misc.compile(arg=['../../lib/libmodel.a'],
                         cwd=pjoin(self.export_dir, 'Source', 'MODEL'),
                         mode='fortran')

        # Compile all contributions
        self.contributions.apply_method_to_all_contribs('compile',
                                                        log='Compiling')
def setup_channel(channelPath):
    """ Compiles the Resummation fortran steering 
    code and returns the corresponding process."""

    logging.info('Setting up resummation runner in\n   %s'%channelPath)

    try:
        misc.compile(cwd=channelPath, mode='fortran', job_specs = False)
    except:
        logging.error("Could not compile resummation runner in %s/%s"%(channelPath))
        raise
    
    logging.info('  ... Done.')
    
    return subprocess.Popen([os.path.join(channelPath,'resum_driver')], 
          stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, 
                                                                   cwd=channelPath)
Esempio n. 10
0
def setup_channel(channelPath):
    """ Compiles the Resummation fortran steering 
    code and returns the corresponding process."""

    logging.info('Setting up resummation runner in\n   %s'%channelPath)

    try:
        misc.compile(cwd=channelPath, mode='fortran', job_specs = False)
    except:
        logging.error("Could not compile resummation runner in %s/%s"%(channelPath))
        raise
    
    logging.info('  ... Done.')
    
    return subprocess.Popen([os.path.join(channelPath,'resum_driver')], 
          stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, 
                                                                   cwd=channelPath)
Esempio n. 11
0
def setup_channel(channelPath):
    """ Copies and compile the MadLoop fortran steering 
    code and returns the corresponding process."""

    logging.info('Setting up virtual runner in\n   %s' % channelPath)

    # Use the presence of the file born_matrix.f to check if this output
    # is a loop_induced one or not.
    if os.path.isfile(os.path.join(channelPath, 'born_matrix.f')):
        checkerName = 'StabilityCheckDriver.f'
    else:
        checkerName = 'StabilityCheckDriver_loop_induced.f'
    # First create the stability check fortran driver executable if not
    # already present.
    if not os.path.isfile(pjoin(channelPath, 'StabilityCheckDriver.f')):
        with open(
                pjoin(MGRootPath, 'Template', 'loop_material', 'Checks',
                      'StabilityCheckDriver.f'), 'r') as checkerFile:
            with open(pjoin(channelPath, 'proc_prefix.txt')) as proc_prefix:
                checkerToWrite = checkerFile.read() % {
                    'proc_prefix': proc_prefix.read()
                }
        checkerFile = open(pjoin(channelPath, 'StabilityCheckDriver.f'), 'w')
        checkerFile.write(checkerToWrite)
        checkerFile.close()
        # Append the compilation of the StabilityCheckDriver to the makefile
        with open(pjoin(channelPath, 'makefile'), 'a') as makefile:
            makefile.write(
                "\nStabilityCheckDriver:  StabilityCheckDriver.o $(PROCESS)\n\t$(FC) $(FFLAGS) -o StabilityCheckDriver StabilityCheckDriver.o $(PROCESS) $(LINKLIBS) $(STDLIB)"
            )
    try:
        misc.compile(arg=['StabilityCheckDriver'], \
                     cwd=channelPath, mode='fortran', job_specs = False)
    except:
        logging.error("Could not compile %s/%s" %
                      (channelPath, StabilityCheckDriver))
        raise

    logging.info('  ... Done.')

    return subprocess.Popen(
        [os.path.join(channelPath, 'StabilityCheckDriver')],
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        cwd=channelPath)
Esempio n. 12
0
    def make_CutTools():
        print "Compiling CutTools in %s."%str(os.path.join(MG5DIR, 'vendor', 'CutTools'))
        # Set the correct fortran compiler
        if 'FC' not in os.environ or not os.environ['FC']:
            if misc.which('gfortran'):
                compiler = 'FC=gfortran'
            else:
                raise self.InvalidCmd('Require gfortran compiler')
        else:
            compiler = '#FC=gfortran'
        
        base_compiler= ['FC=gfortran','#FC=gfortran']            
        path = None            
        path = os.path.join(MG5DIR, 'vendor', 'CutTools', 'makefile')
        text = open(path).read()
        for base in base_compiler:
            text = text.replace(base,compiler)
        open(path, 'w').writelines(text)

        misc.compile(cwd = os.path.join(MG5DIR, 'vendor', 'CutTools'))
Esempio n. 13
0
    def make_CutTools():
        print("Compiling CutTools in %s."%str(os.path.join(MG5DIR, 'vendor', 'CutTools')))
        # Set the correct fortran compiler
        if 'FC' not in os.environ or not os.environ['FC']:
            if misc.which('gfortran'):
                compiler = 'FC=gfortran'
            else:
                raise self.InvalidCmd('Require gfortran compiler')
        else:
            compiler = '#FC=gfortran'
        
        base_compiler= ['FC=gfortran','#FC=gfortran']            
        path = None            
        path = os.path.join(MG5DIR, 'vendor', 'CutTools', 'makefile')
        text = open(path).read()
        for base in base_compiler:
            text = text.replace(base,compiler)
        open(path, 'w').writelines(text)

        misc.compile(cwd = os.path.join(MG5DIR, 'vendor', 'CutTools'))
Esempio n. 14
0
    def test_add_time_of_flight(self):
        """checking time of flight is working fine"""

        if logging.getLogger('madgraph').level <= 20:
            stdout=None
            stderr=None
        else:
            devnull =open(os.devnull,'w')
            stdout=devnull
            stderr=devnull
        if not os.path.exists(pjoin(MG5DIR, 'pythia-pgs')):
            p = subprocess.Popen([pjoin(MG5DIR,'bin','mg5')],
                             stdin=subprocess.PIPE,
                             stdout=stdout,stderr=stderr)
            out = p.communicate('install pythia-pgs')
        misc.compile(cwd=pjoin(MG5DIR,'pythia-pgs'))

        try:
            shutil.rmtree('/tmp/MGPROCESS/')
        except Exception, error:
            pass
Esempio n. 15
0
    def launch_program(self):
        """launch the main program"""

        # Make pythia8
        print "Running make for pythia8 directory"
        misc.compile(cwd=os.path.join(self.running_dir, os.path.pardir), mode='cpp')
        if self.model_dir:
            print "Running make in %s" % self.model_dir
            misc.compile(cwd=self.model_dir, mode='cpp')
        # Finally run make for executable
        makefile = self.executable.replace("main_","Makefile_")
        print "Running make with %s" % makefile
        misc.compile(arg=['-f', makefile], cwd=self.running_dir, mode='cpp')
        
        print "Running " + self.executable
        
        output = open(os.path.join(self.running_dir, self.name), 'w')
        if not self.executable.startswith('./'):
            self.executable = os.path.join(".", self.executable)
        subprocess.call([self.executable], stdout = output, stderr = output,
                        cwd=self.running_dir)
        
        # Display the cross-section to the screen
        path = os.path.join(self.running_dir, self.name) 
        pydoc.pager(open(path).read())

        print "Output of the run is found at " + \
              os.path.realpath(os.path.join(self.running_dir, self.name))
def setup_channel(channelPath):
    """ Copies and compile the MadLoop fortran steering 
    code and returns the corresponding process."""

    logging.info('Setting up virtual runner in\n   %s'%channelPath)

    # Use the presence of the file born_matrix.f to check if this output
    # is a loop_induced one or not.
    if os.path.isfile(os.path.join(channelPath,'born_matrix.f')):
        checkerName = 'StabilityCheckDriver.f'
    else:
        checkerName = 'StabilityCheckDriver_loop_induced.f'                
    # First create the stability check fortran driver executable if not 
    # already present.
    if not os.path.isfile(pjoin(channelPath,'StabilityCheckDriver.f')):
        with open(pjoin(MGRootPath,'Template','loop_material','Checks',
                        'StabilityCheckDriver.f'),'r') as checkerFile:
            with open(pjoin(channelPath,'proc_prefix.txt')) as proc_prefix:
                checkerToWrite = checkerFile.read()%{'proc_prefix':
                                                     proc_prefix.read()}
        checkerFile = open(pjoin(channelPath,'StabilityCheckDriver.f'),'w')
        checkerFile.write(checkerToWrite)
        checkerFile.close()                
    # Append the compilation of the StabilityCheckDriver to the makefile
        with open (pjoin(channelPath,'makefile'),'a') as makefile:
            makefile.write("\nStabilityCheckDriver:  StabilityCheckDriver.o $(PROCESS)\n\t$(FC) $(FFLAGS) -o StabilityCheckDriver StabilityCheckDriver.o $(PROCESS) $(LINKLIBS)")
    try:
        misc.compile(arg=['StabilityCheckDriver'], \
                     cwd=channelPath, mode='fortran', job_specs = False)
    except:
        logging.error("Could not compile %s/%s"%(channelPath,StabilityCheckDriver))
        raise
    
    logging.info('  ... Done.')
    
    return subprocess.Popen([os.path.join(channelPath,'StabilityCheckDriver')], 
          stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, 
                                                                   cwd=channelPath)
Esempio n. 17
0
    def test_w_production_with_ms_decay(self):
        """A run to test madspin (inline and offline) on p p > w+ and p p > w-"""

        cwd = os.getcwd()

        if logging.getLogger('madgraph').level <= 20:
            stdout = None
            stderr = None
        else:
            devnull = open(os.devnull, 'w')
            stdout = devnull
            stderr = devnull

        if not os.path.exists(pjoin(MG5DIR, 'pythia-pgs')):
            p = subprocess.Popen([pjoin(MG5DIR, 'bin', 'mg5')],
                                 stdin=subprocess.PIPE,
                                 stdout=stdout,
                                 stderr=stderr)
            out = p.communicate('install pythia-pgs')
        misc.compile(cwd=pjoin(MG5DIR, 'pythia-pgs'))
        if logging.getLogger('madgraph').level > 20:
            stdout = devnull
        else:
            stdout = None

        #
        #  START REAL CODE
        #
        command = open(pjoin(self.path, 'cmd'), 'w')
        command.write("""import model sm
        set automatic_html_opening False --no_save
        set notification_center False --no_save
        generate p p > w+ 
        add process p p > w-
        output %(path)s
        launch
        madspin=ON
        pythia=ON
        %(path)s/../madspin_card.dat
        set nevents 1000
        set pdlabel cteq6l1
        launch -i
        decay_events run_01 
        %(path)s/../madspin_card2.dat
        """ % {'path': self.run_dir})
        command.close()

        fsock = open(pjoin(self.path, 'madspin_card.dat'), 'w')
        fsock.write("""decay w+ > j j
        decay w- > e- ve~
        launch
        """)
        fsock.close()
        fsock = open(pjoin(self.path, 'madspin_card2.dat'), 'w')
        fsock.write("""decay w+ > j j
        decay w- > j j
        launch
        """)
        fsock.close()

        subprocess.call([
            pjoin(_file_path, os.path.pardir, 'bin', 'mg5'),
            pjoin(self.path, 'cmd')
        ],
                        cwd=pjoin(_file_path, os.path.pardir),
                        stdout=stdout,
                        stderr=stdout)

        #a=rwa_input('freeze')
        self.check_parton_output(cross=150770.0,
                                 error=7.4e+02,
                                 target_event=1000)
        self.check_parton_output('run_01_decayed_1',
                                 cross=66344.2066122,
                                 error=1.5e+03,
                                 target_event=666,
                                 delta_event=40)
        #logger.info('\nMS info: the number of events in the html file is not (always) correct after MS\n')
        self.check_parton_output('run_01_decayed_2',
                                 cross=100521.52517,
                                 error=8e+02,
                                 target_event=1000)
        self.check_pythia_output(run_name='run_01_decayed_1')

        #check the first decayed events for energy-momentum conservation.

        self.assertEqual(cwd, os.getcwd())
Esempio n. 18
0
class TestMECmdShell(unittest.TestCase):
    """this treats all the command not related to MG_ME"""
    def setUp(self):

        self.debugging = False
        if self.debugging:
            self.path = pjoin(MG5DIR, "tmp_test")
            if os.path.exists(self.path):
                shutil.rmtree(self.path)
            os.mkdir(pjoin(MG5DIR, "tmp_test"))
        else:
            self.path = tempfile.mkdtemp(prefix='acc_test_mg5')
        self.run_dir = pjoin(self.path, 'MGPROC')

    def tearDown(self):

        if self.path != pjoin(MG5DIR, "tmp_test"):
            shutil.rmtree(self.path)

    def generate(self, process, model):
        """Create a process"""

        try:
            shutil.rmtree(self.run_dir)
        except Exception, error:
            pass
        interface = MGCmd.MasterCmd()
        interface.no_notification()
        interface.run_cmd('import model %s' % model)
        if isinstance(process, str):
            interface.run_cmd('generate %s' % process)
        else:
            for p in process:
                interface.run_cmd('add process %s' % p)

        if logging.getLogger('madgraph').level <= 20:
            stdout = None
            stderr = None
        else:
            devnull = open(os.devnull, 'w')
            stdout = devnull
            stderr = devnull

        if not os.path.exists(pjoin(MG5DIR, 'pythia-pgs')):
            print "install pythia-pgs"
            p = subprocess.Popen([pjoin(MG5DIR, 'bin', 'mg5')],
                                 stdin=subprocess.PIPE,
                                 stdout=stdout,
                                 stderr=stderr)
            out = p.communicate('install pythia-pgs')
        misc.compile(cwd=pjoin(MG5DIR, 'pythia-pgs'))
        if not os.path.exists(pjoin(MG5DIR, 'MadAnalysis')):
            print "install MadAnalysis"
            p = subprocess.Popen([pjoin(MG5DIR, 'bin', 'mg5')],
                                 stdin=subprocess.PIPE,
                                 stdout=stdout,
                                 stderr=stderr)
            out = p.communicate('install MadAnalysis4')
        misc.compile(cwd=pjoin(MG5DIR, 'MadAnalysis'))

        if not misc.which('root'):
            raise Exception, 'root is require for this test'
        interface.exec_cmd('set pythia-pgs_path %s --no_save' %
                           pjoin(MG5DIR, 'pythia-pgs'))
        interface.exec_cmd('set madanalysis_path %s --no_save' %
                           pjoin(MG5DIR, 'MadAnalysis'))
        interface.onecmd('output madevent %s -f' % self.run_dir)

        if os.path.exists(pjoin(interface.options['syscalc_path'],
                                'sys_calc')):
            shutil.rmtree(interface.options['syscalc_path'])
            #print "install SysCalc"
            #interface.onecmd('install SysCalc')

        self.cmd_line = MECmd.MadEventCmdShell(me_dir=self.run_dir)
        self.cmd_line.no_notification()
        self.cmd_line.options['syscalc_path'] = pjoin(MG5DIR, 'SysCalc')
Esempio n. 19
0
        import subprocess
        if logging.getLogger('madgraph').level <= 20:
            stdout = None
            stderr = None
        else:
            devnull = open(os.devnull, 'w')
            stdout = devnull
            stderr = devnull

        if not os.path.exists(pjoin(MG5DIR, 'pythia-pgs')):
            p = subprocess.Popen([pjoin(MG5DIR, 'bin', 'mg5')],
                                 stdin=subprocess.PIPE,
                                 stdout=stdout,
                                 stderr=stderr)
            out = p.communicate('install pythia-pgs')
        misc.compile(cwd=pjoin(MG5DIR, 'pythia-pgs'))
        if logging.getLogger('madgraph').level > 20:
            stdout = devnull
        else:
            stdout = None

        fsock = open(pjoin(self.path, 'test_mssm_generation'), 'w')
        fsock.write(
            open(pjoin(_file_path, 'input_files',
                       'test_mssm_generation')).read() % {
                           'dir_name': self.run_dir,
                           'mg5_path': pjoin(_file_path, os.path.pardir)
                       })
        fsock.close()

        subprocess.call(
Esempio n. 20
0
        """ """
        cwd = os.getcwd()
        try:
            shutil.rmtree('/tmp/MGPROCESS/')
        except Exception, error:
            pass
        import subprocess
        
        devnull =open(os.devnull,'w')
        pythia_path =  pjoin(_file_path, os.path.pardir, 'pythia-pgs')
        if not os.path.exists(pythia_path):
            p = subprocess.Popen([pjoin(_file_path, os.path.pardir,'bin','mg5')],
                             stdin=subprocess.PIPE,
                             stdout=devnull,stderr=devnull)
            out = p.communicate('install pythia-pgs')
        misc.compile(cwd=pythia_path)
        
        if logging.getLogger('madgraph').level > 20:
            stdout = devnull
        else:
            stdout= None


        subprocess.call([pjoin(_file_path, os.path.pardir,'bin','mg5'), 
                         pjoin(_file_path, 'input_files','test_mssm_generation')],
                         cwd=pjoin(_file_path, os.path.pardir),
                        stdout=stdout,stderr=stdout)

        
        self.check_parton_output(cross=4.541638, error=0.035)
        self.check_parton_output('run_02', cross=4.541638, error=0.035)
    def test_nlo_reweighting(self):
        """check that nlo reweighting is working.
           The main point is to check the recombination of the weights
           Since the rest should be either checked by the lhe_parser classs
           or by the various check of the standalone checks
        """
        
        # create a reweight directory   
        interface = MGCmd.MasterCmd()  
        interface.exec_cmd("import model loop_sm", errorhandling=False)
        interface.exec_cmd("set group_subprocesses False")
        interface.exec_cmd("generate u d~ > e+ ve [virt=QCD]", precmd=True, errorhandling=False)
        interface.exec_cmd('output standalone_rw %s/rw_mevirt -f' % self.path)
        # update the makefile:
        # update make_opts
        m_opts = {}
        if interface.options['lhapdf']:
            #lhapdfversion = subprocess.Popen([mgcmd.options['lhapdf'], '--version'], 
            #        stdout = subprocess.PIPE).stdout.read().strip()[0]
            m_opts['lhapdf'] = True
            m_opts['lhapdfversion'] = 5 # 6 always fail on my computer since 5 is compatible but slower always use 5
            m_opts['llhapdf'] = subprocess.Popen([interface.options['lhapdf'], '--libs'], 
                    stdout = subprocess.PIPE).stdout.read().strip().split()[0]
            m_opts['f2pymode'] = True
        else:
            raise Exception, "need LHAPDF"
            lhapdf = False
            lhapdfversion = 0

        path = pjoin(self.path,'rw_mevirt', 'Source', 'make_opts')
        
        commonCmd.CommonRunCmd.update_make_opts_full(path, m_opts)
    
    
        # Now compile the Source directory
        misc.compile(cwd=pjoin(self.path, 'rw_mevirt', 'Source'))
        #link it 
        with misc.chdir(pjoin(self.path)):
            if self.path not in sys.path:
                sys.path.insert(0, self.path)
            mymod = __import__('rw_mevirt.Source.rwgt2py', globals(), locals(), [],-1)
            mymod =  mymod.Source.rwgt2py
            #mymod.initialise([1,1], 244600)
       
            scales2 =  [[1283.6655, 1283.6655], [1283.6655, 1283.6655], [1283.6655, 1283.6655]] 
            pdg =  [[21, 21], [2, 2]] 
            bjx =  [[0.00036333765, 0.00036942677], [0.5007504, 0.51807252]] 
            wgt =  [[-1.0551457726, 0.890469566701], [0.0, 0.0], [0.0, 0.0]] 
            gs =  [1.3206738, 1.3206738] 
            qcdpower =  [2, 2] 
            orig_wgt =  -0.28722482722716736 
            ref_wgts =  [-1.8403634002861815, 1.5531385730590141] 
       

        #value = mymod.test_pdf() 
        #self.assertAlmostEqual(value, 1.0)
            
        out, partial = mymod.get_wgt(scales2, pdg, bjx, wgt, gs, qcdpower, 1., 1.)  
        #print ref_wgts, partial, [partial[i]/ref_wgts[i] for i in range(2)]
        #print out, orig_wgt, out/orig_wgt
        self.assertAlmostEqual(partial[0], ref_wgts[0], places=2)
        self.assertAlmostEqual(partial[1], ref_wgts[1], places=2)
        self.assertAlmostEqual(out, orig_wgt, places=2)
Esempio n. 22
0
    def do_compile(self, line, refine=False):
        """MadWeight Function:compile the code"""
        self.configure()

        misc.compile(arg=["../lib/libtools.a"],
                     cwd=pjoin(self.me_dir, 'Source'))
        misc.compile(arg=["../lib/libblocks.a"],
                     cwd=pjoin(self.me_dir, 'Source'))
        misc.compile(arg=["../lib/libTF.a"], cwd=pjoin(self.me_dir, 'Source'))
        misc.compile(arg=["../lib/libpdf.a"], cwd=pjoin(self.me_dir, 'Source'))
        misc.compile(arg=["../lib/libdhelas.a"],
                     cwd=pjoin(self.me_dir, 'Source'))
        misc.compile(arg=["../lib/libmodel.a"],
                     cwd=pjoin(self.me_dir, 'Source'))
        misc.compile(arg=["../lib/libgeneric.a"],
                     cwd=pjoin(self.me_dir, 'Source'))
        misc.compile(arg=["../lib/libcernlib.a"],
                     cwd=pjoin(self.me_dir, 'Source'))

        #
        #       here check validity of some parameters
        if self.MWparam['mw_run']['integrator'] == 'm' and self.MWparam[
                'mw_run']['montecarlo_perm'] == 't':
            raise Exception, 'Cannot use mint if monte carlo over permutations'
        if self.MWparam['mw_run']['integrator'] == 'm' and self.MWparam[
                'mw_run']['use_sobol'] == 't':
            raise Exception, 'sobol generator with mint not implemented'

        for MW_dir in self.MWparam.MW_listdir:
            logger.info('compile %s' % MW_dir)
            pdir = pjoin(self.me_dir, 'SubProcesses', MW_dir)
            if refine and os.path.exists(pjoin(pdir, 'initialization.o')):
                os.remove(pjoin(pdir, 'initialization.o'))
            if refine and os.path.exists(pjoin(pdir, 'comp_madweight')):
                os.remove(pjoin(pdir, 'comp_madweight'))
            misc.compile(cwd=pdir)
            if not os.path.exists(pjoin(pdir, 'comp_madweight')):
                raise Exception, 'compilation fails'
        logger.info('MadWeight code has been compiled.')
Esempio n. 23
0
            pass
        import subprocess
        if logging.getLogger('madgraph').level <= 20:
            stdout=None
            stderr=None
        else:
            devnull =open(os.devnull,'w')
            stdout=devnull
            stderr=devnull

        if not os.path.exists(pjoin(MG5DIR, 'pythia-pgs')):
            p = subprocess.Popen([pjoin(MG5DIR,'bin','mg5')],
                             stdin=subprocess.PIPE,
                             stdout=stdout,stderr=stderr)
            out = p.communicate('install pythia-pgs')
        misc.compile(cwd=pjoin(MG5DIR,'pythia-pgs'))
        if logging.getLogger('madgraph').level > 20:
            stdout = devnull
        else:
            stdout= None

        fsock = open(pjoin(self.path, 'test_mssm_generation'),'w')
        fsock.write(open(pjoin(_file_path, 'input_files','test_mssm_generation')).read() %
                    {'dir_name': self.run_dir, 'mg5_path':pjoin(_file_path, os.path.pardir)})
        fsock.close()

        subprocess.call([pjoin(_file_path, os.path.pardir,'bin','mg5'), 
                         pjoin(self.path, 'test_mssm_generation')],
                         #cwd=pjoin(self.path),
                        stdout=stdout,stderr=stdout)
        
Esempio n. 24
0
    def make_IREGI():
        print "Compiling IREGI in %s." % str(
            os.path.join(MG5DIR, 'vendor', 'IREGI', 'src'))
        # Set the correct fortran compiler
        if 'FC' not in os.environ or not os.environ['FC']:
            if misc.which('gfortran'):
                compiler = 'FC=gfortran'
            else:
                raise self.InvalidCmd('Require gfortran compiler')
        else:
            compiler = '#FC=gfortran'

        iregi_path = os.path.join(MG5DIR, 'vendor', 'IREGI')
        # replace the current compiler to be gfortran
        if compiler == 'FC=gfortran':
            # in case there is #FC -> FC
            #search file in src
            file_to_change = misc.find_makefile_in_dir(
                os.path.join(iregi_path, 'src'))
            comp_re = re.compile('^(\s*)#FC\s*=\s*(.+)\s*$')
            var = 'FC'
            mod = False
            for name in file_to_change:
                lines = open(name, 'r').read().split('\n')
                for iline, line in enumerate(lines):
                    result = comp_re.match(line)
                    if result:
                        mod = True
                        lines[iline] = result.group(
                            1) + var + "=" + result.group(2)
                if mod:
                    open(name, 'w').write('\n'.join(lines))
                    mod = False
            # search file in src/oneloop
            file_to_change = misc.find_makefile_in_dir(
                os.path.join(iregi_path, 'src', 'oneloop'))
            mod = False
            for name in file_to_change:
                lines = open(name, 'r').read().split('\n')
                for iline, line in enumerate(lines):
                    result = comp_re.match(line)
                    if result:
                        mod = True
                        lines[iline] = result.group(
                            1) + var + "=" + result.group(2)
                if mod:
                    open(name, 'w').write('\n'.join(lines))
                    mod = False
            # change FC = current  to FC = new
            current = misc.detect_current_compiler(
                os.path.join(iregi_path, 'src', 'makefile_ML5_lib'))
            new = 'gfortran'
            if current != new:
                misc.mod_compilator(os.path.join(iregi_path, 'src'), new,
                                    current)
                misc.mod_compilator(os.path.join(iregi_path, 'src', 'oneloop'),
                                    new, current)
        else:
            #search file in src
            file_to_change = misc.find_makefile_in_dir(
                os.path.join(iregi_path, 'src'))
            comp_re = re.compile('^(\s*)FC\s*=\s*(.+)\s*$')
            var = 'FC'
            mod = False
            for name in file_to_change:
                lines = open(name, 'r').read().split('\n')
                for iline, line in enumerate(lines):
                    result = comp_re.match(line)
                    if result:
                        mod = True
                        lines[iline] = '#' + result.group(
                            1) + var + "=" + result.group(2)
                if mod:
                    open(name, 'w').write('\n'.join(lines))
                    mod = False
            # search file in src/oneloop
            file_to_change = misc.find_makefile_in_dir(
                os.path.join(iregi_path, 'src', 'oneloop'))
            mod = False
            for name in file_to_change:
                lines = open(name, 'r').read().split('\n')
                for iline, line in enumerate(lines):
                    result = comp_re.match(line)
                    if result:
                        mod = True
                        lines[iline] = '#' + result.group(
                            1) + var + "=" + result.group(2)
                if mod:
                    open(name, 'w').write('\n'.join(lines))
                    mod = False

        misc.compile(cwd=os.path.join(iregi_path, 'src'))
Esempio n. 25
0
    def test_generation_from_file_1(self):
        """ """
        cwd = os.getcwd()
        try:
            shutil.rmtree('/tmp/MGPROCESS/')
        except Exception as error:
            pass
        import subprocess
        if logging.getLogger('madgraph').level <= 20:
            stdout = None
            stderr = None
        else:
            devnull = open(os.devnull, 'w')
            stdout = devnull
            stderr = devnull

        if not os.path.exists(pjoin(MG5DIR, 'pythia-pgs')):
            p = subprocess.Popen([pjoin(MG5DIR, 'bin', 'mg5')],
                                 stdin=subprocess.PIPE,
                                 stdout=stdout,
                                 stderr=stderr)
            out = p.communicate('install pythia-pgs'.encode())
        misc.compile(cwd=pjoin(MG5DIR, 'pythia-pgs'))
        if logging.getLogger('madgraph').level > 20:
            stdout = devnull
        else:
            stdout = None

        fsock = open(pjoin(self.path, 'test_mssm_generation'), 'w')
        fsock.write(
            open(pjoin(_file_path, 'input_files',
                       'test_mssm_generation')).read() % {
                           'dir_name': self.run_dir,
                           'mg5_path': pjoin(_file_path, os.path.pardir)
                       })
        fsock.close()

        subprocess.call(
            [
                pjoin(_file_path, os.path.pardir, 'bin', 'mg5'),
                pjoin(self.path, 'test_mssm_generation')
            ],
            #cwd=pjoin(self.path),
            stdout=stdout,
            stderr=stdout)

        self.check_parton_output(cross=4.541638, error=0.035)

        self.check_parton_output('run_02', cross=4.41887317, error=0.035)
        self.check_pythia_output()
        self.assertEqual(cwd, os.getcwd())
        #

        # Additional test: Check that the banner of the run_02 include correctly
        # the ptheavy 50 information
        banner = banner_mod.Banner(
            pjoin(self.run_dir, 'Events', 'run_01', 'run_01_fermi_banner.txt'))
        run_card = banner.charge_card('run_card')
        self.assertEqual(run_card['ptheavy'], 0)

        banner = banner_mod.Banner(
            pjoin(self.run_dir, 'Events', 'run_02', 'run_02_fermi_banner.txt'))
        run_card = banner.charge_card('run_card')
        self.assertEqual(run_card['ptheavy'], 50)

        events = lhe_parser.EventFile(
            pjoin(self.run_dir, 'Events', 'run_02',
                  'unweighted_events.lhe.gz'))
        banner = banner_mod.Banner(events.banner)
        run_card = banner.charge_card('run_card')
        self.assertEqual(run_card['ptheavy'], 50)
        for event in events:
            event.check()
Esempio n. 26
0
    def test_w_production_with_ms_decay(self):
        """A run to test madspin (inline and offline) on p p > w+ and p p > w-"""
        
        cwd = os.getcwd()
        
        if logging.getLogger('madgraph').level <= 20:
            stdout=None
            stderr=None
        else:
            devnull =open(os.devnull,'w')
            stdout=devnull
            stderr=devnull

        if not os.path.exists(pjoin(MG5DIR, 'pythia-pgs')):
            p = subprocess.Popen([pjoin(MG5DIR,'bin','mg5')],
                             stdin=subprocess.PIPE,
                             stdout=stdout,stderr=stderr)
            out = p.communicate('install pythia-pgs')
        misc.compile(cwd=pjoin(MG5DIR,'pythia-pgs'))
        if logging.getLogger('madgraph').level > 20:
            stdout = devnull
        else:
            stdout= None
            
        #
        #  START REAL CODE
        #
        command = open(pjoin(self.path, 'cmd'), 'w')
        command.write("""import model sm
        set automatic_html_opening False --no_save
        set notification_center False --no_save
        generate p p > w+ 
        add process p p > w-
        output %(path)s
        launch
        madspin=ON
        pythia=ON
        %(path)s/../madspin_card.dat
        set nevents 1000
        set pdlabel cteq6l1
        launch -i
        decay_events run_01 
        %(path)s/../madspin_card2.dat
        """ % {'path':self.run_dir})
        command.close()
        
        fsock = open(pjoin(self.path, 'madspin_card.dat'), 'w')
        fsock.write("""decay w+ > j j
        decay w- > e- ve~
        launch
        """)
        fsock.close()
        fsock = open(pjoin(self.path, 'madspin_card2.dat'), 'w')
        fsock.write("""decay w+ > j j
        decay w- > j j
        launch
        """)
        fsock.close()
                
        subprocess.call([pjoin(_file_path, os.path.pardir,'bin','mg5'), 
                         pjoin(self.path, 'cmd')],
                         cwd=pjoin(_file_path, os.path.pardir),
                        stdout=stdout,stderr=stdout)     
        
        #a=rwa_input('freeze')
        self.check_parton_output(cross=150770.0, error=7.4e+02,target_event=1000)
        self.check_parton_output('run_01_decayed_1', cross=66344.2066122, error=1.5e+03,target_event=1000)
        #logger.info('\nMS info: the number of events in the html file is not (always) correct after MS\n')
        self.check_parton_output('run_01_decayed_2', cross=100521.52517, error=8e+02,target_event=1000)
        self.check_pythia_output(run_name='run_01_decayed_1')
        
        #check the first decayed events for energy-momentum conservation.
        
        
        self.assertEqual(cwd, os.getcwd())
Esempio n. 27
0
    def test_add_time_of_flight(self):
        """checking time of flight is working fine"""

        if logging.getLogger('madgraph').level <= 20:
            stdout = None
            stderr = None
        else:
            devnull = open(os.devnull, 'w')
            stdout = devnull
            stderr = devnull
        if not os.path.exists(pjoin(MG5DIR, 'pythia-pgs')):
            p = subprocess.Popen([pjoin(MG5DIR, 'bin', 'mg5')],
                                 stdin=subprocess.PIPE,
                                 stdout=stdout,
                                 stderr=stderr)
            out = p.communicate('install pythia-pgs'.encode())
        misc.compile(cwd=pjoin(MG5DIR, 'pythia-pgs'))

        try:
            shutil.rmtree('/tmp/MGPROCESS/')
        except Exception as error:
            pass

        cmd = """import model sm
                 set automatic_html_opening False --no_save
                 set notification_center False --no_save
                 generate p p > w+ z
                 output %s -f -nojpeg
                 launch -i 
                 set automatic_html_opening False --no_save
                 generate_events
                 parton
                 set nevents 100
                 set event_norm sum
                 set systematics_program none
                 add_time_of_flight --threshold=4e-14
                 pythia
                 """ % self.run_dir
        open(pjoin(self.path, 'mg5_cmd'), 'w').write(cmd)

        if logging.getLogger('madgraph').level <= 20:
            stdout = None
            stderr = None
        else:
            devnull = open(os.devnull, 'w')
            stdout = devnull
            stderr = devnull
        subprocess.call(
            [
                pjoin(_file_path, os.path.pardir, 'bin', 'mg5'),
                pjoin(self.path, 'mg5_cmd')
            ],
            #cwd=self.path,
            stdout=stdout,
            stderr=stderr)

        self.check_parton_output(cross=15.62, error=0.19)
        self.check_pythia_output()
        event = '%s/Events/run_01/unweighted_events.lhe' % self.run_dir
        if not os.path.exists(event):
            misc.gunzip(event)

        has_zero = False
        has_non_zero = False
        for event in lhe_parser.EventFile(event):
            for particle in event:
                if particle.pid in [23, 25]:
                    self.assertTrue(particle.vtim == 0
                                    or particle.vtim > 4e-14)
                    if particle.vtim == 0:
                        has_zero = True
                    else:
                        has_non_zero = True
        self.assertTrue(has_zero)
        self.assertTrue(has_non_zero)

        self.assertFalse(self.debuging)
Esempio n. 28
0
    def do_compile(self, line, refine=False):
        """MadWeight Function:compile the code"""
        self.configure()
        
        misc.compile(arg=["../lib/libtools.a"], cwd=pjoin(self.me_dir,'Source')) 
        misc.compile(arg=["../lib/libblocks.a"], cwd=pjoin(self.me_dir,'Source')) 
        misc.compile(arg=["../lib/libTF.a"], cwd=pjoin(self.me_dir,'Source')) 
        misc.compile(arg=["../lib/libpdf.a"], cwd=pjoin(self.me_dir,'Source')) 
        misc.compile(arg=["../lib/libdhelas.a"], cwd=pjoin(self.me_dir,'Source')) 
        misc.compile(arg=["../lib/libmodel.a"], cwd=pjoin(self.me_dir,'Source')) 
        misc.compile(arg=["../lib/libgeneric.a"], cwd=pjoin(self.me_dir,'Source')) 
        misc.compile(arg=["../lib/libcernlib.a"], cwd=pjoin(self.me_dir,'Source')) 

#
#       here check validity of some parameters
        if self.MWparam['mw_run']['integrator']=='m' and  self.MWparam['mw_run']['montecarlo_perm']=='t':
           raise Exception, 'Cannot use mint if monte carlo over permutations'
        if self.MWparam['mw_run']['integrator']=='m' and  self.MWparam['mw_run']['use_sobol']=='t':
           raise Exception, 'sobol generator with mint not implemented'
 

        
        for MW_dir in self.MWparam.MW_listdir:
            logger.info('compile %s' %MW_dir)
            pdir = pjoin(self.me_dir,'SubProcesses',MW_dir)
            if refine and os.path.exists(pjoin(pdir, 'initialization.o')):
                os.remove(pjoin(pdir, 'initialization.o'))
            if refine and  os.path.exists(pjoin(pdir, 'comp_madweight')):
                os.remove(pjoin(pdir, 'comp_madweight'))
            misc.compile(cwd=pdir)
            if not os.path.exists(pjoin(pdir, 'comp_madweight')):
                raise Exception, 'compilation fails'
        logger.info('MadWeight code has been compiled.')
Esempio n. 29
0
    def make_IREGI():
        print "Compiling IREGI in %s."%str(os.path.join(MG5DIR, 'vendor', 'IREGI','src'))
        # Set the correct fortran compiler
        if 'FC' not in os.environ or not os.environ['FC']:
            if misc.which('gfortran'):
                compiler = 'FC=gfortran'
            else:
                raise self.InvalidCmd('Require gfortran compiler')
        else:
            compiler = '#FC=gfortran'

        iregi_path = os.path.join(MG5DIR, 'vendor', 'IREGI')
        # replace the current compiler to be gfortran
        if compiler == 'FC=gfortran':
            # in case there is #FC -> FC 
            #search file in src
            file_to_change=misc.find_makefile_in_dir(os.path.join(iregi_path,'src'))
            comp_re = re.compile('^(\s*)#FC\s*=\s*(.+)\s*$')
            var = 'FC'
            mod = False
            for name in file_to_change:
                lines = open(name,'r').read().split('\n')
                for iline, line in enumerate(lines):
                    result = comp_re.match(line)
                    if result:
                        mod = True
                        lines[iline] = result.group(1) + var + "=" + result.group(2)
                if mod:
                    open(name,'w').write('\n'.join(lines))
                    mod = False
            # search file in src/oneloop
            file_to_change=misc.find_makefile_in_dir(os.path.join(iregi_path,'src','oneloop'))
            mod = False
            for name in file_to_change:
                lines = open(name,'r').read().split('\n')
                for iline, line in enumerate(lines):
                    result = comp_re.match(line)
                    if result:
                        mod = True
                        lines[iline] = result.group(1) + var + "=" + result.group(2)
                if mod:
                    open(name,'w').write('\n'.join(lines))
                    mod = False
            # change FC = current  to FC = new
            current = misc.detect_current_compiler(
                os.path.join(iregi_path,'src','makefile_ML5_lib'))
            new = 'gfortran'
            if current != new:
                misc.mod_compilator(os.path.join(iregi_path,'src'), new,current)
                misc.mod_compilator(os.path.join(iregi_path,'src','oneloop'),
                                    new, current)
        else:
            #search file in src
            file_to_change=misc.find_makefile_in_dir(os.path.join(iregi_path,'src'))
            comp_re = re.compile('^(\s*)FC\s*=\s*(.+)\s*$')
            var = 'FC'
            mod = False
            for name in file_to_change:
                lines = open(name,'r').read().split('\n')
                for iline, line in enumerate(lines):
                    result = comp_re.match(line)
                    if result:
                        mod = True
                        lines[iline] = '#'+result.group(1) + var + "=" + result.group(2)
                if mod:
                    open(name,'w').write('\n'.join(lines))
                    mod = False
            # search file in src/oneloop
            file_to_change=misc.find_makefile_in_dir(os.path.join(iregi_path,'src','oneloop'))
            mod = False
            for name in file_to_change:
                lines = open(name,'r').read().split('\n')
                for iline, line in enumerate(lines):
                    result = comp_re.match(line)
                    if result:
                        mod = True
                        lines[iline] = '#'+result.group(1) + var + "=" + result.group(2)
                if mod:
                    open(name,'w').write('\n'.join(lines))
                    mod = False

        misc.compile(cwd = os.path.join(iregi_path,'src'))