Beispiel #1
0
 def __init__(self,config):
     self.samples = []
     self.config = BetterConfigParser()
     self.config.read(config)
     for section in self.config.sections():
         # empty object :)
         self.samples.append(sample())
         setattr(self.samples[-1],'id',section)
         for key, value in self.config.items(section):
             setattr(self.samples[-1],key,value)
Beispiel #2
0
class samples(object):
    def __init__(self,config):
        self.samples = []
        self.config = BetterConfigParser()
        self.config.read(config)
        for section in self.config.sections():
            # empty object :)
            self.samples.append(sample())
            setattr(self.samples[-1],'id',section)
            for key, value in self.config.items(section):
                setattr(self.samples[-1],key,value)

    def __getattr__(self, key):
        l = []
        for x in self.samples:
            l.append((getattr(x,key),x))
        def_dict = defaultdict(list)
        for k,v in l:
            def_dict[k].append(v)
        return def_dict

    def __getitem__(self, key):
        return [getattr(x,key) for x in self.samples]
Beispiel #3
0
    @property
    def n_cols(self):
        return self._roc_list[0].n_cols

    @property
    def n_rows(self):
        return self._roc_list[0].n_rows

    def dacs(self):
        return self._roc_list[0].dacs()


if __name__ == "__main__":
    from BetterConfigParser import BetterConfigParser

    config = BetterConfigParser()
    config.read("../data/module")
    logging.basicConfig(level=logging.INFO)
    # make a module from config
    m = DUT(config)

    # access a single pixel
    print m.roc(0).pixel(12, 13)
    # or
    print m.pixel(0, 12, 13)
    print m.pixel(0, 12, 13).trim

    print m.roc(0).dac("Vana")
    # iterate
    for roc in m.rocs():
        roc.dac("Vana").value = 155
Beispiel #4
0
                  default="",
                  help="samples you want to run on")
parser.add_option("-s",
                  "--mergesys",
                  dest="mergesys",
                  default="False",
                  help="merge singlesys step")
parser.add_option("-e",
                  "--mergeeval",
                  dest="mergeeval",
                  default="False",
                  help="merge singleeval step")

(opts, args) = parser.parse_args(argv)

config = BetterConfigParser()
config.read(opts.config)

namelist = opts.names.split(',')
print "namelist:", namelist

if opts.mergesys == 'True':
    pathIN = config.get('Directories', 'SYSin')
    pathOUT = config.get('Directories', 'SYSout')
elif opts.mergeeval == 'True':
    pathIN = config.get('Directories', 'MVAin')
    pathOUT = config.get('Directories', 'MVAout')
else:
    pathIN = config.get('Directories', 'PREPin')
    pathOUT = config.get('Directories', 'PREPout')
Beispiel #5
0
    def __init__(self,samples_config,samples_path):
        try:
            os.stat(samples_config)
        except:
            raise Exception('config file is wrong/missing')
          
        if '/pnfs/psi.ch/cms/' in samples_path:
            T3 = True
            _,p2=samples_path.split('/pnfs/')
            t3_path = '/pnfs/'+p2.strip('\n')
        else:
            T3 = False

        config = BetterConfigParser()
        config.read(samples_config)

        newprefix=config.get('General','newprefix')
        lumi=float(config.get('General','lumi'))
        weightexpression=config.get('General','weightexpression')

        self._samplelist = []

        self.__fileslist=[]
        # print 'T3',T3,'samples_path',samples_path,'t3_path',t3_path
        if T3:
            # ls = os.popen("lcg-ls -b -D srmv2 -l srm://t3se01.psi.ch:8443/srm/managerv2?SFN="+t3_path)
            ls = os.popen("ls "+t3_path)
        else:
            ls = os.popen("ls "+samples_path)
    
        for line in ls.readlines():
                if('.root' in line):
                        truncated_line = line[line.rfind('/')+1:]
                        _p = findnth(truncated_line,'.',2)
                        self.__fileslist.append(truncated_line[_p+1:truncated_line.rfind('.')])

        print '@DEBUG: ' + str(self.__fileslist)

        run_on_fileList = eval(config.get('Samples_running','run_on_fileList'))

        if( not test_samples(run_on_fileList,self.__fileslist,config.sections()) ): # stop if it finds None as sample
                sys.exit('@ERROR: Sample == None. Check RunOnFileList flag in section General, the sample_config of the sample directory.')

        for _listed_file,_config_entry in map(None,self.__fileslist,config.sections()):
            if( run_on_fileList ): 
                _sample = _listed_file
                self._list = self.__fileslist
            else:
                _sample = _config_entry
                self._list = config.sections()

            sample = self.checkSplittedSample(_sample)
            print 'sample',sample
            if not config.has_option(sample,'infile'): continue
            infile = _sample
            sampleName = config.get(sample,'sampleName')
            
            check_correspondency(sample,self._list,config)                    
            
            #Initialize samplecalss element
            sampleType = config.get(sample,'sampleType')
            cut = config.get(sample, 'cut')
            newsample = Sample(sampleName,sampleType)

            newsample.addtreecut = cut
            newsample.identifier=infile
            newsample.weightexpression=weightexpression
            newsample.lumi=lumi
            newsample.prefix=newprefix
            
            if eval(config.get(sample,'subsamples')):
                subnames = eval((config.get(sample, 'subnames')))
                subcuts = eval((config.get(sample, 'subcuts')))
                subgroups = eval((config.get(sample,'sampleGroup')))
                if sampleType != 'DATA':
                    subxsecs = eval((config.get(sample, 'xSec')))
                    subsfs = eval((config.get(sample, 'SF')))
                newsamples = []
                for i,cut in enumerate(subcuts):
                    newsubsample = copy(newsample)
                    newsubsample.subsample = True
                    newsubsample.name = subnames[i]
                    newsubsample.subcut = subcuts[i]
                    newsubsample.group = subgroups[i]
                    if sampleType != 'DATA':
                        newsubsample.sf = float(subsfs[i])
                        newsubsample.xsec = float(subxsecs[i])
                    newsamples.append(newsubsample)
                self._samplelist.extend(newsamples)
                self._samplelist.append(newsample)
            else:
                if sampleType != 'DATA':
                    newsample.xsec = eval((config.get(sample,'xSec')))    
                    newsample.sf = eval((config.get(sample, 'SF')))
                newsample.group = config.get(sample,'sampleGroup')
                self._samplelist.append(newsample)
