Plotting ASCII files in ROOT

后端 未结 3 1603
误落风尘
误落风尘 2020-12-22 12:11

I am trying to write a small macro that reads data from an ASCII file that has 4 columns. But I want to graph only the second the third columns as (x, y).

3条回答
  •  借酒劲吻你
    2020-12-22 12:31

    You can use the "CSV Contructor" as shown above or simply generate an empty TGraph (or TGraphErrors), loop over your CSV file and add points. Example with some constant error bars given in the first line/header:

        ifstream infile("input.csv");
    
        TGraphErrors *g1 = new TGraphErrors();
        g1->SetName("name_for_graph");
        g1->SetTitle("Title for your Graph;x values [x unit];y values [y unit]");
    
        Int_t pt=0, nv=0;
        Double_t e_vc=0.;
        Double_t vs=0., vc=0.;
    
        infile >> e_vs >> e_vc;
    
        while (1) {
                if(!infile.good()) break;
    
                infile >> vs >> vc;
    
                g1->SetPoint(pt, vs, vc);
                g1->SetPointError(pt, e_vs, e_vc);
                pt++;
        }
        infile.close();
    

    ...

        g1->Draw("APX");
    

提交回复
热议问题