1 / 21

# Fitting in AIDA - PowerPoint PPT Presentation

Fitting in AIDA. General Concepts Requirements JAIDA Examples Interfaces Overview Conclusions. General Concepts. The main players: Data Set the actual data, i.e. an Histogram Model or Function a set of parametric shapes to describe the data Fitter

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about ' Fitting in AIDA' - lihua

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

• General Concepts

• Requirements

• JAIDA

• Examples

• Interfaces Overview

• Conclusions

• The main players:

• Data Set

• the actual data, i.e. an Histogram

• Model or Function

• a set of parametric shapes to describe the data

• Fitter

• the engine that finds the best fit between the data and the model by changing a set of paramters

• Fit Method

• the method used by the fitter to evaluate the “best fit”, i.e. Chi2, Least Squares etc.

• Fit Result

• the actual result of a fit

• new set of parameters

• covariance matrix

• contours

• scans

• Optimizer

• the engine that calculates the minimum (or maximum) of the problem

General Concepts Optimizing

Optimizer

Model/Function

Result

Data Set

Model/Function

User

General Concepts Fitting

Optimizer

Fitter

Fit Result

• Easy to use and configure

• change fit method

• change data set

• change model

• Minuit is a must, but not the only product. Many optimizers are available.

• Accept user-provided custom functions

• Straightforward way to build complicated models

• Add, multiply and convolute (analytically when possible)

• Same interface for binned and unbinned fits

• binned fit to histogram

• unbinned fit to a tuple

• Similar interfaces for fitting and optimization

• Multiple fit methods supported

• least squares

• chi2

• Support for simultaneous fits

• fits over different data sets

• JAIDA is our Java implementation of AIDA

• http://java.freehep.org/jaida/index.html

• Fitting implementation:

• fit methods

• least squares

• “leastsquares”, “ls”

• chi2

• “chi2”, “chisquared”

• clever chi2

• “cleverchi2”, cleverchisquared”

• binned maximum likelihood

• “bml”, “binnedmaxlikelihood”, binnedmaximumlikelihood”

• unbinned maximum likelihood

• “uml”, “unbinnedmaxlikelihood”, “unbinnedmaximumlikelihood”

• engines

• Minuit

• Uncmin (pure java code)

• built-in functions

• gaussian “g”

• “amplitude”, “mean”, “sigma”

• exponential “e”

• “amplitude”, “exponent”

• polynomials “p0”,”p1”,…

• “p1”,”p2”…

• Clear distinction between optimization and error analysis

• easy to adopt new optimizers

• The examples below are based on JAIDA

• other implementations might have different fit methods or optimizers.

• Examples Binned fit to an IHistogram

//Create the factories

IFitter fitter = af.createFitFactory().createFitter();

//Perform the fit

IFitResult result = fitter.fit(hist,”g”);

//Plot the result

IPlotter p = af.createPlotterFactory().create();

p.region(0).plot(hist);

p.region(0).plot(result.fittedFunction());

p.show()

Examples Binned fit to a 2D Histogram

//Create the factories

IFunctionfactory funcFactory = af.createFunctionFactory( tree );

IFitter fitter = af.createFitFactory().createFitter("chi2","minuit");

//Create a scripted function, a sum of two gaussians

IFunction func = funcFactory.createFunctionFromScript("twoDdistr",2,"N*(a*exp( -(x[0]-mu0)*(x[0]-mu0)/(2*s0*s0) )+(1-a)*exp( -(x[0]-mu1)*(x[0]-mu1)/(2*s1*s1) ))*exp( -(x[1]-mu2)*(x[1]-mu2)/(2*s2*s2) )","N,a,mu0,s0,mu1,s1,mu2,s2","",null);

//Set the initial parameters

double[] initialPars = { 1, 0.8, 5, 1, 5, 2, 0, 1};

func.setParameters( initialPars );

//Control the parameters and set constraints

fitter.fitParameterSettings("mu2").setFixed(true);

fitter.fitParameterSettings("a").setBounds(0.5,0.9);

fitter.fitParameterSettings("a").setStepSize(0.001);

fitter.fitParameterSettings("s1").setBounds(2,4);

fitter.fitParameterSettings("s1").setStepSize(0.1);

fitter.setConstraint("s0 = s2");