Beispiel #6
0
#! /usr/bin/env python

import sys
import re
from BetterConfigParser import BetterConfigParser

config = BetterConfigParser()
config.read('samples_nosplit.ini')

for arg in sys.argv[1:]:
    expr = config.get(arg, 'xSec').replace('[', '(').replace(']', ')')
    # Make sure input is sanitary
    if re.match(r'[\d\(\)\=\-\*\/\.]*', expr):
        print eval(expr)
Beispiel #7
0
                      "--task",
                      dest="task",
                      default="",
                      help="task (prep, sys, eval, plot) to be checked")
    parser.add_option("-f",
                      "--filelist",
                      dest="filelist",
                      default="",
                      help="list of files you want to run on")

    (opts, args) = parser.parse_args(argv)

    vhbbPlotDef = opts.config[0].split('/')[0] + '/vhbbPlotDef.ini'
    opts.config.append(vhbbPlotDef)  #adds it to the config list

    config = BetterConfigParser()
    config.read(opts.config)

    samplesinfo = config.get('Directories', 'samplesinfo')
    sampleconf = BetterConfigParser()
    sampleconf.read(samplesinfo)

    # if opts.filelist != '': print 'filelist NOT NULL!'

    if opts.task == 'checksingleprep':
        pathOUT_orig = config.get('Directories', 'PREPout')
    elif opts.task == 'checksinglesys':
        pathOUT_orig = config.get('Directories', 'SYSout')
    elif opts.task == 'checksingleeval':
        pathOUT_orig = config.get('Directories', 'MVAout')
    elif opts.task == 'checksingleplot':
