예제 #1
0
    def fromDPMDirectory(cls, name, directory, treeName = "Events", normalization = None, \
                selectionString = None, weightString = None,
                isData = False, color = 0, texName = None, maxN = None, noCheckProxy=False):

        import subprocess
        if not directory.startswith("/dpm"): raise ValueError( "DPM directory does not start with /dpm/: %s" % directory )

        # Renew proxy
        from RootTools.core.helpers import renew_proxy
        proxy_path = os.path.expandvars('$HOME/private/.proxy')
        if not noCheckProxy:
            proxy = renew_proxy(proxy_path)
        else:
            proxy = proxy_path
            logger.info("Not checking your proxy. Asuming you know it's still valid.")
        logger.info( "Using proxy %s"%proxy )

        p = subprocess.Popen(["dpns-ls -l %s" % directory], shell = True , stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        files = []
        for line in p.stdout.readlines():
                line = line[:-1]
                filename = line.split()[-1] # The filename is the last string of the output of dpns-ls
                if filename.endswith(".root"):
                    files.append( "root://hephyse.oeaw.ac.at/" + os.path.join( directory, filename ) )
                if maxN is not None and maxN>0 and len(files)>=maxN:
                    break
        sample =  cls(name = name, treeName = treeName, files = files, normalization = normalization, \
            selectionString = selectionString, weightString = weightString,
            isData = isData, color=color, texName = texName)
        logger.debug("Loaded sample %s from %i files.", name, len(files))
        return sample
예제 #2
0
    def fromDPMDirectory(cls, name, directory, redirector='root://hephyse.oeaw.ac.at/', treeName = "Events", normalization = None, xSection = -1, \
                selectionString = None, weightString = None,
                isData = False, color = 0, texName = None, maxN = None, noCheckProxy=False):

        # Work with directories and list of directories
        directories = [directory] if type(directory) == type("") else directory
        if not all([d.startswith("/dpm") for d in directories]):
            raise ValueError("DPM directories do not start with /dpm/")

        # If no name, enumerate them.
        if not name: name = new_name()

        # Renew proxy
        from RootTools.core.helpers import renew_proxy
        proxy_path = os.path.expandvars('$HOME/private/.proxy')
        if not noCheckProxy:
            proxy = renew_proxy(proxy_path)
        else:
            proxy = proxy_path
            logger.info(
                "Not checking your proxy. Asuming you know it's still valid.")
        logger.info("Using proxy %s" % proxy)

        files = []
        for d in directories:
            cmd = ["xrdfs", redirector, "ls", d]
            fileList = []
            for i in range(10):
                try:
                    fileList = [
                        file for file in subprocess.check_output(cmd).split(
                            "\n")[:-1]
                    ]
                    break
                except:
                    if i < 9: pass
            counter = 0
            for filename in fileList:
                if filename.endswith(".root"):
                    files.append(redirector + os.path.join(d, filename))
                    counter += 1
                if maxN is not None and maxN > 0 and len(files) >= maxN:
                    break
            if counter == 0:
                raise helpers.EmptySampleError(
                    "No root files found in directory %s." % d)

        sample =  cls(name = name, treeName = treeName, files = files, normalization = normalization, xSection = xSection,\
            selectionString = selectionString, weightString = weightString,
            isData = isData, color=color, texName = texName)
        logger.debug("Loaded sample %s from %i files.", name, len(files))
        return sample
예제 #3
0
    def fromDPMDirectory(cls, name, directory, treeName = "Events", normalization = None, xSection = -1, \
                selectionString = None, weightString = None,
                isData = False, color = 0, texName = None, maxN = None, noCheckProxy=False):

        # Work with directories and list of directories
        directories = [directory] if type(directory)==type("") else directory
        if not all([d.startswith("/dpm") for d in directories]): raise ValueError( "DPM directories do not start with /dpm/" )

        # Renew proxy
        from RootTools.core.helpers import renew_proxy
        proxy_path = os.path.expandvars('$HOME/private/.proxy')
        if not noCheckProxy:
            proxy = renew_proxy(proxy_path)
        else:
            proxy = proxy_path
            logger.info("Not checking your proxy. Asuming you know it's still valid.")
        logger.info( "Using proxy %s"%proxy )

        import subprocess

        files = []
        for d in directories:
            p = subprocess.Popen(["dpns-ls -l %s" % d], shell = True , stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
            for line in p.stdout.readlines():
                line = line[:-1]
                filename = line.split()[-1] # The filename is the last string of the output of dpns-ls
                if filename.endswith(".root"):
                    files.append( "root://hephyse.oeaw.ac.at/" + os.path.join( d, filename ) )
                if maxN is not None and maxN>0 and len(files)>=maxN:
                    break
            del p
        sample =  cls(name = name, treeName = treeName, files = files, normalization = normalization, xSection = xSection,\
            selectionString = selectionString, weightString = weightString,
            isData = isData, color=color, texName = texName)
        logger.debug("Loaded sample %s from %i files.", name, len(files))
        return sample
예제 #4
0
def make_batch_job(batch_job_file, batch_job_title, batch_output_dir, command):
    # If X509_USER_PROXY is set, use existing proxy.
    if options.dpm:
        if host == 'lxplus':
            from StopsDilepton.Tools.user import cern_proxy_certificate
            proxy_location = cern_proxy_certificate
        else:
            proxy_location = None

        from RootTools.core.helpers import renew_proxy
        proxy = renew_proxy(proxy_location)

        logger.info("Using proxy certificate %s", proxy)
        proxy_cmd = "export X509_USER_PROXY=%s" % proxy
    else:
        proxy_cmd = ""

    import subprocess

    if host == 'heplx':
        template =\
"""\
#!/bin/sh
#SBATCH -J {batch_job_title}
#SBATCH -D {pwd}
#SBATCH -o {batch_output_dir}batch-test.%j.out

{proxy_cmd}
voms-proxy-info -all
eval \`"scram runtime -sh"\` 
echo CMSSW_BASE: {cmssw_base} 
echo Executing user command  
echo "{command}"
{command} 

voms-proxy-info -all

""".format(\
                command          = command,
                cmssw_base       = os.getenv("CMSSW_BASE"),
                batch_output_dir = batch_output_dir,
                batch_job_title  = batch_job_title,
                pwd              = os.getenv("PWD"),
                proxy_cmd = proxy_cmd
              )
    elif host == 'lxplus':
        template =\
"""\
#!/bin/bash
export CMSSW_PROJECT_SRC={cmssw_base}/src

cd $CMSSW_PROJECT_SRC
eval `scramv1 ru -sh`

alias python={python_release}
which python
python --version

{proxy_cmd}
voms-proxy-info -all
echo CMSSW_BASE: $CMSSW_BASE
cd {pwd}
echo Executing user command while in $PWD
echo "{command}"
{command} 

voms-proxy-info -all

""".format(\
                command          = command,
                cmssw_base       = os.getenv("CMSSW_BASE"),
                #batch_output_dir = batch_output_dir,
                #batch_job_title  = batch_job_title,
                pwd              = os.getenv("PWD"),
                proxy_cmd = proxy_cmd,
                python_release = subprocess.check_output(['which', 'python']).rstrip(),
              )

    batch_job = file(batch_job_file, "w")
    batch_job.write(template)
    batch_job.close()
    return
예제 #5
0
    def __init__(self,
                 heppy_samples,
                 dpm_directories,
                 cache_file,
                 multithreading=True):
        # Read cache file, if exists
        if os.path.exists(cache_file) and not overwrite:
            self.sample_map = pickle.load(file(cache_file))
            logger.info("Loaded cache file %s" % cache_file)
        else:
            logger.info("Cache file %s not found. Recreate map.", cache_file)
            logger.info("Check proxy.")

            # Proxy certificate
            from RootTools.core.helpers import renew_proxy
            # Make proxy in afs to allow batch jobs to run
            proxy_path = os.path.expandvars('$HOME/private/.proxy')
            proxy = renew_proxy(proxy_path)
            logger.info("Using proxy %s" % proxy)

            # Read dpm directories
            self.cmg_directories = {}
            for data_path in dpm_directories:
                logger.info("Walking dpm directory %s", data_path)
                walker = walk_dpm(data_path)
                self.cmg_directories[
                    data_path] = walker.walk_dpm_cmgdirectories('.', maxN=maxN)

                #del walker

            logger.info("Now mapping directories to heppy samples")
            for heppy_sample in heppy_samples:
                heppy_sample.candidate_directories = []
                pd, era = heppy_sample.dataset.split('/')[1:3]
                for data_path in self.cmg_directories.keys():
                    for dpm_directory in self.cmg_directories[data_path].keys(
                    ):
                        if not ('/%s/' % pd in dpm_directory):
                            logger.debug("/%s/ not in dpm_directory %s", pd,
                                         dpm_directory)
                            continue
                        if not ('/' + era in dpm_directory):
                            logger.debug("/%s not in dpm_directory %s", era,
                                         dpm_directory)
                            continue
                        heppy_sample.candidate_directories.append(
                            [data_path, dpm_directory])
                        logger.debug("heppy sample %s in %s",
                                     heppy_sample.name, dpm_directory)
                logger.info("Found heppy sample %s in %i directories.",
                            heppy_sample.name,
                            len(heppy_sample.candidate_directories))

            # Merge
            from RootTools.core.Sample import Sample
            logger.info(
                "Now making new sample map from %i directories and for %i heppy samples to be stored in %s",
                len(dpm_directories), len(heppy_samples), cache_file)
            self.sample_map = {}
            for heppy_sample in heppy_samples:
                if len(heppy_sample.candidate_directories) == 0:
                    logger.info("No directory found for %s", heppy_sample.name)
                else:
                    normalization, files = walker.combine_cmg_directories(\
                            cmg_directories = {dpm_directory:self.cmg_directories[data_path][dpm_directory] for data_path, dpm_directory in heppy_sample.candidate_directories },
                            multithreading = multithreading,
                        )
                    logger.info(
                        "Sample %s: Found a total of %i files with normalization %3.2f",
                        heppy_sample.name, len(files), normalization)
                    tmp_files = []
                    for f in files:
                        isGoodFile = False
                        try:
                            isGoodFile = checkRootFile(
                                "root://hephyse.oeaw.ac.at/" + os.path.join(f))
                            logger.debug("File %s got added", f)
                        except IOError:
                            logger.info("File %s is corrupted, skipping", f)
                        if isGoodFile: tmp_files.append(f)
                    self.sample_map[heppy_sample] = Sample.fromFiles(
                        heppy_sample.name,
                        files=[
                            'root://hephyse.oeaw.ac.at/' + f for f in tmp_files
                        ],
                        normalization=normalization,
                        treeName='tree',
                        isData=heppy_sample.isData,
                        maxN=maxN)

                    logger.info(
                        "Combined %i directories for sample %s to a total of %i files with normalization %3.2f",
                        len(heppy_sample.candidate_directories),
                        heppy_sample.name, len(files), normalization)

            # Store cache file
            dir_name = os.path.dirname(cache_file)
            if len(self.sample_map.keys()) > 0:
                if not os.path.exists(dir_name): os.makedirs(dir_name)
                pickle.dump(self.sample_map, file(cache_file, 'w'))
                logger.info("Created MC sample cache %s", cache_file)
            else:
                logger.info("Skipping to write %s because map is empty.",
                            cache_file)
예제 #6
0
    def from_heppy_samplename(self, heppy_samplename, maxN=-1):
        for heppy_sample in self.sample_map.keys():
            if heppy_samplename == heppy_sample.name:
                res = self.sample_map[heppy_sample]
                if maxN > 0: res.files = res.files[:maxN]
                res.heppy = heppy_sample
                return res


# Proxy certificate
from RootTools.core.helpers import renew_proxy
# Make proxy in afs to allow batch jobs to run
proxy_path = os.path.expandvars('$HOME/private/.proxy')
if not forceProxy:
    proxy = renew_proxy(proxy_path)
else:
    logger.info("Not checking your proxy. Asuming you know it's still valid.")
    proxy = proxy_path
logger.info("Using proxy %s" % proxy)

## Data 2016, 03Feb2017
#data_cache_file = '/afs/hephy.at/data/dspitzbart01/TopEFT/dpm_sample_caches/Run2016_data_2016_1l_v1_2.pkl'
#robert_2016_1l_v1 = ['/dpm/oeaw.ac.at/home/cms/store/user/schoef/cmgTuples/2016_1l_v1']
#data_dpm_directories = robert_2016_1l_v1
#from CMGTools.RootTools.samples.samples_13TeV_DATA2016 import dataSamples as heppy_data_samples
#data_03Feb2017_heppy_mapper = heppy_mapper( heppy_data_samples, data_dpm_directories , data_cache_file, multithreading=multithreading)

# Data 2016, 07Aug17
data_cache_file = '/afs/hephy.at/data/dspitzbart01/TopEFT/dpm_sample_caches/Run2016_data_2016_1l_v14_2.pkl'
daniel_2016_1l_v13 = [
예제 #7
0
파일: walk_dpm.py 프로젝트: schoef/TopEFT
                    if job[0] == jobID:
                        logger.error("Duplicate %i %r", counter, job)
                raise RuntimeError(
                    "Found multiple instances of job %i with different normalizations!"
                    % jobID)
        files = []
        normalization = 0.
        for jobID in all_jobIDs:
            jobID_, file_, normalization_ = next(tup for tup in all_jobs
                                                 if tup[0] == jobID)
            if normalization_ is not None:
                normalization += normalization_
                files.append(file_)

        return normalization, files


if __name__ == "__main__":

    from RootTools.core.helpers import renew_proxy
    proxy = renew_proxy()
    logger.info("Using proxy %s" % proxy)

    import TopEFT.Tools.logger as logger
    logger = logger.get_logger('DEBUG')

    walker = walk_dpm(
        '/dpm/oeaw.ac.at/home/cms/store/user/schoef/cmgTuples/80X_2/JetHT')
    cmg_directories = walker.walk_dpm_cmgdirectories(
        '.', maxN=1, path_substrings=['Run2016B'])
예제 #8
0
def fromHeppySample(sample,
                    data_path,
                    module=None,
                    maxN=None,
                    MCgeneration="Summer16"):
    ''' Load CMG tuple from local directory
    '''

    import importlib
    if module is not None:
        module_ = module
    elif "Run2016" in sample:
        module_ = 'CMGTools.RootTools.samples.samples_13TeV_DATA2016'
    elif "Run2017" in sample:
        module_ = 'CMGTools.RootTools.samples.samples_13TeV_DATA2017'
    elif "ttZ0j_ll" in sample or "ttGamma0j_ll" in sample:
        module_ = 'CMGTools.StopsDilepton.ttX0j_5f_MLM_signals_RunIISummer16MiniAODv2'
    elif "ewkDM" in sample:
        module_ = 'CMGTools.StopsDilepton.ewkDM_signals_RunIISummer16MiniAODv2'
    else:
        if MCgeneration == "Summer17":
            module_ = 'CMGTools.RootTools.samples.samples_13TeV_RunIISummer17MiniAODv2'
        elif MCgeneration == "Fall17":
            module_ = 'CMGTools.RootTools.samples.samples_13TeV_RunIIFall17MiniAODv2'
        else:
            module_ = 'CMGTools.RootTools.samples.samples_13TeV_RunIISummer16MiniAODv2'

    try:
        heppy_sample = getattr(importlib.import_module(module_), sample)
    except:
        raise ValueError("Could not load sample '%s' from %s " %
                         (sample, module_))

    subDir = getSubDir(heppy_sample.dataset, data_path)
    if not subDir:
        raise ValueError("Not a good dataset name: '%s'" %
                         heppy_sample.dataset)

    path = os.path.join(data_path, subDir)
    from TopEFT.Tools.user import runOnGentT2
    if runOnGentT2:
        sample = Sample.fromCMGCrabDirectory(heppy_sample.name,
                                             path,
                                             treeFilename='tree.root',
                                             treeName='tree',
                                             isData=heppy_sample.isData,
                                             maxN=maxN)
    else:  # Vienna -> Load from DPM
        if True:  #'/dpm' in data_path:

            from RootTools.core.helpers import renew_proxy
            user = os.environ['USER']
            # Make proxy in afs to allow batch jobs to run
            proxy_path = os.path.expandvars('$HOME/private/.proxy')
            proxy = renew_proxy(proxy_path)
            logger.info("Using proxy %s" % proxy)

            if module is not None:
                module_ = module
            if "Run2016" in sample:
                from TopEFT.samples.heppy_dpm_samples import data_03Feb2017_heppy_mapper as data_heppy_mapper
                return data_heppy_mapper.from_heppy_samplename(
                    heppy_sample.name, maxN=maxN)
            elif "Run2017" in sample:
                from TopEFT.samples.heppy_dpm_samples import data_Run2017_heppy_mapper as data_Run2017_heppy_mapper
                return data_Run2017_heppy_mapper.from_heppy_samplename(
                    heppy_sample.name, maxN=maxN)
            elif "Summer17" in heppy_sample.dataset:
                from TopEFT.samples.heppy_dpm_samples import Summer17_heppy_mapper
                return Summer17_heppy_mapper.from_heppy_samplename(
                    heppy_sample.name, maxN=maxN)
            elif "Fall17" in heppy_sample.dataset:
                from TopEFT.samples.heppy_dpm_samples import Fall17_heppy_mapper
                return Fall17_heppy_mapper.from_heppy_samplename(
                    heppy_sample.name, maxN=maxN)
            elif "ttZ0j_ll" in sample or "ttGamma0j_ll" in sample:
                from TopEFT.samples.heppy_dpm_samples import signal_0j_0l_heppy_mapper
                return signal_0j_0l_heppy_mapper.from_heppy_samplename(
                    heppy_sample.name, maxN=maxN)
            elif "TTZToLL_LO" in sample:
                from TopEFT.samples.heppy_dpm_samples import signal_madspin_heppy_mapper
                return signal_madspin_heppy_mapper.from_heppy_samplename(
                    heppy_sample.name, maxN=maxN)
            elif "ewkDM" in sample:
                from TopEFT.samples.heppy_dpm_samples import signal_heppy_mapper
                return signal_heppy_mapper.from_heppy_samplename(
                    heppy_sample.name, maxN=maxN)
            else:
                from TopEFT.samples.heppy_dpm_samples import mc_heppy_mapper
                return mc_heppy_mapper.from_heppy_samplename(heppy_sample.name,
                                                             maxN=maxN)
            raise ValueError
        else:
            sample = Sample.fromCMGOutput(heppy_sample.name,
                                          path,
                                          treeFilename='tree.root',
                                          treeName='tree',
                                          isData=heppy_sample.isData,
                                          maxN=maxN)

    sample.heppy = heppy_sample
    return sample
예제 #9
0
        prepareTokens()

    if not len(args) == 1:
        raise Exception(
            "Only one argument accepted! Instead this was given: %s" % args)

    # If X509_USER_PROXY is set, use existing proxy.
    if options.dpm:
        if hostname.startswith("lxplus"):
            from Analysis.Tools.user import cern_proxy_certificate
            proxy_location = cern_proxy_certificate
        else:
            proxy_location = None

        from RootTools.core.helpers import renew_proxy
        proxy = renew_proxy(proxy_location)

        logger.info("Using proxy certificate %s", proxy)
        os.system("export X509_USER_PROXY=%s" % proxy)

    # load file with commands
    if os.path.isfile(args[0]):
        commands = []
        with open(args[0]) as f:
            for line in f.xreadlines():
                commands.extend(getCommands(line.rstrip("\n")))

    # or just the one command
    elif type(args[0]) == type(""):
        commands = getCommands(args[0])
예제 #10
0
def fromHeppySample(sample, data_path, module = None, maxN = None):
    ''' Load CMG tuple from local directory
    '''

    import importlib
    if module is not None:
        module_ = module
    elif "Run2016" in sample:
        module_ = 'CMGTools.RootTools.samples.samples_13TeV_DATA2016'
        #module_ = 'CMGTools.StopsDilepton.samples_13TeV_Moriond2017'
    elif ("T2tt" in sample) or ("T2bt" in sample) or ("T2bW" in sample):
        module_ = 'CMGTools.RootTools.samples.samples_13TeV_signals'
    elif "T8bbllnunu" in sample:
        module_ = 'CMGTools.RootTools.samples.samples_13TeV_signals'
    elif "TTbarDM" in sample:
        module_ = 'CMGTools.StopsDilepton.TTbarDMJets_signals_RunIISummer16MiniAODv2'
    elif "HToInv" in sample:
        module_ = 'CMGTools.StopsDilepton.Higgs_signals_RunIISummer16MiniAODv2'
    else: 
        module_ = 'CMGTools.RootTools.samples.samples_13TeV_RunIISummer16MiniAODv2'

    try:
        heppy_sample = getattr(importlib.import_module( module_ ), sample)
    except:
        raise ValueError( "Could not load sample '%s' from %s "%( sample, module_ ) )

    subDir = getSubDir(heppy_sample.dataset, data_path)
    if not subDir:
        raise ValueError( "Not a good dataset name: '%s'"%heppy_sample.dataset )

    path = os.path.join( data_path, subDir )
    from StopsDilepton.tools.user import runOnGentT2
    if runOnGentT2: 
        sample = Sample.fromCMGCrabDirectory(
            heppy_sample.name, 
            path, 
            treeFilename = 'tree.root', 
            treeName = 'tree', isData = heppy_sample.isData, maxN = maxN)
    else:  # Vienna -> Load from DPM 
        if True: #'/dpm' in data_path:

            from RootTools.core.helpers import renew_proxy
            user = os.environ['USER']
            # Make proxy in afs to allow batch jobs to run
            proxy_path = os.path.expandvars('$HOME/private/.proxy')
            proxy = renew_proxy( proxy_path )
            logger.info( "Using proxy %s"%proxy )

            if module is not None:
                module_ = module
            if "Run2016" in sample:
                from StopsDilepton.samples.heppy_dpm_samples import data_03Feb2017_heppy_mapper as data_heppy_mapper
                return data_heppy_mapper.from_heppy_samplename(heppy_sample.name, maxN = maxN)
            elif ("T2tt" in sample) or ("T8bb" in sample) or ("T2b" in sample):
                from StopsDilepton.samples.heppy_dpm_samples import SUSY_heppy_mapper
                return SUSY_heppy_mapper.from_heppy_samplename(heppy_sample.name, maxN = maxN)
            elif "TTbarDM" in sample:
                from StopsDilepton.samples.heppy_dpm_samples import ttbarDM_heppy_mapper
                return ttbarDM_heppy_mapper.from_heppy_samplename(heppy_sample.name, maxN = maxN)
            elif "HToInv" in sample:
                from StopsDilepton.samples.heppy_dpm_samples import Higgs_heppy_mapper
                return Higgs_heppy_mapper.from_heppy_samplename(heppy_sample.name, maxN = maxN)
            else: 
                from StopsDilepton.samples.heppy_dpm_samples import mc_heppy_mapper
                return mc_heppy_mapper.from_heppy_samplename(heppy_sample.name, maxN = maxN)
            raise ValueError
        else:                           
            sample = Sample.fromCMGOutput(
                heppy_sample.name, 
                path, 
                treeFilename = 'tree.root', 
                treeName = 'tree', isData = heppy_sample.isData, maxN = maxN)

    sample.heppy = heppy_sample
    return sample
예제 #11
0
def make_batch_job( batch_job_file, batch_job_title, batch_output_dir , command ):
    # If X509_USER_PROXY is set, use existing proxy.
    if options.dpm:
        if host == 'lxplus':
            from JetMET.tools.user import cern_proxy_certificate
            proxy_location = cern_proxy_certificate
        else:
            proxy_location = None

        from RootTools.core.helpers import renew_proxy
        proxy = renew_proxy( proxy_location )

        logger.info( "Using proxy certificate %s", proxy )
        proxy_cmd = "export X509_USER_PROXY=%s"%proxy
    else:
        proxy_cmd = ""            

    import subprocess

    if host == 'heplx':
        template =\
"""\
#!/bin/sh
#SBATCH -J {batch_job_title}
#SBATCH -D {pwd}
#SBATCH -o {batch_output_dir}batch-test.%j.out

{proxy_cmd}
voms-proxy-info -all
eval \`"scram runtime -sh"\` 
echo CMSSW_BASE: {cmssw_base} 
echo Executing user command  
echo "{command}"
{command} 

voms-proxy-info -all

""".format(\
                command          = command,
                cmssw_base       = os.getenv("CMSSW_BASE"),
                batch_output_dir = batch_output_dir,
                batch_job_title  = batch_job_title,
                pwd              = os.getenv("PWD"),
                proxy_cmd = proxy_cmd
              )
    elif host == 'lxplus':
        template =\
"""\
#!/bin/bash
export CMSSW_PROJECT_SRC={cmssw_base}/src

cd $CMSSW_PROJECT_SRC
eval `scramv1 ru -sh`

alias python={python_release}
which python
python --version

{proxy_cmd}
voms-proxy-info -all
echo CMSSW_BASE: $CMSSW_BASE
cd {pwd}
echo Executing user command while in $PWD
echo "{command}"
{command} 

voms-proxy-info -all

""".format(\
                command          = command,
                cmssw_base       = os.getenv("CMSSW_BASE"),
                #batch_output_dir = batch_output_dir,
                #batch_job_title  = batch_job_title,
                pwd              = os.getenv("PWD"),
                proxy_cmd = proxy_cmd,
                python_release = subprocess.check_output(['which', 'python']).rstrip(), 
              )

    batch_job = file(batch_job_file, "w")
    batch_job.write(template)
    batch_job.close()
    return
예제 #12
0
def fromHeppySample(sample,
                    data_path,
                    module=None,
                    force_sample_map=None,
                    maxN=None,
                    MCgeneration="Summer16",
                    forceProxy=False):
    ''' Load CMG tuple from local directory
    '''

    import importlib
    if module is not None:
        module_ = module
    elif "Run2016" in sample:
        module_ = 'CMGTools.RootTools.samples.samples_13TeV_DATA2016'
    elif "Run2017" in sample:
        module_ = 'CMGTools.RootTools.samples.samples_13TeV_DATA2017'
    elif "ttZ0j_ll" in sample or "ttGamma0j_ll" in sample:
        module_ = 'CMGTools.StopsDilepton.ttX0j_5f_MLM_signals_RunIISummer16MiniAODv2'
    elif "ewkDM" in sample or sample.startswith('yt_') or sample.startswith(
            'dim6top_'):
        module_ = 'CMGTools.StopsDilepton.ewkDM_signals_RunIISummer16MiniAODv2'
    else:
        if MCgeneration == "Summer17":
            module_ = 'CMGTools.RootTools.samples.samples_13TeV_RunIISummer17MiniAODv2'
        elif MCgeneration == "Fall17":
            module_ = 'CMGTools.RootTools.samples.samples_13TeV_RunIIFall17MiniAOD'
        else:
            module_ = 'CMGTools.RootTools.samples.samples_13TeV_RunIISummer16MiniAODv2'

    try:
        heppy_sample = getattr(importlib.import_module(module_), sample)
    except:
        raise ValueError("Could not load sample '%s' from %s " %
                         (sample, module_))

    subDir = getSubDir(heppy_sample.dataset, data_path)
    if not subDir:
        raise ValueError("Not a good dataset name: '%s'" %
                         heppy_sample.dataset)

    path = os.path.join(data_path, subDir)

    from RootTools.core.helpers import renew_proxy
    user = os.environ['USER']
    # Make proxy in afs to allow batch jobs to run
    proxy_path = os.path.expandvars('$HOME/private/.proxy')
    if not forceProxy:
        proxy = renew_proxy(proxy_path)
    else:
        proxy = proxy_path
        logger.info(
            "Not checking your proxy. Asuming you know it's still valid.")
    logger.info("Using proxy %s" % proxy)
    if force_sample_map is not None:
        mapper = getattr(
            importlib.import_module('TopEFT.samples.heppy_dpm_samples'),
            force_sample_map)
        return mapper.from_heppy_samplename(heppy_sample.name, maxN=maxN)
    if "07Aug17" in sample:
        from TopEFT.samples.heppy_dpm_samples import data_07Aug17_heppy_mapper as data_heppy_mapper
        return data_heppy_mapper.from_heppy_samplename(heppy_sample.name,
                                                       maxN=maxN)
    elif "03Feb2017" in sample:
        from TopEFT.samples.heppy_dpm_samples import data_03Feb2017_heppy_mapper as data_heppy_mapper
        return data_heppy_mapper.from_heppy_samplename(heppy_sample.name,
                                                       maxN=maxN)
    elif "Run2017" in sample:
        from TopEFT.samples.heppy_dpm_samples import data_Run2017_heppy_mapper as data_Run2017_heppy_mapper
        return data_Run2017_heppy_mapper.from_heppy_samplename(
            heppy_sample.name, maxN=maxN)
    elif "Summer17" in heppy_sample.dataset:
        from TopEFT.samples.heppy_dpm_samples import Summer17_heppy_mapper
        return Summer17_heppy_mapper.from_heppy_samplename(heppy_sample.name,
                                                           maxN=maxN)
    elif "Fall17" in heppy_sample.dataset:
        from TopEFT.samples.heppy_dpm_samples import Fall17_heppy_mapper
        return Fall17_heppy_mapper.from_heppy_samplename(heppy_sample.name,
                                                         maxN=maxN)
    elif "ttZ0j_ll" in sample or "ttGamma0j_ll" in sample:
        from TopEFT.samples.heppy_dpm_samples import signal_0j_0l_heppy_mapper
        return signal_0j_0l_heppy_mapper.from_heppy_samplename(
            heppy_sample.name, maxN=maxN)
    elif "TTZToLL_LO" in sample:
        from TopEFT.samples.heppy_dpm_samples import signal_madspin_heppy_mapper
        return signal_madspin_heppy_mapper.from_heppy_samplename(
            heppy_sample.name, maxN=maxN)
    elif "ewkDM" in sample:
        from TopEFT.samples.heppy_dpm_samples import signal_heppy_mapper
        return signal_heppy_mapper.from_heppy_samplename(heppy_sample.name,
                                                         maxN=maxN)
    elif sample.startswith('yt_') or sample.startswith('dim6top_'):
        from TopEFT.samples.heppy_dpm_samples import eft_2016_heppy_mapper
        return eft_2016_heppy_mapper.from_heppy_samplename(heppy_sample.name,
                                                           maxN=maxN)
    else:
        from TopEFT.samples.heppy_dpm_samples import mc_heppy_mapper
        return mc_heppy_mapper.from_heppy_samplename(heppy_sample.name,
                                                     maxN=maxN)
    raise ValueError