Пример #1
0
def get_significance(label, bins):

    if "binary" in args.method:
        score = "sig_prediction"
        min_score = 0
        max_score = 1
    elif "DNNmulti" in args.method:
        score = "(ggH_prediction+VBF_prediction+(1-DY_prediction)+(1-ttbar_prediction))"
        min_score = 1
        max_score = 3
    elif "BDTmva" in args.method:
        score = "MVA"
        min_score = -1
        max_score = 1
    elif "Rapidity" in args.method:
        score = "max_abs_eta_mu"
        min_score = 0
        max_score = 2.4

    # print "Will use method", args.method
    # print "    min score =", min_score
    # print "    max score =", max_score

    step = (args.max_var - args.min_var)/float(args.nSteps)

    print "Rescaling cut boundaries:"
    new_bins = []
    for ii in range(len(bins)):
        new_bins.append(min_score + bins[ii]*step)

    print bins, " --> ", new_bins

    categories = {}
    for ii in range(len(new_bins)-1):
        cat_name = "cat%i"%ii
        cut = "(%s>%f)&(%s<%f)"%(score, new_bins[ii], score, new_bins[ii+1])
        categories[cat_name] = cut

    print "Categories ready:"
    print  categories
    print "Creating datacards..."

    create_datacard(categories, args.sig_input_path, args.data_input_path, args.data_tree, args.output_path,  "datacard_"+label, "workspace_"+label, nuis=args.nuis, res_unc_val=args.res_unc_val, scale_unc_val=args.scale_unc_val, smodel=args.smodel, method=args.method, lumi=args.lumi)

    os.system('ls')
    os.system('combine -M Significance --expectSignal=1 -t -1 -n %s -d datacard_%s.txt'%(label, label))
    os.system('rm datacard_%s.txt'%label)
    os.system('rm workspace_%s.root'%label)  
    os.system('ls')
    significance = 0
    tree = ROOT.TChain("limit")
    tree.Add("higgsCombine%s.Significance.mH120.root"%label)
    for iev,  event in enumerate(tree):
        significance = event.limit
    os.system('rm higgsCombine%s.Significance.mH120.root'%label)
    print "Expected significance =", significance
    return significance
Пример #2
0
    def get_significance(self, label, bins1, bins2):
        new_bins1 = []
        for i in range(len(bins1)):
            new_bins1.append(self.min_var1 + bins1[i] * self.step1)
        new_bins2 = []
        for i in range(len(bins2)):
            new_bins2.append(self.min_var2 + bins2[i] * self.step2)

        self.log("   Rescaled cut boundaries:")
        self.log("   1st variable:   %s --> %s" % (', '.join(
            [str(b) for b in bins1]), ', '.join([str(b) for b in new_bins1])))
        self.log("   2nd variable:   %s --> %s" % (', '.join(
            [str(b) for b in bins2]), ', '.join([str(b) for b in new_bins2])))
        self.log("   Categories ready:")
        categories_for_combine = {}
        for ii in range(len(new_bins1) - 1):
            for jj in range(len(new_bins2) - 1):
                cat_name = "cat_%i_%i" % (ii, jj)
                cut = "(%s>%f)&(%s<%f)&(%s>%f)&(%s<%f)" % (
                    self.var1, new_bins1[ii], self.var1, new_bins1[ii + 1],
                    self.var2, new_bins2[ii], self.var2, new_bins2[ii + 1])
                categories_for_combine[cat_name] = cut
                self.log("   %s:  %s" % (cat_name, cut))
        self.log("   Creating datacards... Please wait...")

        success = create_datacard(categories_for_combine,
                                  args.sig_input_path,
                                  args.data_input_path,
                                  args.data_tree,
                                  args.output_path,
                                  "datacard_" + label,
                                  "workspace_" + label,
                                  nuis=args.nuis,
                                  res_unc_val=args.res_unc_val,
                                  scale_unc_val=args.scale_unc_val,
                                  smodel=args.smodel,
                                  method=args.method,
                                  lumi=args.lumi)
        if not success:
            print "Datacards were not created (might be not enough events in the category). Set significance to 0."
            return 0

        os.system(
            'combine -M Significance --expectSignal=1 -t -1 -n %s -d datacard_%s.txt'
            % (label, label))
        os.system('rm datacard_%s.txt' % label)
        os.system('rm workspace_%s.root' % label)

        significance = 0
        tree = ROOT.TChain("limit")
        tree.Add("higgsCombine%s.Significance.mH120.root" % label)
        for iev, event in enumerate(tree):
            significance = event.limit
        os.system('rm higgsCombine%s.Significance.mH120.root' % label)

        return significance
