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


Python ROOT.RooDataSet类代码示例

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


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

示例1: get_dataset

def get_dataset(varargset, ftree, cut="", wt="", scale=1):
    """Return a dataset.

    Return a dataset from the ntuple `ftree'. Apply a selection cut
    using the `cutVar' variable and the selection `cut'.

    """

    from rplot.fixes import ROOT
    from rplot.tselect import Tsplice

    splice = Tsplice(ftree)
    splice.make_splice("sel", cut)
    from ROOT import RooDataSet, RooFit, RooFormulaVar, RooArgList

    tmpdst = RooDataSet("tmpdataset", "", varargset, RooFit.Import(ftree))
    if wt:
        wtvar = RooFormulaVar("wt", "{}*@0".format(scale), RooArgList(varargset[wt]))
        wtvar = tmpdst.addColumn(wtvar)
        varargset.remove(varargset[wt])
        varargset.add(wtvar)
        dst = RooDataSet("dataset", "Dataset", varargset, RooFit.Import(tmpdst), RooFit.WeightVar(wtvar))
        varargset.remove(wtvar)
        dst = dst.reduce(varargset)
    return dst
开发者ID:suvayu,项目名称:Bs2DsKTools,代码行数:25,代码来源:factory.py

示例2: fillDataSet

def fillDataSet(data, x, N, dsName = 'ds'):
    cols = RooArgSet(x)
    ds = RooDataSet(dsName, dsName, cols)
    #ds.Print()
    print 'length data:', N
    for datum in range(0,N):
        if (data[datum] < x.getMax()) and (data[datum] > x.getMin()):
            x.setVal(data[datum])
            ds.add(cols)
    ds.Print()
    return ds
开发者ID:mendezdpatricia,项目名称:usercode,代码行数:11,代码来源:pedRoutines.py

示例3: main

def main() :
    inputfile_name = "/data1/chibdata/collision/v2/2012_AllData_v2.root"

    chibTree_name = "rootuple/chibTree"
    print "Opening file"
    inputfile = TFile.Open(inputfile_name,"READ")
    print "Importing tree"
    tree = TTree()
    inputfile.GetObject(chibTree_name, tree)

    invm1S = RooRealVar("invm1S", "invm1S", 9.5, 11.5)
    invm2S = RooRealVar("invm2S", "invm2S", 9.5, 20.0)
    invm3S = RooRealVar("invm3S", "invm3S", 9.5, 20.0)
    dimuon_mass = RooRealVar("dimuon_mass","dimuon_mass", 8.0, 12.0)
    dimuon_rapidity = RooRealVar("dimuon_rapidity", "dimuon_rapidity", -5.0, 5.0)
    dimuon_pt = RooRealVar("dimuon_pt","dimuon_pt", 0.0, 100.0)
    photon_eta = RooRealVar("photon_eta","photon_eta", -5.0, 5.0)
    photon_pt = RooRealVar("photon_pt","photon_pt", 0.0, 100.0)
    ctpv = RooRealVar("ctpv","ctpv", -5.0, 5.0)
    ctpv_error = RooRealVar("ctpv_err","ctpv_err", -5.0, 5.0)
    pi0_abs_mass = RooRealVar("pi0_abs_mass","pi0_abs_mass", 0.0, 2.0)
    Y1S_nsigma = RooRealVar("Y1S_nsigma","Y1S_nsigma",0.0,30.0)
    Y2S_nsigma = RooRealVar("Y2S_nsigma","Y2S_nsigma",0.0,30.0)
    Y3S_nsigma = RooRealVar("Y3S_nsigma","Y3S_nsigma",0.0,35.0)
    conv_vertex = RooRealVar("conv_vertex", "conv_vertex", 0.0, 70.0)
    dz = RooRealVar("dz","dz", -50.0, 50.0)


    print "Assigning argset"
    dataArgSet = RooArgSet(invm1S, invm2S, invm3S, dimuon_mass, dimuon_rapidity, dimuon_pt, photon_eta, photon_pt, ctpv)
    dataArgSet.add( ctpv_error )
    dataArgSet.add( pi0_abs_mass )
    dataArgSet.add( Y1S_nsigma )
    dataArgSet.add( Y2S_nsigma )
    dataArgSet.add( Y3S_nsigma )
    dataArgSet.add( conv_vertex )
    dataArgSet.add( dz )

    print "Creating DataSet"
    dataSet = RooDataSet("chibds","Chib RooDataSet", tree, dataArgSet)


    # Selection
    cuts = "photon_pt > 0.0" +                   \
           "&&dimuon_pt > 9.5"                   \
           "&& abs(photon_eta) < 1.4" +          \
           "&& abs(dimuon_rapidity) < 1.25 " +   \
           "&& Y3S_nsigma < 2.5 " +              \
           "&& abs(dz) < 0.1"

    rds_cutted = dataSet.reduce( RooFit.Cut(cuts) )

    dofit(rds_cutted, "Chib_fit_2012_3S")
