channel_names = {
    "eee": "eee",
    "eem": "ee#mu",
    "emm": "#mu#mue",
    "mmm": "#mu#mu#mu"
}
for chan in channels:
    cutflow_entry = CutFlowTools.CutFlowEntry(
        channel_names[chan],
        dataset_manager,
        args.selection.split("_")[0],
    )
    cutflow_entry.addAdditionalCut(args.make_cut)
    cutflow_entry.setStates(chan)
    cutflow_maker.addEntry(cutflow_entry)
filelist = UserInput.getListOfFiles(args.files_to_plot, args.selection)
if not args.no_data:
    data_hist = cutflow_maker.getHist("data_2016", "stat", args.hist_file)
else:
    data_hist = 0
hist_stack = getMonteCarloStack("stack", cutflow_maker, filelist,
                                args.uncertainties, not args.no_scalefactors,
                                args.hist_file)
signal_stack = 0
if len(args.signal_files) > 0:
    signal_filelist = UserInput.getListOfFiles(args.signal_files,
                                               args.selection)
    signal_stack = getMonteCarloStack("signal_stack", cutflow_maker,
                                      signal_filelist, args.uncertainties,
                                      not args.no_scalefactors, args.hist_file)
hist_stack.Draw()
Exemplo n.º 2
0
def main():
    #pdb.set_trace()
    args = getComLineArgs()
    with open('varsFile.json') as var_json_file:
        myvar_dict = json.load(var_json_file)
    for key in myvar_dict.keys():
        if args.branches==str(key):
            args.rebin = myvar_dict[key]['_binning']
            
    ROOT.gROOT.SetBatch(True)
    ROOT.gStyle.SetOptDate(0)
    if args.hist_file == "":
        ROOT.TProof.Open('workers=12')
    filelist = UserInput.getListOfFiles(args.files_to_plot, args.selection)
    print filelist
    path = "/cms/uhussain" if "hep.wisc.edu" in os.environ['HOSTNAME'] else \
        "/afs/cern.ch/user/h/hehe/new_ZZ_test_Sep9/CMSSW_10_3_1/src/Data_manager"
    config_factory = ConfigHistFactory(
        "%s/ZZ4lRun2DatasetManager" % path,
        args.selection.split("_")[0],
        args.object_restrict
    )
    #print args.selection, args.selection.split("_")[0]
    #print args.rebin
    branches = config_factory.getListOfPlotObjects() if args.branches == "all" \
            else [x.strip() for x in args.branches.split(",")]
    print branches
    cut_string = args.make_cut
    (plot_path, html_path) = helper.getPlotPaths(args.selection, args.folder_name, True)
    meta_info = '-'*80 + '\n' + \
        'Script called at %s\n' % datetime.datetime.now() + \
        'The command was: %s\n' % ' '.join(sys.argv) + \
        '-'*80 + '\n'
    for branch in branches:
        hist_stacks = []
        signal_stacks = []
        data_hists = []
        for branch_name in branch.split("+"):
            with open("temp.txt", "w") as mc_file:
                mc_file.write(meta_info)
                mc_file.write("Selection: %s" % args.selection)
                mc_file.write("\nAdditional cut: %s" % ("None" if cut_string == "" else cut_string))
                mc_file.write("\nLuminosity: %0.2f fb^{-1}" % (args.luminosity))
                mc_file.write("\nPlotting branch: %s\n" % branch_name)
            try:
                #pdb.set_trace()
                hist_stack = getStacked("stack_"+branch_name, config_factory, args.selection, filelist, 
                        branch_name, args.channels, args.blinding, not args.no_overflow, args.latex, cut_string,
                        args.luminosity, args.rebin, args.uncertainties, args.hist_file)
            except ValueError as e:
                logging.warning('\033[91m'+ str(e)+'\033[0m')
                continue
            if not args.no_data:
                #pdb.set_trace()
                if args.hist_file == "":
                    #data_hist = helper.getConfigHistFromTree(config_factory, "data_all", args.selection, 
                    data_hist = helper.getConfigHistFromTree(config_factory, "data_all", args.selection, 
                            branch_name, args.channels, args.blinding, 1, not args.no_overflow, args.rebin, 
                            cut_string)
                else:
                    #data_hist = helper.getConfigHistFromFile(args.hist_file, config_factory, "data_all",
                    data_hist = helper.getConfigHistFromFile(args.hist_file, config_factory, "data_all", 
                            args.selection, branch_name, args.channels,addOverflow=(not args.no_overflow), rebin=args.rebin)
                with open("temp.txt", "a") as events_log_file:
                    events_log_file.write("\nNumber of events in data: %i\n" % data_hist.Integral())
            else:
                data_hist = 0
            signal_stack = 0
            if len(args.signal_files) > 0:
                signal_filelist = UserInput.getListOfFiles(args.signal_files, args.selection)
                signal_stack = getStacked("signal_stack_"+branch_name, config_factory, args.selection, signal_filelist, 
                        branch_name, args.channels, args.blinding, not args.no_overflow, args.latex, cut_string,
                        args.luminosity, args.rebin, args.uncertainties, args.hist_file)
            hist_stacks.append(hist_stack)
            signal_stacks.append(signal_stack)
            data_hists.append(data_hist)
        if not hist_stacks:
            continue
        name = branch.replace("+","_")
        plot_name = name if args.append_to_name == "" else "_".join([name, args.append_to_name])

        #embed()
        canvas = helper.makePlots(hist_stacks, data_hists, name, args, signal_stacks)
        helper.savePlot(canvas, plot_path, html_path, plot_name, True, args)
        makeSimpleHtml.writeHTML(html_path.replace("/plots",""), args.selection)
