 |
A H1D histogram using variable bin sizes
Source code name: "histo_log2.py"
Programming language: Python
Topic: Histograms/1D
DMelt Version 1. Last modified: 12/12/2015. License: Pro
https://datamelt.org/code/cache/histo_log2_3859.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
# Using AIDA histogram in log scale. Variable bins
# based on the example of Philippe Di Stefano
from hep.aida import IAnalysisFactory
from java.lang.Math import *;
from jhplot import HPlot,H1D
# create AIDA histogram
af = IAnalysisFactory.create()
mainTree =IAnalysisFactory.create().createTreeFactory().create()
tf = af.createTupleFactory(mainTree)
dpsf =af.createDataPointSetFactory(mainTree);
hf =af.createHistogramFactory(mainTree);
numVal = 1000
lowX = 0.001
hiX = 10.0
valX=[]
valY=[]
for i in range(numVal):
b= i/(numVal-1.0)
a=lowX*pow((hiX/lowX),b)
valX.append(a)
valY.append(pow(a, -1.9))
lowY = valY[numVal - 1]
hiY = valY[0]
print"Min = ",lowY, "\tMax = ",hiY
binsEdges=[0.01, 0.1, 1, 10.0,100.0]
print "Bin Edges=",binsEdges
hist = hf.createHistogram1D("AIDA Meth Log Histogram", \
"AIDA Meth Log Histogram", binsEdges)
for i in range( numVal ):
hist.fill(valY[i])
# ---- plot JAIDA histogram if you want
# thePlot =af.createPlotterFactory().create("Figure")
# thePlot.region(0).plot(hist)
# thePlot.show()
# plot it in JHPlot
c1 = HPlot("Canvas",600,400)
c1.setGrid(0,0)
c1.setGrid(1,0)
c1.setLogScale(0,1)
c1.visible(1)
c1.setAutoRange()
hh=H1D(hist)
hh.setFill(1)
c1.draw(hh)
# export to some image (png,eps,pdf,jpeg...)
# c1.export(Editor.DocMasterName()+".png")
You see the box below because you did not login.