<commit_before>## \file
## \ingroup tutorial_roofit
## \notebook
## Special pdf's: using a pdf defined by a sum of real-valued amplitude components
##
## \macro_code
##
## \date February 2018
## \authors <NAME>, <NAME> (C++ version)

import ROOT


# Setup 2D amplitude functions
# -------------------------------------------------------

# Observables
t = ROOT.RooRealVar("t", "time", -1.0, 15.0)
cosa = ROOT.RooRealVar("cosa", "cos(alpha)", -1.0, 1.0)

# Use ROOT.RooTruthModel to obtain compiled implementation of sinh/cosh
# modulated decay functions
tau = ROOT.RooRealVar("tau", "#tau", 1.5)
deltaGamma = ROOT.RooRealVar("deltaGamma", "deltaGamma", 0.3)
tm = ROOT.RooTruthModel("tm", "tm", t)
coshGBasis = ROOT.RooFormulaVar("coshGBasis", "exp(-@0/ @1)*cosh(@0*@2/2)", [t, tau, deltaGamma])
sinhGBasis = ROOT.RooFormulaVar("sinhGBasis", "exp(-@0/ @1)*sinh(@0*@2/2)", [t, tau, deltaGamma])
coshGConv = tm.convolution(coshGBasis, t)
sinhGConv = tm.convolution(sinhGBasis, t)

# Construct polynomial amplitudes in cos(a)
poly1 = ROOT.RooPolyVar(
    "poly1",
    "poly1",
    cosa,
    ROOT.RooArgList(ROOT.RooFit.RooConst(0.5), ROOT.RooFit.RooConst(0.2), ROOT.RooFit.RooConst(0.2)),
    0,
)
poly2 = ROOT.RooPolyVar(
    "poly2",
    "poly2",
    cosa,
    ROOT.RooArgList(ROOT.RooFit.RooConst(1), ROOT.RooFit.RooConst(-0.2), ROOT.RooFit.RooConst(3)),
    0,
)

# Construct 2D amplitude as uncorrelated product of amp(t)*amp(cosa)
ampl1 = ROOT.RooProduct("ampl1", "amplitude 1", [poly1, coshGConv])
ampl2 = ROOT.RooProduct("ampl2", "amplitude 2", [poly2, sinhGConv])

# Construct amplitude sum pdf
# -----------------------------------------------------

# Amplitude strengths
f1 = ROOT.RooRealVar("f1", "f1", 1, 0, 2)
f2 = ROOT.RooRealVar("f2", "f2", 0.5, 0, 2)

# Construct pdf
pdf = ROOT.RooRealSumPdf("pdf", "pdf", [ampl1, ampl2], [f1, f2])

# Generate some toy data from pdf
data = pdf.generate(ROOT.RooArgSet(t, cosa), 10000)

# Fit pdf to toy data with only amplitude strength floating
pdf.fitTo(data)

# Plot amplitude sum pdf<commit_msg>[RF] Remaining RooArgList to Python list change in rf704_amplitudefit<commit_after>## \file
## \ingroup tutorial_roofit
## \notebook
## Special pdf's: using a pdf defined by a sum of real-valued amplitude components
##
## \macro_code
##
## \date February 2018
## \authors <NAME>, <NAME> (C++ version)

import ROOT


# Setup 2D amplitude functions
# -------------------------------------------------------

# Observables
t = ROOT.RooRealVar("t", "time", -1.0, 15.0)
cosa = ROOT.RooRealVar("cosa", "cos(alpha)", -1.0, 1.0)

# Use ROOT.RooTruthModel to obtain compiled implementation of sinh/cosh
# modulated decay functions
tau = ROOT.RooRealVar("tau", "#tau", 1.5)
deltaGamma = ROOT.RooRealVar("deltaGamma", "deltaGamma", 0.3)
tm = ROOT.RooTruthModel("tm", "tm", t)
coshGBasis = ROOT.RooFormulaVar("coshGBasis", "exp(-@0/ @1)*cosh(@0*@2/2)", [t, tau, deltaGamma])
sinhGBasis = ROOT.RooFormulaVar("sinhGBasis", "exp(-@0/ @1)*sinh(@0*@2/2)", [t, tau, deltaGamma])
coshGConv = tm.convolution(coshGBasis, t)
sinhGConv = tm.convolution(sinhGBasis, t)

# Construct polynomial amplitudes in cos(a)
poly1 = ROOT.RooPolyVar("poly1", "poly1", cosa, [0.5, 0.2, 0.2], 0)
poly2 = ROOT.RooPolyVar("poly2", "poly2", cosa, [1.0, -0.2, 3.0], 0)

# Construct 2D amplitude as uncorrelated product of amp(t)*amp(cosa)
ampl1 = ROOT.RooProduct("ampl1", "amplitude 1", [poly1, coshGConv])
ampl2 = ROOT.RooProduct("ampl2", "amplitude 2", [poly2, sinhGConv])

# Construct amplitude sum pdf
# -----------------------------------------------------

# Amplitude strengths
f1 = ROOT.RooRealVar("f1", "f1", 1, 0, 2)
f2 = ROOT.RooRealVar("f2", "f2", 0.5, 0, 2)

# Construct pdf
pdf = ROOT.RooRealSumPdf("pdf", "pdf", [ampl1, ampl2], [f1, f2])

# Generate some toy data from pdf
data = pdf.generate(ROOT.RooArgSet(t, cosa), 10000)

# Fit pdf to toy data with only amplitude strength floating
pdf.fitTo(data)

# Plot amplitude sum pdf
{'fraction_non_alphanumeric': 0.21783181357649442, 'fraction_numerical': 0.04027355623100304, 'mean_word_length': 3.6623376623376624, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4137951', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1488, 'n_words': 369}