 |
Create contour plot and fit it using Jaida
Source code name: "jaida_ScanAndContour.java"
Programming language: Java
Topic: Data arrays/DataPointSet
DMelt Version 1. Last modified: 08/18/2016. License: Pro
https://datamelt.org/code/cache/jaida_ScanAndContour_7486.java
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.
import hep.aida.*;
import java.util.Random;
public class jaida_ScanAndContour
{
public static void main(String[] argv) throws java.io.IOException
{
IAnalysisFactory anFactory = IAnalysisFactory.create();
ITree tree = anFactory.createTreeFactory().create();
IHistogramFactory histFactory = anFactory.createHistogramFactory( tree );
ITupleFactory tuplFactory = anFactory.createTupleFactory( tree );
IFunctionFactory funcFactory = anFactory.createFunctionFactory( tree );
IFitFactory fitFactory = anFactory.createFitFactory();
IFitter fitter = fitFactory.createFitter("Chi2","jminuit");
IHistogram1D hist = histFactory.createHistogram1D("hist","Test Histogram",100,-5,5);
Random r = new Random();
for (int i=0; i<10000; i++) {
double x = r.nextGaussian();
hist.fill(x);
}
IFitData fitData = fitFactory.createFitData();
fitData.create1DConnection(hist);
IFitResult fitResult = fitter.fit(fitData,"g");
int meanIndex = fitResult.fittedFunction().indexOfParameter("mean");
double meanVal = fitResult.fittedParameters()[meanIndex];
double meanErr = fitResult.errors()[meanIndex];
IDataPointSet meanScan = fitter.createScan1D(fitData, fitResult.fittedFunction(),"mean",20, meanVal-3*meanErr, meanVal+3*meanErr);
int sigmaIndex = fitResult.fittedFunction().indexOfParameter("sigma");
double sigmaVal = fitResult.fittedParameters()[sigmaIndex];
double sigmaErr = fitResult.errors()[sigmaIndex];
IDataPointSet oneSigmaContour = fitter.createContour(fitData, fitResult, "mean", "sigma", 10, 1);
IDataPointSet twoSigmaContour = fitter.createContour(fitData, fitResult, "mean", "sigma", 10, 2);
IPlotter plotter = anFactory.createPlotterFactory().create("Plot");
plotter.destroyRegions();
plotter.createRegion(0,0,.66,1).plot(hist);
plotter.region(0).plot(fitResult.fittedFunction());
plotter.createRegion(.66,0,.33,.5).plot( meanScan );
plotter.createRegion(.66,.5,.33,.5).plot( twoSigmaContour );
plotter.region(2).plot( oneSigmaContour );
plotter.show();
}
}
You see the box below because you did not login.