Print

Print


Commit in lcsim/test/org/lcsim/aida on MAIN
HistogramFitTest.java+46added 1.1
basic test that fitting works

lcsim/test/org/lcsim/aida
HistogramFitTest.java added at 1.1
diff -N HistogramFitTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HistogramFitTest.java	17 Apr 2013 00:14:27 -0000	1.1
@@ -0,0 +1,46 @@
+package org.lcsim.aida;
+
+import hep.aida.IAnalysisFactory;
+import hep.aida.IFitFactory;
+import hep.aida.IFitResult;
+import hep.aida.IFitter;
+import hep.aida.IHistogram1D;
+import hep.aida.IHistogramFactory;
+import hep.aida.IPlotter;
+
+import java.io.IOException;
+import java.util.Random;
+
+import junit.framework.TestCase;
+
+import org.lcsim.util.test.TestUtil.TestOutputFile;
+
+public class HistogramFitTest extends TestCase {
+    
+   public void testFitting() throws IOException {
+       
+      // Create factories
+      IAnalysisFactory analysisFactory = IAnalysisFactory.create();
+      IHistogramFactory histogramFactory = analysisFactory.createHistogramFactory(analysisFactory.createTreeFactory().create());
+      IPlotter plotter = analysisFactory.createPlotterFactory().create("Plot");
+      IFitFactory fitFactory = analysisFactory.createFitFactory();
+      
+      // Create 1D histogram
+      IHistogram1D h1d = histogramFactory.createHistogram1D("Gaussian Distribution",100,-5,5);
+      
+      // Fill 1D histogram with Gaussian
+      Random r = new Random();
+      for (int i=0; i<5000; i++)
+         h1d.fill(r.nextGaussian());
+      
+      // Do Fit
+      IFitter fitter = fitFactory.createFitter("chi2");
+      IFitResult result = fitter.fit(h1d,"g");
+      
+      // Show results
+      plotter.createRegions(1,1,0);
+      plotter.region(0).plot(h1d);
+      plotter.region(0).plot(result.fittedFunction());
+      plotter.writeToFile(new TestOutputFile(this.getClass().getSimpleName() + ".png").getCanonicalPath());
+   }
+}
\ No newline at end of file
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1