Hi,
I want to plot a TGRaph with errors by reading the x, y and the corresponding error of data points from a text file of 100 entries. Unfortunatly I am not able to plot it correctly and I dont undertant what is the problem. I attach my macro and text file here with :
#include <TRandom.h>
#include <TMath.h>
#include <TH1.h>
#include <TH2.h>
#include <TFile.h>
#include <TTree.h>
#include <TF1.h>
#include
#include
#include
#include
#include
#include
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
using namespace std;
TString currentfile;
TRandom rnd;
void Der_Err()
{
Double_t data[8];
char line[150];
Int_t len=150;
Double_t x[100], y[100], Err_y[100], Err_x[100];
Int_t i, j;
strstream *InOut;
ifstream simu;
simu.open(“Der_Err_1.txt”);
if(!simu)
{
cout << “Could not open the simulation file !” << endl;
exit(-1);
}
else
{
cout.setf(ios::showpoint);
cout << “Reading GEF input file” << endl;
}
for(j=0;j<100;j++) {
for(i=0;i<5;i++)
{
data[i] = 0.0;
}
simu.getline(line,len);
InOut = new strstream();
*InOut << line;
for(i=0;i<5;i++)
{
*InOut >> data[i];
}
delete InOut;
x[i]= data[0];
y[i]= data[1];
Err_x[i]= data[2];
Err_y[i]= data[3];
cout<<x[i]<<“\t”<<y[i]<<“\t”<<Err_x[i]<<“\t”<< Err_y[i]<<endl;
}
TGraphErrors *ggamma = new TGraphErrors(100,x,y,Err_x,Err_y);
ggamma->SetMarkerColor(kGreen+3);
ggamma->SetMarkerStyle(20);
ggamma->SetMarkerSize(1.6);
ggamma->Draw(“ALP”);
}
and here is the text file
Der_Err_1.txt (3.3 KB)
When I run the above macro, I am able to assign the values to the array but when I plot I get :
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided