I want to draw image showing different colors for different intensity. It is easy to draw this in Matlab, where we have to give only file it will draw image. I want to draw these images ROOT. can you suggest me how to do that.
You can find below a script reading a text file with an arbitrary number of lines and columns, filling a TH2 and drawing it.
You can change the drawing option as you like.
//first pass on file to count lines and columns
FILE *fp = fopen(filename,“r”);
char line[80]; //put more if needed
int nlines = 0;
int ncol = 0;
while (fgets(line,80,fp)) {
if (!nlines) { //count columns on first line
char *s = line;
while (s) {
s = strtok(s," ");
if (!s ) break;
if (*s == ‘\n’) break;
ncol++;
s += strlen(s) + 1;
}
}
nlines++;
}
fclose(fp);
//create TH2 and fill it with a second pass on the file
TH2F h = new TH2F(“h”,filename,ncol,0,ncol,nlines,0,nlines);
ifstream in;
in.open(filename);
for (int j=0;j<nlines;j++) {
for (int i=0;i<ncol;i++) {
int z; in >> z;
h->SetBinContent(i+1,j+1,z);
}
}
in.close();
h->SetEntries(nlinesncol);
h->Draw(“colz”);
return h;
}
[/code]