Hi,
I am very new to ROOT. My task is to read a series text files with 256 X 256 data matrix and do pattern recognition analysis in each of the files.
Can you please suggest me the things I need to focus to achieve this also, an example that imports a 256 X 256, 2D histogram of data to root and plots it as well will be hugely appreciated.
//open the file in rading mode
FILE *file=fopen("mytext.txt","r");
//create a 256x256 histogram
TH2D *h2d= new TH2D("h2d","My histogram",256,0,256,256,0,256);
double z;
int i,j;
//for loops to read 256x256 file
for(i=1; i<=256; i++)
for(j=1; j<=256; j++)
{
//read the number
fscanf(file,"%lf",&z);
//set the bin content i,j to value z just red
hd2->SetBinContent(i,j,z);
}
//drawing the histogram
h2d->Draw("colz")
Hi I am getting error while using your method. Please let me know what am I doing wrong, I have just started using root? Any Ideas about implementing a pattern recognition code?
Okay I got the file part. But the plotting part still gives me error.
Here is my code:
FILE *file=fopen("100VAmBeBack_004938.txt","r");
//create a 256x256 histogram
TH2D *h2d= new TH2D("h2d","My histogram",256,0,256,256,0,256);
double z;
int i,j;
//for loops to read 256x256 file
for(i=1; i<=256; i++)
{
for(j=1; j<=256; j++)
{
//read the number
fscanf(file,"%lf",&z);
//set the bin content i,j to value z just red
hd2->SetBinContent(i,j,z);
}
}
//drawing the histogram
h2d->Draw("colz");
//drawing the histogram
h2d->Draw("colz");
I have tried with that rectification too, still doesn’t works.
FILE *file=fopen("100VAmBeBack_004938.txt","r");
//create a 256x256 histogram
TH2D *h2d= new TH2D("h2d","My histogram",256,0,256,256,0,256);
double z;
int i,j;
//for loops to read 256x256 file
for(i=1; i<=256; i++)
{
for(j=1; j<=256; j++)
{
//read the number
fscanf(file,"%lf",&z);
//set the bin content i,j to value z just red
h2d->SetBinContent(i,j,z);
}
}
//drawing the histogram
h2d->Draw("colz");
It seems to me that you are missing the proper C++ “ROOT unnamed macro” structure:
{ // begin of an unnamed macro (the first line of your script)
// ...
FILE *file=fopen("100VAmBeBack_004938.txt","r");
// ...
fclose(file); // after the "for" loop
// ...
h2d->Draw("colz");
// ...
} // end of an unnamed macro (the last line of your script)