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', 'Upgrade RlxTau25 Rel. Rate %0.2f' % (9488. / 9355))
0, sci_trigger_r_obj.gps_time_length, type='D', name='trigger_hist', title='trigger: { ' + gps_time_span + ' }') modules_hist = [ Hist(nbins, 0, sci_trigger_r_obj.gps_time_length, type='D', name='module_hist_' + str(i), title='module CT_' + str(i) + ': { ' + gps_time_span + ' }') for i in xrange(1, 26) ] trigger_hist.SetDirectory(None) trigger_hist.SetMinimum(0) trigger_hist.color = 'red' trigger_hist.markerstyle = 3 for i in xrange(25): modules_hist[i].SetDirectory(None) modules_hist[i].SetMinimum(0) modules_hist[i].color = 'blue' modules_hist[i].markerstyle = 3 print ' - reading data ... ' for i in tqdm( xrange(sci_trigger_r_obj.begin_entry, sci_trigger_r_obj.end_entry)): sci_trigger_r_obj.t_trigger.get_entry(i) if not sci_trigger_r_obj.t_trigger.abs_gps_valid: continue trigger_hist.fill((sci_trigger_r_obj.t_trigger.abs_gps_week - sci_trigger_r_obj.start_week) * 604800 +
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)