~madteam/mg5amcnlo/series2.0

« back to all changes in this revision

Viewing changes to tests/acceptance_tests/test_cmd_madevent.py

  • Committer: olivier Mattelaer
  • Date: 2015-03-05 00:14:16 UTC
  • mfrom: (258.1.9 2.3)
  • mto: (258.8.1 2.3)
  • mto: This revision was merged to the branch mainline in revision 259.
  • Revision ID: olivier.mattelaer@uclouvain.be-20150305001416-y9mzeykfzwnl9t0j
partial merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
    
55
55
    def setUp(self):
56
56
        
57
 
        self.path = tempfile.mkdtemp(prefix='acc_test_mg5')
 
57
        debugging = True
 
58
        if debugging:
 
59
            self.path = pjoin(MG5DIR, "tmp_test")
 
60
            if os.path.exists(self.path):
 
61
                shutil.rmtree(self.path)
 
62
            os.mkdir(pjoin(MG5DIR, "tmp_test"))
 
63
        else:
 
64
            self.path = tempfile.mkdtemp(prefix='acc_test_mg5')
58
65
        self.run_dir = pjoin(self.path, 'MGPROC') 
59
66
    
60
67
    def tearDown(self):
61
68
 
62
 
        shutil.rmtree(self.path)
 
69
        if self.path != pjoin(MG5DIR, "tmp_test"):
 
70
            shutil.rmtree(self.path)
63
71
    
64
72
    def generate(self, process, model):
65
73
        """Create a process"""
85
93
            stderr=devnull
86
94
 
87
95
        if not os.path.exists(pjoin(MG5DIR, 'pythia-pgs')):
 
96
            print "install pythia-pgs"
88
97
            p = subprocess.Popen([pjoin(MG5DIR,'bin','mg5')],
89
98
                             stdin=subprocess.PIPE,
90
99
                             stdout=stdout,stderr=stderr)
91
100
            out = p.communicate('install pythia-pgs')
92
101
        misc.compile(cwd=pjoin(MG5DIR,'pythia-pgs'))
93
102
        if not os.path.exists(pjoin(MG5DIR, 'MadAnalysis')):
 
103
            print "install MadAnalysis"
94
104
            p = subprocess.Popen([pjoin(MG5DIR,'bin','mg5')],
95
105
                             stdin=subprocess.PIPE,
96
106
                             stdout=stdout,stderr=stderr)
104
114
        interface.onecmd('output madevent %s -f' % self.run_dir)            
105
115
        
106
116
        if not os.path.exists(pjoin(interface.options['syscalc_path'],'sys_calc')):
 
117
            print "install SysCalc"
107
118
            interface.onecmd('install SysCalc')
108
119
        
109
120
        
120
131
    
121
132
    def do(self, line):
122
133
        """ exec a line in the cmd under test """        
123
 
        self.cmd_line.exec_cmd(line)
 
134
        self.cmd_line.run_cmd(line)
124
135
        
125
136
  
126
137
    def test_madspin_gridpack(self):
171
182
        
172
183
        text = open('%s/Events/run_01/param_card.dat' % self.run_dir).read()
173
184
        data = text.split('DECAY  23')[1].split('DECAY',1)[0]
174
 
        self.assertEqual("""1.492240e+00
175
 
#  BR             NDA  ID1    ID2   ...
176
 
   2.493165e-01   2    3  -3 # 0.37204
177
 
   2.493165e-01   2    1  -1 # 0.37204
178
 
   1.944158e-01   2    4  -4 # 0.290115
179
 
   1.944158e-01   2    2  -2 # 0.290115
180
 
   5.626776e-02   2    -11  11 # 0.083965
181
 
   5.626776e-02   2    -13  13 # 0.083965
182
 
#
183
 
#      PDG        Width""".split('\n'), data.strip().split('\n'))
 
185
        data = data.split('\n')
 
186
        width = float(data[0])
 
187
        self.assertAlmostEqual(width, 1.492240e+00, delta=1e-4)
 
188
        values = {(3,-3): 2.493165e-01,
 
189
                  (1,-1): 2.493165e-01,
 
190
                  (4,-4): 1.944158e-01,
 
191
                  (2,-2): 1.944158e-01,
 
192
                  (-11,11): 5.626776e-02,
 
193
                  (-13,13): 5.626776e-02}
 
194
        for l in data[1:]:
 
195
            if l.startswith("#"):
 
196
                continue
 
