def testIthr(): lines = get_lines('DAC_scan_ithr_0x40to0xf0.dat') gr1 = TGraphErrors() gr2 = TGraphErrors() fUnit = 1000. / 0.7 yUnit = 'e^{-}' for line in lines: if len(line) == 0: continue if line[0] in ['#', '\n']: continue fs = line.rstrip().split() ix = int(fs[0]) gr1.SetPoint(ix, float(fs[1]), float(fs[2]) * fUnit) gr1.SetPointError(ix, 0, float(fs[3]) * fUnit) gr2.SetPoint(ix, float(fs[1]), float(fs[4]) * fUnit) gr2.SetPointError(ix, 0, float(fs[5]) * fUnit) useAtlasStyle() gStyle.SetMarkerStyle(20) gr1.SetMarkerStyle(20) gr1.Draw('AP') h1 = gr1.GetHistogram() h1.GetYaxis().SetTitle("Threshold [" + yUnit + "]") h1.GetXaxis().SetTitle("I_{Thre} code") # h1.GetYaxis().SetRangeUser(0,0.2) gPad.SetTicks(1, 0) gPad.SetRightMargin(0.16) y1b = 0 y2b = 15 x1 = h1.GetXaxis().GetXmax() y1 = h1.GetYaxis().GetXmin() y2 = h1.GetYaxis().GetXmax() raxis = TGaxis(x1, y1, x1, y2, y1b, y2b, 506, "+L") raxis.SetLineColor(2) raxis.SetLabelColor(2) raxis.SetTitleColor(2) raxis.SetTitle("ENC [" + yUnit + "]") raxis.Draw() nP = gr2.GetN() Ys = gr2.GetY() EYs = gr2.GetEY() Y = array( 'd', [y1 + (y2 - y1) / (y2b - y1b) * (Ys[i] - y1b) for i in range(nP)]) EY = array('d', [(y2 - y1) / (y2b - y1b) * EYs[i] for i in range(nP)]) gr2x = TGraphErrors(nP, gr2.GetX(), Y, gr2.GetEX(), EY) gr2x.SetMarkerStyle(24) gr2x.SetLineColor(2) gr2x.SetMarkerColor(2) gr2x.Draw('Psame') waitRootCmdX()
def get_rank_section(directory): # do Rank histo png imgname = "RankSummary.png" gStyle.SetPadTickY(0) c = TCanvas("ranks", "ranks", 500, 400) #gStyle.SetOptStat(0) c.cd() h = directory.rank_histo rank_histof = TH1F(h.GetName(), "", h.GetNbinsX(), h.GetXaxis().GetXmin(), h.GetXaxis().GetXmax()) rank_histof.SetLineWidth(2) for i in xrange(0, h.GetNbinsX() + 1): rank_histof.SetBinContent(i, h.GetBinContent(i)) h.SetTitle("Ranks Summary;Rank;Frequency") h.Draw("Hist") c.Update() rank_histof.ComputeIntegral() integral = rank_histof.GetIntegral() rank_histof.SetContent(integral) rightmax = 1.1 * rank_histof.GetMaximum() scale = gPad.GetUymax() / rightmax rank_histof.SetLineColor(kRed) rank_histof.Scale(scale) rank_histof.Draw("same") #draw an axis on the right side axis = TGaxis(gPad.GetUxmax(), gPad.GetUymin(), gPad.GetUxmax(), gPad.GetUymax(), 0, rightmax, 510, "+L") axis.SetTitle("Cumulative") axis.SetTitleColor(kRed) axis.SetLineColor(kRed) axis.SetLabelColor(kRed) axis.Draw() rank_histof.Draw("Same") c.Print(imgname) page_html = '<div class="span-20"><h2 class="alt"><a name="rank_summary">Ranks Summary</a></h2>' page_html += '<div class="span-19"><img src="%s"></div>' % imgname page_html += '</div> <a href="#top">Top...</a><hr>' return page_html
ymax = 1. graph_pratio_allmases.Draw("AP") graph_pratio_allmases.GetXaxis().SetTitle("Nr of tracks") graph_pratio_allmases.GetYaxis().SetTitle("<ratio>") graph_pratio_allmases.GetYaxis().SetRangeUser(0., ymax) graph_pratio_allmases.Draw("AP") graph_ntr_allmases.Draw("*") leg_all = TLegend(0.65, 0.35, 0.9, 0.55) leg_all.AddEntry(graph_pratio_allmases, "pratio", "l") leg_all.AddEntry(graph_ntr_allmases, "number of tracks", "p") leg_all.SetTextSize(0.015) leg_all.Draw() axis = TGaxis(10.8, 0., 10.8, ymax, 0, ymax * rightmax / leftmax, 510, "+L") axis.SetLineColor(2) axis.SetLabelColor(2) axis.Draw() c_allmases.cd(4) zmax = 0.07 graph_deltar_allmases.Draw("AP") graph_deltar_allmases.GetXaxis().SetTitle("Nr of tracks") graph_deltar_allmases.GetYaxis().SetTitle("deltaR") graph_deltar_allmases.GetYaxis().SetRangeUser(0., zmax) graph_deltar_allmases.Draw("AP") graph_ntr_allmases2.Draw("*") axis2 = TGaxis(10.8, 0., 10.8, zmax, 0, zmax * rightmax2 / leftmax2, 510, "+L") axis2.SetLineColor(2) axis2.SetLabelColor(2) axis2.Draw()
shift = TMath.Abs( hRawYields.GetBinContent(iPt) - hRawYieldDistr[-1].GetMean()) / hRawYieldDistr[-1].GetMean() * 100 syst = TMath.Sqrt(rms**2 + shift**2) hRMS.SetBinContent(iPt, rms) hMeanShift.SetBinContent(iPt, shift) hSyst.SetBinContent(iPt, syst) cRMS = TCanvas('cRMS', '', 800, 800) cRMS.DrawFrame(hRMS.GetBinLowEdge(1), 0.1, ptMax, 20., ';#it{p}_{T} (GeV/#it{c});RMS (%)') hRMS.DrawCopy('same') axisSoverB = TGaxis(gPad.GetUxmax(), gPad.GetUymin(), gPad.GetUxmax(), gPad.GetUymax(), 0.01, 20., 510, "+LG") axisSoverB.SetLineColor(kRed + 1) axisSoverB.SetLabelColor(kRed + 1) axisSoverB.SetLabelFont(42) axisSoverB.SetLabelSize(0.045) axisSoverB.SetTitle('S/B (3#sigma)') axisSoverB.SetTitleOffset(1.2) axisSoverB.SetLabelOffset(0.012) axisSoverB.SetTitleColor(kRed + 1) axisSoverB.SetTitleFont(42) axisSoverB.SetTitleSize(0.05) axisSoverB.SetMaxDigits(3) axisSoverB.Draw() hSoverB.DrawCopy('same') cRMS.Update() cSyst = TCanvas('cSyst', '', 800, 800) cSyst.DrawFrame(hSyst.GetBinLowEdge(1), 0.1, ptMax, 20.,
def AddShadedProfile(can, hist): tobject_collector = [] if can.GetPrimitive('pad_top'): GetTopPad(can).SetRightMargin(0.08) GetBotPad(can).SetRightMargin(0.08) tobject_collector.extend( AddShadedProfile(can.GetPrimitive('pad_top'), hist)) GetBotPad(can).Modified() GetBotPad(can).Update() return tobject_collector from ROOT import TH1, TGraph, THStack, TColor, kGray, kBlue, TGaxis, TText listOfPlottedObjects = [ o for o in can.GetListOfPrimitives() if isinstance(o, (TH1, THStack)) ] listOfPlottedObjects += [ o.GetHistogram() for o in can.GetListOfPrimitives() if isinstance(o, TGraph) ] #print listOfPlottedObjects minValue = 0 maxValue = 1 if listOfPlottedObjects: #maxValue = max([o.GetBinContent(o.GetMaximumBin()) for o in listOfPlottedObjects]) #minValue = min([o.GetBinContent(o.GetMinimumBin()) for o in listOfPlottedObjects]) maxValue = max([ o.GetBinContent(o.GetMaximumBin()) + o.GetBinError(o.GetMaximumBin()) for o in listOfPlottedObjects ]) minValue = min([ o.GetBinContent(o.GetMinimumBin()) - o.GetBinError(o.GetMinimumBin()) for o in listOfPlottedObjects ]) # #print [o.GetMaximum() for o in listOfPlottedObjects] #maxValue = can.GetUymax() #minValue = can.GetUymin() #print maxValue, minValue temp = hist.Clone() temp.SetName("ShadedProfile") temp.SetFillStyle(1001) lightgray = 1001 #color = TColor(lightgray, 0.956, 0.956, 0.956) temp.SetFillColorAlpha(kGray, 0.15) temp.SetLineColor(kGray) #temp.Scale(1./16000) temp.SetStats(0) origMax = temp.GetMaximum() if origMax > 0: temp.Scale(1. / origMax) minCanValue = can.GetUymin() temp.Scale(maxValue - minCanValue) # Get new min value for x in range(temp.GetNbinsX() + 1): temp.AddBinContent(x, minCanValue) #temp.Scale(0.9*maxValue) #print maxValue #for (int x=1; x<=temp->GetXaxis()->GetNbins(); x++) # temp->SetBinContent(x,temp->GetBinContent(x)+0.61) can.cd() temp.Draw("hist same") tobject_collector.append(temp) axis = TGaxis(can.GetUxmax(), can.GetUymin(), can.GetUxmax(), maxValue, 0, origMax, 510, "+L") axis.SetLineColor(kGray) axis.SetLabelColor(kGray) #axis.SetTitle("count") axis.Draw() tobject_collector.append(axis) can.SetTicks(can.GetTickx(), 0) can.Modified() can.Update() #text = TText(0,0, "count"); #text.SetTextAlign(13) #text.SetTextAngle(90) #text.SetTextColor(kGray) #text.Draw() #tobject_collector.append(text) return tobject_collector
class Differential1D: """ Base class for displaying 1D differential plots. Produces a plot comparing the baseline geometry (base) to the geometry specified by the geom arguement. The quantity plotted is given by the "stat" option, and is limited to the different statistics created by the StarBASE application. At present, these include: stat="radlen" :: plots number of radiation lengths of material encountered ... need to add more stats The plot will show a solid histogram for the baseline geometry, with the comparison geometry shown with red hashes. The fractional difference (baseline-comp)/baseline is shown at the bottom in blue, scaled according to the alternate axis at the right. base: selects the baseline geometry. [Mandatory] geom: selects the comparison geometry. [Mandatory] volume: selects the volume to be compared. [Mandatory] geomvolume: selects the volume in the comparison geometry. [Default: same] stat: selects the statistic to compare. [Default: radlen] xmin, xmax: x-axis range. [Optional] ymin, ymax: y-axis range. [Optional] """ def __init__(self, base, geom, volume="EMSS", geomvolume="same", stat="radlen", xmin=+0., xmax=-1., ymin=+0., ymax=-1., canvas=0, legend=False ): self.name = volume self.base = base self.geom = geom baseFile = get_geom_file(base) # get the files compFile = get_geom_file(geom) hname = "h_"+stat+"_"+volume+"_eta" # retrive the histograms from the files print "Get histo: " + str(hname) self.histo_base = stat_histo( stat, volume, file=baseFile ) if ( geomvolume == "same" ): self.histo_comp = stat_histo( stat, volume, compFile ) else: self.histo_comp = stat_histo( stat, geomvolume, compFile ) self.histo_diff = self.histo_base.Clone( hname + "_diff" ) # difference the histograms self.histo_diff.Add( self.histo_comp, -1.0 ) self.histo_diff.Divide(self.histo_base) # diff will be (old-new)/old * 100% if ( canvas == 0 ): canvas = TCanvas("temp"+base+geom+volume+geomvolume,"Differential 1D: baseline="+base+" compare="+geom,500,400); self.canvas = canvas # Detect and apply optional x-axis range if ( xmax > xmin ): self.histo_base.GetXaxis().SetRangeUser(xmin,xmax) self.histo_comp.GetXaxis().SetRangeUser(xmin,xmax) # ... or zoom in on an appropriate scale else: # auto_range( self.histo_base ) # auto_range( self.histo_comp ) xmin = auto_min( self.histo_base ) xmax = auto_max( self.histo_base ) self.histo_base.GetXaxis().SetRangeUser(xmin,xmax) self.histo_comp.GetXaxis().SetRangeUser(xmin,xmax) # xmin = TMath.Min( self.histo_base.GetXaxis().GetXmin(),self.histo_comp.GetXaxis().GetXmin() ) # xmax = TMath.Max( self.histo_base.GetXaxis().GetXmax(),self.histo_comp.GetXaxis().GetXmax() ) # print "xmin="+str(xmin) # print "xmax="+str(xmax) # Detect and apply optional y-axis range if ( ymax > ymin ): self.histo_base.GetYaxis().SetRangeUser(ymin,ymax) else: ymin = self.histo_base.GetMinimum() ymax = TMath.Max( self.histo_base.GetMaximum(), self.histo_comp.GetMaximum()) ymax *= 1.05 # Current range in y-axis extends from 0 to ymax. We want # to expand this to go from -0.2*ymax to ymax. ymin = -0.2 * ymax self.histo_base.GetYaxis().SetRangeUser(ymin,ymax) # Draw the baseline and comparison histograms self.histo_base.SetLineWidth(2) self.histo_base.SetFillStyle(1001) self.histo_base.SetFillColor(22) self.histo_base.Draw() self.histo_comp.SetLineColor(2) self.histo_comp.SetLineStyle(2) self.histo_comp.SetFillStyle(3345) self.histo_comp.SetFillColor(2) self.histo_comp.Draw("same") # Rescale difference histogram so that it is in percent self.histo_diff.Scale(100.0) # This is the maximum of the histogram. yfull_max = self.histo_diff.GetMaximum() yfull_min = self.histo_diff.GetMinimum() yfull = TMath.Max( yfull_max, TMath.Abs( yfull_min ) ) self.max_differential = yfull yfull *= 1.3 if ( yfull == 0. ): yfull = 1.0 # We need to rescale the histogram so that it fits w/in 10% of ymax self.histo_diff.Scale( 0.10 * ymax / yfull ) # Next we shift the histogram down by 0.1 * ymax nbinx=self.histo_diff.GetNbinsX(); i=1 while ( i<=nbinx ): self.histo_diff[i] -= 0.1 * ymax i+=1 # Reset the line color and draw on the same plot self.histo_diff.SetLineColor(4) self.histo_diff.Draw("same") self.line = TLine(xmin, -0.1 * ymax, xmax, -0.1*ymax ) self.line.SetLineStyle(3) self.line.Draw() # And superimpose an axis on the new plot xa = xmax self.axis = TGaxis( xa, -0.2*ymax, xa, 0.0, -yfull, +yfull, 50510, "-+L" ) self.axis.SetLabelSize(0.03) self.axis.SetLabelOffset(-0.02) self.axis.SetLineColor(4) self.axis.SetTextColor(4) self.axis.SetLabelColor(4) self.axis.SetNdivisions(4) # self.axis.SetTitle("(base-comp)/base [%]") self.axis.SetTitleSize(0.0175) self.axis.SetTitleOffset(-0.5) self.axis.Draw(); # Add the legend if requested if ( legend ): self.legend = TLegend( 0.78, 0.80, 0.98, 0.98 ) self.legend.AddEntry( self.histo_base, base ) self.legend.AddEntry( self.histo_comp, geom ) self.legend.AddEntry( self.histo_diff, "#frac{"+base+"-"+geom+"}{"+base+"} [%]" ) self.legend.Draw()
ymax = hxE.GetYaxis().GetXmax() dy = (ymax - ymin) / 0.8 #10 margins top and bottom xmin = hxE.GetXaxis().GetXmin() xmax = hxE.GetXaxis().GetXmax() dx = (xmax - xmin) / 0.8 #10 per cent margins left and right pad2.Range(xmin - 0.1 * dx, ymin - 0.1 * dy, xmax + 0.1 * dx, ymax + 0.1 * dy) pad2.Draw() pad2.cd() hxE.SetMarkerColor(ROOT.kViolet) hxE.Draw("][scat same") pad2.Update() # draw axis on the right side of the pad axis = TGaxis(xmax, ymin, xmax, ymax, ymin, ymax, 50510, "+L") axis.SetLineColor(ROOT.kViolet) axis.SetLabelColor(ROOT.kViolet) axis.SetTitle("E [GeV]") axis.SetTitleColor(ROOT.kViolet) axis.SetLabelSize(0.035) axis.SetTitleSize(0.035) axis.Draw() #### yz cnv.cd(2) ROOT.gPad.SetTicks(1, 1) ROOT.gPad.SetLogz() ROOT.gPad.SetGridy() ROOT.gPad.SetGridx() # hyz = tfile.Get("h2_z_vs_y") hyz.SetTitle(ptitle + " for #it{B} = " + btitle) hyz.Draw("col") dipoleOutYZ.Draw("same")