本文整理汇总了Python中ROOT.RooArgSet.find方法的典型用法代码示例。如果您正苦于以下问题:Python RooArgSet.find方法的具体用法?Python RooArgSet.find怎么用?Python RooArgSet.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ROOT.RooArgSet
的用法示例。
在下文中一共展示了RooArgSet.find方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RooArgSet
# 需要导入模块: from ROOT import RooArgSet [as 别名]
# 或者: from ROOT.RooArgSet import find [as 别名]
removeVars = [ 'tagCatP2VV' ]
selection = 'hlt2_biased==1'
numDataSets = 40
weightName = ''
import P2VV.RooFitWrappers
from ROOT import TFile, RooArgSet
protoFile = TFile.Open(protoFilePathIn)
nTupleFileIn = TFile.Open(nTupleFilePathIn)
protoData = protoFile.Get('JpsiKK_sigSWeight')
nTupleIn = nTupleFileIn.Get('DecayTree')
from ROOT import RooRealVar, RooCategory
obsSet = RooArgSet( protoData.get() )
if runPeriods :
rp = obsSet.find('runPeriod')
if rp : obsSet.remove(rp)
rp = RooCategory( 'runPeriod', 'runPeriod' )
for per in runPeriods : rp.defineType( 'p%d' % per, per )
obsSet.add(rp)
if KKMassBins :
KKCat = obsSet.find('KKMassCat')
if KKCat : obsSet.remove(KKCat)
KKCat = RooCategory( 'KKMassCat', 'KKMassCat' )
for ind in range( len(KKMassBins) - 1 ) : KKCat.defineType( 'bin%d' % ind, ind )
obsSet.add(KKCat)
from array import array
KKBinsArray = array( 'd', KKMassBins )
from ROOT import RooBinning
示例2: RooArgSet
# 需要导入模块: from ROOT import RooArgSet [as 别名]
# 或者: from ROOT.RooArgSet import find [as 别名]
dataNames = [ 'JpsiKK', 'JpsiKK_sigSWeight', 'JpsiKK_cbkgSWeight' ]
cut = 'hlt2_biased==1'
removeObs = [ 'wMC', 'mdau1', 'tagCatP2VV' ] #, 'polarity', 'hlt2_prescale', 'nPVCat', 'BpTCat' ]
dataFilePathIn = 'P2VVDataSets20112012Reco14_I2Mass_6KKMassBins_4TagCats.root'
dataFilePathOut = 'P2VVDataSets20112012Reco14_I2Mass_6KKMassBins_4TagCats_HLT2B.root'
import P2VV.RooFitWrappers
from ROOT import TObject, TFile, RooFit, RooDataSet, RooArgSet
dataFile = TFile.Open(dataFilePathIn)
newDataFile = TFile.Open( dataFilePathOut, 'RECREATE' )
newData = [ ]
print 'read datasets from file "%s"' % dataFile.GetName()
for dataName in dataNames :
print 'reading dataset "%s"' % dataName
data = dataFile.Get(dataName)
data.Print()
newArgSet = RooArgSet( data.get() )
for name in removeObs : newArgSet.remove( newArgSet.find(name) )
newData.append( RooDataSet( dataName, dataName, newArgSet, RooFit.Import(data), RooFit.Cut(cut) ) )
newData[-1].Print()
newDataFile.Add( newData[-1] )
print 'write dataset to file "%s"' % newDataFile.GetName()
newDataFile.Write( dataFilePathOut, TObject.kOverwrite )
示例3: enumerate
# 需要导入模块: from ROOT import RooArgSet [as 别名]
# 或者: from ROOT.RooArgSet import find [as 别名]
# create data sets with final columns
obsSetMain = obsSetNTuple + [ var for var in weightVars ]
mainDataSet = dataTree.buildDataSet( Observables = obsSetMain, Name = 'JpsiKK', Title = 'JpsiKK', IndexName = 'index'
, OrigDataSet = preSDataSet )
del preSDataSet
del preDataSet
dataTreeFile.Close()
from ROOT import gROOT
gROOT.cd('PyROOT:/')
from ROOT import RooArgSet, RooDataSet
dataSets = { }
for it, var in enumerate(weightVars) :
argSet = RooArgSet( mainDataSet.get() )
for remVar in weightVars :
if remVar != var : argSet.remove( argSet.find( remVar.GetName() ) )
dataName = dataSetNameOut if it == 0 else 'JpsiKK_%d' % it
dataSets[var] = RooDataSet( dataName, dataName, argSet, Import = mainDataSet, WeightVar = ( var.GetName(), True ) )
if not printYields : break
print 'P2VV - INFO: createBs2JpsiKKDataSet: produced data sets:'
mainDataSet.Print()
for var in weightVars :
dataSets[var].Print()
if not printYields : break
print
if printYields :
# print event yields
print 'P2VV - INFO: createBs2JpsiKKDataSet: event yields:'
allCats = [ mainDataSet.get().find( obsDict['runPeriod'][0] )
示例4: dict
# 需要导入模块: from ROOT import RooArgSet [as 别名]
# 或者: from ROOT.RooArgSet import find [as 别名]
dataSets.pop('preS')
dataTreeFile.Close()
from ROOT import gROOT
gROOT.cd('PyROOT:/')
print 'P2VV - INFO: createB2CCFitNTuple: produced data set:\n' + ' ' * 13,
dataSets['main'][0].Print()
print
# create weighted data sets
from ROOT import RooArgSet
obsSets = dict( [ ( var.GetName(), RooArgSet( dataSets['main'][0].get() ) ) for var in weightVars ] )
for varName, obsSet in obsSets.iteritems() :
for var in weightVars :
if var.GetName() == varName : continue
obsSet.remove( obsSet.find( var.GetName() ) )
from ROOT import RooDataSet
dataSets['sigSWeight'] = ( RooDataSet( 'JpsiKK_sigSWeight', 'JpsiKK_sigSWeight', obsSets['N_sigMass_sw']
, Import = dataSets['main'][0], WeightVar = ( weightVars[0].GetName(), True ) ), [ ] )
dataSets['cbkgSWeight'] = ( RooDataSet( 'JpsiKK_cbkgSWeight', 'JpsiKK_cbkgSWeight', obsSets['N_cbkgMass_sw']
, Import = dataSets['main'][0], WeightVar = ( weightVars[1].GetName(), True ) ), [ ] )
for sample, data in zip( samples, dataSets['main'][1] ) :
dataSets['sigSWeight'][1].append( RooDataSet( 'JpsiKK_sigSWeight_' + sample[0], 'JpsiKK_sigSWeight', obsSets['N_sigMass_sw']
, Import = data, WeightVar = ( weightVars[0].GetName(), True ) ) )
dataSets['cbkgSWeight'][1].append( RooDataSet( 'JpsiKK_cbkgSWeight_' + sample[0], 'JpsiKK_cbkgSWeight', obsSets['N_cbkgMass_sw']
, Import = data, WeightVar = ( weightVars[1].GetName(), True ) ) )
print 'P2VV - INFO: createB2CCFitNTuple: signal data set:\n' + ' ' * 13,
dataSets['sigSWeight'][0].Print()
print
示例5: RooArgSet
# 需要导入模块: from ROOT import RooArgSet [as 别名]
# 或者: from ROOT.RooArgSet import find [as 别名]
dataNames = [ 'JpsiKK_sigSWeight' ] #[ 'JpsiKK', 'JpsiKK_sigSWeight', 'JpsiKK_cbkgSWeight' ]
removeObs = [ 'wMC', 'mdau1', 'tagCatP2VV' ] #, 'polarity', 'hlt2_prescale', 'nPVCat', 'BpTCat' ]
dataFilePathIn = 'P2VVDataSets20112012Reco14_I2Mass_6KKMassBins_2TagCats_20140309.root'
dataFilePathOut = 'P2VVDataSets2012Reco14_I2Mass_6KKMassBins_2TagCats_20140309.root'
import P2VV.RooFitWrappers
from ROOT import TObject, TFile, RooFit, RooDataSet, RooArgSet, RooCategory
dataFile = TFile.Open(dataFilePathIn)
newDataFile = TFile.Open( dataFilePathOut, 'RECREATE' )
newData = [ ]
print 'read datasets from file "%s"' % dataFile.GetName()
for dataName in dataNames :
print 'reading dataset "%s"' % dataName
data = dataFile.Get(dataName)
data.Print()
newArgSet = RooArgSet( data.get() )
for name in removeObs : newArgSet.remove( newArgSet.find(name) )
if runPeriod :
newArgSet.remove( newArgSet.find('runPeriod') )
rp = RooCategory( 'runPeriod', 'runPeriod' )
rp.defineType( 'p%d' % runPeriod, runPeriod )
newArgSet.add(rp)
newData.append( RooDataSet( dataName, dataName, newArgSet, RooFit.Import(data), RooFit.Cut(cut) ) )
newData[-1].Print()
newDataFile.Add( newData[-1] )
print 'write dataset to file "%s"' % newDataFile.GetName()
newDataFile.Write( dataFilePathOut, TObject.kOverwrite )
示例6: RooObject
# 需要导入模块: from ROOT import RooArgSet [as 别名]
# 或者: from ROOT.RooArgSet import find [as 别名]
# workspace
from P2VV.RooFitWrappers import RooObject
ws = RooObject( workspace = 'JpsiphiWorkspace' ).ws()
# read data set with events in two asymmetry categories
print 'pdfAsymmetry: reading dataset with events in two asymmetry categories'
from ROOT import TFile
dataFile = TFile.Open(dataSetFilePath)
dataSetAsym = dataFile.Get('asymData')
dataFile.Close()
dataSetAsym.Print()
# create weighted data set
from ROOT import RooProduct, RooArgSet, RooArgList
obsSet = RooArgSet( dataSetAsym.get() )
prodList = RooArgList( obsSet.find('sigWeight') )
if applyPlotWeights : prodList.add( obsSet.find('dilution') )
weightVar = RooProduct( 'weightVar', 'weightVar', prodList )
weightVar = dataSetAsym.addColumn(weightVar)
obsSet.add(weightVar)
from ROOT import RooDataSet
dataSetAsymW = RooDataSet( 'asymDataW', 'asymDataW', obsSet, Import = dataSetAsym, WeightVar = ( 'weightVar', True ) )
del dataSetAsym
ws.put(dataSetAsymW)
del dataSetAsymW
dataSetAsymW = ws['asymDataW']
obsSet = RooArgSet( dataSetAsymW.get() )
dataSetAsymW.Print()
# build PDF
示例7: RooArgSet
# 需要导入模块: from ROOT import RooArgSet [as 别名]
# 或者: from ROOT.RooArgSet import find [as 别名]
dataFile.Write( dataSetFileOut, TObject.kOverwrite )
dataFile.Close()
else :
# read data set with events in two asymmetry categories
print 'plotAsymmetry: reading dataset with events in two asymmetry categories'
dataFile = TFile.Open(dataSetFileOut)
dataSetAsym = dataFile.Get('asymData')
dataFile.Close()
dataSetAsym.Print()
# create weighted data set
from ROOT import RooProduct, RooArgSet, RooArgList
obsSet = RooArgSet( dataSetAsym.get() )
prodList = RooArgList( obsSet.find('sigWeight') )
if applyDilWeights : prodList.add( obsSet.find('dilution') )
if applyAngWeights : prodList.add( obsSet.find( 'angWeight_%s' % applyAngWeights ) )
weightVar = RooProduct( 'weightVar', 'weightVar', prodList )
weightVar = dataSetAsym.addColumn(weightVar)
obsSet.add(weightVar)
dataSetAsymW = RooDataSet( 'asymDataW', 'asymDataW', obsSet, Import = dataSetAsym, WeightVar = ( 'weightVar', True ) )
del dataSetAsym
ws.put(dataSetAsymW)
del dataSetAsymW
dataSetAsymW = ws['asymDataW']
obsSet = RooArgSet( dataSetAsymW.get() )
dataSetAsymW.Print()
# get sums of weights
示例8: sum
# 需要导入模块: from ROOT import RooArgSet [as 别名]
# 或者: from ROOT.RooArgSet import find [as 别名]
pdfs['cbkg'][stateName] = simMassPdf.getPdf(stateName).pdfList().at(1)
else :
pdfs['sig'][stateName] = simMassPdf.getPdf(stateName).pdfList().at(0).createIntegral( intSet, normSet )
pdfs['cbkg'][stateName] = simMassPdf.getPdf(stateName).pdfList().at(1).createIntegral( intSet, normSet )
for comp in comps :
yields[comp]['total'] = sum( y for y in yields[comp].itervalues() )
print 'P2VV - INFO: signal and background yields:'
for comp in comps :
print ' %4s: %9.2f' % ( comp, yields[comp]['total'] )
# create datasets
from ROOT import RooFit, RooDataSet, RooRealVar
dataObs = RooArgSet( dataSet.get() )
if genMass :
var = dataObs.find('mass')
if var : dataObs.remove(var)
splitData = dict( [ ( comp, dict( [ ( state.GetName(), RooDataSet('%s_%s' % (dataSet.GetName(), comp), dataSet.GetTitle(), dataObs) )\
for state in splitCat ] ) ) for comp in comps ] )
else :
sigWeight = RooRealVar( 'sigWeight', 'sigWeight', 1. )
dataObs.add(sigWeight)
if weightData :
splitData = dict( [ ( comp, dict( [ ( 'total', RooDataSet( '%s_%s' % ( dataSet.GetName(), comp ), dataSet.GetTitle()
, dataObs, RooFit.WeightVar(sigWeight) ) ) ] ) ) for comp in comps ] )
else :
splitData = dict( [ ( comp, dict( [ ( 'total', RooDataSet( '%s_%s' % ( dataSet.GetName(), comp ), dataSet.GetTitle()
, dataObs ) ) ] ) ) for comp in comps ] )
# function to get observable value from dataset
def getObsVal( names, obsSet ) :
示例9: readDataSet
# 需要导入模块: from ROOT import RooArgSet [as 别名]
# 或者: from ROOT.RooArgSet import find [as 别名]
#.........这里部分代码省略.........
# now read the data set
data = readDataSet(configdict, ws, observables)
@endcode
"""
from ROOT import ( TFile, RooWorkspace, RooRealVar, RooCategory,
RooBinningCategory, RooUniformBinning, RooMappedCategory,
RooDataSet, RooArgSet, RooArgList )
import sys, math
# local little helper routine
def round_to_even(x):
xfl = int(math.floor(x))
rem = x - xfl
if rem < 0.5: return xfl
elif rem > 0.5: return xfl + 1
else:
if xfl % 2: return xfl + 1
else: return xfl
# another small helper routine
def tokenize(s, delims = '+-*/()?:'):
# FIXME: this goes wrong for numerical constants like 1.4e-3
# proposed solution: regexp for general floating point constants,
# replace occurences of matches with empty string
delims = [ c for c in delims ]
delims.insert(0, None)
for delim in delims:
tmp = s.split(delim)
tmp = list(set(( s + ' ' for s in tmp)))
s = ''.join(tmp)
tmp = list(set(s.split(None)))
return tmp
# figure out which names from the mapping we need - look at the observables
names = ()
for n in config['DataSetVarNameMapping'].keys():
if None != observables.find(n):
names += (n,)
# build RooArgSets and maps with source and destination variables
dmap = { }
for k in names: dmap[k] = observables.find(k)
if None in dmap.values():
raise NameError('Some variables not found in destination: %s' % str(dmap))
dset = RooArgSet()
for v in dmap.values(): dset.add(v)
if None != dset.find('weight'):
# RooFit insists on weight variable being first in set
tmpset = RooArgSet()
tmpset.add(dset.find('weight'))
it = dset.fwdIterator()
while True:
obj = it.next()
if None == obj: break
if 'weight' == obj.GetName(): continue
tmpset.add(obj)
dset = tmpset
del tmpset
ddata = RooDataSet('agglomeration', 'of positronic circuits', dset, 'weight')
else:
ddata = RooDataSet('agglomeration', 'of positronic circuits', dset)
# open file with data sets
f = TFile(config['DataFileName'], 'READ')
# get workspace
fws = f.Get(config['DataWorkSpaceName'])
ROOT.SetOwnership(fws, True)
if None == fws or not fws.InheritsFrom('RooWorkspace'):
# ok, no workspace, so try to read a tree of the same name and
# synthesize a workspace
from ROOT import RooWorkspace, RooDataSet, RooArgList
示例10: RooArgSet
# 需要导入模块: from ROOT import RooArgSet [as 别名]
# 或者: from ROOT.RooArgSet import find [as 别名]
from ROOT import TFile, RooArgSet
dataFile = TFile.Open('P2VVDataSets20112012Reco14_I2Mass_6KKMassBins_2TagCats_kinematics.root')
data = dataFile.Get('JpsiKK_sigSWeight')
dataFile.Close()
varSet = RooArgSet( data.get() )
for var in [ 'wMC', 'hlt2_prescale', 'polarity', 'tagCatP2VV', 'nPVCat', 'BpTCat', 'runPeriod' ] :
varSet.remove( varSet.find(var) )
from ROOT import RooCategory
varSet11 = RooArgSet(varSet)
varSet12 = RooArgSet(varSet)
runPeriod11 = RooCategory( 'runPeriod', 'runPeriod' )
runPeriod12 = RooCategory( 'runPeriod', 'runPeriod' )
runPeriod11.defineType( 'p2011', 2011 )
runPeriod12.defineType( 'p2012', 2012 )
varSet11.add(runPeriod11)
varSet12.add(runPeriod12)
from ROOT import RooFit, RooDataSet
data11 = RooDataSet( data.GetName(), data.GetTitle(), varSet11, RooFit.Import(data), RooFit.Cut('hlt2_biased==1 && runPeriod==2011') )
data12 = RooDataSet( data.GetName(), data.GetTitle(), varSet12, RooFit.Import(data), RooFit.Cut('hlt2_biased==1 && runPeriod==2012') )
from ROOT import TObject
dataFile11 = TFile.Open( 'P2VVDataSets2011Reco14_I2Mass_6KKMassBins_2TagCats_kinematics_HLT2B.root', 'RECREATE' )
dataFile11.Add(data11)
dataFile11.Write( 'P2VVDataSets2011Reco14_I2Mass_6KKMassBins_2TagCats_kinematics_HLT2B.root', TObject.kOverwrite )
dataFile11.Close()
dataFile12 = TFile.Open( 'P2VVDataSets2012Reco14_I2Mass_6KKMassBins_2TagCats_kinematics_HLT2B.root', 'RECREATE' )
dataFile12.Add(data12)
dataFile12.Write( 'P2VVDataSets2012Reco14_I2Mass_6KKMassBins_2TagCats_kinematics_HLT2B.root', TObject.kOverwrite )
dataFile12.Close()