Пример #3
0
parser = argparse.ArgumentParser(description='')
parser.add_argument('--sig_in_path',
                    action='store',
                    dest='sig_input_path',
                    help='Input path')
parser.add_argument('--data_in_path',
                    action='store',
                    dest='data_input_path',
                    help='Input path')
parser.add_argument('--sig_tree',
                    action='store',
                    dest='sig_tree',
                    help='Tree name')
parser.add_argument('--data_tree',
                    action='store',
                    dest='data_tree',
                    help='Tree name')
parser.add_argument('--out_path',
                    action='store',
                    dest='output_path',
                    help='Output path')
parser.add_argument('--lumi',
                    action='store',
                    dest='lumi',
                    help='Integrated luminosity')
args = parser.parse_args()

create_datacard([0, 2.4], args.sig_input_path, args.sig_tree,
                args.data_input_path, args.data_tree, args.output_path,
                "datacard", "workspace", args.lumi)
Пример #4
0
                    help='Output path')
parser.add_argument('--lumi',
                    action='store',
                    dest='lumi',
                    help='Integrated luminosity')
parser.add_argument('--nuis',
                    action='store_true',
                    dest='nuis',
                    help='Nuisances')
parser.add_argument('--nuis_val',
                    action='store',
                    dest='nuis_val',
                    help='Resolution uncertainty')
args = parser.parse_args()

args = parser.parse_args()

for i in range(17, 18):
    for j in range(i):
        bins = [0.0, (j + 1) / 10.0, (i + 1) / 10.0, 2.4]
        create_datacard(bins,
                        args.sig_input_path,
                        args.sig_tree,
                        args.data_input_path,
                        args.data_tree,
                        args.output_path,
                        "datacard_3cat_%i_%i" % (j + 1, i + 1),
                        "workspace_3cat_%i_%i" % (j + 1, i + 1),
                        args.lumi,
                        nuis=args.nuis,
                        nuis_val=args.nuis_val)
Пример #5
0
def get_significance(label, bins):
    global memorized
    global additional_cut

    new_bins = []
    for i in range(len(bins)):
        new_bins.append(args.min_var + bins[i] * step)
    log("   Rescaled cut boundaries:")
    log("      %s --> %s" %
        (', '.join([str(b)
                    for b in bins]), ', '.join([str(b) for b in new_bins])))

    log("   Categories ready:")
    categories = {}
    for i in range(len(new_bins) - 1):
        cat_name = "cat%i" % i
        cut = "(%s>%f)&(%s<%f)&(%s)" % (score, new_bins[i], score,
                                        new_bins[i + 1], additional_cut)
        categories[cat_name] = cut
        log("   %s:  %s" % (cat_name, cut))
    log("   Creating datacards... Please wait...")

    if "UCSD" in args.method:
        try:
            success = create_datacard_ucsd(categories,
                                           sig_2016 + sig_2017 + sig_2018,
                                           bkg_2016 + bkg_2017 + bkg_2018,
                                           args.output_path,
                                           "datacard_" + label,
                                           "workspace_" + label)
        except:
            "There was an error. Setting significance to 0."
            return 0

    else:
        success = create_datacard(categories,
                                  args.sig_input_path,
                                  args.data_input_path,
                                  args.data_tree,
                                  args.output_path,
                                  "datacard_" + label,
                                  "workspace_" + label,
                                  nuis=args.nuis,
                                  res_unc_val=args.res_unc_val,
                                  scale_unc_val=args.scale_unc_val,
                                  smodel=args.smodel,
                                  method=args.method,
                                  lumi=args.lumi)

    if not success:
        return 0

    os.system(
        'combine -M Significance --expectSignal=1 -t -1 -n %s -d datacard_%s.txt  --LoadLibrary /home/dkondra/Hmumu_analysis/Hmumu_ML/cut_optimization/dynamic_categorization/lib/RooDCBShape_cxx.so'
        % (label, label))
    os.system('rm datacard_%s.txt' % label)
    os.system('rm workspace_%s.root' % label)

    significance = 0
    tree = ROOT.TChain("limit")
    tree.Add("higgsCombine%s.Significance.mH120.root" % label)
    for iev, event in enumerate(tree):
        significance = event.limit
    os.system('rm higgsCombine%s.Significance.mH120.root' % label)

    log("Expected significance %f calculated for bins %s" %
        (significance, ', '.join([str(b) for b in bins])))

    bins_str = ""
    for ii in range(len(bins) - 1):
        bins_str = bins_str + "%f_" % bins[ii]
    bins_str = bins_str + "%f" % bins[len(bins) - 1]
    memorized[bins_str] = significance

    log("Memorizing result as " + bins_str)
    log(" ")
    log("############################################")
    log(" ")
    return significance
