~madteam/mg5amcnlo/series2.0

« back to all changes in this revision

Viewing changes to tests/acceptance_tests/test_cmd_amcatnlo.py

merged with 2.3 rev286

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
import tests.unit_tests.iolibs.test_file_writers as test_file_writers
31
31
from tests.unit_tests.various.test_aloha import set_global
 
32
import tests.IOTests as IOTests
32
33
 
33
34
import madgraph.interface.master_interface as MGCmd
34
35
import madgraph.interface.amcatnlo_run_interface as NLOCmd
35
36
import madgraph.interface.launch_ext_program as launch_ext
36
37
import madgraph.iolibs.files as files
37
38
import madgraph.various.misc as misc
 
39
import madgraph.various.banner as banner
38
40
 
39
41
 
40
42
_file_path = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]
47
49
#===============================================================================
48
50
# TestCmd
49
51
#===============================================================================
50
 
class TestMECmdShell(unittest.TestCase):
 
52
class MECmdShell(IOTests.IOTestManager):
51
53
    """this treats all the command not related to MG_ME"""
52
54
    
53
55
    loadtime = time.time()
 
56
    debugging = False
54
57
    
55
58
    def setUp(self):
56
59
        
57
 
        self.tmpdir = tempfile.mkdtemp(prefix='amc')
58
 
        #if os.path.exists(self.tmpdir):
59
 
        #    shutil.rmtree(self.tmpdir)
60
 
        #os.mkdir(self.tmpdir)
 
60
        if not self.debugging:
 
61
            self.tmpdir = tempfile.mkdtemp(prefix='amc')
 
62
            #if os.path.exists(self.tmpdir):
 
63
            #    shutil.rmtree(self.tmpdir)
 
64
            #os.mkdir(self.tmpdir)
 
65
            self.path = pjoin(self.tmpdir,'MGProcess')
 
66
        else:
 
67
            if os.path.exists(pjoin(MG5DIR, 'TEST_AMC')):
 
68
                shutil.rmtree(pjoin(MG5DIR, 'TEST_AMC'))
 
69
            os.mkdir(pjoin(MG5DIR, 'TEST_AMC'))
 
70
            self.tmpdir = pjoin(MG5DIR, 'TEST_AMC')
 
71
            
61
72
        self.path = pjoin(self.tmpdir,'MGProcess')
62
 
 
63
73
    def tearDown(self):
64
 
        shutil.rmtree(self.tmpdir)
 
74
        if not self.debugging:
 
75
            shutil.rmtree(self.tmpdir)
65
76
    
66
77
    
67
78
    def generate(self, process, model, multiparticles=[]):
147
158
        self.assertTrue(os.path.exists('%s/Events/run_01/run_01_tag_1_banner.txt' % self.path))
148
159
        self.assertTrue(os.path.exists('%s/Events/run_01/plot_HERWIG6_1_0.top' % self.path))
149
160
 
150
 
 
151
 
    def test_check_html_long_process_strings(self):
152
 
        """check that the info.html file correctly lists all the subprocesses,
153
 
        even when the process string has to be split on more lines (for length 
154
 
        reasons)"""
 
161
    @IOTests.createIOTest()
 
162
    def testIO_check_html_long_process_strings(self):
 
163
        """ target: info.html
 
164
        """
 
165
        #check that the info.html file correctly lists all the subprocesses,
 
166
        #even when the process string has to be split on more lines (for length 
 
167
        #reasons)
 
168
        
155
169
        cmd = os.getcwd()
156
170
        self.generate(['p p > h w+ > ta+ ta- e+ ve [QCD]'], 'sm')
157
171
        self.assertEqual(cmd, os.getcwd())
158
172
 
159
 
        info_html_target = open(os.path.join(cmd, 'tests', 'input_files',
160
 
               'info_pp_to_hw_to_lvtata_nloqcd.html')).read()
 
173
        #info_html_target = open(os.path.join(cmd, 'tests', 'input_files',
 
174
        #       'info_pp_to_hw_to_lvtata_nloqcd.html')).read()
161
175
        info_html_this = open(os.path.join(self.path, 'HTML', 'info.html')).read()
162
 
        self.assertEqual(info_html_target, info_html_this)
163
 
 
 
176
        #self.assertEqual(info_html_target, info_html_this)
 
177
        open(pjoin(self.IOpath, "info.html"),"w").write(info_html_this)
164
178
 
165
179
    def test_check_ppzjj(self):
166
180
        """test that p p > z j j is correctly output without raising errors"""