Beispiel #8
0
    def __init__(self, samples_config, samples_path):
        try:
            os.stat(samples_config)
        except:
            raise Exception('config file is wrong/missing')

        if '/pnfs/psi.ch/cms/' in samples_path:
            T3 = True
            _, p2 = samples_path.split('/pnfs/')
            t3_path = '/pnfs/' + p2.strip('\n')
        else:
            T3 = False

        config = BetterConfigParser()
        config.read(samples_config)

        newprefix = config.get('General', 'newprefix')
        lumi = float(config.get('General', 'lumi'))
        weightexpression = config.get('General', 'weightexpression')

        self._samplelist = []

        self.__fileslist = []
        if T3:
            ls = os.popen(
                "lcg-ls -b -D srmv2 -l srm://t3se01.psi.ch:8443/srm/managerv2?SFN="
                + t3_path)
        else:
            ls = os.popen("ls -l " + samples_path)

        for line in ls.readlines():
            if ('.root' in line):
                truncated_line = line[line.rfind('/') + 1:]
                _p = findnth(truncated_line, '.', 2)
                self.__fileslist.append(
                    truncated_line[_p + 1:truncated_line.rfind('.')])

        print '@DEBUG: ' + str(self.__fileslist)

        run_on_fileList = eval(config.get('Samples_running',
                                          'run_on_fileList'))

        if (not test_samples(
                run_on_fileList, self.__fileslist,
                config.sections())):  # stop if it finds None as sample
            sys.exit(
                '@ERROR: Sample == None. Check RunOnFileList flag in section General, the sample_config of the sample directory.'
            )

        for _listed_file, _config_entry in map(None, self.__fileslist,
                                               config.sections()):
            if (run_on_fileList):
                _sample = _listed_file
                self._list = self.__fileslist
            else:
                _sample = _config_entry
                self._list = config.sections()

            sample = self.checkSplittedSample(_sample)
            if not config.has_option(sample, 'infile'): continue
            infile = _sample
            sampleName = config.get(sample, 'sampleName')

            check_correspondency(sample, self._list, config)

            #Initialize samplecalss element
            sampleType = config.get(sample, 'sampleType')
            cut = config.get(sample, 'cut')
            newsample = Sample(sampleName, sampleType)

            newsample.addtreecut = cut
            newsample.identifier = infile
            newsample.weightexpression = weightexpression
            newsample.lumi = lumi
            newsample.prefix = newprefix

            if eval(config.get(sample, 'subsamples')):
                subnames = eval((config.get(sample, 'subnames')))
                subcuts = eval((config.get(sample, 'subcuts')))
                subgroups = eval((config.get(sample, 'sampleGroup')))
                if sampleType != 'DATA':
                    subxsecs = eval((config.get(sample, 'xSec')))
                    subsfs = eval((config.get(sample, 'SF')))
                newsamples = []
                for i, cut in enumerate(subcuts):
                    newsubsample = copy(newsample)
                    newsubsample.subsample = True
                    newsubsample.name = subnames[i]
                    newsubsample.subcut = subcuts[i]
                    newsubsample.group = subgroups[i]
                    if sampleType != 'DATA':
                        newsubsample.sf = float(subsfs[i])
                        newsubsample.xsec = float(subxsecs[i])
                    newsamples.append(newsubsample)
                self._samplelist.extend(newsamples)
                self._samplelist.append(newsample)
            else:
                if sampleType != 'DATA':
                    newsample.xsec = eval((config.get(sample, 'xSec')))
                    newsample.sf = eval((config.get(sample, 'SF')))
                newsample.group = config.get(sample, 'sampleGroup')
                self._samplelist.append(newsample)
Beispiel #9
0
    parser.add_option("-S", "--samples", dest="names", default="",
                                  help="samples you want to run on")
    parser.add_option("-R", "--region", dest="region", default="",
                                  help="region to plot")

    parser.add_option("-t", "--task", dest="task", default="",
                                  help="task (prep, sys, eval, plot) to be checked")
    parser.add_option("-f", "--filelist", dest="filelist", default="",
                                  help="list of files you want to run on")

    (opts, args) = parser.parse_args(argv)

    vhbbPlotDef=opts.config[0].split('/')[0]+'/vhbbPlotDef.ini'
    opts.config.append(vhbbPlotDef)#adds it to the config list

    config = BetterConfigParser()
    config.read(opts.config)

    samplesinfo=config.get('Directories','samplesinfo')
    sampleconf = BetterConfigParser()
    sampleconf.read(samplesinfo)

    # if opts.filelist != '': print 'filelist NOT NULL!'

    if opts.task == 'checksingleprep':
        pathOUT_orig = config.get('Directories','PREPout')
        pathIN_orig = 'DAS'
    elif opts.task == 'checksinglesys':
        pathOUT_orig = config.get('Directories','SYSout')
        pathIN_orig = config.get('Directories','SYSin')
    elif opts.task == 'checksingleeval':
Beispiel #10
0
    @property
    def n_cols(self):
        return self._roc_list[0].n_cols

    @property
    def n_rows(self):
        return self._roc_list[0].n_rows

    def dacs(self):
        return self._roc_list[0].dacs()


if __name__ == '__main__':
    from BetterConfigParser import BetterConfigParser
    config = BetterConfigParser()
    config.read('../data/module')
    logging.basicConfig(level=logging.INFO)
    #make a module from config
    m = DUT(config)

    #access a single pixel
    print m.roc(0).pixel(12, 13)
    #or
    print m.pixel(0, 12, 13)
    print m.pixel(0, 12, 13).trim

    print m.roc(0).dac('Vana')
    #iterate
    for roc in m.rocs():
        roc.dac('Vana').value = 155