开发者ID:argiro,项目名称:usercode,代码行数:53,代码来源:chibFit3S.py

示例4: __init__

class MLFit :
  def __init__(self, plot_dire, condition):
    self.plot_dire = plot_dire
    self.condition = condition
    self.mjj = RooRealVar("ZJJMass", "ZJJMass", 50., 7000.)
    #self.costhetastar = RooRealVar("costhetastar", "costhetastar", -1., 1.)
    self.weight = RooRealVar("weight", "weight", -100., 100.)
    self.isSignal = RooCategory("isSignal", "isSignal")
    self.isSignal.defineType("signal", 1);
    self.isSignal.defineType("background", 0);
    self.ras = RooArgSet(self.mjj, self.weight)
    self.ds = RooDataSet("ds"+condition, "ds"+condition, self.ras, "weight")
    
    #self.mu = RooRealVar("mu", "mu", 90., 80., 100.)
    #self.widthL = RooRealVar("widthL", "widthL", 15., 2., 30.)
    #self.widthR = RooRealVar("widthR", "widthR", 4., 2., 15.)
    #self.sigmass = RooBifurGauss("bifurgauss", "bifurgauss", self.mjj, self.mu, self.widthL, self.widthR)

    self.c0 = RooRealVar("c0", "c0", -100., 100.)
    self.bkgmass = RooExponential("expo", "expo", self.mjj, self.c0)

    #self.nsig = RooRealVar("nsig", "nsig", 100, 0, 200)
    #self.nbkg = RooRealVar("nbkg", "nbkg", 100, 0, 200)
  
    #self.components = RooArgList(self.sigmass, self.bkgmass)
    #self.coefficients = RooArgList(self.nsig, self.nbkg)

    self.modelmass = self.bkgmass #RooAddPdf("massmodel", "massmodel", self.components, self.coefficients)



  
  def addToDataset(self, event, isSignal):
    if not eval(self.condition):
      return
    self.mjj = event.ZJJMass
    print self.mjj
    #self.costhetastar = event.costhetastar
    self.weight = event.weight
    #self.isSignal = isSignal
    self.ds.fill()


  def fit(self):
    print "nentries", self.ds.numEntries()
    #for i in range(self.ds.numEntries()):
    #  argset = self.ds.get(i)
    #  argset.Dump()
    
    fitresult = self.modelmass.fitTo(self.ds, RooFit.Save(True), RooFit.Extended(), RooFit.PrintLevel(3), RooFit.Strategy(2)) #, RooFit.SumW2Error(True))
开发者ID:lenzip,项目名称:UserCode-PyHLLJJHighMass,代码行数:50,代码来源:fit.py

