ms=20, mew=10, linewidth=0, label=oJetnsjCutLabel) ax.set_xlim((0.0, 1.1)) ax.set_ylim((0.0, 2.0)) ax.set_xticks(np.linspace(0., 1., 6)) ax.set_yticks(np.linspace(0., 1., 6)) helpers.add_legend(fig, ax, numpoints=1) helpers.add_labels(fig, ax, xlabel='signal', ylabel='background') helpers.add_description( fig, ax, align='tl', strings=[ helpers.dataSetStr, 'iso., $\Delta R(\mathrm{gJet},\mathrm{oJet})\leq 1$', helpers.seedCutStr, helpers.noiseCutStr, gJetEtCutLabel, gTowerEtThrLabel, offlineLabel ]) helpers.add_grid(fig, ax) helpers.to_file( fig, ax, 'rates/{}_gJetEt{:0.0f}_gTowerEt{:0.0f}.png'.format( filename_id, gJetEt_cut, gTowerEt_cut)) pl.close(fig) endTime_wall = time.time() endTime_processor = time.clock() print "Finished job in:\n\t Wall time: {:0.2f} s \n\t Clock Time: {:0.2f} s".format( (endTime_wall - startTime_wall), (endTime_processor - startTime_processor))
try: print "\t"*2, "y-projection slices of resolution" # y projection slices pl_res_proj = {} fig, ax = pl.subplots(figsize=helpers.figsize) for oJetPt_cuts in [(170., 180.), (200., 220.), (300., 350.)]: oJetPt_cut = helpers.btwn(data['oJet.pt'], oJetPt_cuts[0], oJetPt_cuts[1]) hist, bins = np.histogram(resolution[np.where(cut & oJetPt_cut & tJet_exists_subtracted)], bins=100, density=True) fwhm = helpers.FWHM(bins, hist) ax.plot(bins[:-1], hist, linestyle='steps-post', alpha=0.75, color='b', label=r'${:0.0f}\ \mathrm{{GeV}} < p_T^\mathrm{{oJet}} <\ {:0.0f}\ \mathrm{{GeV}}$\nFWHM = {:0.4f}'.format(oJetPt_cuts[0], oJetPt_cuts[1], fwhm), linewidth=helpers.linewidth) pl_res_proj['{:0.0f}to{:0.0f}'.format(oJetPt_cuts[0], oJetPt_cuts[1])] = resolution[np.where(cut & oJetPt_cut & tJet_exists_subtracted)] helpers.add_legend(fig, ax) helpers.add_labels(fig, ax, xlabel=r'resolution $\frac{E_T^\mathrm{gFEX} - p_T^\mathrm{offline}}{p_T^\mathrm{offline}}$', ylabel='normalized counts', title='Y-Axis Projections of Resolution') helpers.add_description(fig, ax, align='br', strings=[helpers.dataSetStr, helpers.seedCutStr, helpers.noiseCutStr, helpers.towerThrStr]) ax.set_xlim((-1.0, 1.0)) helpers.add_grid(fig, ax) pickle.dump(pl_res_proj, file(helpers.write_file('plots/pickle/{}_resolution_PtOffline_projection_region{}.pkl'.format(filename_id, i)), 'w+')) helpers.to_file(fig, ax, 'plots/resolution/{}_resolution_PtOffline_projection_region{}.png'.format(filename_id, i)) pl.close(fig) except: print "\t"*2, "Error for {}: could not make resolution projection".format(region) pl.close(fig) pass try: print "\t"*2, "y-projection slices of corrected resolution" pl_res_proj = {} fig, ax = pl.subplots(figsize=helpers.figsize) for oJetPt_cuts in [(170., 180.), (200., 220.), (300., 350.)]:
sigData = np.zeros((4, 4)) bkgData = background['gJetEtCut_{:0.0f}'.format(gJetEt_cut)]['']['gTowerEtCut_{:0.0f}'.format(gTowerEt_cut)]['oJetnsjCut_{:d}'.format(0)]['vals'] for gJetnsj_cut, i in zip([1, 2, 3, 4], range(4)): # add storage by oJetnsj_cut sigData[i] = signal['gJetEtCut_{:0.0f}'.format(gJetEt_cut)][filenameEnd]['gTowerEtCut_{:0.0f}'.format(gTowerEt_cut)]['gJetnsjCut_{:d}'.format(gJetnsj_cut)]['vals'] fig, ax = pl.subplots(figsize=helpers.figsize) for sig, color, oJetnsj_cut in zip(sigData.T, helpers.colors, range(1, 5)): print "\t"*3, "oJetnsj_cut = {}".format(oJetnsj_cut) # make a label for oJet nsj cut oJetnsjCutLabel = r'$N(P_T^\mathrm{{oJet\ subjet}} >\ 20 \ \mathrm{{GeV}}) \geq {:d}$'.format(oJetnsj_cut) ax.plot(sig, bkgData, linestyle='steps-mid', alpha=0.75, color=color, marker='x', ms=20, mew=10, linewidth=0, label=oJetnsjCutLabel) ax.set_xlim((0.0, 1.1)) ax.set_ylim((0.0, 2.0)) ax.set_xticks(np.linspace(0., 1., 6)) ax.set_yticks(np.linspace(0., 1., 6)) helpers.add_legend(fig, ax, numpoints=1) helpers.add_labels(fig, ax, xlabel='signal', ylabel='background') helpers.add_description(fig, ax, align='tl', strings=[helpers.dataSetStr, 'iso., $\Delta R(\mathrm{gJet},\mathrm{oJet})\leq 1$', helpers.seedCutStr, helpers.noiseCutStr, gJetEtCutLabel, gTowerEtThrLabel, offlineLabel]) helpers.add_grid(fig, ax) helpers.to_file(fig, ax, 'rates/{}_gJetEt{:0.0f}_gTowerEt{:0.0f}.png'.format(filename_id, gJetEt_cut, gTowerEt_cut)) pl.close(fig) endTime_wall = time.time() endTime_processor = time.clock() print "Finished job in:\n\t Wall time: {:0.2f} s \n\t Clock Time: {:0.2f} s".format((endTime_wall - startTime_wall), (endTime_processor - startTime_processor))
data['gTower_distribution'][where]).astype(float)[::-1])[::-1] / where[0].size, linestyle='steps-post', alpha=0.75, color=helpers.colors[3], label='$200 < p_T^\mathrm{{oJet}} < 250$\n{:d} events'.format( where[0].size), linewidth=helpers.linewidth) helpers.add_legend(fig, ax) helpers.add_labels(fig, ax, xlabel='$E_T^\mathrm{gTower}$ [GeV]', ylabel='gTower multiplicity / event') helpers.add_grid(fig, ax) helpers.add_description(fig, ax, align='bl', strings=[helpers.dataSetStr]) ax.set_yscale('log', nonposy='clip') ax.set_ylim((0.0, 1284.0)) helpers.to_file(fig, ax, 'plots/multiplicity/{}.png'.format(filename_id)) pl.close(fig) except: print "Could not make multiplicity plot" pl.close(fig) pass valid_gJets = np.where(tJet_exists) try: print "running out profiles for gTowers" fig, ax = pl.subplots(figsize=helpers.figsize)
n, bins, unweightedPatches = axt.hist(data['oJet.pt'], bins=np.arange(0, 500, 2), stacked=True, fill=False, histtype='step', color='r', label=r'unweighted', linewidth=helpers.linewidth, alpha=0.75) # http://matplotlib.org/examples/api/two_scales.html for tl in ax.get_yticklabels(): tl.set_color('b') for tl in axt.get_yticklabels(): tl.set_color('r') # http://stackoverflow.com/questions/5484922/secondary-axis-with-twinx-how-to-add-to-legend patches = [weightedPatches[0], unweightedPatches[0]] # http://matplotlib.org/examples/pylab_examples/legend_auto.html labels = [p.get_label() for p in patches] ax.set_yscale('log', nonposy='clip') axt.set_yscale('log', nonposy='clip') legend = ax.legend(patches, labels, fancybox=True, framealpha=0.75, fontsize=helpers.labelsize) legend.get_frame().set_facecolor(helpers.light_grey) legend.get_frame().set_linewidth(0.0) helpers.add_labels(fig, ax, xlabel=r'$p_T$ [GeV]', ylabel=r'weighted count') helpers.add_labels(fig, axt, ylabel=r'unweighted count') helpers.add_description(fig, ax, align='cr', strings=[helpers.dataSetStr, helpers.towerThrStr]) helpers.to_file(fig, ax, "plots/weighting/{}_pt.png".format(filename_id)) pl.close(fig) endTime_wall = time.time() endTime_processor = time.clock() print "Finished job in:\n\t Wall time: {:0.2f} s \n\t Clock Time: {:0.2f} s".format((endTime_wall - startTime_wall), (endTime_processor - startTime_processor))
# http://stackoverflow.com/questions/5484922/secondary-axis-with-twinx-how-to-add-to-legend patches = [unweightedPatches[0], weightedPatches[0]] # http://matplotlib.org/examples/pylab_examples/legend_auto.html labels = [p.get_label() for p in patches] ax.set_yscale('log', nonposy='clip') axt.set_yscale('log', nonposy='clip') ax.set_ylim((1e-5, ax.get_ylim()[1])) axt.set_ylim((1e-5, axt.get_ylim()[1])) legend = ax.legend(patches, labels, fancybox=True, framealpha=0.75, fontsize=helpers.labelsize) legend.get_frame().set_facecolor(helpers.light_grey) legend.get_frame().set_linewidth(0.0) helpers.add_labels(fig, ax, xlabel=r'$p_T$ [GeV]', ylabel=r'unweighted count') helpers.add_labels(fig, axt, ylabel=r'weighted count') helpers.add_description(fig, ax, align='cr', strings=[helpers.dataSetStr, helpers.seedCutStr, helpers.noiseCutStr, helpers.towerThrStr]) helpers.to_file(fig, ax, "plots/offline_jet_kinematics/{}_oJet_Pt.png".format(filename_id)) pl.close(fig) fig, ax = pl.subplots(figsize=helpers.figsize) n, bins, unweightedPatches = ax.hist(data['oJet.eta'], bins=np.arange(-4.9, 4.9, 0.2), label='unweighted', stacked=True, fill=False, histtype='step', alpha=0.75, color='r') axt = ax.twinx() n, bins, weightedPatches = axt.hist(data['oJet.eta'], weights=data['weight'], bins=np.arange(-4.9, 4.9, 0.2), label='weighted', stacked=True, fill=False, histtype='step', alpha=0.75, color='b') # http://matplotlib.org/examples/api/two_scales.html for tl in ax.get_yticklabels(): tl.set_color('r') for tl in axt.get_yticklabels(): tl.set_color('b') # make bigger ax.xaxis.set_tick_params(width=2, which='both')
where = np.where(helpers.btwn(data['oJet.pt'], 200., 250.)) ax.plot(bins_multiplicity[:-1], np.cumsum(np.sum(data['gTower_distribution'][where]).astype(float)[::-1])[::-1]/where[0].size, linestyle='steps-post', alpha=0.75, color=helpers.colors[3], label='$200 < p_T^\mathrm{{oJet}} < 250$\n{:d} events'.format(where[0].size), linewidth=helpers.linewidth) helpers.add_legend(fig, ax) helpers.add_labels(fig, ax, xlabel='$E_T^\mathrm{gTower}$ [GeV]', ylabel='gTower multiplicity / event') helpers.add_grid(fig, ax) helpers.add_description(fig, ax, align='bl', strings=[helpers.dataSetStr]) ax.set_yscale('log', nonposy='clip') ax.set_ylim((0.0, 1284.0)) helpers.to_file(fig, ax, 'plots/multiplicity/{}.png'.format(filename_id)) pl.close(fig) except: print "Could not make multiplicity plot" pl.close(fig) pass valid_gJets = np.where(tJet_exists) try: print "running out profiles for gTowers" fig, ax = pl.subplots(figsize=helpers.figsize)