Beispiel #11
0
    def __init__(self,samples_config,samples_path,config=None):
        '''
        Methode filling a list of Sample "self._samplelist = []" contained in the class. 
        "sample_path" contains the path where the samples are stored (PREPin). 
        "samples_config" is the "samples_nosplit.cfg" file. Depending of the variable "run_on_files" defined in "samples_nosplit.cfg", 
        the sample list are generated from the input folder (PREPin) or the list in "samples_nosplit.cfg" '''

        self.debug = 'XBBDEBUG' in os.environ
        if not config:
            if self.debug:
                print "Start getting infos on all the samples (ParseInfo)"
                print "==================================================\n"
                print 'samples_config is', samples_config
            try:
                os.stat(samples_config)
            except:
                raise Exception('config file is wrong/missing')

            # if no config object given, read full config again
            # this should be avoided by passing config object to ParseInfo class
            pathConfig = '/'.join(samples_config.split('/')[:-1]) + '/paths.ini'
            if os.path.isfile(pathConfig):
                config = BetterConfigParser()
                config.read(pathConfig)
                configList = config.get('Configuration', 'List').split(' ')
                for configFileName in configList:
                    configFileName = '/'.join(samples_config.split('/')[:-1]) + '/' + configFileName
                    if os.path.isfile(configFileName):
                        config.read(configFileName)
                if self.debug:
                    print "WARNING (performance): whole config read again, pass the config obect to ParseInfo class to avoid this."
            else:
                # old behavior: read only one file, config might be inconsistent
                config = BetterConfigParser()
                config.read(samples_config)
        elif self.debug:
            print "DEBUG: config object passed to sample parser."

        lumi = float(config.get('General','lumi'))

        self._samplelist = []
        self.__fileslist = []

        configSamples = [x for x in config.sections() if config.has_option(x, 'sampleName')]
        if self.debug:
            print "DEBUG:", len(configSamples), " samples found."
            
        for sample in configSamples:
            sampleName = config.get(sample, 'sampleName')
            sampleType = config.get(sample,'sampleType')
            cut = config.get(sample, 'cut')

            specialweight = config.get(sample, 'specialweight') if config.has_option(sample, 'specialweight') else "1"
            fullname = config.get(sample, 'sampleName')
            mergeCachingSize = int(config.get(sample, 'mergeCachingSize')) if config.has_option(sample, 'mergeCachingSize') else -1

            #fill the sample
            newsample = Sample(sampleName, sampleType)
            newsample.addtreecut = cut
            newsample.identifier = sample
            newsample.weightexpression = '' 
            newsample.specialweight = specialweight
            newsample.lumi = lumi
            newsample.prefix = '' 
            newsample.FullName = sampleName 

            if mergeCachingSize > 0:
                newsample.mergeCachingSize = mergeCachingSize
            if config.has_option(sample, 'skipParts'):
                newsample.skipParts = eval(config.get(sample, 'skipParts'))

            newsample.index = eval(config.get(sample, 'sampleIndex')) if config.has_option(sample, 'sampleIndex') else -999999

            # add and fill all the subsamples
            if config.has_option(sample,'subsamples') and eval(config.get(sample,'subsamples')):
                subgroups = eval((config.get(sample,'sampleGroup')))
                try:
                    subnames = eval((config.get(sample, 'subnames')))
                except:
                    # create subnames automatically based on subgroup name to avoid duplication
                    try:
                        shortname = config.get(sample, 'shortname').strip()
                    except:
                        # use full name if no short name given
                        shortname = sampleName
                    subnames = [shortname + '_' + x for x in subgroups]
                subcuts = eval((config.get(sample, 'subcuts')))

                if sampleType != 'DATA':
                    subxsecs = eval((config.get(sample, 'xSec')))
                    if len(list(set(subxsecs))) == 1:
                        newsample.xsec = [subxsecs[0]]
                    else:
                        print "\x1b[31mWARNING: different cross sections for the sub-samples of", sampleName, " are you sure you want to do this?\x1b[0m"
                    subsfs = eval((config.get(sample, 'SF'))) if config.has_option(sample, 'SF') else [1.0]*len(subxsecs)
                try:
                    subspecialweights = eval((config.get(sample, 'specialweight')))
                    #print 'specialweights=', subspecialweights
                    if len(subspecialweights) < 2:
                        subspecialweights = []
                        print "\x1b[31mWARNING: specialweight not defined for subsamples but for full sample only!\x1b[0m"
                except:
                    subspecialweights = []

                subindices = None
                newsamples = []
                for i,cut in enumerate(subcuts):
                    newsubsample = copy(newsample)
                    newsubsample.subsample = True
                    newsubsample.name = subnames[i]
                    newsubsample.subcut = subcuts[i]
                    newsubsample.group = subgroups[i]
                    if sampleType != 'DATA':
                        newsubsample.sf = float(subsfs[i])
                        newsubsample.xsec = float(subxsecs[i])
                    if len(subspecialweights) == len(subcuts):
                        newsubsample.specialweight = subspecialweights[i] 

                    if type(newsample.index) == list:
                        newsubsample.index = newsample.index[i]

                    newsamples.append(newsubsample)

                self._samplelist.extend(newsamples)
                self._samplelist.append(newsample)
            else:
                if sampleType != 'DATA':
                    newsample.xsec = eval((config.get(sample,'xSec')))    
                    newsample.sf = eval((config.get(sample, 'SF'))) if config.has_option(sample, 'SF') else 1.0
                newsample.group = config.get(sample,'sampleGroup')
                self._samplelist.append(newsample)