示例5: File2Dataset

    def File2Dataset(self, fnames, dsName, ws, noCuts = False, 
                     weighted = False, CPweight = False, cutOverride = None,
                     interference = 0, additionalWgt = 1.0):
        if ws.data(dsName):
            return ws.data(dsName)

        cols = RooArgSet(ws.set('obsSet'))
        # print 'interference weight flag:',interference
        if (weighted):
            evtWgt = RooRealVar('evtWgt', 'evtWgt', 1.0)
            cols.add(evtWgt)
            ds = RooDataSet(dsName, dsName, cols, 'evtWgt')
            print 'including weights for eff',
            if CPweight:
                print 'and CP weight',
            if interference in [1,2,3]:
                print 'and interference',
            print
        else:
            ds = RooDataSet(dsName, dsName, cols)
            
        if not (type(fnames) == type([])):
            fnames = [fnames]

        try:
            obs = [ self.pars.varNames[x] for x in self.pars.var ]
        except AttributeError:
            obs = self.pars.var

        for fname in fnames:
            for (row, effWgt, cpw, iwt) in \
                    self.TreeLoopFromFile(fname, noCuts,
                                          CPweight = CPweight,
                                          cutOverride = cutOverride,
                                          interference = interference):
                inRange = True
                for (i,v) in enumerate(obs):
                    inRange = (inRange and ws.var(v).inRange(row[i], ''))
                    cols.setRealValue(v, row[i])
                if CPweight:
                    effWgt *= cpw
                if interference in [1,2,3]:
                    effWgt *= iwt
                if inRange:
                    ds.add(cols, effWgt*additionalWgt)

        getattr(ws, 'import')(ds)

        return ws.data(dsName)
开发者ID:kalanand,项目名称:VPlusJets,代码行数:49,代码来源:RooWjj2DFitterUtils.py

示例6: roofit_poisson_unbinned

def roofit_poisson_unbinned(data):
    """returns lambda, error of lambda"""

    x = RooRealVar('x', 'x', 0, max(data) * 10)
    lam = RooRealVar('lambda', 'lambda', 0.1, 0.000001, max(data))

    model = RooPoisson('model', 'model', x, lam)

    dataset = RooDataSet('data', 'data', RooArgSet(x))
    for val in data:
        x.setVal(val)
        dataset.add(RooArgSet(x))

    model.fitTo(dataset, RooFit.Save(), RooFit.PrintLevel(-1))
    return lam.getVal(), lam.getError()
开发者ID:mokapharr,项目名称:diploma-thesis-code,代码行数:15,代码来源:roofit_poissons.py

示例7: get_dataset

def get_dataset(varargset, ftree, cut='', cutVars=[], *cmdArgs):
    """Return a dataset.

    Return a dataset from the ntuple `ftree'. Apply a selection cut
    using the `cutVar' variable and the selection `cut'.

    """

    varargsetclone = varargset.clone('varargsetclone')
    for cvar in cutVars:
        varargsetclone.add(cvar) # Add selVar to apply cut

    tmpdataset = RooDataSet('dataset', 'Dataset', varargsetclone,
                            RooFit.Import(ftree), RooFit.Cut(cut), *cmdArgs)
    dataset = tmpdataset.reduce(varargset)
    del tmpdataset
    return dataset
开发者ID:lbel,项目名称:Bs2DsKTools,代码行数:17,代码来源:factory.py