Exemplo n.º 3
0
def main():
    args = getComLineArgs()
    logging.basicConfig(level=(logging.DEBUG if args.debug else (logging.ERROR if args.quiet else logging.INFO)))

    ROOT.gROOT.SetBatch(True)
    ROOT.gStyle.SetOptDate(0)
    if args.hist_file == "":
        ROOT.TProof.Open('workers=12')
    filelist = UserInput.getListOfFiles(args.files_to_plot, args.selection)
    path = "/cms/kdlong" if "hep.wisc.edu" in os.environ['HOSTNAME'] else \
        "/afs/cern.ch/work/m/mumuhamm/WBoson/CMSSW_11_0_0/src/Data_Manager"
    config_factory = ConfigHistFactory(
        "%s/AnalysisDatasetManager" % path,
        #args.selection.split("_")[0],
        args.selection,
        args.object_restrict
    )
    branches = config_factory.getListOfPlotObjects() if args.branches == "all" \
            else [x.strip() for x in args.branches.split(",")]
    cut_string = args.make_cut
    (plot_path, html_path) = helper.getPlotPaths(args.selection, args.folder_name, True)
    meta_info = '-'*80 + '\n' + \
        'Script called at %s\n' % datetime.datetime.now() + \
        'The command was: %s\n' % ' '.join(sys.argv) + \
        '-'*80 + '\n'
    for branch in branches:
        hist_stacks = []
        signal_stacks = []
        data_hists = []
        for branch_name in branch.split("+"):
            with open("temp.txt", "w") as mc_file:
                mc_file.write(meta_info)
                mc_file.write("Selection: %s" % args.selection)
                mc_file.write("\nAdditional cut: %s" % ("None" if cut_string == "" else cut_string))
                mc_file.write("\nLuminosity: %0.2f fb^{-1}" % (args.luminosity))
                mc_file.write("\nPlotting branch: %s\n" % branch_name)
            try:
                hist_stack = getStacked("stack_"+branch_name, config_factory, args.selection, filelist, 
                        branch_name, args.channels, args.blinding, not args.no_overflow, args.latex, cut_string,
                        args.luminosity, args.rebin, args.uncertainties, args.hist_file, args.scale)
            except ValueError as e:
                logging.warning('\033[91m'+ str(e)+'\033[0m')
                continue
            if args.data != 'none':
                if args.hist_file == "":
                    data_hist = helper.getConfigHistFromTree(config_factory, args.data, args.selection, 
                            branch_name, args.channels, args.blinding, 1, not args.no_overflow, args.rebin, 
                            cut_string)
                else:
                    data_hist = helper.getConfigHistFromFile(args.hist_file, config_factory, args.data, 
                            args.selection, branch_name, args.channels,addOverflow=(not args.no_overflow), rebin=args.rebin)
                with open("temp.txt", "a") as events_log_file:
                    events_log_file.write("\nNumber of events in data: %i\n" % data_hist.Integral())
            else:
                data_hist = 0
            signal_stack = 0
            if len(args.signal_files) > 0:
                signal_filelist = UserInput.getListOfFiles(args.signal_files, args.selection)
                signal_stack = getStacked("signal_stack_"+branch_name, config_factory, args.selection, signal_filelist, 
                        branch_name, args.channels, args.blinding, not args.no_overflow, args.latex, cut_string,
                        args.luminosity, args.rebin, args.uncertainties, args.hist_file)
            hist_stacks.append(hist_stack)
            signal_stacks.append(signal_stack)
            data_hists.append(data_hist)
        if not hist_stacks:
            continue
        name = branch.replace("+","_")
        plot_name = name if args.append_to_name == "" else "_".join([name, args.append_to_name])

        #embed()
        canvas = helper.makePlots(hist_stacks, data_hists, name, args, signal_stacks)

        #ratioPad = canvas.GetListOfPrimitives().FindObject("ratioPad")
        #stackPad = canvas.GetListOfPrimitives().FindObject("stackPad")
        #ratiohist = ratioPad.GetListOfPrimitives().FindObject('%s_canvas_central_ratioHist' % name)
        #for i in ratioPad.GetListOfPrimitives(): print i
        #xaxis = hist.GetXaxis()
        #xaxis.SetLabelOffset(1.2)

        helper.savePlot(canvas, plot_path, html_path, plot_name, True, args)
        makeSimpleHtml.writeHTML(html_path.replace("/plots",""), args.selection)
