# Reading columns from text file

**URL:** <https://root-forum.cern.ch/t/reading-columns-from-text-file/55394>\
**Category:** Newbie\
**Created:** [June 22, 2023, 9:09am UTC](https://root-forum.cern.ch/t/reading-columns-from-text-file/55394 "2023-06-22T09:09:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KH0719](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kh0719/32/33738_2.png) [@KH0719](https://root-forum.cern.ch/u/KH0719)\
**Post date:** [June 22, 2023, 9:09am UTC](https://root-forum.cern.ch/t/reading-columns-from-text-file/55394/1 "2023-06-22T09:09:08Z")

</div>

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:_ -

* * *

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [June 22, 2023, 10:03am UTC](https://root-forum.cern.ch/t/reading-columns-from-text-file/55394/2 "2023-06-22T10:03:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 22, 2023, 10:17am UTC](https://root-forum.cern.ch/t/reading-columns-from-text-file/55394/3 "2023-06-22T10:17:27Z")

</div>

> [@KH0719](#):
>
> I need to draw in histogram only, each column is a single histogram

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.

---

<div class="post-metadata">

**Author:** ![KH0719](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kh0719/32/33738_2.png) [@KH0719](https://root-forum.cern.ch/u/KH0719)\
**Post date:** [June 26, 2023, 7:38am UTC](https://root-forum.cern.ch/t/reading-columns-from-text-file/55394/4 "2023-06-26T07:38:52Z")

</div>

Hi,

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

```auto
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();

```
