Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided
hi i want to read my data from csv file to create histogram for column 7, but i am not able to read i have not coded it well, can anybody knows,
{
TCanvas *tc = new TCanvas("ta","tb",1000,700);
float x;
int y;
FILE *fr1;
ifstream myReadFile;
fr1 = fopen ("pedestal-16-01.csv", "rt");
cout<<"Value of line: "<<fr1;
char line1[80];
int i = 2;
double sum=0;
double sumw=0;
for(int j=0; j<1; j++)
fgets(line1, 80, fr1);
// cout<<"This is working for loop 1st";
vector<double> vx,vy;
while (fgets(line1, 80, fr1) != NULL) {
sscanf (line1, "%e %d", &x, &y);
// cout<<"this is working while after for";
vx.push_back(x);
vy.push_back(y);
i++;
cout<<"i= "<<i<<endl;
}
myReadFile.close();
double deltax = vx[1]-vx[0];
double xmax = vx[0];
double xmin = vx[i-1];
double nbin = i;
cout <<nbin<<endl;
TH1D *histo = new TH1D("histo","histo",nbin,xmin,xmax);
cout<<"This is Working after while loop ";
for(int k=0; k<nbin; k++){
sum+=vx[k]*vy[k];
sumw+=vy[k];
for(int w=0;w<vy[k];w++){
histo->Fill(vx[k]);
}
}
histo->SetTitle("1");
histo->GetXaxis()->SetTitle("c)");
histo->GetYaxis()->SetTitle("number of events");
histo->Rebin(5);
histo->Draw("Hist");
}