#include "fstream" #include "iostream" #include "stdio.h" #include "string.h" #include "stdlib.h" #include "TGraphErrors.h" #include "TH2F.h" #include "TCanvas.h" #include "TF1.h" #include "math.h" #include "TMultiGraph.h" #include "TMinuit.h" using namespace std; Double_t afunc(Double_t *x, Double_t *par){ Float_t fitval = 0; fitval = (par[0] + par[1]*sin(x[0])); return (fitval); } void testfit(){ const int bins = 12; double phi[bins] = {0.27, 0.77, 1.29, 1.81, 2.34, 2.90, 3.39, 3.89, 4.47, 4.99, 5.50, 6.00} ; double asym[bins] = {0.014, 0.027, 0.012, 0.030, 0.035, 0.005, -0.008, -0.038, -0.050, -0.021, -0.021, -0.014 } ; double asym_err[bins] = {0.00653693, 0.00587808, 0.00726165, 0.00876149, 0.0107372, 0.00865679, 0.0077391, 0.010013, 0.00988164, 0.00703232, 0.00586795, 0.00651871} ; double null[bins] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; TGraphErrors *gr1 = new TGraphErrors(bins, phi, asym, null, asym_err); // Draw Graph gr1->Draw("AP"); TF1 *gr_fit = new TF1("gr_fit", afunc, 0.0, 6.28, 2); gr_fit->SetParName(0, "Constant"); gr_fit->SetParName(1, "sin #phi moment"); gr_fit->SetParameter(0, 0.0); gr_fit->SetParameter(1, 0.02); gr_fit->SetParLimits(0, -.1, .1); gr_fit->SetParLimits(1, -0.2, 0.2); gr1->Fit(gr_fit, "RV"); gr_fit->Draw("same"); }