def plot_raw_detector_vs_detector(detector_one_data, detector_two_data, style, name): # Set ROOT graph style set_style(str(style)) detector_one_list = [] detector_two_list = [] for block in range(len(detector_one_data)): for bcid in range(len(detector_one_data[block])): detector_one_list.append(detector_one_data[block][bcid]) detector_two_list.append(detector_two_data[block][bcid]) # create graph graph = Graph(len(detector_one_list)) for i, (xx, yy) in enumerate(zip(detector_one_list, detector_two_list)): graph.SetPoint(i, float(xx), float(yy)) # set visual attributes graph.markercolor = 'blue' graph.xaxis.SetTitle("BCM V [Raw Rate]") graph.yaxis.SetTitle("LUCID BI [Raw Rate]") graph.xaxis.SetRangeUser(0, 1) graph.yaxis.SetRangeUser(0, 1) # plot with ROOT canvas = Canvas() graph.Draw("AP") label = ROOT.TText(0.6, 0.9, str(name)) label.SetTextFont(43) label.SetTextSize(25) label.SetNDC() label.Draw() canvas.Modified() canvas.Update() wait(True)
def luminosity_vs_time(timing_list, luminosity_list, style, run_name): ''' :param timing_list: Python list containing the timing data :param luminosity_list: Python list containing the luminosity data :param style: ROOT style in string, such as 'ATLAS' :return: ''' # Set ROOT graph style set_style(str(style)) # create graph graph = Graph(len(timing_list)) for i, (xx, yy) in enumerate(zip(timing_list, luminosity_list)): graph.SetPoint(i, xx, yy) # set visual attributes graph.markercolor = 'blue' graph.xaxis.SetTitle("Time") graph.yaxis.SetTitle("Luminosity") graph.xaxis.SetRangeUser(min(timing_list), max(timing_list)) graph.yaxis.SetRangeUser(min(luminosity_list), max(luminosity_list)) # plot with ROOT canvas = Canvas() graph.Draw("AP") label = ROOT.TText(0.8, 0.9, str(run_name)) label.SetTextFont(43) label.SetTextSize(25) label.SetNDC() label.Draw() canvas.Modified() canvas.Update() wait(True)
def init_palette(): from rootpy.plotting.style import set_style, get_style atlas = get_style("ATLAS") atlas.SetPalette(51) set_style(atlas) return True
def plot_percent_luminosity_ratio(detector_one_data, detector_two_data, style, run_name): ''' :param detector_one_data: Data from one detector type, such as ATLAS' LUCID, in a list of lists, every entry is one luminsoity block, with the luminosity block being a list of BCID data, assumed to be same length as detector_two_data :param detector_two_data: Data from another detector type, such as ATLAS' LUCID, in a list of lists, every entry is one luminosity block, with the luminosity block being a list of BCID data, assumed to be same length as detector_one_data :param style: The ROOT style for the graph, generally 'ATLAS' :return: ROOT plots of the ratio of luminosities over the luminosity, as percetnage difference from first data point ''' # Set ROOT graph style set_style(str(style)) print("Number of Luminosity Blocks included: " + str(len(detector_one_data))) # Get ratio of the detectors luminosity_ratio = [] lumi_blocks = [] for block in range(len(detector_one_data)): for bcid in range(len(detector_one_data[block])): detector_one_point = detector_one_data[block][bcid] detector_two_point = detector_two_data[block][bcid] # Check if the blocks are zero if detector_one_point != 0.0 and detector_two_point != 0.0: ratio = -math.log(1 - detector_one_point) / -math.log(1 - detector_two_point) luminosity_ratio.append(ratio) lumi_blocks.append(block) # Get percentage difference based off the first block and BCID first_point = luminosity_ratio[0] for index in range(len(luminosity_ratio)): luminosity_ratio[index] = (luminosity_ratio[index] / first_point) - 1 # create graph graph = Graph(len(lumi_blocks), title=run_name) 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 [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") label = ROOT.TText(0.8, 0.9, str(run_name)) label.SetTextFont(43) label.SetTextSize(25) label.SetNDC() label.Draw() canvas.Modified() canvas.Update() wait(True)
def SetupATLAS(): rootpy.log.basic_config_colorized() #use latex for text rc('text', usetex=True) # set the style style = get_style('ATLAS') style.SetEndErrorSize(3) set_style(style) set_style('ATLAS', mpl=True) rc('font', family='sans-serif', weight='medium', size=16) rc('legend', fontsize=16)
def main(parameters): style = get_style('CMSTDR') style.SetTitleSize(0.07, "XYZ") style.SetLegendBorderSize(0) style.SetLegendFillColor(0) style.SetLegendFont(43) style.SetTextSize(25) set_style(style) input_file = parameters.input_file plot_distributions(input_file, parameters.distribution_plots) plot_comparisons(input_file, parameters.comparison_plots)
def main(parameters): set_style(style_rate) l1_data = read(parameters.input_file, parameters.input_tree) l1_data = root2array( parameters.input_file, parameters.input_tree, branches=['cl3d_pt', 'cl3d_eta', 'cl3d_phi'], object_selection={'cl3d_pt>0': ['cl3d_pt', 'cl3d_eta', 'cl3d_phi']}) rates = rate(l1_data['cl3d_pt'], parameters.thresholds, total_events=l1_data.shape[0]) rates.Scale(parameters.scale_factor) plot_rate.plot(parameters.plot_params, rates)
def set_hsg4_style(shape='square'): style = get_style('ATLAS', shape=shape) #style.SetFrameLineWidth(2) #style.SetLineWidth(2) #style.SetTitleYOffset(1.8) #style.SetTickLength(0.04, 'X') #style.SetTickLength(0.02, 'Y') # custom HSG4 modifications # style.SetPadTopMargin(0.06) style.SetPadLeftMargin(0.16) style.SetTitleYOffset(1.6) style.SetHistTopMargin(0.) style.SetHatchesLineWidth(1) style.SetHatchesSpacing(1) set_style(style)
def set_hsg4_style(shape='square'): style = get_style('ATLAS', shape=shape) #style.SetFrameLineWidth(2) #style.SetLineWidth(2) #style.SetTitleYOffset(1.8) #style.SetTickLength(0.04, 'X') #style.SetTickLength(0.02, 'Y') # custom HSG4 modifications # style.SetPadTopMargin(0.06) style.SetPadLeftMargin(0.16) style.SetTitleYOffset(1.6) style.SetHistTopMargin(0.) style.SetHatchesLineWidth(1) style.SetHatchesSpacing(1) ROOT.TGaxis.SetMaxDigits(4) set_style(style)
def main(parameters): set_style(style_turnon) l1_variables = [parameters.l1_pt] if parameters.identification_inputs != None: l1_variables = [parameters.l1_pt] + parameters.identification_inputs data = read_and_match(parameters.input_file, parameters.input_tree, ref_variables=[parameters.reference_pt], l1_variables=l1_variables, selection=parameters.reference_selection, matching=parameters.matching) ref_pt = data[parameters.reference_pt] l1_pt = data[parameters.l1_pt] identification_inputs = data[parameters.identification_inputs]\ .view((np.float32, len(parameters.identification_inputs))) efficiency = turnon(ref_pt, l1_pt, threshold=parameters.threshold, selection_function=parameters.identification_function, selection_inputs=identification_inputs) plot_efficiency.plot(parameters.plot_params, efficiency)
def luminosity_block_log_time(luminosity_list, style): ''' :param timing_list: Python list containing the timing data :param luminosity_list: Python list containing the luminosity data :param style: ROOT style in string, such as 'ATLAS' :return: Graph of the luminosity over a single block ''' # Set ROOT graph style set_style(str(style)) luminosity_ratio = [] for bcid in range(len(luminosity_list)): detector_one_point = luminosity_list[bcid] # Check if the blocks are zero if detector_one_point != 0.0: ratio = -math.log(1 - detector_one_point) luminosity_ratio.append(ratio) # create graph graph = Graph(len(luminosity_ratio)) for i, (xx, yy) in enumerate(zip(range(len(luminosity_ratio)), luminosity_ratio)): graph.SetPoint(i, xx, yy) # set visual attributes graph.markercolor = 'blue' graph.xaxis.SetTitle("Time") graph.yaxis.SetTitle("-Ln(1 - Rate) [Single Detector]") graph.xaxis.SetRangeUser(0, 3564) graph.yaxis.SetRangeUser(min(luminosity_ratio), max(luminosity_ratio)) # plot with ROOT canvas = Canvas() graph.Draw("AP") wait(True)
def main(parameters): set_style(style_turnon) ref_pt, l1_pt = read_and_match(parameters.input_file, parameters.input_tree) efficiency = turnon(ref_pt, l1_pt, threshold=parameters.threshold) plot_efficiency.plot(parameters.plot_params, efficiency)
import ROOT ROOT.gROOT.SetBatch(True) style = get_style('ATLAS') style.SetEndErrorSize(3) titlesize = 25 style.SetTitleSize(titlesize, "x") style.SetTitleSize(titlesize, "y") style.SetTitleYOffset(1) #style.SetTitleXOffset(3) #style.SetPadTopMargin(0.0) #style.SetPadRightMargin(0.05) #style.SetPadBottomMargin(0.2) #style.SetPadLeftMargin(0.15) #style.setPalette(51,0) set_style(style) labelmargin = 0.18 #Labeling #==================== EDIT THESE ========================# lumipb = 12300 #pb-1 (10 fb-1) lumifb = lumipb / 1000.0 sqrts = 13 signalprocess = 'Two Lepton' signaljets = 'with ISR' yminimum = 1e0 ymaximum = 1e4 #jetcut_switch = True
import ROOT import numpy as np import rootpy rootpy.log.basic_config_colorized() from rootpy.plotting import Hist, HistStack, Legend, Canvas from rootpy.plotting.style import get_style, set_style from rootpy.plotting.utils import get_limits from rootpy.interactive import wait import rootpy.plotting.root2matplotlib as rplt import matplotlib.pyplot as plt from matplotlib.ticker import AutoMinorLocator, MultipleLocator # set the style style = get_style('ATLAS') style.SetEndErrorSize(3) set_style(style) # set the random seed ROOT.gRandom.SetSeed(42) np.random.seed(42) # signal distribution signal = 126 + 10 * np.random.randn(100) signal_obs = 126 + 10 * np.random.randn(100) # create histograms h1 = Hist(30, 40, 200, title='Background', markersize=0) h2 = h1.Clone(title='Signal') h3 = h1.Clone(title='Data') h3.markersize = 1.2
style = get_style('ATLAS', shape='square') #style.SetFrameLineWidth(2) #style.SetLineWidth(2) #style.SetTitleYOffset(1.8) #style.SetTickLength(0.04, 'X') #style.SetTickLength(0.02, 'Y') # custom HSG4 modifications style.SetPadLeftMargin(0.16) style.SetTitleYOffset(1.6) style.SetHistTopMargin(0.) style.SetHatchesLineWidth(1) style.SetHatchesSpacing(1) set_style(style) ROOT.TGaxis.SetMaxDigits(4) from rootpy.utils.silence import silence_sout_serr with silence_sout_serr(): from rootpy.stats import mute_roostats; mute_roostats() import yellowhiggs log.info("using yellowhiggs {0}".format(yellowhiggs.__version__)) CONST_PARAMS = [ 'Lumi', 'mu_XS8_ggH', 'mu_XS7_ggH', 'mu_XS8_VBF',
from rootpy.plotting import Hist from ROOT import Double import numpy as np from math import pi import matplotlib.pyplot as plt from matplotlib.ticker import NullFormatter from matplotlib.ticker import AutoMinorLocator, MaxNLocator from extract_yield import extract_yield #import rootnotes #%config InlineBackend.figure_format = 'png' from rootpy.plotting.style import set_style set_style('ATLAS', mpl=True) import matplotlib as mpl # does not handle unicode minus properly! mpl.rcParams['axes.unicode_minus'] = False def project_onto_deta_with_sections(hist_2D): hists = [] # near side ridge tmp = asrootpy(hist_2D.ProjectionY("nearside_px", hist_2D.get_xaxis().FindBin(-pi/3), hist_2D.get_xaxis().FindBin(pi/3))) scaling = (hist_2D.get_xaxis().FindBin(pi/3) - hist_2D.get_xaxis().FindBin(-pi/3) + 1) tmp.Scale(1.0/scaling) tmp.SetTitle('near side')
def plot_percent_luminosity_ratio_sum(detector_one_data, detector_two_data, style, run_name): ''' :param detector_one_data: Data from one detector type, such as ATLAS' LUCID, in a list of lists, every entry is one luminsoity block, with the luminosity block being a list of BCID data, assumed to be same length as detector_two_data :param detector_two_data: Data from another detector type, such as ATLAS' LUCID, in a list of lists, every entry is one luminosity block, with the luminosity block being a list of BCID data, assumed to be same length as detector_one_data :param style: The ROOT style for the graph, generally 'ATLAS' :return: ROOT plots of the ratio of luminosity sums over the luminosity, as percentage difference from first data point ''' # Set ROOT graph style set_style(str(style)) print("Number of Luminosity Blocks included: " + str(len(detector_one_data))) # Get average value of the rate for each luminosity block temp_detector_one = [[] for _ in xrange(len(detector_one_data))] temp_detector_two = [[] for _ in xrange(len(detector_one_data))] for block in range(len(detector_one_data)): detector_one_avg = 0 one_count = 0 detector_two_avg = 0 two_count = 0 for bcid in range(len(detector_one_data[block])): detector_one_point = detector_one_data[block][bcid] detector_two_point = detector_two_data[block][bcid] detector_one_avg += detector_one_point one_count += 1 detector_two_avg += detector_two_point two_count += 1 if one_count != 0: detector_one_avg = detector_one_avg / one_count detector_two_avg = detector_two_avg / two_count temp_detector_one[block].append(detector_one_avg) temp_detector_two[block].append(detector_two_avg) # Reassign temp to the original lists detector_one_data = temp_detector_one detector_two_data = temp_detector_two # Get ratio of the detectors luminosity_ratio = [] lumi_blocks = [] for block in range(len(detector_one_data)): for bcid in range(len(detector_one_data[block])): detector_one_point = detector_one_data[block][bcid] detector_two_point = detector_two_data[block][bcid] # Check if the blocks are zero if detector_one_point != 0.0 and detector_two_point != 0.0: ratio = -math.log(1 - detector_one_point) / -math.log(1 - detector_two_point) luminosity_ratio.append(ratio) lumi_blocks.append(block) # Get percentage difference based off the first block and BCID first_point = luminosity_ratio[0] for index in range(len(luminosity_ratio)): luminosity_ratio[index] = (luminosity_ratio[index] / first_point) - 1 # Delete last point, when the beams are being shut down and there are massive spikes luminosity_ratio = luminosity_ratio[:-1] lumi_blocks = lumi_blocks[:-1] # create graph graph = Graph(len(lumi_blocks), title=run_name) 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") label = ROOT.TText(0.8, 0.9, str(run_name)) label.SetTextFont(43) label.SetTextSize(25) label.SetNDC() label.Draw() canvas.Modified() canvas.Update() wait(True)
def plot_normalized_luminosity_ratio(detector_one_data, detector_two_data, style, run_name): ''' :param detector_one_data: Data from one detector type, such as ATLAS' LUCID, in a list of lists, every entry is one luminsoity block, with the luminosity block being a list of BCID data, assumed to be same length as detector_two_data :param detector_two_data: Data from another detector type, such as ATLAS' LUCID, in a list of lists, every entry is one luminosity block, with the luminosity block being a list of BCID data, assumed to be same length as detector_one_data :param style: The ROOT style for the graph, generally 'ATLAS' :return: ROOT plots of the ratio of luminosities over the luminosity, normalized to one ''' # Set ROOT graph style set_style(str(style)) print("Number of Luminosity Blocks included: " + str(len(detector_one_data))) # Get ratio of the detectors luminosity_ratio = [] lumi_blocks = [] for block in range(len(detector_one_data)): for bcid in range(len(detector_one_data[block])): detector_one_point = detector_one_data[block][bcid] detector_two_point = detector_two_data[block][bcid] # Check if the blocks are zero if detector_one_point != 0.0 and detector_two_point != 0.0: ratio = -math.log(1 - detector_one_point) / -math.log(1 - detector_two_point) luminosity_ratio.append(ratio) lumi_blocks.append(block) # Normalize the ratios def normalize(x, x_min, x_max): top = x - x_min bottom = x_max - x_min return top / bottom max_ratio = max(luminosity_ratio) min_ratio = min(luminosity_ratio) print("Max ratio: " + str(max_ratio)) print("Min Ratio: " + str(min_ratio)) for ratio_entry in range(len(luminosity_ratio)): luminosity_ratio[ratio_entry] = normalize(luminosity_ratio[ratio_entry], x_max=max_ratio, x_min=min_ratio) # create graph graph = Graph(len(lumi_blocks), title=run_name) 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 [Normalized 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") label = ROOT.TText(0.8, 0.9, str(run_name)) label.SetTextFont(43) label.SetTextSize(25) label.SetNDC() label.Draw() canvas.Modified() canvas.Update() wait(True)
#!/bin/env python2 import optparse,csv,sys sys.argv.append("-b") from ROOT import * import rootpy as rpy from rootpy.plotting.style import set_style, get_style import os atlas = get_style('ATLAS') atlas.SetPalette(51) set_style(atlas) sys.argv = sys.argv[:-1] topmass = 173.34 def parse_argv(): parser = optparse.OptionParser() parser.add_option("--lumi", help="luminosity", default=5, type=int) #parser.add_option("--z-label", help="z axis title", default="significance in optimal cut") parser.add_option("--text-file", help="text csv file", default=None, type=str) parser.add_option("--outdir", help="outfile directory", default="plots") parser.add_option("--outfilebase", help="outfile base name", default="output") parser.add_option("--g-min", help="min gluino mass", default=800, type=float) parser.add_option("--g-max", help="max gluino mass", default=2000, type=float) parser.add_option("--l-min", help="min lsp mass", default=0, type=float) parser.add_option("--l-max", help="max lsp mass", default=1300, type=float) parser.add_option("--bin-width", help="bin width", default=100, type=float) parser.add_option("--x-dim", help="x dimension of figure", default=800, type=float) parser.add_option("--y-dim", help="y dimension of figure", default=600, type=float)
def __exit__(self, exception_type, exception_value, traceback): """Override the __exit__ method to reset to the original gStyle. """ set_style(self.old_gStyle)
def __enter__(self): """Override the __enter__ method to remember the current gStyle. """ self.old_gStyle = get_style(ROOT.gStyle.name) set_style(self) return self
def fithist(data,weightdata,central,eff=eff,plotDir=None): plotting = not (plotDir==None) if plotting and not os.path.exists(plotDir): print '== Making folder '+options.plotDir+' ==' os.makedirs(options.plotDir) if plotting: try: from rootpy.plotting.style import set_style, get_style print '== Using ATLAS style ==' atlas = get_style('ATLAS') atlas.SetPalette(51) set_style(atlas) set_style('ATLAS',mpl=True) except ImportError: print '== Not using ATLAS style (Can\'t import rootpy.) ==' if plotting: n,bins,patches = plt.hist(data,normed=True,bins=100,weights=weightdata,facecolor='b',histtype='stepfilled') weightdata = weightdata/sum(weightdata) if central == 'absolute_median' or central == 'mode': if eff<0 or eff>1: raise RuntimeError('In order to use absolute IQR, you have to provide the reconstruction efficiency. Use --eff option.') (mu,mu_err,sigma,sigma_err,upper_quantile,lower_quantile,err) = distribution_values(data,weightdata,central,eff=eff) if plotting: plt.plot((mu,mu),(0,plt.ylim()[1]),'r--',linewidth=2) height = 0.607*max(n) #height at x=1*sigma in normal distribution if lower_quantile>float('-inf'): plt.plot((lower_quantile,upper_quantile),(height,height),'r--',linewidth=2) plt.plot((lower_quantile,lower_quantile),(height-0.02,height+0.02),'r-',linewidth=2) else: plt.plot((mu,upper_quantile),(height,height),'r--',linewidth=2) plt.plot((upper_quantile,upper_quantile),(height-0.02,height+0.02),'r-',linewidth=2) if central == 'median': (mu,mu_err,sigma,sigma_err,upper_quantile,lower_quantile) = distribution_values(data,weightdata,central) if plotting: plt.plot((mu,mu),(0,plt.ylim()[1]),'r--',linewidth=2) height = 0.607*max(n) #height at x=1*sigma in normal distribution plt.plot((lower_quantile,upper_quantile),(height,height),'r--',linewidth=2) plt.plot((lower_quantile,lower_quantile),(height-0.02,height+0.02),'r-',linewidth=2) plt.plot((upper_quantile,upper_quantile),(height-0.02,height+0.02),'r-',linewidth=2) if central == 'mean': (mu,mu_err,sigma,sigma_err) = distribution_values(data,weightdata,central) if plotting: gfunc = norm y = gfunc.pdf( bins, mu, sigma) plt.plot((mu,mu),(0,gfunc.pdf(mu,mu,sigma)),'r--',linewidth=2) l = plt.plot(bins, y, 'r--', linewidth=2) if central == 'trimmed': (mu,mu_err,sigma,sigma_err,lower,upper) = distribution_values(data,weightdata,central) if plotting: #print mu,sigma,ptbin gfunc = norm y = gfunc.pdf(bins, mu, sigma) plt.plot((mu,mu),(0,gfunc.pdf(mu,mu,sigma)),'r--',linewidth=2) newbins = bins[all([bins>lower,bins<upper],axis=0)] newy = y[all([bins>lower,bins<upper],axis=0)] l = plt.plot(newbins, newy, 'r--', linewidth=2) if plotting: plt.xlabel('$p_T^{reco}/p_T^{true}$') plt.ylabel('a.u.') plt.savefig(plotDir+'/'+'histfit_'+central+'.png') plt.close() #avgres.append(mu) #avgres_errs.append(mu_err) #sigmaRs.append(sigma) #sigmaR_errs.append(sigma_err) return mu,mu_err,sigma,sigma_err
def init_palette(): from rootpy.plotting.style import set_style, get_style atlas = get_style('ATLAS') atlas.SetPalette(51) set_style(atlas) return 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)
# parse the arguments, throw errors if missing any args = parser.parse_args() import ROOT ROOT.PyConfig.IgnoreCommandLineOptions = True ROOT.gROOT.SetBatch(args.batch_mode) import numpy as np from rootpy.plotting.style import set_style, get_style atlas = get_style('ATLAS') atlas.SetPalette(51) set_style(atlas) summary = json.load(file(args.summary)) plot_array = { 'sig': [r['significance'] for r in summary], 'signal': [r['signal'] for r in summary], 'bkgd': [r['bkgd'] for r in summary], 'mgluino': [r['m_gluino'] for r in summary], 'mlsp': [r['m_lsp'] for r in summary], 'ratio': [r['ratio'] for r in summary], } # load in supercuts with open(args.supercuts) as f: supercuts = json.load(f)
def plot_all_luminosity_block_ratio(all_detector_one_data, all_detector_two_data, background_list, status_data, style, name, detector_one_calibration, detector_two_calibration): ''' :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) # print(sorted(all_detector_one_data.keys())) for run in sorted(all_detector_one_data.keys()): block_count = 0 print"Starting run", run 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][:] block_count += 1 detector_one_avg = 0 one_count = 0 detector_two_avg = 0 two_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 status_data.get(run)[block][bcid - 1] <= 0.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] print("BCID [N-1] Stability: " + str(status_data.get(run)[block][bcid - 1])) else: print("No empty BCID to subtract background from") if all_detector_one_data.get(run)[block][bcid] < 1 and all_detector_two_data.get(run)[block][bcid] < 1: print("BCID [N] Stability: " + str(status_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) 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_one_avg += detector_one_point one_count += 1 detector_two_avg += detector_two_point two_count += 1 else: #print(" RUN: " + str(run) + " END") #print(all_detector_one_data.get(run)[block][bcid]) # Checking if the status is stable if 1 > all_detector_one_data.get(run)[block][bcid] > 0.0 and 1 > all_detector_two_data.get(run)[block][bcid] > 0.0\ and status_data.get(run)[block][bcid] > 0.0: #print("Value of Block, BCID: " + str(block) + " " + str(bcid) + " " + str(all_detector_one_data.get(run)[block][bcid])) 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_one_avg += detector_one_point one_count += 1 detector_two_avg += detector_two_point two_count += 1 if one_count != 0: detector_one_avg = detector_one_avg / one_count detector_two_avg = detector_two_avg / two_count if run == "286282": print("One Average: " + str(detector_one_avg)) temp_detector_one.get(run)[block_count - 1].append(detector_one_avg) temp_detector_two.get(run)[block_count - 1].append(detector_two_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] # Reassign temp to the original lists all_detector_one_data = temp_detector_one all_detector_two_data = temp_detector_two # Get ratio of the detectors 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 or detector_two_point != 0.0: ratio = detector_one_point / detector_two_point luminosity_ratio.append(ratio) lumi_blocks.append(block_count1) else: print("Run", str(run), " Block:", str(block), "One:", str(detector_one_point), "Two:", str(detector_two_point)) print("Length lumi_blocks: " + str(len(lumi_blocks))) print("length lumi_ratio: " + str((len(luminosity_ratio)))) # Get percentage difference based off the first block and BCID first_point = detector_one_calibration / detector_two_calibration for index in range(len(luminosity_ratio)): luminosity_ratio[index] = 100 * ((luminosity_ratio[index] / first_point) - 1) # create graph graph = Graph(len(lumi_blocks)) for i, (xx, yy) in enumerate(zip(lumi_blocks, luminosity_ratio)): #print (xx, yy) 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)) graph.yaxis.SetRangeUser(-5, 5) # plot with ROOT canvas = Canvas() graph.Draw("AP") # Draw lines for different runs run_length = 0 for run in sorted(all_detector_one_data.keys()): #print("Length of Run " + str(run) + ": " + str(len(all_detector_one_data.get(run)))) run_length += len(all_detector_one_data.get(run)) line = ROOT.TLine(run_length, -5, #min(luminosity_ratio), run_length, 5,) # max(luminosity_ratio)) line.Draw() line_label = ROOT.TText(run_length - 30, 5 -1.5, str(run)) #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)
===================== rootpy implements an additional histogram bin merging method making it easier to merge bins in specified windows of bin indices. """ print __doc__ import ROOT from rootpy.interactive import wait from rootpy.plotting import Canvas, Hist, Hist2D from rootpy.plotting.style import set_style import numpy as np from random import randint, choice import time import os set_style('ATLAS') BATCH = ROOT.gROOT.IsBatch() def random_bin_merge(h): # randomly choose axis if h.GetDimension() > 1: axis = choice([ axis for axis in range(h.GetDimension()) if h.nbins(axis) > 1]) else: axis = 0 # randomly choose starting bin start = randint(1, h.nbins(axis) - 1) end = randint(start + 1, min(start + 5 * h.GetDimension(), h.nbins(axis))) return h.merge_bins([(start, end)], axis=axis)
SEE ALSO ROOT <http://root.cern.ch> Highslide <http://highslide.com/> 2011-02-16 """ #------------------------------------------------------------------------------ import os, sys, getopt import time import re import math import ROOT from rootpy.plotting.style import set_style set_style('ATLAS', shape='rect') ROOT.gROOT.SetBatch(True) # try: # import rootlogon # your custom ROOT options, comment-out this if you don't have one # except: # print 'Could not import rootlogon' ROOT.gErrorIgnoreLevel = 1001 path_of_this_file = os.path.abspath( __file__ ) dir_of_this_file = os.path.dirname(os.path.abspath( __file__ )) #------------------------------------------------------------------------------ ## global options highslide_path = os.path.join(dir_of_this_file, 'highslide-4.1.9/highslide')
from pprint import pprint from numpy import array from optparse import OptionParser import matplotlib.pyplot as plt from matplotlib.ticker import AutoMinorLocator, MultipleLocator os.environ[ 'MPLCONFIGDIR' ] = '/tmp/' #to get matplotlib to work import pdb atlas_style = False try: from rootpy.plotting.style import set_style, get_style print 'ATLAS style!' atlas = get_style('ATLAS') atlas.SetPalette(51) set_style(atlas) set_style('ATLAS',mpl=True) atlas_style=True except ImportError: print 'Not using ATLAS style (Can\'t import rootpy. Try setting up a virtual environment.)' parser = OptionParser() # job configuration parser.add_option("--submitDir", help="Directory containing output files",type=str, default="../output_absolute") parser.add_option("--plotDir", help="Directory containing plots",type=str, default="../plots") parser.add_option("--collections", help="file containing jet collection identifiers and labels",type=str, default="collections") #parser.add_option("--plotlabel", help="label going on every plot (only if using ATLAS style)",type=str, default='$\mathregular{\sqrt{s}=13}$ TeV, $\mathregular{<\mu>=20}$') parser.add_option("--mu",help="Name of thing to plot against. Doesn't have to be mu.",type=str,default="mus") parser.add_option("--mu_label",help="Label of x-axis value. Doesn't have to be mu.",type=str,default="<$\mu$>") (options, args) = parser.parse_args()
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)
os.getenv('CMSSW_BASE'), 'src/FireROOT/Analysis/python/outputs/rootfiles/additionalVariables.root') outdir = os.path.join(os.getenv('CMSSW_BASE'), 'src/FireROOT/Analysis/python/etc/plots/massXX') if not os.path.isdir(outdir): os.makedirs(outdir) # for d in ['ch2mu2e', 'ch4mu']: # _o = os.path.join(outdir, d) # if not os.path.isdir(_o): # os.makedirs(_o) sty = MyStyle() sty.SetOptStat(0) sty.SetStatX(0.9) sty.SetStatY(0.9) sty.SetStatTextColor(ROOT.kRed) sty.SetStatBorderSize(0) set_style(sty) def plot_4mu(masstag): mxx = masstag.split('_')[0].split('-')[1] ma = masstag.split('_')[1].split('-')[1].replace('p', '.') lxy = masstag.split('_')[2].split('-')[1].replace('p', '.') h = getattr(getattr(f.ch4mu.sig, masstag), 'invm_e{}'.format(mxx)) h.color = 'blue' h.linewidth = 2 h.drawstyle = 'hist' h.axis(0).SetTitle('lepton-jet pair invariant mass [GeV]') _fit = ROOT.TF1('_fit', 'gaus', float(mxx) / 10 * 7, float(mxx) / 10 * 13) _fit.SetLineColor(ROOT.kRed) _fit.SetLineWidth(2)
import ROOT import sys from eff_tools.auxiliary import aux from eff_tools.eff_plotting_tools import RejectionCurve from eff_tools.eff_plotting_tools import RoCcurve from eff_tools.eff_plotting_tools import SvsB_Perf_Canvas from eff_tools.eff_plotting_tools import DiscriVar_Canvas from eff_tools.eff_plotting_tools import EfficiencyPlot from rootpy.extern import ordereddict from rootpy.plotting.style import set_style ROOT.gROOT.SetBatch(True) set_style('ATLAS', shape='rect') #-----> Open the rootfiles files = ordereddict.OrderedDict() files["Z_14TeV_all"] = ROOT.TFile( "efficiencies/efficiencies_presel_Ztautau_14TeV_all_v16.root") files["Z_14TeV_mu20"] = ROOT.TFile( "efficiencies/efficiencies_presel_Ztautau_14TeV_mu20_v16.root") files["Z_14TeV_mu40"] = ROOT.TFile( "efficiencies/efficiencies_presel_Ztautau_14TeV_mu40_v16.root") files["Z_14TeV_mu60"] = ROOT.TFile( "efficiencies/efficiencies_presel_Ztautau_14TeV_mu60_v16.root") files["Z_14TeV_mu80"] = ROOT.TFile( "efficiencies/efficiencies_presel_Ztautau_14TeV_mu80_v16.root") files["bkg_JF_14TeV_mu40"] = ROOT.TFile( "efficiencies/efficiencies_presel_JF17_14TeV_mu40_v16.root")
import os from rootpy.io import root_open from rootpy.plotting.style import set_style from rootpy.plotting import Hist, Legend, Canvas from FireROOT.Analysis.Utils import * fn = os.path.join( os.getenv('CMSSW_BASE'), 'src/FireROOT/Analysis/python/outputs/rootfiles/centralSig/validategen.root' ) outdir = os.path.join(os.getenv('CMSSW_BASE'), 'src/FireROOT/Analysis/python/etc/plots/validategen') if not os.path.isdir(outdir): os.makedirs(outdir) set_style(MyStyle()) f = root_open(fn) ################################################# # dark photon lxy c = Canvas() masstag = 'mXX-1000_mA-1p2' mxx, ma = masstag.split('_') mxx = mxx.split('-')[-1] ma = ma.split('-')[1].replace('p', '.') massdir = getattr(f.ch4mu, masstag) lxytags = [x.name for x in massdir.keys()] # lxy-0p3_ctau-0p0025
# # #==================================================================================================================== import matplotlib.pyplot as plt from rootpy.plotting.style import get_style, set_style import numpy as np import matplotlib as mpl # # #==================================================================================================================== set_style('lhcb', mpl=True) #----------------------------------- G_F = 1.11e+1 #Fermi's constant @ M_b in TeV^-2 V_ts=39.4e-3 err_Vts =2.3e-3 V_tb=1.01190 err_Vtb=0.025 err_ts_tb = (V_ts*V_tb)*((err_Vtb/V_tb)**2+(err_Vts/V_ts)**2)**(.5) m= 0.85 g=1 c10_SM= -4.3 alpha_EM = 1/137 m_Bs=5366.28e-6 #TeV err_Bs= 0.22e-6 #t_Bs=1.505e-12 #sec t_Bs= 2.25e+15 # TeV^-1 factor = 16*np.pi**3 m_tau=1776.86e-6 err_m_tau=0.12e-6 f_Bs= 0.198e-3 err_f_Bs= 0.0083017e-3 #----------------------------------- #-----------------------------------