Esempio n. 1
0
def get_mc_name(run):
    global all_ds
    if all_ds is None:
        from pwa.datasets import get_dataset_mapping
        all_ds = get_dataset_mapping("mc*")
    dataset = all_ds[int(run)]
    return "{d.run}_{d.physicsshort}".format(d=dataset)
Esempio n. 2
0
def mcrescale(self, params):
    from pwa.datasets import get_dataset_mapping
    from uncertainties import ufloat
    datasets = get_dataset_mapping("mc*")
    
    if not exists("pre_rescale"):
        makedirs("pre_rescale")
    
    match = re.compile("^.*?-P(.+)-R(\d+).root$").match
    lumi = params.lumi
    
    if params.uncert:
        lumi = ufloat((lumi, lumi * (params.uncert / 100.)))
    
    for filename in params.files:
        m = match(filename)
        if not m:
            print "Skipping", filename
            continue
        
        period, run = m.groups()
        dataset = datasets[int(run)]
        effective_lumi = dataset.effective_luminosity
        factor = dataset.reweight_factor(lumi)
        print "Processing", filename, period, run, dataset.physicsshort, effective_lumi, factor
        
        target_name = "mc_{d.run}_{d.physicsshort}.root".format(d=dataset)
        prerescale_path = pjoin("pre_rescale", filename)
        
        rename(filename, prerescale_path)
        f_in = R.TFile(prerescale_path, "read")
        f_out = R.TFile(target_name, "recreate")
        
        from minty.tools.minty_rescale import rescale_dir
        rescale_dir(f_in, f_out, factor.nominal_value)
        
        f_out.cd()
        save_ufloat("effective_lumi", effective_lumi)
        save_ufloat("mc_weight", factor)