当前位置: 首页>>代码示例>>Python>>正文


Python RooArgSet.assignValueOnly方法代码示例

本文整理汇总了Python中ROOT.RooArgSet.assignValueOnly方法的典型用法代码示例。如果您正苦于以下问题:Python RooArgSet.assignValueOnly方法的具体用法?Python RooArgSet.assignValueOnly怎么用?Python RooArgSet.assignValueOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ROOT.RooArgSet的用法示例。


在下文中一共展示了RooArgSet.assignValueOnly方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from ROOT import RooArgSet [as 别名]
# 或者: from ROOT.RooArgSet import assignValueOnly [as 别名]
    def run(self, **kwargs):
        from ROOT import RooArgSet

        __check_req_kw__("Observables", kwargs)
        __check_req_kw__("Pdf", kwargs)

        observables = kwargs.pop("Observables")
        obs_set = RooArgSet(*observables)

        pdf = kwargs.pop("Pdf")
        genPdf = kwargs.pop("GenPdf", pdf)

        gen_obs_set = RooArgSet()
        for o in list(observables) + list(genPdf.ConditionalObservables()):
            gen_obs_set.add(o._target_())
        gen_pdf_params = genPdf.getParameters(gen_obs_set).snapshot(True)

        genPdf = genPdf.clone(genPdf.GetName() + "_toy_clone")
        genPdf.recursiveRedirectServers(gen_pdf_params)

        fit_obs_set = RooArgSet()
        for o in list(observables) + list(pdf.ConditionalObservables()):
            fit_obs_set.add(o._target_())
        params = pdf.getParameters(fit_obs_set)

        pdf_params = RooArgSet()
        for p in params:
            if p.isConstant():
                continue
            pdf_params.add(p)
        ## for param in pdf_params:
        ##     if param.GetName() not in ['Gamma', 'dGamma']:
        ##         param.setConstant()
        self._gen_params = pdf_params.snapshot(True)

        # Make another ArgSet to put the fit results in
        result_params = RooArgSet(pdf_params, "result_params")

        transform = self.transform()
        if transform:
            trans_params = transform.gen_params(gen_obs_set)
            for p in trans_params:
                result_params.add(p)

        # Some extra numbers of interest
        from ROOT import RooRealVar

        NLL = RooRealVar("NLL", "-log(Likelihood)", 1.0)
        ngen = RooRealVar("ngen", "number of generated events", self.options().nevents)
        seed = RooRealVar("seed", "random seed", 0.0)
        from ROOT import RooCategory

        status = RooCategory("status", "fit status")
        status.defineType("success", 0)
        status.defineType("one", 1)
        status.defineType("two", 2)
        status.defineType("three", 3)
        status.defineType("other", 4)
        result_params.add(status)
        result_params.add(NLL)
        result_params.add(ngen)
        result_params.add(seed)

        # The dataset to store the results
        from ROOT import RooDataSet

        self._data = RooDataSet("result_data", "result_data", result_params)
        data_params = self._data.get()

        from ROOT import RooRandom
        import struct, os

        while self._data.numEntries() < self.options().ntoys:
            # Get a good random seed, set it and store it
            s = struct.unpack("I", os.urandom(4))[0]
            RooRandom.randomGenerator().SetSeed(s)
            seed.setVal(s)

            # Reset pdf parameters to initial values. Note: this does not reset the estimated errors...
            pdf_params.assignValueOnly(self.gen_params())
            args = dict(NumEvents=self.options().nevents)
            if "ProtoData" in kwargs:
                args["ProtoData"] = kwargs.pop("ProtoData")

            genPdf.getParameters(obs_set).assignValueOnly(gen_pdf_params)
            data = genPdf.generate(obs_set, **args)
            if transform:
                data = transform(data)
                if not data:
                    # Transform has failed
                    transform.set_params(data_params)
                    self._data.add(data_params)
                    continue

            if data.isWeighted() and "SumW2Error" not in self.fit_opts():
                self.fit_opts()["SumW2Error"] = False

            j = 0
            while j < 4:
                fit_result = pdf.fitTo(data, NumCPU=self.options().ncpu, **(self.fit_opts()))
#.........这里部分代码省略.........
开发者ID:GerhardRaven,项目名称:P2VV,代码行数:103,代码来源:ToyMCUtils.py

示例2: getObsVal

# 需要导入模块: from ROOT import RooArgSet [as 别名]
# 或者: from ROOT.RooArgSet import assignValueOnly [as 别名]
# function to get observable value from dataset
def getObsVal( names, obsSet ) :
    vals = [ ]
    for name in names :
        catInd = obsSet.getCatIndex( name, -999 )
        vals.append( catInd if catInd != -999 else obsSet.getRealValue(name) )
    return tuple(vals) if len(vals) > 1 else vals[0]

# fill datasets
from P2VV.Utilities.Studies import condObsDist
from ROOT import TRandom3
randGen = TRandom3(args.jobID)
for evObs in dataSet :
    # get values of observables
    massPdfObs.assignValueOnly(evObs)
    dataObs.assignValueOnly(evObs)
    stateName = splitCat.getLabel()
    if not genMass : sigWeight.setVal( dataSet.weight() )

    # get PDF values
    pdfVals = dict( [ ( comp, yields[comp]['total'] * ( 1. if genMass else pdfs[comp][stateName].getVal() ) ) for comp in comps ] )
    for varList in condObs.itervalues() :
        valList = [ getObsVal( condObsVars[var], evObs ) for var in varList ]
        for comp in comps :
            pdfVals[comp] *= condObsDist( varList, valList, comp )

    # decide if event is signal or background
    totVal = sum( pdfVals.itervalues() )
    addVal = 0.
    genVal = randGen.Rndm()
    for comp in comps :
开发者ID:GerhardRaven,项目名称:P2VV,代码行数:33,代码来源:splitDataSetSigBkg.py


注:本文中的ROOT.RooArgSet.assignValueOnly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。