コード例 #1
0
    def do_set(self, line):
        """ add one of the options """

        args = self.split_arg(line)
        self.check_set(args)

        if args[0] not in ['ms_dir', 'run_card']:
            args[1] = args[1].lower()

        if args[0] in ['max_weight', 'BW_effect', 'ms_dir', 'spinmode']:
            self.options[args[0]] = args[1]
            if args[0] == 'ms_dir':
                self.options['curr_dir'] = self.options['ms_dir']
        elif args[0] == 'seed':
            random.seed(int(args[1]))
            self.seed = int(args[1])
        elif args[0] == 'BW_cut':
            self.options[args[0]] = float(args[1])
        elif args[0] in ['onlyhelicity', 'use_old_dir']:
            self.options[args[0]] = banner.ConfigFile.format_variable(
                args[1], bool, args[0])
        elif args[0] in ['run_card']:
            if args[1] == 'default':
                self.options['run_card'] = None
            elif os.path.isfile(args[1]):
                self.options['run_card'] = banner.RunCard(args[1])
            elif len(args) > 2:
                if not self.options['run_card']:
                    self.options['run_card'] = banner.RunCardLO()
                    self.options['run_card'].remove_all_cut()
                self.options['run_card'][args[1]] = args[2]

        else:
            self.options[args[0]] = int(args[1])
コード例 #2
0
ファイル: test_cmd_madevent.py プロジェクト: mfasDa/MadGraph5
    def test_e_e_collision(self):
        """check that e+ e- > t t~ gives the correct result"""

        mg_cmd = MGCmd.MasterCmd()
        mg_cmd.no_notification()
        mg_cmd.exec_cmd('set automatic_html_opening False --save')
        mg_cmd.exec_cmd(' generate e+ e-  > e+ e-')
        mg_cmd.exec_cmd('output %s/' % self.run_dir)
        self.cmd_line = MECmd.MadEventCmdShell(me_dir=self.run_dir)
        self.cmd_line.no_notification()

        # couple of test checking that default run_card is as expected
        run_card = banner.RunCardLO(
            pjoin(self.run_dir, 'Cards', 'run_card.dat'))
        self.assertFalse('ptj' in run_card.user_set)
        self.assertFalse('drjj' in run_card.user_set)
        self.assertFalse('ptj2min' in run_card.user_set)
        self.assertFalse('ptj3min' in run_card.user_set)
        self.assertFalse('mmjj' in run_card.user_set)
        self.assertFalse('ptheavy' in run_card.user_set)
        self.assertTrue('el' in run_card.user_set)
        self.assertTrue('polbeam1' in run_card.user_set)
        self.assertTrue('ptl' in run_card.user_set)

        shutil.copy(os.path.join(_file_path, 'input_files', 'run_card_ee.dat'),
                    '%s/Cards/run_card.dat' % self.run_dir)

        self.do('generate_events -f')
        val1 = self.cmd_line.results.current['cross']
        err1 = self.cmd_line.results.current['error']

        target = 155.9
        self.assertTrue(abs(val1 - target) / err1 < 2.)
コード例 #3
0
    def setUp(self):
        """ """
    
        if os.path.exists('/tmp/edit_card'):
            os.system('rm -rf /tmp/edit_card')
        os.system('mkdir /tmp/edit_card;mkdir /tmp/edit_card/Cards;')
        template_path = pjoin(root_path, '..', 'Template')
        card= 'param_card'
        files.cp(pjoin(root_path, 'input_files/restrict_sm.dat'), '/tmp/edit_card/Cards/%s.dat' % card)
        files.cp(pjoin(root_path, 'input_files/restrict_sm.dat'), '/tmp/edit_card/Cards/%s_default.dat' % card)
                
        card = 'run_card'
        import madgraph.various.banner as banner_mod
        card = banner_mod.RunCardLO()
        card.write('/tmp/edit_card/Cards/run_card.dat')
        card.write('/tmp/edit_card/Cards/run_card_default.dat')


        card = 'MadWeight_card'
        files.cp(pjoin(template_path, 'MadWeight/Cards/%s.dat' % card), '/tmp/edit_card/Cards')
        files.cp(pjoin(template_path, 'MadWeight/Cards/%s.dat' % card), '/tmp/edit_card/Cards/%s_default.dat' % card)
        card = 'shower_card'
        files.cp(pjoin(template_path, 'NLO/Cards/%s.dat' % card), '/tmp/edit_card/Cards')
        files.cp(pjoin(template_path, 'NLO/Cards/%s.dat' % card), '/tmp/edit_card/Cards/%s_default.dat' % card)
        
        #MadLoop Card
        files.cp(pjoin(template_path, 'loop_material/StandAlone/Cards/MadLoopParams.dat'), '/tmp/edit_card/Cards')
        
        fakemother = FakeInterface('/tmp/edit_card/')
        self.cmd = runcmd.AskforEditCard('', cards=['run_card.dat', 'param_card.dat', 'madweight_card.dat', 'shower_card.dat'],
                                        mode='auto', mother_interface=fakemother)
