# Create kernel PDF from the generated sample # If the number of variables passed to the constructor is larger by 1 than the phase # space dimensionality, the last variables is considered as the weight kde = BinnedKernelDensity("KernelPDF", phsp, ntuple, # Input ntuple "x", # Variable to use "w", # Weight variable 1000, # Number of bins 0.1, # Kernel width 0, # Approximation PDF (0 for flat approximation) 100000 # Sample size for MC convolution (0 for binned convolution) ) # Write binned PDF into a file kde.writeToFile("WeightedTuple_bins.root") # That's it. Now fill some control histograms and plot them. kernel_hist = TH1F("kernel", "Kernel PDF", 200, -1.5, 1.5) kde.project(kernel_hist) uniform_hist.Write() kernel_hist.Write() gStyle.SetOptStat(0) canvas = TCanvas("canvas", "WeightedTuple", 400, 400) uniform_hist.Draw() kernel_hist.Scale( uniform_hist.GetSumOfWeights() / kernel_hist.GetSumOfWeights() ) kernel_hist.SetLineColor(2)
# Generate 10000 toys according to the uniform PDF uniform.generate(ntuple, 10000) # Create kernel PDF from the generate sample kde = BinnedKernelDensity("KernelPDF", phsp, ntuple, # Input ntuple "x", # Variable to use 1000, # Number of bins 0.2, # Kernel width 0, # Approximation PDF (0 for flat approximation) 100000 # Sample size for MC convolution (0 for binned convolution) ) # Write binned PDF into a file kde.writeToFile("OneDimPdfBins.root") uniform_hist = TH1F("unform", "PDF", 200, -1.5, 1.5) kernel_hist = TH1F("kernel", "Kernel PDF", 200, -1.5, 1.5) uniform.project(uniform_hist) kde.project(kernel_hist) gStyle.SetOptStat(0) canvas = TCanvas("canvas", "OneDimPdf", 400, 400) uniform_hist.Draw() kernel_hist.Scale( uniform_hist.GetSumOfWeights() / kernel_hist.GetSumOfWeights() ) kernel_hist.SetLineColor(2) kernel_hist.Draw("same")
50000 # Sample size for MC integration ) # Create kernel PDF from the generated sample kde = BinnedKernelDensity("KernelPDF", phsp, # Phase space ntuple, # Input ntuple "x","y", # Variables to use 200,200, # Numbers of bins 0.4, 0.4,# Kernel widths poly, # Approximation PDF (0 for flat approximation) 50000 # Sample size for MC convolution (0 for binned convolution) ) # Write binned PDF into a file kde.writeToFile("DalitzPdf_bins.root") # That's it. Now fill some histograms and show the results. true_hist = TH2F("true", "True PDF", 100, phsp.lowerLimit(0), phsp.upperLimit(0), 100, phsp.lowerLimit(1), phsp.upperLimit(1)) poly_hist = TH2F("poly", "Polynomial PDF", 100, phsp.lowerLimit(0), phsp.upperLimit(0), 100, phsp.lowerLimit(1), phsp.upperLimit(1)) kernel_hist = TH2F("kernel", "Kernel PDF", 100, phsp.lowerLimit(0), phsp.upperLimit(0), 100, phsp.lowerLimit(1), phsp.upperLimit(1)) true_kpi = TH1F("true_kpi", "M^{2}(K_{S}#pi) slice", 100, phsp.lowerLimit(0), phsp.upperLimit(0) ) poly_kpi = TH1F("poly_kpi", "M^{2}(K_{S}#pi) slice", 100, phsp.lowerLimit(0), phsp.upperLimit(0) ) kernel_kpi = TH1F("kernel_kpi", "M^{2}(K_{S}#pi) slice", 100, phsp.lowerLimit(0), phsp.upperLimit(0) ) true_pipi = TH1F("true_pipi", "M^{2}(#pi#pi) slice", 100, phsp.lowerLimit(1), phsp.upperLimit(1) ) poly_pipi = TH1F("poly_pipi", "M^{2}(#pi#pi) slice", 100, phsp.lowerLimit(1), phsp.upperLimit(1) )
# Generate 50000 toys according to the "true" PDF truepdf.generate(ntuple, 50000) # Create kernel PDF from the generated sample. Use polynomial shape as an approximation PDF kde = BinnedKernelDensity("KernelPDF", phsp, # Phase space ntuple, # Input ntuple "x","y", # Variables to use 200,200, # Numbers of bins 0.2, 0.2, # Kernel widths approxpdf, # Approximation PDF (0 for flat approximation) 100000 # Sample size for MC convolution (0 for binned convolution) ) # Write binned PDF into a file kde.writeToFile("ParamPhsp_bins.root") # That's it. Now fill some histograms and show the results. true_hist = TH2F("true", "True PDF", 100, phsp.lowerLimit(0), phsp.upperLimit(0), 100, phsp.lowerLimit(1), phsp.upperLimit(1)) kernel_hist = TH2F("kernel", "Kernel PDF", 100, phsp.lowerLimit(0), phsp.upperLimit(0), 100, phsp.lowerLimit(1), phsp.upperLimit(1)) true_kpi = TH1F("true_kpi", "X slice", 100, phsp.lowerLimit(0), phsp.upperLimit(0) ) kernel_kpi = TH1F("kernel_kpi", "X slice", 100, phsp.lowerLimit(0), phsp.upperLimit(0) ) true_pipi = TH1F("true_pipi", "Y slice", 100, phsp.lowerLimit(1), phsp.upperLimit(1) ) kernel_pipi = TH1F("kernel_pipi", "Y slice", 100, phsp.lowerLimit(1), phsp.upperLimit(1) ) # Coordinates in the phase space where we will create the 1D slices. from ROOT import std, Double