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')
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)
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"
@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
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/'