DataPointSets

An IDataPointSet is a collection of IDataPoints. Each IDataPoint is an n-dimensional collection of IMeasurements. Through an IDataPointSetFactory it is possible to either create empty IDataPointSets or already full sets using the data stored in IHistograms, IClouds and IProfiles. IDataPoints and IMeasurements cannot be created, they can only be accessed through the IDataPointSet.

AIDA also provides arithmetic operations among IDataPointSets that have the same size and the same dimension.

Create and Fill an IDataPointSet

In the example below we show how to create an empty one and two dimensional IDataPointSet, how to fill it and plot it:

import hep.aida.*;

public class DataPointSetCreateAndFill
{
   public static void main(String[] argv)
   {    
      IAnalysisFactory af = IAnalysisFactory.create();
      ITree tree = af.createTreeFactory().create();
      IDataPointSetFactory dpsf = af.createDataPointSetFactory(tree);
      
      // Create a one dimensional IDataPointSet.
      IDataPointSet dps1D = dpsf.create("dps1D","one dimensional IDataPointSet",1);

      // Fill the one dimensional IDataPointSet
      double[] yVals1D = { 0.32, 0.45, 0.36, 0.29, 0.34 };
      double[] yErrP1D = { 0.06, 0.07, 0.03, 0.07, 0.04 };

      for ( int i = 0; i<yVals1D.length; i++ ) {
        dps1D.addPoint();
        dps1D.point(i).coordinate(0).setValue( yVals1D[i] );
        dps1D.point(i).coordinate(0).setErrorPlus( yErrP1D[i] );
      }


      // Create a two dimensional IDataPointSet.
      IDataPointSet dps2D = dpsf.create("dps2D","two dimensional IDataPointSet",2);

      // Fill the two dimensional IDataPointSet
      double[] yVals2D = { 0.12, 0.22, 0.35, 0.42, 0.54 , 0.61 };
      double[] yErrP2D = { 0.01, 0.02, 0.03, 0.03, 0.04 , 0.04 };
      double[] yErrM2D = { 0.02, 0.02, 0.02, 0.04, 0.06 , 0.05 };
      double[] xVals2D = { 1.5, 2.6, 3.4, 4.6, 5.5 , 6.4 };
      double[] xErrP2D = { 0.5, 0.5, 0.4, 0.4, 0.5 , 0.5 };

      for ( int i = 0; i<yVals2D.length; i++ ) {
        dps2D.addPoint();
        dps2D.point(i).coordinate(0).setValue( xVals2D[i] );
        dps2D.point(i).coordinate(0).setErrorPlus( xErrP2D[i] );
        dps2D.point(i).coordinate(1).setValue( yVals2D[i] );
        dps2D.point(i).coordinate(1).setErrorPlus( yErrP2D[i] );
        dps2D.point(i).coordinate(1).setErrorMinus( yErrM2D[i] );
      }

      // Display the results
      IPlotter plotter = af.createPlotterFactory().create("Plot IDataPointSets");
      plotter.createRegions(2,1);
      plotter.region(0).plot( dps1D );
      plotter.region(1).plot( dps2D );
      plotter.show();


   }
}

Create, Fill and Fit an IDataPointSet

In the example below we show how to fit a two dimensional IDataPointSet, with a one dimensional, second order polynomial

import hep.aida.*;

public class CreateAndFitDataPointSet {

   public static void main(String[] argv) {    

      IAnalysisFactory     af     = IAnalysisFactory.create();
      ITree                tree   = af.createTreeFactory().create();
      IDataPointSetFactory dpsf   = af.createDataPointSetFactory(tree);
      IFunctionFactory     funcF  = af.createFunctionFactory(tree);
      IFitFactory          fitF   = af.createFitFactory();
      IFitter              fitter = fitF.createFitter("Chi2","uncmin");

      // Create a two dimensional IDataPointSet.
      IDataPointSet dataPointSet = dpsf.create("dataPointSet","two dimensional IDataPointSet",2);

      // Fill the two dimensional IDataPointSet
      double[] yVals2D = { 0.12, 0.22, 0.35, 0.42, 0.54 , 0.61 };
      double[] yErrP2D = { 0.01, 0.02, 0.03, 0.03, 0.04 , 0.04 };
      double[] yErrM2D = { 0.02, 0.02, 0.02, 0.04, 0.06 , 0.05 };
      double[] xVals2D = { 1.5, 2.6, 3.4, 4.6, 5.5 , 6.4 };
      double[] xErrP2D = { 0.5, 0.5, 0.4, 0.4, 0.5 , 0.5 };

      for ( int i = 0; i<yVals2D.length; i++ ) {
        dataPointSet.addPoint();
        dataPointSet.point(i).coordinate(0).setValue( xVals2D[i] );
        dataPointSet.point(i).coordinate(0).setErrorPlus( xErrP2D[i] );
        dataPointSet.point(i).coordinate(1).setValue( yVals2D[i] );
        dataPointSet.point(i).coordinate(1).setErrorPlus( yErrP2D[i] );
        dataPointSet.point(i).coordinate(1).setErrorMinus( yErrM2D[i] );
      }


      //Create a 1d second order polynomial
      IFunction p2 = funcF.createFunctionFromScript("p2", 1, "a+b*x[0]+c*x[0]*x[0]", "a,b,c","",null); 

      IFitData data = fitF.createFitData();
      data.create1DConnection(dataPointSet,0,1);

      IFitResult fittedFunction = fitter.fit(data,p2);

      // Display the results
      IPlotter plotter = af.createPlotterFactory().create("Plot IDataPointSets");
      plotter.createRegions();
      plotter.region(0).plot( dataPointSet );
      plotter.region(0).plot( fittedFunction.fittedFunction() );
      plotter.show();


   }
}







Create an IDataPointSet from another AIDA data source

Through the IDataPointSetFactory it is easy to convert an IHistogram, an ICloud or an IProfile to an IDataPointSet as shown in the example below:

import hep.aida.*;

public class DataPointSetCreateFromData
{
   public static void main(String[] argv) throws java.io.IOException
   {    
      IAnalysisFactory af = IAnalysisFactory.create();

      // Create a tree loading the AIDA objects stored in an AIDA file.
      ITree tree = af.createTreeFactory().create("aidaStore.aida");

      IDataPointSetFactory dpsf = af.createDataPointSetFactory(tree);

      IHistogram1D h1 = (IHistogram1D) tree.find("h1");
      IProfile2D   p2 = (IProfile2D)   tree.find("p2");
      ICloud3D     c3 = (ICloud3D)     tree.find("c3");
        
      // Create IDataPointSets from the the above AIDA objects.
      IDataPointSet dps1DFromHist   = dpsf.create("dps1DFromHist",h1);
      IDataPointSet dps2DFromProf   = dpsf.create("dps2DFromProf",p2);
      IDataPointSet dps3DFromCloud  = dpsf.create("dps2DFromCloud",c3);
   }
}

Table of Contents -- Next Section


$Id: dataPointSets.jsp,v 1.1 2006/03/09 18:22:09 turri Exp $