fitter.setConstraint("mu0 = mu1");

//Perform the fit

IFitResult fitResult = fitter.fit(hist2d,func);

Examples Unbinned Fit

//Create the factories

IFunctionfactory funcFactory = af.createFunctionFactory( tree );

IFitFactory fitf = af.createFitFactory();

IFitter fitter = fitf.createFitter(“uml",“uncmin");

IFitData data = fitf.createFitData();

ITupleFactory tupf = af.createTupleFactory(tree);

//Create a function, control the parameters, set bounds and constraints…

//…

//Get and ITuple and create an IEvaluator for its columns

ITuple tuple = (ITuple) tree.find(“myTuple”);

IEvaluator eval = tupf.createEvaluator(“sqrt(px*px + py*py)”);

//Connect the data set to the ITuple through the IEvaluator

data.createConnection(tuple, eval);

//Perform the fit

IFitResult fitResult = fitter.fit(data,func);

Interfaces Overview The factories

• From IAnalysisFactory

• IFitFactory createFitFactory()

• IFunctionFactory createFunctionFactory(ITree)

• IFitFactory creates

• fitters

• data sets (for advanced data handling)

• e.g. select columns from tuple

• IFunctionFactory creates

• functions

Interfaces Overview IFitFactory

• Methods

• IFitData createFitData()

• IFitter createFitter(fitMethod,engine)

• Through IFitData connections to all the AIDA data objects are established

• IFitter is the main fitting engine

Interfaces Overview IFunctionFactory

• IFunction creatFunctionByName(name,model)

• IFunction createFunctionFromScript(……)

• IFunction cloneFunction(name, function)

• IFunctionCatalog catalog()

• “byName” are built-in functions

• “fromScript” are scripted functions

• user-defined functions

• e.g. define “Gauss+Gauss+Pol1+…” to be “myFavoriteFunc”

• …that can be added to a function catalog for future use

Interfaces Overview IFitter

• Do the fit

• IFitResult fit(“data”,”model”,”pars”)

• IDataPointSet createContour(IFitData, IFitResult…..)

• IDataPointSet createScan1D(IFitData, IFunction…)

• Configure the fitter

• void setFitMethod(String)

• String fitMethodName()

• void setEngine(String)

• String engineName()

• Control the parameters in the fit

• IFitParameterSetting fitParameterSettings(String)

• String[] listParameterSettings()

• void resetParameterSettings()

Interfaces Overview IFitter

• Constraints

• void setConstraint(String)

• String[] constraints()

• void resetConstraints()

• The fitter does not change the function; the fitted parameters are in the IFitResult

Interfaces Overview IFitResult

• Fit outcome

• int fitStatus()

• int ndf()

• double quality()

• Fit info

• String fitMethodName()

• String engineName()

• String[] constraints()

• Fitted function

• IFunction fittedFunction()

• String[] fittedParameterNames()

• double fittedParameter(String)

• double fittedParameters()

• IFitParameterSettings fitParameterSettings(String)

• Errors

• double covMatrixElement(int,int)

• double[] errors()

• double[] errorsMinus()

• double[] errorsPlus()

Interfaces Overview IFitData

• Connect the data

• create1DConnection(…)

• create2DConnection(…)

• create3DConnection(…)

• createConnection(…)

• Ranges

• IRangeSet range(int)

• Utils

• int dimension()

• reset()

Interfaces Overview IFunction

• General

• double value(double[])

• int dimension()

• int numberOfParameters()

• Variables

• String variableName(int)

• String[] variableNames()

• Parameters

• String[] parameterNames()

• double[] parameters()

• double parameter(String)

• int indexOfParameter(String)

• void setParameter(String,double)

• void setParameters(double[])

Interfaces Overview IFitParameterSettings

• Control a parameter

• Bounds

• double lowerBound()

• void setLowerBound(double)

• double upperBound()

• void setUpperBound()

• boolean isBound()

• void setBounds(double, double)

• void removeBounds()

• Step

• void setStepSize(double)

• double stepSize()

• Fix

• boolean isFixed()

• void setFixed(boolean)

• Other

• void reset()

• String name()

• AIDA has a complete set of interfaces for fitting

• flexible interfaces

• room for improvements

• JAIDA future:

• Extend the pool of optimizers

• Implement more built-in functions

• Allow model-building