~maddevelopers/mg5amcnlo/2.6.5_ewa

« back to all changes in this revision

Viewing changes to madgraph/interface/common_run_interface.py

  • Committer: olivier-mattelaer
  • Date: 2020-08-13 08:01:25 UTC
  • mfrom: (281.3.23 2.7.4)
  • Revision ID: olivier-mattelaer-20200813080125-dvgl90l47g9jekf1
merge with 2.7.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1036
1036
            out = ask(question, '0', possible_answer, timeout=int(1.5*timeout),
1037
1037
                              path_msg='enter path', ask_class = AskforEditCard,
1038
1038
                              cards=cards, mode=mode, **opt)
1039
 
 
 
1039
            if 'return_instance' in opt and opt['return_instance']:
 
1040
                out, cmd = out
 
1041
        if 'return_instance' in opt and opt['return_instance']:
 
1042
            return (out, cmd)
 
1043
        return out
1040
1044
 
1041
1045
    @staticmethod
1042
1046
    def detect_card_type(path):
2836
2840
                    reco_output = pjoin(self.me_dir,
2837
2841
                           'MA5_%s_ANALYSIS%s_%d'%(mode.upper(),MA5_runtag,i+1))
2838
2842
                    # Look for either a root or .lhe.gz output
2839
 
                    reco_event_file = misc.glob('*.lhe.gz',pjoin(reco_output,'Output','_reco_events','lheEvents0_%d'%MA5_run_number))+\
2840
 
                                       misc.glob('*.root',pjoin(reco_output,'Output','_reco_events', 'RecoEvents0_%d'%MA5_run_number))
 
2843
                    reco_event_file = misc.glob('*.lhe.gz',pjoin(reco_output,'Output','SAF','_reco_events','lheEvents0_%d'%MA5_run_number))+\
 
2844
                                       misc.glob('*.root',pjoin(reco_output,'Output','SAF','_reco_events', 'RecoEvents0_%d'%MA5_run_number))
2841
2845
                    if len(reco_event_file)==0:
2842
2846
                        raise MadGraph5Error, "MadAnalysis5 failed to produce the "+\
2843
2847
                  "reconstructed event file for reconstruction '%s'."%MA5_runtag[6:]
2852
2856
                    parent_dir_name = os.path.basename(os.path.dirname(reco_event_file))
2853
2857
                    files.ln(pjoin(self.me_dir,'HTML',self.run_name,
2854
2858
                      '%s_MA5_%s_ANALYSIS%s_%d'%(self.run_tag,mode.upper(),
2855
 
                      MA5_runtag,i+1),'Output','_reco_events',parent_dir_name,links_created[-1]),
 
2859
                      MA5_runtag,i+1),'Output','SAF','_reco_events',parent_dir_name,links_created[-1]),
2856
2860
                                      pjoin(self.me_dir,'Events',self.run_name))
2857
2861
 
