lines[-txtid].SetLineStyle(style) lines[-txtid].SetLineColor(color) if 'Axis' in param: paxis = param['Axis'] axis_margin = 0.015 * (plot_range['ymax'] - plot_range['ymin']) axis = TGaxis(-param['TextWidth'] - param['space'], paxis['range_min'], -param['TextWidth'] - param['space'], paxis['range_max'], paxis['range_min'], paxis['range_max'], paxis['ticks'], "") axis.SetTitle(paxis['title']) axis.SetLabelSize(paxis['label_size']) axis.SetTitleSize(paxis['title_size']) axis.SetTitleOffset(paxis['title_offset']) axis.Draw() for line in lines: line.SetLineWidth(param['LineWidth']) alllines.append(line) for text in texts: text.SetTextSize(param['TextSize']) text.Draw() for i_g, g in enumerate(gamma): #python2 #level1 = filter(lambda x: x.GetY1() == g['from'],lines)[0] #level2 = filter(lambda x: x.GetY1() == g['to'],lines)[0] #python3 level1 = next(filter(lambda x: x.GetY1() == g['from'], lines))
mg.GetYaxis().SetMoreLogLabels() mg.GetYaxis().SetTitleOffset(1.9) legend.SetBorderSize(0) legend.SetTextSize(0.03) legend.Draw("same") c.SetGrid() gStyle.SetGridStyle(2) gStyle.SetGridColor(ROOT.kGray) latex = Text(gPad, 0.88,0.65, "#scale[1.2]{#bf{CMS}} #font[50]{Preliminary}", align = 33) latex = Text(gPad, 0.88,0.60,"Run2 Data (13 TeV)", align = 33,size = 0.03) if args.glob: latex = Text(gPad, 0.88,0.55,"Z#rightarrow ee events, EB", align = 33,size = 0.03) if args.loc: latex = Text(gPad, 0.88,0.55,"Same cluster, EB", align = 33,size = 0.03) latex = Text(gPad, 0.88,0.48,"#sigma = #frac{N}{A_{eff}} #font[62]{#oplus} #sqrt{2}C", align = 33,size = 0.04) top_axis = TGaxis(xmin ,mg.GetHistogram().GetMaximum(),xmax,mg.GetHistogram().GetMaximum(),ADC2GEV_B*xmin,ADC2GEV_B*xmax,510,"G-"); top_axis.SetTitle("E [GeV]") top_axis.SetTitleSize(0.035) top_axis.SetLabelSize(0.035) top_axis.SetTitleFont(42) top_axis.SetLabelFont(42) top_axis.Draw() Frame(gPad) c.Update() c.Modified() input() c.SaveAs("plots/"+args.tag+"/allYears/sigma_"+name+".png") c.SaveAs("plots/"+args.tag+"/allYears/sigma_"+name+".pdf")
graph_exclusion_cms_8TeV_2g = TGraph(6, mass_cms_8TeV_2g, ctau_cms_8TeV_2g) graph_exclusion_cms_8TeV_2g.SetFillColorAlpha(kGray, 0.6) graph_exclusion_cms_8TeV_2g.SetLineColorAlpha(kGray, 0.6) graph_exclusion_cms_8TeV_2g.Draw("Fsames") #Lambda axis f1_lambda = TF1("f1", "(x+6.00)/1.454", 72.902, 416.78) A1_lambda = TGaxis(100.0, 0.02, 600.0, 0.02, "f1", 1010, "NI") A1_lambda.SetLabelFont(42) A1_lambda.SetLabelSize(0.035) A1_lambda.SetTextFont(42) A1_lambda.SetTextSize(1.2) A1_lambda.SetTitle("#Lambda [TeV]") A1_lambda.SetTitleSize(0.04) A1_lambda.SetTitleOffset(0.9) A1_lambda.Draw() ### only graph_exclusion_exp_ = TGraph( len(lambda_point_boundary_exp_), np.array(1.454 * lambda_point_boundary_exp_ - 6.0), np.array(ctau_points)) graph_exclusion_obs_ = TGraph( len(lambda_point_boundary_obs_), np.array(1.454 * lambda_point_boundary_obs_ - 6.0), np.array(ctau_points)) graph_exclusion_exp_.GetXaxis().SetTitleSize(axisTitleSize) graph_exclusion_exp_.GetXaxis().SetTitleOffset(axisTitleOffset) graph_exclusion_exp_.GetYaxis().SetTitleSize(axisTitleSize) graph_exclusion_exp_.GetYaxis().SetTitleOffset(axisTitleOffset)
if drawObs: leg_2d_exclusion_.AddEntry(graph_exclusion_obs_, "CMS observed " + label_this_withoutY, "L") leg_2d_exclusion_.AddEntry( graph_exclusion_atlas_8TeV_2g, "ATLAS observed 20.3 fb^{-1} (8 TeV), #gamma#gamma", "L") #leg_2d_exclusion_.AddEntry(graph_exclusion_cms_8TeV_2g, "CMS Obs 8 TeV #gamma#gamma", "F") #leg_2d_exclusion_.AddEntry(graph_exclusion_cms_8TeV_1g, "CMS Obs 8 TeV #gamma", "F") leg_2d_exclusion_.AddEntry(graph_exclusion_cms_7TeV_1g, "CMS observed 4.9 fb^{-1} (7 TeV), #gamma", "L") leg_2d_exclusion_.Draw("same") #drawCMS3(myC2D, 13, lumi_this) A1_lambda.Draw("same") myC2D.SaveAs(outputDir + "/limits" + "/limit_exclusion_region_2D_" + year_this + plot_tag + ".pdf") myC2D.SaveAs(outputDir + "/limits" + "/limit_exclusion_region_2D_" + year_this + plot_tag + ".png") myC2D.SaveAs(outputDir + "/limits" + "/limit_exclusion_region_2D_" + year_this + plot_tag + ".C") ##draw only this analysis, with color map ##2D color map myC2D.SetLogz(1) #stops = np.array([0.0, 1.0]) #red = np.array([0.0, 0.8]) #green = np.array([0.3, 1.0])
tHalfLow_y = SensClass.GetTHalf(mbbMax_meV * 1.e-3 * CLHEP.eV, isotope, nmeModel, ga) / CLHEP.year tHalfHigh_y = SensClass.GetTHalf(mbbMin_meV * 1.e-3 * CLHEP.eV, isotope, nmeModel, ga) / CLHEP.year nLabels = 4 gAxis = TGaxis(expMax_ty * 1.01, mbbMax_meV, expMax_ty - (expMax_ty - expMin_ty) / 10000., mbbMin_meV, tHalfLow_y, tHalfHigh_y, nLabels, "-G") if (options.xenon136): gAxis.SetTitle("^{136}Xe T^{0#nu}_{1/2} sensitivity (90% CL) [years]") else: gAxis.SetTitle("^{76}Ge T^{0#nu}_{1/2} sensitivity (90% CL) [years]") gAxis.SetTitleOffset(1.4) gAxis.SetBit(TAxis.kRotateTitle) gAxis.SetBit(TAxis.kCenterTitle) gAxis.Draw() else: mbbHi_meV = SensClass.GetMbb(tHalfMin_y * CLHEP.year, isotope, nmeModel, ga) / CLHEP.meV mbbLow_meV = SensClass.GetMbb(tHalfMax_y * CLHEP.year, isotope, nmeModel, ga) / CLHEP.meV nLabels = 4 gAxis = TGaxis(expMax_ty * 1.01, tHalfMax_y, expMax_ty - (expMax_ty - expMin_ty) / 10000., tHalfMin_y, mbbLow_meV, mbbHi_meV, nLabels, "-G") gAxis.SetTitle("m_{#beta#beta} sensitivity (90% CL) [meV]") gAxis.SetTitleOffset(1.2) gAxis.SetTitleFont(hiBGFunc.GetYaxis().GetTitleFont()) gAxis.SetTitleSize(hiBGFunc.GetYaxis().GetTitleSize()) gAxis.SetLabelFont(hiBGFunc.GetYaxis().GetLabelFont()) gAxis.SetLabelSize(hiBGFunc.GetYaxis().GetLabelSize())
def makeTwoScalesGraph(file): print(file) ch1 = OPData.fromPath('../data/part3/%s' % file, 1) ch2 = OPData.fromPath('../data/part3/%s' % file, 2) print('make canvas + pad') c = TCanvas('c-%s' % file, '', 1280, 720) pad = TPad('pad-%s' % file, '', 0, 0, 1, 1) pad.Draw() pad.cd() print('frame') frame = pad.DrawFrame(0, min(ch1.getY()) * 1.1, 0.051, max(ch1.getY()) * 1.1) frame.SetXTitle('Zeit t / s') frame.GetXaxis().CenterTitle() frame.SetYTitle('Spannung Spule 2: U_{2} / V') frame.GetYaxis().CenterTitle() frame.GetYaxis().SetLabelColor(4) frame.GetYaxis().SetTitleColor(4) print('g1') g1 = ch1.makeGraph('g1-%s' % file) prepareGraph(g1) g1.Draw('PX') print('overlay') c.cd() overlay = TPad('overlay-%s' % file, '', 0, 0, 1, 1) overlay.SetFillStyle(4000) # transparent overlay.SetFillColor(0) # white overlay.SetFrameFillStyle(4000) # transparent overlay.Draw() overlay.cd() print('g2') g2 = ch2.makeGraph('g2-%s' % file) prepareGraph(g2, 2) g2ymin = min(ch2.getY()) xmin = pad.GetUxmin() xmax = pad.GetUxmax() ymin = 1.1 * g2ymin ymax = abs(ymin) if file == '07.tab': # same scale like 06.tab ymin, ymax = -0.07128, 0.07128 oframe = overlay.DrawFrame(xmin, ymin, xmax, ymax) oframe.GetXaxis().SetLabelOffset(99) oframe.GetYaxis().SetLabelOffset(99) oframe.GetYaxis().SetTickLength(0) g2.Draw('PX') print('axis') axis = TGaxis(xmax, ymin, xmax, ymax, ymin, ymax, 510, "+L") axis.SetTitle('Spannung Photodiode: U_{ph} / V') axis.CenterTitle() axis.SetTitleOffset(1.2) axis.Draw() print('print') c.Update() c.Print('../img/part3/%s.pdf' % file[:-4], 'pdf')
def train_and_apply(): np.random.seed(1) ROOT.gROOT.SetBatch() #Extract data from root file tree = uproot.open("SIM_100.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 = 100 # 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) outputs = Activation('tanh')(x) # Instantiate Decoder Model decoder = Model(latent_inputs, outputs) decoder.summary() # Autoencoder = Encoder + Decoder # Instantiate Autoencoder Model autoencoder = Model(inputs, decoder(encoder(inputs)), name='autoencoder') autoencoder.summary() # Train the autoencoder - 'mse' autoencoder.compile(loss='mse', optimizer='adam') 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) # mean # Train the autoencoder - quantile_loss autoencoder.compile(loss=quantile_loss, optimizer='adam') 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_quantile_loss = autoencoder.predict(x_test_noisy) # mean+sigma # Draw Comparision Plots os.system("rm -rf Plots") os.system("mkdir Plots") for j in range(0, nvariable): 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. lbin = (max - min) / nbin lbin = str(float((max - min) / nbin)) xtitle = branch_rec[j] ytitle = "Events/" + lbin h_gen = TH1D("h_gen", "" + ";%s;%s" % (xtitle, ytitle), nbin, min, max) h_gen.Sumw2() 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_gen.Fill(x_train_noisy[i][j]) h_rec.Fill(x_test_noisy[i][j]) h_pre.Fill(x_decoded[i][j]) h_gen = UnderOverFlow1D(h_gen) h_rec = UnderOverFlow1D(h_rec) h_pre = UnderOverFlow1D(h_pre) maxR = 2 maxY = TMath.Max(h_rec.GetMaximum(), h_pre.GetMaximum()) h_gen.SetLineColor(4) h_gen.SetFillStyle(0) h_gen.SetLineWidth(2) h_gen.SetLineStyle(1) 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_gen.SetStats(0) h_rec.SetStats(0) h_pre.SetStats(0) h_gen.GetYaxis().SetRangeUser(0, maxY * 1.1) h_gen.Draw("HIST") h_rec.Draw("same HIST") h_pre.Draw("same HIST") h_gen.GetYaxis().SetTitleSize(0.06) h_gen.GetYaxis().SetTitleOffset(0.85) theLeg = TLegend(0.58, 0.45, 0.99, 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_gen, "Generation", "L") 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 = TH1D("h_Ratio", "" + ";%s;%s" % (xtitle, ytitle), nbin, min, max) h_Ratio.SetLineColor(1) h_Ratio.SetLineWidth(2) h_Ratio.SetMarkerStyle(8) h_Ratio.SetMarkerSize(0.7) h_Ratio.GetYaxis().SetRangeUser(0, maxR) 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_pre.GetBinContent(i) eD = h_pre.GetBinError(i) if D == 0: eD = 0.92 B = h_rec.GetBinContent(i) eB = h_rec.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) if h_Ratio.GetBinContent(i) > maxR: h_Ratio.SetBinContent(i, maxR) h_Ratio.Draw("e0") axis1.Draw() c.SaveAs("Plots/" + branch_rec[j] + "_comparision.png") #2D plots c2 = TCanvas("c2", "c2", 700, 700) fPads3 = TPad("pad3", "Run2", 0.0, 0.0, 1.00, 1.00) fPads3.SetBottomMargin(0.09) fPads3.SetLeftMargin(0.10) fPads3.SetRightMargin(0.15) fPads3.Draw() fPads3.cd() xtitle = branch_rec[j] + " (Rec)" ytitle = branch_rec[j] + " (Pre)" h_2D = TH2D("h_2D", "" + ";%s;%s" % (xtitle, ytitle), nbin, min, max, nbin, min, max) h_2D.Sumw2() h_2D.SetStats(0) for i in range(x_test_noisy.shape[0]): h_2D.Fill(x_test_noisy[i][j], x_decoded[i][j]) h_2D.GetYaxis().SetTitleSize(0.04) h_2D.GetYaxis().SetTitleOffset(1.20) h_2D.Draw("colz") title = TLatex( 0.93, 0.93, "AE prediction compare with reconstruction, epochs=" + str(options.epochs)) title.SetNDC() title.SetTextSize(0.04) title.SetTextFont(42) title.SetTextAlign(31) title.SetLineWidth(2) title.Draw() c2.SaveAs("Plots/2D_" + branch_rec[j] + "_comparision.png")
';#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., ';#it{p}_{T} (GeV/#it{c}); Syst (%)') SetObjectStyle(hRMS, color=kRed + 1, fillstyle=0, linewidth=3) SetObjectStyle(hMeanShift, color=kBlack, fillstyle=0, linewidth=3) SetObjectStyle(hSyst, color=kBlue + 1, fillstyle=0, linewidth=3) hMeanShift.DrawCopy('same') hSyst.DrawCopy('same') hRMS.DrawCopy('same') leg = TLegend(0.5, 0.8, 0.8, 0.95) leg.SetTextSize(0.04) leg.SetFillStyle(0)
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
def PlotOnCanvas(self, pdf_name): #gROOT.SetBatch(False) tdrstyle.setTDRStyle() canvas = TCanvas("c1", "c1", 600, 600) pad1 = TPad("pad1", "pad1", 0, 0.0, 1, 1.0) pad1.SetBottomMargin(0.32) pad1.SetGridx() pad1.Draw() pad1.cd() self.histo1.SetStats(0) self.histo1.Draw(self.option) self.histo2.Draw(self.option + " same") if self.logx: pad1.SetLogx() if self.logy: pad1.SetLogy() legend = TLegend(0.65, 0.7, 0.85, 0.83) legend.SetHeader("Legend", "C") legend.AddEntry(self.histo1, self.legend1, "l") legend.AddEntry(self.histo2, self.legend2, "l") legend.Draw() # Redraw axis to avoid clipping 0 self.histo1.GetXaxis().SetLabelSize(0.) self.histo1.GetXaxis().SetTitle('') axis = TGaxis(-9, -2.8, -9, 2.8, 0, 10000, 50510, "") axis.SetLabelFont(43) axis.SetLabelSize(15) axis.Draw("same") pad2 = TPad("pad2", "pad2", 0, 0.0, 1, 0.3) pad2.SetTopMargin(0) pad2.SetBottomMargin(0.4) pad2.SetGridx() pad2.Draw() pad2.cd() if self.logx: pad2.SetLogx() self.ratio.SetLineColor(ROOT.kBlack) self.ratio.SetMinimum(0.5) self.ratio.SetMaximum(1.5) self.ratio.SetStats(0) self.ratio.SetMarkerStyle(21) self.ratio.Draw("ep") self.histo1.SetLineColor(ROOT.kBlue + 1) self.histo1.SetLineWidth(2) max_y = max(self.histo1.GetMaximum(), self.histo2.GetMaximum()) self.histo1.SetMaximum(max_y * 1.1) self.histo1.GetYaxis().SetNdivisions(505) self.histo1.GetYaxis().SetTitleSize(20) self.histo1.GetYaxis().SetTitleFont(43) self.histo1.GetYaxis().SetTitleOffset(1.8) self.histo2.SetLineColor(ROOT.kRed) self.histo2.SetLineWidth(2) self.ratio.SetTitle("") self.ratio.GetYaxis().SetTitle("Ratio") self.ratio.GetYaxis().SetNdivisions(505) self.ratio.GetYaxis().SetTitleSize(20) self.ratio.GetYaxis().SetTitleFont(43) self.ratio.GetYaxis().SetTitleOffset(1.8) self.ratio.GetYaxis().SetLabelFont(43) self.ratio.GetYaxis().SetLabelSize(15) self.ratio.GetXaxis().SetNdivisions(510) self.ratio.GetXaxis().SetTitleSize(20) self.ratio.GetXaxis().SetTitleFont(43) self.ratio.GetXaxis().SetTitleOffset(4.) self.ratio.GetXaxis().SetLabelFont(43) self.ratio.GetXaxis().SetLabelSize(15) ROOT.SetOwnership(canvas, False) ROOT.SetOwnership(pad1, False) ROOT.SetOwnership(pad2, False) canvas.Print(pdf_name, 'Title:' + self.title) canvas.Close()
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()
def main(): # pylint: disable=too-many-locals, too-many-statements, too-many-branches """ Main plotting function """ gROOT.SetBatch(True) # pylint: disable=unused-variable parser = argparse.ArgumentParser() parser.add_argument("--database-analysis", "-d", dest="database_analysis", help="analysis database to be used", required=True) parser.add_argument("--analysis", "-a", dest="type_ana", help="choose type of analysis", required=True) parser.add_argument("--input", "-i", dest="input_file", help="results input file", required=True) args = parser.parse_args() typean = args.type_ana shape = typean[len("jet_"):] print("Shape:", shape) file_in = args.input_file with open(args.database_analysis, "r") as file_db: data_param = yaml.safe_load(file_db) case = list(data_param.keys())[0] datap = data_param[case] logger = get_logger() i_cut = file_in.rfind("/") rootpath = file_in[:i_cut] # plotting # LaTeX string p_latexnhadron = datap["analysis"][typean]["latexnamehadron"] p_latexbin2var = datap["analysis"][typean]["latexbin2var"] v_varshape_latex = datap["analysis"][typean]["var_shape_latex"] # first variable (hadron pt) lpt_finbinmin = datap["analysis"][typean]["sel_an_binmin"] lpt_finbinmax = datap["analysis"][typean]["sel_an_binmax"] var1ranges = lpt_finbinmin.copy() var1ranges.append(lpt_finbinmax[-1]) # second variable (jet pt) v_var2_binning = datap["analysis"][typean]["var_binning2"] # name lvar2_binmin_reco = datap["analysis"][typean].get("sel_binmin2_reco", None) lvar2_binmax_reco = datap["analysis"][typean].get("sel_binmax2_reco", None) p_nbin2_reco = len(lvar2_binmin_reco) # number of reco bins lvar2_binmin_gen = datap["analysis"][typean].get("sel_binmin2_gen", None) lvar2_binmax_gen = datap["analysis"][typean].get("sel_binmax2_gen", None) p_nbin2_gen = len(lvar2_binmin_gen) # number of gen bins var2ranges_reco = lvar2_binmin_reco.copy() var2ranges_reco.append(lvar2_binmax_reco[-1]) var2binarray_reco = array( "d", var2ranges_reco) # array of bin edges to use in histogram constructors var2ranges_gen = lvar2_binmin_gen.copy() var2ranges_gen.append(lvar2_binmax_gen[-1]) var2binarray_gen = array( "d", var2ranges_gen) # array of bin edges to use in histogram constructors # observable (z, shape,...) v_varshape_binning = datap["analysis"][typean][ "var_binningshape"] # name (reco) v_varshape_binning_gen = datap["analysis"][typean][ "var_binningshape_gen"] # name (gen) lvarshape_binmin_reco = \ datap["analysis"][typean].get("sel_binminshape_reco", None) lvarshape_binmax_reco = \ datap["analysis"][typean].get("sel_binmaxshape_reco", None) p_nbinshape_reco = len(lvarshape_binmin_reco) # number of reco bins lvarshape_binmin_gen = \ datap["analysis"][typean].get("sel_binminshape_gen", None) lvarshape_binmax_gen = \ datap["analysis"][typean].get("sel_binmaxshape_gen", None) p_nbinshape_gen = len(lvarshape_binmin_gen) # number of gen bins varshaperanges_reco = lvarshape_binmin_reco.copy() varshaperanges_reco.append(lvarshape_binmax_reco[-1]) varshapebinarray_reco = array( "d", varshaperanges_reco ) # array of bin edges to use in histogram constructors varshaperanges_gen = lvarshape_binmin_gen.copy() varshaperanges_gen.append(lvarshape_binmax_gen[-1]) varshapebinarray_gen = array( "d", varshaperanges_gen ) # array of bin edges to use in histogram constructors file_results = TFile.Open(file_in) if not file_results: logger.fatal(make_message_notfound(file_in)) ibin2 = 1 suffix = "%s_%g_%g" % (v_var2_binning, lvar2_binmin_gen[ibin2], lvar2_binmax_gen[ibin2]) # HF data nameobj = "%s_hf_data_%d_stat" % (shape, ibin2) hf_data_stat = file_results.Get(nameobj) if not hf_data_stat: logger.fatal(make_message_notfound(nameobj, file_in)) nameobj = "%s_hf_data_%d_syst" % (shape, ibin2) hf_data_syst = file_results.Get(nameobj) if not hf_data_syst: logger.fatal(make_message_notfound(nameobj, file_in)) # HF PYTHIA nameobj = "%s_hf_pythia_%d_stat" % (shape, ibin2) hf_pythia_stat = file_results.Get(nameobj) if not hf_pythia_stat: logger.fatal(make_message_notfound(nameobj, file_in)) # HF ratio nameobj = "%s_hf_ratio_%d_stat" % (shape, ibin2) hf_ratio_stat = file_results.Get(nameobj) if not hf_ratio_stat: logger.fatal(make_message_notfound(nameobj, file_in)) nameobj = "%s_hf_ratio_%d_syst" % (shape, ibin2) hf_ratio_syst = file_results.Get(nameobj) if not hf_ratio_syst: logger.fatal(make_message_notfound(nameobj, file_in)) # inclusive data nameobj = "%s_incl_data_%d_stat" % (shape, ibin2) incl_data_stat = file_results.Get(nameobj) if not incl_data_stat: logger.fatal(make_message_notfound(nameobj, file_in)) nameobj = "%s_incl_data_%d_syst" % (shape, ibin2) incl_data_syst = file_results.Get(nameobj) if not incl_data_syst: logger.fatal(make_message_notfound(nameobj, file_in)) # inclusive PYTHIA nameobj = "%s_incl_pythia_%d_stat" % (shape, ibin2) incl_pythia_stat = file_results.Get(nameobj) if not incl_pythia_stat: logger.fatal(make_message_notfound(nameobj, file_in)) nameobj = "%s_incl_pythia_%d_syst" % (shape, ibin2) incl_pythia_syst = file_results.Get(nameobj) if not incl_pythia_syst: logger.fatal(make_message_notfound(nameobj, file_in)) # inclusive ratio nameobj = "%s_incl_ratio_%d_stat" % (shape, ibin2) incl_ratio_stat = file_results.Get(nameobj) if not incl_ratio_stat: logger.fatal(make_message_notfound(nameobj, file_in)) nameobj = "%s_incl_ratio_%d_syst" % (shape, ibin2) incl_ratio_syst = file_results.Get(nameobj) if not incl_ratio_syst: logger.fatal(make_message_notfound(nameobj, file_in)) # quark PYTHIA nameobj = "%s_quark_pythia_%d_stat" % (shape, ibin2) quark_pythia_stat = file_results.Get(nameobj) if not quark_pythia_stat: logger.fatal(make_message_notfound(nameobj, file_in)) nameobj = "%s_quark_pythia_%d_syst" % (shape, ibin2) quark_pythia_syst = file_results.Get(nameobj) if not quark_pythia_syst: logger.fatal(make_message_notfound(nameobj, file_in)) # gluon PYTHIA nameobj = "%s_gluon_pythia_%d_stat" % (shape, ibin2) gluon_pythia_stat = file_results.Get(nameobj) if not gluon_pythia_stat: logger.fatal(make_message_notfound(nameobj, file_in)) nameobj = "%s_gluon_pythia_%d_syst" % (shape, ibin2) gluon_pythia_syst = file_results.Get(nameobj) if not gluon_pythia_syst: logger.fatal(make_message_notfound(nameobj, file_in)) # plot the results with systematic uncertainties and models size_can = [800, 800] size_can_double = [800, 1000] offsets_axes = [0.8, 1.1] offsets_axes_double = [0.8, 0.8] margins_can = [0.1, 0.13, 0.1, 0.03] margins_can_double = [0.1, 0.1, 0.1, 0.1] margins_can_double = [0., 0., 0., 0.] size_thg = 0.05 offset_thg = 0.85 gStyle.SetErrorX(0) # do not plot horizontal error bars of histograms fontsize = 0.035 opt_leg_g = "FP" opt_plot_g = "2" list_new = [] # list to avoid loosing objects created in loops # labels x_latex = 0.16 y_latex_top = 0.83 y_step = 0.055 title_x = v_varshape_latex title_y = "(1/#it{N}_{jet}) d#it{N}/d%s" % v_varshape_latex title_full = ";%s;%s" % (title_x, title_y) title_full_ratio = ";%s;data/MC: ratio of %s" % (title_x, title_y) title_full_ratio_double = f";{title_x};MC/data" text_alice = "#bf{ALICE}, pp, #sqrt{#it{s}} = 13 TeV" text_alice_sim = "#bf{ALICE} Simulation, pp, #sqrt{#it{s}} = 13 TeV" text_pythia = "PYTHIA 8 (Monash)" text_pythia_short = "PYTHIA 8" text_pythia_split = "#splitline{PYTHIA 8}{(Monash)}" text_jets = "charged jets, anti-#it{k}_{T}, #it{R} = 0.4" text_ptjet = "%g #leq %s < %g GeV/#it{c}, |#it{#eta}_{jet}| #leq 0.5" % ( lvar2_binmin_reco[ibin2], p_latexbin2var, lvar2_binmax_reco[ibin2]) text_pth = "%g #leq #it{p}_{T}^{%s} < %g GeV/#it{c}, |#it{y}_{%s}| #leq 0.8" % ( lpt_finbinmin[0], p_latexnhadron, min(lpt_finbinmax[-1], lvar2_binmax_reco[ibin2]), p_latexnhadron) text_ptcut = "#it{p}_{T, incl. ch. jet}^{leading track} #geq 5.33 GeV/#it{c}" text_ptcut_sim = "#it{p}_{T, incl. ch. jet}^{leading h^{#pm}} #geq 5.33 GeV/#it{c} (varied)" text_sd = "Soft Drop (#it{z}_{cut} = 0.1, #it{#beta} = 0)" title_thetag = "#it{#theta}_{g} = #it{R}_{g}/#it{R}" radius_jet = 0.4 # colour and marker indeces c_hf_data = 0 c_incl_data = 1 c_hf_mc = 2 c_incl_mc = 6 c_quark_mc = 5 c_gluon_mc = 0 # markers m_hf_data = get_marker(0) m_incl_data = get_marker(1) m_hf_mc = get_marker(0, 2) m_incl_mc = get_marker(1, 2) m_quark_mc = get_marker(2) m_gluon_mc = get_marker(3) # make the horizontal error bars smaller if shape == "nsd": for gr in [ hf_data_syst, incl_data_syst, hf_ratio_syst, incl_ratio_syst, incl_pythia_syst, quark_pythia_syst, gluon_pythia_syst ]: for i in range(gr.GetN()): gr.SetPointEXlow(i, 0.1) gr.SetPointEXhigh(i, 0.1) # data, HF and inclusive hf_data_syst_cl = hf_data_syst.Clone() leg_pos = [.72, .75, .85, .85] list_obj = [hf_data_syst, incl_data_syst, hf_data_stat, incl_data_stat] labels_obj = ["%s-tagged" % p_latexnhadron, "inclusive", "", ""] colours = [ get_colour(i, j) for i, j in zip((c_hf_data, c_incl_data, c_hf_data, c_incl_data), (2, 2, 1, 1)) ] markers = [m_hf_data, m_incl_data, m_hf_data, m_incl_data] y_margin_up = 0.46 y_margin_down = 0.05 cshape_data, list_obj_data_new = make_plot("cshape_data_" + suffix, size=size_can, \ list_obj=list_obj, labels_obj=labels_obj, opt_leg_g=opt_leg_g, opt_plot_g=opt_plot_g, offsets_xy=offsets_axes, \ colours=colours, markers=markers, leg_pos=leg_pos, margins_y=[y_margin_down, y_margin_up], margins_c=margins_can, \ title=title_full) for gr, c in zip((hf_data_syst, incl_data_syst), (c_hf_data, c_incl_data)): gr.SetMarkerColor(get_colour(c)) list_obj_data_new[0].SetTextSize(fontsize) if shape == "nsd": hf_data_syst.GetXaxis().SetNdivisions(5) # Draw a line through the points. if shape == "nsd": for h in (hf_data_stat, incl_data_stat): h_line = h.Clone(h.GetName() + "_line") h_line.SetLineStyle(2) h_line.Draw("l hist same") list_new.append(h_line) cshape_data.Update() if shape == "rg": # plot the theta_g axis gr_frame = hf_data_syst axis_rg = gr_frame.GetXaxis() rg_min = axis_rg.GetBinLowEdge(axis_rg.GetFirst()) rg_max = axis_rg.GetBinUpEdge(axis_rg.GetLast()) thetag_min = rg_min / radius_jet thetag_max = rg_max / radius_jet y_axis = cshape_data.GetUymax() axis_thetag = TGaxis(rg_min, y_axis, rg_max, y_axis, thetag_min, thetag_max, 510, "-") axis_thetag.SetTitle(title_thetag) axis_thetag.SetTitleSize(size_thg) axis_thetag.SetLabelSize(0.036) axis_thetag.SetTitleFont(42) axis_thetag.SetLabelFont(42) axis_thetag.SetLabelOffset(0) axis_thetag.SetTitleOffset(offset_thg) cshape_data.SetTickx(0) axis_thetag.Draw("same") # Draw LaTeX y_latex = y_latex_top list_latex_data = [] for text_latex in [ text_alice, text_jets, text_ptjet, text_pth, text_ptcut, text_sd ]: latex = TLatex(x_latex, y_latex, text_latex) list_latex_data.append(latex) draw_latex(latex, textsize=fontsize) y_latex -= y_step cshape_data.Update() cshape_data.SaveAs("%s/%s_data_%s.pdf" % (rootpath, shape, suffix)) # data and PYTHIA, HF leg_pos = [.72, .65, .85, .85] list_obj = [hf_data_syst_cl, hf_data_stat, hf_pythia_stat] labels_obj = ["data", "", text_pythia_split] colours = [ get_colour(i, j) for i, j in zip((c_hf_data, c_hf_data, c_hf_mc), (2, 1, 1)) ] markers = [m_hf_data, m_hf_data, m_hf_mc] y_margin_up = 0.4 y_margin_down = 0.05 cshape_data_mc_hf, list_obj_data_mc_hf_new = make_plot("cshape_data_mc_hf_" + suffix, size=size_can, \ list_obj=list_obj, labels_obj=labels_obj, opt_leg_g=opt_leg_g, opt_plot_g=opt_plot_g, offsets_xy=offsets_axes, \ colours=colours, markers=markers, leg_pos=leg_pos, margins_y=[y_margin_down, y_margin_up], margins_c=margins_can, \ title=title_full) for gr, c in zip([hf_data_syst_cl], [c_hf_data]): gr.SetMarkerColor(get_colour(c)) leg_data_mc_hf = list_obj_data_mc_hf_new[0] leg_data_mc_hf.SetHeader("%s-tagged" % p_latexnhadron) leg_data_mc_hf.SetTextSize(fontsize) if shape == "nsd": hf_data_syst_cl.GetXaxis().SetNdivisions(5) #axis_nsd = hf_data_syst_cl.GetHistogram().GetXaxis() #x1 = axis_nsd.GetBinLowEdge(1) #x2 = axis_nsd.GetBinUpEdge(axis_nsd.GetNbins()) #axis_nsd.Set(5, x1, x2) #for ibin in range(axis_nsd.GetNbins()): # axis_nsd.SetBinLabel(ibin + 1, "%d" % ibin) #axis_nsd.SetNdivisions(5) cshape_data_mc_hf.Update() if shape == "rg": # plot the theta_g axis axis_rg = hf_data_stat.GetXaxis() rg_min = axis_rg.GetBinLowEdge(axis_rg.GetFirst()) rg_max = axis_rg.GetBinUpEdge(axis_rg.GetLast()) thetag_min = rg_min / radius_jet thetag_max = rg_max / radius_jet y_axis = cshape_data_mc_hf.GetUymax() axis_thetag = TGaxis(rg_min, y_axis, rg_max, y_axis, thetag_min, thetag_max, 510, "-") axis_thetag.SetTitle(title_thetag) axis_thetag.SetTitleSize(size_thg) axis_thetag.SetLabelSize(0.036) axis_thetag.SetTitleFont(42) axis_thetag.SetLabelFont(42) axis_thetag.SetLabelOffset(0) axis_thetag.SetTitleOffset(offset_thg) cshape_data_mc_hf.SetTickx(0) axis_thetag.Draw("same") # Draw LaTeX y_latex = y_latex_top list_latex_data_mc_hf = [] for text_latex in [text_alice, text_jets, text_ptjet, text_pth, text_sd]: latex = TLatex(x_latex, y_latex, text_latex) list_latex_data_mc_hf.append(latex) draw_latex(latex, textsize=fontsize) y_latex -= y_step cshape_data_mc_hf.Update() cshape_data_mc_hf.SaveAs("%s/%s_data_mc_hf_%s.pdf" % (rootpath, shape, suffix)) # data and PYTHIA, inclusive #leg_pos = [.68, .65, .85, .85] list_obj = [ incl_data_syst, incl_pythia_syst, incl_data_stat, incl_pythia_stat ] labels_obj = ["data", text_pythia_split] colours = [ get_colour(i, j) for i, j in zip((c_incl_data, c_incl_mc, c_incl_data, c_incl_mc), (2, 2, 1, 1)) ] markers = [m_incl_data, m_incl_mc, m_incl_data, m_incl_mc] y_margin_up = 0.4 y_margin_down = 0.05 cshape_data_mc_incl, list_obj_data_mc_incl_new = make_plot("cshape_data_mc_incl_" + suffix, size=size_can, \ list_obj=list_obj, labels_obj=labels_obj, opt_leg_g=opt_leg_g, opt_plot_g=opt_plot_g, offsets_xy=offsets_axes, \ colours=colours, markers=markers, leg_pos=leg_pos, margins_y=[y_margin_down, y_margin_up], margins_c=margins_can, \ title=title_full) for gr, c in zip([incl_data_syst, incl_pythia_syst], [c_incl_data, c_incl_mc]): gr.SetMarkerColor(get_colour(c)) leg_data_mc_incl = list_obj_data_mc_incl_new[0] leg_data_mc_incl.SetHeader("inclusive") leg_data_mc_incl.SetTextSize(fontsize) if shape == "nsd": incl_data_syst.GetXaxis().SetNdivisions(5) cshape_data_mc_incl.Update() if shape == "rg": # plot the theta_g axis axis_rg = incl_data_stat.GetXaxis() rg_min = axis_rg.GetBinLowEdge(axis_rg.GetFirst()) rg_max = axis_rg.GetBinUpEdge(axis_rg.GetLast()) thetag_min = rg_min / radius_jet thetag_max = rg_max / radius_jet y_axis = cshape_data_mc_incl.GetUymax() axis_thetag = TGaxis(rg_min, y_axis, rg_max, y_axis, thetag_min, thetag_max, 510, "-") axis_thetag.SetTitle(title_thetag) axis_thetag.SetTitleSize(size_thg) axis_thetag.SetLabelSize(0.036) axis_thetag.SetTitleFont(42) axis_thetag.SetLabelFont(42) axis_thetag.SetLabelOffset(0) axis_thetag.SetTitleOffset(offset_thg) cshape_data_mc_incl.SetTickx(0) axis_thetag.Draw("same") # Draw LaTeX y_latex = y_latex_top list_latex_data_mc_incl = [] for text_latex in [text_alice, text_jets, text_ptjet, text_ptcut, text_sd]: latex = TLatex(x_latex, y_latex, text_latex) list_latex_data_mc_incl.append(latex) draw_latex(latex, textsize=fontsize) y_latex -= y_step cshape_data_mc_incl.Update() cshape_data_mc_incl.SaveAs("%s/%s_data_mc_incl_%s.pdf" % (rootpath, shape, suffix)) # Ratios data/MC, HF and inclusive line_1 = TLine(lvarshape_binmin_reco[0], 1, lvarshape_binmax_reco[-1], 1) line_1.SetLineStyle(9) line_1.SetLineColor(1) line_1.SetLineWidth(3) #leg_pos = [.72, .7, .85, .85] # with header leg_pos = [.72, .75, .85, .85] # without header list_obj = [ hf_ratio_syst, line_1, incl_ratio_syst, hf_ratio_stat, incl_ratio_stat ] labels_obj = ["%s-tagged" % p_latexnhadron, "inclusive"] colours = [ get_colour(i, j) for i, j in zip((c_hf_data, c_incl_data, c_hf_data, c_incl_data), (2, 2, 1, 1)) ] markers = [m_hf_data, m_incl_data, m_hf_data, m_incl_data] y_margin_up = 0.52 y_margin_down = 0.05 if shape == "nsd": y_margin_up = 0.22 cshape_ratio, list_obj_ratio_new = make_plot("cshape_ratio_" + suffix, size=size_can, \ list_obj=list_obj, labels_obj=labels_obj, opt_leg_g=opt_leg_g, opt_plot_g=opt_plot_g, offsets_xy=offsets_axes, \ colours=colours, markers=markers, leg_pos=leg_pos, margins_y=[y_margin_down, y_margin_up], margins_c=margins_can, \ title=title_full_ratio) cshape_ratio.Update() for gr, c in zip((hf_ratio_syst, incl_ratio_syst), (c_hf_data, c_incl_data)): gr.SetMarkerColor(get_colour(c)) leg_ratio = list_obj_ratio_new[0] leg_ratio.SetTextSize(fontsize) #leg_ratio.SetHeader("data/MC") if shape == "nsd": hf_ratio_syst.GetXaxis().SetNdivisions(5) cshape_ratio.Update() if shape == "rg": # plot the theta_g axis gr_frame = hf_ratio_syst axis_rg = gr_frame.GetXaxis() rg_min = axis_rg.GetBinLowEdge(axis_rg.GetFirst()) rg_max = axis_rg.GetBinUpEdge(axis_rg.GetLast()) thetag_min = rg_min / radius_jet thetag_max = rg_max / radius_jet y_axis = cshape_ratio.GetUymax() axis_thetag = TGaxis(rg_min, y_axis, rg_max, y_axis, thetag_min, thetag_max, 510, "-") axis_thetag.SetTitle(title_thetag) axis_thetag.SetTitleSize(size_thg) axis_thetag.SetLabelSize(0.036) axis_thetag.SetTitleFont(42) axis_thetag.SetLabelFont(42) axis_thetag.SetLabelOffset(0) axis_thetag.SetTitleOffset(offset_thg) cshape_ratio.SetTickx(0) axis_thetag.Draw("same") # Draw LaTeX y_latex = y_latex_top list_latex_ratio = [] for text_latex in [ text_alice, text_jets, text_ptjet, text_pth, text_ptcut, text_sd, text_pythia ]: latex = TLatex(x_latex, y_latex, text_latex) list_latex_ratio.append(latex) draw_latex(latex, textsize=fontsize) y_latex -= y_step cshape_ratio.Update() cshape_ratio.SaveAs("%s/%s_ratio_%s.pdf" % (rootpath, shape, suffix)) # PYTHIA, HF, inclusive, quark, gluon incl_pythia_syst_cl = incl_pythia_syst.Clone() y_min_h, y_max_h = get_y_window_his([ hf_pythia_stat, incl_pythia_stat, quark_pythia_stat, gluon_pythia_stat ]) y_min_g, y_max_g = get_y_window_gr( [incl_pythia_syst, quark_pythia_syst, gluon_pythia_syst]) y_min = min(y_min_h, y_min_g) y_max = max(y_max_h, y_max_g) y_margin_up = 0.46 y_margin_down = 0.05 y_min_plot, y_max_plot = get_plot_range(y_min, y_max, y_margin_down, y_margin_up) #leg_pos = [.6, .65, .75, .85] leg_pos = [.72, .55, .85, .85] list_obj = [ incl_pythia_syst, quark_pythia_syst, gluon_pythia_syst, hf_pythia_stat, incl_pythia_stat, quark_pythia_stat, gluon_pythia_stat ] labels_obj = ["inclusive", "quark", "gluon", "%s-tagged" % p_latexnhadron] colours = [ get_colour(i, j) for i, j in zip((c_incl_mc, c_quark_mc, c_gluon_mc, c_hf_mc, c_incl_mc, c_quark_mc, c_gluon_mc), (2, 2, 2, 1, 1, 1, 1)) ] markers = [ m_incl_mc, m_quark_mc, m_gluon_mc, m_hf_mc, m_incl_mc, m_quark_mc, m_gluon_mc ] y_margin_up = 0.46 y_margin_down = 0.05 cshape_mc, list_obj_mc_new = make_plot("cshape_mc_" + suffix, size=size_can, \ list_obj=list_obj, labels_obj=labels_obj, opt_leg_g=opt_leg_g, opt_plot_g=opt_plot_g, offsets_xy=offsets_axes, \ colours=colours, markers=markers, leg_pos=leg_pos, range_y=[y_min_plot, y_max_plot], margins_c=margins_can, \ title=title_full) cshape_mc.Update() for gr, c in zip((incl_pythia_syst, quark_pythia_syst, gluon_pythia_syst), (c_incl_mc, c_quark_mc, c_gluon_mc)): gr.SetMarkerColor(get_colour(c)) leg_mc = list_obj_mc_new[0] leg_mc.SetTextSize(fontsize) leg_mc.SetHeader(text_pythia_split) if shape == "nsd": incl_pythia_syst.GetXaxis().SetNdivisions(5) cshape_mc.Update() if shape == "rg": # plot the theta_g axis axis_rg = hf_pythia_stat.GetXaxis() rg_min = axis_rg.GetBinLowEdge(axis_rg.GetFirst()) rg_max = axis_rg.GetBinUpEdge(axis_rg.GetLast()) thetag_min = rg_min / radius_jet thetag_max = rg_max / radius_jet y_axis = cshape_mc.GetUymax() axis_thetag = TGaxis(rg_min, y_axis, rg_max, y_axis, thetag_min, thetag_max, 510, "-") axis_thetag.SetTitle(title_thetag) axis_thetag.SetTitleSize(size_thg) axis_thetag.SetLabelSize(0.036) axis_thetag.SetTitleFont(42) axis_thetag.SetLabelFont(42) axis_thetag.SetLabelOffset(0) axis_thetag.SetTitleOffset(offset_thg) cshape_mc.SetTickx(0) axis_thetag.Draw("same") # Draw LaTeX y_latex = y_latex_top list_latex_mc = [] for text_latex in [ text_alice_sim, text_jets, text_ptjet, text_pth, text_ptcut_sim, text_sd ]: latex = TLatex(x_latex, y_latex, text_latex) list_latex_mc.append(latex) draw_latex(latex, textsize=fontsize) y_latex -= y_step cshape_mc.Update() cshape_mc.SaveAs("%s/%s_mc_%s.pdf" % (rootpath, shape, suffix)) # PYTHIA, HF, quark, gluon #leg_pos = [.6, .65, .75, .85] leg_pos = [.72, .61, .85, .85] list_obj = [ quark_pythia_syst, gluon_pythia_syst, hf_pythia_stat, quark_pythia_stat, gluon_pythia_stat ] labels_obj = ["quark", "gluon", "%s-tagged" % p_latexnhadron] colours = [ get_colour(i, j) for i, j in zip((c_quark_mc, c_gluon_mc, c_hf_mc, c_quark_mc, c_gluon_mc), (2, 2, 1, 1, 1)) ] markers = [m_quark_mc, m_gluon_mc, m_hf_mc, m_quark_mc, m_gluon_mc] y_margin_up = 0.46 y_margin_down = 0.05 cshape_mc, list_obj_mc_new = make_plot("cshape_mc_qgd_" + suffix, size=size_can, \ list_obj=list_obj, labels_obj=labels_obj, opt_leg_g=opt_leg_g, opt_plot_g=opt_plot_g, offsets_xy=offsets_axes, \ colours=colours, markers=markers, leg_pos=leg_pos, range_y=[y_min_plot, y_max_plot], margins_c=margins_can, \ title=title_full) cshape_mc.Update() for gr, c in zip((quark_pythia_syst, gluon_pythia_syst), (c_quark_mc, c_gluon_mc)): gr.SetMarkerColor(get_colour(c)) leg_mc = list_obj_mc_new[0] leg_mc.SetTextSize(fontsize) leg_mc.SetHeader(text_pythia_split) if shape == "nsd": quark_pythia_syst.GetXaxis().SetNdivisions(5) cshape_mc.Update() if shape == "rg": # plot the theta_g axis axis_rg = hf_pythia_stat.GetXaxis() rg_min = axis_rg.GetBinLowEdge(axis_rg.GetFirst()) rg_max = axis_rg.GetBinUpEdge(axis_rg.GetLast()) thetag_min = rg_min / radius_jet thetag_max = rg_max / radius_jet y_axis = cshape_mc.GetUymax() axis_thetag = TGaxis(rg_min, y_axis, rg_max, y_axis, thetag_min, thetag_max, 510, "-") axis_thetag.SetTitle(title_thetag) axis_thetag.SetTitleSize(size_thg) axis_thetag.SetLabelSize(0.036) axis_thetag.SetTitleFont(42) axis_thetag.SetLabelFont(42) axis_thetag.SetLabelOffset(0) axis_thetag.SetTitleOffset(offset_thg) cshape_mc.SetTickx(0) axis_thetag.Draw("same") # Draw LaTeX y_latex = y_latex_top list_latex_mc = [] for text_latex in [ text_alice_sim, text_jets, text_ptjet, text_pth, text_ptcut_sim, text_sd ]: latex = TLatex(x_latex, y_latex, text_latex) list_latex_mc.append(latex) draw_latex(latex, textsize=fontsize) y_latex -= y_step cshape_mc.Update() cshape_mc.SaveAs("%s/%s_mc_qgd_%s.pdf" % (rootpath, shape, suffix)) # PYTHIA, HF, inclusive #leg_pos = [.6, .65, .75, .85] leg_pos = [.72, .67, .85, .85] list_obj = [incl_pythia_syst_cl, incl_pythia_stat, hf_pythia_stat] labels_obj = ["inclusive", "", "%s-tagged" % p_latexnhadron] colours = [ get_colour(i, j) for i, j in zip((c_incl_mc, c_incl_mc, c_hf_mc), (2, 1, 1)) ] markers = [m_incl_mc, m_incl_mc, m_hf_mc] y_margin_up = 0.46 y_margin_down = 0.05 cshape_mc, list_obj_mc_new = make_plot("cshape_mc_id_" + suffix, size=size_can, \ list_obj=list_obj, labels_obj=labels_obj, opt_leg_g=opt_leg_g, opt_plot_g=opt_plot_g, offsets_xy=offsets_axes, \ colours=colours, markers=markers, leg_pos=leg_pos, range_y=[y_min_plot, y_max_plot], margins_c=margins_can, \ title=title_full) # Draw a line through the points. if shape == "nsd": for h in (incl_pythia_stat, hf_pythia_stat): h_line = h.Clone(h.GetName() + "_line") h_line.SetLineStyle(2) h_line.Draw("l hist same") list_new.append(h_line) cshape_mc.Update() incl_pythia_syst_cl.SetMarkerColor(get_colour(c_incl_mc)) leg_mc = list_obj_mc_new[0] leg_mc.SetTextSize(fontsize) leg_mc.SetHeader(text_pythia_split) if shape == "nsd": incl_pythia_syst_cl.GetXaxis().SetNdivisions(5) cshape_mc.Update() if shape == "rg": # plot the theta_g axis axis_rg = hf_pythia_stat.GetXaxis() rg_min = axis_rg.GetBinLowEdge(axis_rg.GetFirst()) rg_max = axis_rg.GetBinUpEdge(axis_rg.GetLast()) thetag_min = rg_min / radius_jet thetag_max = rg_max / radius_jet y_axis = cshape_mc.GetUymax() axis_thetag = TGaxis(rg_min, y_axis, rg_max, y_axis, thetag_min, thetag_max, 510, "-") axis_thetag.SetTitle(title_thetag) axis_thetag.SetTitleSize(size_thg) axis_thetag.SetLabelSize(0.036) axis_thetag.SetTitleFont(42) axis_thetag.SetLabelFont(42) axis_thetag.SetLabelOffset(0) axis_thetag.SetTitleOffset(offset_thg) cshape_mc.SetTickx(0) axis_thetag.Draw("same") # Draw LaTeX y_latex = y_latex_top list_latex_mc = [] for text_latex in [ text_alice_sim, text_jets, text_ptjet, text_pth, text_ptcut_sim, text_sd ]: latex = TLatex(x_latex, y_latex, text_latex) list_latex_mc.append(latex) draw_latex(latex, textsize=fontsize) y_latex -= y_step cshape_mc.Update() cshape_mc.SaveAs("%s/%s_mc_id_%s.pdf" % (rootpath, shape, suffix)) # data inclusive vs PYTHIA, quark, gluon #leg_pos = [.6, .65, .75, .85] #leg_pos = [.72, .55, .85, .85] leg_pos = [.6, .7, .85, .85] list_obj = [ incl_data_syst, quark_pythia_syst, gluon_pythia_syst, incl_data_stat, quark_pythia_stat, gluon_pythia_stat ] labels_obj = ["inclusive (data)", "quark (PYTHIA 8)", "gluon (PYTHIA 8)"] colours = [ get_colour(i, j) for i, j in zip((c_incl_data, c_quark_mc, c_gluon_mc, c_incl_data, c_quark_mc, c_gluon_mc), (2, 2, 2, 1, 1, 1)) ] markers = [ m_incl_data, m_quark_mc, m_gluon_mc, m_incl_data, m_quark_mc, m_gluon_mc ] y_margin_up = 0.3 y_margin_down = 0.05 cshape_mc, list_obj_mc_new = make_plot("cshape_mc_data_iqg" + suffix, size=size_can, \ list_obj=list_obj, labels_obj=labels_obj, opt_leg_g=opt_leg_g, opt_plot_g=opt_plot_g, offsets_xy=offsets_axes, \ colours=colours, markers=markers, leg_pos=leg_pos, margins_y=[y_margin_down, y_margin_up], margins_c=margins_can, \ title=title_full) for gr, c in zip((incl_data_syst, quark_pythia_syst, gluon_pythia_syst), (c_incl_data, c_quark_mc, c_gluon_mc)): gr.SetMarkerColor(get_colour(c)) leg_mc = list_obj_mc_new[0] leg_mc.SetTextSize(fontsize) cshape_mc.Update() cshape_mc.SaveAs("%s/%s_data_i_mc_qg_%s.pdf" % (rootpath, shape, suffix)) # data + MC/data, HF and inclusive # print relative syst. unc. for name, gr in zip(("HF", "inclusive"), (hf_data_syst, incl_data_syst)): print(f"Rel. syst. unc. for {name} {shape}") e_plus_min = float("inf") e_minus_min = float("inf") e_plus_max = 0. e_minus_max = 0. for i in range(gr.GetN()): y = gr.GetPointY(i) e_plus = 100 * gr.GetErrorYhigh(i) e_minus = 100 * gr.GetErrorYlow(i) e_plus /= y e_minus /= y e_plus_min = min(e_plus_min, e_plus) e_minus_min = min(e_minus_min, e_minus) e_plus_max = max(e_plus_max, e_plus) e_minus_max = max(e_minus_max, e_minus) # print(f"Point {i}, up {e_plus:.2g} %, down {e_minus:.2g} %") # print(f"Minima: up {e_plus_min:.2g} %, down {e_minus_min:.2g} %") # print(f"Maxima: up {e_plus_max:.2g} %, down {e_minus_max:.2g} %") print( f"Absolutes: min: {min(e_plus_min, e_minus_min):.2g} %, max {max(e_plus_max, e_minus_max):.2g} %" ) # explicit y ranges [zg, rg, nsd] list_range_y = [[0, 9], [0, 6], [0, 0.7]] # data list_range_y_rat = [[0, 2], [0, 2], [0, 2]] # mc/data ratios i_shape = 0 if shape == "zg" else 1 if shape == "rg" else 2 print(f"Index {i_shape}") # data leg_pos = [.7, .75, .82, .85] list_obj = [hf_data_syst, incl_data_syst, hf_data_stat, incl_data_stat] labels_obj = ["%s-tagged" % p_latexnhadron, "inclusive", "", ""] colours = [ get_colour(i, j) for i, j in zip((c_hf_data, c_incl_data, c_hf_data, c_incl_data), (2, 2, 1, 1)) ] markers = [m_hf_data, m_incl_data, m_hf_data, m_incl_data] y_margin_up = 0.42 y_margin_down = 0.05 cshape_datamc_all = TCanvas("cshape_datamc_" + suffix, "cshape_datamc_" + suffix) cshape_datamc_all.Divide(1, 2) pad1 = cshape_datamc_all.cd(1) pad2 = cshape_datamc_all.cd(2) pad1.SetPad(0., 0.3, 1, 1) pad2.SetPad(0., 0., 1, 0.3) pad1.SetBottomMargin(0.) pad2.SetBottomMargin(0.25) pad1.SetTopMargin(0.1) pad2.SetTopMargin(0.) pad1.SetLeftMargin(0.12) pad2.SetLeftMargin(0.12) pad1.SetTicks(1, 1) pad2.SetTicks(1, 1) cshape_datamc_all, list_obj_data_new = make_plot("cshape_datamc_" + suffix, size=size_can_double, \ can=cshape_datamc_all, pad=1, \ list_obj=list_obj, labels_obj=labels_obj, opt_leg_g=opt_leg_g, opt_plot_g=opt_plot_g, offsets_xy=[0.8, 1.1], \ colours=colours, markers=markers, leg_pos=leg_pos, margins_c=margins_can_double, \ # margins_y=[y_margin_down, y_margin_up], \ range_y=list_range_y[i_shape], \ title=title_full) for gr, c in zip((hf_data_syst, incl_data_syst), (c_hf_data, c_incl_data)): gr.SetMarkerColor(get_colour(c)) list_obj_data_new[0].SetTextSize(fontsize) hf_data_syst.GetYaxis().SetLabelSize(0.1 * 3 / 7) #hf_data_syst.GetYaxis().SetTitleSize(0.1) if shape == "nsd": hf_data_syst.GetXaxis().SetNdivisions(5) # Draw a line through the points. if shape == "nsd": for h in (hf_data_stat, incl_data_stat): h_line = h.Clone(h.GetName() + "_line") h_line.SetLineStyle(2) h_line.Draw("l hist same") list_new.append(h_line) cshape_datamc_all.Update() if shape == "rg": # plot the theta_g axis gr_frame = hf_data_syst axis_rg = gr_frame.GetXaxis() rg_min = axis_rg.GetBinLowEdge(axis_rg.GetFirst()) rg_max = axis_rg.GetBinUpEdge(axis_rg.GetLast()) thetag_min = rg_min / radius_jet thetag_max = rg_max / radius_jet y_axis = pad1.GetUymax() axis_thetag = TGaxis(rg_min, y_axis, rg_max, y_axis, thetag_min, thetag_max, 510, "-") axis_thetag.SetTitle(title_thetag) axis_thetag.SetTitleSize(size_thg) axis_thetag.SetLabelSize(0.036) axis_thetag.SetTitleFont(42) axis_thetag.SetLabelFont(42) axis_thetag.SetLabelOffset(0) axis_thetag.SetTitleOffset(offset_thg) cshape_datamc_all.cd(1).SetTickx(0) axis_thetag.Draw("same") # Draw LaTeX y_latex = y_latex_top list_latex_data = [] for text_latex in [ text_alice, text_jets, text_ptjet, text_pth, text_ptcut, text_sd ]: latex = TLatex(x_latex, y_latex, text_latex) list_latex_data.append(latex) draw_latex(latex, textsize=fontsize) y_latex -= y_step cshape_datamc_all.Update() # MC/data leg_pos = [.15, .85, .85, .95] hf_ratio_pythia_stat = hf_pythia_stat.Clone( f"{hf_pythia_stat.GetName()}_rat") hf_ratio_pythia_stat.Divide(hf_data_stat) # hf_ratio_pythia_stat = hf_data_stat.Clone(f"{hf_data_stat.GetName()}_rat") # version data/MC # hf_ratio_pythia_stat.Divide(hf_pythia_stat) # version data/MC # create a graph with PYTHIA points and with zero syst. unc. hf_pythia_stat_zero = hf_pythia_stat.Clone( f"{hf_pythia_stat.GetName()}_zero") for i in range(hf_pythia_stat_zero.GetNbinsX()): hf_pythia_stat_zero.SetBinError(i + 1, 0) gStyle.SetErrorX( 0.5 ) # we have to restore the histogram bin width to propagate it to graph hf_pythia_syst = TGraphAsymmErrors( hf_pythia_stat_zero) # convert histogram into a graph gStyle.SetErrorX(0) # set back the intended settings hf_ratio_pythia_syst = divide_graphs(hf_pythia_syst, hf_data_syst) # hf_ratio_pythia_syst = divide_graphs(hf_data_syst, hf_pythia_syst) # version data/MC incl_ratio_pythia_stat = incl_pythia_stat.Clone( f"{incl_pythia_stat.GetName()}_rat") incl_ratio_pythia_stat.Divide(incl_data_stat) incl_ratio_pythia_syst = divide_graphs(incl_pythia_syst, incl_data_syst) # incl_ratio_pythia_stat = incl_data_stat.Clone(f"{incl_data_stat.GetName()}_rat") # version data/MC # incl_ratio_pythia_stat.Divide(incl_pythia_stat) # version data/MC # incl_ratio_pythia_syst = divide_graphs(incl_data_syst, incl_pythia_syst) # version data/MC list_obj = [ hf_ratio_pythia_syst, incl_ratio_pythia_syst, hf_ratio_pythia_stat, incl_ratio_pythia_stat, line_1 ] labels_obj = [ f"{p_latexnhadron}-tagged {text_pythia_short}", f"inclusive {text_pythia_short}", "", "" ] colours = [ get_colour(i, j) for i, j in zip((c_hf_mc, c_incl_mc, c_hf_mc, c_incl_mc), (2, 2, 1, 1)) ] markers = [m_hf_mc, m_incl_mc, m_hf_mc, m_incl_mc] y_margin_up = 0.2 y_margin_down = 0.05 cshape_datamc_all, list_obj_data_mc_hf_new = make_plot("cshape_data_mc_hf_" + suffix, size=size_can_double, \ can=cshape_datamc_all, pad=2, \ list_obj=list_obj, labels_obj=labels_obj, opt_leg_g=opt_leg_g, opt_plot_g=opt_plot_g, offsets_xy=[1, 1.3 * 3/7], \ colours=colours, markers=markers, leg_pos=leg_pos, margins_c=margins_can_double, \ # margins_y=[y_margin_down, y_margin_up], \ range_y=list_range_y_rat[i_shape], \ title=title_full_ratio_double) hf_ratio_pythia_syst.GetXaxis().SetLabelSize(0.1) hf_ratio_pythia_syst.GetXaxis().SetTitleSize(0.1) hf_ratio_pythia_syst.GetYaxis().SetLabelSize(0.1) hf_ratio_pythia_syst.GetYaxis().SetTitleSize(0.1) for gr, c in zip([hf_ratio_pythia_syst, incl_ratio_pythia_syst], [c_hf_mc, c_incl_mc]): gr.SetMarkerColor(get_colour(c)) leg_data_mc_hf = list_obj_data_mc_hf_new[0] #leg_data_mc_hf.SetHeader("%s-tagged" % p_latexnhadron) leg_data_mc_hf.SetTextSize(fontsize * 7 / 3) leg_data_mc_hf.SetNColumns(2) if shape == "nsd": hf_ratio_pythia_syst.GetXaxis().SetNdivisions(5) cshape_datamc_all.Update() # Draw LaTeX #y_latex = y_latex_top #list_latex_data_mc_hf = [] #for text_latex in [text_alice, text_jets, text_ptjet, text_pth, text_sd]: # latex = TLatex(x_latex, y_latex, text_latex) # list_latex_data_mc_hf.append(latex) # draw_latex(latex, textsize=fontsize) # y_latex -= y_step #cshape_datamc_all.Update() pad1.RedrawAxis() pad2.RedrawAxis() cshape_datamc_all.SaveAs("%s/%s_datamc_all_%s.pdf" % (rootpath, shape, suffix))
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., 0.7) 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, 0.7, 0, 0.7 * rightmax / leftmax, 510, "+L") axis.SetLineColor(2) axis.SetLabelColor(2) axis.Draw() c_allmases.cd(4) 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., 0.09) graph_deltar_allmases.Draw("AP") graph_ntr_allmases2.Draw("*") axis2 = TGaxis(10.8, 0., 10.8, 0.09, 0, 0.09 * rightmax2 / leftmax2, 510, "+L") axis2.SetLineColor(2) axis2.SetLabelColor(2) axis2.Draw() c_allmases.Modify()
def ratio_plot(h1, h2, legend, name='c', dim=(800, 600), mode='', l_range=(0, 0), l_y_title=''): if not isinstance(dim, collections.abc.Sequence): raise TypeError("The variable 'dim' has a wrong type") elif len(dim) != 2: raise ValueError("Wrong length given for list 'dim'") if not isinstance(l_range, collections.abc.Sequence): raise TypeError("The variable 'l_range' has a wrong type") elif len(l_range) != 2: raise ValueError("Wrong length given for list 'l_range'") if name == 'c': name = name + '_' + random_string() c = TCanvas(name, '', dim[0], dim[1]) pad1 = TPad('pad1', 'pad1', 0, 0.3, 1, 1.0) pad1.SetBottomMargin(0) # Upper and lower plot are joined pad1.Draw() # Draw the upper pad: pad1 pad1.cd() # pad1 becomes the current pad h1.SetStats(0) h1.Draw() h2opt = h2.GetOption() + 'SAME' h2.Draw(h2opt) legend.Draw() axis = TGaxis(-5, 20, -5, 220, 20, 220, 510, '') axis.SetLabelFont(43) # Absolute font size in pixel (precision 3) axis.SetLabelSize(20) axis.SetTitleFont(43) axis.SetTitleSize(20) axis.SetTitleOffset(1.3) axis.Draw() c.Update() # lower plot will be in pad c.cd() # Go back to the main canvas before defining pad2 pad2 = TPad('pad2', 'pad2', 0, 0.01, 1., 0.30) pad2.SetTopMargin(0.0) pad2.SetBottomMargin(0.28) pad2.SetGridy(1) pad2.Draw() pad2.cd() # pad2 becomes the current pad # Define the ratio plot h3 = h1.Clone('h3') h3.SetLineColor(kPurpleC) h3.SetMarkerColor(kPurpleC) h3.SetMarkerSize(0.5) h3.Sumw2() h3.SetStats(0) # No statistics on lower plot if (mode == 'ratio'): h3.Divide(h2) if (mode == 'diff'): h3.Add(h2, -1.) h3.SetMarkerStyle(21) h3.Draw('ep') # Draw the ratio plot # Remove the ratio title h3.SetTitle('') # Y axis ratio plot settings l_title = '' if l_y_title == '': l_title = mode + ' ' else: l_title = l_y_title h3.GetYaxis().SetTitle(l_title) h3.GetYaxis().SetNdivisions(505) h3.GetYaxis().SetTitleSize(20) h3.GetYaxis().SetTitleFont(43) h3.GetYaxis().SetTitleOffset(1.2) h3.GetYaxis().SetLabelFont(43) # Absolute font size in pixel(precision 3) h3.GetYaxis().SetLabelSize(16) if l_range != (0, 0): h3.GetYaxis().SetRangeUser(l_range[0], l_range[1]) # X axis ratio plot settings h3.GetXaxis().SetTitleSize(20) h3.GetXaxis().SetTitleFont(43) h3.GetXaxis().SetTitleOffset(3.5) h3.GetXaxis().SetLabelFont(43) # Absolute font size in pixel(precision 3) h3.GetXaxis().SetLabelSize(18) c.Write() c.Close()
corrected_nue.SetLineWidth(4) simple_nue.SetLineWidth(4) simple_nue.GetXaxis().SetRangeUser(0, 4) corrected_nue.GetXaxis().SetRangeUser(0, 4) simple_nue.Draw("hist") corrected_nue.Draw("hist same") # Do not draw the Y axis label on the upper plot and redraw a small # axis instead, in order to avoid the first label (0) to be clipped. corrected_nue.GetYaxis().SetLabelSize(0.) axis = TGaxis(-5, 20, -5, 220, 20, 220, 510, "") axis.SetLabelFont(43) # Absolute font size in pixel (precision 3) axis.SetLabelSize(15) axis.Draw() leg_nue = TLegend(0.75, 0.95, 0.75, 0.95) leg_nue.AddEntry(simple_nue, "nue std. Flux", "l") leg_nue.AddEntry(corrected_nue, "nue cor. Flux", "l") leg_nue.Draw() c6.cd() pad2 = TPad("pad2", "pad2", 0, 0.05, 1, 0.3) pad2.SetTopMargin(0.1) pad2.SetBottomMargin(0.1) pad2.SetGridx() # vertical grid pad2.Draw() pad2.cd() # pad2 becomes the current pad ratio_nue.SetLineColor(12)