canvProfile = prepare_single_canvas( 'upstreamEnergy_e' + str(energy) + 'GeV_eta' + str(eta), 'Upstream energy vs energy in first layer for #eta = ' + str(eta)) draw_1histogram(hUpstremCellProfile, 'E_{firstLayer} ' + energyUnit, 'upstream energy ' + energyUnit) hUpstremCellProfile.Fit(fitProfile, "SR") for ibin in reversed( range(0, hUpstremCellProfile.GetXaxis().GetNbins())): if hUpstremCellProfile.GetBinContent(ibin) > 0: lastNonEmpty = ibin break hUpstremCellProfile.GetXaxis().SetRange(0, lastNonEmpty + 3) legendProfile = draw_text([str(energy) + ' GeV e^{-}, B = 4T'], [0.67, 0.18, 0.85, 0.28], 9, 0) legendProfile.SetTextSize(0.05) legendProfile.SetTextFont(42) canvProfile.Update() # save canvases filled for each energy and eta if calo_init.output(ifile): canvProfile.SaveAs( calo_init.output(ifile) + "_previewProfile_eta" + str(eta) + "_e" + str(energy) + "GeV.png") else: canvProfile.SaveAs("upstremCorrection_previewProfile_eta" + str(eta) + "_" + str(layer * width) + "cm.png") if calo_init.args.previewPhi: canvPhi = prepare_single_canvas( 'phi_e' + str(energy) + 'GeV__eta' + str(eta),
cRes.cd() # Fit energy resolution fRes = TF1("res", "sqrt([0]*[0] + pow([1]/sqrt(x),2))",5,600) fRes.SetParName(0,"const") fRes.SetParName(1,"sqrt") fRes.SetLineColor(colour) fitResult = gRes.Fit(fRes, 'S') # Draw graph and all labels gRes.Draw("ape") if calo_init.args.axisMax: gRes.GetYaxis().SetRangeUser(0, calo_init.args.axisMax) formula = "#frac{#sigma_{E}}{E} = " + str(round(fitResult.Get().Parameter(0)*100,2))+"% #oplus #frac{"+str(round(fitResult.Get().Parameter(1)*100,2))+"%}{#sqrt{E}}" if not calo_init.args.noLinearity: draw_text([formula], [0.55,0.8,0.95,0.95], colour, 0).SetTextSize(0.05) else: draw_text([formula], [0.55,0.7,0.95,0.85], colour, 0).SetTextSize(0.05) if calo_init.args.technical: constString = "const: "+str(round(fitResult.Get().Parameter(0),4))+" #pm "+str(round(fitResult.Get().Error(0),4)) samplingString = "sampl: "+str(round(fitResult.Get().Parameter(1),4))+" #pm "+str(round(fitResult.Get().Error(1),4)) draw_text([constString, samplingString], [0.55,0.68,0.88,0.76], colour+1, 0).SetTextSize(0.05) draw_text(["energy resolution"], [0.2,0.88, 0.45,0.98], 1, 0).SetTextSize(0.05) if calo_init.args.noLinearity and calo_init.args.specialLabel: draw_text([calo_init.args.specialLabel], [0.67,0.88, 0.95,0.98], kGray+3, 0).SetTextSize(0.05) cRes.Update() if not calo_init.args.noLinearity: padLin.cd() gLin.Draw("ape") draw_text(["linearity"], [0.2,0.78, 0.4,0.88], 1, 0).SetTextSize(0.05*factor) if calo_init.args.specialLabel:
# add second axis canv.SetRightMargin(0.1) all_graphs[0].GetXaxis().SetRangeUser(0, 68) all_graphs[0].GetXaxis().SetLabelOffset(0.02) gPad.RangeAxis(0, gPad.GetUymin(), 68, gPad.GetUxmax()) axis = TGaxis(gPad.GetUxmin(), gPad.GetUymin(), gPad.GetUxmax(), gPad.GetUymin(), gPad.GetUxmin() * calo_init.args.X0density, gPad.GetUxmax() * calo_init.args.X0density, 506, "-") axis.SetLabelSize(0.05) axis.SetTitleSize(0.07) axis.SetTitleOffset(0.9) axis.SetLabelOffset(0.02) axis.Draw() axis.SetLabelFont(42) unit1 = draw_text(['(cm)'], [0.91, 0.09, 1, 0.14], 1, 0) unit1.SetTextSize(0.05) unit1.SetTextFont(42) unit2 = draw_text(['(X_{0})'], [0.91, 0.16, 1, 0.21], 1, 0) unit2.SetTextSize(0.05) unit2.SetTextFont(42) canv.Update() # Draw all labels if calo_init.args.specialLabel: draw_text([calo_init.args.specialLabel], [0.57, 0.88, 0.85, 0.98], kGray + 3, 0).SetTextSize(0.05) canv.Update() # Save canvas and root file with graph, const term and sampling term if calo_init.output(0):
if calo_init.args.axisMax: all_graphs[0].SetMaximum(calo_init.args.axisMax) if calo_init.args.axisMin: all_graphs[0].SetMinimum(calo_init.args.axisMin) canv.Update() lines = [] for iLine, line in enumerate(avgSF): lines.append(TLine(0, avgSF[iLine], 65, avgSF[iLine])) lines[iLine].SetLineColor(colour[iLine]) all_graphs[iLine].SetMarkerColor(colour[iLine]) all_graphs[iLine].SetLineColor(colour[iLine]) lines[iLine].Draw('same') if len(graphTitles) > 1: draw_text(graphTitles, [0.18,0.9 - 0.07 * len(graphTitles),0.4,0.95], 0.4, 0).SetTextSize(0.06) # Draw all labels if calo_init.args.specialLabel: draw_text([calo_init.args.specialLabel], [0.57,0.88, 0.85,0.98], kGray+3, 0).SetTextSize(0.05) canv.Update() # Save canvas and root file with graph, const term and sampling term if calo_init.output(0): canv.SaveAs(calo_init.output(0)+".eps") canv.SaveAs(calo_init.output(0)+".png") plots = TFile(calo_init.output(0)+".root","RECREATE") if calo_init.args.preview: cPreview.SaveAs("preview_"+calo_init.output(0)+".png") else: canv.SaveAs("sampling_fraction_plots.eps")
dSigma = result.Get().Error(2) resolution_list.append("#color["+str(colours[ifile])+"]{"+legend[ifile]+str(round(sigma / mean * 100 ,2))+" %}") mean_list.append("#color["+str(colours[ifile])+"]{"+legend[ifile]+str(round((mean-energy)/energy*100 ,1))+" %}") prepare_histogram(hEn, ';E_{beam} '+energyUnit+';fraction of events', colours[ifile]) hEn.GetXaxis().SetRangeUser(0.9 * energy, 1.1* energy) if ifile == 0: hEn.DrawCopy() else: hEn.DrawCopy("sameep") fit.Draw("same") canv.Update() if not calo_init.args.noLinearity: draw_text(["energy resolution", "#color[1]{#sigma_{E_{rec}}/#LTE_{rec}#GT}"] + resolution_list, [0.17,0.8-0.05*len(resolution_list),0.42,0.88], 1, 1) draw_text(["linearity", "#color[1]{(#LTE_{rec}#GT-E_{beam})/E_{beam}}"] + mean_list, [0.7,0.8-0.05*len(resolution_list),0.95,0.88], 1, 1) else: draw_text(["energy resolution", "#color[1]{#sigma_{E_{rec}}/#LTE_{rec}#GT}"] + resolution_list, [0.6,0.7-0.07*len(resolution_list),0.95,0.78], 1, 0) if calo_init.args.specialLabel: draw_text([calo_init.args.specialLabel], [0.57,0.88, 0.85,0.98], kGray+3, 0).SetTextSize(0.05) canv.Update() if calo_init.output(ifile): canv.Print("energyDistribution_"+calo_init.output(0)+".png") else:
all_graphs[0].GetXaxis().SetRangeUser(0,68) all_graphs[0].GetXaxis().SetLabelOffset(0.02) gPad.RangeAxis(0,gPad.GetUymin(),68,gPad.GetUxmax()) axis = TGaxis(gPad.GetUxmin(), gPad.GetUymin(), gPad.GetUxmax(), gPad.GetUymin(), gPad.GetUxmin() * calo_init.args.X0density, gPad.GetUxmax() * calo_init.args.X0density,506,"-") axis.SetLabelSize(0.05) axis.SetTitleSize(0.07) axis.SetTitleOffset(0.9) axis.SetLabelOffset(0.02) axis.Draw() axis.SetLabelFont(42) unit1 = draw_text(['(cm)'],[0.91,0.09,1,0.14] , 1, 0) unit1.SetTextSize(0.05) unit1.SetTextFont(42) unit2 = draw_text(['(X_{0})'],[0.91,0.16,1,0.21] , 1, 0) unit2.SetTextSize(0.05) unit2.SetTextFont(42) canv.Update() # Draw all labels if calo_init.args.specialLabel: draw_text([calo_init.args.specialLabel], [0.57,0.88, 0.85,0.98], kGray+3, 0).SetTextSize(0.05) canv.Update() # Save canvas and root file with graph, const term and sampling term if calo_init.output(0):
# Set proper names for the plot legend if len(calo_init.args.legend) > 1: graphTitles = calo_init.args.legend elif calo_init.args.legend: graphTitles, check = calo_init.substitute(calo_init.args.legend[0]) else: graphTitles=[] for ileg, legend in enumerate(graphTitles): graphTitles[ileg] = legend.replace("formula","#frac{#sigma_{E}}{E} = #frac{"+str(round(samplTerm[ileg]*100.,2))+"%}{#sqrt{E}} #oplus "+str(abs(round(constTerm[ileg]*100.,2)))+"%") graphTitles = ['#color['+str(colour[i])+']{'+t+'}' for i,t in enumerate(graphTitles)] # Draw all labels if not calo_init.args.noLinearity: padRes.cd() draw_text(graphTitles, [0.4,0.85 - 0.07 * len(graphTitles),0.95,0.95], 1, 0).SetTextSize(0.04) else: draw_text(graphTitles, [0.3,0.8 - 0.07 * len(graphTitles),0.95,0.86], 1, 0).SetTextSize(0.04) if not (calo_init.args.noLinearity and calo_init.args.title): draw_text(["energy resolution"], [0.2,0.88, 0.4,0.98], 1, 0).SetTextSize(0.05) else: cRes.SetTopMargin(0.1) draw_text([calo_init.args.title], [0.,0.9, 1,1], 1, 0).SetTextSize(0.05) if calo_init.args.noLinearity and calo_init.args.specialLabel: draw_text([calo_init.args.specialLabel], [0.67,0.88, 0.95,0.98], 1, 0).SetTextSize(0.05) if not calo_init.args.noLinearity: padLin.cd() draw_text(["linearity"], [0.2,0.78, 0.4,0.88], 1, 0).SetTextSize(0.05*factor) if calo_init.args.specialLabel: draw_text([calo_init.args.specialLabel], [0.67,0.78, 0.95,0.88], 1, 0).SetTextSize(0.05*factor)
# fill energy-dependent graphs param0.SetPoint(ifile,energyGraph,result.Get().Parameter(0)) param0.SetPointError(ifile,energyErrorGraph,result.Get().Error(0)) param1.SetPoint(ifile,energyGraph,result.Get().Parameter(1)) param1.SetPointError(ifile,energyErrorGraph,result.Get().Error(1)) if calo_init.args.preview: canvProfile = prepare_single_canvas( 'upstreamEnergy_e'+str(energy)+'GeV_eta'+str(eta), 'Upstream energy vs energy in first layer for #eta = '+str(eta)) draw_1histogram(hUpstremCellProfile, 'E_{firstLayer} '+energyUnit,'upstream energy '+energyUnit) hUpstremCellProfile.Fit(fitProfile, "SR") for ibin in reversed(range(0,hUpstremCellProfile.GetXaxis().GetNbins())): if hUpstremCellProfile.GetBinContent(ibin) > 0: lastNonEmpty = ibin break hUpstremCellProfile.GetXaxis().SetRange(0, lastNonEmpty + 3) legendProfile = draw_text([str(energy)+' GeV e^{-}, B = 4T'], [0.67,0.18, 0.85,0.28], 9, 0) legendProfile.SetTextSize(0.05) legendProfile.SetTextFont(42) canvProfile.Update() # save canvases filled for each energy and eta if calo_init.output(ifile): canvProfile.SaveAs(calo_init.output(ifile) + "_previewProfile_eta" + str(eta) + "_e"+str(energy)+"GeV.png") else: canvProfile.SaveAs("upstremCorrection_previewProfile_eta"+str(eta)+"_"+str(layer*width)+"cm.png") if calo_init.args.previewPhi: canvPhi = prepare_single_canvas( 'phi_e'+str(energy)+'GeV__eta'+str(eta), 'Phi distribution of first layer deposits for #eta = '+str(eta)) draw_1histogram(hCellPhi, '#varphi ' + angleUnit,'E_{firstLayer} ' + energyUnit) # Draw all labels if calo_init.args.specialLabel: canvProfile.cd() draw_text([calo_init.args.specialLabel], [0.57,0.88, 0.85,0.98], kGray+3, 0).SetTextSize(0.05)
else: graphTitles = [] for ileg, legend in enumerate(graphTitles): graphTitles[ileg] = legend.replace( "formula", "#frac{#sigma_{E}}{E} = #frac{" + str(round(samplTerm[ileg] * 100., 2)) + "%}{#sqrt{E}} + " + str(round(constTerm[ileg] * 100., 2)) + "%") graphTitles = [ '#color[' + str(colour[i]) + ']{' + t + '}' for i, t in enumerate(graphTitles) ] # Draw all labels if not calo_init.args.noLinearity: padRes.cd() draw_text(graphTitles, [0.55, 0.95 - 0.08 * len(graphTitles), 0.95, 0.95], 1, 0).SetTextSize(0.04) elif not calo_init.args.specialLabel: draw_text(graphTitles, [0.55, 0.95 - 0.08 * len(graphTitles), 0.95, 0.95], 1, 0).SetTextSize(0.04) else: draw_text(graphTitles, [0.55, 0.9 - 0.08 * len(graphTitles), 0.95, 0.85], 1, 0).SetTextSize(0.04) draw_text(["energy resolution"], [0.2, 0.88, 0.4, 0.98], 1, 0).SetTextSize(0.05) if calo_init.args.noLinearity and calo_init.args.specialLabel: draw_text([calo_init.args.specialLabel], [0.67, 0.88, 0.95, 0.98], 1, 0).SetTextSize(0.05) if not calo_init.args.noLinearity: padLin.cd() draw_text(["linearity"], [0.2, 0.78, 0.4, 0.88], 1, 0).SetTextSize(0.05 * factor)
fitResult = gRes.Fit(fRes, 'S') # Draw cRes = TCanvas("resolution", "Energy resolution", 1200, 900) gRes.Draw("ape") if calo_init.args.axisMax: gRes.GetYaxis().SetRangeUser(0, calo_init.args.axisMax) formula = str(round(fitResult.Get().Parameter(0), 4)) + " #oplus #frac{" + str( round(fitResult.Get().Parameter(1), 4)) + "}{#sqrt{E}}" constString = "const: " + str(round(fitResult.Get().Parameter(0), 4)) + " #pm " + str( round(fitResult.Get().Error(0), 4)) samplingString = "sampl: " + str(round(fitResult.Get().Parameter(1), 4)) + " #pm " + str( round(fitResult.Get().Error(1), 4)) draw_text([formula], [0.55, 0.8, 0.88, 0.86], colour, 0) draw_text([constString, samplingString], [0.55, 0.7, 0.88, 0.78], colour + 1, 0) cRes.Update() # Save canvas and root file with graph, const term and sampling term if calo_init.output(0): cRes.SaveAs(calo_init.output(0) + ".png") plots = TFile(calo_init.output(0) + ".root", "RECREATE") else: cRes.SaveAs("energy_resolution_plots.png") plots = TFile("energy_resolution_plots.root", "RECREATE") gRes.Write() const = numpy.zeros(1, dtype=float) sampl = numpy.zeros(1, dtype=float) constErr = numpy.zeros(1, dtype=float)
mean_list.append("#color[" + str(colours[ifile]) + "]{" + legend[ifile] + str(round((mean - energy) / energy * 100, 1)) + " %}") prepare_histogram(hEn, ';E_{beam} ' + energyUnit + ';fraction of events', colours[ifile]) hEn.GetXaxis().SetRangeUser(0.9 * energy, 1.1 * energy) if ifile == 0: hEn.DrawCopy() else: hEn.DrawCopy("sameep") fit.Draw("same") canv.Update() if not calo_init.args.noLinearity: draw_text( ["energy resolution", "#color[1]{#sigma_{E_{rec}}/#LTE_{rec}#GT}"] + resolution_list, [0.17, 0.8 - 0.05 * len(resolution_list), 0.42, 0.88], 1, 1) draw_text(["linearity", "#color[1]{(#LTE_{rec}#GT-E_{beam})/E_{beam}}"] + mean_list, [0.7, 0.8 - 0.05 * len(resolution_list), 0.95, 0.88], 1, 1) else: draw_text( ["energy resolution", "#color[1]{#sigma_{E_{rec}}/#LTE_{rec}#GT}"] + resolution_list, [0.6, 0.7 - 0.07 * len(resolution_list), 0.95, 0.78], 1, 0) if calo_init.args.specialLabel: draw_text([calo_init.args.specialLabel], [0.57, 0.88, 0.85, 0.98], kGray + 3, 0).SetTextSize(0.05) canv.Update() if calo_init.output(ifile):