本文整理汇总了Python中ROOT.RooArgSet.selectByAttrib方法的典型用法代码示例。如果您正苦于以下问题:Python RooArgSet.selectByAttrib方法的具体用法?Python RooArgSet.selectByAttrib怎么用?Python RooArgSet.selectByAttrib使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ROOT.RooArgSet
的用法示例。
在下文中一共展示了RooArgSet.selectByAttrib方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RooArgSet
# 需要导入模块: from ROOT import RooArgSet [as 别名]
# 或者: from ROOT.RooArgSet import selectByAttrib [as 别名]
#pars.Print('v')
obs = RooArgSet(mass, ws.cat('dataCat'))
obs.setName('observables')
poi = RooArgSet(ws.var('x2'))
ws.var('x2').setRange(0.01, 1.2)
if ws.var('x3'):
# poi.add(ws.var('x3'))
ws.var('x3').setRange(0.01, 1.2)
if ws.var('x23'):
# poi.add(ws.var('x23'))
ws.var('x23').setRange(0.01, 1.2)
poi.setName('poi')
nuis = RooArgSet(pars)
nuis.setName('nuisance')
nuis.remove(poi)
nuis.remove(nuis.selectByAttrib('Constant', True))
## nuis.remove(ws.var('nbkg_pp'))
## nuis.remove(ws.var('nbkg_hi'))
## nuis.remove(ws.var('mscale_hi'))
## nuis.remove(ws.var('mscale_pp'))
## nuis.remove(ws.var('syst_bg_pp'))
## nuis.remove(ws.var('syst_bg_hi'))
## nuis.remove(ws.var('width_hi'))
## nuis.remove(ws.var('syst_width_hi'))
## nuis.remove(ws.var('npow'))
## nuis.remove(ws.var('syst_npow'))
print 'observables'
obs.Print()
print 'parameter of interest'
示例2: doDataFit
# 需要导入模块: from ROOT import RooArgSet [as 别名]
# 或者: from ROOT.RooArgSet import selectByAttrib [as 别名]
#.........这里部分代码省略.........
# I use a2 as the sigma of my gaussian
gauss1 = RooCBShape('gauss1', 'gauss1',x, mean_1, a2_1, a1_1, n1_1)
gauss2 = RooCBShape('gauss2', 'gauss2',x, mean_2, a2_2, a1_2, n1_2)
# I use n2 as the ratio of cb with respect to gauss
chib1_pdf = RooAddPdf('chib1','chib1',RooArgList(cb1, gauss1),RooArgList(n2_1))
chib2_pdf = RooAddPdf('chib2','chib2',RooArgList(cb2, gauss2),RooArgList(n2_2))
#background
q01S_Start = 9.5
alpha = RooRealVar("#alpha","#alpha",1.5,-1,3.5)#0.2 anziche' 1
beta = RooRealVar("#beta","#beta",-2.5,-7.,0.)
q0 = RooRealVar("q0","q0",q01S_Start)#,9.5,9.7)
delta = RooFormulaVar("delta","TMath::Abs(@[email protected])",RooArgList(x,q0))
b1 = RooFormulaVar("b1","@0*(@[email protected])",RooArgList(beta,x,q0))
signum1 = RooFormulaVar( "signum1","( TMath::Sign( -1.,@[email protected] )+1 )/2.", RooArgList(x,q0) )
background = RooGenericPdf("background","Background", "signum1*pow(delta,#alpha)*exp(b1)", RooArgList(signum1,delta,alpha,b1) )
if useOtherBackgroundParametrization: # in thies case I redefine background
a0 = RooRealVar('a0','a0',1.,-1.,1.) #,0.5,0.,1.)
a1 = RooRealVar('a1','a1',0.1,-1.,1.) #-0.2,0.,1.)
#a2 = RooRealVar('a2','a2',-0.1,1.,-1.)
background = RooChebychev('background','Background',x,RooArgList(a0,a1))
parameters.add(RooArgSet(a0, a1))
else:
parameters.add(RooArgSet(alpha, beta, q0))
#together
chibs = RooArgList(chib1_pdf,chib2_pdf,background)
# ndof
floatPars = parameters.selectByAttrib("Constant",ROOT.kFALSE)
ndof = numBins - floatPars.getSize() - 1
# # Here I have as parameters N1, N2, and N_background
# n_chib1 = RooRealVar("n_chib1","n_chib1",1250, 0, 50000)
# n_chib2 = RooRealVar("n_chib2","n_chib2",825, 0, 50000)
# n_background = RooRealVar('n_background','n_background',4550, 0, 50000)
# ratio_list = RooArgList(n_chib1, n_chib2, n_background)
# modelPdf = RooAddPdf('ModelPdf', 'ModelPdf', chibs, ratio_list)
# Here I have as parameters N_12, ratio_12, N_background
n_chib = RooRealVar("n_chib","n_chib",2075, 0, 100000)
ratio_21 = RooRealVar("ratio_21","ratio_21",0.6, 0, 1)
n_chib1 = RooFormulaVar("n_chib1","@0/([email protected])",RooArgList(n_chib, ratio_21))
n_chib2 = RooFormulaVar("n_chib2","@0/(1+1/@1)",RooArgList(n_chib, ratio_21))
n_background = RooRealVar('n_background','n_background',4550, 0, 50000)
ratio_list = RooArgList(n_chib1, n_chib2, n_background)
parameters.add(RooArgSet(n_chib1, n_chib2, n_background))
modelPdf = RooAddPdf('ModelPdf', 'ModelPdf', chibs, ratio_list)
print 'Fitting to data'
fit_region = x.setRange("fit_region",9.7,10.1)
result=modelPdf.fitTo(data,RooFit.Save(), RooFit.Range("fit_region"))
# define frame
frame = x.frame()
frame.SetNameTitle("fit_resonance","Fit Resonanace")
frame.GetXaxis().SetTitle(x_axis_label )
frame.GetYaxis().SetTitle( "Events/5 MeV " )
frame.GetXaxis().SetTitleSize(0.04)
frame.GetYaxis().SetTitleSize(0.04)
frame.GetXaxis().SetTitleOffset(1.1)
示例3: doMCFit
# 需要导入模块: from ROOT import RooArgSet [as 别名]
# 或者: from ROOT.RooArgSet import selectByAttrib [as 别名]
def doMCFit(inputfile_name, mass_chib, cuts, output_name='ChiB', plotTitle = "#Chi_{b}", fittedVariable='qValue', returnOnlyFitResult = False, useOtherSignalParametrization = False, drawPulls = False, legendOnPlot=True):
mass_error = 0.15
print "Creating DataSet from file "+str(inputfile_name)
dataSet = makeRooDataset(inputfile_name)
if(fittedVariable == 'refittedMass'):
x_var = 'rf1S_chib_mass'
output_suffix = '_refit'
x_axis_label= 'm_{#mu^{+} #mu^{-} #gamma} [GeV]'
else:
x_var = 'invm1S'
output_suffix = '_qValue'
x_axis_label = 'm_{#gamma #mu^{+} #mu^{-}} - m_{#mu^{+} #mu^{-}} + m^{PDG}_{#Upsilon} [GeV]'
cuts_str = str(cuts)
#cuts_str = quality_cut +"photon_pt > 0.5 && abs(photon_eta) < 1.0 && abs(dimuon_rapidity) < 1.0 && dimuon_pt>5.0 && pi0_abs_mass > 0.025 && fabs(dz) < 0.1 "#&& numPrimaryVertices < 16"
data = dataSet.reduce( RooFit.Cut(cuts_str) )
print 'Creating pdf'
x=RooRealVar(x_var,'m(#mu #mu #gamma) - m(#mu #mu) + m_{#Upsilon}',9.8,9.96)#9.7,10.1,'GeV')
numBins = 32 # define here so that if I change it also the ndof change accordingly
x.setBins(numBins)
# Double sided Crystal Ball
mean=RooRealVar("#mu","mean ChiB",mass_chib, mass_chib-mass_error,mass_chib+mass_error,"GeV")
sigma=RooRealVar("#sigma","sigma ChiB",0.006, 0,0.2,'GeV')
a1 = RooRealVar('#alpha1', '#alpha1', 0.75, 0, 3)
a2 = RooRealVar('#alpha2', '#alpha2', 1.6, 0, 3)
n1 = RooRealVar('n1', 'n1', 2.8)#, 1.0,4.0) # 2 per 2S
n2 = RooRealVar('n2', 'n2', 3)#, 1.,4.0) # 1 per 2S
parameters = RooArgSet(mean, sigma, a1, a2, n1, n2)
cb_pdf = My_double_CB('chib', 'chib', x, mean, sigma, a1, n1, a2, n2)
#cb_pdf = RooCBShape('chib', 'chib', x, mean, sigma, a1, n1)
# ndof
floatPars = parameters.selectByAttrib("Constant",ROOT.kFALSE)
ndof = numBins - floatPars.getSize() - 1
if useOtherSignalParametrization: # In this case I redefine cb_pdf
n1 = RooRealVar('n1', 'n1', 2)
cb = RooCBShape('cb1', 'cb1', x, mean, sigma, a1, n1)
# I use a2 as the sigma of my second CB
a2 = RooRealVar('#alpha2', '#alpha2', 0.5, 0, 3)
gauss = RooCBShape('cb2', 'cb2',x, mean, a2, a1, n1)
# I use n2 as the ratio of cb1 with respect to cb2
n2 = RooRealVar('n2', 'n2',0.,1.)
cb_pdf = RooAddPdf('chib','chib',RooArgList(cb, gauss),RooArgList(n2))
#cb_pdf = cb
print 'Fitting to data'
fit_region = x.setRange("fit_region",9.8,9.96)
result = cb_pdf.fitTo(data, RooFit.Save(), RooFit.Range("fit_region"))
# a1_val = a1.getVal()
# a2_val = a2.getVal()
# a1 = RooRealVar('#alpha1', '#alpha1', a1_val)
# a2 = RooRealVar('#alpha2', '#alpha2', a2_val)
# n1 = RooRealVar('n1', 'n1', 1.7,1.0,5.)
# n2 = RooRealVar('n2', 'n2', 1.7,0.,4.)
# cb_pdf = My_double_CB('chib', 'chib', x, mean, sigma, a1, n1, a2, n2)
# result = cb_pdf.fitTo(data, RooFit.Save())
if returnOnlyFitResult:
return result
# define frame
frame = x.frame()
frame.SetNameTitle("fit_resonance","Fit Resonanace")
frame.GetXaxis().SetTitle(x_axis_label )
frame.GetYaxis().SetTitle( "Events/5 MeV " )
frame.GetXaxis().SetTitleSize(0.04)
frame.GetYaxis().SetTitleSize(0.04)
frame.GetXaxis().SetTitleOffset(1.1)
frame.GetXaxis().SetLabelSize(0.04)
frame.GetYaxis().SetLabelSize(0.04)
frame.SetLineWidth(1)
frame.SetTitle(plotTitle)
# plot things on frame
data.plotOn(frame, RooFit.MarkerSize(0.7))
cb_pdf.plotOn(frame, RooFit.LineWidth(2))
# chiSquare legend
chi2 = frame.chiSquare()
probChi2 = TMath.Prob(chi2*ndof, ndof)
chi2 = round(chi2,2)
probChi2 = round(probChi2,2)
leg = TLegend(0.3,0,.10,.10)
leg.SetBorderSize(0)
leg.SetFillStyle(0)
cb_pdf.paramOn(frame, RooFit.Layout(0.17,0.56,0.93))
leg.AddEntry(0,'#chi^{2} ='+str(chi2),'')
#.........这里部分代码省略.........