leg.SetTextSize(0.03) lineColors = [ kBlue, kMagenta, kRed ] bins = [150, 250, 350, 500] for chiso in ChIsoSbSels: purityFile.write(chiso[0]+" ") hist = TH1F(chiso[0],chiso[0],(len(bins)-1),array('d',bins)) hist.GetXaxis().SetTitle("#gamma p_{T} (GeV)") hist.GetYaxis().SetTitle("Purity") hist.SetMaximum(1.05) hist.SetMinimum(0.5) hist.SetLineColor(lineColors[ChIsoSbSels.index(chiso)]) hist.SetLineWidth(2) hist.SetStats(False) leg.AddEntry(hist,chiso[0],'L') for ptCut in PhotonPtSels[0][1:]: lowEdge = int(ptCut[0].split("t")[2]) binNumber = 0 for bin in bins: if bin == lowEdge: binNumber = bins.index(bin) + 1 purity = float(purities[loc][pid][chiso[0]][MetSels[0][0]][ptCut[0]][source][0]) uncertainty = float(purities[loc][pid][chiso[0]][MetSels[0][0]][ptCut[0]][source][1]) # print binNumber, purity, uncertainty
chIsoRange = chiso[0].strip("ChIso").split("to") chIsoLabel = " CH Iso $[%.1f, %.1f]$ " % (float(chIsoRange[0])/10.0, float(chIsoRange[1])/10.0) purityFile.write(chIsoLabel) hists = [] himp = TH1F(chiso[0]+"imp",chiso[0]+"imp;#gamma p_{T} (GeV)",(len(bins)-1),array('d',bins)) himp.GetYaxis().SetTitle("Impurity (%)") hists.append(himp) herr = TH1F(chiso[0]+"err",chiso[0]+"err;#gamma p_{T} (GeV)",(len(bins)-1),array('d',bins)) herr.GetYaxis().SetTitle("Relative Error on Impurity (%)") hists.append(herr) canvas.legend.add(chiso[0], title = chIsoLabel.replace("$",""), lcolor = lineColors[ChIsoSbSels.index(chiso)], lwidth = 3) canvas.legend.apply(chiso[0], hists[0]) canvas.legend.apply(chiso[0], hists[1]) for ptCut in PhotonPtSels[1:]: lowEdge = int(ptCut[0].split("t")[2]) binNumber = 0 for bin in bins: if bin == lowEdge: binNumber = bins.index(bin) + 1 impurity = float(purities[source][loc][pid][ptCut[0]][metCut[0]][chiso[0]][0]) uncertainty = float(purities[source][loc][pid][ptCut[0]][metCut[0]][chiso[0]][-1]) # print binNumber, purity, uncertainty purityFile.write(r"& %.2f $\pm$ %.2f " % (impurity, uncertainty) ) hists[0].SetBinContent(binNumber, impurity)