def test_atlas(): style = get_style('ATLAS') with style: hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution") ROOT.gRandom.SetSeed() for i in xrange(1000): hpx.Fill(ROOT.gRandom.Gaus()) hpx.GetXaxis().SetTitle("random variable [unit]") hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]") hpx.SetMaximum(80.) hpx.Draw() ATLAS_label(.4, .8)
def test_cmstdr(): style = get_style('CMSTDR') with style: hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution") ROOT.gRandom.SetSeed() for i in xrange(1000): hpx.Fill(ROOT.gRandom.Gaus()) hpx.GetXaxis().SetTitle("random variable [unit]") hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]") hpx.SetMaximum(100.) hpx.Draw() labels.CMS_label("Testing 2050", sqrts=100)
def test_lhcb(): style = get_style('LHCb') with style: canvas = Canvas() hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution") ROOT.gRandom.SetSeed() for i in xrange(1000): hpx.Fill(ROOT.gRandom.Gaus()) hpx.GetXaxis().SetTitle("random variable [unit]") hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]") hpx.SetMaximum(80.) hpx.Draw() LHCb_label("R", "preliminary") if INTERACTIVE: wait()
from rootpy.extern.six.moves import range try: kwargs = {} for arg in extra: name, value = arg.lstrip('--').split('=') kwargs[name] = value except ValueError: print("specify style parameters with --name=value") try: style = get_style(args.style, **kwargs) except ValueError: print('Invalid style: `{0}`. Using the `ATLAS` style.'.format(args.style)) style = get_style('ATLAS') # Use styles as context managers. The selected style will only apply # within the following context: with style: c = Canvas() hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution") # generate some random data ROOT.gRandom.SetSeed() for i in range(25000): hpx.Fill(ROOT.gRandom.Gaus()) hpx.GetXaxis().SetTitle("random variable [unit]") hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]") hpx.SetMaximum(1000.) hpx.Draw() wait()
uct_efficiency = Efficiency(uct_pass_vs_pu, total_vs_pu).decorate(linecolor='blue', linewidth=2, markerstyle=20, markercolor='blue') uct_iso_efficiency = Efficiency(uct_iso_pass_vs_pu, total_vs_pu).decorate(linecolor='green', linewidth=2, markerstyle=20, markercolor='green') frame = Hist(*binning) frame.SetMaximum(1) frame.SetMinimum(0) frame.axis().SetTitle("Number of vertices") frame.axis(2).SetTitle("Efficiency (w.r.t. reco. p_{T}>40 GeV)") canvas.SetLogy(False) canvas.SetLeftMargin(0.2) frame.Draw() l1_efficiency.Draw('pe same') uct_efficiency.Draw('pe same') uct_iso_efficiency.Draw('pe same') legend = Legend(3, topmargin=0.25, leftmargin=0.25) legend.AddEntry(l1_efficiency, 'lp', 'Current Tau44') legend.AddEntry(uct_efficiency, 'lp',
linestyle='dashed', linewidth=2) up.Reset() up.fill_array(transform(up_scores)) dn = nominal.Clone(title='Down', linecolor='blue', linestyle='dashed', linewidth=2) dn.Reset() dn.fill_array(transform(dn_scores)) # Plot the nominal, up, and down scores canvas = Canvas() nominal.SetMaximum(max(dn) * 1.1) nominal.Draw() nominal.xaxis.SetTitle('BDT Score') nominal.yaxis.SetTitle('Events') up.Draw('same hist') dn.Draw('same hist') leg = Legend(3, pad=canvas, leftmargin=.5) leg.AddEntry(nominal, style='LEP') leg.AddEntry(up, style='L') leg.AddEntry(dn, style='L') leg.Draw() canvas.SaveAs('canvas_original.png') # Take the ratio of systematic / nominal
sys = nom.Clone(linewidth=2, linestyle='dashed') nom.Smooth(10) for i, bin in enumerate(sys.bins()): bin.value += i / 10. smooth_sys = smooth(nom, sys, 10, linecolor='red', linewidth=2, linestyle='dashed') smooth_alt_sys = smooth_alt(nom, sys, linecolor='blue', linewidth=2, linestyle='dashed') nom.SetMaximum( max(nom.GetMaximum(), sys.GetMaximum(), smooth_sys.GetMaximum(), smooth_alt_sys.GetMaximum()) * 1.2) nom.SetMinimum(-1) nom.Draw('hist') sys.Draw('hist same') smooth_sys.Draw('hist same') smooth_alt_sys.Draw('hist same') wait()
def makeComparisionPage(histodicts, fileNames, fileDescr, separateFiles): """ Prepares a canvas comparing multiple histograms: plotting all in one pad and their ratios in the second """ import rootpy from rootpy.plotting import Hist, Canvas, Legend import ROOT from ROOT import gPad log = logging.getLogger('pyroplot') cans = {} colors = [ ROOT.kBlue, ROOT.kRed + 1, ROOT.kViolet - 1, ROOT.kOrange + 7, ROOT.kGreen - 7, ROOT.kOrange - 6, ROOT.kPink - 9, ROOT.kTeal - 6, ROOT.kBlue + 4, ROOT.kAzure + 2 ] log.info("Drawing histograms ..") # prepare set of histograms to compare to the reference on (the first) # loop over the reference set of histos (sorted by key): for hidx, refname in enumerate(sorted(histodicts[0].keys())): # prepare canvas if separateFiles: log.debug("Creating new canvas with index %d." % (hidx)) c = Canvas(600, 270) cans[refname] = c c.Divide(3, 1) c.cd(1) if not separateFiles and (hidx) % 4 == 0: log.debug("Creating new canvas with index %d." % (hidx / 3)) # start a new canvas c = Canvas(600, 800) cans[refname] = c c.Divide(3, 4) # prepare histograms for drawing log.debug("Drawing histogram #" + str(hidx + 1) + " (" + refname + ") on canvas #" + str(len(cans))) hists = [] ratiohists = [] hiter = iter(histodicts) # special treatment for tprofile: prepare the reference projection for the ratio if histodicts[0][refname].__class__.__name__ == "Profile": refProj = histodicts[0][refname].ProjectionX() refProj.SetName("reference_proj") for idx, h in enumerate(hiter): # make sure we have this histogram loaded: if not refname in h: continue # access the corresponding histogram of the other files at the same hidx as used for ref h[refname].color = colors[idx] h[refname].linestyle = idx hists.append(h[refname]) # prepare ratio is this is not the first (i.e. reference) histogram if idx: # special treatment for TProfile: if h[refname].__class__.__name__ == "Profile": myratio = Hist(h[refname].nbins(), h[refname].lowerbound(), h[refname].upperbound()) #dummy hist myratioproj = h[refname].ProjectionX() myratioproj.SetName("cmp_hist_proj" + str(idx)) try: myratio.divide(myratioproj, refProj) except rootpy.ROOTError, e: log.error( "Calculation of ratio for histogram %s caused ROOTError exception ('%s')" % (h[refname].GetName(), e.msg)) break myratio.color = colors[idx] else: myratio = h[refname].clone( ) # make sure that the ratio has the right type try: myratio.Divide( h[refname], histodicts[0][refname]) # divide by reference hist except rootpy.ROOTError, e: log.error( "Calculation of ratio for histogram %s caused ROOTError exception ('%s')" % (h[refname].GetName(), e.msg)) break myratio.yaxis.SetTitle("(h_{cmp} - h_{ref})/h_{ref}") myratio.SetTitle("ratio to reference") myratio.SetMaximum(2) myratio.SetMinimum(0) myratio.SetStats(0) ratiohists.append(myratio)