Reading columns from text file

Hi,

I am new to programming and learning as I work, plus crash-coursing as my time period is short. I have a csv file that has 64 columns for 64 ‘channels’, with the rows as new entries for each trigger of activity. I would like to know how I should do this.

Able to do:

  • Convert csv file to text file
  • Isolate each column
  • Read text file using isolated column and drawing histogram by way of Fill()

Unable to do:

  • Read directly from csv file
  • Read and draw histogram of multiple columns from text file

I have searched the forum and I have no idea where to start.
I need to draw in histogram only, each column is a single histogram. I am open to either reading from csv or text, whichever is easiest. Feel free to ignore all that I know and guide me anew.

I apologize, I cannot upload the relevant files as my account is new.

Thanks a lot in advance!

ROOT Version: 6.26.10
Platform: Ubuntu
Compiler: -


What do you mean by “histogram of multiple columns”?

Create an histogram with as many bins as the line is your CSV file. As I understand, for one column, each line is a bin content ? Then use SetBinContent to fill each bin.

Hi,

Thanks for the replies. But I have solved it on my own. I apologize if I was not clear.

TCanvas *c1 = new TCanvas("c1","c1");
c1->Divide(8,8);
ifstream ifs("data.txt");
TH1F *h0 = new TH1F("hist0", "histogram0", 512, 0, 100); 
"
"
" to h63
double ch0 ... ch63;
while(ifs>>ch0>>...>>ch63){
h0->Fill(ch0,1.0);
"
"
" to h63
}
ifs.close();
 c1->Draw();