Beispiel #12
0
from gethistofromtree import getHistoFromTree, orderandadd

#CONFIGURE
argv = sys.argv
parser = OptionParser()
parser.add_option("-P", "--path", dest="path", default="",
                      help="path to samples")
parser.add_option("-V", "--var", dest="variable", default="",
                      help="variable for shape analysis")
parser.add_option("-C", "--config", dest="config", default=[], action="append",
                      help="configuration file")
(opts, args) = parser.parse_args(argv)
if opts.config =="":
        opts.config = "config"
print opts.config
config = BetterConfigParser()
config.read(opts.config)
anaTag = config.get("Analysis","tag")



# -------------------- parsing configuration and options: (an ugly spaghetti code section) ----------------------------------------------------------------------
#get locations:
Wdir=config.get('Directories','Wdir')
#systematics
systematics=config.get('systematics','systematics')
systematics=systematics.split(' ')
weightF=config.get('Weights','weightF')
path=opts.path
var=opts.variable
plot=config.get('Limit',var)
Beispiel #13
0
#! /usr/bin/env python

import sys

if len(sys.argv) == 1:
    print ' && '.join([
        'met_pt > 170',
        'json != 0',
        #            'jet_pt0 > 50',
        #            'jet_pt1 > 30',
        #            'HCMVAV2_reg_pt > 80',
    ])
    exit(0)

from BetterConfigParser import BetterConfigParser

config = BetterConfigParser()
config.read('cuts.ini')

print ' && '.join(['(%s)' % config.get('Cuts', reg) for reg in sys.argv[1:]])
Beispiel #14
0
    def __init__(self, samples_config, samples_path):
        '''
        Methode filling a list of Sample "self._samplelist = []" contained in the class. 
        "sample_path" contains the path where the samples are stored (PREPin). 
        "samples_config" is the "samples_nosplit.cfg" file. Depending of the variable "run_on_files" defined in "samples_nosplit.cfg", 
        the sample list are generated from the input folder (PREPin) or the list in "samples_nosplit.cfg" '''

        print "Start getting infos on all the samples (ParseInfo)"
        print "==================================================\n"
        print 'samples_config is', samples_config
        try:
            os.stat(samples_config)
        except:
            raise Exception('config file is wrong/missing')

        if '/pnfs/psi.ch/cms/' in samples_path:

            T3 = True
            _, p2 = samples_path.split('/pnfs/')
            t3_path = '/pnfs/' + p2.strip('\n')
        else:
            T3 = False

        config = BetterConfigParser()
        config.read(samples_config)

        newprefix = config.get('General', 'newprefix')
        lumi = float(config.get('General', 'lumi'))
        weightexpression = config.get('General', 'weightexpression')

        self._samplelist = []

        #!! Store the list of input samples in __fileslist. Reads them directly from the folder defined in PREPin
        self.__fileslist = []
        # print 'T3',T3,'samples_path',samples_path,'t3_path',t3_path
        if T3:
            ls = os.popen("ls " + t3_path)
        else:
            ls = os.popen("ls " + samples_path)

#print 'will start the loop over the lines.'
#print ls.read()
        for line in ls.readlines():
            #print 'loop over the lines'
            if ('.root' in line):
                truncated_line = line[line.rfind('/') + 1:]
                _p = findnth(truncated_line, '.', 2)
                self.__fileslist.append(
                    truncated_line[_p + 1:truncated_line.rfind('.')])
    #print 'added a new line !'

        print '@DEBUG: ' + str(self.__fileslist)

        #Deleteme: Do a loop to check on __fileslist
        #Start the loop
        #for i in range(0,len(self.__fileslist)):
        #print 'Is the ',i ,'th file None ? Answer:', (self.__fileslist[i] == None)

        #End Deleteme

        run_on_fileList = eval(
            config.get('Samples_running', 'run_on_fileList'
                       ))  #Evaluate run_on_fileList from samples_nosplit.cfg

        #print 'Is Sample None ? Answer: ', (self.__fileslist == None)

        if (not test_samples(
                run_on_fileList, self.__fileslist,
                config.sections())):  # stop if it finds None as sample
            sys.exit(
                '@ERROR: Sample == None. Check RunOnFileList flag in section General, the sample_config of the sample directory.'
            )

        #!! Start to loop over the samples. If run_on_files list is true, use the sample from the PREPin folder (_listed_file).
