Showing histogram using GROOT
Source code name: "groot_histo1.java"
Programming language: Java
Topic: Histograms/1D
DMelt Version 1.9. Last modified: 07/16/1971. License: Free
https://datamelt.org/code/cache/groot_histo1_4054.java
To run this script using the DataMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


import java.util.Random;
import javax.swing.JFrame;
import org.jlab.groot.data.H1F;
import org.jlab.groot.graphics.EmbeddedCanvas;

public class groot_histo1 {

	public static void main(String[] args) {
		JFrame frame = new JFrame("Basic GROOT Demo");
		EmbeddedCanvas canvas = new EmbeddedCanvas();
		frame.setSize(800,500);
		H1F histogram = new H1F("histogram",100,-5,5); 
		Random randomGenerator = new Random();
		for(int i=0; i<50000; i++){
			histogram.fill(randomGenerator.nextGaussian());
		}
		histogram.setTitleX("Randomly Generated Function");
		histogram.setTitleY("Counts");
		canvas.getPad(0).setTitle("BasicDemo Test");
		histogram.setLineWidth(2);
		histogram.setLineColor(21);
		histogram.setFillColor(34);
		histogram.setOptStat(1110);
		canvas.draw(histogram);
		canvas.setFont("HanziPen TC");  
		canvas.setTitleSize(32);
		canvas.setAxisTitleSize(24);
		canvas.setAxisLabelSize(18);
		canvas.setStatBoxFontSize(18);
		frame.add(canvas);
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
	}

}