Exemplo n.º 4
0
        hist = cutflow_maker.getHist(plot_set, unc, "", scale_facs)
        hist_stack.Add(hist)
    return hist_stack


ROOT.gROOT.SetBatch(True)
ROOT.TProof.Open('workers=12')
path = "/cms/kdlong" if "hep.wisc.edu" in os.environ['HOSTNAME'] else \
    "/afs/cern.ch/work/m/mumuhamm/WBoson/CMSSW_11_0_0/src/Data_Manager"
parser = UserInput.getDefaultParser()
args = parser.parse_args()
cutflow_maker = CutFlowDefinitions.getWZCutFlow(
    "%s/AnalysisDatasetManager" % path, "full")
cutflow_maker.setLuminosity(args.luminosity)
cutflow_maker.setStates(args.channels)
filelist = UserInput.getListOfFiles(args.files_to_plot, "Wselection")
if not args.no_data:
    data_hist = cutflow_maker.getHist("data_2016", "stat", "")
else:
    data_hist = 0
hist_stack = getMonteCarloStack(cutflow_maker, filelist, args.uncertainties,
                                not args.no_scalefactors)
hist_stack.Draw()
hist_stack.GetXaxis().SetLabelSize(0.4 * 8 / 9)
canvas = helper.makePlot(hist_stack, data_hist, "CutFlow", args)
canvas.SetRightMargin(0.3)
(plot_path, html_path) = helper.getPlotPaths("WZxsec2016/Wselection",
                                             args.folder_name)
helper.savePlot(canvas, plot_path, html_path, "CutFlow", False, args)
makeSimpleHtml.writeHTML(html_path, "Wselection")