~maddevelopers/mg5amcnlo/2.7.4_array

« back to all changes in this revision

Viewing changes to madgraph/interface/common_run_interface.py

  • Committer: olivier-mattelaer
  • Date: 2019-10-16 11:38:38 UTC
  • mfrom: (282.1.28 2.6.7)
  • Revision ID: olivier-mattelaer-20191016113838-6u4j5u3hn06rq2wc
pass to 2.6.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
1583
1583
        logger.info("   --start_id=       # define the starting digit for the additial weight. If not specify it is determine automatically")
1584
1584
        logger.info("   --only_beam=0     # only apply the new pdf set to the beam selected.")
1585
1585
        logger.info("   --ion_scaling=True# if original sample was using rescaled PDF: apply the same rescaling for all PDF sets.")
 
1586
        logger.info("   --weight_format=\"%(id)i\"  # allow to customise the name of the weight. The resulting name SHOULD be unique.")
 
1587
        logger.info("   --weight_info=  # allow to customise the text describing the weights.")
1586
1588
        logger.info("")
1587
1589
        logger.info("   Allowed value for the pdf options:", '$MG:BOLD')
1588
1590
        logger.info("       central  : Do not perform any pdf variation"    )
1601
1603
        logger.info("       id1,id2  : keep/remove all the weights between those two values --included--")
1602
1604
        logger.info("       PATTERN  : keep/remove all the weights matching the (python) regular expression.")
1603
1605
        logger.info("       note that multiple entry of those arguments are allowed")
 
1606
        logger.info("")
 
1607
        logger.info("   Input for weight format")
 
1608
        logger.info("     The parameter will be interpreted by python using: https://docs.python.org/2/library/stdtypes.html#string-formatting")
 
1609
        logger.info("     The allowed parameters are 'muf','mur','pdf','dyn','alps','id'") 
1604
1610
    def complete_systematics(self, text, line, begidx, endidx):
1605
1611
        """auto completion for the systematics command"""
1606
1612
 
1666
1672
 
1667
1673
        #check sanity of options
1668
1674
        if any(not o.startswith(('--mur=', '--muf=', '--alps=','--dyn=','--together=','--from_card','--pdf=',
1669
 
                                 '--remove_wgts=', '--keep_wgts','--start_id='))
 
1675
                                 '--remove_wgts=', '--keep_wgts','--start_id=', '--weight_format=',
 
1676
                                 '--weight_info='))
1670
1677
                for o in opts):
1671
1678
            raise self.InvalidCmd, "command systematics called with invalid option syntax. Please retry."
1672
1679
        