188
202
        self.assertEqual(cmd, os.getcwd())
189
203
 
190
204
        card = open('%s/Cards/run_card_default.dat' % self.path).read()
191
 
        self.assertTrue('    1   = lpp' in card)
192
 
        self.assertTrue('6500   = ebeam' in card)
193
 
        self.assertTrue('nn23nlo   = pdlabel' in card)
194
 
        card = card.replace('    1   = lpp', '    0   = lpp')
195
 
        card = card.replace('6500   = ebeam', ' 500   = ebeam')
196
 
        card = card.replace('nn23nlo   = pdlabel', '\'lhapdf\' = pdlabel')
197
 
        open('%s/Cards/run_card.dat' % self.path, 'w').write(card)
 
205
        # this check that the value of lpp/beam are change automatically
 
206
        self.assertTrue('0   = lpp1' in card)
 
207
        self.assertTrue('500   = ebeam' in card)
 
208
        # pass to the object
 
209
        card = banner.RunCardNLO(card)
 
210
        card['pdlabel'] = "lhapdf"
 
211
        self.assertEqual(card['lpp1'], 0)
 
212
        self.assertEqual(card['lpp2'], 0)
 
213
        self.assertEqual(card['ebeam1'], 500)
 
214
        self.assertEqual(card['ebeam2'], 500)
 
215
        card.write('%s/Cards/run_card.dat' % self.path)
 
216
        
198
217
 
199
218
        self.do('calculate_xsect -f LO')
200
219
        self.do('quit')
201
220
 
202
 
        self.assertTrue(os.path.exists('%s/Events/run_01_LO/MADatNLO.top' % self.path))
 
221
        self.assertTrue(os.path.exists('%s/Events/run_01_LO/MADatNLO.HwU' % self.path))
203
222
        self.assertTrue(os.path.exists('%s/Events/run_01_LO/res.txt' % self.path))
204
223
        self.assertTrue(os.path.exists('%s/Events/run_01_LO/summary.txt' % self.path))
205
224
        self.assertTrue(os.path.exists('%s/Events/run_01_LO/run_01_LO_tag_1_banner.txt' % self.path))
300
319
        cmd = os.getcwd()
301
320
        self.generate(['p p > e+ e- [real=QCD] '], 'sm')
302
321
        card = open('%s/Cards/run_card_default.dat' % self.path).read()
303
 
        self.assertTrue( ' -1 = nevt_job' in card)
 
322
        self.assertTrue( '-1 = nevt_job' in card)
304
323
        self.assertTrue( '10000 = nevents' in card)
305
 
        self.assertTrue( ' -1 = req_acc' in card)
 
324
        self.assertTrue( '-1.0 = req_acc' in card)
306
325
        card = card.replace(' -1 = nevt_job', '1 = nevt_job')
307
326
        card = card.replace('10000 = nevents', '6 = nevents')
308
327
        card = card.replace(' -1 = req_acc', '0.1 = req_acc')
433
452
 
434
453
        self.do('launch NLO -f')
435
454
        # test the plot file exists
436
 
        self.assertTrue(os.path.exists('%s/Events/run_01/MADatNLO.top' % self.path))
 
455
        self.assertTrue(os.path.exists('%s/Events/run_01/MADatNLO.HwU' % self.path))
437
456
        self.assertTrue(os.path.exists('%s/Events/run_01/summary.txt' % self.path))
438
457
        self.assertTrue(os.path.exists('%s/Events/run_01/run_01_tag_1_banner.txt' % self.path))
439
458
        self.assertTrue(os.path.exists('%s/Events/run_01/res.txt' % self.path))
450
469
                stdout = open(os.devnull, 'w'))
451
470
 
452
471
        # test the plot file exists
453
 
        self.assertTrue(os.path.exists('%s/Events/run_01/MADatNLO.top' % self.path))
 
472
        self.assertTrue(os.path.exists('%s/Events/run_01/MADatNLO.HwU' % self.path))
454
473
        self.assertTrue(os.path.exists('%s/Events/run_01/summary.txt' % self.path))
455
474
        self.assertTrue(os.path.exists('%s/Events/run_01/run_01_tag_1_banner.txt' % self.path))
456
475
        self.assertTrue(os.path.exists('%s/Events/run_01/alllogs_0.html' % self.path))
757
776
        self.do('calculate_xsect NLO -f')        
758
777
        
759
778
        # test the plot file exists
