I am very new to ROOT and just learning it and I am having a problem understanding some of the tutorials and how to adapt them for my use. I have a very simple linear fit code that I would like to add error bars to. I am having a hard time finding a tutorial for error bars that is not so complex that I can merge it with my simple program. Does anyone have any suggestions?? I’ve pasted a copy of my code below.
#include "TGraphErrors.h"
#include "TF1.h"
#include "TRandom.h"
#include "TCanvas.h"
#include "TLegend.h"
#include "TMath.h"
void linearfit()
{
Int_t n=6;
Double_t x[6] = {1,2,3,4,5,6};
Double_t y[6] = {139,99.75,88.4,121.8,90.6,149};
Double_t c[6] = {1e6,.5e6,.25e6,1e5,.5e5,.25e5};
Double_t e[6];
for (i=0; i<6; i++)
{
e[i] = y[i]*1/sqrt(c[i]);
}
TCanvas *myc = new TCanvas("myc",
"linear fits");
//myc->SetFillColor(42);
myc->SetGrid();
//Generate points along a 1st degree polynomial:
TGraphErrors *gre1 = new TGraphErrors(6, x, y, 0, e);
gre1->Draw("a*");
//Fit the graph with the predefined "pol3" function
gre1->Fit("pol1");
}