How many data points can TGraphErrors class use to plot?

I used TGraphErrors class to plot, when the data points are much larger like in the file upload, the task would be killed, so how many data points can TGraphErrors class use to plot?
Silicon.txt (127.2 KB)


ROOT Version: 6.24
Platform: Ubuntu 20.04
Compiler: Gcc 9.3


Your data file has just 3815 data lines so no problem for a TGraph.

Note, however, that ROOT will not be able to read your data file directly. You need to write a “parser” for this kind of input data (or you need to edit this file and remove everything except data points).

Silicon.C (121 Bytes)
Silicon.txt (123.0 KB)

Sorry i made a mistake at describing the problem, i wrote a “parser” to read the data in file “Silicon.txt”,
the .cpp file is upload, i add data to TGraphErrors class object through the AddPoint() function, in the process of running the application, the task would be killed.

Plot_CS.cpp (777 Bytes)

The file is named “Silicon.txt”, but your macro tries to open “SIlicon”.

i rename the file “Silicon” to “Silicon.txt” for uploading.

So as Wile said, you still need to write a proper parser to read the data file, or (proably easier for you) edit it and leave in it only the 2 columns of data, nothing else, so that it can be read by your macro.

when the data lines are little, the .cpp file works well, i do not know why not for file with so larger data lines.

void Plot_CS()
{
    auto c1 = new TCanvas("c1","Cross Section Plot",1200,1200);
    c1->SetLogx();
    c1->SetLogy();

    auto gr = new TGraph();
    ifstream silicon("Silicon.txt");
    std::string line;

    // Skip the first 12 lines
    for (int i=1;i<=12;i++) getline(silicon,line);

    double x,y;
    while (getline(silicon,line)) {
       sscanf(line.c_str(),"%lg %lg",&x,&y);
       if (line.find("/") < 32) continue;
       gr->AddPoint(x,y);
    }

    gr->Draw("AL");

}

root Plot_CS.cpp gives:

couet, thanks!
i revised my c++ code, now i works well!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.