If yes, you can have a ROOT macro that loads the histo from the file and invokes Print, and when you run that macro (e.g. histo.C) you redirect the output to a file with root -q test.C > output.txt.
Thank you very much for the fast response to my question!
First of all, I did save the histogram in a .root file. And your method truly worked. It really redirected the output from the terminal to a .txt file!
Beyond that, it would be much appreciated if you could help me shed some more light into this. TO be more specific, could I present this output in a more “classy” way in the .txt file? Instead of using the h5->Print(“all”);, is there any other command I could use like cout or something like that to present them in a more organized way?
Thank you in advance for your insight into this matter
stekoul
After studying carefully the aforementioned thread, I would like to ask you a question mainly based on this remark I made yesterday about presenting the data in a more “classy” way. First of all, I have succeeded in redirecting the output from the terminal to a file as discussed yesterday for a TH2 histo. Afrterwards, for a TH1 histogram, I have successfully written in an input file the bin centers and the bin content of each data point (as you can see on the uploaded macro). histogram_txt.C (927 Bytes)
So my question is this: In the case of a TH2 histogram, how can I make a similar type of macro? I suppose that I have to make a double “for” loop in order to extract the data points (x,y) and the counts for each bin. But I’m really in a loss on how to actually write this macro.
This is really my last question in this thread. I’m sorry for the inconvenience.
stekoul
I believe that I didn’t phrase my question correctly. I meant to say the x,y coordinates of each point and not the values of binx and biny. In the following simple macro i have made a 2D histogram filled with random numbers. hIHisto.C (432 Bytes)
For instance, with the command h2->Print(“all”); we print binc and the coordinates x,y.
So, I want to do the same by printing these values into an ascii file (.dat , .txt etc.) in proper format by also using “for” loops instead of using the aforementioned command.
I get this (an excerpt of the result):
5.5 0.5 0
5.5 1.5 0
5.5 2.5 0
5.5 3.5 0
5.5 4.5 0
5.5 5.5 1
5.5 6.5 0
5.5 7.5 0
5.5 8.5 0
5.5 9.5 0
And it doesn’t return me for example the (x,y) = (5.2,5.55) that I wanted.
Sorry for keep asking questions but I’m a newbie… I’m very grateful for giving me all this useful feedback! It is really helpful.
This gives you the impression that the points inside it are individual points separate from the bin center, ie the original points you added at first. But this is not really the case. The bin content is just a value, and then ROOT paints individual points randomly scatter around it, see:
For each cell (i,j) a number of points proportional to the cell content is drawn. A maximum of kNMAX points per cell is drawn. If the maximum is above kNMAX contents are normalized to kNMAX (kNMAX=2000)
Or do you rather want to draw your data using a TGraph class, where you can have many many points, without any binning, and you can later retrieve the exact coordinate of each of them?
I will give you an exact overview of what i want to do: I have a .root file which contains a large amount of experimental data. Using this .root file let’s just say that I have made a TH2 histogram (“colz”) correlating two parameters of the file under certain conditions.
So, for a next step, I want to isolate these events that are now depicted in this histogram (meaning that I want their coordinates, or to be more precise, their precise values of the parameters) in order to make a further analysis and possible 1D distributions of them.
This is the case that I am dealing with! All of the above excerpts were just parts of some macros that I do as exercises in order to achieve the big picture; Which is what I have written now in this reply.
Once you learn about the correlation between the two parameters, write it down or store it into a variable in your script, for example you want to analyze specifically the area where x > 2 and x <= 3.5.
With that, you need to traverse again your TTree and apply your filter. You cannot do it directly on the TH2F because your data points are lost (binned). So start again from the first entry in your TTree until the last one. On every iteration, check if x is outside the desired range. If that’s the case, continue with the next iteration instead of analyzing those data.