#!! Else use the sample from  samples_nosplit.cfg (_config_entry).
#!! The sample description from samples_nosplit.cfg are then applied.
        for _listed_file, _config_entry in map(None, self.__fileslist,
                                               config.sections()):
            if (run_on_fileList):
                _sample = _listed_file
                self._list = self.__fileslist
            else:
                _sample = _config_entry
                self._list = config.sections()

            sample = self.checkSplittedSample(
                _sample)  #Check if is splitted and remove the _
            if not config.has_option(sample, 'sampleName'):
                continue  #Check if the sample has the infile parameter. If not skip
            infile = _sample
            # print 'infile',infile
            sampleName = config.get(sample, 'sampleName')

            check_correspondency(
                sample, self._list,
                config)  #Check if the sample exists, not fully understood yet

            #Initialize samplecalss element
            sampleType = config.get(sample, 'sampleType')
            cut = config.get(sample, 'cut')
            if config.has_option(sample, 'specialweight'):
                specialweight = config.get(sample, 'specialweight')
            else:
                specialweight = "1"

    #fill the sample
            newsample = Sample(sampleName, sampleType)
            newsample.addtreecut = cut
            newsample.identifier = infile
            newsample.weightexpression = weightexpression
            newsample.specialweight = specialweight
            newsample.lumi = lumi
            newsample.prefix = newprefix

            #add and fills all the subsamples
            if eval(config.get(sample, 'subsamples')):
                subnames = eval((config.get(sample, 'subnames')))
                subcuts = eval((config.get(sample, 'subcuts')))
                subgroups = eval((config.get(sample, 'sampleGroup')))
                if sampleType != 'DATA':
                    subxsecs = eval((config.get(sample, 'xSec')))
                    subsfs = eval((config.get(sample, 'SF')))
                newsamples = []
                for i, cut in enumerate(subcuts):
                    newsubsample = copy(newsample)
                    newsubsample.subsample = True
                    newsubsample.name = subnames[i]
                    newsubsample.subcut = subcuts[i]
                    newsubsample.group = subgroups[i]
                    if sampleType != 'DATA':
                        newsubsample.sf = float(subsfs[i])
                        newsubsample.xsec = float(subxsecs[i])
                    newsamples.append(newsubsample)
                self._samplelist.extend(newsamples)
                self._samplelist.append(newsample)
            else:
                if sampleType != 'DATA':
                    newsample.xsec = eval((config.get(sample, 'xSec')))
                    newsample.sf = eval((config.get(sample, 'SF')))
                newsample.group = config.get(sample, 'sampleGroup')
                self._samplelist.append(newsample)
        print "Finished getting infos on all the samples (ParseInfo)"
        print "=====================================================\n"
Beispiel #15
0
    argv = sys.argv

    #get files info from config
    parser = OptionParser()
    parser.add_option("-C", "--config", dest="config", default=[], action="append",
                          help="directory config")
    parser.add_option("-S", "--samples", dest="names", default="",
                                  help="samples you want to run on")
    parser.add_option("-s", "--mergesys", dest="mergesys", default="False",
                                  help="merge singlesys step")
    parser.add_option("-e", "--mergeeval", dest="mergeeval", default="False",
                                  help="merge singleeval step")

    (opts, args) = parser.parse_args(argv)

    config = BetterConfigParser()
    config.read(opts.config)

    namelist=opts.names.split(',')
    print "namelist:",namelist

    if opts.mergesys == 'True':
        pathIN = config.get('Directories','SYSin')
        pathOUT = config.get('Directories','SYSout')
    elif opts.mergeeval == 'True':
        pathIN = config.get('Directories','MVAin')
        pathOUT = config.get('Directories','MVAout')
    else:
        pathIN = config.get('Directories','PREPin')
        pathOUT = config.get('Directories','PREPout')
Beispiel #16
0
        return (roc.n_cols,roc.n_rows)

    @property
    def n_cols(self):
        return self._roc_list[0].n_cols

    @property
    def n_rows(self):
        return self._roc_list[0].n_rows

    def dacs(self):
        return self._roc_list[0].dacs()

if __name__=='__main__':
    from BetterConfigParser import BetterConfigParser
    config = BetterConfigParser()
    config.read('../data/module')
    logging.basicConfig(level=logging.INFO) 
    #make a module from config
    m = DUT(config)

    #access a single pixel
    print m.roc(0).pixel(12,13)
    #or
    print m.pixel(0,12,13)
    print m.pixel(0,12,13).trim

    print m.roc(0).dac('Vana')
    #iterate
    for roc in m.rocs():
        roc.dac('Vana').value = 155