示例8: get_dataset_from_tree

    def get_dataset_from_tree(
        self,
        path_to_tree,
        tree_variables,
        weight="1==1",
        weight_var_name=0,
        dataset_name="my_dataset",
        basket=True,
        category=None,
    ):
        """
        Creates RooDataSet from a plain root tree given:
        - variables name list
        - weight expression. It works in the same way as TTree cut.

        Returns:
        --------
        - RooDataSet
        - also fills the basket with datasets (basket inhereted from RootHelperBase class)

        TODO
        ----
        - add implementation for category setting(check in prepare_toy_datasets_for_sync)
            - check if adding toy dataset to each channel workspace individually behaves well
              after combineCards.py.
        """

        # make RooRealVars from tree_variables
        my_arg_set = RooArgSet()
        my_rrv = dict()
        for var_name in tree_variables:
            # TODO implement check that branch exist
            my_rrv[var_name] = RooRealVar(var_name, var_name, -999999999, 999999999)
            my_arg_set.add(my_rrv[var_name])
        if self.DEBUG:
            self.log.debug("RooArgSet is now:")
            my_arg_set.Print()

        # get the tree from path_to_tree
        my_tree = self.get_TTree(path_to_tree, cut=weight)
        self.log.debug("Selected tree contains {0} events".format(my_tree.GetEntries()))
        # create RooDataSet and reduce tree if needed
        # self.dataset_from_tree =  RooDataSet(dataset_name, dataset_name, my_tree, my_arg_set, weight).reduce(my_arg_set)
        self.dataset_from_tree = RooDataSet(dataset_name, dataset_name, my_tree, my_arg_set)
        # self.dataset_from_tree =  RooDataSet(dataset_name, dataset_name, my_tree, my_arg_set, "", weight_var_name)
        # data[j]=new RooDataSet(Form("data%d",j),Form("data%d",j),outTree,RooArgSet(rCMS_zz4l_widthKD,rCMS_zz4l_widthMass,rweightFit),"","_weight_");
        self.log.debug("RooDataSet contains {0} events".format(self.dataset_from_tree.sumEntries()))
        # .reduce(ROOT.RooArgSet(self.D0))
        self.current_arg_set = my_arg_set

        # add dataset to basket
        if basket:
            self.add_to_basket(self.dataset_from_tree, new_name=dataset_name, new_title=dataset_name)

        return self.dataset_from_tree
开发者ID:HZZ4l,项目名称:Datacards13TeV,代码行数:55,代码来源:ToyDataSetManager.py

示例9: fill_dataset

def fill_dataset(varargset, ftree, wt, wtvar, cut=""):
    """Return a dataset (slow, get_dataset is more efficient).

    Return a dataset from the ntuple `ftree', also apply `cut'.  Use
    `wt' as the weight expression in the tree.  `wtvar' is the
    corresponding RooRealVar weight.  Note, varargset should contain
    wtvar.

    The dataset is filled by iterating over the tree.  This is needed
    when you want to ensure different datasets have the same weight
    variable names, so that they can be combined later on.  This is
    needed even if they are combined as different categories.

    """

    from rplot.fixes import ROOT
    from ROOT import RooDataSet, RooFit, TTreeFormula
    from helpers import suppress_warnings

    suppress_warnings()
    from rplot.tselect import Tsplice

    splice = Tsplice(ftree)
    splice.make_splice("sel", cut)

    formulae = {}
    wtname = wtvar.GetName()
    for var in varargset:
        name = var.GetName()
        expr = wt if name == wtname else name
        formulae[name] = TTreeFormula(name, expr, ftree)

    dataset = RooDataSet("dataset", "Dataset", varargset, RooFit.WeightVar(wtvar))
    for i in xrange(ftree.GetEntries()):
        ftree.GetEntry(i)
        for var, expr in formulae.iteritems():
            realvar = varargset.find(var)
            realvar.setVal(expr.EvalInstance())
        dataset.add(varargset, varargset[wtname].getVal())
    return dataset
开发者ID:suvayu,项目名称:Bs2DsKTools,代码行数:40,代码来源:factory.py