コード例 #4
0
ファイル: test_cmd_madevent.py プロジェクト: mfasDa/MadGraph5
    def test_madspin_gridpack(self):

        self.out_dir = self.run_dir
        self.generate('g g > t t~', 'sm')

        #put the MadSpin card
        ff = open(pjoin(self.out_dir, 'Cards/madspin_card.dat'), 'w')
        orig_card = open(pjoin(self.out_dir,
                               'Cards/madspin_card_default.dat')).read()
        ff.write('set ms_dir %s' % pjoin(self.out_dir, 'MSDIR1'))
        ff.write(orig_card)
        ff.close()

        run_card = banner.RunCardLO(
            pjoin(self.run_dir, 'Cards', 'run_card.dat'))
        self.assertFalse('ptj' in run_card.user_set)
        self.assertFalse('drjj' in run_card.user_set)
        self.assertFalse('ptj2min' in run_card.user_set)
        self.assertFalse('ptj3min' in run_card.user_set)
        self.assertFalse('mmjj' in run_card.user_set)
        self.assertTrue('ptheavy' in run_card.user_set)
        self.assertFalse('el' in run_card.user_set)
        self.assertFalse('ej' in run_card.user_set)
        self.assertFalse('polbeam1' in run_card.user_set)
        self.assertFalse('ptl' in run_card.user_set)

        #reduce the number of events
        files.cp(pjoin(_file_path, 'input_files', 'run_card_matching.dat'),
                 pjoin(self.out_dir, 'Cards/run_card.dat'))

        #create the gridpack
        self.do('launch -f')
        self.check_parton_output('run_01', 100)
        self.check_parton_output('run_01_decayed_1', 100)
        #move the MS gridpack
        self.assertTrue(os.path.exists(pjoin(self.out_dir, 'MSDIR1')))
        files.mv(pjoin(self.out_dir, 'MSDIR1'), pjoin(self.out_dir, 'MSDIR2'))

        #put the MadSpin card
        ff = open(pjoin(self.out_dir, 'Cards/madspin_card.dat'), 'w')
        ff.write('set ms_dir %s' % pjoin(self.out_dir, 'MSDIR2'))
        ff.write(orig_card)
        ff.close()

        #create the gridpack
        self.do('launch -f')

        self.check_parton_output('run_02_decayed_1', 100)

        self.assertEqual(self.debugging, False)
コード例 #5
0
ファイル: test_cmd_madevent.py プロジェクト: mfasDa/MadGraph5
    def test_e_p_collision(self):
        """check that e p > e j gives the correct result"""

        mg_cmd = MGCmd.MasterCmd()
        mg_cmd.no_notification()
        mg_cmd.exec_cmd('set automatic_html_opening False --save')
        mg_cmd.exec_cmd(' generate e- p  > e- j')
        mg_cmd.exec_cmd('output %s/' % self.run_dir)
        self.cmd_line = MECmd.MadEventCmdShell(me_dir=self.run_dir)
        self.cmd_line.no_notification()
        self.cmd_line.exec_cmd('set automatic_html_opening False')

        #check validity of the default run_card
        run_card = banner.RunCardLO(
            pjoin(self.run_dir, 'Cards', 'run_card.dat'))
        self.assertTrue('ptj' in run_card.user_set)
        self.assertFalse('drjj' in run_card.user_set)
        self.assertFalse('ptj2min' in run_card.user_set)
        self.assertFalse('ptj3min' in run_card.user_set)
        self.assertFalse('mmjj' in run_card.user_set)
        self.assertFalse('ptheavy' in run_card.user_set)
        self.assertFalse('el' in run_card.user_set)
        self.assertFalse('ej' in run_card.user_set)
        self.assertTrue('polbeam1' in run_card.user_set)
        self.assertTrue('ptl' in run_card.user_set)

        shutil.copy(os.path.join(_file_path, 'input_files', 'run_card_ep.dat'),
                    '%s/Cards/run_card.dat' % self.run_dir)

        self.do('generate_events -f')
        val1 = self.cmd_line.results.current['cross']
        err1 = self.cmd_line.results.current['error']

        target = 3932.0
        self.assertTrue(
            abs(val1 - target) / err1 < 1.,
            'large diference between %s and %s +- %s' % (target, val1, err1))
