示例#1
0
def getComLineArgs():
    parser = UserInput.getDefaultParser()
    parser.add_argument("-s",
                        "--selection",
                        type=str,
                        required=True,
                        help="Specificy selection level to run over")
    parser.add_argument("--latex",
                        action='store_true',
                        help='table in latex format')
    parser.add_argument("-r",
                        "--object_restrict",
                        type=str,
                        default="",
                        help="Use modified object file")
    parser.add_argument("-b",
                        "--branches",
                        type=str,
                        default="all",
                        help="List (separate by commas) of names of branches "
                        "in root and config file to plot")
    parser.add_argument("-m",
                        "--make_cut",
                        type=str,
                        default="",
                        help="Enter a valid root cut string to apply")
    parser.add_argument(
        "--blinding",
        type=list,
        default=[
            "Mass < 400", "Pt < 200", "mjj < 500", "dEtajj < 2.5", "MTWZ < 400"
        ],
        help="Blinding cuts to apply (only to that distribution)")
    return parser.parse_args()
示例#2
0
def getComLineArgs():
    parser = UserInput.getDefaultParser()
    parser.add_argument("-s", "--selection", type=str, required=True, help="Specificy selection level to run over")
    parser.add_argument("-r", "--object_restrict", type=str, default="", help="Use modified object file")
    parser.add_argument(
        "-b",
        "--branches",
        type=str,
        default="all",
        help="List (separate by commas) of names of branches " "in root and config file to plot",
    )
    parser.add_argument("-m", "--make_cut", type=str, default="", help="Enter a valid root cut string to apply")
    parser.add_argument("--ratio_text", default="", type=str, help="Ratio text")
    parser.add_argument(
        "-t", "--extra_text", type=str, default="", help="Extra text to be added below (above) the legend"
    )
    parser.add_argument("--extra_text_above", action="store_true", help="Position extra text above the legend")
    parser.add_argument(
        "--folder_name", type=str, default="", help="Folder name to save plots in (default is current time)"
    )
    parser.add_argument("--simulation", action="store_true", help="Write 'Simulation' in CMS style text")
    parser.add_argument("--no_overflow", action="store_true", help="No overflow bin")
    parser.add_argument("--no_scalefactors", action="store_true", help="No scale factors")
    parser.add_argument("--scaleymax", type=float, default=1.0, help="Scale default ymax by this amount")
    parser.add_argument("--scaleymin", type=float, default=1.0, help="Scale default ymin by this amount")
    parser.add_argument("--scalelegy", type=float, default=1.0, help="Scale default legend entry size by this amount")
    parser.add_argument("--ratio_range", nargs=2, default=[0.5, 1.5], help="Ratio min ratio max (default 0.5 1.5)")
    parser.add_argument("--scalexmax", type=float, default=1.0, help="Scale default xmax by this amount")
    return parser.parse_args()
示例#3
0
def getComLineArgs():
    parser = UserInput.getDefaultParser()
    parser.add_argument("-s",
                        "--selection",
                        type=str,
                        required=True,
                        help="Specificy selection level to run over")
    parser.add_argument("-b",
                        "--branches",
                        type=str,
                        default="all",
                        help="List (separate by commas) of names of branches "
                        "in root and config file to plot")
    parser.add_argument("--systematics",
                        type=str,
                        required=True,
                        help="Specificy systematics to plot")
    return parser.parse_args()
def getComLineArgs():
    parser = UserInput.getDefaultParser()
    parser.add_argument("-s",
                        "--selection",
                        type=str,
                        required=True,
                        help="Specificy selection level to run over")
    parser.add_argument("--backgroundOnly",
                        action='store_true',
                        help="Use background only fit rather than s+b")
    parser.add_argument("--noCR",
                        action='store_true',
                        help="Remove control region from fit distribution")
    parser.add_argument("-b",
                        "--branches",
                        type=str,
                        default="all",
                        help="List (separate by commas) of names of branches "
                        "in root and config file to plot")
    return parser.parse_args()
            # Channels should be ordered the same way as passed to the histogram
            # Thus bin 0 is the underflow, bin 1 is total, and bin 2
            # is the first bin with channel content (mmm/emm/eem/eee by default)
            yield_info[chan] = getFormattedYieldAndError(hist, i + 2, sigfigs)
        yield_info["Total Yield"] = getFormattedYieldAndError(hist, 1, sigfigs)
        yield_table.add_row(
            [formatted_names[hist.GetName().replace("_standalone", "")]] +
            yield_info.values())
    with open("temp.txt", "a") as log_file:
        log_file.write(yield_table.get_latex_string())


ROOT.gROOT.SetBatch(True)
path = "/cms/kdlong" if "hep.wisc.edu" in os.environ['HOSTNAME'] else \
    "/afs/cern.ch/user/k/kelong/work"
parser = UserInput.getDefaultParser()
parser.add_argument("-s",
                    "--selection",
                    type=str,
                    required=True,
                    help="Specificy selection level to run over")
parser.add_argument("-m",
                    "--make_cut",
                    type=str,
                    default="",
                    help="Enter a valid root cut string to apply")
args = parser.parse_args()
if args.hist_file == "":
    ROOT.TProof.Open('workers=12')

dataset_manager = "%s/AnalysisDatasetManager" % path
示例#6
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)
示例#7
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)
示例#8
0
import Utilities.helper_functions as helper
from Utilities import CutFlowDefinitions
import os

def getMonteCarloStack(cutflow_maker, filelist):
    hist_stack = ROOT.THStack("cutflow", "")
    for plot_set in filelist:
        hist = cutflow_maker.getHist(plot_set)
        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/user/k/kelong/work"
parser = UserInput.getDefaultParser()
args = parser.parse_args()
cutflow_maker = CutFlowDefinitions.getWZCutFlow(
    "%s/AnalysisDatasetManager" % path,
    "full"
)
cutflow_maker.setLuminosity(1340)
cutflow_maker.setStates(["eee", "mmm", "emm", "eem"])
filelist = ["ttbar", "st", "ttv", "vvv", "ww", "zz", "dy-filt", "zg-filt",
        "wz"] if args.files_to_plot == "all" else \
        [x.strip() for x in args.files_to_plot.split(",")]
data_hist = cutflow_maker.getHist("data")
hist_stack = getMonteCarloStack(cutflow_maker, filelist)
hist_stack.Draw()
hist_stack.GetXaxis().SetLabelSize(0.4*8/9)
print "Now stack is %s" % hist_stack
示例#9
0
import os


def getMonteCarloStack(cutflow_maker, filelist, unc, scale_facs):
    hist_stack = ROOT.THStack("stack", "")
    for plot_set in filelist:
        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)