本文整理汇总了Python中histogram.Histogram.add方法的典型用法代码示例。如果您正苦于以下问题:Python Histogram.add方法的具体用法?Python Histogram.add怎么用?Python Histogram.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类histogram.Histogram
的用法示例。
在下文中一共展示了Histogram.add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HistogramTest
# 需要导入模块: from histogram import Histogram [as 别名]
# 或者: from histogram.Histogram import add [as 别名]
class HistogramTest(unittest.TestCase):
def setUp(self):
self.h = Histogram()
self.h.add("Apache")
self.h.add("Apache")
def test_add(self):
assert self.h.get_dict().get("Apache") is not None
def test_count(self):
self.assertEqual(self.h.count("Apache"), 2)
示例2: get_headers
# 需要导入模块: from histogram import Histogram [as 别名]
# 或者: from histogram.Histogram import add [as 别名]
def get_headers(self):
all_links = self.parse_html()
server_names = ["Apache", "nginx", "Zeus", "Microsoft-IIS"]
histogram = Histogram()
for link in all_links:
try:
if link is not None and "link.php?id=" in link:
req = requests.head(self.url + link, timeout=3, allow_redirects=True)
get_server = req.headers["Server"]
print(get_server)
for servers in server_names:
if servers in get_server:
get_server = servers
histogram.add(get_server)
break
if servers == server_names[-1]:
get_server = "other servers"
histogram.add(get_server)
except Exception:
print("The page is not responding...")
continue
return histogram
示例3: getServersDict
# 需要导入模块: from histogram import Histogram [as 别名]
# 或者: from histogram.Histogram import add [as 别名]
def getServersDict(all_servers):
h = Histogram()
for server in all_servers:
if server is not None:
if 'apache' in server.lower():
h.add('Apache')
if 'nginx' in server.lower():
h.add('nginx')
if 'IIS' in server.upper():
h.add('IIS')
return h
示例4: HistogramTests
# 需要导入模块: from histogram import Histogram [as 别名]
# 或者: from histogram.Histogram import add [as 别名]
class HistogramTests(unittest.TestCase):
def setUp(self):
self.ap = 'Apache'
self.ng = 'nginx'
self.iis = 'IIS'
self.h = Histogram()
def testAddRecord(self):
self.h.add(self.ap)
self.assertEqual(1, len(self.h.get_dict()))
def testAddRecord_2(self):
self.h.add(self.ap)
self.h.add(self.ng)
self.assertEqual(2, len(self.h.get_dict()))
def testCountRecord(self):
self.h.add(self.ap)
self.assertEqual(1, self.h.count("Apache"))
def testCountRecord_2(self):
self.h.add(self.ap)
self.h.add(self.ap)
self.assertEqual(2, self.h.count("Apache"))
def testCountRecord_3(self):
self.h.add(self.ap)
self.h.add(self.ap)
self.h.add(self.ng)
self.assertEqual(None, self.h.count("IBM Web Server"))
def testGetDict_4(self):
self.h.add(self.ap)
self.h.add(self.ap)
self.h.add(self.ng)
self.h.add(self.ng)
self.h.add(self.iis)
self.assertEqual(self.h.get_dict(), {"Apache": 2, "nginx": 2, "IIS": 1})
示例5: scalePlots
# 需要导入模块: from histogram import Histogram [as 别名]
# 或者: from histogram.Histogram import add [as 别名]
def scalePlots(self, outputDir):
groups = dict([(g.name, g) for g in self.groups])
fakeGroups = ['EGFake', 'JGFake']
candClass = 'PhotonAnd' + self.lepton
jlClass = 'PhotonAndFake' + self.lepton
fakeClasses = ['ElePhotonAnd' + self.lepton, 'FakePhotonAnd' + self.lepton]
### CREATE TEMPLATES FROM SAMPLE HISTOGRAMS IN GROUPS
observed = self.tempDef.generate(suffix = 'observed')
fakeHistograms = dict([(gname, Histogram(self.tempDef, suffix = gname)) for gname in fakeGroups])
vgHistogram = Histogram(self.tempDef, suffix = 'vg')
qcdHistogram = Histogram(self.tempDef, suffix = 'qcd')
for sample in groups['Observed'].samples:
observed.Add(sample.histograms[self.tempDef.name].hWeighted)
for sample in groups['EWK'].samples:
observed.Add(sample.histograms[self.tempDef.name].hWeighted, -1.)
for gname in fakeGroups:
for sample in groups[gname].samples:
fakeHistograms[gname].add(sample.histograms[self.tempDef.name])
for sample in groups['VGamma'].getSamples(candClass):
vgHistogram.add(sample.histograms[self.tempDef.name])
for sample in groups['JLFake'].samples:
qcdHistogram.add(sample.histograms[self.tempDef.name])
### FIT FOR CENTRAL VALUES
fitter = ROOT.TemplateChi2Fitter.singleton()
vgScale = ROOT.RooRealVar('vg', 'vg', 1., 0., 5.)
qcdScale = ROOT.RooRealVar('qcd', 'qcd', 0.1, 0., 1.)
target = observed.Clone('target')
for histo in fakeHistograms.values():
target.Add(histo.hWeighted, -1.)
fitter.setTarget(target)
fitter.addTemplate(vgHistogram.hWeighted, 'vg', vgScale)
fitter.addTemplate(qcdHistogram.hWeighted, 'qcd', qcdScale)
target.Delete()
directory = outputDir.GetDirectory('PreTemplateFit')
if not directory:
directory = outputDir.mkdir('PreTemplateFit')
directory.cd()
fitter.plot(directory)
directory.Write()
if fitter.fit() != 0:
raise RuntimeError('Template fit did not converge')
directory = outputDir.GetDirectory('PostTemplateFit')
if not directory:
directory = outputDir.mkdir('PostTemplateFit')
directory.cd()
fitter.plot(directory)
directory.Write()
vgCentral = vgScale.getVal()
vgCentralErr = vgScale.getError()
qcdCentral = qcdScale.getVal()
qcdCentralErr = qcdScale.getError()
### ERROR ESTIMATION
directory = outputDir.GetDirectory('TemplateFitError')
if not directory:
directory = outputDir.mkdir('TemplateFitError')
directory.cd()
# tree = ROOT.TTree('toys', 'Toys')
# vg = array.array('d', [0.])
# qcd = array.array('d', [0.])
# targetContents = array.array('d', [0.] * self.tempDef.nx)
# targetErrors = array.array('d', [0.] * self.tempDef.nx)
# vgContents = array.array('d', [0.] * self.tempDef.nx)
# vgErrors = array.array('d', [0.] * self.tempDef.nx)
# tree.Branch('vg', vg, 'vg/D')
# tree.Branch('qcd', qcd, 'qcd/D')
# tree.Branch('targetContents', targetContents, 'content[%d]/D' % self.tempDef.nx)
# tree.Branch('targetErrors', targetErrors, 'error[%d]/D' % self.tempDef.nx)
# tree.Branch('vgContents', vgContents, 'content[%d]/D' % self.tempDef.nx)
# tree.Branch('vgErrors', vgErrors, 'error[%d]/D' % self.tempDef.nx)
vgScales = []
qcdScales = []
vgScalesNoEff = []
qcdScalesNoEff = []
def modifyTemplate(histogram, sigma, name = 'template'):
result = histogram.hWeighted.Clone(name)
for iX in range(1, result.GetNbinsX() + 1):
err = max(abs(histogram.hScaleUp.GetBinContent(iX) - result.GetBinContent(iX)), abs(result.GetBinContent(iX) - histogram.hScaleDown.GetBinContent(iX)))
result.SetBinContent(iX, result.GetBinContent(iX) + err * sigma)
#.........这里部分代码省略.........