Initially, I had posted this somewhere else and I noticed it had not reached members. So, I think here is a correct place to post it.
I have learned to model a set of experimental data according to some theory that is known in advance and then find the best parameters that will fit the data based on Xi squared method. Now, I would like to extend the code to a level that it can actually evaluate/predict the “model” at a particular value which is given in terms of (some mean+/-error). Given the best-fit parameters, the code should be able to evaluate the model and then give the result in (mean+/-stdev). I could not find any extension from root website to add to my code. Your help is greatly appreciated. Below is my original code.
[code]#include
#include <math.h>
#include “TFile.h”
#include “TF2.h”
#include “TH1.h”
#include “TH1F.h”
#include “TH2F.h”
#include “TCanvas.h”
#include “TFitResult.h”
#include “TMath.h”
#include “TGraphErrors.h”
#include “TGraph2DErrors.h”
#include “TLegend.h”
#include “TApplication.h”
#include “TFormula.h”
#include “TGraphPolar.h”
#include “TLatex.h”
#include “TMinuit.h”
#include “TProfile.h”
#include “TRandom3.h”
#include “TStyle.h”
void format_line(TAttLine* line,int col,int sty){
line->SetLineWidth(3); line->SetLineColor(col);
line->SetLineStyle(sty);}
double the_model(double* vars, double* pars){
/return pars[0] + pars[1] * std::pow(1 + pars[2] * std::pow(vars[0], pars[3]), -1) ;}/
if (vars[0] < pars[2])
return pars[0] * std::pow((vars[0] / pars[2]), pars[1]);
else
return pars[0] * std::pow((vars[0] / pars[2]), pars[3]) ;}
int myfit(){
TCanvas* c1=new TCanvas();
c1->SetGrid();
TGraphErrors graph_data("./mydata=.txt", “%lg %lg”);
graph_data.SetTitle(“Plot; X; Y”);
graph_data.SetMarkerStyle(kMultiply);
graph_data.SetFillColor(kBlack);
graph_data.Print();
gStyle->SetOptTitle(1); gStyle->SetOptStat(0);
gStyle->SetOptFit(1111); gStyle->SetStatBorderSize(0);
gStyle->SetStatX(.89); gStyle->SetStatY(.89);
TF1 model(“model”, the_model,18.0,24.0,4);
double a=1; double b=1; double c=1; double d=1;
model.SetParameters(a,b,c,d);
model.SetParNames(“a”,“b”,“c”,“d”);
format_line(&model, kBlue,1);
model.SetParameter(0, -22.93);
model.SetParameter(1, 1.385);
model.SetParameter(2, 21.06);
model.SetParameter(3, 2.853);
TFitResultPtr frp = graph_data.Fit(&model, “S”);
frp->Print();
TMatrixDSym covMatrix (frp->GetCovarianceMatrix());
covMatrix.Print();
graph_data.GetYaxis()->SetRangeUser(-29,-20);
graph_data.DrawClone(“APE”);
}
#ifndef CINT
void StandaloneApplication(int argc, char** argv) {
// eventually, evaluate the application parameters argc, argv
// ==>> here the ROOT macro is called
myfit();
}
// This is the standard “main” of C++ starting
// a ROOT application
int main(int argc, char** argv) {
TApplication app(“ROOT Application”, &argc, argv);
StandaloneApplication(app.Argc(), app.Argv());
app.Run();
return 0;
}
#endif[/code]