// Plot C2_exponentialDecayOverlapping.dat #include "TGraph.h" #include #include #include int fit(){ using namespace std; // controls const char *inputFileName = "C2_exponentialDecayOverlapping.dat"; bool WantToFit = true; // switch for fitting const char *GraphTitle = "C2"; const char *GraphXLabel = "X"; const char *GraphYLabel = "Y"; const char *FitFunc = "expo"; // "[0] * exp ( t * [1] )"; const char *DrawOption = "AP" ; // see https://root.cern.ch/doc/master/classTGraphPainter.html int xmin = 0; int xmax = 100; // create the coordinate arrays vector x; vector y; // create the error arrays // Double_t dx[5] = {0}; // Double_t dy[nArray]; ifstream inFile(inputFileName); if(inFile.is_open()){ cout<<"Input File was opened successfully"<>linex>>liney) { x.emplace_back(linex); y.emplace_back(liney); //cout<SetGrid(); // create the TGraphErrors and draw it TGraphErrors *gr = new TGraphErrors(x.size(),&x[0],&y[0]); // change title and axes titles here gr->SetTitle("C2;X;Y"); gr->SetMarkerColor(4); gr->SetMarkerStyle(21); TAxis *axis = gr->GetXaxis(); axis->SetLimits(x[0],100); gr->Draw(DrawOption); // Define Fit Function if (WantToFit){ TF1 *f = new TF1("f", FitFunc, xmin, xmax); //f->SetParNames("A0","A1","A2"); f->SetParameters(100,-0.02); gr->Fit(f, "B"); cout << "Fitting" << endl; } c1->Update(); return 0; }