示例10: addAsciiData

    def addAsciiData(self, ws, ds_name, item_title, var_set_name, var_set_type, ds_file_name, weight_var_name = None, debug = 0, sets = None):
        legend = '[exostConfig::addAsciiData]:'
        
        arg_set = RooArgSet()
        if (var_set_type == 'set'):
            #_var_set = ws.set(var_set_name)
            _var_set = sets[var_set_name]
            arg_set.add(_var_set)

            if _var_set.getSize() != 1:
                print legend, 'Error: too many or too few columns in the input ASCII file'
                print legend, 'Error: Smart program as I am, I can only handle ASCII files'
                print legend, 'Error: with exactly one column at the moment.'
                print legend, 'Error: Support for multiple columns will be implemented'
                print legend, 'Error: eventually, contact the developers.'
                print legend, 'Error: Better yet, switch to ROOT input files,'
                print legend, 'Error: all the cool kids are doing that!'

                return -1
            
        elif (var_set_type == 'var'):
            arg_set.add(ws.var(var_set_name))
        else:
            print legend, 'error: unknown var_set_type, cannot create dataset', ds_name
            return -1

        #create the dataset
        if weight_var_name == None: #no weight
            if (debug>0):
                print legend, 'no weight variable given'

            _arglist = RooArgList(arg_set)
            #ds = RooDataSet()ds_name, item_title)
            ds = RooDataSet.read(ds_file_name, _arglist)
            ds.SetName(ds_name)
            ds.SetTitle(item_title)
        else:
            if (debug>0):
                print legend, 'using variable', weight_var_name, 'as weight'
        
                print legend, 'Error: Smart program as I am, I cannot handle'
                print legend, 'Error: weights when loading from ASCII files yet.'
                print legend, 'Error: Support for weights from ASCII files will'
                print legend, 'Error: be implemented eventually, contact the developers.'
                print legend, 'Error: Better yet, switch to ROOT input files,'
                print legend, 'Error: all the cool kids are doing that!'

                return -1


        # import the datahist. Note workaround 'import' being a reserved word
        getattr(ws, 'import')(ds)
开发者ID:ajaykumar649,项目名称:exo-diphoton-limits,代码行数:52,代码来源:exostConfig.py

示例11: dump_simple

def dump_simple():
    # try poisson
    roo_lam = RooRealVar("lambda", ".", lam, 0.0, 1.5)
    roo_x = RooRealVar('x', 'x range', 0, bins)

    model = RooPoisson("poisson", "Poisson Model", roo_x, roo_lam)

    #data = model.generate(RooArgSet(roo_x), n_events)

    data = RooDataSet('data', 'Data', RooArgSet(roo_x))
    for val in unbinned_from_binned(xdata, ydata):
        roo_x.setVal(val)
        data.add(RooArgSet(roo_x))

    #// --- Perform extended ML fit of composite PDF to toy data ---
    fitresult = model.fitTo(data, RooFit.Save(), RooFit.PrintLevel(-1)) ;

    #// --- Plot toy data and composite PDF overlaid ---
    mesframe = roo_x.frame(bins) ;
    data.plotOn(mesframe) ;
    model.plotOn(mesframe) ;
    mesframe.Draw()
开发者ID:mokapharr,项目名称:diploma-thesis-code,代码行数:22,代码来源:roofit_simple.py

示例12: RooCategory

    dataset.SetNameTitle(name_title, name_title)
    print '%s is weighted: %s' % (dataset.GetName(), dataset.isWeighted())
    dsetlist += [dataset]

decaycat = RooCategory('decaycat', 'Decay mode category')
decaycat.defineType('DsPi')
decaycat.defineType('DsK')

varlist += [decaycat]

for idx, mode in enumerate(['DsPi', 'DsK']):
    decaycat.setLabel(mode)
    dsetlist[idx].addColumn(decaycat)

dataset = RooDataSet('dataset', 'Combined dataset (DsK + DsPi)',
                     RooArgSet(time, decaycat),
                     RooFit.Import(dsetlist[0]))
dataset.append(dsetlist[1])

for dset in dsetlist:
    dset.Print()
dataset.Print()

## Basic B decay pdf with time resolution
# Resolution model
mean = RooRealVar('mean', 'Mean', 0.)
# scale = RooRealVar('scale', 'Per-event time error scale factor', 1.19)
resmodel = RooGaussModel('resmodel', 'Time resolution model', time,
                         mean, RooRealConstant.value(0.044),
                         RooRealConstant.value(1.0),
                         RooRealConstant.value(1.0))
