I have the root file,now i need to generate the text file from it i.e. the graph contents which is the x and the y values
which would be seen as two columns in that text file like saying getting back the ASCII values of the data in the .txt format from the .root file.
I am doing the following :-
void use()
{
TFile *f=new TFile("10th nov 04.root"); // opens the root file
TH1F * tr=(TH1F *)f->Get("htemp");
float a,b;
ofstream myfile;
myfile.open ("new example.txt");
myfile << "a b\n";
for (int idx=0; idx <tr->GetNbinsX();idx++) {
a = tr->GetBinCenter(idx);
b = tr->GetBinContent(idx);
cout << a << " " << b << endl; //print to the screen
myfile << a << " " << b << "\n"; //write to file
}
myfile.close();
}
the .txt file is getting generated but its blank,it doesn’t have any data in it from the graph.
Now what’s the error in this ? yours help is welcome !
I am attaching the .root fie which you can see. 10th nov 04 N.root (19.9 KB)
sorry for the misprint there,its actually 10th nov 04 N.root in the above program,so make the changes accordingly
although i did it right while performing the above.