Histogram from a text file

It’s fine now. The problem was the textfile. There was a character on one of the lines that should be there!!

Hi Yus,

I tried to work with the your ROOT macro but it doesn’t work , it shows me an error : variable length array declaration not allowed at file scope !

What should i do ?

Thanks

I believe you simply need to change lines 47 and 48 to the following:

float *x = new float[numL];
float *y = new float[numL];

Note: I have not tested this.

Hello Smith,

I tried but this is happened : warning: ISO C++11 does not allow conversion from string literal to ‘char *’

Try this on line 24

const char * filename = "testfile.txt";

I tried but this happened again :confused:
2017-04-11 15:42:40.834 root.exe[2155:59829] Fatal error: requested non-existing drawable 154
2017-04-11 15:42:40.834 root.exe[2155:59829] This window not found among allocated/deleted drawables

Thanks for your attempts to help me

I’m not sure, it appeared to work for me with an empty text file. Can you post your text file?

MyData.txt (45 Bytes)

Result using your data (I changed the marker style to be easier to see.):

Looks like there may be some issue on your end. I used ROOT 6.08/06.

i have root_v6.09.02, i will test your version and see … hope it will work

Send me your ROOT macro which you have tested with !

Thanks

It is the same as above with the modifications we discussed:
hist2Dfromfilev03.c (2.4 KB)

it doesn’t work :confused:
i have to change the root version i think

Hi,
I am trying to use your code but keep getting the error below. Any help pls.

root [0] .L histo.cpp
/home/munirat/MCA/./histo.cpp:25:20: warning: ISO C++11 does not allow
      conversion from string literal to 'char *' [-Wwritable-strings]
        char * filename = "b.txt";
                          ^
/home/munirat/MCA/./histo.cpp:48:8: error: variable length array declaration not
      allowed at file scope
        float x[numL];
              ^ ~~~~

Did you read the discussion toward the bottom of the thread? These issues were discussed and solved:



Hi,
I followed your correction which clear the error and show something like this but i cant see the plooted values


Thanks

What are the numbers you are plotting? Could you attach your final code (histo.cpp) and your data file?

Also, have you tried this solution instead?

I tried this but the following error occurred please suggest what to do :

TTree MyTree = new TTree(MyTree, MyTree);
Error: Symbol MyTree is not defined in current scope (tmpfile):1:
Error: Symbol MyTree is not defined in current scope (tmpfile):1:

I have used the TGraph to plot data from text file. Is it possible to have widths of the distribution, beacuse when I use Tgraph it shows 0 for all the legends.

When I use TTree also I have the legends of the histogram 0. So how to obtain the std deviation of the plotted distribution.

What I have in my text file is the Mass and the number of the counts, which I want to plot as a 1D Histogram, and need to have its width.

Could someone suggest me some ways to do this ?