# How to create a histogam from a .dat file

**URL:** <https://root-forum.cern.ch/t/how-to-create-a-histogam-from-a-dat-file/35286>\
**Category:** Newbie\
**Created:** [July 20, 2019, 11:03pm UTC](https://root-forum.cern.ch/t/how-to-create-a-histogam-from-a-dat-file/35286 "2019-07-20T23:03:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrc1104](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/a5b964/32.png) [@mrc1104](https://root-forum.cern.ch/u/mrc1104)\
**Post date:** [July 20, 2019, 11:03pm UTC](https://root-forum.cern.ch/t/how-to-create-a-histogam-from-a-dat-file/35286/1 "2019-07-20T23:03:49Z")

</div>

I know this question has been asked a lot on this site but I cannot find an example that pertains to my current situation. I have a .dat that has data for a time calibration spectrum. My problem is that it is just a wall of values (eg 0000000…000324000…0000000 continuously for 411 lines).

I’ve tried using TFile to open the file and

“TH1F \*h1(TH1F \*)TFile-\>Get();”

to read in the data but it is not a ROOT File. So then I tried a variant with ifstream but ifstream is not a pointer. Any advice?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [July 21, 2019, 11:07am UTC](https://root-forum.cern.ch/t/how-to-create-a-histogam-from-a-dat-file/35286/3 "2019-07-21T11:07:13Z")

</div>

> [@Filling Histograms with a text file](https://root-forum.cern.ch/t/filling-histograms-with-a-text-file/34190/2):
>
> Try: /\* Usage examples: root [0] .L Am241.cxx root [1] Am241(); // expects "Am241.txt" in the current directory root [1] Am241("/full/path/to/some/Am241.txt"); or simply: root [0] .x Am241.cxx root [0] .x Am241.cxx("/full/path/to/some/Am241.txt") \*/ #include "TGraph.h" #include \<fstream\> void Am241(const char \*file = "Am241.txt") { if ((!file) || (!file[0])) return; // just a precaution TGraph \*g = new TGraph(); g-\>SetTitle("Count Rate;N\_{counts};# occurencies"); double y;…
