Converting file to ascii


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.18
Platform: Not Provided
Compiler: C++


Hi

I am trying to convert my root file to ascii but when I do that I get a straight line i.e. my program produces an ascii file that is a straight line, however, my root file is an exponential decay. Please let me how I can fix this to get an ascii with an exponential decayascii1.C (559 Bytes) decay_600ns.root (12.0 KB)

Your file contains a TCanvas:

root [1] f1->ls()
TFile**		decay_600ns.root	
 TFile*		decay_600ns.root	
  KEY: TCanvas	Time_distr;1	

and you try to it it in a TH1S …

  TH1S *hGam = (TH1S*) f1->Get(name);

The TCanvas is the output. So I was trying to ocnvert a root file to ascii that way, I don’t know if there’s a better way.

A TCanvas is not a TH1S. Have a look in the list of primitives of the canvas if you have a TH1S. You can do Time_distr->ls()

I had a look and its not on the list of primitives. The list is attached. I suppose then that the way I am converting is not right?

As you can see you have an histogram in that canvas. It is called cube2_zx_py. You can do:

TCanvas *C = (TCanvas*) f1->Get(name);
TH1D h = (TH1D*)C->GetListOfPrimitives()->FindObject("cube2_zx_py");

I have just tried doing this several times and it does not work. Also Iam just a beginner in root and some things are not so trivial to me.

To help you further we will need your root file.

Ok it is attached.

decay_600ns.root (12.0 KB)

root [0] auto f = new TFile("decay_600ns.root");
root [1] auto C = (TCanvas*) f->Get("Time_distr");
root [2] auto h = (TH1D*)C->GetListOfPrimitives()->FindObject("cube_2_zx_py");
root [3] h->Print()
TH1.Print Name  = cube_2_zx_py, Entries= 3353172, Total sum= 3.27269e+06
root [4] 

Ok thanks. Where is the ascii generated here?

do:

root [3] .> ascii.dat
h->Print("all") 
.>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.