예제 #1
0
sigma = RooRealVar(  'sigma', 'width of gaussian', 5.0 )

# Load reference ROOT tree
full_ch = TChain("DecayTree")
full_ch.Add("/mnt/home/kklimaszewski/LHCb/Bs2JpsieePhi/M_Bs_Fits/mc/DVNtuples_Bs2JpsieePhi_13154001_MCfull_R14ac_TupleBsDetached_PIDCorr_S21_NewSel_tupleB.root")
# Run selection
ch = full_ch.CopyTree("sigmam>0. && sigmam<250. && time>0.3 && time<14. && sigmat<0.12 && BDT_response_NewSel>0.2 && eminus_bremmult==0 && eplus_bremmult==0")
#fit.mass.setBins(_comp['config']['bins'])
# Create hist PDF
data = RooDataSet(
        'data_set',
        '',
        RooArgSet(x),
        RooFit.Import(ch)
        )
hist = data.binnedClone()
p1 = RooHistPdf(
        'histpdf',
        '',
        RooArgSet(x),
        hist,
        2  # Order of interpolation function
        )
#p2 = RooGaussian(
p2 = RooGaussModel(
    "comp_2",
    "",
    x,
    mean,
    sigma
    )
    ## Phi fitting

    kcanvas = TCanvas("kcanvas", "kcanvas", 1400, 800)

    pullpad = TPad("pullpad", "pullpad", 0.0, 0.05, 1.0, 0.33)
    plotpad = TPad("histopad", "histopad", 0.0, 0.35, 1.0, 1.0)
    plotpad.SetFillStyle(4004)
    pullpad.SetFillStyle(4004)
    plotpad.Draw()
    pullpad.Draw()

    traKFitData = theData.Clone("fitTrakData")

    if binnedfit:
        tt_mass.setBins(30)
        traKFitData = theData.binnedClone("binnedTrakData")

    phimean = 1.019
    gammavalue = 0.0012

    fitphimin = 1.00
    fitphimax = 1.04

    kkSigma = RooRealVar("#sigma", "#sigma", 0.0013)
    kkGamma = RooRealVar("#Gamma", "#Gamma", gammavalue, 0.001, 0.015)
    kkMean = RooRealVar("m_{kk}", "m_{kk}", phimean, phimean - 0.005,
                        phimean + 0.005)

    # B_1     = RooRealVar ( "B_1"    , "B_1 "    , 0.3  , -20   , 100   )
    # B_2     = RooRealVar ( "B_2"    , "B_2"    , 0.3  , -20   , 100   )
    # B_3     = RooRealVar ( "B_3"    , "B_3"    , 0.3  , -20   , 100   )
예제 #3
0
n_regions= len(regions)

#Create index for RooFit to distinguish regions
regionIndex = RooCategory("regionIndex", "regionIndex")
for i in range(n_regions) :
    regionIndex.defineType(regions[i])

lo_mass_cut = 1845
hi_mass_cut = 1885
lo_mid_dataset = mid_dataset_raw.reduce("D0_mass < "+str(lo_mass_cut))
mid_dataset = mid_dataset_raw.reduce("D0_mass >= "+str(lo_mass_cut)+" && D0_mass <= "+str(hi_mass_cut))
hi_mid_dataset = mid_dataset_raw.reduce("D0_mass > "+str(hi_mass_cut))

#Create new dataset separated by region
dataset = RooDataSet("dataset_"+mag, "dataset_"+mag, RooArgSet(deltam), Index(regionIndex), Import("lo_mid", lo_mid_dataset), Import("mid", mid_dataset), Import("hi_mid", hi_mid_dataset))
datahist = dataset.binnedClone()

##############################################
print "Dataset binned successfully!\n"

########### Fitting Pure Signal ##############

draw_p_sig = True

#Initial parameters for signal components
init_m = [145.4, 145.1, 148.3]
init_w = [0.37, 1, 5]
w_min = 0
w_max = 10