760
 
        self.assertTrue(os.path.exists('%s/Events/run_01/MADatNLO.top' % self.path))
 
779
        self.assertTrue(os.path.exists('%s/Events/run_01/MADatNLO.HwU' % self.path))
761
780
        self.assertTrue(os.path.exists('%s/Events/run_01/res.txt' % self.path))
762
781
        self.assertTrue(os.path.exists('%s/Events/run_01/summary.txt' % self.path))
763
782
        self.assertTrue(os.path.exists('%s/Events/run_01/run_01_tag_1_banner.txt' % self.path))
773
792
        self.do('calculate_xsect LO -f')        
774
793
        
775
794
        # test the plot file exists
776
 
        self.assertTrue(os.path.exists('%s/Events/run_01_LO/MADatNLO.top' % self.path))
 
795
        self.assertTrue(os.path.exists('%s/Events/run_01_LO/MADatNLO.HwU' % self.path))
777
796
        self.assertTrue(os.path.exists('%s/Events/run_01_LO/res.txt' % self.path))
778
797
        self.assertTrue(os.path.exists('%s/Events/run_01_LO/summary.txt' % self.path))
779
798
        self.assertTrue(os.path.exists('%s/Events/run_01_LO/run_01_LO_tag_1_banner.txt' % self.path))
786
805
        
787
806
        cwd = os.getcwd()
788
807
        try:
789
 
            shutil.rmtree('%s/' % self.path)
 
808
            os.remove('%s/test.log' % self.tmpdir)
790
809
        except Exception, error:
791
810
            pass
792
811
        import subprocess
793
812
        
794
 
        stdout = open('/tmp/test.log','w')
 
813
        stdout = open('%s/test.log' % self.tmpdir,'w')
795
814
        if logging.getLogger('madgraph').level <= 20:
796
815
            stderr=None
797
816
        else:
802
821
            
803
822
        subprocess.call([pjoin(_file_path, os.path.pardir,'bin','mg5'), 
804
823
                         pjoin(_file_path, 'input_files','test_amcatnlo')],
805
 
                         cwd=pjoin(MG5DIR),
 
824
                         cwd=self.tmpdir,
806
825
                        stdout=stdout,stderr=stderr)
807
826
        stdout.close()
808
 
        text = open('/tmp/test.log','r').read()
 
827
        text = open('%s/test.log' % self.tmpdir,'r').read()
809
828
        data = text.split('\n')
810
829
        for i,line in enumerate(data):
811
830
            if 'Summary:' in line:
823
842
 
824
843
        #      Number of events generated: 10000        
825
844
        self.assertTrue('Number of events generated: 100' in data[i+4])
826
 
        
 
845
 
 
846
 
 
847
    def test_jet_veto_xsec(self):
 
848
        """tests the jet-veto cross section at NNLL+NLO"""
 
849
        self.generate_production()
 
850
        cmd = """generate_events NLO
 
851
                 set ickkw -1
 
852
                 set ptj 10
 
853
                 """
 
854
        open('/tmp/mg5_cmd','w').write(cmd)
 
855
        self.assertFalse(self.cmd_line.options['automatic_html_opening'])
 
856
        self.cmd_line.import_command_file('/tmp/mg5_cmd')
 
857
        self.assertTrue(os.path.exists('%s/Events/run_01/summary.txt' % self.path))
 
858
        text=open('%s/Events/run_01/summary.txt' % self.path,'r').read()
 
859
        data=text.split('\n')
 
860
        for i,line in enumerate(data):
 
861
            if 'Process' in line:
 
862
                break
 
863
        #      Run at p-p collider (6500 + 6500 GeV)
 
864
        self.assertTrue('Run at p-p collider (6500 + 6500 GeV)' in data[i+1])
 
865
        cross_section = data[i+2]
 
866
        cross_section = float(cross_section.split(':')[1].split('+-')[0])
 
867
        try:
 
868
            self.assertAlmostEqual(6011.0, cross_section,delta=50)
 
869
        except TypeError:
 
870
            self.assertTrue(cross_section < 4151. and cross_section > 4151.)
827
871
 
828
872
    def load_result(self, run_name):
829
873
        
830
874
        import madgraph.iolibs.save_load_object as save_load_object
831
 
        import madgraph.various.gen_crossxhtml as gen_crossxhtml
 
875
        import madgraph.madevent.gen_crossxhtml as gen_crossxhtml
832
876
        
833
877
        result = save_load_object.load_from_file('%s/HTML/results.pkl' % self.path)
834
878
        return result[run_name]