Hi.
This topic is to covert .dat file to .root file
I found the basic2.C program in the tutorial and I use it for the conversion.
The few of the entries in my ‘txtdata.dat’ file are given in the file below:
txtdata.txt (314 Bytes)
Following is the txt2root.C program that I use:
#include "Riostream.h"
void txt2root() {
TString dir = gROOT->GetTutorialDir();
dir.Append("/tree/");
dir.ReplaceAll("/./","/");
TFile *f = new TFile("output.root","RECREATE");
/*TH1F *h1 = new TH1F("h1","x distribution",100,-4,4);*/
TTree *T = new TTree("ntuple","data from ascii file");
ULong64_t nlines = T->ReadFile(Form("%stxtdata.dat",dir.Data()),"x:y:z");
printf(" found %llu points\n",nlines);
/*T->Draw("x","z>2");*/
T->Write();
}
I run this program in terminal and get the following:
$ root -l txt2root.C
root [0]
Processing txt2root.C...
x=20014208721000, y=1, z=645
x=20014209165640, y=1, z=6263
x=20014209480080, y=1, z=848
x=20014209657920, y=2, z=503
x=20014209790760, y=1, z=4993
found 18966287 points
root [1] ntuple->Scan("x:y:z","","colsize=30")
***************************************************************************************************************
* Row * x * y * z *
***************************************************************************************************************
* 0 * 20014207860736 * 1 * 645 *
* 1 * 20014209957888 * 1 * 6263 *
* 2 * 20014209957888 * 1 * 848 *
* 3 * 20014209957888 * 2 * 503 *
* 4 * 20014209957888 * 1 * 4993 *
* 5 * 20014209957888 * 2 * 5016 *
* 6 * 20014209957888 * 2 * 5019 *
* 7 * 20014212055040 * 2 * 803 *
* 8 * 20014212055040 * 2 * 558 *
* 9 * 20014212055040 * 1 * 259 *
* 10 * 20014212055040 * 2 * 4015 *
* 11 * 20014212055040 * 1 * 3142 *
* 12 * 20014212055040 * 1 * 2224 *
* 13 * 20014214152192 * 2 * 5006 *
Problem:
Why only the ‘x’ values not same as that of my ‘txtdata.dat’ file?
The ‘y’ and ‘z’ values are correctly stored in output.root file.
Note:
- The original ‘txtdata.dat’ is a big file of size ~980MB.
- I also used the file of size ~314Bytes (which I have attached above), but got the same result.
Any comments or an alternate to solve this?
ROOT Version: 6.26/10
Platform: Ubuntu 22.04.2 LTS
Thanks,
Newbieeee