4122
4129
        """
4123
4130
 
4124
4131
        if not lhapdf_version:
4125
 
            lhapdf_version = subprocess.Popen([lhapdf_config, '--version'], 
4126
 
                        stdout = subprocess.PIPE).stdout.read().strip()
4127
 
                        
4128
 
                        
 
4132
            lhapdf_version = CommonRunCmd.get_lhapdf_version_static(lhapdf_config)
 
4133
 
4129
4134
        if not pdfsets_dir:
4130
 
            if 'LHAPATH' in os.environ:
4131
 
                for p in os.environ['LHAPATH'].split(':'):
4132
 
                    if os.path.exists(p):
4133
 
                        pdfsets_dir = p
4134
 
                        break
4135
 
                else:
4136
 
                    del os.environ['LHAPATH'] 
4137
 
                    pdfsets_dir = subprocess.Popen([lhapdf_config, '--datadir'], 
4138
 
                        stdout = subprocess.PIPE).stdout.read().strip()                    
4139
 
            else:
4140
 
                pdfsets_dir = subprocess.Popen([lhapdf_config, '--datadir'], 
4141
 
                        stdout = subprocess.PIPE).stdout.read().strip()
 
4135
            pdfsets_dir = CommonRunCmd.get_lhapdf_pdfsetsdir_static(lhapdf_config, lhapdf_version)
4142
4136
 
4143
4137
        if isinstance(filename, int):
4144
4138
            pdf_info = CommonRunCmd.get_lhapdf_pdfsets_list_static(pdfsets_dir, lhapdf_version)
4185
4179
           os.path.isdir(pjoin(pdfsets_dir, filename)):
4186
4180
            logger.info('%s successfully downloaded and stored in %s' \
4187
4181
                    % (filename, pdfsets_dir))
 
4182
            
4188
4183
        #otherwise (if v5) save it locally
4189
4184
        elif lhapdf_version.startswith('5.'):
4190
4185
            logger.warning('Could not download %s into %s. Trying to save it locally' \
4207
4202
               os.path.isdir(pjoin(pdfsets_dir, filename)):
4208
4203
                logger.info('%s successfully downloaded and stored in %s' \
4209
4204
                        % (filename, pdfsets_dir))  
 
4205
            elif 'LHAPDF_DATA_PATH' in os.environ and os.environ['LHAPDF_DATA_PATH']:
 
4206
                
 
4207
                if pdfsets_dir in os.environ['LHAPDF_DATA_PATH'].split(':'):
 
4208
                    lhapath = os.environ['LHAPDF_DATA_PATH'].split(':')
 
4209
                    lhapath = [p for p in lhapath if os.path.exists(p)]
 
4210
                    lhapath.remove(pdfsets_dir)
 
4211
                    os.environ['LHAPDF_DATA_PATH'] = ':'.join(lhapath)
 
4212
                    if lhapath:
 
4213
                        return CommonRunCmd.install_lhapdf_pdfset_static(lhapdf_config, None, 
 
4214
                                                              filename, 
 
4215
                                        lhapdf_version, alternate_path)
 
4216
                    elif 'LHAPATH' in os.environ and os.environ['LHAPATH']:
 
4217
                        return CommonRunCmd.install_lhapdf_pdfset_static(lhapdf_config, None, 
 
4218
                                                              filename, 
 
4219
                                        lhapdf_version, alternate_path)
 
4220
                    else:
 
4221
                        raise MadGraph5Error, \
 
4222
                'Could not download %s into %s. Please try to install it manually.' \
 
4223
                    % (filename, pdfsets_dir) 
 
4224
                else:
 
4225
                    return CommonRunCmd.install_lhapdf_pdfset_static(lhapdf_config, None, 
 
4226
                                                              filename, 
 
4227
                                        lhapdf_version, alternate_path)
4210
4228
            elif 'LHAPATH' in os.environ and os.environ['LHAPATH']:
4211
4229
                misc.sprint(os.environ['LHAPATH'], '-> retry')
4212
4230
                if pdfsets_dir in os.environ['LHAPATH'].split(':'):
4282
4300
 
4283
4301
        return lhapdf_pdfsets
4284
4302
 
 
4303
    @staticmethod
 
4304
    def get_lhapdf_version_static(lhapdf_config):
 
4305
        """returns the lhapdf version number"""
 
4306
 
 
4307
        try:
 
4308
            lhapdf_version = \
 
4309
                    subprocess.Popen([lhapdf_config, '--version'], 
 
4310
                        stdout = subprocess.PIPE).stdout.read().strip()
 
4311
        except OSError, error:
 
4312
            if error.errno == 2:
 
4313
                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']
 
4314
            else:
 
4315
                raise
 
4316
                
 
4317
        # this will be removed once some issues in lhapdf6 will be fixed
 
4318
        if lhapdf_version.startswith('6.0'):
 
4319
            raise MadGraph5Error('LHAPDF 6.0.x not supported. Please use v6.1 or later')
 
4320
        return lhapdf_version
 
4321
 
4285
4322
 
4286
4323
    def get_lhapdf_version(self):
4287
4324
        """returns the lhapdf version number"""
4288
4325
        if not hasattr(self, 'lhapdfversion'):
4289
 
            try:
4290
 
                self.lhapdf_version = \
4291
 
                    subprocess.Popen([self.options['lhapdf'], '--version'], 
4292
 
                        stdout = subprocess.PIPE).stdout.read().strip()
4293
 
            except OSError, error:
4294
 
                if error.errno == 2:
4295
 
                    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']
4296
 
                else:
4297
 
                    raise
4298
 
                
4299
 
        # this will be removed once some issues in lhapdf6 will be fixed
4300
 
        if self.lhapdf_version.startswith('6.0'):
4301
 
            raise MadGraph5Error('LHAPDF 6.0.x not supported. Please use v6.1 or later')
 
4326
            self.lhapdf_version = self.get_lhapdf_version_static(self.options['lhapdf'])
4302
4327
        return self.lhapdf_version
4303
4328
 
4304
 
 
4305
 
    def get_lhapdf_pdfsetsdir(self):
4306
 
        lhapdf_version = self.get_lhapdf_version()
 
4329
    @staticmethod
 
4330
    def get_lhapdf_pdfsetsdir_static(lhapdf_config, lhapdf_version=None):
 
4331
        """ """
 
4332
        if not lhapdf_version:
 
4333
            lhapdf_version = CommonRunCmd.get_lhapdf_version_static(lhapdf_config)
4307
4334
 
4308
4335
        # check if the LHAPDF_DATA_PATH variable is defined
4309
4336
        if 'LHAPDF_DATA_PATH' in os.environ.keys() and os.environ['LHAPDF_DATA_PATH']:
4310
4337
            datadir = os.environ['LHAPDF_DATA_PATH']
4311
4338
        elif lhapdf_version.startswith('5.'):
4312
 
            datadir = subprocess.Popen([self.options['lhapdf'], '--pdfsets-path'],
 
4339
            datadir = subprocess.Popen([lhapdf_config, '--pdfsets-path'],
4313
4340
                         stdout = subprocess.PIPE).stdout.read().strip()
4314
4341
 
4315
4342
        elif lhapdf_version.startswith('6.'):
4316
 
            datadir = subprocess.Popen([self.options['lhapdf'], '--datadir'],
 
4343
            datadir = subprocess.Popen([lhapdf_config, '--datadir'],
4317
4344
                         stdout = subprocess.PIPE).stdout.read().strip()
4318
4345
        
4319
4346
        if ':' in datadir:
4325
4352
        
4326
4353
        return datadir
4327
4354
 
 
4355
    def get_lhapdf_pdfsetsdir(self):
 
4356
        
 
4357
        lhapdf_version = self.get_lhapdf_version()
 
4358
        return self.get_lhapdf_pdfsetsdir_static(self.options['lhapdf'], lhapdf_version)
 
4359
 
4328
4360
    ############################################################################
4329
4361
    def get_Pdir(self):
4330
4362
        """get the list of Pdirectory if not yet saved."""