def produceFamilyPlot(family, surname): canvas = TCanvas(surname, "", 2400, 800) legend = TLegend(0.1, 0.5, 0.4, 0.87) legend.SetBorderSize(0) legend.SetFillStyle(0) counter = 0 markers = [] for person in family: if len(person) < 2: print "error" continue name = person[0] sex = person[1] if len(person) >= 3: birth = person[2] else: birth = 0 plot = makePlot(name, sex) normalizePlot(plot) plot.SetTitle("") plot.GetYaxis().SetLabelSize(0) plot.GetXaxis().SetLabelSize(0.07) plot.GetYaxis().SetTickSize(0) plot.GetYaxis().SetTitle("normalized popularity") plot.GetYaxis().SetTitleSize(0.07) plot.GetYaxis().SetTitleOffset(0.22) plot.SetLineColor(colors[counter]) legend.AddEntry(plot, name, "L") plot.Draw("same C") if birth > 0: marker = TMarker(birth+0.5, plot.GetBinContent(plot.FindBin(birth)), 20) marker.SetMarkerColor(colors[counter]) marker.SetMarkerSize(5) markers.append(marker) markers[counter].Draw("same") counter += 1 legend.Draw() canvas.SaveAs(surname + ".pdf")
def myMarkerTextSmall2(x, y, lcolor, lstyle, mcolor, mstyle, msize, size, text): l = TLatex() l.SetTextAlign(12) l.SetTextSize(size / 2.5) l.SetNDC() l.DrawLatex(x, y, text) yb1 = y - 0.15 * size yb2 = y + 0.15 * size xb1 = x - 0.28 * size - 0.45 * size xb2 = x + 0.28 * size - 0.45 * size print "box = ", xb1, yb1, xb2, yb2 #print "line = ",xl1,yl1,xl2,yl2 mline1 = TLine(xb1, yb1, xb2, yb2) mline1.SetLineColor(lcolor) mline1.SetLineStyle(lstyle) mline1.SetLineWidth(2) y_new = (yb1 + yb2) / 2. mline1.DrawLineNDC(xb1, y_new, xb2, y_new) mline2 = TLine(xb1, yb1, xb2, yb2) mline2.SetLineColor(lcolor) mline2.SetLineStyle(lstyle) mline2.SetLineWidth(2) x_new = (xb1 + xb2) / 2. mline2.DrawLineNDC(x_new, yb1, x_new, yb2) marker = TMarker((xb1 + xb2) / 2.0, y, mstyle) marker.SetNDC() marker.SetMarkerColor(mcolor) marker.SetMarkerStyle(mstyle) marker.SetMarkerSize(msize) marker.Draw() return marker
def plotFailedHoMatchesNoTrg(): c = TCanvas("cFailedHoMatchesNoTrg","cFailedHoMatchesNoTrg",1200,1200) c.cd().SetRightMargin(0.25) c.cd().SetLeftMargin(0.08) #Graph for in events not in geometric acceptance grNotInGaNC = file.Get("hoMuonAnalyzer/graphs/NoTrgTdmiNotInGA") grNotInGa = PlotStyle.convertToHcalCoords(grNotInGaNC) grNotInGa.GetYaxis().SetTitle("i#phi / a.u.") grNotInGa.GetXaxis().SetTitle("i#eta / a.u.") grNotInGa.GetYaxis().SetTitleFont(62) grNotInGa.GetYaxis().SetLabelFont(62) grNotInGa.SetMarkerStyle(6) grNotInGa.SetMarkerColor(PlotStyle.colorRwthDarkBlue) grNotInGa.SetTitle("#eta #phi plot failed HO matches in no Single #mu Trg. events") grNotInGa.Draw("AP") #Graph of events with HO match below threshold grHoBelowThrNC = file.Get("hoMuonAnalyzer/graphs/NoTrgTdmiBelowThr") grHoBelowThr = PlotStyle.convertToHcalCoords(grHoBelowThrNC) grHoBelowThr.SetMarkerStyle(20) grHoBelowThr.SetMarkerSize(1.2) grHoBelowThr.SetMarkerColor( PlotStyle.colorRwthGruen ) grHoBelowThr.Draw("samep") #Graph for events where HO matching failed grHoMatchFailNC = file.Get("hoMuonAnalyzer/graphs/NoTrgHoMatchFail") grHoMatchFail = PlotStyle.convertToHcalCoords(grHoMatchFailNC) grHoMatchFail.SetMarkerStyle(21) grHoMatchFail.SetMarkerSize(1) grHoMatchFail.SetMarkerColor( PlotStyle.colorRwthRot ) grHoMatchFail.Draw("samep") #Draw chimneys chimney1Converted = PlotStyle.convertToHcalCoords(PlotStyle.chimney1) chimney2Converted = PlotStyle.convertToHcalCoords(PlotStyle.chimney2) chimney1Converted.SetLineColor(PlotStyle.colorRwthMagenta) chimney2Converted.SetLineColor(PlotStyle.colorRwthMagenta) chimney1Converted.Draw('same') chimney2Converted.Draw('same') #cms private label label = TPaveText(PlotStyle.getLabelCmsPrivateSimulation(x1ndc=0.5,x2ndc=0.75)) label.Draw() #create extra marker for the legend marker = TMarker(1,1,2) marker.SetMarkerSize(3) marker.SetMarkerColor(PlotStyle.colorRwthDarkBlue) #legend legend = TLegend(0.75,0.8,0.99,0.9) legend.AddEntry(chimney2Converted,"chimney","l") legend.AddEntry(marker,'Not in GA','p') legend.AddEntry(grHoMatchFail,'HO match fail','p') legend.AddEntry(grHoBelowThr,'HO match < 0.2 GeV','p') legend.Draw() nNotMatching = grHoMatchFail.GetN() nNotInGa = grNotInGa.GetN() nBelowThr = grHoBelowThr.GetN() nTotal = nNotMatching + nNotInGa + nBelowThr print 80*'#' print 'Not Matching:\t%5d/%d\t=> %5.2f%% +- %f%%' % (nNotMatching,nTotal,nNotMatching/float(nTotal)*100,PlotStyle.calcSigma(nNotMatching,float(nTotal))) print 'Not in GA:\t%5d/%d\t=> %5.2f%% +- %f%%' % (nNotInGa,nTotal,nNotInGa/float(nTotal)*100,PlotStyle.calcSigma(nNotInGa,float(nTotal))) print 'Below Thr:\t%5d/%d\t=> %5.2f%% +- %f%%' % (nBelowThr,nTotal,nBelowThr/float(nTotal)*100,PlotStyle.calcSigma(nBelowThr,float(nTotal))) print 80*'#' c.Update() c.SaveAs('plots/graphsEtaPhi/gNoTrgHoMatchingFailed.png') c.SaveAs('plots/graphsEtaPhi/gNoTrgHoMatchingFailed.pdf') return c,grNotInGa,label,chimney1Converted,chimney2Converted,legend,grHoMatchFail,grHoBelowThr
ROCwmass.SetLineColor(2) ROCwmass.SetLineWidth(2) ROCwmass.SetTitle(";signal efficiency;background rejection") c2 = TCanvas("c2") ptlimstrs = [str(int(2000.0*ptlims[0])),str(int(2000.0*ptlims[1]))] ROCwmass.Draw() prelim.DrawLatex( 0.15, 0.85, ptlimstrs[0]+" GeV < p_{T} < "+ptlimstrs[1]+" GeV" ) if (cust=="w" or cust=="top") and Drawmarker: if cust=="w": prelim.DrawLatex( 0.44, 0.55, "N_{2}^{DDT}+msd" ) TM = TMarker(0.4, 0.01, 23) if cust=="top": prelim.DrawLatex( 0.44, 0.60, "#tau_{32}+msd+subjetb" ) TM = TMarker(0.4, 0.017, 23) TM.SetMarkerSize(2) TM.SetMarkerColor(4) TM.Draw() c2.SetLogy() c2.Write("rocwmass") ROC.Draw() c2.Write("roccomp") dnnsig.Write() dnnbkg.Write() output.Write() output.Close()
chi2, N = getChi2(i) if N == 0: continue chi2 /= N if chi2 < minChi2 or minChi2 < 0.0: minChi2 = chi2 minChi2HitAndTOBDrop = i minChi2Index = copy.deepcopy(index) g.SetPoint(n, i, chi2) n += 1 print "(" + str(iteration + 1) + " / " + str( nIterations) + ") minimum chi2: " + str(minChi2) + " at " + str( minChi2HitAndTOBDrop) m = TMarker(minChi2HitAndTOBDrop, minChi2, 29) m.SetMarkerSize(3) hitDropGridLower = hitDropGrid[ minChi2Index - 1] if minChi2Index > 0 else hitDropGrid[ minChi2Index] - hitDropGrid[minChi2Index + 1] hitDropGridUpper = hitDropGrid[minChi2Index + 1] if minChi2Index < len( hitDropGrid) - 1 else hitDropGrid[minChi2Index] + hitDropGrid[ minChi2Index - 1] hitDropGrid = numpy.linspace(max(hitDropGridLower, 0.0), hitDropGridUpper, 5) foutMode = "update" if iteration > 0 else "recreate" fout = TFile.Open("hipChi2.root", foutMode) fout.cd() g.Write("chi2VsHitDropProbability_" + str(iteration)) m.Write("bestFitPoint_" + str(iteration))
def MuFit(Nbins,irebin=1.): # Get histrograms h_bgr = GetMassDistribution(1) h_data = GetMassDistribution(2) h_sig = GetMassDistribution(125) h_bgr.Rebin(irebin) h_data.Rebin(irebin) h_sig.Rebin(irebin) h_sf = TH2D("scalefactor","title",Nbins,0.5,2.,Nbins,0.,5.) for i in range(1,h_sf.GetNbinsX()+1): for j in range(1,h_sf.GetNbinsY()+1): sf_bgr = h_sf.GetXaxis().GetBinCenter(i) sf_sig = h_sf.GetYaxis().GetBinCenter(j) # Loop over bins, compute likelihood loglik = 0. for iDataBin in range(1,h_data.GetNbinsX()+1): m4lepBin = h_data.GetBinCenter(iDataBin) NObsBin = h_data.GetBinContent(iDataBin) MeanBin = sf_bgr*h_bgr.GetBinContent(iDataBin) + sf_sig*h_sig.GetBinContent(iDataBin) if (MeanBin>0): loglik += TMath.Log( TMath.Poisson(NObsBin,MeanBin) ) h_sf.SetBinContent(i,j,-2.*loglik) # Get best SF parameters x=ctypes.c_int(0) y=ctypes.c_int(0) z=ctypes.c_int(0) h_sf.GetBinXYZ(h_sf.GetMinimumBin(),x,y,z) Minimum = h_sf.GetBinContent(x.value,y.value) best_alpha = h_sf.GetXaxis().GetBinCenter(x.value) best_mu = h_sf.GetYaxis().GetBinCenter(y.value) print(Minimum,best_alpha,best_mu) # Rescale histogram for i in range(1,h_sf.GetNbinsX()+1): for j in range(1,h_sf.GetNbinsY()+1): h_sf.SetBinContent( i,j, h_sf.GetBinContent(i,j)-Minimum ) canvas = TCanvas("canvas","Standard Canvas",600,400) canvas.cd() Min = TMarker(best_alpha,best_mu,29) Min.SetMarkerSize(2) h_sf.SetStats(kFALSE) h_sf.SetTitle("HIGGS PRODUCTION CROSS SECTION - PARAMETERS") h_sf.GetXaxis().SetTitle(r"#alpha") h_sf.GetYaxis().SetTitle(r"#mu") h_sf.Draw("COLZ") h_sigma = h_sf.Clone("h_sigma") h_sigma.Reset() for i in range(1,h_sigma.GetNbinsX()+1): for j in range(1,h_sigma.GetNbinsY()+1): if( h_sf.GetBinContent(i,j)<=1.): h_sigma.SetBinContent(i,j, 1.) h_sigma.SetMarkerColorAlpha(kRed,0.40) h_sigma.SetMarkerSize(10) h_sigma.Draw("same L") Min.Draw() leg1 = TLegend(0.65,0.85,0.85,0.75) leg1.SetBorderSize(1); leg1.SetFillColor(0); leg1a = leg1.AddEntry(Min, r"optimal (#alpha,#mu)", "p"); leg1a.SetTextSize(0.04); leg1.Draw() canvas.Print("Plots/MuFit.pdf")