Cannot Draw Data from ascii file

I am trying to plot the simplest ever ascii file. I want to create a graph using TGraph of an ascii file that has the format

0.2 1.06 0.225 1.15 0.25 1.23 0.275 1.31 0.3 1.39 0.325 1.46 0.35 1.54 0.375 1.61 0.4 1.69 0.45 1.83 0.5 1.98 0.55 2.13 0.6 2.27 0.65 2.42 0.7 2.57 0.8 2.88 0.9 3.19 1 3.51 1.1 3.84 1.2 4.18 1.3 4.53 1.4 4.89 1.5 5.26 1.6 5.65 1.7 6.04 1.8 6.44 2 7.27 2.25 8.37 2.5 9.53 2.75 10.75 3 12.04 3.25 13.38 3.5 14.78 3.75 16.24 4 17.76 4.5 20.96 5 24.38 5.5 28.02 6 31.86 6.5 35.90 7 40.15 8 49.21 9 59.05 10 69.69

I used the following lines

root [1] TGraph g1("p_in_Si.rng", "%lg %lg") root [2] g1->Draw();

The result is a blank canvas!
I am running in on ubuntu 12.04. Note that the exact same lines do work on vista.
Why is this happening and how can it be fixed?

Thank’s in advance.

Hi,

I don’t know what could be wrong, but I just tried (Ubuntu 12.04/3 and ROOT 5.34.10) and I can correctly see the line on the canvas, copying data and commands from your post.

Just for curiosity: what was the command of root[0]?

Thank you very much for your answer! My root[0] command was .ls

I tried it again from zero line and it has the exact same behaviour.

root [0] TGraph g1("p_in_Si.rng", "%lg %lg") root [1] g1->Draw(); Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1

It’s really weird…

My root version is 5.34.03.
I also tried using

root [0] TGraph *g1 = new TGraph("testascii.txt", "%lg %lg"); root [1] g1->Draw(); Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1

but I get the same behaviour. And again the same code works on vista. This is completely crazy.

The only way to get it to work is using this macro

[code]#include <TGraph.h>
#include <TMath.h>
#include <TTree.h>
#include <string.h>

void basic2() {

TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
dir.ReplaceAll(“basic2.C”,"");
dir.ReplaceAll("/./","/");

TFile *f = new TFile(“data1.root”,“RECREATE”); //create file data.root
TTree *T = new TTree(“tree”,“data from ascii file”);
Double_t nlines = T->ReadFile(Form("%sp_in_Si.rng",dir.Data()),“energy:range”);//create tree with cal:channel:amplitude:rms
//printf(" found %lld points\n",nlines); //not needed so

//TFile *f2 = new TFile(“data2.root”,“RECREATE”); //create file data.root
//TTree *T2 = new TTree(“tree2”,“data from ascii file”);
//Double_t nlines2 = T2->ReadFile(Form("%salpha_in_Si.rng",dir.Data()),“energy:range”);

gROOT->SetStyle(“Plain”);
gStyle->SetOptStat(1111);
gStyle->SetOptFit(1111);

TCanvas *c = new TCanvas(“c”, “c”);
c->SetFillColor(5);
c->SetFrameFillColor(10);

TMultiGraph * mg = new TMultiGraph(“mg”,“mg”);

//make graphs
tree->Draw(“range:energy”);
TGraph *gr = new TGraph(tree->GetSelectedRows(),tree->GetV2(), tree->GetV1());
gr->SetName(“myGraph”);
gr->Draw();}[/code]

The thing is that it’s like shooting a fly with a canon! I have to create a root file just to plot a two-column ascii file? In addition, my final point is to make a multigraph. In this case the above macro cannot be used, because I can’t load more that one file at a macro.

Just an idea… Could you type

instead of

Before the version 5.34.10, you had to specify arguments in the Draw method.

I believe that you are a GOD!!!
It works!!!
Thank you so much!!!

However, why is this happening?
In vista, it works and I think that I have the same version.

For historical reason the TGraph class needs the option A to define the axis system.
So when you what to plot a TGraph as a line plot you need to combine the 2 Options A and L

If the option A is not specified then the graph is drawn on the current axis system.

Recently we have added the shortcut pamputt explained.

Note you would have find the answer reading the doc:

root.cern.ch/root/html534/TGraph.html
root.cern.ch/root/html/TGraphPainter.html

Thank you very much for your explanation.
The shock is great when you take the same code from one system to the other and you don’t get the same output.

Very likely you do not have the same version on both systems or the context is a bit different or the code is not exactly the same. This behavior is totally independent from the operating system.