Hello, I am trying to extract data from geant4 root file called inelastic.root. What I want is numbered data for x-axis and y-axis.
I tried to follow How to extract a data from dna.root file? post here but I was able to do the geant4dna file posted there but unable to do so even when I change the code to match my file name.
Can someone help? I am a complete newbie user to root as well as coding.
I attached my root file for reference. Thank you for your help! inelastic.root (33.6 KB)
C:\Users\bellenot\rootdev>root -l
root [0] TFile *f = TFile::Open("inelastic.root")
root [1] f->ls()
TFile** inelastic.root
TFile* inelastic.root
KEY: TH1D 2;1 kinetic energy of gamma
KEY: TH1D 4;1 kinetic energy of protons
KEY: TH1D 5;1 kinetic energy of deuterons
KEY: TH1D 6;1 kinetic energy of alphas
KEY: TH1D 7;1 kinetic energy of nuclei
KEY: TH1D 10;1 Q = Ekin out - Ekin in
root [2]
You can also start a TBrowser and inspect/draw the content of the file (see the screenshot below):
C:\Users\bellenot\rootdev>root -l
root [0] TFile *f = TFile::Open("inelastic.root")
root [1] f->ls()
TFile** inelastic.root
TFile* inelastic.root
KEY: TH1D 2;1 kinetic energy of gamma
KEY: TH1D 4;1 kinetic energy of protons
KEY: TH1D 5;1 kinetic energy of deuterons
KEY: TH1D 6;1 kinetic energy of alphas
KEY: TH1D 7;1 kinetic energy of nuclei
KEY: TH1D 10;1 Q = Ekin out - Ekin in
root [2]
You can also start a TBrowser and inspect/draw the content of the file (see the screenshot below):
Hi, first thanks for your reply. I think my purpose wasn’t clear though, I am able to draw the graph already but I want to extract the graph into a file with data only i.e text file or excel file.
Thank you so much! I followed your code and the output was displayed on the screen but not in the text file. I can just copy and paste from here though. Thank you again!
Thank you so much! I followed your code and the output was displayed on the screen but not in the text file. I can just copy and paste from here though. Thank you again!
[quote=“jeonyboy”]Thank you so much! I followed your code and the output was displayed on the screen but not in the text file. I can just copy and paste from here though. Thank you again!
[/quote]
You’re welcome! And since you are using ROOT 5, you should do following: