def plotSummary(name, closure, xmin=0, xmax=1, xTitle='m_{vis} [GeV]'): histoSmoothRatios = [] for hname, graph in closure.data['True/Est'].items(): if 'Histo' in hname and 'Smooth' in hname and not 'Error' in hname: histoSmoothRatios.append(graph) ################ Plot ratios histoDummyRatio = Hist(1, xmin, xmax, type='F') values = [] for ratio in histoSmoothRatios: for p in xrange(ratio.GetN()): values.append(ratio.GetY()[p]) maxi = max(values) mini = min(values) maxi = maxi * 1.1 if maxi > 0 else maxi * 0.9 mini = mini * 1.1 if mini < 0 else mini * 0.9 histoDummyRatio.SetAxisRange(mini, maxi, 'Y') ## for ratio in histoSmoothRatios: ratio.SetLineColor(ROOT.kGray + 3) ratio.SetLineWidth(1) ## canvasRatio = Canvas(800, 800) canvasRatio.SetName('Ratio_Summary_Canvas') histoDummyRatio.SetXTitle(xTitle) histoDummyRatio.SetYTitle('Ratio') histoDummyRatio.Draw() for ratio in histoSmoothRatios: ratio.Draw('l same') canvasRatio.Print( 'results/{NAME}_NonClosure_Ratio_Summary.png'.format(NAME=name))
def plotDataMC(name, closureData, closureMC, bins, xTitle='m_{vis} [GeV]'): binid = hash(str(bins)) # histoRatioData = closureData.data['True/Est']['Histo_{H}'.format(H=binid)] histoSmoothRatioData = closureData.data['True/Est'][ 'Histo_{H}_Smooth'.format(H=binid)] histoSmoothRatioErrorData = closureData.data['True/Est'][ 'Histo_{H}_SmoothError'.format(H=binid)] histoRatioMC = closureMC.data['True/Est']['Histo_{H}'.format(H=binid)] histoSmoothRatioMC = closureMC.data['True/Est']['Histo_{H}_Smooth'.format( H=binid)] histoSmoothRatioErrorMC = closureMC.data['True/Est'][ 'Histo_{H}_SmoothError'.format(H=binid)] # ################ Plot ratios histoDummyRatio = Hist(1, bins[0], bins[-1], type='F') values = [] values.append(histoRatioData.GetMaximum()) values.append(histoRatioData.GetMinimum()) values.append(histoRatioMC.GetMaximum()) values.append(histoRatioMC.GetMinimum()) maxi = max(values) mini = min(values) maxi = maxi * 1.1 if maxi > 0 else maxi * 0.9 mini = mini * 1.1 if mini < 0 else mini * 0.9 histoDummyRatio.SetAxisRange(mini, maxi, 'Y') ## histoRatioData.SetMarkerColor(ROOT.kBlack) histoSmoothRatioData.SetLineColor(ROOT.kGray + 3) histoSmoothRatioData.SetLineWidth(2) histoSmoothRatioErrorData.SetLineColor(ROOT.kGray + 1) histoSmoothRatioErrorData.SetFillColor(ROOT.kGray + 1) ## histoRatioMC.SetMarkerColor(ROOT.kRed) histoRatioMC.SetMarkerStyle(21) histoSmoothRatioMC.SetLineColor(ROOT.kRed) histoSmoothRatioMC.SetLineWidth(2) histoSmoothRatioErrorMC.SetLineColor(ROOT.kRed - 7) #histoSmoothRatioErrorMC.SetFillColorAlpha(ROOT.kRed-7, 0.35) histoSmoothRatioErrorMC.SetFillStyle(3344) histoSmoothRatioErrorMC.SetFillColor(ROOT.kRed - 7) ## canvasRatio = Canvas(800, 800) canvasRatio.SetName('{NAME}_Ratio_Canvas'.format(NAME=name)) histoDummyRatio.SetXTitle(xTitle) histoDummyRatio.SetYTitle('Ratio') histoDummyRatio.Draw() histoSmoothRatioErrorData.Draw('fl same') histoSmoothRatioData.Draw('pl same') histoSmoothRatioErrorMC.Draw('fl same') histoSmoothRatioMC.Draw('pl same') histoRatioData.Draw('E1 same') histoRatioMC.Draw('E1 same') # legend = ROOT.TLegend(0.15, 0.75, 0.45, 0.9) legend.SetFillColor(0) legend.SetLineColor(0) legend.AddEntry(histoRatioMC, 'MC', 'lp') legend.AddEntry(histoRatioData, 'Data', 'lp') legend.Draw() canvasRatio.Print('results/{NAME}_NonClosure_Ratio.png'.format(NAME=name))
def main(parameters): input_files = parameters.input_files tree_name = parameters.input_tree means = Hist(4*len(input_files), 0, 4*len(input_files), name='mean values') rmss = Hist(4*len(input_files), 0, 4*len(input_files), name='rms values') cov_means = Hist(2*len(input_files), 0, 2*len(input_files), name='covariance mean values') cov_rmss = Hist(2*len(input_files), 0, 2*len(input_files), name='covariance rms values') means.SetYTitle('Variance mean [cm^{2}]') rmss.SetYTitle('Variance RMS [cm^{2}]') cov_means.SetYTitle('Covariance mean [cm^{2}]') cov_rmss.SetYTitle('Covariance RMS [cm^{2}]') with root_open(parameters.output_file, 'recreate') as output_file: for i, (name, input_file_name) in enumerate(input_files): means.GetXaxis().SetBinLabel(i*4+1, name+' x') means.GetXaxis().SetBinLabel(i*4+2, name+' y') means.GetXaxis().SetBinLabel(i*4+3, name+' u') means.GetXaxis().SetBinLabel(i*4+4, name+' v') rmss.GetXaxis().SetBinLabel(i*4+1, name+' x') rmss.GetXaxis().SetBinLabel(i*4+2, name+' y') rmss.GetXaxis().SetBinLabel(i*4+3, name+' u') rmss.GetXaxis().SetBinLabel(i*4+4, name+' v') cov_means.GetXaxis().SetBinLabel(i*2+1, name+' x/y') cov_rmss.GetXaxis().SetBinLabel(i*2+1, name+' x/y') cov_means.GetXaxis().SetBinLabel(i*2+2, name+' u/v') cov_rmss.GetXaxis().SetBinLabel(i*2+2, name+' u/v') with root_open(input_file_name) as input_file: tree = input_file.Get(tree_name) moment_2nd_x, moment_2nd_y, moment_2nd_xy, moment_2nd_u, moment_2nd_v, moment_2nd_uv = shape_distribution(tree, parameters.log_weights) print name print 'x variance Mu =', moment_2nd_x.GetMean(), '+/-', moment_2nd_x.GetMeanError(), 'RMS =', moment_2nd_x.GetRMS(), '+/-', moment_2nd_x.GetRMSError() print 'y variance Mu =', moment_2nd_y.GetMean(), '+/-', moment_2nd_y.GetMeanError(), 'RMS =', moment_2nd_y.GetRMS(), '+/-', moment_2nd_y.GetRMSError() print 'u variance Mu =', moment_2nd_u.GetMean(), '+/-', moment_2nd_u.GetMeanError(), 'RMS =', moment_2nd_u.GetRMS(), '+/-', moment_2nd_u.GetRMSError() print 'v variance Mu =', moment_2nd_v.GetMean(), '+/-', moment_2nd_v.GetMeanError(), 'RMS =', moment_2nd_v.GetRMS(), '+/-', moment_2nd_v.GetRMSError() print 'x-y covariance Mu =', moment_2nd_xy.GetMean(), '+/-', moment_2nd_xy.GetMeanError(), 'RMS =', moment_2nd_xy.GetRMS(), '+/-', moment_2nd_xy.GetRMSError() print 'u-v covariance Mu =', moment_2nd_uv.GetMean(), '+/-', moment_2nd_uv.GetMeanError(), 'RMS =', moment_2nd_uv.GetRMS(), '+/-', moment_2nd_uv.GetRMSError() # fill mean values of variances means.SetBinContent(i*4+1, moment_2nd_x.GetMean()) means.SetBinError(i*4+1, moment_2nd_x.GetMeanError()) means.SetBinContent(i*4+2, moment_2nd_y.GetMean()) means.SetBinError(i*4+2, moment_2nd_y.GetMeanError()) means.SetBinContent(i*4+3, moment_2nd_u.GetMean()) means.SetBinError(i*4+3, moment_2nd_u.GetMeanError()) means.SetBinContent(i*4+4, moment_2nd_v.GetMean()) means.SetBinError(i*4+4, moment_2nd_v.GetMeanError()) # fill rms values of variances rmss.SetBinContent(i*4+1, moment_2nd_x.GetRMS()) rmss.SetBinError(i*4+1, moment_2nd_x.GetRMSError()) rmss.SetBinContent(i*4+2, moment_2nd_y.GetRMS()) rmss.SetBinError(i*4+2, moment_2nd_y.GetRMSError()) rmss.SetBinContent(i*4+3, moment_2nd_u.GetRMS()) rmss.SetBinError(i*4+3, moment_2nd_u.GetRMSError()) rmss.SetBinContent(i*4+4, moment_2nd_v.GetRMS()) rmss.SetBinError(i*4+4, moment_2nd_v.GetRMSError()) # fill mean values of covariances cov_means.SetBinContent(i*2+1, moment_2nd_xy.GetMean()) cov_means.SetBinError(i*2+1, moment_2nd_xy.GetMeanError()) cov_means.SetBinContent(i*2+2, moment_2nd_uv.GetMean()) cov_means.SetBinError(i*2+2, moment_2nd_uv.GetMeanError()) # fill rms values of covariances cov_rmss.SetBinContent(i*2+1, moment_2nd_xy.GetRMS()) cov_rmss.SetBinError(i*2+1, moment_2nd_xy.GetRMSError()) cov_rmss.SetBinContent(i*2+2, moment_2nd_uv.GetRMS()) cov_rmss.SetBinError(i*2+2, moment_2nd_uv.GetRMSError()) # write variance distributions moment_2nd_x.SetName(moment_2nd_x.GetName()+'_'+name) moment_2nd_y.SetName(moment_2nd_y.GetName()+'_'+name) moment_2nd_xy.SetName(moment_2nd_xy.GetName()+'_'+name) moment_2nd_u.SetName(moment_2nd_u.GetName()+'_'+name) moment_2nd_v.SetName(moment_2nd_v.GetName()+'_'+name) output_file.cd() moment_2nd_x.Write() moment_2nd_y.Write() moment_2nd_xy.Write() moment_2nd_u.Write() moment_2nd_v.Write() means.Write() rmss.Write() cov_means.Write() cov_rmss.Write()
def plotClosure(name, closure, bins, smoothWidth=0.1, kernelDistance='Adapt', doErrors=False, xTitle='m_{vis} [GeV]'): binid = hash(str(bins)) closure.computeHisto('True', bins) closure.computeHisto('Est', bins) closure.computeRatio('Est', 'True', 'Histo_{H}'.format(H=binid), smoothWidth, kernelDistance, doErrors) # histoTrue = closure.data['True']['Histo_{H}'.format(H=binid)] histoEst = closure.data['Est']['Histo_{H}'.format(H=binid)] histoRatio = closure.data['True/Est']['Histo_{H}'.format(H=binid)] histoSmoothRatio = closure.data['True/Est']['Histo_{H}_Smooth'.format( H=binid)] histoSmoothRatioError = closure.data['True/Est'][ 'Histo_{H}_SmoothError'.format(H=binid)] # ############ plot raw distributions histoDummy = Hist(1, bins[0], bins[-1], type='F') values = [] values.append(histoTrue.GetMaximum()) values.append(histoTrue.GetMinimum()) values.append(histoEst.GetMaximum()) values.append(histoEst.GetMinimum()) maxi = max(values) * 1.1 mini = min(values) histoDummy.SetAxisRange(mini, maxi, 'Y') ## histoTrue.SetMarkerColor(ROOT.kBlack) histoEst.SetMarkerStyle(24) histoEst.SetMarkerColor(ROOT.kGray + 3) ## canvas = Canvas(800, 800) canvas.SetName('{NAME}_Canvas'.format(NAME=name)) histoDummy.SetXTitle(xTitle) histoDummy.SetYTitle('Events') histoDummy.Draw() histoTrue.Draw('same') histoEst.Draw('same') legend = ROOT.TLegend(0.4, 0.7, 0.9, 0.9) legend.SetFillColor(0) legend.SetLineColor(0) legend.AddEntry(histoTrue, 'True background', 'lp') legend.AddEntry(histoEst, 'Estimated background', 'lp') legend.Draw() canvas.Print('results/{NAME}_NonClosure.png'.format(NAME=name)) ################ Plot ratios histoDummyRatio = Hist(1, bins[0], bins[-1], type='F') values = [] values.append(histoRatio.GetMaximum()) values.append(histoRatio.GetMinimum()) maxi = max(values) mini = min(values) maxi = maxi * 1.1 if maxi > 0 else maxi * 0.9 mini = mini * 1.1 if mini < 0 else mini * 0.9 histoDummyRatio.SetAxisRange(mini, maxi, 'Y') ## histoRatio.SetMarkerColor(ROOT.kBlack) histoSmoothRatio.SetLineColor(ROOT.kGray + 3) histoSmoothRatio.SetLineWidth(2) histoSmoothRatioError.SetLineColor(ROOT.kGray + 1) histoSmoothRatioError.SetFillColor(ROOT.kGray + 1) ## canvasRatio = Canvas(800, 800) canvasRatio.SetName('{NAME}_Ratio_Canvas'.format(NAME=name)) histoDummyRatio.SetXTitle(xTitle) histoDummyRatio.SetYTitle('Ratio') histoDummyRatio.Draw() histoSmoothRatioError.Draw('fl same') histoSmoothRatio.Draw('pl same') histoRatio.Draw('same') canvasRatio.Print('results/{NAME}_NonClosure_Ratio.png'.format(NAME=name))