コード例 #6
0
    def test_madevent_ptj_bias(self):
        """ Test that biasing LO event generation works as intended. """
        self.out_dir = self.run_dir

        if not self.debugging or not os.path.isdir(
                pjoin(MG5DIR, 'BackUp_tmp_test')):
            self.generate('d d~ > u u~', 'sm')
            run_card = banner.RunCardLO(
                pjoin(self.out_dir, 'Cards', 'run_card.dat'))
            run_card.set('bias_module', 'ptj_bias', user=True)
            run_card.set(
                'bias_parameters',
                "{'ptj_bias_target_ptj': 1000.0,'ptj_bias_enhancement_power': 4.0}",
                user=True)
            run_card.set('use_syst', False)
            run_card.set('nevents', 10000)
            run_card.write(pjoin(self.out_dir, 'Cards', 'run_card.dat'))
            self.do('launch -f')
            run_card = banner.RunCardLO(
                pjoin(self.out_dir, 'Cards', 'run_card.dat'))
            run_card.set('bias_module', 'dummy', user=True)
            run_card.set('bias_parameters', "{}", user=True)
            run_card.set('use_syst', False)
            run_card.set('nevents', 10000)
            run_card.write(pjoin(self.out_dir, 'Cards', 'run_card.dat'))
            self.do('launch -f')
            if self.debugging:
                if os.path.isdir(pjoin(MG5DIR, 'BackUp_tmp_test')):
                    shutil.rmtree(pjoin(MG5DIR, 'BackUp_tmp_test'))
                shutil.copytree(pjoin(MG5DIR, 'tmp_test'),
                                pjoin(MG5DIR, 'BackUp_tmp_test'))
        else:
            shutil.rmtree(pjoin(MG5DIR, 'tmp_test'))
            shutil.copytree(pjoin(MG5DIR, 'BackUp_tmp_test'),
                            pjoin(MG5DIR, 'tmp_test'))

        biased_events = lhe_parser.EventFile(
            pjoin(self.out_dir, 'Events', 'run_01',
                  'unweighted_events.lhe.gz'))
        unbiased_events = lhe_parser.EventFile(
            pjoin(self.out_dir, 'Events', 'run_02',
                  'unweighted_events.lhe.gz'))

        biased_events_ptj = []
        biased_events_wgts = []
        for event in biased_events:
            biased_events_ptj.append(math.sqrt(event[2].px**2 +
                                               event[2].py**2))
            biased_events_wgts.append(event.wgt)

        biased_median_ptj = sorted(biased_events_ptj)[len(biased_events_ptj) //
                                                      2]
        unbiased_events_ptj = []
        for event in unbiased_events:
            unbiased_events_ptj.append(
                math.sqrt(event[2].px**2 + event[2].py**2))
        unbiased_median_ptj = sorted(unbiased_events_ptj)[
            len(unbiased_events_ptj) // 2]

        # Make that not all biased events have the same weights
        self.assertGreater(len(set(biased_events_wgts)), 1)
        # Make sure that there is significantly more events in the ptj tail
        self.assertGreater(biased_median_ptj, 5.0 * unbiased_median_ptj)
        # Make sure that the cross-section is close enough for the bias and unbiased samples
        self.assertLess((abs(biased_events.cross - unbiased_events.cross) /
                         abs(unbiased_events.cross)), 0.03)