开发者ID:suvayu,项目名称:Bs2DsKTools,代码行数:31,代码来源:ltFit.py

示例13: RooRealVar

# DAS_EX_2.1
# Define a RooRealVar object for the ST variable
st = RooRealVar("st", "st", ranges["fit","lo"], ranges["fit","hi"])


############################################
# Get data and models
############################################

# 
print "Reading Files"
# DAS_EX_2.2
# Read data from file into RooDataSet using the RooDataSet.read() method.
#rdata = RooDataSet.add(files["dat"], RooArgList(st))
rdata = RooDataSet.read(files["dat"], RooArgList(st))

###################################
# Set up fit PDFs with information
# from fitFuncs dictionary
###################################

# Declare a few dictionaries
pdfs = {}; pars = {}; aset = {}

for func in ["f2", "f1", "f3"]:

    # DAS_EX_2.3
    # Define and initialize (with your ST RooRealVar) a RooArgSet for use in the pdf
    # We need one RooArgSet for each function, so store in python dictionary indexed
    # by "func" string:
开发者ID:TENorbert,项目名称:SUSY-TOOLS,代码行数:30,代码来源:bkgfit_das.py

示例14: makeRooDataSet

def makeRooDataSet(type,infile_name,outfile_name,tree_name,nevents):
    """ Make RooDataSets from TTrees"""




    inputfile = TFile.Open(infile_name,"READ")
    print "Importing tree"
    tree = TTree()
    inputfile.GetObject(tree_name, tree)  #get the tree from the data file

   

    #define variables for the RooDataSet
    m_mumu        = RooRealVar("m_mumu",   "m_mumu",   0.0, 4.0)
    y_mumu        = RooRealVar("y_mumu",   "y_mumu",   0.0, 2.0 )
    pt_mumu       = RooRealVar("pt_mumu",  "pt_mumu",  0.0, 260.0)
    eta_gamma     = RooRealVar("eta_gamma","eta_gamma",-3.5, 3.5)
    pt_gamma      = RooRealVar("pt_gamma", "pt_gamma", 0.0, 100.0)
    m_gamma       = RooRealVar("m_gamma",  "m_gamma",  -0.1,0.1)
  
    m_chi_rf1S    = RooRealVar("m_chi_rf1S", "m_chi_rf1S", 0.0, 7.0)
    m_chi_rf2S    = RooRealVar("m_chi_rf2S", "m_chi_rf2S", -1.0, 1.0)
    Qvalue        = RooRealVar("Qvalue","Q", -15., 15.) 

    ctpv          = RooRealVar("ctpv","ctpv", -1.0, 3.5)
    ctpv_error    = RooRealVar("ctpv_err","ctpv_err", -1.0, 1.0)
    pi0_abs_mass  = RooRealVar("pi0_abs_mass","pi0_abs_mass", 0.0, 2.2)
    psi1S_nsigma  = RooRealVar("psi1S_nsigma","psi1S_nsigma",0.0,1.0)
    psi2S_nsigma  = RooRealVar("psi2S_nsigma","psi2S_nsigma",0.0,1.0)
    psi3S_nsigma  = RooRealVar("psi3S_nsigma","psi3S_nsigma",0.0,1.0)
    rho_conv      = RooRealVar("rho_conv", "rho_conv", 0.0, 70.0)
    dz            = RooRealVar("dz","dz", -1.0, 1.0)

    probFit1S     = RooRealVar('probFit1S','probFit1S',0,1)
    probFit2S     = RooRealVar('probFit2S','probFit2S',0,1)
    probFit3S     = RooRealVar('probFit3S','probFit3S',0,1)

    dataArgSet = RooArgSet(m_mumu,
                           y_mumu,
                           pt_mumu,
                           eta_gamma,
                           pt_gamma,
                           m_gamma, 
                           m_chi_rf1S)
    
    dataArgSet.add( m_chi_rf2S )
    dataArgSet.add( Qvalue )
    dataArgSet.add( ctpv )
    dataArgSet.add( ctpv_error )
    dataArgSet.add( pi0_abs_mass )
    dataArgSet.add( psi1S_nsigma )
    dataArgSet.add( psi2S_nsigma )
    dataArgSet.add( psi3S_nsigma )
    dataArgSet.add( rho_conv )
    dataArgSet.add( dz )
    dataArgSet.add( probFit1S)
    dataArgSet.add( probFit2S)
    dataArgSet.add( probFit3S)

 

    print "Creating DataSet"
    dataSet = RooDataSet("chicds","Chic RooDataSet", dataArgSet)

    entries = tree.GetEntries()
    print entries

    if nevents is not 0:
        entries = nevents

    for ientry in range(0,entries):
        tree.GetEntry(ientry)

        # unfort ntuples are slightly different for chic and chib

        if applyscale:
            
            if usekinfit :    
                spatial = tree.rf3S_photon_p4.Vect()
                #spatial = tree.photon_p4.Vect()
                spatial *= (1/escale)
                corr_photon_p4=TLorentzVector()
                #corr_photon_p4.SetVectM(spatial,tree.rf1S_photon_p4.M())
                corr_photon_p4.SetVectM(spatial,0)
                corr_chi_p4 = tree.rf3S_dimuon_p4 + corr_photon_p4

            else:
                        
                spatial = tree.photon_p4.Vect()
                spatial *= (1/escale)
                corr_photon_p4=TLorentzVector()
                corr_photon_p4.SetVectM(spatial,tree.photon_p4.M())
                corr_chi_p4 = tree.dimuon_p4 + corr_photon_p4
                
            
        else :
            corr_chi_p4 = tree.chi_p4
        
        if type == 'chic':