2858
2862
                logger.info("MadAnalysis5 successfully completed the reconstruction "+
3328
3332
            if mass and abs(width/mass) < 1e-12:
3329
3333
                if hasattr(interface, 'run_card') and isinstance(interface.run_card, banner_mod.RunCardLO):
3330
3334
                    if interface.run_card['small_width_treatment'] < 1e-12:
3331
 
                        logger.error('The width of particle %s is too small for an s-channel resonance (%s) and the small_width_paramer is too small to prevent numerical issues. If you have this particle in an s-channel, this is likely to create numerical instabilities .', param.lhacode[0], width)
 
3335
                        logger.error('The width of particle %s is too small for an s-channel resonance (%s) and the small_width_treatment parameter is too small to prevent numerical issues. If you have this particle in an s-channel, this is likely to create numerical instabilities .', param.lhacode[0], width)
3332
3336
                else:
3333
3337
                    logger.error('The width of particle %s is too small for an s-channel resonance (%s). If you have this particle in an s-channel, this is likely to create numerical instabilities .', param.lhacode[0], width)
3334
3338
                if CommonRunCmd.sleep_for_error:
3700
3704
 
3701
3705
        madspin_cmd.import_command_file(path)
3702
3706
 
3703
 
        # create a new run_name directory for this output
3704
 
        i = 1
3705
 
        while os.path.exists(pjoin(self.me_dir,'Events', '%s_decayed_%i' % (self.run_name,i))):
3706
 
            i+=1
3707
 
        new_run = '%s_decayed_%i' % (self.run_name,i)
 
3707
 
 
3708
        if not madspin_cmd.me_run_name: 
 
3709
            # create a new run_name directory for this output
 
3710
            i = 1
 
3711
            while os.path.exists(pjoin(self.me_dir,'Events', '%s_decayed_%i' % (self.run_name,i))):
 
3712
                i+=1
 
3713
            new_run = '%s_decayed_%i' % (self.run_name,i)
 
3714
        else:
 
3715
            new_run = madspin_cmd.me_run_name
 
3716
            if os.path.exists(pjoin(self.me_dir,'Events', new_run)):
 
3717
                i = 1
 
3718
                while os.path.exists(pjoin(self.me_dir,'Events', '%s_%i' % (new_run,i))):
 
3719
                    i+=1
 
3720
                new_run = '%s_%i' % (new_run,i)
 
3721
 
3708
3722
        evt_dir = pjoin(self.me_dir, 'Events')
3709
3723
 
3710
3724
        os.mkdir(pjoin(evt_dir, new_run))
4098
4112
            if not require_local and (os.path.exists(pjoin(pdfsets_dir, pdfset)) or \
4099
4113
                                    os.path.isdir(pjoin(pdfsets_dir, pdfset))):
4100
4114
                continue
 
4115
            if not require_local:
 
4116
                if 'LHAPDF_DATA_PATH' in os.environ:
 
4117
                    found = False
 
4118
                    for path in os.environ['LHAPDF_DATA_PATH'].split(":"):
 
4119
                        if (os.path.exists(pjoin(path, pdfset)) or \
 
4120
                                    os.path.isdir(pjoin(path, pdfset))):
 
4121
                            found =True
 
4122
                            break
 
4123
                    if found:
 
4124
                        continue
 
4125
                    
 
4126
                    
4101
4127
            #check that the pdfset is not already there
4102
4128
            elif not os.path.exists(pjoin(self.me_dir, 'lib', 'PDFsets', pdfset)) and \
4103
4129
               not os.path.isdir(pjoin(self.me_dir, 'lib', 'PDFsets', pdfset)):
4309
4335
                        stdout = subprocess.PIPE).stdout.read().strip()
4310
4336
        except OSError, error:
4311
4337
            if error.errno == 2:
4312
 
                raise Exception, 'lhapdf executable (%s) is not found on your system. Please install it and/or indicate the path to the correct executable in input/mg5_configuration.txt' % self.options['lhapdf']
 
4338
                raise Exception, 'lhapdf executable (%s) is not found on your system. Please install it and/or indicate the path to the correct executable in input/mg5_configuration.txt' % lhapdf_config
4313
4339
            else:
4314
4340
                raise
4315
4341
                
4495
4521
        self.modified_card = set() #set of cards not in sync with filesystem
4496
4522
                              # need to sync them before editing/leaving
4497
4523
        self.init_from_banner(from_banner, banner)
4498
 
        
 
4524
        self.writting_card = True
 
4525
        if 'write_file' in opt:
 
4526
            if not opt['write_file']:
 
4527
                self.writting_card = False
 
4528
                self.param_consistency = False
 
4529
                        
4499
4530
        #update default path by custom one if specify in cards
4500
4531
        for card in cards:
4501
4532
            if os.path.exists(card) and os.path.sep in cards:
4773
4804
            return []
4774
4805
        
4775
4806
        self.special_shortcut.update({
4776
 
            'spinmode':([str], ['add madspin_card --before_line="launch" set spinmode %(0)s'])
 
4807
            'spinmode':([str], ['add madspin_card --before_line="launch" set spinmode %(0)s']),
 
4808
            'nodecay':([], ['edit madspin_card --comment_line="decay"'])
4777
4809
            })
