1 / 11

HepFitting : a C++ fitting API for HEP

HepFitting : a C++ fitting API for HEP. => Features => Usage => Getting started. Features. OO API for batch fitting in the LHC++ environment (no graphics)

erma
Télécharger la présentation

HepFitting : a C++ fitting API for HEP

An Image/Link below is provided (as is) to download presentation 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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. HepFitting : a C++ fitting API for HEP => Features => Usage => Getting started

  2. Features • OO API for batch fitting in the LHC++ environment (no graphics) • main fitting class HEPHistoFit , derived from either NAGmin or Cminuit , inherits the whole Gemini’s functionality • easy switch between minimizers at compilation time • -D_MINUIT_ , in order to use Minuit • fits models to HistOOgrams and to general sets of data points • arbitrary models and models composed of pre-defined components (Gaussian, polynomial, exponential) • chi-squared and Poisson maximum likelihood fits • fitting in arbitrarily selected sub-regions • easy creation of confidence regions • small (~1100 lines, ~20% comments)

  3. Steps to go • Create a fitting objectHEPHistoFit myFitObj; • Load dataHepRef(Histo1D) histo = … ; myFitObj.setHistogram(*histo);orint p; // space dimensionality int n; // number of data points double x[], fval[], ferr[]; myFitObj.setDataPoints(p,n,x,fval,ferr);

  4. Steps to go, continued • Define a model • create a model object of the type MODELfun// e.g. capture a user model function myFun()MODELfun myModel(myFun, spaceDim, noOfParms); • assign the model object to the fitting objectmyFitObj.setModel(&myModel); • Manipulate fit range, if necessary (full flexibility) • Perform the fit, obtain results, e.g.myFitObj.perform(Chi2fit); myFitObj.perform(PoissonMLfit);

  5. Pre-defined components • Gaussian Gparm1 * exp[ -0.5*( (x-parm2)/parm3 )^2 ] • Polynomial Pnparm1 + parm2*x + parm3*x^2 +…+ parm(n+1)*x^n • Exponential Eexp[ parm1 + parm2*x ]

  6. Single-component models Use specialized model object constructor. Suitable model function, which also computes gradient, and an objective function suitable for the given model and fit criterion are created automatically. MODELfun model1(”G”); // Gaussian model MODELfun model2(”P2”); // second-degree polynomial model HEPHistoFit myFitObj; // create a fitting object // load some data ... myFitObj.setModel(&model1); myFitObj.perform(Chi2fit); ... myFitObj.setModel(&model2); myFitObj.perform(Chi2fit);

  7. Multi-component models • Derive your private class from MODELfun • Define the expression by overriding the virtual member function modelfun() • reference the components in the expression as f(0,x,p), f(1,x,p),… • modelfun() should return the value of the expression • if only the four basic operators (+-*/) are used to build the expression, there is a simple way to provide the gradient:“Look at the components f(i,x,p) as if they were all functions of the same single variable, use df(i,x,p) to denote derivatives, apply well-known differentiation rules and assign to g the resulting expression.” • Define the components through a specialized MODELfun constructor or via MODELfun.setComponents(char *string)

  8. Example: derived model class class myModelObject : public MODELfun{ public: // allow for setting components in the class definition myModelObject(char *components) : MODELfun(components){} // override modelfun, to define the expression // here, it’s simply the product of two components double modelfun(const double x[], const double p[], array_n<double>& g, int code){ // compute gradient, if requested if(code==2) g = df(0,x,p)*f(1,x,p) + f(0,x,p)*df(1,x,p); // return model function value return f(0,x,p)*f(1,x,p); } }

  9. Example: continued // use the derived class to define a model which is the product // of a Gaussian and a second-degree polynomial HEPHistoFit myFitObj; // fitting object myModelObject modObj(”P2G”); // model object with components myFitObj.setModel(&modObj); // model assignement // load data, set initial parameters’ values e.t.c. // fix the first parameter of the Gaussian at 1 to ensure // identifiability (it’s the 4th parameter preceded // by 3 parameters of P2) myFitObj.parmDef(4,”Gmass”,1,1,1,1); // perform a fit

  10. Errors and confidence regions => default one-sigma errors => automatic selection of the error parameter according to the fitting method (UP-parameter in the Minuit-jargon) => Hessian-based and Minos confidence regions according to confidence level, e.g. // define contour objects GEminiContour c1('*'), c2('+’); // create Hessian- and Minos-based 90% regions for parms 1 and 3 myFitObj.ellipticalConfidenceRegion(1, 3, c1, 0.90); myFitObj.minosConfidenceRegion (1, 3, c2, 0.90); // overlay and plot (c1+c2).plot();

  11. Getting started • Copy, run and modify complete examples and GNUmakefile from • $(LHCXXTOP)/share/HEPFITTING/pro/examples • On-line and PostScript documentation available through the main LHC++ page • Environment and library instalation details in • $(LHCXXTOP)/share/HEPFITTING/pro/doc/HEPfitlib.html

More Related