How to write a histogramming code in root

I know that my question is too beginner :blush: . Anyhow I have to work with Geant4 and I need to get a histogram.
I am a newbie to both LInux and c++
I am running ubuntu 10.10 , I have installed root successfully .
I don’t know to write a histogramming code from where I have to start. I have had a look at documentations but didn’t find any sample code. I will really appreciate if any one can give me a good hint.
Many thanks in advance

Well… first of all you can try creating a simple histogram at the command line! :slight_smile:
Type root in a bash shell (= Terminal), then write these simple lines of code:

root[0] TH1D *myFirstHisto = new TH1D("myFirstHisto","My first histogram in ROOT!", 100,-5,5)
root[1] for(int i = 0; i < 100000; i++)myFirstHisto->Fill( gRandom->Gaus(0,1) )
root[2] myFirstHisto->Draw()
root[3] myFirstHisto->Fit("gaus")

I think this is the best way to enjoy ROOT (so was for me)! Ah, press ENTER after each line!

Another hint: start reading the ROOT tutorials! (in the $ROOTSYS/tutorials folder or via web
at )… in the hist directory there are many script examples.

Good luck!


Thank you for your response. Actually I have to learn working with Geant4. I have installed both AIDA and root for analysis.
they have their own histogramming code, I ran those codes but the output is a .root file.
I don’t know if I can open this file in root!
I have trasfered my output file with the name AnaEx01.root to the /root7macros and then I opened root and ,tried to load and open this file but I got:
Bad source file(binary) ~/root/macros/AnaEx01.root interpreter error recovered

Thanks again in advance

Sorry, I thought you were a ROOT beginner! Anyway… in general if you have a .root file you should be able to open it via TBrowser, i.e. open ROOT in your working directory, type at the command line

and browse your .root file if possible.

On the other hand if it’s a binary file maybe it contains histogram data as a binary sequence. In this case you can convert it in a ASCII .dat file of floats or doubles with a standard C or C++ program.


Hej Pacher,
Really thanks for your nice help