~madteam/mg5amcnlo/series2.0

« back to all changes in this revision

Viewing changes to tests/acceptance_tests/test_cmd_reweight.py

  • Committer: olivier-mattelaer
  • Date: 2020-08-21 09:16:56 UTC
  • mfrom: (284.2.24 python3)
  • Revision ID: olivier-mattelaer-20200821091656-iizux2mj94tkssuo
pass to 2.8.0 (and move to python3 branch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#
14
14
################################################################################
15
15
from __future__ import division
 
16
from __future__ import absolute_import
16
17
import subprocess
17
18
import math
18
19
import unittest
23
24
import logging
24
25
import time
25
26
import tempfile   
 
27
from six.moves import zip
26
28
 
27
29
logger = logging.getLogger('test_cmd')
28
30
 
135
137
        ff.write(cmd_lines)
136
138
        ff.close()
137
139
        
138
 
 
139
140
        if logger.level <= 10:
140
141
                me_cmd.run_cmd('reweight run_01 --from_cards')
141
142
        else:
160
161
        """ testing that we can reweight the tt~ sample when increasing the top mass
161
162
        """
162
163
        me_cmd = self.get_MEcmd(pjoin(_pickle_path, 'ttbar.lhe.gz'))
163
 
        
164
164
        cmd_lines = """
165
165
        change output 2.0
166
166
        launch
170
170
        ff = open(pjoin(self.run_dir, 'Cards', 'reweight_card.dat'),'w')
171
171
        ff.write(cmd_lines)
172
172
        ff.close()
173
 
        
174
 
        with misc.stdchannel_redirected(sys.stdout, os.devnull):
 
173
        #misc.sprint(self.run_dir)
 
174
        if 1:
 
175
        #with misc.stdchannel_redirected(sys.stdout, os.devnull):
175
176
            me_cmd.run_cmd('reweight run_01 --from_cards')
176
177
 
177
178
        #check that initial file is untouched!        
212
213
        ff = open(pjoin(self.run_dir, 'Cards', 'reweight_card.dat'),'w')
213
214
        ff.write(cmd_lines)
214
215
        ff.close()
215
 
        
216
 
        with misc.stdchannel_redirected(sys.stdout, os.devnull):
 
216
        mad_logger = logging.getLogger('madgraph')
 
217
 
 
218
        if mad_logger.level > 20: 
 
219
            with misc.stdchannel_redirected(sys.stdout, os.devnull):
 
220
                me_cmd.run_cmd('reweight run_01 --from_cards')
 
221
        else:
217
222
            me_cmd.run_cmd('reweight run_01 --from_cards')
218
223
        
219
224
        lhe = lhe_parser.EventFile(pjoin(self.run_dir,'Events','run_01', 'events.lhe.gz'))
242
247
        ff.write(cmd_lines)
243
248
        ff.close()
244
249
        
245
 
        if 1: #with misc.stdchannel_redirected(sys.stdout, os.devnull):
 
250
        mad_logger = logging.getLogger('madgraph')
 
251
        if mad_logger.level > 20: 
 
252
            with misc.stdchannel_redirected(sys.stdout, os.devnull):
 
253
                me_cmd.run_cmd('reweight run_01 --from_cards')
 
254
        else:
246
255
            me_cmd.run_cmd('reweight run_01 --from_cards')
247
 
        
248
256
        #solutions = [41.511565, 41.930505, 41.511565, 41.511565, 41.586169, 41.511565, 41.511565, 41.511565, 41.511565, 42.046806, 41.511565, 44.164503, 41.511565, -41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.778368, 41.511565, 42.05448, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 42.115494, 41.511854, 41.511567, 41.511565, 42.00028, 42.120605, 41.514867, -41.511565, 41.511565, 45.125706, 41.511565, 42.180208, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.997509, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.513926, 41.511565, 41.882499, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 47.532736, 41.511565, 41.809063, 41.511565, 41.511565, 41.511565, 41.927695, 41.511565, 41.511565, 41.555692, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, -41.511565, 41.511565, 42.029675, 41.725129, 41.511565, 41.511565, 41.511778, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 42.050439, 41.511565, 41.511565, 41.511565, -41.511565, 42.071105, 41.511565, 41.511565]
249
257
        solutions =  [41.511565, 41.75164, 41.511565, 41.511565, 41.557009, 41.511565, 41.511565, 41.511565, 41.511565, 41.759881, 41.511565, 44.717244, 41.511565, -41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 42.041827, 41.511565, 41.663092, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.920917, 41.511736, 41.511566, 41.511565, 205.29791, 42.538389, 41.513573, -41.511565, 41.511565, 44.650974, 41.511565, 42.549187, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.431553, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.513265, 41.511565, 43.902643, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 8853.0397, 41.511565, 333.38491, 41.511565, 41.511565, 41.511565, 75.701362, 41.511565, 41.511565, 41.54695, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, -41.511565, 41.511565, 41.454923, 41.53984, 41.511565, 41.511565, 41.511743, 41.511565, 41.511565, 41.511565, 41.511565, 41.511565, 41.732627, 41.511565, 41.511565, 41.511565, -41.511565, 41.395865, 41.511565, 41.511565]
250
258
        lhe = lhe_parser.EventFile(pjoin(self.run_dir,'Events','run_01', 'rwgt_events_tree_rwgt_1.lhe.gz'))
251
259
        lhe_orig = lhe_parser.EventFile(pjoin(self.run_dir,'Events','run_01', 'events.lhe.gz'))
252
 
        from itertools import izip
 
260
        
253
261
        i=-1
254
262
        #solutions = []
255
 
        for event, event_orig in izip(lhe, lhe_orig): 
 
263
        for event, event_orig in zip(lhe, lhe_orig): 
256
264
            i+=1
257
265
            rwgt_data = event_orig.parse_reweight()
258
266
            #solutions.append(rwgt_data['rwgt_1_tree'])
288
296
        ff = open(pjoin(self.run_dir, 'Cards', 'reweight_card.dat'),'w')
289
297
        ff.write(cmd_lines)
290
298
        ff.close()
291
 
        
292
299
        if logger.level <=10:
293
300
            me_cmd.run_cmd('reweight run_01 --from_cards')
294
301
        else:
299
306
        lhe2=  lhe_parser.EventFile(pjoin(self.run_dir,'Events','run_01', 'rwgt_events_tree_rwgt_1.lhe.gz'))
300
307
        solutions = [-113.54512, -113.58961, 113.54938, 113.48467, 113.54938, 113.12672, -113.4863, 113.54938, 113.54938, -113.26805, 105.5589, 110.41614, -113.57167, -113.26911, 113.53355, 113.54938, 113.54869, 113.43885, 113.4151, 113.43279, -113.59921, -113.54938, 113.47688, -113.41315, 113.54938, 113.54938, 113.50453, 113.54938, -113.34559, 113.41821, 113.50674, 113.54273, -113.55721, 113.5204, 113.54938, 113.9101, 113.54938, 110.76533, 85.233315, 113.38153, 113.4684, 113.41541, 113.54272, 114.08548, -113.54938, -113.48963, 113.47811, 86.336518, -113.53947, 113.62442, 113.54938, 119.1288, -113.54595, 113.39149, 113.6222, -113.50107, 114.29253, 81.891469, 113.43238, 113.59844, 112.58522, 113.53639, 111.24306, -113.52251, -113.42222, 113.53443, 113.52775, 113.59714, 101.79775, -173.10123, -113.64323, -113.52939, 113.76665, 113.38901, 113.54938, -113.85094, 112.01344, 113.52052, 113.54769, 113.54938, 113.54938, -113.74874, 114.35555, 113.49268, 113.1658, -113.54938, 113.54938, 113.45114, -106.86842, -113.25424, 113.54488, -113.70535, 113.53027, 113.02052, 113.54938, 113.54938, 113.48797, 113.5419, 113.47777, 113.53698, -113.54938, 113.58857, -113.59011, -113.53687, -113.5632, -113.54938, 50.881047, 113.54904, 113.54696, -113.53998, 98.021403, 113.52701, 113.54544, 112.85106, 113.54891, 113.54938, 113.48127, 113.27728, 113.43749, 113.4915, 113.5246, 113.48554, 113.48386, 112.76115, -113.51762, 113.54938, 112.42106, 113.47272, 115.03299, -113.53507, 113.3365, 113.48839, -113.62701, 113.54938, 113.54019, 115.84251, 113.45177, -113.5123, 113.54938, 113.53011, 109.36941, 112.78596, 113.53325, -113.62137, 113.19992, 114.3632, 113.557, 113.54938, 113.5199, 113.42012, -113.57844, 49.469316, 112.17603, 113.51455, 113.51559, 113.54938]
301
308
        for i,event in enumerate(lhe): 
302
 
            event2 = lhe2.next()
 
309
            event2 = next(lhe2)
303
310
            rwgt_data = event.parse_reweight()
304
311
            #solutions.append(rwgt_data['MYNLO_tree'])
305
312
            if i < len(solutions):
312
319
        """
313
320
        me_cmd = self.get_MEcmd(pjoin(_pickle_path, 'wj_zj.lhe.gz'))
314
321
        
 
322
        
315
323
        cmd_lines = """
316
324
        launch --rwgt_name=SINGLE
317
325
        set aEWM1 150
323
331
        ff.write(cmd_lines)
324
332
        ff.close()
325
333
        
326
 
        with misc.stdchannel_redirected(sys.stdout, os.devnull):
 
334
        if not self.debugging:
 
335
            with misc.stdchannel_redirected(sys.stdout, os.devnull):
 
336
                me_cmd.run_cmd('reweight run_01 --from_cards')
 
337
        else:
327
338
            me_cmd.run_cmd('reweight run_01 --from_cards')
328
 
            
329
339
 
330
340
 
331
341
        lhe = lhe_parser.EventFile(pjoin(self.run_dir,'Events','run_01', 'unweighted_events.lhe.gz'))
335
345
        for i,event in enumerate(lhe):
336
346
            
337
347
            rwgt_data = event.parse_reweight()
 
348
            #misc.sprint(rwgt_data)
338
349
            self.assertTrue('SINGLE' in rwgt_data)
339
350
            self.assertTrue('NAME_0' in rwgt_data)
340
351
            self.assertTrue('NAME_1' in rwgt_data)
369
380
            m_opts['lhapdf'] = True
370
381
            m_opts['lhapdfversion'] = 5 # 6 always fail on my computer since 5 is compatible but slower always use 5
371
382
            m_opts['llhapdf'] = subprocess.Popen([interface.options['lhapdf'], '--libs'], 
372
 
                    stdout = subprocess.PIPE).stdout.read().strip().split()[0]
 
383
                    stdout = subprocess.PIPE).stdout.read().strip().split()[0].decode()
373
384
            m_opts['f2pymode'] = True
374
385
        else:
375
 
            raise Exception, "need LHAPDF"
 
386
            raise Exception("need LHAPDF")
376
387
            lhapdf = False
377
388
            lhapdfversion = 0
378
389
 
388
399
            if self.path not in sys.path:
389
400
                sys.path.insert(0, self.path)
390
401
            mod_name = 'rw_mevirt.Source.rwgt2py'
391
 
            if mod_name in sys.modules.keys():
 
402
            if mod_name in list(sys.modules.keys()):
392
403
                del sys.modules[mod_name]
393
404
                tmp_mod_name = mod_name
394
405
                while '.' in tmp_mod_name:
395
406
                    tmp_mod_name = tmp_mod_name.rsplit('.',1)[0]
396
407
                    del sys.modules[tmp_mod_name]
397
 
                mymod = __import__(mod_name, globals(), locals(), [],-1)  
 
408
                mymod = __import__(mod_name, globals(), locals(), [])  
398
409
            else:
399
 
                mymod = __import__(mod_name, globals(), locals(), [],-1) 
 
410
                mymod = __import__(mod_name, globals(), locals(), []) 
400
411
                
401
412
            mymod =  mymod.Source.rwgt2py
402
413
            #mymod.initialise([1,1], 244600)