def test_fizzbuzz(self): source = textwrap.dedent(''' for i in range(1, 101): if i % 3 == 0 and i % 5 == 0: print ("fizzbuzz") elif i % 3 == 0: print("fizz") elif i % 5 == 0: print("buzz") else: print(i) ''') transformed_source = beautify( (DeMorganFlipper, DoubleNegativeCreator, NodeDepthAnnotator, IfDepthMaximizer, ForLoopUnroller), source) self.assertEqualStdout(source, transformed_source)
def prettyContour(c,cfg): bea = beautify() c.UseCurrentStyle() prims = c.GetListOfPrimitives() it = prims.__iter__() histoName = None for it in prims: tempName = it.GetName() if tempName and "frame_" in tempName: histoName = tempName histo = c.FindObject(histoName) histo.SetTitle("") histo.SetStats(0) histo.GetXaxis().SetTitle(cfg.get('Global','par1PlotName')) histo.GetYaxis().SetTitle(cfg.get('Global','par2PlotName')) histo.GetXaxis().SetTitleFont(132) histo.GetYaxis().SetTitleFont(132) histo.GetYaxis().SetTitleOffset(1.35) histo.GetXaxis().SetNdivisions(505) cont95 = c.FindObject("contour_nll_TopLevelPdf_allcountingdata_with_constr_n2.447747") histo.GetYaxis().SetRangeUser(-1.5*cont95.GetYaxis().GetXmax(), 1.5*cont95.GetYaxis().GetXmax()) # pad RooPlot cont68 = c.FindObject("contour_nll_TopLevelPdf_allcountingdata_with_constr_n1.509592") if not cont68 == None: cont68.SetLineStyle(2) legend = c.GetPrimitive("TPave") bea.beautifyLegend(legend) legend.SetHeader("CMS Preliminary"); # legend.SetHeader("CMS Preliminary, #int L = 2.17 fb^{-1}"); legend.AddEntry(cont68,"68% CL","l") legend.AddEntry(cont95,"95% CL","l") legend.Draw() c.RedrawAxis() c.ResetAttPad() c.Update()
def prettyContour(c, cfg): bea = beautify() c.UseCurrentStyle() prims = c.GetListOfPrimitives() it = prims.__iter__() histoName = None for it in prims: tempName = it.GetName() if tempName and "frame_" in tempName: histoName = tempName histo = c.FindObject(histoName) histo.SetTitle("") histo.SetStats(0) histo.GetXaxis().SetTitle(cfg.get('Global', 'par1PlotName')) histo.GetYaxis().SetTitle(cfg.get('Global', 'par2PlotName')) histo.GetXaxis().SetTitleFont(132) histo.GetYaxis().SetTitleFont(132) histo.GetYaxis().SetTitleOffset(1.35) histo.GetXaxis().SetNdivisions(505) cont95 = c.FindObject( "contour_nll_TopLevelPdf_allcountingdata_with_constr_n2.447747") histo.GetYaxis().SetRangeUser(-1.5 * cont95.GetYaxis().GetXmax(), 1.5 * cont95.GetYaxis().GetXmax()) # pad RooPlot cont68 = c.FindObject( "contour_nll_TopLevelPdf_allcountingdata_with_constr_n1.509592") if not cont68 == None: cont68.SetLineStyle(2) legend = c.GetPrimitive("TPave") bea.beautifyLegend(legend) legend.SetHeader("CMS Preliminary") # legend.SetHeader("CMS Preliminary, #int L = 2.17 fb^{-1}"); legend.AddEntry(cont68, "68% CL", "l") legend.AddEntry(cont95, "95% CL", "l") legend.Draw() c.RedrawAxis() c.ResetAttPad() c.Update()
def prettyObsPlots(ws,cfg): bea = beautify() fit_sections = cfg.sections() fit_sections.remove('Global') ws.var('%s_%s'%(cfg.get('Global','par1Name'), cfg.get('Global','couplingType'))).removeMax() #make a pt plot with data/background/sm/atgc for each input channel for section in fit_sections: obsVar = ws.var('%s_%s'%(cfg.get(section,'obsVar'),section)) obsHist = ws.obj('%s_input_data'%section) bkgHist = ws.obj('allbkgs_%s'%section).createHistogram(section,obsVar,RooFit.Scaling(False)) ws.loadSnapshot('%s_fitresult'%cfg.get('Global','couplingType')) bestFit = ws.function('expected_%s'%section).createHistogram(section,obsVar,RooFit.Scaling(False)) bestFit.SetName('%s_bestfit'%section) ws.loadSnapshot('standardmodel') sm = ws.function('expected_%s'%section).createHistogram(section,obsVar,RooFit.Scaling(False)) sm.SetName('%s_sm'%section) ws.var('%s_%s'%(cfg.get('Global','par1Name'), cfg.get('Global','couplingType'))).setVal(0) ws.var('%s_%s'%(cfg.get('Global','par2Name'), cfg.get('Global','couplingType'))).setVal(cfg.getfloat(section,'par2GridMax')) gridPoint = ws.function('expected_%s'%section).createHistogram(section,obsVar,RooFit.Scaling(False)) gridPoint.SetName('%s_gridpoint'%section) obsHist.GetXaxis().SetTitle(cfg.get(section,'obsVarPlotName')) obsHist.GetYaxis().SetTitle('Events') obsHist.GetYaxis().SetTitleOffset(1.35) obsHist.SetMinimum(0.0) canv = TCanvas('%s_obs_canvas'%section,'',500,500) canv.cd() obsHist.SetStats(0) obsHist.SetTitle('') obsHist.Draw('E') bkgHist.SetLineColor(4) bkgHist.SetFillStyle(3001) bkgHist.SetFillColor(4) bkgHist.Draw('SAMEHISTO') sm.SetFillColor(0) sm.SetLineColor(1) sm.Draw('SAMEHISTO') bestFit.SetLineColor(4) bestFit.SetLineStyle(7) bestFit.Draw('SAMEHISTO') gridPoint.SetLineWidth(2) gridPoint.SetLineColor(2) gridPoint.SetFillColor(0) gridPoint.Draw('SAMEHISTO') legend = ROOT.TLegend(3.42741935483870941e-01,6.03813559322033955e-01, 9.15322580645161255e-01,9.23728813559322015e-01) legend.SetNColumns(2) bea.beautifyLegend(legend) # legend.SetTextSize(16.) legend.SetHeader("CMS Preliminary"); # legend.SetHeader("CMS Preliminary, #int L = 4.7 fb^{-1}"); legend.AddEntry(obsHist,"Data","lpe") legend.AddEntry(bkgHist,"Background","f") legend.AddEntry(sm,"Standard Model","l") legend.AddEntry(bestFit,"Best Fit","l") legend.AddEntry(gridPoint, "Anomalous Coupling %s = %.3f"%(cfg.get('Global','par2Name'), cfg.getfloat(section,'par1GridMax')), "l") legend.Draw() canv.Write()
from beautify import beautify import os data = [] update = '' adv = [] for file in os.listdir(): if len(file.split('.')) >= 2: if file.split('.')[1] == 'json': adv.append(file.split('.')[0]) update += beautify(file)[1] with open('today.txt', 'w') as f: f.write(update) try: with open('adv.txt', 'r') as f: dam = f.read() for num in dam.split('\n'): k = 0 for i in adv: if i == num: k = 1 if k == 0: adv.append(num) except: pass with open('adv.txt', 'w') as f: text = '' for i in adv: text += i + '\n' f.write(text) print(len(adv))
def prettyObsPlots(ws, cfg): bea = beautify() fit_sections = cfg.sections() fit_sections.remove('Global') ws.var('%s_%s' % (cfg.get( 'Global', 'par1Name'), cfg.get('Global', 'couplingType'))).removeMax() #make a pt plot with data/background/sm/atgc for each input channel for section in fit_sections: obsVar = ws.var('%s_%s' % (cfg.get(section, 'obsVar'), section)) obsHist = ws.obj('%s_input_data' % section) bkgHist = ws.obj('allbkgs_%s' % section).createHistogram( section, obsVar, RooFit.Scaling(False)) ws.loadSnapshot('%s_fitresult' % cfg.get('Global', 'couplingType')) bestFit = ws.function('expected_%s' % section).createHistogram( section, obsVar, RooFit.Scaling(False)) bestFit.SetName('%s_bestfit' % section) ws.loadSnapshot('standardmodel') sm = ws.function('expected_%s' % section).createHistogram( section, obsVar, RooFit.Scaling(False)) sm.SetName('%s_sm' % section) ws.var('%s_%s' % (cfg.get('Global', 'par1Name'), cfg.get('Global', 'couplingType'))).setVal(0) ws.var('%s_%s' % (cfg.get( 'Global', 'par2Name'), cfg.get('Global', 'couplingType'))).setVal( cfg.getfloat(section, 'par2GridMax')) gridPoint = ws.function('expected_%s' % section).createHistogram( section, obsVar, RooFit.Scaling(False)) gridPoint.SetName('%s_gridpoint' % section) obsHist.GetXaxis().SetTitle(cfg.get(section, 'obsVarPlotName')) obsHist.GetYaxis().SetTitle('Events') obsHist.GetYaxis().SetTitleOffset(1.35) obsHist.SetMinimum(0.0) canv = TCanvas('%s_obs_canvas' % section, '', 500, 500) canv.cd() obsHist.SetStats(0) obsHist.SetTitle('') obsHist.Draw('E') bkgHist.SetLineColor(4) bkgHist.SetFillStyle(3001) bkgHist.SetFillColor(4) bkgHist.Draw('SAMEHISTO') sm.SetFillColor(0) sm.SetLineColor(1) sm.Draw('SAMEHISTO') bestFit.SetLineColor(4) bestFit.SetLineStyle(7) bestFit.Draw('SAMEHISTO') gridPoint.SetLineWidth(2) gridPoint.SetLineColor(2) gridPoint.SetFillColor(0) gridPoint.Draw('SAMEHISTO') legend = ROOT.TLegend(3.42741935483870941e-01, 6.03813559322033955e-01, 9.15322580645161255e-01, 9.23728813559322015e-01) legend.SetNColumns(2) bea.beautifyLegend(legend) # legend.SetTextSize(16.) legend.SetHeader("CMS Preliminary") # legend.SetHeader("CMS Preliminary, #int L = 4.7 fb^{-1}"); legend.AddEntry(obsHist, "Data", "lpe") legend.AddEntry(bkgHist, "Background", "f") legend.AddEntry(sm, "Standard Model", "l") legend.AddEntry(bestFit, "Best Fit", "l") legend.AddEntry( gridPoint, "Anomalous Coupling %s = %.3f" % (cfg.get( 'Global', 'par2Name'), cfg.getfloat(section, 'par1GridMax')), "l") legend.Draw() canv.Write()