4778
4810
        self.special_shortcut_help.update({
4779
 
            'spinmode' : 'full|none|onshell. Choose the mode of madspin.\n   - full: spin-correlation and off-shell effect\n  - onshell: only spin-correlation,]\n  - none: no spin-correlation and not offshell effects.'
 
4811
            'spinmode' : 'full|none|onshell. Choose the mode of madspin.\n   - full: spin-correlation and off-shell effect\n  - onshell: only spin-correlation,]\n  - none: no spin-correlation and not offshell effects.',
 
4812
            'nodecay': 'remove all decay previously defined in madspin',
4780
4813
             })
4781
4814
        return []
4782
4815
    
5241
5274
    def do_set(self, line):
5242
5275
        """ edit the value of one parameter in the card"""
5243
5276
        
5244
 
        
 
5277
 
5245
5278
        args = self.split_arg(line)
5246
5279
        
5247
5280
        
5504
5537
                try:
5505
5538
                    key = tuple([int(i) for i in args[start+1:-1]])
5506
5539
                except ValueError:
5507
 
                    if args[start] == 'decay' and args[start+1:-1] == ['all']:
 
5540
                    if args[start+1:-1] == ['all']:
5508
5541
                        for key in self.param_card[args[start]].param_dict:
5509
5542
                            if (args[start], key) in self.restricted_value:
5510
5543
                                continue
5980
6013
                    self.do_set('shower_card extrapaths None ') 
5981
6014
                    
5982
6015
        # ensure that all cards are in sync
5983
 
        for key in list(self.modified_card):
5984
 
            self.write_card(key)
 
6016
        if self.writting_card:
 
6017
            for key in list(self.modified_card):
 
6018
                self.write_card(key)
5985
6019
 
5986
6020
 
5987
6021
    def reask(self, *args, **opt):
6107
6141
        self.run_card.write(self.paths['run'], self.paths['run_default'])
6108
6142
        
6109
6143
    def write_card_param(self):
6110
 
        """ write the param_card """        
 
6144
        """ write the param_card """    
 
6145
    
6111
6146
        self.param_card.write(self.paths['param'])
6112
6147
        
6113
6148
    @staticmethod
6492
6527
        logger.info( '     --before_line="<regular-expression>" write the line before the first line matching the regular expression')
6493
6528
        logger.info( '     --replace_line="<regular-expression>" replace the line matching the regular expression')
6494
6529
        logger.info( '     --clean remove all previously existing line in  the file')
 
6530
        logger.info( '     --comment_line="<regular-expression>"  comment all lines matching the regular expression')
6495
6531
        logger.info('')
6496
6532
        logger.info('    Note: all regular-expression will be prefixed by ^\s*')
6497
6533
        logger.info('')
6637
6673
                logger.info("Replacing the line \"%s\" [line %d of %s] by \"%s\"" %
6638
6674
                         (old_line, posline, card, new_line ),'$MG:BOLD') 
6639
6675
                self.last_editline_pos = posline               
6640
 
                                            
 
6676
 
 
6677
            elif args[1].startswith('--comment_line='):
 
6678
                # catch the line/regular expression and replace the associate line
 
6679
                # if no line match go to check if args[2] has other instruction starting with --
 
6680
                text = open(path).read()
 
6681
                split = text.split('\n')
 
6682
                search_pattern=r'''comment_line=(?P<quote>["'])(?:(?=(\\?))\2.)*?\1'''
 
6683
                pattern = '^\s*' + re.search(search_pattern, line).group()[14:-1]
 
6684
                nb_mod = 0
 
6685
                for posline,l in enumerate(split):
 
6686
                    if re.search(pattern, l):
 
6687
                        split[posline] = '#%s' % l
 
6688
                        nb_mod +=1
 
6689
                        logger.info("Commenting line \"%s\" [line %d of %s]" %
 
6690
                         (l, posline, card ),'$MG:BOLD') 
 
6691
                        # overwrite the previous line
 
6692
                if not nb_mod:
 
6693
                    logger.warning('no line commented (no line matching)')
 
6694
                ff = open(path,'w')
 
6695
                ff.write('\n'.join(split))
 
6696
 
 
6697
                self.last_editline_pos = posline               
 
6698
 
6641
6699
            
6642
6700
            elif args[1].startswith('--before_line='):
6643
6701
                # catch the line/regular expression and write before that line