#Number of separate pdfs which make up the signal
예제 #4
0
파일: decayFit.py 프로젝트: graag/LHCb
def init_pdfs(fit, params, prefix, signal):
    '''
    Initialize RooFit PDFs from parameter dictionary

    :param MassFit fit: - MassFit instance
    :param dict params: - parameter dictionary
    :param str prefix: - pdf name prefix
    :param bool signal: - signal pdf
    :return: (pdf, components) with pdf - Composit pdf, components - list of component pdfs
    :rtype: tuple
    '''
    # Build recursive composit pdf:
    # M(x) = f_sig*S(x) + (1-f_sig){f_peak*P(x) + (1-f_peak)*B(x)}
    #
    # This avoids problems with sum(fractions) > 1
    # See chapter 3 of RooFit Users Manual
    #
    # Store all auto generated obejcts in TLists. Otherwise python will destroy
    # them as soon as this function ends

    _pdf = None  #: Composit PDF to return
    _components = TList()  #: List of component PDFs
    _components_all = TList()  #: List of component PDFs
    _fracs = TList()  #: List of fractions
    _funcs = TList()  #: List of formula variables
    _params = { prefix+"_"+fit.mass_name: fit.mass }
    _i = 1
    _n_comps = len(params["components"])
    for _comp in params["components"]:
        # Create parameters
        _comp_params = TList()
        _comp_constrs = TList()
        for _par in _comp["params"]:
            _name = prefix + "_" + _par["name"]
            if _name in _params:
                _comp_params.append(_params[_name])
            else:
                if "random" in _par and _par["random"] == True:
                    # Generate starting value and validity range
                    _min = random.uniform(_par["min"], _par["value"])
                    _max = random.uniform(_par["value"], _par["max"])
                    _value = random.uniform(_min, _max)
                    _par["random"] = False
                    # Store obtained values
                    _par["min"] = _min
                    _par["max"] = _max
                    _par["value"] = _value
                    _var = RooRealVar(
                            _name, _par["title"], _value,
                            _min, _max, _par["units"]
                            )
                else:
                    _var = RooRealVar(
                            _name, _par["title"], _par["value"],
                            _par["min"], _par["max"], _par["units"]
                            )
                fit.parameters.push_back(_var)
                _comp_params.Add(_var)
                _params[_name] = _var
                if "constraint" in _par:
                    _constr = RooGaussian(
                            _name+"_constr",
                            _par["title"]+"_constr",
                            _var,
                            RooFit.RooConst(_par["constraint"]["mean"]),
                            RooFit.RooConst(_par["constraint"]["sigma"])
                            )
                    fit.constraints.push_back(_constr)
                    _comp_constrs.Add(_constr)
        # Store mean and sigma of core part of the signal PDF
        if _i == 1 and signal == True:
            fit.sig_mass = _comp_params.At(0)
            fit.sig_sigma = _comp_params.At(1)
        _name = prefix+"_"+_comp["name"]
        # Initialize component
        if _comp["type"] not in supported_pdfs:
            raise Exception("Unknown PDF type: %s" % _comp["type"])
        if _comp["type"] == "RooAddPdf":
            (_sum_pdf, _sum_components, _sum_params) = init_pdfs(fit, _comp, _comp['name'], signal)
            _components_all.AddAll(_sum_components)
            _components.Add(_sum_pdf)
            _params.update(_sum_params)
        elif _comp["type"] == "RooGaussian":
            _components.Add(RooGaussian(
                    _name,
                    _comp["title"],
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(1))
                    )
        elif _comp["type"] == "RooParamGaussian":
            _v = RooFormulaVar(
                    _name+"_variable",
                    "",
                    "@0*@1",
                    RooArgList(
                        _comp_params.At(1),
                        _comp_params.At(2))
                    )
            _funcs.Add(_v)
            _components.Add(RooGaussian(
                    _name,
                    _comp["title"],
                    fit.mass,
                    _comp_params.At(0),
                    _v)
                    )
        elif _comp["type"] == "RooParamGaussianOffset":
            _m = RooFormulaVar(
                    _name+"_var_mean",
                    "",
                    "@0+@1",
                    RooArgList(
                        _comp_params.At(0),
                        _comp_params.At(1))
                    )
            _s = RooFormulaVar(
                    _name+"_var_sigma",
                    "",
                    "@0*@1",
                    RooArgList(
                        _comp_params.At(2),
                        _comp_params.At(3))
                    )
            _funcs.Add(_m)
            _funcs.Add(_s)
            _components.Add(RooGaussian(
                    _name,
                    _comp["title"],
                    fit.mass,
                    _m,
                    _s)
                    )
        elif _comp["type"] == "RooPolynomial":
            if len(_comp_params):
                _components.Add(RooPolynomial(
                        _name,
                        _comp["title"],
                        fit.mass,
                        RooArgList(_comp_params))
                        )
            else:
                _components.Add(RooPolynomial(
                        _name,
                        _comp["title"],
                        fit.mass)
                        )
        elif _comp["type"] == "RooChebychev":
            _components.Add(RooChebychev(
                    _name,
                    _comp["title"],
                    fit.mass,
                    RooArgList(_comp_params))
                    )
        elif _comp["type"] == "RooExponential":
            _components.Add(RooExponential(
                    _name,
                    _comp["title"],
                    fit.mass,
                    _comp_params.At(0))
                    )
        elif _comp["type"] == "RooVoigtian":
            _components.Add(RooVoigtian(
                    _name,
                    _comp["title"],
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(1),
                    _comp_params.At(2))
                    )
        elif _comp["type"] == "RooCBShape":
            _components.Add(RooCBShape(
                    _name,
                    _comp["title"],
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(1),
                    _comp_params.At(2),
                    _comp_params.At(3))
                    )
        elif _comp["type"] == "RooParamCBShape":
            _v = RooFormulaVar(
                    _name+"_variable",
                    "",
                    "@0*@1",
                    RooArgList(
                        _comp_params.At(1),
                        _comp_params.At(2))
                    )
            _funcs.Add(_v)
            _components.Add(RooCBShape(
                    _name,
                    _comp["title"],
                    fit.mass,
                    _comp_params.At(0),
                    _v,
                    _comp_params.At(3),
                    _comp_params.At(4))
                    )
        elif _comp["type"] == "RooDoubleCBShape":
            _components.Add(RooDoubleCBShape(
                    _name,
                    _comp["title"],
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(1),
                    _comp_params.At(2),
                    _comp_params.At(3),
                    _comp_params.At(4),
                    _comp_params.At(5))
                    )
        elif _comp["type"] == "RooCutCBShape":
            _components.Add(RooCutCBShape(
                    _name,
                    _comp["title"],
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(1),
                    _comp_params.At(2),
                    _comp_params.At(3),
                    _comp_params.At(4))
                    )
        elif _comp["type"] == "RooArgusBG":
            _components.Add(RooArgusBG(
                    _name,
                    _comp["title"],
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(1))
                    )
        elif _comp["type"] == "RooRArgusBG":
            _v = RooFormulaVar(
                    _name+"_variable",
                    "",
                    "2*@0 - @1",
                    RooArgList(
                        _comp_params.At(0),
                        fit.mass)
                    )
            _funcs.Add(_v)
            _components.Add(RooArgusBG(
                    _name,
                    _comp["title"],
                    _v,
                    _comp_params.At(0),
                    _comp_params.At(1))
                    )
        elif _comp["type"] == "RooIpatia":
            _components.Add(RooIpatia(
                    _name,
                    _comp["title"],
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(1),
                    _comp_params.At(2),
                    _comp_params.At(3),
                    _comp_params.At(4),
                    _comp_params.At(5),
                    _comp_params.At(6))
                    )
        elif _comp["type"] == "RooIpatia2":
            _components.Add(RooIpatia2(
                    _name,
                    _comp["title"],
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(1),
                    _comp_params.At(2),
                    _comp_params.At(3),
                    _comp_params.At(4),
                    _comp_params.At(5),
                    _comp_params.At(6),
                    _comp_params.At(7),
                    _comp_params.At(8))
                    )
        elif _comp["type"] == "RooCassandra":
            _components.Add(RooCassandra(
                    _name,
                    _comp["title"],
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(1),
                    _comp_params.At(2),
                    _comp_params.At(3))
                    )
        elif _comp["type"] == "RooAsymCassandra":
            _components.Add(RooAsymCassandra(
                    _name,
                    _comp["title"],
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(1),
                    _comp_params.At(2),
                    _comp_params.At(3),
                    _comp_params.At(4))
                    )
        elif _comp["type"] == "RooDecay":
            _r = RooGaussModel(
                    _name+"_resolution",
                    _comp["title"]+"_resolution",
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(2)
                    )
            _components.Add(RooDecay(
                _name,
                _comp["title"],
                fit.mass,
                _comp_params.At(1),
                _r,
                RooDecay.DoubleSided)
                )
            _funcs.Add(_r)
        elif _comp["type"] == "RooDecayLeft":
            _r = RooGaussModel(
                    _name+"_resolution",
                    _comp["title"]+"_resolution",
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(2)
                    )
            _components.Add(RooDecay(
                _name,
                _comp["title"],
                fit.mass,
                _comp_params.At(1),
                _r,
                RooDecay.Flipped)
                )
            _funcs.Add(_r)
        elif _comp["type"] == "RooDecayRight":
            _r = RooGaussModel(
                    _name+"_resolution",
                    _comp["title"]+"_resolution",
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(2)
                    )
            _components.Add(RooDecay(
                _name,
                _comp["title"],
                fit.mass,
                _comp_params.At(1),
                _r,
                RooDecay.SingleSided)
                )
            _funcs.Add(_r)
        elif _comp["type"] == "RooExpGaussExp":
            _components.Add(RooExpGaussExp(
                    _name,
                    _comp["title"],
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(1),
                    _comp_params.At(2),
                    _comp_params.At(3))
                    )
        elif _comp["type"] == "RooHistPdf":
            if 'config' not in _comp:
                raise Exception("Missing 'config' section for RooHistPdf.")
            if 'file' not in _comp['config']:
                raise Exception("Missing 'file' key in the 'config' section for RooHistPdf.")
            if 'name' not in _comp['config']:
                raise Exception("Missing 'name' key in the 'config' section for RooHistPdf.")
            _f = TFile(_comp['config']['file'])
            _pdf = _f.Get(_comp['config']['name'])
            _components.Add(_pdf)
        elif _comp["type"] == "Conv_RooDecay_RooBreitWigner":
            _r1 = RooGaussModel(
                    _name+"_resolution_1",
                    _comp["title"]+"_resolution_1",
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(2)
                    )
            _f1 = RooDecay(
                _name+"_comp_1",
                _comp["title"]+"_comp_1",
                fit.mass,
                _comp_params.At(1),
                _r1,
                RooDecay.DoubleSided
                )
            _f2 = RooBreitWigner(
                _name+"_comp_2",
                _comp["title"]+"_comp_2",
                fit.mass,
                _comp_params.At(3),
                _comp_params.At(4)
                )
            _funcs.Add(_r1)
            _funcs.Add(_f1)
            _funcs.Add(_f2)
            _pdf = RooNumConvPdf(
                _name,
                _comp["title"],
                fit.mass,
                _f1,
                _f2
                )
            _components.Add(_pdf)
        elif _comp["type"] == "FFT_RooDecay_RooBreitWigner":
            # Define sampling frequency
            fit.mass.setBins(10000,"fft") ;
            _r1 = RooGaussModel(
                    _name+"_resolution_1",
                    _comp["title"]+"_resolution_1",
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(2)
                    )
            _f1 = RooDecay(
                _name+"_comp_1",
                _comp["title"]+"_comp_1",
                fit.mass,
                _comp_params.At(1),
                _r1,
                RooDecay.DoubleSided
                )
            _f2 = RooBreitWigner(
                _name+"_comp_2",
                _comp["title"]+"_comp_2",
                fit.mass,
                _comp_params.At(3),
                _comp_params.At(4)
                )
            _funcs.Add(_r1)
            _funcs.Add(_f1)
            _funcs.Add(_f2)
            _pdf = RooFFTConvPdf(
                _name,
                _comp["title"],
                fit.mass,
                _f1,
                _f2
                )
            _pdf.setBufferFraction(50.0)
            _components.Add(_pdf)
        elif _comp["type"] == "FFT_RooDecay_RooCBShape":
            # Define sampling frequency
            fit.mass.setBins(10000,"fft") ;
            _r1 = RooGaussModel(
                    _name+"_resolution_1",
                    _comp["title"]+"_resolution_1",
                    fit.mass,
                    _comp_params.At(0),
                    _comp_params.At(2)
                    )
            _f1 = RooDecay(
                _name+"_comp_1",
                _comp["title"]+"_comp_1",
                fit.mass,
                _comp_params.At(1),
                _r1,
                RooDecay.DoubleSided
                )
            _f2 = RooCBShape(
                _name+"_comp_2",
                _comp["title"]+"_comp_2",
                fit.mass,
                _comp_params.At(3),
                _comp_params.At(4),
                _comp_params.At(5),
                _comp_params.At(6)
                )
            _funcs.Add(_r1)
            _funcs.Add(_f1)
            _funcs.Add(_f2)
            _pdf = RooFFTConvPdf(
                _name,
                _comp["title"],
                fit.mass,
                _f1,
                _f2
                )
            _pdf.setBufferFraction(50.0)
            _components.Add(_pdf)
        elif _comp["type"] == "FFT_RooCassandra_RooGaussian":
            # Define sampling frequency
            fit.mass.setBins(10000,"fft") ;
            _f1 = RooCassandra(
                _name+"_comp_1",
                _comp["title"]+"_comp_1",
                fit.mass,
                _comp_params.At(0),
                _comp_params.At(1),
                _comp_params.At(2)
                )
            _f2 = RooGaussian(
                _name+"_comp_2",
                _comp["title"]+"_comp_2",
                fit.mass,
                _comp_params.At(3),
                _comp_params.At(4)
                )
            _funcs.Add(_f1)
            _funcs.Add(_f2)
            _pdf = RooFFTConvPdf(
                _name,
                _comp["title"],
                fit.mass,
                _f1,
                _f2
                )
            _pdf.setBufferFraction(50.0)
            _components.Add(_pdf)
        elif _comp["type"] == "FFT_RooAsymCassandra_RooGaussian":
            # Define sampling frequency
            fit.mass.setBins(10000,"fft") ;
            _f1 = RooAsymCassandra(
                _name+"_comp_1",
                _comp["title"]+"_comp_1",
                fit.mass,
                _comp_params.At(0),
                _comp_params.At(1),
                _comp_params.At(2),
                _comp_params.At(3),
                _comp_params.At(4)
                )
            _f2 = RooGaussian(
                _name+"_comp_2",
                _comp["title"]+"_comp_2",
                fit.mass,
                _comp_params.At(5),
                _comp_params.At(6)
                )
            _funcs.Add(_f1)
            _funcs.Add(_f2)
            #_pdf = RooFFTConvPdf(
            #    _name,
            #    _comp["title"],
            #    fit.mass,
            #    _f1,
            #    _f2
            #    )
            _pdf = RooFFTConvPdf(
                _name,
                _comp["title"],
                fit.mass,
                _f2,
                _f1
                )
            _pdf.setBufferFraction(50.0)
            _components.Add(_pdf)
        elif _comp["type"] == "FFT_RooAsymCassandra_RooDoubleGaussian":
            # Define sampling frequency
            fit.mass.setBins(10000,"fft") ;
            _v = RooFormulaVar(
                    _name+"_variable",
                    "",
                    "@0*@1",
                    RooArgList(
                        _comp_params.At(6),
                        _comp_params.At(7))
                    )
            _funcs.Add(_v)
            _f1 = RooAsymCassandra(
                _name+"_comp_1",
                _comp["title"]+"_comp_1",
                fit.mass,
                _comp_params.At(0),
                _comp_params.At(1),
                _comp_params.At(2),
                _comp_params.At(3),
                _comp_params.At(4)
                )
            _f2 = RooGaussian(
                _name+"_comp_2",
                _comp["title"]+"_comp_2",
                fit.mass,
                _comp_params.At(5),
                _comp_params.At(6)
                )
            _f3 = RooGaussian(
                _name+"_comp_3",
                _comp["title"]+"_comp_3",
                fit.mass,
                _comp_params.At(5),
                _v
                )
            _f4 = RooAddPdf(
               _name,
               _comp["title"],
               RooArgList(_f2, _f3),
               RooArgList(_comp_params.At(8))
               )
            _funcs.Add(_f1)
            _funcs.Add(_f2)
            _funcs.Add(_f3)
            _funcs.Add(_f4)
            _pdf = RooFFTConvPdf(
                _name,
                _comp["title"],
                fit.mass,
                _f4,
                _f1
                )
            _pdf.setBufferFraction(50.0)
            _components.Add(_pdf)
        elif _comp["type"] == "Conv_RooAsymCassandra_RooGaussian":
            _f1 = RooAsymCassandra(
                _name+"_comp_1",
                _comp["title"]+"_comp_1",
                fit.mass,
                _comp_params.At(0),
                _comp_params.At(1),
                _comp_params.At(2),
                _comp_params.At(3),
                _comp_params.At(4)
                )
            _f2 = RooGaussian(
                _name+"_comp_2",
                _comp["title"]+"_comp_2",
                fit.mass,
                _comp_params.At(5),
                _comp_params.At(6)
                )
            _funcs.Add(_f1)
            _funcs.Add(_f2)
            _pdf = RooNumConvPdf(
                _name,
                _comp["title"],
                fit.mass,
                _f2,
                _f1
                )
            # Does not work
            #_pdf.setConvolutionWindow(_comp_params.At(5), _comp_params.At(6), 6.0)
            _components.Add(_pdf)
        elif _comp["type"] == "FFT_RooAsymCassandra3_RooGaussian":
            # Define sampling frequency
            fit.mass.setBins(10000,"fft") ;
            _f1 = RooAsymCassandra3(
                _name+"_comp_1",
                _comp["title"]+"_comp_1",
                fit.mass,
                _comp_params.At(0),
                _comp_params.At(1),
                _comp_params.At(2),
                _comp_params.At(3),
                _comp_params.At(4),
                _comp_params.At(5),
                _comp_params.At(6)
                )
            _f2 = RooGaussian(
                _name+"_comp_2",
                _comp["title"]+"_comp_2",
                fit.mass,
                _comp_params.At(7),
                _comp_params.At(8)
                )
            _funcs.Add(_f1)
            _funcs.Add(_f2)
            _pdf = RooFFTConvPdf(
                _name,
                _comp["title"],
                fit.mass,
                _f2,
                _f1
                )
            _pdf.setBufferFraction(50.0)
            _components.Add(_pdf)
        elif _comp["type"] == "FFT_RooCassandra_RooCBShape":
            # Define sampling frequency
            fit.mass.setBins(50000,"fft") ;
            _f1 = RooCassandra(
                _name+"_comp_1",
                _comp["title"]+"_comp_1",
                fit.mass,
                _comp_params.At(0),
                _comp_params.At(1),
                _comp_params.At(2)
                )
            _f2 = RooCBShape(
                _name+"_comp_2",
                _comp["title"]+"_comp_2",
                fit.mass,
                _comp_params.At(3),
                _comp_params.At(4),
                _comp_params.At(5),
                _comp_params.At(6)
                )
            _funcs.Add(_f1)
            _funcs.Add(_f2)
            _pdf = RooFFTConvPdf(
                _name,
                _comp["title"],
                fit.mass,
                _f1,
                _f2
                )
            _pdf.setBufferFraction(100.0)
            _components.Add(_pdf)
        elif _comp["type"] == "FFT_RooCassandra3_RooCBShape":
            # Define sampling frequency
            fit.mass.setBins(50000,"fft") ;
            _f1 = RooCassandra3(
                _name+"_comp_1",
                _comp["title"]+"_comp_1",
                fit.mass,
                _comp_params.At(0),
                _comp_params.At(1),
                _comp_params.At(2),
                _comp_params.At(3)
                )
            _f2 = RooCBShape(
                _name+"_comp_2",
                _comp["title"]+"_comp_2",
                fit.mass,
                _comp_params.At(4),
                _comp_params.At(5),
                _comp_params.At(6),
                _comp_params.At(7)
                )
            _funcs.Add(_f1)
            _funcs.Add(_f2)
            _pdf = RooFFTConvPdf(
                _name,
                _comp["title"],
                fit.mass,
                _f1,
                _f2
                )
            _pdf.setBufferFraction(100.0)
            _components.Add(_pdf)
        elif _comp["type"] == "FFT_RooHistPdf_RooGaussian":
            # Load reference ROOT tree
            _ref_full_ch = TChain(_comp['config']['tree'])
            _ref_full_ch.Add(_comp['config']['files'])
            # Run selection
            _ref_ch = _ref_full_ch.CopyTree(_comp['config']['selection'])
            _bins = fit.mass.getBins()
            fit.mass.setBins(_comp['config']['bins'])
            # Create hist PDF
            _data = RooDataSet(
                    'ds_' + _name,
                    '',
                    RooArgSet(fit.mass),
                    RooFit.Import(_ref_ch)
                    )
            _hist = _data.binnedClone()
            _f1 = RooHistPdf(
                    name+'_histpdf',
                    _comp['title']+'_histpdf',
                    RooArgSet(fit.mass),
                    _hist,
                    2  # Order of interpolation function
                    )
            fit.mass.setBins(_bins)

            # Define sampling frequency
            fit.mass.setBins(10000,"fft") ;
            _f2 = RooGaussModel(
                _name+"_comp_2",
                _comp["title"]+"_comp_2",
                fit.mass,
                _comp_params.At(0),
                _comp_params.At(1)
                )
            _funcs.Add(_hist)
            _funcs.Add(_f1)
            _funcs.Add(_f2)
            _pdf = RooFFTConvPdf(
                _name,
                _comp["title"],
                fit.mass,
                _f2,
                _f1
                )
            _pdf.setBufferFraction(5.0)
            _components.Add(_pdf)
        elif _comp["type"] == "Conv_RooHistPdf_RooGaussian":
            if 'config' not in _comp:
                raise Exception("Missing 'config' section for RooHistPdf.")
            if 'file' not in _comp['config']:
                raise Exception("Missing 'file' key in the 'config' section for RooHistPdf.")
            if 'name' not in _comp['config']:
                raise Exception("Missing 'name' key in the 'config' section for RooHistPdf.")
            _file = TFile(_comp['config']['file'])
            _f1 = _file.Get(_comp['config']['name'])
            _f2 = RooGaussian(
                _name+"_comp_2",
                _comp["title"]+"_comp_2",
                fit.mass,
                _comp_params.At(0),
                _comp_params.At(1)
                )
            _funcs.Add(_f1)
            _funcs.Add(_f2)
            _pdf = RooNumConvPdf(
                _name,
                _comp["title"],
                fit.mass,
                _f2,
                _f1
                )
            _components.Add(_pdf)
        elif _comp["type"] == "FFT_RooDoubleCBShape_RooGaussian":
            # Define sampling frequency
            fit.mass.setBins(10000,"fft") ;
            _f1 = RooDoubleCBShape(
                _name+"_comp_1",
                _comp["title"]+"_comp_1",
                fit.mass,
                _comp_params.At(0),
                _comp_params.At(1),
                _comp_params.At(2),
                _comp_params.At(3),
                _comp_params.At(4),
                _comp_params.At(5)
                )
            _f2 = RooGaussian(
                _name+"_comp_2",
                _comp["title"]+"_comp_2",
                fit.mass,
                _comp_params.At(6),
                _comp_params.At(7)
                )
            _funcs.Add(_f1)
            _funcs.Add(_f2)
            _pdf = RooFFTConvPdf(
                _name,
                _comp["title"],
                fit.mass,
                _f1,
                _f2
                )
            _pdf.setBufferFraction(50.0)
            _components.Add(_pdf)
        elif _comp["type"] == "FFT_2xCBShape_RooGaussian":
            # Define sampling frequency
            fit.mass.setBins(10000,"fft") ;
            _cb_frac = RooRealVar(
                    _name+"_cb_frac",
                    _name+"_cb_frac",
                    0.1, 0.0, 1.0)
            _f1 = RooCBShape(
                _name+"_comp_1",
                _comp["title"]+"_comp_1",
                fit.mass,
                _comp_params.At(0),
                _comp_params.At(1),
                _comp_params.At(2),
                _comp_params.At(3)
                )
            _f2 = RooCBShape(
                _name+"_comp_2",
                _comp["title"]+"_comp_2",
                fit.mass,
                _comp_params.At(0),
                _comp_params.At(1),
                _comp_params.At(4),
                _comp_params.At(5)
                )
            _f3 = RooAddPdf(
                _name+"_comp_3",
                _comp["title"]+"_comp_3",
                RooArgList(_f1, _f2),
                RooArgList(_cb_frac),
                kTRUE)
            _f4 = RooGaussian(
                _name+"_comp_4",
                _comp["title"]+"_comp_4",
                fit.mass,
                _comp_params.At(6),
                _comp_params.At(7)
                )
            _funcs.Add(_f1)
            _funcs.Add(_f2)
            _funcs.Add(_f3)
            _funcs.Add(_f4)
            _funcs.Add(_cb_frac)
            _pdf = RooFFTConvPdf(
                _name,
                _comp["title"],
                fit.mass,
                _f3,
                _f4
                )
            _pdf.setBufferFraction(50.0)
            _components.Add(_pdf)
        else:
            raise Exception("Unknown PDF type: "+_comp["type"])

        if _i < _n_comps:
            _f_v = 0.1
            _f_min = 0.0
            _f_max = 1.0
            if "fraction" in _comp:
                _f_v = _comp["fraction"]["value"]
                _f_min = _comp["fraction"]["min"]
                _f_max = _comp["fraction"]["max"]
            _f = RooRealVar(
                    prefix+"_frac_"+_comp["name"],
                    prefix+" component "+_comp["name"]+" fraction",
                    _f_v, _f_min, _f_max)
            if "fraction" in _comp and "constraint" in _comp["fraction"]:
                _constr = RooGaussian(
                        _name+"_frac_constr",
                        _name+"_frac_constr",
                        _f,
                        RooFit.RooConst(_comp["fraction"]["constraint"]["mean"]),
                        RooFit.RooConst(_comp["fraction"]["constraint"]["sigma"])
                        )
                fit.constraints.push_back(_constr)
                _comp_constrs.Add(_constr)
            _fracs.Add(_f)

        _i += 1

    if _n_comps == 1:
        _pdf = _components.At(0)
    else:
        # Make sure we are creating a recursive composit PDF
        _pdf = RooAddPdf(
            prefix+"_pdf",
            prefix+" PDF",
            RooArgList(_components),
            RooArgList(_fracs),
            kTRUE)

    _components_all.AddAll(_components)
    return (_pdf, _components_all, _params)
