739
739
param = param_card['decay'].get((part.pdg_code,))
741
741
if param.value != 0:
742
logger.info('''For gauge cancellation, the width of \'%s\' has been set to zero.'''
742
logger.info('''For gauge cancellation, the width of \'%s\' has been set to zero.'''\
743
743
% part.name,'$MG:color:BLACK')
746
746
param_card.write_inc_file(outfile, ident_card, default)
749
"""return the model related to this process"""
751
if self.options['mg5_path']:
752
sys.path.append(self.options['mg5_path'])
753
import models.import_ufo as import_ufo
754
with misc.MuteLogger(['madgraph.model'],[50]):
755
out= import_ufo.import_model(pjoin(self.me_dir,'bin','internal','ufomodel'))
758
return self.mother._curr_model
749
762
def ask_edit_cards(self, cards, mode='fixed', plot=True, first_cmd=None):
1685
1698
if self.cluster_mode == 1:
1686
1699
opt = self.options
1687
1700
cluster_name = opt['cluster_type']
1688
self.cluster = cluster.from_name[cluster_name](**opt)
1691
def check_param_card(self, path, run=True):
1701
if cluster_name in cluster.from_name:
1702
self.cluster = cluster.from_name[cluster_name](**opt)
1704
if MADEVENT and ('mg5_path' not in self.options or not self.options['mg5_path']):
1705
raise self.InvalidCmd('%s not native cluster type and not MG5aMC found to check for plugin')
1707
mg5dir = self.options['mg5_path']
1708
if mg5dir not in sys.path:
1709
sys.path.append(mg5dir)
1712
# Check if a plugin define this type of cluster
1713
# check for PLUGIN format
1714
for plug in os.listdir(pjoin(mg5dir, 'PLUGIN')):
1715
if os.path.exists(pjoin(mg5dir, 'PLUGIN', plug, '__init__.py')):
1717
__import__('PLUGIN.%s' % plug)
1718
except Exception, error:
1719
logger.critical('plugin directory %s fail to be loaded. Please check it', plug)
1721
plugin = sys.modules['PLUGIN.%s' % plug]
1722
if not hasattr(plugin, 'new_cluster'):
1724
if not misc.is_plugin_supported(plugin):
1726
if cluster_name in plugin.new_cluster:
1727
logger.info("cluster handling will be done with PLUGIN: %s" % plug,'$MG:color:BLACK')
1728
self.cluster = plugin.new_cluster[cluster_name](**opt)
1731
raise self.InvalidCmd, "%s is not recognized as a supported cluster format." % cluster_name
1734
def check_param_card(self, path, run=True, dependent=False):
1693
1736
1) Check that no scan parameter are present
1694
1737
2) Check that all the width are define in the param_card.
1695
1738
- If a scan parameter is define. create the iterator and recall this fonction
1696
1739
on the first element.
1697
- If some width are set on 'Auto', call the computation tools."""
1740
- If some width are set on 'Auto', call the computation tools.
1741
3) if dependent is on True check for dependent parameter (automatic for scan)"""
1699
1743
pattern_scan = re.compile(r'''^(decay)?[\s\d]*scan''', re.I+re.M)
1700
1744
pattern_width = re.compile(r'''decay\s+(\+?\-?\d+)\s+auto(@NLO|)''',re.I)
1720
1764
if not has_nlo:
1721
1765
self.do_compute_widths('%s %s' % (' '.join(pdg), path))
1723
self.do_compute_widths('%s %s --nlo' % (' '.join(pdg), path))
1767
self.do_compute_widths('%s %s --nlo' % (' '.join(pdg), path))
1725
1769
logger.info('''Some width are on Auto in the card.
1726
1770
Those will be computed as soon as you have finish the edition of the cards.
1727
1771
If you want to force the computation right now and being able to re-edit
1728
1772
the cards afterwards, you can type \"compute_wdiths\".''')
1775
card = check_param_card.ParamCard(path)
1776
AskforEditCard.update_dependent(self, self.me_dir, card, path, timer=20)
1731
1780
def add_error_log_in_html(self, errortype=None):
1732
1781
"""If a ME run is currently running add a link in the html output"""
2530
2579
'fixed_scale': ['run_card fixed_fac_scale T', 'run_card fixed_ren_scale T', 'run_card scale %(0)s', 'run_card dsqrt_q2fact1 %(0)s' ,'run_card dsqrt_q2fact2 %(0)s'],
2533
def __init__(self, question, cards=[], mode='auto', *args, **opt):
2582
def load_default(self):
2583
""" define all default variable. No load of card here.
2584
This allow to subclass this class and just change init and still have
2585
all variables defined."""
2588
self.param_card = None
2590
self.pname2block = {}
2592
self.restricted_value = {}
2598
self.has_shower = False
2601
def define_paths(self, **opt):
2536
2604
if 'pwd' in opt:
2537
2605
self.me_dir = opt['pwd']
2540
cmd.OneLinePathCompletion.__init__(self, question, *args, **opt)
2606
elif 'mother_interface' in opt:
2607
self.mother_interface = opt['mother_interface']
2542
2608
if not hasattr(self, 'me_dir') or not self.me_dir:
2543
2609
self.me_dir = self.mother_interface.me_dir
2612
self.paths['param'] = pjoin(self.me_dir,'Cards','param_card.dat')
2613
self.paths['param_default'] = pjoin(self.me_dir,'Cards','param_card_default.dat')
2614
self.paths['run'] = pjoin(self.me_dir,'Cards','run_card.dat')
2615
self.paths['run_default'] = pjoin(self.me_dir,'Cards','run_card_default.dat')
2616
self.paths['transfer'] =pjoin(self.me_dir,'Cards','transfer_card.dat')
2617
self.paths['MadWeight'] =pjoin(self.me_dir,'Cards','MadWeight_card.dat')
2618
self.paths['MadWeight_default'] =pjoin(self.me_dir,'Cards','MadWeight_card_default.dat')
2619
self.paths['ML'] =pjoin(self.me_dir,'Cards','MadLoopParams.dat')
2620
self.paths['shower'] = pjoin(self.me_dir,'Cards','shower_card.dat')
2621
self.paths['shower_default'] = pjoin(self.me_dir,'Cards','shower_card_default.dat')
2622
self.paths['pythia'] =pjoin(self.me_dir, 'Cards','pythia_card.dat')
2623
self.paths['madspin_default'] = pjoin(self.me_dir,'Cards/madspin_card_default.dat')
2624
self.paths['madspin'] = pjoin(self.me_dir,'Cards/madspin_card.dat')
2625
self.paths['reweight'] = pjoin(self.me_dir,'Cards','reweight_card.dat')
2626
self.paths['delphes'] = pjoin(self.me_dir,'Cards','delphes_card.dat')
2628
def __init__(self, question, cards=[], mode='auto', *args, **opt):
2631
self.define_paths(**opt)
2632
cmd.OneLinePathCompletion.__init__(self, question, *args, **opt)
2549
self.param_card = check_param_card.ParamCard(pjoin(self.me_dir,'Cards','param_card.dat'))
2636
self.param_card = check_param_card.ParamCard(self.paths['param'])
2550
2637
except (check_param_card.InvalidParamCard, ValueError) as e:
2551
2638
logger.error('Current param_card is not valid. We are going to use the default one.')
2552
2639
logger.error('problem detected: %s' % e)
2553
2640
files.cp(pjoin(self.me_dir,'Cards','param_card_default.dat'),
2554
2641
pjoin(self.me_dir,'Cards','param_card.dat'))
2555
self.param_card = check_param_card.ParamCard(pjoin(self.me_dir,'Cards','param_card.dat'))
2556
default_param = check_param_card.ParamCard(pjoin(self.me_dir,'Cards','param_card_default.dat'))
2642
self.param_card = check_param_card.ParamCard(self.paths['param'])
2643
default_param = check_param_card.ParamCard(self.paths['param_default'])
2560
self.run_card = banner_mod.RunCard(pjoin(self.me_dir,'Cards','run_card.dat'))
2647
self.run_card = banner_mod.RunCard(self.paths['run'])
2561
2648
except IOError:
2562
2649
self.run_card = {}
2564
run_card_def = banner_mod.RunCard(pjoin(self.me_dir,'Cards','run_card_default.dat'))
2651
run_card_def = banner_mod.RunCard(self.paths['run_default'])
2565
2652
except IOError:
2566
2653
run_card_def = {}
2943
3030
if args[0] in ['run_card', 'param_card', 'MadWeight_card', 'shower_card']:
2944
3031
if args[1] == 'default':
2945
3032
logging.info('replace %s by the default card' % args[0])
2946
files.cp(pjoin(self.me_dir,'Cards','%s_default.dat' % args[0]),
2947
pjoin(self.me_dir,'Cards','%s.dat'% args[0]))
3033
files.cp(self.paths['%s_default' %args[0][:-5]], self.paths[args[0][:-5]])
2948
3034
if args[0] == 'param_card':
2949
self.param_card = check_param_card.ParamCard(pjoin(self.me_dir,'Cards','param_card.dat'))
3035
self.param_card = check_param_card.ParamCard(self.paths['param'])
2950
3036
elif args[0] == 'run_card':
2951
self.run_card = banner_mod.RunCard(pjoin(self.me_dir,'Cards','run_card.dat'))
3037
self.run_card = banner_mod.RunCard(self.paths['run'])
2952
3038
elif args[0] == 'shower_card':
2953
self.shower_card = shower_card_mod.ShowerCard(pjoin(self.me_dir,'Cards','shower_card.dat'))
3039
self.shower_card = shower_card_mod.ShowerCard(self.paths['shower'])
3161
3245
if args[start+1].lower() == 'default':
3162
default = shower_card_mod.ShowerCard(pjoin(self.me_dir,'Cards','shower_card_default.dat'))
3246
default = shower_card_mod.ShowerCard(self.paths['shower_default'])
3163
3247
if args[start] in default.keys():
3164
self.shower_card.set_param(args[start],default[args[start]],pjoin(self.me_dir,'Cards','shower_card.dat'))
3248
self.shower_card.set_param(args[start],default[args[start]], self.paths['shower'])
3166
3250
logger.info('remove information %s from the shower_card' % args[start])
3167
3251
del self.shower_card[args[start]]
3168
3252
elif args[start+1].lower() in ['t','.true.','true']:
3169
self.shower_card.set_param(args[start],'.true.',pjoin(self.me_dir,'Cards','shower_card.dat'))
3253
self.shower_card.set_param(args[start],'.true.',self.paths['shower'])
3170
3254
elif args[start+1].lower() in ['f','.false.','false']:
3171
self.shower_card.set_param(args[start],'.false.',pjoin(self.me_dir,'Cards','shower_card.dat'))
3255
self.shower_card.set_param(args[start],'.false.',self.paths['shower'])
3173
3257
args_str = ' '.join(str(a) for a in args[start+1:len(args)])
3174
self.shower_card.set_param(args[start],args_str,pjoin(self.me_dir,'Cards','shower_card.dat'))
3258
self.shower_card.set_param(args[start],args_str,self.paths['shower'])
3176
3260
# MadLoop Parameter ---------------------------------------------------
3177
3261
elif self.has_ml and args[start] in self.ml_vars \
3302
3386
logger.warning('No transfer function currently define. Please use the change_tf command to define one.')
3304
3388
def postcmd(self, stop, line):
3306
3389
ending_question = cmd.OneLinePathCompletion.postcmd(self,stop,line)
3307
3391
if ending_question:
3308
3392
self.check_card_consistency()
3393
self.do_update_dependent('', timer=20)
3309
3394
return ending_question
3396
def do_update_dependent(self, line, timer=0):
3397
"""Change the mass/width of particles which are not free parameter for the
3399
if not self.mother_interface:
3400
logger.warning('Failed to update dependent parameter. This might create trouble for external program (like MadSpin/shower/...)')
3402
pattern_width = re.compile(r'''decay\s+(\+?\-?\d+)\s+auto(@NLO|)''',re.I)
3403
pattern_scan = re.compile(r'''^(decay)?[\s\d]*scan''', re.I+re.M)
3404
param_text= open(self.paths['param']).read()
3406
if pattern_scan.search(param_text):
3407
#for block, key in self.restricted_value:
3408
# self.param_card[block].get(key).value = -9.999e-99
3409
# self.param_card.write(self.paths['param'])
3411
elif pattern_width.search(param_text):
3412
self.do_compute_widths('')
3413
self.param_card = check_param_card.ParamCard(self.paths['param'])
3415
# calling the routine doing the work
3416
self.update_dependent(self.mother_interface, self.me_dir, self.param_card,
3417
self.paths['param'], timer)
3420
def update_dependent(mecmd, me_dir, param_card, path ,timer=0):
3421
"""static method which can also be called from outside the class
3422
usefull in presence of scan.
3423
return if the param_card was updated or not
3426
class TimeOutError(Exception):
3428
def handle_alarm(signum, frame):
3430
signal.signal(signal.SIGALRM, handle_alarm)
3436
# Try to load the model in the limited amount of time allowed
3438
model = mecmd.get_model()
3440
except TimeOutError:
3441
logger.warning('The model takes too long to load so we bypass the updating of dependent parameter.\n'+\
3442
'This might create trouble for external program (like MadSpin/shower/...)\n'+\
3443
'The update can be forced without timer by typing \'update_dependent\' at the time of the card edition')
3446
logger.warning('Failed to update dependent parameter. This might create trouble for external program (like MadSpin/shower/...)')
3449
restrict_card = pjoin(me_dir,'Source','MODEL','param_card_rule.dat')
3450
if not os.path.exists(restrict_card):
3451
restrict_card = None
3452
#restrict_card = None
3454
modify = param_card.update_dependent(model, restrict_card, log_level)
3456
param_card.write(path)
3458
logger.warning('missing MG5aMC code. Fail to update dependent parameter. This might create trouble for program like MadSpin/shower/...')
3461
logger.info('param_card up to date.')
3311
3468
def check_answer_consistency(self):
3312
3469
"""function called if the code reads a file"""
3313
self.check_card_consistency()
3470
self.check_card_consistency()
3471
self.do_update_dependent('', timer=20)
3315
3473
def help_set(self):
3316
3474
'''help message for set'''
3540
3702
answer = answer.replace('madweight', 'MadWeight')
3542
3704
if 'MadLoopParams' in answer:
3543
answer = pjoin(me_dir,'Cards','MadLoopParams.dat')
3705
answer = self.paths['ML']
3544
3706
if not '.dat' in answer and not '.lhco' in answer:
3545
3707
if answer != 'trigger':
3546
path = pjoin(me_dir,'Cards','%s_card.dat' % answer)
3708
path = self.paths[answer]
3548
path = pjoin(me_dir,'Cards','delphes_trigger.dat')
3710
path = self.paths['delphes']
3549
3711
elif not '.lhco' in answer:
3550
path = pjoin(me_dir, 'Cards', answer)
3713
path = self.paths[answer.split('_')[0]]
3715
path = pjoin(me_dir, 'Cards', answer)
3552
3717
path = pjoin(me_dir, self.mw_card['mw_run']['inputfile'])
3553
3718
if not os.path.exists(path):
3582
3747
logger.error('problem detected: %s' % e)
3583
3748
logger.error('Please re-open the file and fix the problem.')
3584
3749
logger.warning('using the \'set\' command without opening the file will discard all your manual change')
3585
elif path == pjoin(self.me_dir,'Cards','run_card.dat'):
3586
self.run_card = banner_mod.RunCard(pjoin(self.me_dir,'Cards','run_card.dat'))
3587
elif path == pjoin(self.me_dir,'Cards','MadLoopParams.dat'):
3588
self.MLcard = banner_mod.MadLoopParam(pjoin(self.me_dir,'Cards','MadLoopParams.dat'))
3589
elif path == pjoin(self.me_dir,'Cards','MadWeight_card.dat'):
3750
elif path == self.paths['run']:
3751
self.run_card = banner_mod.RunCard(path)
3752
elif path == self.paths['ML']:
3753
self.MLcard = banner_mod.MadLoopParam(path)
3754
elif path == self.paths['MadWeight']:
3591
3756
import madgraph.madweight.Cards as mwcards
3593
3758
import internal.madweight.Cards as mwcards
3594
self.mw_card = mwcards.Card(pjoin(self.me_dir,'Cards','MadWeight_card.dat'))
3759
self.mw_card = mwcards.Card(path)
3762
class EditParamCard(AskforEditCard):
3763
"""a dedicated module for the param"""
3765
special_shortcut ={}
3767
def __init__(self, question, card=[], mode='auto', *args, **opt):
3770
cmd.OneLinePathCompletion.__init__(self, question, *args, **opt)
3771
if os.path.isfile(card[0]):
3772
self.param_card = check_param_card.ParamCard(card[0])
3773
self.paths['param'] = card[0]
3774
if os.path.isfile(card[0].replace('.dat', '_default.dat')):
3775
self.paths['param_default'] = card[0].replace('.dat', '_default.dat')
3777
self.paths['param_default'] = card[0]
3779
raise Exception, 'path %s do not exists' % card[0]
3781
self.pname2block, self.restricted_value = self.param_card.analyze_param_card()
3782
self.cards=['param']
3784
def do_asperge(self, *args, **opts):
3786
logger.warning("asperge not available in this mode")