``` 1 # Histograms. A histogram in 1D. Using AIDA histogram in log scale. Variable bins 2 # based on the example of Philippe Di Stefano 3 4 from hep.aida import IAnalysisFactory 5 from java.lang.Math import *; 6 from jhplot import HPlot,H1D 7 8 # create AIDA histogram 9 af = IAnalysisFactory.create() 10 mainTree =IAnalysisFactory.create().createTreeFactory().create() 11 tf = af.createTupleFactory(mainTree) 12 dpsf =af.createDataPointSetFactory(mainTree); 13 hf =af.createHistogramFactory(mainTree); 14 15 numVal = 1000 16 lowX = 0.001 17 hiX = 10.0 18 19 valX=[] 20 valY=[] 21 for i in range(numVal): 22 b= i/(numVal-1.0) 23 a=lowX*pow((hiX/lowX),b) 24 valX.append(a) 25 valY.append(pow(a, -1.9)) 26 27 28 lowY = valY[numVal - 1] 29 hiY = valY[0] 30 print"Min = ",lowY, "\tMax = ",hiY 31 binsEdges=[0.01, 0.1, 1, 10.0,100.0] 32 33 print "Bin Edges=",binsEdges 34 35 hist = hf.createHistogram1D("AIDA Meth Log Histogram", \ 36 "AIDA Meth Log Histogram", binsEdges) 37 38 39 40 for i in range( numVal ): 41 hist.fill(valY[i]) 42 43 44 # ---- plot JAIDA histogram if you want 45 # thePlot =af.createPlotterFactory().create("Figure") 46 # thePlot.region(0).plot(hist) 47 # thePlot.show() 48 49 # plot it in JHPlot 50 c1 = HPlot("Canvas",600,400) 51 c1.setGrid(0,0) 52 c1.setGrid(1,0) 53 c1.setLogScale(0,1) 54 c1.visible(1) 55 c1.setAutoRange() 56 hh=H1D(hist) 57 hh.setFill(1) 58 c1.draw(hh) 59 60 61 62 # export to some image (png,eps,pdf,jpeg...) 63 # c1.export(Editor.DocMasterName()+".png") ### © jHepWork. S.Chekanov ### ```