Beispiel #17
0
    def __init__(self,samples_config,samples_path):
        '''
        Methode filling a list of Sample "self._samplelist = []" contained in the class. 
        "sample_path" contains the path where the samples are stored (PREPin). 
        "samples_config" is the "samples_nosplit.cfg" file. Depending of the variable "run_on_files" defined in "samples_nosplit.cfg", 
        the sample list are generated from the input folder (PREPin) or the list in "samples_nosplit.cfg" '''

        self.debug = 'XBBDEBUG' in os.environ
        if self.debug:
            print "Start getting infos on all the samples (ParseInfo)"
            print "==================================================\n"
            print 'samples_config is', samples_config
        try:
            os.stat(samples_config)
        except:
            raise Exception('config file is wrong/missing')
          
        if samples_path and '/pnfs/psi.ch/cms/' in samples_path:
            T3 = True
            _,p2=samples_path.split('/pnfs/')
            t3_path = '/pnfs/'+p2.strip('\n')
        else:
            T3 = False

        config = BetterConfigParser()
        config.read(samples_config)

        # TODO: 08.03.2018: newprefix and weightexpression needed?
        newprefix = config.get('General','newprefix') if config.has_option('General','newprefix') else ''
        lumi=float(config.get('General','lumi'))
        weightexpression=config.get('General','weightexpression') if config.has_option('General','weightexpression') else ''

        self._samplelist = []
        self.__fileslist=[]
    
        # TODO: 08.03.2018: clean up this file !!!!!!

        if samples_path:
            #!! Store the list of input samples in __fileslist. Reads them directly from the folder defined in PREPin  
            # print 'T3',T3,'samples_path',samples_path,'t3_path',t3_path
            if T3:
                ls = os.popen("ls "+t3_path)
            else:
                ls = os.popen("ls "+samples_path)
        
      #print 'will start the loop over the lines.'
      #print ls.read()
            for line in ls.readlines():
        #print 'loop over the lines'
                    if('.root' in line):
                            truncated_line = line[line.rfind('/')+1:]
                            _p = findnth(truncated_line,'.',2)
                            self.__fileslist.append(truncated_line[_p+1:truncated_line.rfind('.')])
          #print 'added a new line !'

            print '@DEBUG: ' + str(self.__fileslist)

      #Deleteme: Do a loop to check on __fileslist
      #Start the loop
      #for i in range(0,len(self.__fileslist)):
        #print 'Is the ',i ,'th file None ? Answer:', (self.__fileslist[i] == None) 

      #End Deleteme

        run_on_fileList = eval(config.get('Samples_running','run_on_fileList'))#Evaluate run_on_fileList from samples_nosplit.cfg 

  #print 'Is Sample None ? Answer: ', (self.__fileslist == None)

        if( not test_samples(run_on_fileList,self.__fileslist,config.sections()) ): # stop if it finds None as sample
                sys.exit('@ERROR: Sample == None. Check RunOnFileList flag in section General, the sample_config of the sample directory.')

        #!! Start to loop over the samples. If run_on_files list is true, use the sample from the PREPin folder (_listed_file). 
  #!! Else use the sample from  samples_nosplit.cfg (_config_entry).
        #!! The sample description from samples_nosplit.cfg are then applied.
        for _listed_file,_config_entry in map(None,self.__fileslist,config.sections()):
            if( run_on_fileList ): 
                _sample = _listed_file
                self._list = self.__fileslist
            else:
                _sample = _config_entry
                self._list = config.sections()

            sample = self.checkSplittedSample(_sample)#Check if is splitted and remove the _
            if not config.has_option(sample,'sampleName'): continue #Check if the sample has the infile parameter. If not skip
            infile = _sample
            # print 'infile',infile
            sampleName = config.get(sample,'sampleName')
            
            check_correspondency(sample,self._list,config)#Check if the sample exists, not fully understood yet                    
            
            #Initialize samplecalss element
            sampleType = config.get(sample,'sampleType')
            cut = config.get(sample, 'cut')
            if config.has_option(sample, 'specialweight'):
                specialweight = config.get(sample, 'specialweight')
            else:
                specialweight = "1"

            fullname = config.get(sample,'sampleName')

            mergeCachingSize = int(config.get(sample, 'mergeCachingSize')) if config.has_option(sample, 'mergeCachingSize') else -1

      #fill the sample
            newsample = Sample(sampleName,sampleType)
            newsample.addtreecut = cut
            newsample.identifier=infile
            newsample.weightexpression=weightexpression
            newsample.specialweight=specialweight
            newsample.lumi=lumi
            newsample.prefix=newprefix
            newsample.FullName = fullname
            
            if mergeCachingSize > 0:
                newsample.mergeCachingSize = mergeCachingSize
            if config.has_option(sample, 'skipParts'):
                newsample.skipParts = eval(config.get(sample, 'skipParts'))

      #add and fills all the subsamples
            if eval(config.get(sample,'subsamples')):
                subgroups = eval((config.get(sample,'sampleGroup')))
                try:
                    subnames = eval((config.get(sample, 'subnames')))
                except:
                    # create subnames automatically based on subgroup name to avoid duplication
                    try:
                        shortname = config.get(sample, 'shortname').strip()
                    except:
                        # use full name if no short name given
                        shortname = sampleName
                    subnames = [shortname + '_' + x for x in subgroups]
                subcuts = eval((config.get(sample, 'subcuts')))
                
                if sampleType != 'DATA':
                    subxsecs = eval((config.get(sample, 'xSec')))
                    subsfs = eval((config.get(sample, 'SF')))
                try:
                    subspecialweights = eval((config.get(sample, 'specialweight')))
                    #print 'specialweights=', subspecialweights
                    if len(subspecialweights) < 2:
                        subspecialweights = []
                except:
                    subspecialweights = []
                newsamples = []
                for i,cut in enumerate(subcuts):
                    newsubsample = copy(newsample)
                    newsubsample.subsample = True
                    newsubsample.name = subnames[i]
                    newsubsample.subcut = subcuts[i]
                    newsubsample.group = subgroups[i]
                    if sampleType != 'DATA':
                        newsubsample.sf = float(subsfs[i])
                        newsubsample.xsec = float(subxsecs[i])
                    if len(subspecialweights) == len(subcuts):
                        newsubsample.specialweight = subspecialweights[i] 
                    newsamples.append(newsubsample)
                    #print 'newsubsample:', newsubsample

                self._samplelist.extend(newsamples)
                self._samplelist.append(newsample)
            else:
                if sampleType != 'DATA':
                    newsample.xsec = eval((config.get(sample,'xSec')))    
                    newsample.sf = eval((config.get(sample, 'SF')))
                newsample.group = config.get(sample,'sampleGroup')
                self._samplelist.append(newsample)
        if self.debug:
            print "Finished getting infos on all the samples (ParseInfo)"
            print "=====================================================\n"