Пример #6
0
	"(%s>%f)&(%s<%f)"%(score, mva_cuts[2], score, mva_cuts[3]), #cat8
	"(%s>%f)&(%s<%f)"%(score, mva_cuts[2], score, mva_cuts[3]), #cat9
	"(%s>%f)&(%s<%f)"%(score, mva_cuts[3], score, mva_cuts[4]), #cat10
	"(%s>%f)&(%s<%f)"%(score, mva_cuts[3], score, mva_cuts[4]), #cat11
	"(%s>%f)&(%s<%f)"%(score, mva_cuts[3], score, mva_cuts[4]), #cat12
	"(%s>%f)&(%s<%f)"%(score, mva_cuts[4], score, mva_cuts[5]), #cat13
	"(%s>%f)"%(score, mva_cuts[5]), #cat14
]


# categories_inclusive = {"cat0": "1"}
# create_datacard(categories_inclusive, args.sig_input_path, args.data_input_path, args.data_tree, args.output_path,  "datacard_dnn_option%s_inclusive"%args.option, "workspace_dnn_option%s_inclusive"%args.option, nuis=args.nuis, res_unc_val=args.res_unc_val, scale_unc_val=args.scale_unc_val, smodel=args.smodel, method=args.method, lumi=lumi)

# categories_full = {}
# for i in range(len(eta_cut_full)):
# 	categories_full["cat%i"%i] = "(%s)&(%s)"%(eta_cut_full[i], mva_cut_full[i])
# create_datacard(categories_full, args.sig_input_path, args.data_input_path, args.data_tree, args.output_path,  "datacard_dnn_option%s_full"%args.option, "workspace_dnn_option%s_full"%args.option, nuis=args.nuis, res_unc_val=args.res_unc_val, scale_unc_val=args.scale_unc_val, smodel=args.smodel, method=args.method, lumi=lumi)

categories_mva = {}
for i in range(len(mva_cut)):
	categories_mva["cat%i"%i] = "(%s)"%(mva_cut[i]) # only mva categorization
create_datacard(categories_mva, args.sig_input_path, args.data_input_path, args.data_tree, args.output_path,  "datacard_dnn_option%s_mva"%args.option, "workspace_dnn_option%s_mva"%args.option, nuis=args.nuis, res_unc_val=args.res_unc_val, scale_unc_val=args.scale_unc_val, smodel=args.smodel, method=args.method, lumi=lumi)

# categories_eta = {}
# for i in range(len(eta_cut)):
# 	categories_eta["cat%i"%i] = "(%s)"%(eta_cut[i]) # only eta categorization
# create_datacard(categories_eta, args.sig_input_path, args.data_input_path, args.data_tree, args.output_path,  "datacard_dnn_option%s_eta"%args.option, "workspace_dnn_option%s_eta"%args.option, nuis=args.nuis, res_unc_val=args.res_unc_val, scale_unc_val=args.scale_unc_val, smodel=args.smodel, method=args.method, lumi=lumi)



