import hep.aida.*;
import java.util.Random;
import hep.aida.ref.function.*;
public class Example4 {

  public static void main(String[] args){
    IAnalysisFactory af = IAnalysisFactory.create();
    IHistogramFactory hf = af.createHistogramFactory(null);

    IHistogram1D h = hf.createHistogram1D("Example1", 100, 0, 1);

    Random r = new Random(1234567);
    for (int i = 0; i < 16000; i++) {
      double x = Math.sqrt(r.nextDouble());
      h.fill(x);
    }
    IFunction f1 = new AbstractIFunction("Linear", 1, 2) {
            public double value(double[] v) { return p[0]*v[0]+p[1]; }
      };
    f1.setParameters(new double[] {320.,0. } );

    IPlotterFactory pf = af.createPlotterFactory();
    IPlotterStyle style = pf.createPlotterStyle();
    style.dataStyle().setParameter("fillHistogramBars","false");
    style.dataStyle().setParameter("functionLineColor","red");
    IPlotter plotter = pf.create();

    plotter.currentRegion().plot(h,style);
    plotter.currentRegion().plot(f1,style);

    plotter.show();
  }
}