Beispiel #18
0
            try:
                return isinstance(eval(filename[filename.rfind('_') + 1:]),
                                  int)
            except:
                return False
        else:
            return False


if __name__ == '__main__':

    # read config

    #configSamples = ['WminusH_HToBB_WToLNu_M125_13TeV_powheg_pythia8', 'WplusH_HToBB_WToLNu_M125_13TeV_powheg_pythia8', 'ZH_HToBB_ZToLL_M125_13TeV_powheg_pythia8', 'ggZH_HToBB_ZToLL_M125_13TeV_powheg_pythia8', 'ZH_HToBB_ZToNuNu_M125_13TeV_powheg_pythia8', 'ggZH_HToBB_ZToNuNu_M125_13TeV_powheg_pythia8', 'ZZ_TuneCP5_13TeV-pythia8', 'ZZTo2L2Q_13TeV_amcatnloFXFX_madspin_pythia8', 'WZ_TuneCP5_13TeV-pythia8', 'WZTo1L1Nu2Q_13TeV_amcatnloFXFX_madspin_pythia8', 'WW_TuneCP5_13TeV-pythia8', 'WWTo1L1Nu2Q_13TeV_amcatnloFXFX_madspin_pythia8',.....]
    ## this is what the XbbConfigReader module is doing:
    pathconfig = BetterConfigParser()
    pathconfig.read(
        '/mnt/t3nfs01/data01/shome/krgedia/CMSSW_10_1_0/src/Xbb/python/Wlv2018config/paths.ini'
    )  #parent class 'ConfigParser' method
    configFiles = pathconfig.get('Configuration', 'List').split(' ')
    config = BetterConfigParser()
    print('configFiles parsed', configFiles)
    for configFile in configFiles:
        config.read('Wlv2017config/' + configFile)

    #print(config.get('Weights','weightF'))
    #config = XbbConfigReader.read('Zvv2017')

    #inputFile = 'root://t3dcachedb03.psi.ch:1094//pnfs/psi.ch/cms/trivcat/store/user/berger_p2/VHbb/VHbbPostNano2017/V5/Zvv/rerun/v4j/eval/ggZH_HToBB_ZToNuNu_M125_13TeV_powheg_pythia8/tree_aa5e971734ef4e885512748d534e6937ff03dc61feed21b6772ba943_000000_000000_0000_9_a6c5a52b56e5e0c7ad5aec31429c8926bf32cf39adbe087f05cfb323.root'
    path = 'root://t3dcachedb03.psi.ch:1094//pnfs/psi.ch/cms/trivcat/store/user/krgedia/VHbb/Wlv/VHbbPostNano2018/mva/17jan20v4'
    #samplefiles = '../samples/VHbbPostNano2017_V5/merged_Zvv2017/'