Пример #7
0
parser.add_argument('--nSteps', action='store', dest='nSteps', help='nSteps', type=int)
parser.add_argument('--nIter', action='store', dest='nIter', help='nIter', type=int)
parser.add_argument('--lumi', action='store', dest='lumi', help='lumi', type=float)
parser.add_argument('--penalty', action='store', dest='penalty', help='penalty', type=float)

args = parser.parse_args()


eta_categories = {
    "eta0": "(max_abs_eta_mu>0)&(max_abs_eta_mu<0.9)", 
    "eta1": "(max_abs_eta_mu>0.9)&(max_abs_eta_mu<1.9)", 
    "eta2": "(max_abs_eta_mu>1.9)&(max_abs_eta_mu<2.4)"
}

if args.option is "0": # inclusive
    create_datacard({"cat0": "1"}, args.sig_input_path, args.data_input_path, args.data_tree, args.output_path,  "datacard_inclusive", "workspace_inclusive", nuis=args.nuis, res_unc_val=args.res_unc_val, scale_unc_val=args.scale_unc_val, smodel=args.smodel, method=args.method, lumi=args.lumi)
    create_datacard(eta_categories, args.sig_input_path, args.data_input_path, args.data_tree, args.output_path,  "datacard_inclusive_eta", "workspace_inclusive_eta", nuis=args.nuis, res_unc_val=args.res_unc_val, scale_unc_val=args.scale_unc_val, smodel=args.smodel, method=args.method, lumi=args.lumi)
    sys.exit() 

step = (args.max_var - args.min_var)/float(args.nSteps)

def bins_to_illustration(min, max, bins):
    result = ""
    for iii in range(min, max):
        if (iii in bins):
            result = result+"| "
        result = result+"%i "%iii
    result = result+"| "
    return result

def get_significance(label, bins):
Пример #8
0
                    dest='nuis',
                    help='Nuisances')
parser.add_argument('--nuis_val',
                    action='store',
                    dest='res_unc_val',
                    help='Resolution uncertainty')
parser.add_argument('--scale_unc_val',
                    action='store',
                    dest='scale_unc_val',
                    help='Scale uncertainty')
parser.add_argument('--smodel',
                    action='store',
                    dest='smodel',
                    help='Signal model')
args = parser.parse_args()

for i in range(23):
    bins = [0, (i + 1) / 10.0, 2.4]
    create_datacard(bins,
                    args.sig_input_path,
                    args.sig_tree,
                    args.data_input_path,
                    args.data_tree,
                    args.output_path,
                    "datacard_2cat_%i" % (i + 1),
                    "workspace_2cat_%i" % (i + 1),
                    args.lumi,
                    nuis=args.nuis,
                    res_unc_val=args.res_unc_val,
                    scale_unc_val=args.scale_unc_val,
                    smodel=args.smodel)
Пример #9
0
args = parser.parse_args()

second_cut_options = {
    # "1p8": 1.8,
    "1p9": 1.9,
    "2p0": 2.0,
}
scan_options = ["Bscan", "Oscan", "Escan"]
for key, value in second_cut_options.iteritems():
    for scan in scan_options:
        if "O" in scan:
            for i in range(int((value - 1) * 10)):
                bins = [0, 0.9, (i + 10) / 10.0, value, 2.4]
                create_datacard(bins, args.input_path,
                                args.output_path + "_%s_%s/" % (key, scan),
                                "datacard_0p9_%i_%s" % ((i + 10), key),
                                "workspace_0p9_%i_%s" % ((i + 10), key))
        if "E" in scan:
            for i in range(23 - int((value) * 10)):
                bins = [0, 0.9, value, i / 10.0 + value + 0.1, 2.4]
                create_datacard(
                    bins, args.input_path,
                    args.output_path + "_%s_%s/" % (key, scan),
                    "datacard_0p9_%i_%s" % ((i + 1 + value * 10), key),
                    "workspace_0p9_%i_%s" % ((i + 1 + value * 10), key))
        if "B" in scan:
            for i in range(8):
                bins = [0, (i + 1) / 10.0, 0.9, value, 2.4]
                create_datacard(bins, args.input_path,
                                args.output_path + "_%s_%s/" % (key, scan),
                                "datacard_0p9_%i_%s" % ((i + 1), key),