def get_dataset(data_name, varname, max_entries = -1, option = 'merged'):
    tree = trees.get(data_name, option)
    cfg = config_map[varname]
    datasets = []
    ## Get a dataset for each expression-selection pair
    for expr, cuts in zip(cfg.expressions, cfg.selections):
        if hasattr(cfg, 'binning') and len(cfg.binning.split(',')) == 3:
            nbins, varmin, varmax = map(float, cfg.binning.split(','))
            variable = ROOT.RooRealVar(cfg.name, expr, varmin, varmax)
            variable.setBins(int(nbins))
        else:
            variable = ROOT.RooRealVar(cfg.name, expr)
        cuts = [cuts]
        if max_entries > 0:
            cuts.append('Entry$ < %d' % max_entries)
        dataset = datasetly.get(tree=tree, variable=variable, cuts=cuts)
        variable = dataset.get().first()
        variable.SetTitle(cfg.title)
        variable.setUnit(cfg.unit)
        datasets.append(dataset)
    ## End of loop over expressions and selections
    dataset = datasets[0]
    for further_dataset in datasets[1:]:
        dataset.append(further_dataset)
    return dataset
def get_dataset(data_name, varname, max_entries=-1, option='merged'):
    tree = trees.get(data_name, option)
    cfg = config_map[varname]
    datasets = []
    ## Get a dataset for each expression-selection pair
    for expr, cuts in zip(cfg.expressions, cfg.selections):
        if hasattr(cfg, 'binning') and len(cfg.binning.split(',')) == 3:
            nbins, varmin, varmax = map(float, cfg.binning.split(','))
            variable = ROOT.RooRealVar(cfg.name, expr, varmin, varmax)
            variable.setBins(int(nbins))
        else:
            variable = ROOT.RooRealVar(cfg.name, expr)
        cuts = [cuts]
        if max_entries > 0:
            cuts.append('Entry$ < %d' % max_entries)
        dataset = datasetly.get(tree=tree, variable=variable, cuts=cuts)
        variable = dataset.get().first()
        variable.SetTitle(cfg.title)
        variable.setUnit(cfg.unit)
        datasets.append(dataset)
    ## End of loop over expressions and selections
    dataset = datasets[0]
    for further_dataset in datasets[1:]:
        dataset.append(further_dataset)
    return dataset
Beispiel #3
0
 def __init__(self,
              name,
              varname,
              option,
              max_entries,
              prescale,
              prescale_phase=0):
     print 'DEBUG', self.__class__.__name__, '__init__'
     if prescale > 1:
         msg = ', '.join(
             ['max_entries=%d' % max_entries,
              'prescale=%d' % prescale])
         raise RuntimeError, 'Illegal arguments ' + msg
     self.name = name
     self.varname = varname
     #self.max_entries = max_entries
     #self.option = self.option
     tree = trees.get(name, option)
     cfg = config_map[varname]
     datasets = []
     ## Get a dataset for each expression-selection pair
     for expr, cuts in zip(cfg.expressions, cfg.selections):
         if hasattr(cfg, 'qqbinning') and len(
                 cfg.qqbinning.split(',')) == 3:
             nbins, varmin, varmax = map(float, cfg.qqbinning.split(','))
             variable = ROOT.RooRealVar(cfg.name, expr, varmin, varmax)
             variable.setBins(int(nbins))
         else:
             variable = ROOT.RooRealVar(cfg.name, expr, 0.)
         cuts = [cuts]
         ## Adds an appropriate prescale
         if max_entries > 0:
             all_entries = float(tree.GetEntries())
             prescale = ROOT.TMath.CeilNint(all_entries / max_entries)
         if prescale > 1:
             cut = 'Entry$ %% %d == %d' % (prescale, prescale_phase)
             print 'Prescaling %s: %s' % (name, cut)
             cuts.append(cut)
         dataset = datasetly.get(tree=tree, variable=variable, cuts=cuts)
         variable = dataset.get().first()
         variable.SetTitle(cfg.title)
         variable.setUnit(cfg.unit)
         datasets.append(dataset)
     ## End of loop over expressions and selections
     dataset = datasets[0]
     for further_dataset in datasets[1:]:
         dataset.append(further_dataset)
     dataset.SetTitle('Raw ' + name.split('-')[0].capitalize())
     dataset.SetName('raw_' + name.split('-')[0])
     print 'max_entries, numEntries', max_entries, dataset.numEntries()
     #if max_entries > 0 and dataset.numEntries() > max_entries:
     ### Downsample to reduce the size of data
     #dataset.Print()
     #print 'QQ DEBUG: Downsampling to', max_entries
     #dataset = Resampler(dataset).downsample(max_entries)
     #dataset.Print()
     self.data = dataset
     self.xvar = dataset.get().first()
