def draw_curve_8(_func, name, title, ylow, yhigh, num_errs=1): """ Draw 8TeV trigger efficiency curves """ graphs = [] for (trigger, color) in triggers: tool = ROOT.TrigTauEfficiency() tool.loadInputFile(os.path.join(base, 'triggerSF_{0}.root'.format(trigger))) func = getattr(tool, _func) eff = np.array(map(lambda x: func(x, eta, 0, period, prong, wpflag, eveto), pt)) errs_low = [] errs_high = [] for ierr in xrange(num_errs): eff_low = np.array(map(lambda x: func(x, eta, -1, period, prong, wpflag, eveto), pt)) eff_high = np.array(map(lambda x: func(x, eta, 1, period, prong, wpflag, eveto), pt)) errs_low.append(eff_low) errs_high.append(eff_high) # quadrature sum of error eff_low = np.sqrt(np.sum([np.power(err, 2) for err in errs_low], axis=0)) eff_high = np.sqrt(np.sum([np.power(err, 2) for err in errs_high], axis=0)) graph = Graph(len(pt), name=trigger) for i, (p, e, e_low, e_high) in enumerate(zip(pt, eff, eff_low, eff_high)): graph.SetPoint(i, p / 1000, e) graph.SetPointError(i, 0.4, 0.4, e_low, e_high) graph.linecolor = color graph.linewidth = 2 graph.fillstyle = '/' graph.fillcolor = color graphs.append(graph) c = Canvas() leg = Legend(len(graphs), pad=c, topmargin=0.6, leftmargin=0.3, textsize=25, margin=0.2) for i, g in enumerate(graphs): if i == 0: g.Draw('3AL') g.xaxis.title = '#font[52]{p}_{T} [GeV]' g.xaxis.SetLimits(20, 100) g.yaxis.SetLimits(ylow, yhigh) g.yaxis.SetRangeUser(ylow, yhigh) g.yaxis.title = title else: g.Draw('3L SAME') leg.AddEntry(g, g.name, 'L') leg.Draw() lines = [] for thresh in (25, 35): line = Line(thresh, ylow, thresh, yhigh) line.linestyle = 'dashed' line.linewidth = 2 line.Draw() lines.append(line) c.SaveAs('trigger_{0}.png'.format(name)) c.SaveAs('trigger_{0}.eps'.format(name))
def draw_curve_7(_func, name, title, ylow, yhigh): """ Draw 7TeV trigger efficiency curves """ graphs = [] for (trigger, color) in triggers: tool = ROOT.TauTriggerCorrections( os.path.join(base, 'triggerSF_%s.root' % trigger)) func = getattr(tool, _func) eff = map(lambda x: func(x, 0), pt) eff_low = map(lambda x: func(x, -1), pt) eff_high = map(lambda x: func(x, 1), pt) graph = Graph(len(pt), name=trigger) for i, (p, e, e_low, e_high) in enumerate(zip(pt, eff, eff_low, eff_high)): graph.SetPoint(i, p / 1000, e) graph.SetPointError(i, 0.4, 0.4, e - e_low, e_high - e) graph.linecolor = color graph.linewidth = 2 graph.fillstyle = '/' graph.fillcolor = color graphs.append(graph) c = Canvas() leg = Legend(len(graphs), pad=c, topmargin=0.4, leftmargin=0.3, textsize=25, margin=0.2) for i, g in enumerate(graphs): if i == 0: g.Draw('3AC') g.xaxis.title = '#font[52]{p}_{T} [GeV]' g.xaxis.SetLimits(20, 100) g.yaxis.SetLimits(ylow, yhigh) g.yaxis.SetRangeUser(ylow, yhigh) g.yaxis.title = title else: g.Draw('3C SAME') leg.AddEntry(g, g.name, 'L') leg.Draw() lines = [] for thresh in (25, 35): line = Line(thresh, ylow, thresh, yhigh) line.linestyle = 'dashed' line.linewidth = 2 line.Draw() lines.append(line) c.SaveAs('trigger_{0}.png'.format(name)) c.SaveAs('trigger_{0}.eps'.format(name))
def draw_curve_7(_func, name, title, ylow, yhigh): """ Draw 7TeV trigger efficiency curves """ graphs = [] for (trigger, color) in triggers: tool = ROOT.TauTriggerCorrections(os.path.join(base, 'triggerSF_%s.root' % trigger)) func = getattr(tool, _func) eff = map(lambda x: func(x, 0), pt) eff_low = map(lambda x: func(x, -1), pt) eff_high = map(lambda x: func(x, 1), pt) graph = Graph(len(pt), name=trigger) for i, (p, e, e_low, e_high) in enumerate(zip(pt, eff, eff_low, eff_high)): graph.SetPoint(i, p / 1000, e) graph.SetPointError(i, 0.4, 0.4, e - e_low, e_high - e) graph.linecolor = color graph.linewidth = 2 graph.fillstyle = '/' graph.fillcolor = color graphs.append(graph) c = Canvas() leg = Legend(len(graphs), pad=c, topmargin=0.4, leftmargin=0.3, textsize=25, margin=0.2) for i, g in enumerate(graphs): if i == 0: g.Draw('3AC') g.xaxis.title = '#font[52]{p}_{T} [GeV]' g.xaxis.SetLimits(20, 100) g.yaxis.SetLimits(ylow, yhigh) g.yaxis.SetRangeUser(ylow, yhigh) g.yaxis.title = title else: g.Draw('3C SAME') leg.AddEntry(g, g.name, 'L') leg.Draw() lines = [] for thresh in (25, 35): line = Line(thresh, ylow, thresh, yhigh) line.linestyle = 'dashed' line.linewidth = 2 line.Draw() lines.append(line) c.SaveAs('trigger_{0}.png'.format(name)) c.SaveAs('trigger_{0}.eps'.format(name))
def pvalue_plot(poi, pvalues, pad=None, xtitle='X', ytitle='P_{0}', linestyle=None, linecolor=None, yrange=None, verbose=False): """ Draw a pvalue plot Parameters ---------- poi : list List of POI values tested pvalues : list List of p-values or list of lists of p-values to overlay multiple p-value curves pad : Canvas or Pad, optional (default=None) Pad to draw onto. Create new pad if None. xtitle : str, optional (default='X') The x-axis label (POI name) ytitle : str, optional (default='P_{0}') The y-axis label linestyle : str or list, optional (default=None) Line style for the p-value graph or a list of linestyles for multiple p-value graphs. linecolor : str or list, optional (default=None) Line color for the p-value graph or a list of linestyles for multiple p-value graphs. Returns ------- pad : Canvas The pad. graphs : list of Graph The p-value graphs """ if not pvalues: raise ValueError("pvalues is empty") if not poi: raise ValueError("poi is empty") # determine if pvalues is list or list of lists if not isinstance(pvalues[0], (list, tuple)): pvalues = [pvalues] if linecolor is not None: if not isinstance(linecolor, list): linecolor = [linecolor] linecolor = cycle(linecolor) if linestyle is not None: if not isinstance(linestyle, list): linestyle = [linestyle] linestyle = cycle(linestyle) with preserve_current_canvas(): if pad is None: pad = Canvas() pad.cd() pad.SetLogy() # create the axis min_poi, max_poi = min(poi), max(poi) haxis = Hist(1000, min_poi, max_poi) xaxis = haxis.xaxis yaxis = haxis.yaxis xaxis.SetRangeUser(min_poi, max_poi) haxis.Draw('AXIS') min_pvalue = float('inf') graphs = [] for ipv, pv in enumerate(pvalues): graph = Graph(len(poi), linestyle='dashed', drawstyle='L', linewidth=2) for idx, (point, pvalue) in enumerate(zip(poi, pv)): graph.SetPoint(idx, point, pvalue) if linestyle is not None: graph.linestyle = linestyle.next() if linecolor is not None: graph.linecolor = linecolor.next() graphs.append(graph) curr_min_pvalue = min(pv) if curr_min_pvalue < min_pvalue: min_pvalue = curr_min_pvalue if verbose: for graph in graphs: log.info(['{0:1.1f}'.format(xval) for xval in list(graph.x())]) log.info(['{0:0.3f}'.format(yval) for yval in list(graph.y())]) # automatically handles axis limits axes, bounds = draw(graphs, pad=pad, same=True, logy=True, xtitle=xtitle, ytitle=ytitle, xaxis=xaxis, yaxis=yaxis, ypadding=(0.2, 0.1), logy_crop_value=1E-300) if yrange is not None: xaxis, yaxis = axes yaxis.SetLimits(*yrange) yaxis.SetRangeUser(*yrange) min_pvalue = yrange[0] # draw sigma levels up to minimum of pvalues line = Line() line.SetLineStyle(2) line.SetLineColor(2) latex = ROOT.TLatex() latex.SetNDC(False) latex.SetTextSize(20) latex.SetTextColor(2) sigma = 0 while True: pvalue = gaussian_cdf_c(sigma) if pvalue < min_pvalue: break keepalive(pad, latex.DrawLatex(max_poi, pvalue, " {0}#sigma".format(sigma))) keepalive(pad, line.DrawLine(min_poi, pvalue, max_poi, pvalue)) sigma += 1 pad.RedrawAxis() pad.Update() return pad, graphs
np.random.seed(42) # points x = np.sort(np.random.random(10)) * 3500 y = np.random.random(10) # set style for ROOT set_style('ATLAS') # create graph graph = Graph(x.shape[0]) for i, (xx, yy) in enumerate(zip(x, y)): graph.SetPoint(i, xx, yy) # set visual attributes graph.linecolor = 'blue' graph.markercolor = 'blue' graph.xaxis.SetTitle("E_{T} [GeV]") graph.yaxis.SetTitle("d#sigma_{jet}/dE_{T,jet} [fb/GeV]") graph.xaxis.SetRangeUser(0, 3500) graph.yaxis.SetRangeUser(0, 1) # plot with ROOT canvas = Canvas() graph.Draw("APL") label = ROOT.TText(0.4, 0.8, "ROOT") label.SetTextFont(43) label.SetTextSize(25) label.SetNDC() label.Draw()
def pvalue_plot(poi, pvalues, pad=None, xtitle='X', ytitle='P_{0}', linestyle=None, linecolor=None, yrange=None, verbose=False): """ Draw a pvalue plot Parameters ---------- poi : list List of POI values tested pvalues : list List of p-values or list of lists of p-values to overlay multiple p-value curves pad : Canvas or Pad, optional (default=None) Pad to draw onto. Create new pad if None. xtitle : str, optional (default='X') The x-axis label (POI name) ytitle : str, optional (default='P_{0}') The y-axis label linestyle : str or list, optional (default=None) Line style for the p-value graph or a list of linestyles for multiple p-value graphs. linecolor : str or list, optional (default=None) Line color for the p-value graph or a list of linestyles for multiple p-value graphs. Returns ------- pad : Canvas The pad. graphs : list of Graph The p-value graphs """ if not pvalues: raise ValueError("pvalues is empty") if not poi: raise ValueError("poi is empty") # determine if pvalues is list or list of lists if not isinstance(pvalues[0], (list, tuple)): pvalues = [pvalues] if linecolor is not None: if not isinstance(linecolor, list): linecolor = [linecolor] linecolor = cycle(linecolor) if linestyle is not None: if not isinstance(linestyle, list): linestyle = [linestyle] linestyle = cycle(linestyle) with preserve_current_canvas(): if pad is None: pad = Canvas() pad.cd() pad.SetLogy() # create the axis min_poi, max_poi = min(poi), max(poi) haxis = Hist(1000, min_poi, max_poi) xaxis = haxis.xaxis yaxis = haxis.yaxis xaxis.SetRangeUser(min_poi, max_poi) haxis.Draw('AXIS') min_pvalue = float('inf') graphs = [] for ipv, pv in enumerate(pvalues): graph = Graph(len(poi), linestyle='dashed', drawstyle='L', linewidth=2) for idx, (point, pvalue) in enumerate(zip(poi, pv)): graph.SetPoint(idx, point, pvalue) if linestyle is not None: graph.linestyle = linestyle.next() if linecolor is not None: graph.linecolor = linecolor.next() graphs.append(graph) curr_min_pvalue = min(pv) if curr_min_pvalue < min_pvalue: min_pvalue = curr_min_pvalue if verbose: for graph in graphs: log.info(['{0:1.1f}'.format(xval) for xval in list(graph.x())]) log.info(['{0:0.3f}'.format(yval) for yval in list(graph.y())]) # automatically handles axis limits axes, bounds = draw(graphs, pad=pad, same=True, logy=True, xtitle=xtitle, ytitle=ytitle, xaxis=xaxis, yaxis=yaxis, ypadding=(0.2, 0.1), logy_crop_value=1E-300) if yrange is not None: xaxis, yaxis = axes yaxis.SetLimits(*yrange) yaxis.SetRangeUser(*yrange) min_pvalue = yrange[0] # draw sigma levels up to minimum of pvalues line = Line() line.SetLineStyle(2) line.SetLineColor(2) latex = ROOT.TLatex() latex.SetNDC(False) latex.SetTextSize(20) latex.SetTextColor(2) sigma = 0 while True: pvalue = gaussian_cdf_c(sigma) if pvalue < min_pvalue: break keepalive( pad, latex.DrawLatex(max_poi, pvalue, " {0}#sigma".format(sigma))) keepalive(pad, line.DrawLine(min_poi, pvalue, max_poi, pvalue)) sigma += 1 pad.RedrawAxis() pad.Update() return pad, graphs
def draw_curve_8(_func, name, title, ylow, yhigh, num_errs=1): """ Draw 8TeV trigger efficiency curves """ graphs = [] for (trigger, color) in triggers: tool = ROOT.TrigTauEfficiency() tool.loadInputFile( os.path.join(base, 'triggerSF_{0}.root'.format(trigger))) func = getattr(tool, _func) eff = np.array( map(lambda x: func(x, eta, 0, period, prong, wpflag, eveto), pt)) errs_low = [] errs_high = [] for ierr in xrange(num_errs): eff_low = np.array( map(lambda x: func(x, eta, -1, period, prong, wpflag, eveto), pt)) eff_high = np.array( map(lambda x: func(x, eta, 1, period, prong, wpflag, eveto), pt)) errs_low.append(eff_low) errs_high.append(eff_high) # quadrature sum of error eff_low = np.sqrt( np.sum([np.power(err, 2) for err in errs_low], axis=0)) eff_high = np.sqrt( np.sum([np.power(err, 2) for err in errs_high], axis=0)) graph = Graph(len(pt), name=trigger) for i, (p, e, e_low, e_high) in enumerate(zip(pt, eff, eff_low, eff_high)): graph.SetPoint(i, p / 1000, e) graph.SetPointError(i, 0.4, 0.4, e_low, e_high) graph.linecolor = color graph.linewidth = 2 graph.fillstyle = '/' graph.fillcolor = color graphs.append(graph) c = Canvas() leg = Legend(len(graphs), pad=c, topmargin=0.6, leftmargin=0.3, textsize=25, margin=0.2) for i, g in enumerate(graphs): if i == 0: g.Draw('3AL') g.xaxis.title = '#font[52]{p}_{T} [GeV]' g.xaxis.SetLimits(20, 100) g.yaxis.SetLimits(ylow, yhigh) g.yaxis.SetRangeUser(ylow, yhigh) g.yaxis.title = title else: g.Draw('3L SAME') leg.AddEntry(g, g.name, 'L') leg.Draw() lines = [] for thresh in (25, 35): line = Line(thresh, ylow, thresh, yhigh) line.linestyle = 'dashed' line.linewidth = 2 line.Draw() lines.append(line) c.SaveAs('trigger_{0}.png'.format(name)) c.SaveAs('trigger_{0}.eps'.format(name))
def plot_all_integrated_luminosity(all_detector_one_data, all_detector_two_data, all_detector_three_data, block_length, bcid_status, background_list, style, name, detector_one_calibration, detector_two_calibration, detector_three_calibration): ''' Take all the luminosity ratio for each luminosity block and multiply by the time to get the integrated luminosity :param all_detector_one_data: A dictionary of the run name to a list of lists of luminosity blocks :param all_detector_two_data: A dictionary of the run name to a list of lists of luminosity blocks :param block_length: A dictionary the same length as the detector arrays containing the luminosity block length (time) :param style: a string corresponding to a ROOT graphing style, e.g. 'ATLAS' :return: Plot of all the detector data on a graph chronologically according to run number ''' # Set ROOT graph style set_style(str(style)) # Get average value of the rate for each luminosity block temp_detector_one = copy.deepcopy(all_detector_one_data) temp_detector_two = copy.deepcopy(all_detector_two_data) temp_detector_three = copy.deepcopy(all_detector_three_data) print(sorted(all_detector_one_data.keys())) for run in sorted(all_detector_one_data.keys()): block_count = 0 for block in range(len(all_detector_one_data.get(run)) - 1): del temp_detector_one.get(run)[block][:] del temp_detector_two.get(run)[block][:] del temp_detector_three.get(run)[block][:] block_count += 1 detector_one_avg = 0 one_count = 0 detector_two_avg = 0 two_count = 0 detector_three_avg = 0 three_count = 0 for bcid in range(len(all_detector_one_data.get(run)[block])): # Gets the previous BCID luminosity to subtract as the background if run in background_list: if bcid_status.get(run)[block][bcid - 1] == 0: detector_one_point_background = all_detector_one_data.get(run)[block][bcid - 1] detector_two_point_background = all_detector_two_data.get(run)[block][bcid - 1] detector_three_point_background = all_detector_three_data.get(run)[block][bcid - 1] print("BCID [N-1] Stability: " + str(bcid_status.get(run)[block][bcid - 1])) print("BCID [N] Stability: " + str(bcid_status.get(run)[block][bcid])) detector_one_point = -math.log(1 - all_detector_one_data.get(run)[block][bcid]) \ + math.log(1 - detector_one_point_background) print("Detector 1 Point: " + str(detector_one_point)) detector_two_point = -math.log(1 - all_detector_two_data.get(run)[block][bcid]) \ + math.log(1 - detector_two_point_background) print("Detector 2 Point: " + str(detector_two_point)) detector_three_point = -math.log(1 - all_detector_three_data.get(run)[block][bcid]) \ + math.log(1 - detector_three_point_background) detector_one_avg += detector_one_point one_count += 1 detector_two_avg += detector_two_point two_count += 1 detector_three_avg += detector_three_point three_count += 1 else: print("No empty BCID to subtract background from") ''' print("BCID [N] Stability: " + str(bcid_status.get(run)[block][bcid])) detector_one_point = -math.log(1 - all_detector_one_data.get(run)[block][bcid]) #\ #+ math.log(1 - detector_one_point_background) print("Detector 1 Point: " + str(detector_one_point)) detector_two_point = -math.log(1 - all_detector_two_data.get(run)[block][bcid]) #\ #+ math.log(1 - detector_two_point_background) print("Detector 2 Point: " + str(detector_two_point)) detector_three_point = -math.log(1 - all_detector_three_data.get(run)[block][bcid]) #\ #+ math.log(1 - detector_three_point_background) detector_one_avg += detector_one_point one_count += 1 detector_two_avg += detector_two_point two_count += 1 detector_three_avg += detector_three_point three_count += 1 ''' if bcid_status.get(run)[block][bcid] > 0.0: detector_one_point = -math.log(1 - all_detector_one_data.get(run)[block][bcid]) detector_two_point = -math.log(1 - all_detector_two_data.get(run)[block][bcid]) detector_three_point = -math.log(1 - all_detector_three_data.get(run)[block][bcid]) detector_one_avg += detector_one_point one_count += 1 detector_two_avg += detector_two_point two_count += 1 detector_three_avg += detector_three_point three_count += 1 if one_count != 0: detector_one_avg = detector_one_avg / one_count detector_two_avg = detector_two_avg / two_count detector_three_avg = detector_three_avg / three_count temp_detector_one.get(run)[block_count - 1].append(detector_one_avg) temp_detector_two.get(run)[block_count - 1].append(detector_two_avg) temp_detector_three.get(run)[block_count - 1].append(detector_three_avg) # Remove the last luminosity block from each run, the one that generally spikes temp_detector_one[run] = temp_detector_one[run][:-10] temp_detector_two[run] = temp_detector_two[run][:-10] temp_detector_three[run] = temp_detector_three[run][:-10] # Reassign temp to the original lists all_detector_one_data = temp_detector_one all_detector_two_data = temp_detector_two all_detector_three_data = temp_detector_three # Get integrated luminosity of the detectors integrated_luminosity_one = [] integrated_luminosity_two = [] integrated_luminosity_three = [] luminosity_ratio_two = [] luminosity_ratio_three = [] lumi_blocks = [] block_count1 = 0 lumi_total = 0 lumi_total_two = 0 lumi_total_three = 0 # To keep track of how long each run actually is when plotting run_length_dict = {} for run in sorted(all_detector_one_data.keys()): run_length_dict[run] = 0 for block in range(len(all_detector_one_data.get(run))): block_count1 += 1 for bcid in range(len(all_detector_one_data.get(run)[block])): detector_one_point = all_detector_one_data.get(run)[block][bcid] detector_two_point = all_detector_two_data.get(run)[block][bcid] detector_three_point = all_detector_three_data.get(run)[block][bcid] if detector_one_point != 0.0 and detector_two_point != 0.0 and detector_three_point != 0.0: # Use conversion factor converted_point_one = convert_to_raw_luminosity(11.245, 20.8, detector_one_point) converted_point_two = convert_to_raw_luminosity(11.245, 20.8, detector_two_point) converted_point_three = convert_to_raw_luminosity(11.245, 20.8, detector_three_point) ratio_one_two = converted_point_one / converted_point_two ratio_one_three = converted_point_one / converted_point_three luminosity_ratio_two.append(ratio_one_two) luminosity_ratio_three.append(ratio_one_three) length = block_length.get(run)[block][bcid] lumi_total += converted_point_one * length lumi_total_two += converted_point_two * length lumi_total_three += converted_point_three * length integrated_luminosity_one.append(lumi_total) integrated_luminosity_two.append(lumi_total_two) integrated_luminosity_three.append(lumi_total_three) lumi_blocks.append(block_count1) run_length_dict[run] += 1 # Get percentage difference based off the first block and BCID first_point = detector_one_calibration / detector_two_calibration third_point = detector_one_calibration / detector_three_calibration for index in range(len(integrated_luminosity_one)): luminosity_ratio_two[index] = 100 * ((luminosity_ratio_two[index] / first_point) - 1) luminosity_ratio_three[index] = 100 * ((luminosity_ratio_three[index] / third_point) - 1) # create graph graph = Graph(len(integrated_luminosity_one)) for i, (xx, yy) in enumerate(zip(integrated_luminosity_one, luminosity_ratio_two)): graph.SetPoint(i, float(xx), float(yy)) # set visual attributes # Set temp list for the min and max functions luminosity_ratio = luminosity_ratio_two + luminosity_ratio_three integrated_luminosity = integrated_luminosity_one #integrated_luminosity = lumi_blocks graph.markercolor = 'blue' graph.yaxis.SetTitle("Luminosity Ratio [Percent]") graph.xaxis.SetTitle("Luminosity [Integrated]") graph.yaxis.SetRangeUser(min(luminosity_ratio), max(luminosity_ratio)) graph.xaxis.SetRangeUser(min(integrated_luminosity), max(integrated_luminosity)) # plot with ROOT canvas = Canvas() graph.Draw("AP") canvas.Update() # add points from detectors 1 and 3 # create graph graph1 = Graph(len(integrated_luminosity)) for i, (xx, yy) in enumerate(zip(integrated_luminosity, luminosity_ratio_three)): graph1.SetPoint(i, float(xx), float(yy)) # set visual attributes graph1.linecolor = 'white' # Hides the lines at this time graph1.markercolor = 'red' graph1.Draw("P") canvas.Update() # Draw lines for different runs run_length = 0 total_length = 0 num_run = 0 print"Integrated Luminosity length: ",len(integrated_luminosity) for run in sorted(all_detector_one_data.keys()): print str(run) total_length += run_length_dict[run] print"Total Length: ",total_length #run_length = integrated_luminosity[total_length - 1] print"Run Length", run_length line = ROOT.TLine(run_length, min(luminosity_ratio), run_length, max(luminosity_ratio)) line.Draw() line_label = ROOT.TText(run_length - 30, max(luminosity_ratio) - 1.5, str(run)) line_label.SetTextAngle(90) line_label.SetTextSize(18) line_label.SetTextFont(43) line_label.Draw() label = ROOT.TText(0.2, 0.9, str(name)) label.SetTextFont(43) label.SetTextSize(25) label.SetNDC() label.Draw() canvas.Modified() canvas.Update() wait(True)
def plot_multiple_all_luminosity_block_ratio(all_detector_one_data, all_detector_two_data, all_detector_three_data, background_list, style, name): ''' :param all_detector_one_data: A dictionary of the run name to a list of lists of luminosity blocks :param all_detector_two_data: A dictionary of the run name to a list of lists of luminosity blocks :param style: a string corresponding to a ROOT graphing style, e.g. 'ATLAS' :return: Plot of all the detector data on a graph chronologically according to run number ''' # Set ROOT graph style set_style(str(style)) # Get average value of the rate for each luminosity block temp_detector_one = copy.deepcopy(all_detector_one_data) temp_detector_two = copy.deepcopy(all_detector_two_data) temp_detector_three = copy.deepcopy(all_detector_three_data) print(sorted(all_detector_one_data.keys())) for run in sorted(all_detector_one_data.keys()): block_count = 0 for block in range(len(all_detector_one_data.get(run)) - 1): del temp_detector_one.get(run)[block][:] del temp_detector_two.get(run)[block][:] del temp_detector_three.get(run)[block][:] block_count += 1 detector_one_avg = 0 one_count = 0 detector_two_avg = 0 two_count = 0 detector_three_avg = 0 three_count = 0 for bcid in range(len(all_detector_one_data.get(run)[block])): # Gets the previous BCID luminosity to subtract as the background if run == "286282": detector_one_point_background = all_detector_one_data.get(run)[block][bcid - 1] detector_two_point_background = all_detector_two_data.get(run)[block][bcid - 1] detector_three_point_background = all_detector_three_data.get(run)[block][bcid - 1] print("BCID [N-1]: " + str(detector_one_point_background)) print("BCID [N]: " + str(all_detector_one_data.get(run)[block][bcid])) detector_one_point = -math.log(1 - all_detector_one_data.get(run)[block][bcid]) \ + math.log(1 - detector_one_point_background) detector_three_point = -math.log(1 - all_detector_three_data.get(run)[block][bcid]) \ + math.log(1 - detector_three_point_background) print("Detector 1 Point: " + str(detector_one_point)) detector_two_point = -math.log(1 - all_detector_two_data.get(run)[block][bcid]) \ + math.log(1 - detector_two_point_background) detector_one_avg += detector_one_point one_count += 1 detector_two_avg += detector_two_point two_count += 1 detector_three_avg += detector_three_point three_count += 1 else: detector_one_point = -math.log(1 - all_detector_one_data.get(run)[block][bcid]) detector_two_point = -math.log(1 - all_detector_two_data.get(run)[block][bcid]) detector_three_point = -math.log(1 - all_detector_three_data.get(run)[block][bcid]) detector_one_avg += detector_one_point one_count += 1 detector_two_avg += detector_two_point two_count += 1 detector_three_avg += detector_three_point three_count += 1 if one_count != 0: detector_one_avg = detector_one_avg / one_count detector_two_avg = detector_two_avg / two_count detector_three_avg = detector_three_avg / three_count temp_detector_one.get(run)[block_count - 1].append(detector_one_avg) temp_detector_two.get(run)[block_count - 1].append(detector_two_avg) temp_detector_three.get(run)[block_count - 1].append(detector_three_avg) # Remove the last luminosity block from each run, the one that generally spikes temp_detector_one[run] = temp_detector_one[run][:-10] temp_detector_two[run] = temp_detector_two[run][:-10] temp_detector_three[run] = temp_detector_three[run][:-10] # Reassign temp to the original lists all_detector_one_data = temp_detector_one all_detector_two_data = temp_detector_two all_detector_three_data = temp_detector_three # Get ratio of the detectors 1 and 2 luminosity_ratio = [] lumi_blocks = [] block_count1 = 0 for run in sorted(all_detector_one_data.keys()): for block in range(len(all_detector_one_data.get(run))): block_count1 += 1 for bcid in range(len(all_detector_one_data.get(run)[block])): detector_one_point = all_detector_one_data.get(run)[block][bcid] detector_two_point = all_detector_two_data.get(run)[block][bcid] # Check if the blocks are zero if detector_one_point != 0.0 and detector_two_point != 0.0: ratio = detector_one_point / detector_two_point luminosity_ratio.append(ratio) lumi_blocks.append(block_count1) # Get ratio of the detectors 1 and 3 luminosity_ratio_1 = [] lumi_blocks_1 = [] block_count2 = 0 for run in sorted(all_detector_one_data.keys()): for block in range(len(all_detector_one_data.get(run))): block_count2 += 1 for bcid in range(len(all_detector_one_data.get(run)[block])): detector_one_point = all_detector_one_data.get(run)[block][bcid] detector_three_point = all_detector_three_data.get(run)[block][bcid] # Check if the blocks are zero if detector_one_point != 0.0 and detector_three_point != 0.0: ratio = detector_one_point / detector_three_point luminosity_ratio_1.append(ratio) lumi_blocks_1.append(block_count2) # Get percentage difference based off the first block and BCID first_point = luminosity_ratio[0] first_point_1 = luminosity_ratio_1[0] for index in range(len(luminosity_ratio)): luminosity_ratio[index] = 100 * ((luminosity_ratio[index] / first_point) - 1) for index in range(len(luminosity_ratio_1)): luminosity_ratio_1[index] = 100 * ((luminosity_ratio_1[index] / first_point_1) - 1) # create graph graph = Graph(len(lumi_blocks)) for i, (xx, yy) in enumerate(zip(lumi_blocks, luminosity_ratio)): graph.SetPoint(i, float(xx), float(yy)) # set visual attributes graph.markercolor = 'blue' graph.xaxis.SetTitle("Luminosity Block") graph.yaxis.SetTitle("Luminosity [Average Percent Ratio]") graph.xaxis.SetRangeUser(min(lumi_blocks), max(lumi_blocks)) graph.yaxis.SetRangeUser(min(luminosity_ratio), max(luminosity_ratio)) # plot with ROOT canvas = Canvas() graph.Draw("AP") canvas.Update() # add points from detectors 1 and 3 # create graph graph1 = Graph(len(lumi_blocks_1)) for i, (xx, yy) in enumerate(zip(lumi_blocks_1, luminosity_ratio_1)): graph1.SetPoint(i, float(xx), float(yy)) # set visual attributes graph1.linecolor = 'white' # Hides the lines at this time graph1.markercolor = 'red' # graph1.xaxis.SetRangeUser(min(lumi_blocks_1), max(lumi_blocks_1)) # graph1.yaxis.SetRangeUser(min(luminosity_ratio_1), max(luminosity_ratio_1)) graph1.Draw("P") canvas.Update() # Draw lines for different runs run_length = 0 for run in sorted(all_detector_one_data.keys()): run_length += len(all_detector_one_data.get(run)) line = ROOT.TLine(run_length, min(luminosity_ratio), run_length, max(luminosity_ratio)) line.Draw() line_label = ROOT.TText(run_length - 30, max(luminosity_ratio) - 1.5, str(run)) line_label.SetTextAngle(90) line_label.SetTextSize(18) line_label.SetTextFont(43) line_label.Draw() label = ROOT.TText(0.7, 0.8, str(name)) label.SetTextFont(43) label.SetTextSize(25) label.SetNDC() label.Draw() canvas.Modified() canvas.Update() wait(True)