Example #1
0
from ROOT import DalitzPhaseSpace, BinnedKernelDensity, FactorisedDensity, FormulaDensity
from ROOT import BinnedDensity, AdaptiveKernelDensity, PolynomialDensity
from ROOT import TFile, TNtuple, TCanvas, TH1F, TH2F, TText

# Define masses of initial ("d") and final state particles ("a,b,c") for the Dalitz phase space. 
md = 1.8646  # D0
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
                         )
#
#  It also uses FormulaDensity to describe the true PDF in a parametrised way. 

from ROOT import gSystem, gStyle

gSystem.Load("../lib/libMeerkat.so")

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)
Example #3
0
gSystem.Load("../lib/libMeerkat.so")

from ROOT import OneDimPhaseSpace, ParametricPhaseSpace, FormulaDensity, PolynomialDensity
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") 
Example #4
0
from ROOT import gSystem, gStyle

gSystem.Load("../lib/libMeerkat.so")

from ROOT import OneDimPhaseSpace, ParametricPhaseSpace, BinnedKernelDensity, FormulaDensity
from ROOT import TFile, TNtuple, TCanvas, TH1F, 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.)

# Create a uniform PDF over this phase space
# Sum of a polynomial shape and a Gaussian peak with correlation between x and y
truepdf = FormulaDensity("TruePDF", phsp, "1.-0.8*x^2-0.8*y^2+exp(-(x-y)^2/2./(0.4)^2-(x+y)^2/2./(0.8)^2)") 

# Create an approximation PDF over this phase space
# Just a polymonial shape. It will mostly be used to approximate the PDF 
# at the edges of the phase space.
approxpdf = FormulaDensity("TruePDF", phsp, "1.-0.8*x^2-0.8*y^2") 

outfile = TFile("ParamPhsp.root", "RECREATE")
ntuple = TNtuple("ntuple", "2D NTuple", "x:y") 

# 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