from ROOT import TFile, TNtuple, TCanvas, TH2F, TText # First create the 1D phase space for variable x xphsp = OneDimPhaseSpace("PhspX", -1., 1.) # Now create the parametric phase space for (x,y) where limits on variable y are functions of x phsp = ParametricPhaseSpace("PhspParam", xphsp, "-sqrt(1-x^2)", "sqrt(1-x^2)", -1., 1.) outfile = TFile("TwoDimPolyPdf.root", "RECREATE") ntuple = TNtuple("ntuple", "2D NTuple", "x:y") # True PDF true_pdf = FormulaDensity("TruePDF", phsp, "1.+0.1*x-0.4*x^2-0.8*y^2") # Generate 10000 toys according to the true PDF true_pdf.generate(ntuple, 50000) poly = PolynomialDensity("PolyPDF", phsp, 4, ntuple, "x", "y", 100000) poly_hist = TH2F("poly", "Polynomial PDF", 200, -1.1, 1.1, 200, -1.1, 1.1) poly.project(poly_hist) poly_hist.Write() gStyle.SetOptStat(0) canvas = TCanvas("canvas", "TwoDimPolyPdf", 400, 400) poly_hist.Draw("zcol") canvas.Print("TwoDimPolyPdf.png")
ma = 0.497 # KS0 mb = 0.139 # Pi mc = 0.139 # Pi # Define Dalitz phase space for D0->KsPiPi decay # The phase space is defined in x=m^2(ab), y=m^2(ac) variables phsp = DalitzPhaseSpace("PhspDalitz", md, ma, mb, mc) # Create a true PDF over this phase space, polynomial of power 4 in x and y truepdf = FormulaDensity("TruePDF", phsp, "sqrt(1.-0.1*(x-1.3)^4)*(1.+2.*exp(-y))") outfile = TFile.Open("DalitzPdf.root", "RECREATE") ntuple = TNtuple("ntuple", "2D NTuple", "x:y") # Generate 50000 toys according to the "true" PDF truepdf.generate(ntuple, 25000) # Create an approximation PDF, polynomial of power 3 poly = PolynomialDensity("PolyPDF", phsp, # Phase space 2, # Power of the polynomial ntuple, # Input ntuple "x","y", # Ntuple variables 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
from ROOT import OneDimPhaseSpace, FormulaDensity from ROOT import BinnedKernelDensity, BinnedDensity, AdaptiveKernelDensity from ROOT import TFile, TNtuple, TCanvas, TH1F, TText # Define 1D phase space for a variable in range (-1, 1) phsp = OneDimPhaseSpace("Phsp1D", -1., 1.) # Create a "true" PDF over this phase space in a parametrised way formula = FormulaDensity("FormulaPDF", phsp, "(1. + 4.*exp(-x*x/2/0.1/0.1))*( abs(x)<1 )") outfile = TFile("OneDimAdaptiveKernel.root", "RECREATE") ntuple = TNtuple("ntuple", "1D NTuple", "x") # Generate toys according to the "true" PDF formula.generate(ntuple, 10000) # Create kernel PDF from the generate sample kde = BinnedKernelDensity("KernelPDF", phsp, # Phase space ntuple, # Input ntuple "x", # Variable to use 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) ) # Create adaptive kernel PDF with the kernel width depending on the binned PDF kde_adaptive = AdaptiveKernelDensity("AdaptivePDF", phsp, # Phase space