# Data file to .root \[Segmentation violation\]

**URL:** <https://root-forum.cern.ch/t/data-file-to-root-segmentation-violation/48492>\
**Category:** Newbie\
**Tags:** root\
**Created:** [January 21, 2022, 5:04pm UTC](https://root-forum.cern.ch/t/data-file-to-root-segmentation-violation/48492 "2022-01-21T17:04:08Z")\
**Posts on this page:** 3\
**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 21, 2022, 5:04pm UTC](https://root-forum.cern.ch/t/data-file-to-root-segmentation-violation/48492/1 "2022-01-21T17:04:09Z")

</div>

Dear Root experts;

I stuck in converting the magnetic field data in root file. I have written a code (from an example given in root forum) but am receiving segmentation fault.

My data file has 6 columns and 20000 lines. I am unable to proceed now. Please help me.

For the sake I am attaching herewith the c and data file.  
[field.C](https://root-forum.cern.ch/uploads/short-url/tTiq8Xzx0ctO4KUB8gMqESUzzmT.C) (608 Bytes)

Regards  
vJ  
[field.txt](https://root-forum.cern.ch/uploads/short-url/cdTOAOFwWjf5cpcHkKoZt28O3QJ.txt) (1.6 KB)

PS::  
The error I am getting is as:  
\*\*\* Break \*\*\* segmentation violation

# =========================================================== There was a crash. This is the entire stack trace of all threads:

---

<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 21, 2022, 6:05pm UTC](https://root-forum.cern.ch/t/data-file-to-root-segmentation-violation/48492/2 "2022-01-21T18:05:42Z")

</div>

In your “field.txt” file, make sure that the values are separated by at least one space character.

```cpp
{
  TFile *f = new TFile("MATRIX.root", "RECREATE");
  TTree *t = new TTree("ntuple", "data from the MATRIX file");
  t->ReadFile("field.txt", "x:y:z:a:b:c");
  // t->Scan("*");
  TH1F *h = new TH1F("h1", "x distribution", 100, -4., 4.);
  t->Project("h1", "x");
  f->Write();
  delete f; // automatically deletes t and h, too
}

```

---

<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 21, 2022, 10:08pm UTC](https://root-forum.cern.ch/t/data-file-to-root-segmentation-violation/48492/4 "2022-01-21T22:08:24Z")

</div>

Thanyou so much … It is Solved … A hug … Gracias …
