Esempio n. 1
0
 def getValue(self, plot_group):
     hist = helper.getConfigHist(self.config_factory, 
             plot_group, 
             self.data_tier, 
             "l1Pt", 
             self.states, 
             self.luminosity, 
             self.additional_cut
     )
     events = hist.Integral()
     hist.Delete()
     return events
Esempio n. 2
0
def main():
    args = getComLineArgs()
    ROOT.gROOT.SetBatch(True)
    ROOT.TProof.Open("workers=12")
    filelist = getListOfFiles(args.files_to_plot, args.selection)
    path = "/cms/kdlong" if "hep.wisc.edu" in os.environ["HOSTNAME"] else "/afs/cern.ch/user/k/kelong/work"
    print "MANAGER PATH IS ", path
    config_factory = ConfigHistFactory("%s/AnalysisDatasetManager" % path, 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)
    for branch_name in branches:
        hist_stack = getStacked(
            config_factory,
            args.selection,
            filelist,
            branch_name,
            args.channels,
            not args.no_overflow,
            cut_string,
            args.luminosity,
            args.no_scalefactors,
            args.uncertainties,
        )
        if not args.no_data:
            data_hist = helper.getConfigHist(
                config_factory, "data", args.selection, branch_name, args.channels, not args.no_overflow, cut_string
            )
            with open("temp.txt", "a") as events_log_file:
                events_log_file.write("\nNumber of events in data: %i" % data_hist.Integral())
        else:
            data_hist = 0
        canvas = helper.makePlot(hist_stack, data_hist, branch_name, args)
        helper.savePlot(canvas, plot_path, html_path, branch_name, True, args)
        makeSimpleHtml.writeHTML(html_path, args.selection)
Esempio n. 3
0
def getStacked(
    config_factory,
    selection,
    filelist,
    branch_name,
    channels,
    addOverflow,
    cut_string="",
    luminosity=1,
    no_scalefacs=False,
    uncertainties="none",
):
    hist_stack = ROOT.THStack("stack", "")
    hist_info = {}
    for plot_set in filelist:
        print "plot set is %s " % plot_set
        hist = helper.getConfigHist(
            config_factory,
            plot_set,
            selection,
            branch_name,
            channels,
            addOverflow,
            cut_string,
            luminosity,
            no_scalefacs,
            uncertainties,
        )
        raw_events = hist.GetEntries() - 1
        hist_stack.Add(hist)
        error = array.array("d", [0])
        weighted_events = hist.IntegralAndError(0, hist.GetNbinsX(), error)
        if not hist.GetSumw2():
            hist.Sumw2()
        hist_info[plot_set] = {
            "raw_events": raw_events,
            "weighted_events": weighted_events,
            "error": 0 if int(raw_events) <= 0 else error[0],
            "stat error": weighted_events / math.sqrt(raw_events) if raw_events != 0 else 0,
        }
    writeMCLogInfo(hist_info, selection, branch_name, luminosity, cut_string)
    scale_uncertainty = False
    if not scale_uncertainty:
        return hist_stack
    for plot_set in filelist:
        expression = "MaxIf$(LHEweights," "Iteration$ < 6 || Iteration$ == 7 || Iteration$ == 9)" "/LHEweights[0]"
        scale_hist_up = helper.getConfigHist(
            config_factory,
            plot_set,
            selection,
            branch_name + "_scaleup",
            luminosity,
            expression + ("*" + cut_string if cut_string != "" else ""),
        )
        expression = "MinIf$(LHEweights," "Iteration$ < 6 || Iteration$ == 7 || Iteration$ == 9)" "/LHEweights[0]"
        scale_hist_down = helper.getConfigHist(
            config_factory,
            plot_set,
            selection,
            branch_name + "_scaledown",
            luminosity,
            "(%s)" % expression + ("*" + cut_string if cut_string != "" else ""),
        )
        scale_hist_up.SetLineStyle(0)
        scale_hist_down.SetLineStyle(0)
        scale_hist_up.SetLineWidth(1)
        scale_hist_down.SetLineWidth(1)
        hist_stack.Add(scale_hist_up)
        hist_stack.Add(scale_hist_down)
    return hist_stack