def sobWeightedPlot(self, fileName, datasetName, channel, cat, log, mass, tanb, blind, sob=False): # print 'yuta', channel, cat c = TCanvas(fileName, '', 600, 600) c.cd() if log: c.SetLogy(1) f = self.openTFile('Plot_' + fileName + '.root') isEMSM = fileName.find('SM') != -1 and fileName.find('em') != -1 isETSM = fileName.find('SM') != -1 and fileName.find('et') != -1 samples = ['ggH', 'Ztt', 'signal', 'data_obs', 'ttbar', 'EWK', 'Fakes'] if isEMSM: samples.append('ggH_hww') if isETSM: samples.append('Zee') dataGraph = self.tfileGet(f, 'Graph_from_data_obs') histDict = {} for sample in samples: histDict[sample] = self.tfileGet(f, sample) # print 'check :', sample, histDict[sample].GetSumOfWeights() if not histDict[sample]: print 'Missing histogram', sample, 'in file', 'Plot_' + fileName + '.root' # original for plots xminInset = 60 # 0 xmaxInset = 179 # 340 (for full range) # all range # xminInset = 0 # 0 # xmaxInset = 350 # 340 (for full range) # xminInset = 40 # 0 # xmaxInset = 200 # 340 (for full range) # xminInset = 120 # 0 # xmaxInset = 251 # 340 (for full range) if tanb > 0: xminInset = mass - 100 xmaxInset = mass + 100 if sob: xminInset = 0.4 xmaxInset = 0.7 ztt = histDict['Ztt'] ggH = histDict['ggH'] data = histDict['data_obs'] # This is to fix a weird plotting bug if sob: new_data = TH1F('new_data', '', ggH.GetNbinsX(), 0., 0.7) for i in range(1, new_data.GetNbinsX() + 1): new_data.SetBinContent(i, data.GetBinContent(i)) # print data.GetBinContent(i) data = new_data ggH_hww = 0 zee = 0 signal = histDict['signal'] if isEMSM: ggH_hww = histDict['ggH_hww'] if isETSM: print 'retrieve Zee' zee = histDict['Zee'] tt = histDict['ttbar'] ewk = histDict['EWK'] fakes = histDict['Fakes'] ztt.GetYaxis().SetRangeUser(0., 1.3 * self.findMaxY(data, 0)) if log: ztt.GetYaxis().SetRangeUser(0.001, 50. * self.findMaxY(data, 0)) ztt.GetXaxis().SetTitle('#bf{m_{#tau#tau} [GeV]}') ztt.GetYaxis().SetTitle('#bf{S/B Weighted dN/dm_{#tau#tau} [1/GeV]}') if tanb > 0. and not log: ztt.GetXaxis().SetRangeUser(0., mass + 200.) if sob: ztt.GetXaxis().SetTitle('S/(S+B)') ztt.GetYaxis().SetTitle('Events') ztt.SetTitleOffset(1.3, 'Y') ztt.SetTitleOffset(1., 'X') ztt.GetYaxis().SetNdivisions(505) ztt.SetNdivisions(505) for b in range(0, signal.GetNbinsX() + 2): if signal.GetBinCenter( b) < xminInset or xmaxInset < signal.GetBinCenter(b): signal.SetBinContent(b, 0.) signal.SetBinError(b, 0.) signal.SetName('sig') signal.SetFillStyle(3353) # 1001=solid , 3004,3005=diagonal signal.SetFillColor(2) signal.SetLineColor(2) signal.SetLineStyle(1) signal.SetLineWidth(0) ggH.SetBinContent(0, 0) # remove red line on top of y axis in plot ggH.SetBinContent(ggH.GetNbinsX() + 1, 0) ggH.SetBinError(0, 0) ggH.SetBinError(ggH.GetNbinsX() + 1, 0) ggH.SetName('ggH') ggH.SetFillStyle(3353) # 1001=solid , 3004,3005=diagonal ggH.SetFillColor(2) ggH.SetLineColor(2) ggH.SetLineStyle(1) ggH.SetLineWidth(0) if isEMSM: errorBand = TH1F(ggH_hww) else: errorBand = TH1F(ztt) errorBand.SetName("errorBand") errorBand.SetMarkerSize(0) errorBand.SetFillColor(1) errorBand.SetFillStyle(3013) errorBand.SetLineWidth(1) legend = TLegend() mssmLabel = '' if tanb > 0: mssmLabel = "tan#beta={tanb}".format(tanb=tanb) higgsLabel = "H(125 GeV)#rightarrow#tau#tau" if tanb > 0: higgsLabel = "H(125 GeV)#rightarrow#tau#tau" legend.SetFillStyle(0) legend.SetFillColor(0) legend.SetBorderSize(0) legend.AddEntry(ggH, higgsLabel, "F") if tanb > 0: legend.AddEntry(TObject(0), mssmLabel, "") legend.AddEntry(data, "observed", "LP") if isEMSM: legend.AddEntry(ggH_hww, "H(125 GeV)#rightarrowWW", "F") legend.AddEntry(ztt, "Z#rightarrow#tau#tau", "F") legend.AddEntry(tt, "t#bar{t}", "F") if isETSM: legend.AddEntry(zee, "Z#rightarrowee", "F") legend.AddEntry(ewk, "electroweak", "F") legend.AddEntry(fakes, "QCD", "F") legend.SetX1NDC(0.63) legend.SetX2NDC(1.05) legend.SetY1NDC(0.25) legend.SetY2NDC(0.46) if log: legend.SetX1NDC(0.18) legend.SetX2NDC(0.60) legend.SetY1NDC(0.17) legend.SetY2NDC(0.38) legend.SetTextSize(.028) legend.SetTextAlign(12) if isEMSM: dataDiff = self.diffPlot(data, ggH_hww, 1) dataDiffGraph = self.diffGraph(dataGraph, ggH_hww, 1) errBand = self.getErrorBand(ggH_hww) else: dataDiff = self.diffPlot(data, ztt, 1) dataDiffGraph = self.diffGraph(dataGraph, ztt, 1) errBand = self.getErrorBand(ztt) errBand.SetFillStyle( 3013 ) # 1001=solid , 3004,3005=diagonal, 3013=hatched official for H.tau tau errBand.SetFillColor(1) errBand.SetLineStyle(1) errBand.SetLineColor(1) errBand.SetLineWidth(1) errBandFrame = TH1F( 'errBandFrame', '', int((xmaxInset - xminInset) / dataDiff.GetBinWidth(1)), xminInset, xmaxInset) errBandFrame.GetYaxis().SetTitle("") errBandFrame.GetYaxis().SetRangeUser( -1.1 * self.findMinY(dataDiff, blind, 0, xminInset, xmaxInset), 2.0 * self.findMaxY(dataDiff, blind, 0, xminInset, xmaxInset)) # errBandFrame.GetYaxis().SetRangeUser(-1.*self.findMinY(dataDiff,blind,0,xminInset,xmaxInset),1.1*self.findMaxY(dataDiff,blind,0,xminInset,xmaxInset)) # good ! # errBandFrame.GetYaxis().SetRangeUser(-0.2*self.findMinY(dataDiff,blind,0,xminInset,xmaxInset),0.5*self.findMaxY(dataDiff,blind,0,xminInset,xmaxInset)) print 'Yuta', channel, cat if (channel == 'e#tau_{h}' and cat == 'vbf') or (channel == 'e#tau_{h}' and cat == ''): print 'enter' errBandFrame.GetYaxis().SetRangeUser( -2. * self.findMinY(dataDiff, blind, 0, xminInset, xmaxInset), 2.0 * self.findMaxY(dataDiff, blind, 0, xminInset, xmaxInset)) errBandFrame.GetYaxis().SetNdivisions(5) errBandFrame.GetYaxis().SetLabelSize(0.06) errBandFrame.GetXaxis().SetTitle("#bf{m_{#tau#tau} [GeV]} ") errBandFrame.GetXaxis().SetTitleColor(kBlack) errBandFrame.GetXaxis().SetTitleSize(0.07) errBandFrame.GetXaxis().SetTitleOffset(0.85) errBandFrame.GetXaxis().SetLabelSize(0.06) errBandFrame.GetXaxis().SetNdivisions(506) # errBandFrame.SetNdivisions(505) legendDiff = TLegend() legendDiff.SetFillStyle(0) legendDiff.SetFillColor(0) legendDiff.SetBorderSize(0) legendDiff.AddEntry(signal, higgsLabel, "F") if tanb > 0: legendDiff.AddEntry(TObject(0), mssmLabel, '') # That might not work in python # legendDiff.AddEntry(dataDiff,"Data - Background","LP") legendDiff.AddEntry(dataDiffGraph, "Data - Background", "LEP") legendDiff.AddEntry(errBand, "Bkg. Uncertainty", "F") legendDiff.SetX1NDC(0.45) legendDiff.SetX2NDC(0.88) legendDiff.SetY1NDC(0.67) legendDiff.SetY2NDC(0.88) if dataDiff.GetBinContent(dataDiff.FindBin(mass)) < 0.: legendDiff.SetX1NDC(0.45) legendDiff.SetX2NDC(0.88) legendDiff.SetY1NDC(0.24) legendDiff.SetY2NDC(0.45) legendDiff.SetTextSize(.045) legendDiff.SetTextAlign(12) padBack = TPad( "padBack", "padBack", 0.57, 0.58, 0.975, 0.956) # TPad must be created after TCanvas otherwise ROOT crashes padBack.SetFillColor(0) pad = TPad( "diff", "diff", 0.45, 0.5, 0.9765, 0.957) # TPad must be created after TCanvas otherwise ROOT crashes pad.cd() pad.SetFillColor(0) pad.SetFillStyle(0) errBandFrame.Draw() errBand.Draw("e2lsame") signal.Draw("histsame") line = TLine() line.DrawLine(xminInset, 0, xmaxInset, 0) # dataDiff.Draw("pe same") if blind == False: self.HideBin(dataDiffGraph) dataDiffGraph.SetMarkerSize(0.5) dataDiffGraph.Draw('pe same') for ibin in range(0, dataDiffGraph.GetN()): x = Double(0.) y = Double(0.) dataDiffGraph.GetPoint(ibin, x, y) print 'Yuta_bin=', ibin, 'x=', x, 'y=', y, dataDiffGraph.GetErrorYhigh( ibin), dataDiffGraph.GetErrorYlow(ibin) print 'Yuta_error=', ibin, errBand.GetXaxis().GetBinCenter( ibin + 1), errBand.GetBinError(ibin + 1) legendDiff.Draw() pad.RedrawAxis() c.cd() ztt.Draw("hist") ggH.Draw("hist same") if isEMSM: ggH_hww.Draw("hist same") ztt.Draw("hist same") errorBand.Draw("e2 same") tt.Draw("hist same") if isETSM: zee.Draw("hist same") ewk.Draw("hist same") fakes.Draw("hist same") # data.Draw("pe same") dataGraph.SetMarkerSize(1) dataGraph.Draw('PE same') if blind == False: self.HideBin(dataGraph) print '#####', data.Integral(), data.GetBinContent(1) legend.Draw() c.RedrawAxis() padBack.Draw() # clear the background axe pad.Draw() if log: c.SetLogy(1) self.CMSPrelim(c, datasetName, channel, cat) savepath = 'figure/Plot_' + fileName if cat == '': savepath = savepath + '.pdf' else: savepath = savepath + '_' + cat + '.pdf' # c.Print('figure/Plot_'+fileName+".eps") # c.Print('figure/Plot_'+fileName+".png") # c.Print('figure/Plot_'+fileName+".pdf") c.Print(savepath) c.Close()
mc = [(21, kRed + 1), (22, kBlue + 1), (23, kMagenta + 1)] for trig in trigs: for prong in prongs: fileName = f"plots/fakerate/fakerate_data_trig{trig}_{prong}.pdf" mg = TMultiGraph() mg.SetName("Fake Rates") c = TCanvas(f"c_{trig}_{prong}", "", 900, 900) c.SetLogx() leg = TLegend(0.50, 0.55, 0.90, 0.75) leg.SetTextFont(42) leg.SetFillStyle(0) leg.SetBorderSize(0) leg.SetTextSize(0.036) leg.SetTextAlign(32) gNom = dNom.Get(f"fakerate_data_trig{trig}_{prong}").CreateGraph() x = gNom.GetX() y = gNom.GetY() x = array('d', [i / 1000 for i in x]) exH = array('d', [gNom.GetErrorXhigh(i) / 1000 for i in range(len(x))]) exL = array('d', [gNom.GetErrorXlow(i) / 1000 for i in range(len(x))]) eWidth = array('d', [h + l for h, l in zip(exH, exL)]) x = array('d', [x[i] - 0.4 * eWidth[i] for i in range(len(x))]) exH = array('d', [e + 0.4 * eWidth[i] for i, e in enumerate(exH)]) exL = array('d', [e - 0.4 * eWidth[i] for i, e in enumerate(exL)]) gNomGeV = TGraphAsymmErrors(len(x), x, y, exL, exH, gNom.GetEYlow(), gNom.GetEYhigh()) leg.AddEntry(gNomGeV, "Nominal", "lep") for j, (nm, ud) in enumerate(dSysts.items()):
canvas.cd(2) gPad.SetPad(0, 0, 1, 0.25) gPad.SetMargin(0.15, 0.05, 0.4, 0.0) gPad.SetFillStyle(0) gPad.SetTickx(1) gPad.SetTicky(1) gPad.Update() gPad.Draw() canvas.cd(1) legend = TLegend(0.1783167, 0.6399027, 0.5249643, 0.8459043) legend.SetBorderSize(0) legend.SetFillColor(0) legend.SetFillStyle(0) legend.SetTextAlign(12) # first get baseline histogram baselineHistogram = getHistogram(pt, variable, baseline) legend.AddEntry(baselineHistogram, "100 #times 150 #mum^{2} (#phi,#rho)", "LEFP") # then get altered pitch histograms histograms = [] ratios = [] for pitch in plot['pitches']: currentHistogram = getHistogram(pt, variable, pitch) scalings = getScalings(pitch) sizeLabel = str(int(100.0 / scalings[0])) + " #times " + str( int(150.0 / scalings[1])) + " #mum^{2} (#phi,#rho)" currentHistogram.SetName(sizeLabel)
class PlotGraphs: def __init__(self, data, xlow, xhigh, ylow, yhigh, xlabel="", ylabel="", xLegend=.45, yLegend=.60, legendWidth=0.20, legendHeight=0.45, fillStyle=3395, drawOption='APL3', make_tfile=False): self.graph_index = {} self.ngraphs = 0 self.data = data self.drawOption = drawOption self.xlow = xlow self.xhigh = xhigh self.ylow = ylow self.yhigh = yhigh self.xlabel = xlabel self.ylabel = ylabel self.multigraph = TMultiGraph("MultiGraph", "") self.legend_type = {} if make_tfile: self.tfile = TFile('tgraphs.root', 'recreate') self.legend = TLegend(xLegend, yLegend, xLegend + legendWidth, yLegend + legendHeight) self.g_ = {} self.g2_ = {} self.g3_ = {} for cat in data.cat: if data.type[cat] == 'observed': #self.g_[cat] = TGraph(len(data.x[cat]), data.x[cat], data.y[cat]) self.g_[cat] = TGraphAsymmErrors(len(data.x[cat]), data.x[cat], data.y[cat], data.exl[cat], data.exh[cat], data.eyl[cat], data.eyh[cat]) self.g_[cat].SetName(cat) if make_tfile: _gcopy = self.g_[cat].Clone() self.tfile.Append(_gcopy) if data.dofit[cat]: #self.g_[cat].Fit("pol3", "M", "", data.fit_min[cat], data.fit_max[cat]) f1 = TF1( "f1", "[0]+[1]*(x-1000.0)/1000.0+[2]*(x-1000.0)*(x-1000.0)/1000000.0+[3]*(x-1000.0)*(x-1000.0)*(x-1000.0)/1000000000.0", data.fit_min[cat], data.fit_max[cat]) f2 = TF1( "f2", "[0]+[1]*(x-1000.0)/1000.0+[2]*(x-1000.0)*(x-1000.0)/1000000.0", data.fit_min[cat], data.fit_max[cat]) f3 = TF1("f3", "[0]+[1]*(x-1000.0)/1000.0", data.fit_min[cat], data.fit_max[cat]) _fr = self.g_[cat].Fit("f2", "MEWS", "", data.fit_min[cat], data.fit_max[cat]) _fr.Print() elif data.type[cat] == 'expected': self.g_[cat] = TGraphAsymmErrors(len(data.x[cat]), data.x[cat], data.y[cat], data.exl[cat], data.exh[cat], data.eyl[cat], data.eyh[cat]) self.g2_[cat] = TGraphAsymmErrors( len(data.x[cat]), data.x[cat], data.y[cat], data.exl2[cat], data.exh2[cat], data.eyl2[cat], data.eyh2[cat]) self.g3_[cat] = TGraphAsymmErrors(len(data.x[cat]), data.x[cat], data.y[cat], data.exl2[cat], data.exh2[cat], data.y[cat], data.exl2[cat]) self.g3_[cat].SetFillStyle(1002) #self.g3_[cat].SetFillStyle(3008) # 95% quantile self.g2_[cat].SetMarkerColor(data.fill2_color[cat]) self.g2_[cat].SetMarkerStyle(data.marker_style[cat]) self.g2_[cat].SetMarkerSize(data.marker_size[cat]) self.g2_[cat].SetLineColor(data.fill2_color[cat]) self.g2_[cat].SetLineStyle(data.line_style[cat]) self.g2_[cat].SetLineWidth(data.line_width[cat]) #self.g2_[cat].SetFillColor(data.marker_color[cat]+2) self.g2_[cat].SetFillColor(data.fill2_color[cat]) #self.g2_[cat].SetFillStyle(3008) #self.g2_[cat].SetFillStyle(3003) self.g2_[cat].SetFillStyle(data.fill2_style[cat]) self.g_[cat].SetMarkerColor(data.marker_color[cat]) self.g_[cat].SetMarkerStyle(data.marker_style[cat]) self.g_[cat].SetMarkerSize(data.marker_size[cat]) self.g_[cat].SetLineColor(data.line_color[cat]) self.g_[cat].SetLineStyle(data.line_style[cat]) self.g_[cat].SetLineWidth(data.line_width[cat]) self.g_[cat].SetFillColor(data.fill_color[cat]) if data.fill_style[cat] == None: self.g_[cat].SetFillStyle(fillStyle) else: self.g_[cat].SetFillStyle(data.fill_style[cat]) if data.type[cat] == 'observed': # only the main observed limit is a line, # everything else is a filled area if cat[0:3] == 'obs': _legend_type = 'lp' if 'PC' in drawOption: _draw_option = 'PC' else: _draw_option = 'PL' self.multigraph.Add(self.g_[cat], _draw_option) elif cat[0:3] == 'SSM': _legend_type = 'lp' _draw_option = '3' self.multigraph.Add(self.g_[cat], _draw_option) # print theory curve #self.g_[cat].Print() elif cat[0:3] == 'Psi': _legend_type = 'lp' _draw_option = '3' self.multigraph.Add(self.g_[cat], _draw_option) elif cat[0:3] == 'Stu': _legend_type = 'lp' _draw_option = '3' self.multigraph.Add(self.g_[cat], _draw_option) elif cat[0:2] == 'RS': _legend_type = 'f' _draw_option = '3' self.multigraph.Add(self.g_[cat], _draw_option) else: _legend_type = 'f' self.multigraph.Add(self.g_[cat]) #self.multigraph.Add(self.g_[cat]) self.graph_index[cat] = self.ngraphs self.ngraphs += 1 #self.legend . AddEntry( self.g_[cat], data.tlegend[cat], _legend_type); self.legend_type[cat] = _legend_type elif data.type[cat] == 'expected': self.g3_[cat].SetFillColor(0) self.g3_[cat].SetMinimum(self.ylow) self.g3_[cat].SetMaximum(self.yhigh) self.g3_[cat].GetXaxis().SetLimits(self.xlow, self.xhigh) self.multigraph.Add(self.g3_[cat], 'C3') self.ngraphs += 1 # 95 expected band self.multigraph.Add(self.g2_[cat], 'C4L') self.ngraphs += 1 self.multigraph.Add(self.g_[cat], 'C4L') self.graph_index[cat] = self.ngraphs self.ngraphs += 1 # median line gline = self.g_[cat].Clone() gline.SetLineWidth(3) gline.SetLineColor(ROOT.kBlue) gline.SetLineStyle(2) # median expected marker gline.SetMarkerStyle(8) gline.SetMarkerSize(1) # print graph contents #gline.Print() #self.multigraph.Add(gline, 'LXC') self.multigraph.Add(gline, 'C3X') self.ngraphs += 1 # median expected legend #self.legend . AddEntry( gline, 'median expected', "l"); self.legend_type[cat] = "l" _g = self.g_[cat] self.g_[cat] = gline # 68% expected band legend #self.legend . AddEntry( self.g_[cat], '68% expected', "f"); self.legend_type[cat + '1sig'] = "f" self.g_[cat + '1sig'] = _g # 95% expected band legend #self.legend . AddEntry( self.g2_[cat], '95% expected', "f"); self.legend_type[cat + '2sig'] = "f" self.g_[cat + '2sig'] = self.g2_[cat] keylist = data.legend_index.keys() # keys are indices keylist.sort() for key in keylist: print key, data.legend_index[key] self.legend.AddEntry(self.g_[data.legend_index[key]], data.tlegend[data.legend_index[key]], self.legend_type[data.legend_index[key]]) self.legend.SetShadowColor(0) self.legend.SetFillColor(0) self.legend.SetLineColor(0) if make_tfile: self.tfile.Write() self.tfile.Close() def draw(self, yLabelSize=0.055): self.multigraph.SetMinimum(self.ylow) self.multigraph.SetMaximum(self.yhigh) self.multigraph.Draw(self.drawOption) self.multigraph.GetXaxis().SetNdivisions(405) self.multigraph.GetYaxis().SetNdivisions(405) self.multigraph.GetXaxis().SetLimits(self.xlow, self.xhigh) #self.multigraph.GetYaxis().SetTitle("") self.multigraph.GetYaxis().SetLabelSize(yLabelSize) self.multigraph.GetXaxis().SetLabelSize(yLabelSize) latex = TLatex() latex.SetNDC() #latex.SetTextSize(0.04) latex.SetTextSize(yLabelSize) latex.SetTextAlign(31) # align right latex.DrawLatex(0.95, 0.01, self.xlabel) latex.SetTextAngle(90) latex.DrawLatex(0.03, 0.9, self.ylabel) self.legend.SetFillStyle(0) self.legend.SetBorderSize(0) #self.legend.SetTextSize(0.04) #self.legend.SetTextSize(yLabelSize) self.legend.SetTextSize(yLabelSize * 0.7) self.legend.SetTextFont(42) self.legend.SetTextAlign(11) self.legend.Draw() return self.multigraph def draw_line(self, xline, ymin=-0.02, ymax=0.20): if xline == None: return #print 'XXXX', xline _x = array('d') _y = array('d') _x.append(xline) _y.append(ymin) _x.append(float(xline)) _y.append(ymax) g_ = TGraph(len(_x), _x, _y) self.multigraph.Add(g_, 'L') def print_values(self, cat1, cat2): legend = 'PlotGraphs::print_values():' if cat1 in self.data.cat: graph1 = self.multigraph.GetListOfGraphs().At( self.graph_index[cat1]) else: return None if cat2 in self.data.cat: graph2 = self.multigraph.GetListOfGraphs().At( self.graph_index[cat2]) else: return None for x in range(750, 1150, 50): dmax = 0.0 drelmax = 0.0 v1 = graph1.Eval(x) v2 = graph2.Eval(x) d = math.fabs(v2 - v1) drel = math.fabs((v2 - v1) / v1) if d > dmax: dmax = d if drel > drelmax: drelmax = drel print legend, 'x =', x print legend, cat1, 'value =', v1 print legend, cat2, 'value =', v2 print legend, 'abs diff =', d print legend, 'abs relative diff =', drel print legend, 'max abs diff =', dmax print legend, 'max abs relative diff =', drelmax def find_intersection(self, cat1, cat2, xmin=350, xmax=3500, precision=0.000000001): legend = 'PlotGraphs::find_intersection(%s,%s):' % (cat1, cat2) #always put "exp" or "obs" in cat1 if cat1 is "exp" or cat1 is "obs": if cat1 in self.data.cat: graph1 = self.multigraph.GetListOfGraphs().At( self.graph_index[cat1]) else: print "Failed to get ", cat1 return ["None"] else: print cat1, " is not obs/exp limit." return ["None"] if cat2 in self.data.cat: graph2 = self.multigraph.GetListOfGraphs().At( self.graph_index[cat2]) #graph2.Print() else: print "Failed to get ", cat2 return ["None"] _x = xmin print legend, graph1.Eval(_x) - graph2.Eval(_x) if graph1.Eval(_x) > graph2.Eval(_x): result = ["lowlimit"] else: result = [] _interval = 1 _sign1 = graph1.Eval(_x) > graph2.Eval(_x) while _x < xmax: _x += _interval _sign2 = graph1.Eval(_x) > graph2.Eval(_x) if _sign1 != _sign2: _d = 100000 _step = -0.5 * _interval _crosspt = _x while abs(_d) > precision: _crosspt += _step _d = graph1.Eval(_crosspt) - graph2.Eval(_crosspt) _sign2 = _d > 0 if _sign1 != _sign2: _step = -0.5 * abs(_step) else: _step = 0.5 * abs(_step) _sign1 = not (_sign1) result.append(_crosspt) if result: print "Allowed region:", _x = 0 while _x < len(result): if _x + 1 < len(result): print "[", result[_x], ",", result[_x + 1], "];", else: if _x + 1 == len(result): print "[", result[_x], ", inf ];" if _x + 2 == len(result): print _x += 2 else: print "[", xmin, "~", xmax, "] is excluded." del graph1 del graph2 return result