197
            l = l.strip()
 
198
            if not l:
 
199
                continue
 
200
            #2.493165e-01   2    3  -3 # 0.37204
 
201
            br, _, id1,id2,_,_ = l.split()
 
202
            
 
203
            self.assertAlmostEqual(float(br), values[(int(id1),int(id2))],delta=1e-3)
 
204
        
 
205
        
 
206
#         self.assertEqual("""1.492240e+00
 
207
# #  BR             NDA  ID1    ID2   ...
 
208
#    2.493165e-01   2    3  -3 # 0.37204
 
209
#    2.493165e-01   2    1  -1 # 0.37204
 
210
#    1.944158e-01   2    4  -4 # 0.290115
 
211
#    1.944158e-01   2    2  -2 # 0.290115
 
212
#    5.626776e-02   2    -11  11 # 0.083965
 
213
#    5.626776e-02   2    -13  13 # 0.083965
 
214
# #
 
215
# #      PDG        Width""".split('\n'), data.strip().split('\n'))
184
216
        
185
217
    def test_creating_matched_plot(self):
186
218
        """test that the creation of matched plot works and the systematics as well"""
297
329
        err1 = self.cmd_line.results.current['error']
298
330
        
299
331
        target = 155.9
300
 
        self.assertTrue(abs(val1 - target) / err1 < 1.)
 
332
        self.assertTrue(abs(val1 - target) / err1 < 2.)
301
333
        
302
334
    def load_result(self, run_name):
303
335
        
304
336
        import madgraph.iolibs.save_load_object as save_load_object
305
 
        import madgraph.various.gen_crossxhtml as gen_crossxhtml
 
337
        import madgraph.madevent.gen_crossxhtml as gen_crossxhtml
306
338
        
307
339
        result = save_load_object.load_from_file('%s/HTML/results.pkl' % self.run_dir)
308
340
        return result[run_name]
495
527
        
496
528
        #a=rwa_input('freeze')
497
529
        self.check_parton_output(cross=150770.0, error=7.4e+02,target_event=1000)
498
 
        self.check_parton_output('run_01_decayed_1', cross=66344.2066122, error=6.3e+02,target_event=1000)
 
530
        self.check_parton_output('run_01_decayed_1', cross=66344.2066122, error=1.5e+03,target_event=1000)
499
531
        #logger.info('\nMS info: the number of events in the html file is not (always) correct after MS\n')
500
532
        self.check_parton_output('run_01_decayed_2', cross=100521.52517, error=8e+02,target_event=1000)
501
533
        self.check_pythia_output(run_name='run_01_decayed_1')
553
585
    def load_result(self, run_name):
554
586
        
555
587
        import madgraph.iolibs.save_load_object as save_load_object
556
 
        import madgraph.various.gen_crossxhtml as gen_crossxhtml
 
588
        import madgraph.madevent.gen_crossxhtml as gen_crossxhtml
557
589
        
558
590
        result = save_load_object.load_from_file(pjoin(self.run_dir,'HTML/results.pkl'))
559
591
        return result[run_name]
568
600
        self.assertTrue('lhe' in data[0].parton)
569
601
        
570
602
        if cross:
571
 
            self.assertTrue(abs(cross - float(data[0]['cross']))/error < 3,
572
 
                            'cross is %s and not %s. NB_SIGMA %s' % (float(data[0]['cross']), cross, float(data[0]['cross'])/error)
 
603
            import math
 
604
            new_error = math.sqrt(error**2 + float(data[0]['error'])**2)
 
605
            self.assertTrue(abs(cross - float(data[0]['cross']))/new_error < 3,
 
606
                            'cross is %s and not %s. NB_SIGMA %s' % (float(data[0]['cross']), cross, float(data[0]['cross'])/new_error)
573
607
                            )
 
608
            self.assertTrue(float(data[0]['error']) < 3 * error)
574
609
                            
575
610
    def check_pythia_output(self, run_name='run_01'):
576
611
        """ """
631
666
    def load_result(self, run_name):
632
667
        
633
668
        import madgraph.iolibs.save_load_object as save_load_object
634
 
        import madgraph.various.gen_crossxhtml as gen_crossxhtml
 
669
        import madgraph.madevent.gen_crossxhtml as gen_crossxhtml
635
670
        
636
671
        result = save_load_object.load_from_file('/tmp/MGPROCESS/HTML/results.pkl')
637
672
        return result[run_name]