本文整理汇总了Python中ROOT.RooRealVar.setBin方法的典型用法代码示例。如果您正苦于以下问题:Python RooRealVar.setBin方法的具体用法?Python RooRealVar.setBin怎么用?Python RooRealVar.setBin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ROOT.RooRealVar
的用法示例。
在下文中一共展示了RooRealVar.setBin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from ROOT import RooRealVar [as 别名]
# 或者: from ROOT.RooRealVar import setBin [as 别名]
class Fit2L:
def __init__(self, file_names, br_name="mass"):
self.file_names = file_names
self.br_name = br_name
min_x = 8
max_x = 12
self.obs = RooRealVar("obs", "m4l", min_x, max_x)
self.nbins = int((max_x - min_x) * 20)
self.obs.setBin(self.nbins)
# self.ws = ROOT.RooWorkspace("combined", "combined")
self.obs.setRange("fit", 8.5, 11.5)
self.dummy_hists = []
self.chi2_cut = 10000
def build_model(self):
# mean = RooRealVar("mean", "mass of 1S", 9.46, 9.2, 9.7)
# sigma = RooRealVar("sigma", "sigma of gaussian", 0.14, 0.09, 0.3)
mean = RooRealVar("mean", "mass of 1S", 9.48352)
sigma = RooRealVar("sigma", "sigma of gaussian", 1.38574e-01)
gaussian = ROOT.RooGaussian("gauss", "gauss", self.obs, mean, sigma)
## try Crystal Ball
# alpha = RooRealVar("alpha", "alpha of CB", 5.9, 0, 100)
# cb_n = RooRealVar("cb_n", "n of CB", 55.4, 0, 100)
# gaussian = ROOT.RooCBShape("gauss", "gauss", self.obs, mean, sigma, alpha, cb_n)
n_sig = RooRealVar("n_sig", "number of signal", 5000, 0, 100000)
esig = ROOT.RooExtendPdf("esig", "esig", gaussian, n_sig)
m2_shift = RooRealVar("m2_shift", "m2 shift", 0.56296)
m2 = ROOT.RooFormulaVar("m2", "mass of 2S", "@0+ @1", RooArgList(mean, m2_shift))
s2 = ROOT.RooFormulaVar("s2", "sigma*(unit+m2_shift)/mean", "@0*([email protected]/9.46)", RooArgList(sigma, m2_shift))
g2 = ROOT.RooGaussian("g2", "gauss", self.obs, m2, s2)
n2 = RooRealVar("n2", "number of 2S", 800, 100, 100000)
# n2 = ROOT.RooFormulaVar("n2", "number of 2S" ,"n_sig*0.26", RooArgList(n_sig))
esig2 = ROOT.RooExtendPdf("esig2", "esig2", g2, n2)
m3_shift = RooRealVar("m3_shift", "m3 shift", 0.8949)
m3 = ROOT.RooFormulaVar("m3", "mass of 3S", "mean + m3_shift", RooArgList(mean, m3_shift))
s3 = ROOT.RooFormulaVar("s3", "sigma*(unit+m2_shift)/mean", "@0*([email protected]/9.46)", RooArgList(sigma, m3_shift))
g3 = ROOT.RooGaussian("g3", "gauss", self.obs, m3, s3)
# n3 = RooRealVar("n3", "number of 3S" , 50, 0, 1000)
n3 = ROOT.RooFormulaVar("n3", "number of 3S", "n2*0.45", RooArgList(n2))
esig3 = ROOT.RooExtendPdf("esig3", "esig3", g3, n3)
n_bkg = RooRealVar("n_bkg", "number of bkg", 1000, 0, 1e6)
# p0 = RooRealVar("p0", "p0", 5.8677e-02, -1E6, 1E6)
# p1 = RooRealVar("p1", "p1", -5.086E-02, -1E6, 1E6)
# p2 = RooRealVar("p2", "p2", -1.96e-02, -1E6, 1E6)
# p3 = RooRealVar("p3", "p3", -1.08E-02, -1E6, 1E6)
# p4 = RooRealVar("p4", "p4", -1.55E-02, -1E6, 1E6)
# best fitted value using 2015+2016
p0 = RooRealVar("p0", "p0", 5.86772e-02)
p1 = RooRealVar("p1", "p1", -5.08695e-02)
p2 = RooRealVar("p2", "p2", -1.95595e-02)
p3 = RooRealVar("p3", "p3", -1.08105e-02)
p4 = RooRealVar("p4", "p4", -1.54855e-02)
bkg = ROOT.RooChebychev("bkg", "bkg", self.obs, RooArgList(p0, p1, p2, p3, p4))
# bkg = ROOT.RooPolynomial("bkg", "bkg", self.obs, RooArgList(p0, p1, p2))
ebkg = ROOT.RooExtendPdf("ebkg", "ebkg", bkg, n_bkg)
model = ROOT.RooAddPdf("model", "model", RooArgList(esig, esig2, esig3, ebkg))
getattr(self.ws, "import")(model)
def get_data(self):
"""
create RooDataSet from file_names
"""
tree = ROOT.TChain("upsilon", "upsilon")
if type(self.file_names) is list:
for file_name in self.file_names:
tree.Add(file_name)
else:
tree.Add(self.file_names)
nentries = tree.GetEntries()
print "total: ", nentries
obs_set = RooArgSet(self.obs)
data = ROOT.RooDataSet("data", "data", obs_set)
for ientry in xrange(nentries):
tree.GetEntry(ientry)
for i, m4l in enumerate(getattr(tree, self.br_name)):
# m4l = m4l/1000
if m4l > self.obs.getMax() or m4l < self.obs.getMin():
continue
if tree.chi2[i] > self.chi2_cut:
continue
self.obs.setVal(m4l)
data.add(obs_set)
getattr(self.ws, "import")(data)
def fit(self):
if not hasattr(self, "ws"):
self.ws = ROOT.RooWorkspace("combined", "combined")
self.build_model()
self.get_data()
data = self.ws.obj("data")
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from ROOT import RooRealVar [as 别名]
# 或者: from ROOT.RooRealVar import setBin [as 别名]
class Fit2L:
def __init__(self, file_name, br_name="mass"):
self.file_name = file_name
self.br_name = br_name
min_x = 8
max_x = 12
self.obs = RooRealVar("obs", "m4l", min_x, max_x)
self.nbins = int((max_x - min_x) * 20)
self.obs.setBin(self.nbins)
#self.ws = ROOT.RooWorkspace("combined", "combined")
self.dummy_hists = []
self.chi2_cut = 10000
# dionia selection or onia selection
self.dionia_selection = False
# with 3mu4 trigger or not
self.with_3mu4 = True
# only unprescaled runs
self.only_unprescaled = True
# different onia_pt cuts, 0:noCut, 1:<5, 2:5-10, 3:10,20, 4:>20
self.onia_pt_cut = 0
self.onia_pt_cuts = [0, 5, 10, 20]
#self.onia_pt_cuts = [0, 10, 20]
# different muon pT cuts
# suggested by Terry to look at onia mass that have one muon with pT (3, 4) GeV.
self.use_low_pt_muon = False
# it is found that these low pT muons contributes a lot the background 40%
# while only gain 15% signal
self.no_low_pt = False
# if build new model
self.new_model = False
self.model_name = "model"
# workspace components
self.data = None
self.model = None
def pass_onia_pt_cut(self, pT):
pT_cut = int(self.onia_pt_cut)
if pT_cut >= len(self.onia_pt_cuts):
return pT >= self.onia_pt_cuts[ len(self.onia_pt_cuts)-1 ]
elif pT_cut > 0:
return pT >= self.onia_pt_cuts[pT_cut-1] and pT < self.onia_pt_cuts[pT_cut]
else:
return True
def print_onia_pt_cut(self):
pT_cut = int(self.onia_pt_cut)
if pT_cut >= len(self.onia_pt_cuts):
return "p_{T}^{onia} in ["+str(self.onia_pt_cuts[ len(self.onia_pt_cuts)-1 ])+", #infty) GeV"
elif pT_cut > 0:
return "p_{T}^{onia} in ["+str(self.onia_pt_cuts[pT_cut-1])+", "+str(self.onia_pt_cuts[pT_cut])+") GeV"
else:
return "p_{T}^{onia} in [-#infty, #infty] GeV"
def print_dionia_selection(self):
if self.dionia_selection:
return "di-onia selection"
else:
return "onia selection"
def print_trigger(self):
if self.with_3mu4:
return "with trigger"
else:
return "no trigger"
def get_ws_name(self):
res = "ws_chi2Cut"+str(self.chi2_cut)+"_DiOnia"+str(self.dionia_selection)+"_pTCut"+str(self.onia_pt_cut)+"_withTrigger"+str(self.with_3mu4)
if self.use_low_pt_muon:
res += "_LowPtMuon"
if self.no_low_pt:
res += "_noLowPtMuon"
res += ".root"
return res
def build_model(self):
#mean = RooRealVar("mean", "mass of 1S", 9.46, 9.2, 9.7)
#sigma = RooRealVar("sigma", "sigma of gaussian", 0.14, 0.09, 0.3)
mean = RooRealVar("mean", "mass of 1S", 9.46)
sigma = RooRealVar("sigma", "sigma of gaussian", 0.18)
gaussian = ROOT.RooGaussian("gauss", "gauss", self.obs, mean, sigma)
## try Crystal Ball
#alpha = RooRealVar("alpha", "alpha of CB", 5.9, 0, 100)
#cb_n = RooRealVar("cb_n", "n of CB", 55.4, 0, 100)
#gaussian = ROOT.RooCBShape("gauss", "gauss", self.obs, mean, sigma, alpha, cb_n)
n_sig = RooRealVar("n_sig", "number of signal" , 5000, 0, 1E6)
esig = ROOT.RooExtendPdf("esig", "esig", gaussian, n_sig)
m2_shift = RooRealVar("m2_shift", "m2 shift", 0.56296)
m2 = ROOT.RooFormulaVar("m2", "mass of 2S", "@0+ @1", RooArgList(mean, m2_shift))
s2 = ROOT.RooFormulaVar("s2", "sigma*(unit+m2_shift)/mean", "@0*([email protected]/9.46)", RooArgList(sigma, m2_shift))
g2 = ROOT.RooGaussian("g2", "gauss", self.obs, m2, s2)
#.........这里部分代码省略.........