Beispiel #4
0
 def __init__(self, name, varname, option, max_entries, prescale,
              prescale_phase=0):
     print 'DEBUG', self.__class__.__name__, '__init__' 
     if prescale > 1:
         msg = ', '.join(['max_entries=%d' % max_entries,
                           'prescale=%d' % prescale])
         raise RuntimeError, 'Illegal arguments ' + msg
     self.name = name
     self.varname = varname
     #self.max_entries = max_entries
     #self.option = self.option
     tree = trees.get(name, option)
     cfg = config_map[varname]
     datasets = []
     ## Get a dataset for each expression-selection pair
     for expr, cuts in zip(cfg.expressions, cfg.selections):
         if hasattr(cfg, 'qqbinning') and len(cfg.qqbinning.split(',')) == 3:
             nbins, varmin, varmax = map(float, cfg.qqbinning.split(','))
             variable = ROOT.RooRealVar(cfg.name, expr, varmin, varmax)
             variable.setBins(int(nbins))
         else:
             variable = ROOT.RooRealVar(cfg.name, expr, 0.)
         cuts = [cuts]
             ## Adds an appropriate prescale
         if max_entries > 0:
             all_entries = float(tree.GetEntries())
             prescale = ROOT.TMath.CeilNint(all_entries / max_entries)
         if prescale > 1:
             cut = 'Entry$ %% %d == %d' % (prescale, prescale_phase)
             print 'Prescaling %s: %s' % (name, cut)
             cuts.append(cut)
         dataset = datasetly.get(tree=tree, variable=variable, cuts=cuts)
         variable = dataset.get().first()
         variable.SetTitle(cfg.title)
         variable.setUnit(cfg.unit)
         datasets.append(dataset)
     ## End of loop over expressions and selections
     dataset = datasets[0]
     for further_dataset in datasets[1:]:
         dataset.append(further_dataset)
     dataset.SetTitle('Raw ' + name.split('-')[0].capitalize())
     dataset.SetName('raw_' + name.split('-')[0])
     print 'max_entries, numEntries', max_entries, dataset.numEntries()
     #if max_entries > 0 and dataset.numEntries() > max_entries:
         ### Downsample to reduce the size of data
         #dataset.Print()
         #print 'QQ DEBUG: Downsampling to', max_entries
         #dataset = Resampler(dataset).downsample(max_entries)
         #dataset.Print()
     self.data = dataset
     self.xvar = dataset.get().first()
    'setae',
    'sphib',
    'sphie',
    'sieieb',
    'sieiee',
    'cieipb',
    'cieipe',
    's4ratiob',
    's4ratioe',
]

output_filename = trees.analysis + '_' + dataset + '_id-histos.root'
destination = os.path.join(trees.base_dir, trees.analysis, 'histos',
                           output_filename)

tree = trees.get(dataset, option)
outfile = ROOT.TFile(destination, 'recreate')

hist = {}

for variable in variables_to_plot:
    cfg = config_map[variable]
    canvases.next(cfg.name).SetGrid()
    option = ''
    for expression, selection in zip(cfg.expressions, cfg.selections):
        if not ROOT.gDirectory.Get(cfg.name):
            varexp = expression + '>>' + cfg.name
            if hasattr(cfg, 'binning'):
                varexp += '(' + cfg.binning + ')'
        else:
            varexp = expression + '>>+' + cfg.name
    'pt', 'pt1', 'pt2',
    'eta', 'eta1', 'eta2',
    'r9b', 'r9e',
    'setab', 'setae',
    'sphib', 'sphie',
    'sieieb', 'sieiee',
    'cieipb', 'cieipe',
    's4ratiob', 's4ratioe',
]


output_filename = trees.analysis + '_' + dataset + '_id-histos.root'
destination = os.path.join(trees.base_dir, trees.analysis, 'histos',
                           output_filename)
                           
tree = trees.get(dataset, option)
outfile = ROOT.TFile(destination, 'recreate')

hist = {}

for variable in variables_to_plot:
    cfg = config_map[variable]
    canvases.next(cfg.name).SetGrid()
    option = ''
    for expression, selection in zip(cfg.expressions, cfg.selections):
        if not ROOT.gDirectory.Get(cfg.name):
            varexp = expression + '>>' + cfg.name 
            if hasattr(cfg, 'binning'):
                varexp += '(' + cfg.binning + ')'
        else:
            varexp = expression + '>>+' + cfg.name