Hi, I am new to ROOT and I am trying to create a macro for a 1-D histogram which is filled with a .txt file, but I don’t really know how to do it.
I’ve read some recommendations on other forums on how to do this, but whenever I try I get an empty canvas, meaning that it is not reading the text file nor filling it.
Here is the macro (which is most likely very wrong since I am new to ROOT… pls help) testalphacount.C (268 Bytes)
Here’s the text file in question (it has about 4000+ entries): Am241.txt (8.2 KB)
now, I also have a couple questions:
Does it matter where I save the text file for ROOT to read it into the histogram? if so, where should I save it? How do I read the text file on the macro to fill the histogram?
This means that all the bin numbers above 100 will be outside the histogram range and all the bins between 4095 and 6000 will be the same but in addition the value x will be undefined.
You should first clarify what you want to do exactly. Does one line in the .txt file correspond to one bin of your histogram ?
Hi!
Sorry for any bad wording.
Overall I wanted big bins in my histogram (hence why I chose it to have just 100 bins), and now I see what I did wrong on the SetBinContent loop.
Anyhow, if I wanted each line in the .txt to correspond to one bin, what should I do then?
Thank you for your response!
I left 6000 as maximum value for the X axis. It was intentional to show that the number of bins and the axis values are decoupled. In that particular case it might be more logical to replace 6000 by 4095… that’s up to you to decide.
How do you run the macro ?
Do you have some messages when you it ?
I have the text file Am241.txt and the macro testalphacount.C in the same folder. I start root at the shell prompt from that folder and I do:
$ root
------------------------------------------------------------
| Welcome to ROOT 6.17/01 https://root.cern |
| (c) 1995-2019, The ROOT Team |
| Built for macosx64 on May 22 2019, 06:34:58 |
| From heads/master@v6-16-00-rc1-2164-g789b8e6cd5 |
| Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------
root [0] .x testalphacount.C
root [1]
I usually just open the terminal and open root from the predetermined prompt shell, then I execute the file just how you do it, but I don’t get any messages:
I moved the file to the home directory and it works now!
However, is there a better way to do this? since I don’t want to flood my home directory with text files for root to read it.