예제 #5
0
                  resmodel, RooDecay.SingleSided)
decay = RooAddPdf('decay', 'Decay function for the B_{s}',
                  decayH, decayL, RooRealConstant.value(0.5))
decayargset = RooArgSet(decay)

# Get tree
rfile = get_file('data/smalltree-new-MC.root', 'read')
ftree = get_object('ftree', rfile)

# dt dataset for denom
trigger = 'HLT2Topo3BodyTOS'
triggerVar = RooRealVar(trigger, trigger, 0, 2)
cut = trigger+'>0'
tmpdtdataset = RooDataSet('dtdataset', 'dt dataset', RooArgSet(dt, triggerVar),
                            RooFit.Import(ftree), RooFit.Cut(cut))
dtdatahist = tmpdtdataset.binnedClone('dtdatahist', 'Binned dt')
dtdatahist = dtdatahist.reduce(dtargset)
errorPdf = RooHistPdf('errorPdf', 'Time error Hist PDF', dtargset, dtdatahist)

decaywdt = RooProdPdf('decaywdt', 'Decay function with dt distribution',
                      RooArgSet(errorPdf),
                      RooFit.Conditional(decayargset, timeargset))

del tmpdtdataset, dtdatahist

# Variable width binning
nbins1 = 50
nbins2 = 24
binedges1 = numpy.zeros(nbins1+1 , dtype=float)
binedges2 = numpy.zeros(nbins2+1 , dtype=float)
logwidth = log10((1E-2 + 2E-4) / 2E-4)
예제 #6
0
    c.SaveAs("mm_mass_histos.root")

if args.nofit:
    sys.exit()

#### #### Done plotting

#### #### Fitting
### Trak trak
#

traKFitData = trakData.Clone("fitTrakData")

if binnedfit:
    tt_mass.setBins(100)
    traKFitData = trakData.binnedClone("binnedTrakData")

phimean = 1.019
gammavalue = 0.01

fitphimin = 1.0
fitphimax = 1.04

if args.nofitkk and args.noreco:

    ## RECO

    kkSigma = RooRealVar("#sigma", "#sigma", 0.0013)
    kkGamma = RooRealVar("#Gamma", "#Gamma", gammavalue, 0.001, 0.015)
    kkMean = RooRealVar("mean", "mean", phimean, phimean - 0.007,
                        phimean + 0.007)