def get_lumi(filename):
    sample_name = extract_sample(filename)
    lumi = read_lumi(
        os.path.join(
            'inputs',
            jobid,
            sample_name+".lumicalc.sum"
        )
    )
    return lumi
def get_lumi(filename):
    sample_name = extract_sample(filename)
    lumi        = read_lumi( 
        os.path.join(
            'inputs',
            jobid,
            sample_name+".lumicalc.sum"
        ) 
    )
    return lumi
Exemple #3
0
import re
#from pudb import set_trace; set_trace()

paths = {
    #os.environ['current'],
    'current'  : 'inputs/%s/' % os.environ['jobid'],
    'previous' : 'inputs/2013-Jun-30-8TeV/',
}


for dataset in ['DoubleMu', 'DoubleElectron', 'MuEG']:
    lumi_dict = {}
    for jobid, path in paths.iteritems():
        lumi_dict[jobid] = {}
        for lumifile in glob.glob(path+'/data_'+dataset+'*.lumicalc.sum'):
            lumi_dict[jobid][extract_sample(lumifile)] = read_lumi(lumifile)

    print dataset
    print '%60s%20s%20s' % ('', 'current', 'previous')
    keys = []
    for i in lumi_dict.values():
        keys += i.keys()
    keys = list(set(keys))
    
    total_lumis = dict([(i, {'current' : 0., 'previous' : 0.}) for i in ['2012A', '2012B', '2012C', '2012D', 'TOTAL',]])
    
    for sample in keys:
        curr_l = lumi_dict['current'][sample] if sample in lumi_dict['current'] else 0.
        total_lumis['TOTAL']['current'] += curr_l
        previous_l  = lumi_dict['previous'][sample]  if sample in lumi_dict['previous'] else 0.
        total_lumis['TOTAL']['previous'] += previous_l
    data_lumi   = 0.
    for i in data_files:
        data_lumi += get_lumi(i)
        data_tree.Add(i)
    num_pass    = data_tree.GetEntries(cut_pass.GetTitle())
    num_fail    = data_tree.GetEntries(cut_fail.GetTitle())
    log.info("found %i input files for a total lumi: %f total passing events: %i. total failing events: %i" % (len(data_files), data_lumi, num_pass, num_fail) )

if args.forceLumi:
    data_lumi = args.forceLumi
    log.info("forcing total lumi to %f", data_lumi )
    mc_multiplicative = 1

mc_trees = []
for mc_file in mc_files:
    sample_name = extract_sample(mc_file)
    log.info('getting %s dataset...' % sample_name)
    mc_tree   = ROOT.TFile.Open(mc_file).Get(input_tree)
    mc_lumi   = get_lumi(mc_file)
    mc_factor = mc_multiplicative*(data_lumi / mc_lumi) \
                if data_lumi <> -1 else 1.
    log.info('   Events are going to be scaled by %f' % mc_factor)
    mc_trees.append( (sample_name, mc_tree, mc_factor) )


out_tfile.cd()

######################################
## Loading training Tree
######################################
Exemple #5
0
import re
#from pudb import set_trace; set_trace()

paths = {
    #os.environ['current'],
    'current': 'inputs/%s/' % os.environ['jobid'],
    'previous': 'inputs/2013-Jun-30-8TeV/',
}

for dataset in ['DoubleMu', 'DoubleElectron', 'MuEG']:
    lumi_dict = {}
    for jobid, path in paths.iteritems():
        lumi_dict[jobid] = {}
        for lumifile in glob.glob(path + '/data_' + dataset +
                                  '*.lumicalc.sum'):
            lumi_dict[jobid][extract_sample(lumifile)] = read_lumi(lumifile)

    print dataset
    print '%60s%20s%20s' % ('', 'current', 'previous')
    keys = []
    for i in lumi_dict.values():
        keys += i.keys()
    keys = list(set(keys))

    total_lumis = dict([(i, {
        'current': 0.,
        'previous': 0.
    }) for i in [
        '2012A',
        '2012B',
        '2012C',