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
gr_minus.SetLineWidth(4) gr_minus.SetMarkerSize(3) gr_minus.SetMarkerStyle(21) gr_minus.SetMarkerColor(4) gr_plus.Draw("ep same") gr_minus.Draw("ep same") canvas.Update() axis = TGaxis(ROOT.gPad.GetUxmax(), ROOT.gPad.GetUymin(), ROOT.gPad.GetUxmax(), ROOT.gPad.GetUymax(), 0, 2, 510, "+L") axis.SetTitle("Temperature (before - after) [degC]") axis.SetTitleOffset(1.5) axis.SetTitleFont(42) axis.SetLineColor(6) axis.SetTextColor(6) axis.SetLabelFont(42) axis.Draw() gr_temp.SetLineColor(6) gr_temp.SetLineWidth(4) gr_temp.SetMarkerSize(3) gr_temp.SetMarkerStyle(22) gr_temp.SetMarkerColor(6) label = ROOT.TLatex(0.68, 0.75, klayer) label.SetNDC() label2 = ROOT.TLatex(0.2, 0.93, "CMS") label2.SetNDC()
c_allmases.cd(3) 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)
def train_and_apply(): np.random.seed(1) ROOT.gROOT.SetBatch() #Extract data from root file tree = uproot.open("out_all.root")["outA/Tevts"] branch_mc = [ "MC_B_P", "MC_B_eta", "MC_B_phi", "MC_B_pt", "MC_D0_P", "MC_D0_eta", "MC_D0_phi", "MC_D0_pt", "MC_Dst_P", "MC_Dst_eta", "MC_Dst_phi", "MC_Dst_pt", "MC_Est_mu", "MC_M2_miss", "MC_mu_P", "MC_mu_eta", "MC_mu_phi", "MC_mu_pt", "MC_pis_P", "MC_pis_eta", "MC_pis_phi", "MC_pis_pt", "MC_q2" ] branch_rec = [ "B_P", "B_eta", "B_phi", "B_pt", "D0_P", "D0_eta", "D0_phi", "D0_pt", "Dst_P", "Dst_eta", "Dst_phi", "Dst_pt", "Est_mu", "M2_miss", "mu_P", "mu_eta", "mu_phi", "mu_pt", "pis_P", "pis_eta", "pis_phi", "pis_pt", "q2" ] nvariable = len(branch_mc) x_train = tree.array(branch_mc[0], entrystop=options.maxevents) for i in range(1, nvariable): x_train = np.vstack( (x_train, tree.array(branch_mc[i], entrystop=options.maxevents))) x_test = tree.array(branch_rec[0], entrystop=options.maxevents) for i in range(1, nvariable): x_test = np.vstack( (x_test, tree.array(branch_rec[i], entrystop=options.maxevents))) x_train = x_train.T x_test = x_test.T x_test = array2D_float(x_test) #Different type of reconstruction variables #BN normalization gamma = 0 beta = 0.2 ar = np.array(x_train) a = K.constant(ar[:, 0]) mean = K.mean(a) var = K.var(a) x_train = K.eval(K.batch_normalization(a, mean, var, gamma, beta)) for i in range(1, nvariable): a = K.constant(ar[:, i]) mean = K.mean(a) var = K.var(a) a = K.eval(K.batch_normalization(a, mean, var, gamma, beta)) x_train = np.vstack((x_train, a)) x_train = x_train.T ar = np.array(x_test) a = K.constant(ar[:, 0]) mean = K.mean(a) var = K.var(a) x_test = K.eval(K.batch_normalization(a, mean, var, gamma, beta)) for i in range(1, nvariable): a = K.constant(ar[:, i]) mean = K.mean(a) var = K.var(a) a = K.eval(K.batch_normalization(a, mean, var, gamma, beta)) x_test = np.vstack((x_test, a)) x_test = x_test.T #Add noise, remain to be improved noise = np.random.normal(loc=0.0, scale=0.01, size=x_train.shape) x_train_noisy = x_train + noise noise = np.random.normal(loc=0.0, scale=0.01, size=x_test.shape) x_test_noisy = x_test + noise x_train = np.clip(x_train, -1., 1.) x_test = np.clip(x_test, -1., 1.) x_train_noisy = np.clip(x_train_noisy, -1., 1.) x_test_noisy = np.clip(x_test_noisy, -1., 1.) # Network parameters input_shape = (x_train.shape[1], ) batch_size = 128 latent_dim = 2 # Build the Autoencoder Model # First build the Encoder Model inputs = Input(shape=input_shape, name='encoder_input') x = inputs # Shape info needed to build Decoder Model shape = K.int_shape(x) # Generate the latent vector latent = Dense(latent_dim, name='latent_vector')(x) # Instantiate Encoder Model encoder = Model(inputs, latent, name='encoder') encoder.summary() # Build the Decoder Model latent_inputs = Input(shape=(latent_dim, ), name='decoder_input') x = Dense(shape[1])(latent_inputs) x = Reshape((shape[1], ))(x) outputs = Activation('tanh', name='decoder_output')(x) # Instantiate Decoder Model decoder = Model(latent_inputs, outputs, name='decoder') decoder.summary() # Autoencoder = Encoder + Decoder # Instantiate Autoencoder Model autoencoder = Model(inputs, decoder(encoder(inputs)), name='autoencoder') autoencoder.summary() autoencoder.compile(loss='mse', optimizer='adam') # Train the autoencoder autoencoder.fit(x_train_noisy, x_train, validation_data=(x_test_noisy, x_test), epochs=options.epochs, batch_size=batch_size) # Predict the Autoencoder output from corrupted test imformation x_decoded = autoencoder.predict(x_test_noisy) # Draw Comparision Plots c = TCanvas("c", "c", 700, 700) fPads1 = TPad("pad1", "Run2", 0.0, 0.29, 1.00, 1.00) fPads2 = TPad("pad2", "", 0.00, 0.00, 1.00, 0.29) fPads1.SetBottomMargin(0.007) fPads1.SetLeftMargin(0.10) fPads1.SetRightMargin(0.03) fPads2.SetLeftMargin(0.10) fPads2.SetRightMargin(0.03) fPads2.SetBottomMargin(0.25) fPads1.Draw() fPads2.Draw() fPads1.cd() nbin = 50 min = -1. max = 1. variable = "P^{B}" lbin = (max - min) / nbin lbin = str(float((max - min) / nbin)) xtitle = branch_rec[options.branch - 1] ytitle = "Events/" + lbin + "GeV" h_rec = TH1D("h_rec", "" + ";%s;%s" % (xtitle, ytitle), nbin, min, max) h_rec.Sumw2() h_pre = TH1D("h_pre", "" + ";%s;%s" % (xtitle, ytitle), nbin, min, max) h_pre.Sumw2() for i in range(x_test_noisy.shape[0]): h_rec.Fill(x_test_noisy[i][options.branch - 1]) h_pre.Fill(x_decoded[i][options.branch - 1]) h_rec = UnderOverFlow1D(h_rec) h_pre = UnderOverFlow1D(h_pre) maxY = TMath.Max(h_rec.GetMaximum(), h_pre.GetMaximum()) h_rec.SetLineColor(2) h_rec.SetFillStyle(0) h_rec.SetLineWidth(2) h_rec.SetLineStyle(1) h_pre.SetLineColor(3) h_pre.SetFillStyle(0) h_pre.SetLineWidth(2) h_pre.SetLineStyle(1) h_rec.SetStats(0) h_pre.SetStats(0) h_rec.GetYaxis().SetRangeUser(0, maxY * 1.1) h_rec.Draw("HIST") h_pre.Draw("same HIST") h_rec.GetYaxis().SetTitleSize(0.06) h_rec.GetYaxis().SetTitleOffset(0.78) theLeg = TLegend(0.5, 0.45, 0.95, 0.82, "", "NDC") theLeg.SetName("theLegend") theLeg.SetBorderSize(0) theLeg.SetLineColor(0) theLeg.SetFillColor(0) theLeg.SetFillStyle(0) theLeg.SetLineWidth(0) theLeg.SetLineStyle(0) theLeg.SetTextFont(42) theLeg.SetTextSize(.05) theLeg.AddEntry(h_rec, "Reconstruction", "L") theLeg.AddEntry(h_pre, "Prediction", "L") theLeg.SetY1NDC(0.9 - 0.05 * 6 - 0.005) theLeg.SetY1(theLeg.GetY1NDC()) fPads1.cd() theLeg.Draw() title = TLatex( 0.91, 0.93, "AE prediction compare with reconstruction, epochs=" + str(options.epochs)) title.SetNDC() title.SetTextSize(0.05) title.SetTextFont(42) title.SetTextAlign(31) title.SetLineWidth(2) title.Draw() fPads2.cd() h_Ratio = h_pre.Clone("h_Ratio") h_Ratio.Divide(h_rec) h_Ratio.SetLineColor(1) h_Ratio.SetLineWidth(2) h_Ratio.SetMarkerStyle(8) h_Ratio.SetMarkerSize(0.7) h_Ratio.GetYaxis().SetRangeUser(0, 2) h_Ratio.GetYaxis().SetNdivisions(504, 0) h_Ratio.GetYaxis().SetTitle("Pre/Rec") h_Ratio.GetYaxis().SetTitleOffset(0.35) h_Ratio.GetYaxis().SetTitleSize(0.13) h_Ratio.GetYaxis().SetTitleSize(0.13) h_Ratio.GetYaxis().SetLabelSize(0.11) h_Ratio.GetXaxis().SetLabelSize(0.1) h_Ratio.GetXaxis().SetTitleOffset(0.8) h_Ratio.GetXaxis().SetTitleSize(0.14) h_Ratio.SetStats(0) axis1 = TGaxis(min, 1, max, 1, 0, 0, 0, "L") axis1.SetLineColor(1) axis1.SetLineWidth(1) for i in range(1, h_Ratio.GetNbinsX() + 1, 1): D = h_rec.GetBinContent(i) eD = h_rec.GetBinError(i) if D == 0: eD = 0.92 B = h_pre.GetBinContent(i) eB = h_pre.GetBinError(i) if B < 0.1 and eB >= B: eB = 0.92 Err = 0. if B != 0.: Err = TMath.Sqrt((eD * eD) / (B * B) + (D * D * eB * eB) / (B * B * B * B)) h_Ratio.SetBinContent(i, D / B) h_Ratio.SetBinError(i, Err) if B == 0.: Err = TMath.Sqrt((eD * eD) / (eB * eB) + (D * D * eB * eB) / (eB * eB * eB * eB)) h_Ratio.SetBinContent(i, D / 0.92) h_Ratio.SetBinError(i, Err) if D == 0 and B == 0: h_Ratio.SetBinContent(i, -1) h_Ratio.SetBinError(i, 0) h_Ratio.Draw("e0") axis1.Draw() c.SaveAs(branch_rec[options.branch - 1] + "_comparision.png")
rms = hRawYieldDistr[-1].GetRMS() / hRawYieldDistr[-1].GetMean() * 100 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)
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()
ymin = hxE.GetYaxis().GetXmin() 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")