# How I can convert dat file to root file

**URL:** <https://root-forum.cern.ch/t/how-i-can-convert-dat-file-to-root-file/37793>\
**Category:** ROOT\
**Created:** [January 30, 2020, 8:45pm UTC](https://root-forum.cern.ch/t/how-i-can-convert-dat-file-to-root-file/37793 "2020-01-30T20:45:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phy.vijayraj](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/phy.vijayraj/32/18580_2.png) [@phy.vijayraj](https://root-forum.cern.ch/u/phy.vijayraj)\
**Post date:** [January 30, 2020, 8:45pm UTC](https://root-forum.cern.ch/t/how-i-can-convert-dat-file-to-root-file/37793/1 "2020-01-30T20:45:36Z")

</div>

Dear Sir,

I am new to root and willing to learn it at my highest. I recently performed an experiment and the collection of data was in the form of .dat format. I am interested to turn it to .root file, where X axis are channels and Y axis - counts. The file is attched herewith.  
I have gone through the [Generate root file from a data file](https://root-forum.cern.ch/t/generate-root-file-from-a-data-file/29295), but unable to convert.

Eagerly waiting to receive suggestions.

Much Respect  
VJ  
[10B27Al-120MeV-Ge-8.dat.tar.gz](https://root-forum.cern.ch/uploads/short-url/xmAh9fCscnmrd8vWI725JFAqgMc.gz) (29.2 KB)

---

<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:** [January 30, 2020, 9:02pm UTC](https://root-forum.cern.ch/t/how-i-can-convert-dat-file-to-root-file/37793/2 "2020-01-30T21:02:06Z")

</div>

```cpp
{
  TGraph *g = new TGraph("10B27Al-120MeV-Ge-8.dat");
  g->SetTitle("Sample title;channel number;#counts");
  Int_t T_real = g->GetY()[0]; g->GetY()[0] = 0;
  Int_t T_vivo = g->GetY()[1]; g->GetY()[1] = 0;
  std::cout << "Espectro en: " << g->GetN() << " canales" << std::endl;
  std::cout << "T real: " << T_real << " s" << std::endl;
  std::cout << "T vivo: " << T_vivo << " s" << std::endl;
  g->Draw("ALP");
  // g->SetMinimum(1); gPad->SetLogy(1);
}

```

---

<div class="post-metadata">

**Author:** ![phy.vijayraj](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/phy.vijayraj/32/18580_2.png) [@phy.vijayraj](https://root-forum.cern.ch/u/phy.vijayraj)\
**Post date:** [January 30, 2020, 9:50pm UTC](https://root-forum.cern.ch/t/how-i-can-convert-dat-file-to-root-file/37793/3 "2020-01-30T21:50:03Z")

</div>

Dear Sir, million thanks for helping me.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [February 13, 2020, 9:50pm UTC](https://root-forum.cern.ch/t/how-i-can-convert-dat-file-to-root-file/37793/4 "2020-02-13T21:50:06Z")

</div>

Closed on February 13, 2020, 9:50pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