#.........这里部分代码省略.........
开发者ID:argiro,项目名称:usercode,代码行数:101,代码来源:makeRooDataSet3SVaryScale.py

示例15: run

    def run(self, **kwargs):
        from ROOT import RooArgSet

        __check_req_kw__("Observables", kwargs)
        __check_req_kw__("Pdf", kwargs)
        __check_req_kw__("Sigmat", kwargs)
        __check_req_kw__("Time", kwargs)
        __check_req_kw__("SigmaGen", kwargs)
        sigma_gen = kwargs.pop("SigmaGen")
        observables = kwargs.pop("Observables")
        obs_set = RooArgSet(*observables)

        pdf = kwargs.pop("Pdf")
        sigmat = kwargs.pop("Sigmat")
        time = kwargs.pop("Time")

        gen_obs_set = RooArgSet(*observables)

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

        from P2VV.RooFitWrappers import RealVar

        da = RealVar("da", Observable=True, MinMax=(0.01, 1.1))
        dft = RealVar("dft", Observable=True, MinMax=(0.01, 1.1))
        result_params.add(da._target_())
        result_params.add(dft._target_())

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

        # Some extra numbers of interest
        from ROOT import RooRealVar

        seed = RooRealVar("seed", "random seed", 0.0)
        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

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

        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)

            data = pdf.generate(spec)
            if self.transform():
                old_data = data
                data = self.transform()(old_data)
                if not data:
                    transform.set_params(data_params)
                    self._data.add(data_params)
                    continue

            from P2VV import Dilution

            d_ft = Dilution.dilution_ft(data, time, t_range=2, quiet=True)
            d_a = Dilution.signal_dilution_dg(data, sigmat, *sigma_gen)
            da.setVal(d_a[0])
            da.setError(d_a[1] if d_a[1] != None else 0.0)
            dft.setVal(d_ft[0])
            dft.setError(d_ft[1] if d_ft[1] != None else 0.0)

            if transform:
                transform.set_params(data_params)

            self._data.add(result_params)

        return self.data()
开发者ID:GerhardRaven,项目名称:P2VV,代码行数:86,代码来源:ToyMCUtils.py


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