# How to extract a data from dna.root file?

**URL:** <https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182>\
**Category:** ROOT\
**Created:** [June 3, 2013, 1:08pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182 "2013-06-03T13:08:06Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rootroot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rootroot/32/37811_2.png) [@rootroot](https://root-forum.cern.ch/u/rootroot)\
**Post date:** [June 3, 2013, 1:08pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/1 "2013-06-03T13:08:06Z")

</div>

Good day for everyone! I need help!

I have simulated a proton particle track using Geant4dna software. The output file is dna.root - see attach 1.

I can visualise this file with a macro “Plot.C”. I can see a file structure using Root Explorer. But i cannot extract data from this file - see attach 2.  
I want to convert file dna.root to a simple txt file like:

## N1 X1 Y1 Z1 E1 TYPE1 … Nn Xn Yn Zn En TYPEn

Where are:  
Ni - number of I event  
Xi, Yi, Zi - 3D coordinates of particle-water interaction  
Ei - deposited energy  
TYPEn - type of interaction (ionisation or exitation).

Briefly, I want to convert dna.root to txt or csv file.

 ![](https://root-forum.cern.ch/uploads/default/original/2X/4/4f1a5bf7832bdbaa7f044967b248724044b45ef9.png)  
  
[dna.root](https://root-forum.cern.ch/uploads/default/original/2X/2/24b45ab9bde677b9efa642424b55d517eaf77795.root) (45 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:** [June 3, 2013, 2:09pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/2 "2013-06-03T14:09:01Z")

</div>

```auto
//
// Name this file "dump.cxx" and use as:
//
// root [0] .x dump.cxx(); > dump.txt
//
// Produces "dump.txt" and "dump.xml" files.
//

void dump(const char *fname = "dna.root",
          const char *nname = "ntuple")
{
  if (!fname || !(*fname) || !nname || !(*nname)) return; // just a precaution
  
  TFile *f = TFile::Open(fname, "READ");
  if ((!f) || f->IsZombie()) { delete f; return; } // just a precaution
  
  TTree *t; f->GetObject(nname, t);
  if (!t) { delete f; return; } // just a precaution
  
  // See:
  // http://root.cern.ch/root/html/TTreePlayer.html#TTreePlayer:Scan
  // http://root.cern.ch/root/html/TTree.html#TTree:Scan
  t->SetScanField(0);
  t->Scan("*");
  
  // See:
  // http://root.cern.ch/root/html/TObject.html#TObject:SaveAs
  t->SaveAs("dump.xml");
  // t->SaveAs(TString::Format("%s.xml", nname));
  
  delete f; // no longer needed (automatically deletes "t")
}

```

---

<div class="post-metadata">

**Author:** ![rootroot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rootroot/32/37811_2.png) [@rootroot](https://root-forum.cern.ch/u/rootroot)\
**Post date:** [June 3, 2013, 2:25pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/3 "2013-06-03T14:25:37Z")

</div>

Thanks for reply!  
I have created dump.cxx in a directory containig dna.root

Execute in terminal and recieve next message:

`localhost.localdomain:/dna-b < 91 >root [0] .x dump.cxx(); > dump.txt
Badly placed ()'s.
`

---

<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:** [June 3, 2013, 2:34pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/4 "2013-06-03T14:34:53Z")

</div>

“root [0]” means interactive ROOT command line.

See also:

- [Compile and run from command prompt](https://root-forum.cern.ch/t/compile-and-run-from-command-prompt/13799/2)
- [Ask: how to transfer the parameter for the root scritpt](https://root-forum.cern.ch/t/ask-how-to-transfer-the-parameter-for-the-root-scritpt/13535/4)
- [ROOT User’s Guide -\> Getting Started -\> Start and Quit a ROOT Session](https://root.cern.ch/root/html534/guides/users-guide/GettingStarted.html#start-and-quit-a-root-session)

---

<div class="post-metadata">

**Author:** ![rootroot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rootroot/32/37811_2.png) [@rootroot](https://root-forum.cern.ch/u/rootroot)\
**Post date:** [June 3, 2013, 2:48pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/5 "2013-06-03T14:48:38Z")

</div>

I am sorry, may be i do something wrong? Now I received this:

 ![](https://root-forum.cern.ch/uploads/default/original/2X/1/1bd8204c14f1e569184d38aa7af3e7ef85b7cd72.png)

---

<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:** [June 3, 2013, 2:57pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/6 "2013-06-03T14:57:30Z")

</div>

Do NOT type "root [0] " yourself (this is the ROOT interactive prompt).

Make familiar with:

- [ROOT Primer](https://root.cern.ch/root/htmldoc/guides/primer/ROOTPrimer.html)
- [ROOT User’s Guide](https://root.cern.ch/root/htmldoc/guides/users-guide/ROOTUsersGuide.html)

---

<div class="post-metadata">

**Author:** ![rootroot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rootroot/32/37811_2.png) [@rootroot](https://root-forum.cern.ch/u/rootroot)\
**Post date:** [June 3, 2013, 3:03pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/7 "2013-06-03T15:03:10Z")

</div>

[quote=“Wile E. Coyote”]Do NOT type "root [0] " yourself (this is the ROOT interactive prompt).

Do read:  
[ROOT Primer](http://root.cern.ch/download/doc/primer/ROOTPrimer.html)  
[ROOT User’s Guide](http://root.cern.ch/download/doc/ROOTUsersGuide.html)[/quote]  
Many, many thanks! Everything is works!

```auto
************************************************************************************************************
* Row * flagParti * flagProce * x * y * z * edep * size * diffKin *
************************************************************************************************************
* 0 * 2 * 19 * 0 * 0 * 0 * 10.79 * 215439.17 * 0 *
* 1 * 3 * 21 * 0 * 0 * 0.2154391 * 13.39 * 3115361.3 * 14.596182 *
* 2 * 3 * 21 * 0 * 0 * 3.3308005 * 13.39 * 4162531.8 * 14.448767 *
* 3 * 3 * 22 * 0 * 0 * 7.4933323 * 0 * 831263.13 * 0 *
* 4 * 1 * 11 * 0 * 0 * 8.3245955 * 0.5300324 * 0 * 0.5300324 *
* 5 * 1 * 11 * 0 * 0 * 7.4933323 * 1.0587679 * 0 * 1.0587679 *
* 6 * 1 * 11 * 0 * 0 * 3.3308005 * 1.2061821 * 0 * 1.2061821 *
* 7 * 2 * 19 * 0 * 0 * 8.3245955 * 10.79 * 104402.88 * 0 *
* 8 * 3 * 21 * 0 * 0 * 8.4289984 * 13.39 * 589709.29 * 14.626472 *
* 9 * 3 * 21 * 0 * 0 * 9.0187077 * 16.05 * 822017.44 * 18.047898 *
* 10 * 3 * 22 * 0 * 0 * 9.8407251 * 0 * 2492888.8 * 0 *
* 11 * 1 * 11 * 0 * 0 * 12.333614 * 0.5060763 * 0 * 0.5060763 *
* 12 * 1 * 11 * 0 * 0 * 9.8407251 * 1.9978981 * 0 * 1.9978981 *
* 13 * 1 * 11 * 0 * 0 * 9.0187077 * 1.2364721 * 0 * 1.2364721 *
* 14 * 2 * 19 * 0 * 0 * 12.333614 * 10.79 * 70228.643 * 0 *
* 15 * 3 * 21 * 0 * 0 * 12.403842 * 13.39 * 1111412.5 * 15.388224 *
* 16 * 3 * 21 * 0 * 0 * 13.515255 * 16.05 * 241050.94 * 17.721315 *
* 17 * 3 * 21 * 0 * 0 * 13.756306 * 10.79 * 7302.8799 * 11.120379 *
* 18 * 3 * 21 * 0 * 0 * 13.763609 * 13.39 * 238368.93 * 14.158694 *
* 19 * 3 * 21 * 0 * 0 * 14.001978 * 13.39 * 893221.23 * 14.266538 *
* 20 * 3 * 21 * 0 * 0 * 14.895199 * 13.39 * 2021842.9 * 14.553518 *
* 21 * 3 * 22 * 0 * 0 * 16.917042 * 0 * 721422.97 * 0 *
* 22 * 1 * 11 * 0 * 0 * 17.638465 * 0.4524330 * 0 * 0.4524330 *
* 23 * 1 * 11 * 0 * 0 * 16.917042 * 1.1635187 * 0 * 1.1635187 *
* 24 * 1 * 11 * 0 * 0 * 14.895199 * 0.8765386 * 0 * 0.8765386 *
* 25 * 1 * 11 * 0 * 0 * 14.001978 * 0.7686945 * 0 * 0.7686945 *
* 26 * 1 * 11 * 0 * 0 * 13.763609 * 0.3303796 * 0 * 0.3303796 *
* 27 * 1 * 11 * 0 * 0 * 13.756306 * 1.6713156 * 0 * 1.6713156 *
* 28 * 1 * 11 * 0 * 0 * 13.515255 * 1.9982239 * 0 * 1.9982239 *
* 29 * 2 * 19 * 0 * 0 * 17.638465 * 10.79 * 58291.305 * 0 *
* 30 * 3 * 22 * 0 * 0 * 17.696756 * 0 * 2561872.2 * 0 *
* 31 * 1 * 11 * 0 * 0 * 20.258628 * 0.4463142 * 0 * 0.4463142 *
* 32 * 2 * 19 * 0 * 0 * 20.258628 * 10.79 * 209844.09 * 0 *
* 33 * 3 * 20 * 0 * 0 * 20.468472 * 12.91 * 724637.32 * 12.91 *
* 34 * 3 * 22 * 0 * 0 * 21.19311 * 0 * 1901871.4 * 0 *
* 35 * 1 * 11 * 0 * 0 * 23.094981 * 0.4331677 * 0 * 0.4331677 *
* 36 * 2 * 19 * 0 * 0 * 23.094981 * 10.79 * 218167.75 * 0 *
* 37 * 3 * 21 * 0 * 0 * 23.313149 * 13.39 * 107944.07 * 13.464029 *
* 38 * 3 * 21 * 0 * 0 * 23.421093 * 13.39 * 321397.11 * 13.561393 *
* 39 * 3 * 21 * 0 * 0 * 23.742490 * 10.79 * 290393.20 * 12.400589 *
* 40 * 3 * 21 * 0 * 0 * 24.032883 * 10.79 * 611615.49 * 12.394458 *
* 41 * 3 * 21 * 0 * 0 * 24.644499 * 10.79 * 11490785 * 11.501690 *
* 42 * 3 * 21 * 0 * 0 * 36.135284 * 13.39 * 2728386.2 * 14.590160 *
* 43 * 3 * 21 * 0 * 0 * 38.863670 * 10.79 * 5953196.4 * 11.185971 *
* 44 * 3 * 21 * 0 * 0 * 44.816866 * 10.79 * 860503.87 * 10.928753 *
* 45 * 3 * 22 * 0 * 0 * 45.677370 * 0 * 747634.37 * 0 *
* 46 * 1 * 11 * 0 * 0 * 46.425005 * 0.3725830 * 0 * 0.3725830 *
* 47 * 1 * 11 * 0 * 0 * 45.677370 * 0.1387533 * 0 * 0.1387533 *
* 48 * 1 * 11 * 0 * 0 * 44.816866 * 0.3959717 * 0 * 0.3959717 *
* 49 * 1 * 11 * 0 * 0 * 38.863670 * 1.2001601 * 0 * 1.2001601 *
* 50 * 1 * 11 * 0 * 0 * 36.135284 * 0.7116909 * 0 * 0.7116909 *
* 51 * 1 * 11 * 0 * 0 * 24.644499 * 1.6044580 * 0 * 1.6044580 *
* 52 * 1 * 11 * 0 * 0 * 24.032883 * 1.6105898 * 0 * 1.6105898 *
* 53 * 1 * 11 * 0 * 0 * 23.742490 * 0.1713931 * 0 * 0.1713931 *
* 54 * 1 * 11 * 0 * 0 * 23.421093 * 0.0740294 * 0 * 0.0740294 *
* 55 * 2 * 19 * 0 * 0 * 46.425005 * 10.79 * 25229.709 * 0 *
* 56 * 3 * 21 * 0 * 0 * 46.450234 * 13.39 * 939068.59 * 14.458238 *
* 57 * 3 * 21 * 0 * 0 * 47.389303 * 13.39 * 2749950.3 * 13.601135 *
* 58 * 3 * 21 * 0 * 0 * 50.139253 * 10.79 * 4179778.8 * 11.938533 *
* 59 * 3 * 21 * 0 * 0 * 54.319032 * 10.79 * 1104110.3 * 11.990252 *
* 60 * 3 * 21 * 0 * 0 * 55.423142 * 13.39 * 1918698.5 * 14.176235 *
* 61 * 3 * 21 * 0 * 0 * 57.341841 * 10.79 * 1594010.2 * 10.902289 *
* 62 * 3 * 21 * 0 * 0 * 58.935851 * 10.79 * 1770371.4 * 11.413828 *
* 63 * 3 * 20 * 0 * 0 * 60.706223 * 10.13 * 1331088.3 * 10.13 *
* 64 * 3 * 21 * 0 * 0 * 62.037311 * 16.05 * 733549.86 * 16.975841 *
* 65 * 3 * 20 * 0 * 0 * 62.770861 * 14.5 * 437498.65 * 14.5 *
* 66 * 3 * 22 * 0 * 0 * 63.208359 * 0 * 1327494.0 * 0 *
* 67 * 1 * 11 * 0 * 0 * 64.535853 * 0.2956605 * 0 * 0.2956605 *
* 68 * 1 * 11 * 0 * 0 * 62.770861 * 0.9258411 * 0 * 0.9258411 *
* 69 * 1 * 11 * 0 * 0 * 60.706223 * 0.6238281 * 0 * 0.6238281 *
* 70 * 1 * 11 * 0 * 0 * 58.935851 * 0.1122891 * 0 * 0.1122891 *
* 71 * 1 * 11 * 0 * 0 * 57.341841 * 0.7862357 * 0 * 0.7862357 *
* 72 * 1 * 11 * 0 * 0 * 55.423142 * 1.2002522 * 0 * 1.2002522 *
* 73 * 1 * 11 * 0 * 0 * 54.319032 * 1.1485337 * 0 * 1.1485337 *
* 74 * 1 * 11 * 0 * 0 * 50.139253 * 0.2111353 * 0 * 0.2111353 *
* 75 * 1 * 11 * 0 * 0 * 47.389303 * 1.0682382 * 0 * 1.0682382 *
* 76 * 2 * 19 * 0 * 0 * 64.535853 * 10.79 * 26615.535 * 0 *
* 77 * 3 * 21 * 0 * 0 * 64.562469 * 13.39 * 2694328.2 * 13.584737 *
* 78 * 3 * 21 * 0 * 0 * 67.256797 * 16.05 * 9084080.6 * 17.146362 *
* 79 * 3 * 22 * 0 * 0 * 76.340878 * 0 * 2369318.1 * 0 *
* 80 * 1 * 11 * 0 * 0 * 78.710196 * 0.2728904 * 0 * 0.2728904 *
* 81 * 1 * 11 * 0 * 0 * 76.340878 * 1.0963626 * 0 * 1.0963626 *
* 82 * 1 * 11 * 0 * 0 * 67.256797 * 0.1947375 * 0 * 0.1947375 *
* 83 * 2 * 19 * 0 * 0 * 78.710196 * 10.79 * 26575.968 * 0 *
* 84 * 3 * 21 * 0 * 0 * 78.736772 * 10.79 * 5516320.4 * 11.017054 *
* 85 * 3 * 21 * 0 * 0 * 84.253093 * 16.05 * 3188945.4 * 16.424238 *
* 86 * 3 * 22 * 0 * 0 * 87.442038 * 0 * 6756938.1 * 0 *
* 87 * 1 * 11 * 0 * 0 * 94.198976 * 0.2519244 * 0 * 0.2519244 *
* 88 * 1 * 11 * 0 * 0 * 87.442038 * 0.3742385 * 0 * 0.3742385 *
* 89 * 1 * 11 * 0 * 0 * 84.253093 * 0.2270541 * 0 * 0.2270541 *
* 90 * 2 * 19 * 0 * 0 * 94.198976 * 10.79 * 146671.78 * 0 *
* 91 * 3 * 21 * 0 * 0 * 94.345648 * 13.39 * 387629.74 * 13.740585 *
* 92 * 3 * 21 * 0 * 0 * 94.733278 * 10.79 * 825310.69 * 11.529662 *
* 93 * 3 * 21 * 0 * 0 * 95.558588 * 13.39 * 2513850.9 * 13.669665 *
* 94 * 3 * 22 * 0 * 0 * 98.072439 * 0 * 299584.96 * 0 *
* 95 * 1 * 11 * 0 * 0 * 98.372024 * 0.2247074 * 0 * 0.2247074 *
* 96 * 1 * 11 * 0 * 0 * 98.072439 * 0.2796656 * 0 * 0.2796656 *
* 97 * 1 * 11 * 0 * 0 * 95.558588 * 0.7396627 * 0 * 0.7396627 *
* 98 * 1 * 11 * 0 * 0 * 94.733278 * 0.3505850 * 0 * 0.3505850 *
* 99 * 2 * 19 * 0 * 0 * 98.372024 * 10.79 * 234895.31 * 0 *
* 100 * 3 * 21 * 0 * 0 * 98.60692 * 16.05 * 1127643.5 * 16.333734 *
* 101 * 3 * 21 * 0 * 0 * 99.734563 * 13.39 * 8001311.5 * 13.585833 *
* 102 * 3 * 21 * 0 * 0 * 107.73587 * 10.79 * 1726944.4 * 11.457160 *
* 103 * 3 * 21 * 0 * 0 * 109.46282 * 13.39 * 1331764.7 * 13.581384 *
* 104 * 3 * 21 * 0 * 0 * 110.79458 * 13.39 * 2092830.3 * 13.537113 *
* 105 * 3 * 21 * 0 * 0 * 112.88741 * 32.3 * 778207.91 * 32.455213 *
* 106 * 3 * 21 * 0 * 0 * 113.66562 * 10.79 * 1180491.1 * 11.362828 *
* 107 * 3 * 21 * 0 * 0 * 114.84611 * 13.39 * 3535426.9 * 13.891004 *
* 108 * 3 * 21 * 0 * 0 * 118.38154 * 10.79 * 2465080.1 * 11.093422 *
* 109 * 3 * 21 * 0 * 0 * 120.84662 * 16.05 * 8618171.8 * 16.434264 *
* 110 * 3 * 21 * 0 * 0 * 129.46479 * 10.79 * 279583.91 * 11.073360 *
* 111 * 3 * 22 * 0 * 0 * 129.74437 * 0 * 2641570.6 * 0 *
* 112 * 1 * 11 * 0 * 0 * 132.38594 * 0.1289569 * 0 * 0.1289569 *
* 113 * 1 * 11 * 0 * 0 * 129.74437 * 0.2833604 * 0 * 0.2833604 *
* 114 * 1 * 11 * 0 * 0 * 129.46479 * 0.3842641 * 0 * 0.3842641 *
* 115 * 1 * 11 * 0 * 0 * 120.84662 * 0.3034226 * 0 * 0.3034226 *
* 116 * 1 * 11 * 0 * 0 * 118.38154 * 0.5010049 * 0 * 0.5010049 *
* 117 * 1 * 11 * 0 * 0 * 114.84611 * 0.5728281 * 0 * 0.5728281 *
* 118 * 1 * 11 * 0 * 0 * 113.66562 * 0.1552131 * 0 * 0.1552131 *
* 119 * 1 * 11 * 0 * 0 * 112.88741 * 0.1471137 * 0 * 0.1471137 *
* 120 * 1 * 11 * 0 * 0 * 110.79458 * 0.1913844 * 0 * 0.1913844 *
* 121 * 1 * 11 * 0 * 0 * 109.46282 * 0.6671605 * 0 * 0.6671605 *
* 122 * 1 * 11 * 0 * 0 * 107.73587 * 0.1958329 * 0 * 0.1958329 *
* 123 * 1 * 11 * 0 * 0 * 99.734563 * 0.2837345 * 0 * 0.2837345 *
* 124 * 2 * 19 * 0 * 0 * 132.38594 * 10.79 * 60396.270 * 0 *
* 125 * 3 * 21 * 0 * 0 * 132.44634 * 10.79 * 1417514.5 * 10.946709 *
* 126 * 3 * 21 * 0 * 0 * 133.86385 * 10.79 * 1697430.4 * 10.910124 *
* 127 * 3 * 21 * 0 * 0 * 135.56128 * 13.39 * 4209922.0 * 13.400704 *
* 128 * 3 * 21 * 0 * 0 * 139.77121 * 16.05 * 4763348.7 * 16.341884 *
* 129 * 3 * 21 * 0 * 0 * 144.53455 * 32.3 * 8344732.5 * 32.323317 *
* 130 * 3 * 21 * 0 * 0 * 152.87929 * 10.79 * 6534382.2 * 10.937910 *
* 131 * 3 * 22 * 0 * 0 * 159.41367 * 0 * 2140478.9 * 0 *
* 132 * 1 * 11 * 0 * 0 * 161.55415 * 0.0713516 * 0 * 0.0713516 *
* 133 * 1 * 11 * 0 * 0 * 159.41367 * 0.1479106 * 0 * 0.1479106 *
* 134 * 1 * 11 * 0 * 0 * 152.87929 * 0.0233173 * 0 * 0.0233173 *
* 135 * 1 * 11 * 0 * 0 * 144.53455 * 0.2918841 * 0 * 0.2918841 *
* 136 * 1 * 11 * 0 * 0 * 139.77121 * 0.0107049 * 0 * 0.0107049 *
* 137 * 1 * 11 * 0 * 0 * 135.56128 * 0.1201246 * 0 * 0.1201246 *
* 138 * 1 * 11 * 0 * 0 * 133.86385 * 0.1567098 * 0 * 0.1567098 *
* 139 * 2 * 19 * 0 * 0 * 161.55415 * 10.79 * 20289.797 * 0 *
* 140 * 3 * 22 * 0 * 0 * 161.57444 * 0 * 11580309. * 0 *
* 141 * 1 * 11 * 0 * 0 * 173.15475 * 0.0654403 * 0 * 0.0654403 *
* 142 * 2 * 19 * 0 * 0 * 173.15475 * 10.79 * 67579.780 * 0 *
* 143 * 3 * 22 * 0 * 0 * 173.22233 * 0 * 11242195. * 0 *
* 144 * 1 * 11 * 0 * 0 * 184.46452 * 0.0595323 * 0 * 0.0595323 *
* 145 * 2 * 18 * 0 * 0 * 184.46452 * 95.710462 * 24846162. * 95.710462 *
************************************************************************************************************

```

---

<div class="post-metadata">

**Author:** ![SANKET\_GUNGE](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@SANKET\_GUNGE](https://root-forum.cern.ch/u/SANKET_GUNGE)\
**Post date:** [February 27, 2017, 4:09pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/8 "2017-02-27T16:09:13Z")

</div>

Got Error

input\_line\_41:2:9: error: expected expression  
dump();\>dump.txt /\* invoking function corresponding to ‘.x’ \*/  
^  
input\_line\_41:2:14: error: member reference base type 'void (const char \*, const  
char _)’ is not a structure or union  
dump();\>dump.txt /_ invoking function corresponding to ‘.x’ \*/  
~~~~^~~

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [February 27, 2017, 4:52pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/9 "2017-02-27T16:52:39Z")

</div>

In ROOT 6, you need to:

```nohighlight
root [0] .> dump.txt
.x dump.cxx
.>
root [3] 

```

Note also that, in many simple cases, you should be able to use the operating system redirection, e.g.:

```bash
[...]$ root -l -q dump.cxx > dump.txt

```

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [March 4, 2019, 1:02am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/10 "2019-03-04T01:02:02Z")

</div>

Wil\_E\_Coyote,

My question is kind of related to this thread. I have two .root files, one contains a tree having an array of values two of which I need to pull out.  
The second contains addition of .root files of good runs. I would like to use the two values from first .root files along with the good runs .root files to plot histogram of invariant mass and pT.

How can I get these two values from the file hadron.root to use?

Same code:

```auto
//macro to plot the new mass and pt plots
void plotmass(const char *fname = "newgood.root")// file containing the good runs
{
  //std::vector<string> runnumber;
   
  gStyle->SetOptStat
  //gDirectory->
  // Opening a TFile 
  TFile *tfile = new TFile(fname,"READ");

  // Get TTree tree from TFile
  TTree *tree = (TTree*)tfile->Get("tree");

  // Get ntval from tree that contains the mass and pt values store in root file hadron.root
  Float_t ntval[35];// number of variables in tree equal 35.
  TBranch *ntv_branch = tree->GetBranch("ntval");
  ntv_branch->SetAddress(&ntval);
  
  // histograms
  TH1 *h_mass = new TH1F("h_mass","upc e+/e- mass",10,2.0,4.0);
  TH1 *h_pt = new TH1F("h_pt","upc e+/e- pt",40,0.,4.0);
  
  Int_t nevents = tree->GetEntries();
  //nevents = 10; // for debugging only, comment this out if you want all events
  for (Int_t ievt=0; ievt<nevents; ievt++)
  {
    tree->GetEvent(ievt);
    //cout << ievt << "\t" << ntval[10] << endl;//10 is mass value
    
    //loop over good runs
     //int run = ntval[17];

    //for( int i =0; i<runnumber.size(); i++){ if (run != runnumber.at(i) continue;)
    Float_t mass = ntval[10];
    Float_t pt = ntval[11];// pt value

    if ( ntval[7]<5 && fabs(ntval[0])<30.0 && ntval[12]==0 )
    {
      h_mass->Fill( mass );
      h_pt->Fill( pt );
      
    } 
  } 

    TFile *f=new TFile("testfile.root", "NEW");
    TCanvas *C = new TCanvas("C","",850,500);
    h_mass->Draw("ehist");
    h_mass->Write();
    h_pt->Draw("ehist");
    h_pt->Write();

```

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [March 5, 2019, 9:24pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/11 "2019-03-05T21:24:45Z")

</div>

Thank you everyone. Problem was solved.

---

<div class="post-metadata">

**Author:** ![rootroot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rootroot/32/37811_2.png) [@rootroot](https://root-forum.cern.ch/u/rootroot)\
**Post date:** [March 6, 2019, 2:44pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/12 "2019-03-06T14:44:48Z")

</div>

In my case, after command:

```auto
root [0] .> dump.txt

```

Nothing happened, ROOT stacks and i can see only cursor lighting…Trying to wait 3 hour - nothing changed

Tryies this solution - [How to convert .root to .txt file?](https://root-forum.cern.ch/t/how-to-convert-root-to-txt-file/30534/4)  
and get this Errors;

```auto
In file included from input_line_10:1:
/home/local1/dnaphysics-build/d2.cxx:21:18: error: use of undeclared identifier 'fTree'
 ((TTreePlayer *)fTree->GetPlayer())->SetScanRedirect(kTRUE)
                 ^
/home/local1/dnaphysics-build/d2.cxx:22:18: error: use of undeclared identifier 'fTree'
 ((TTreePlayer *)fTree->GetPlayer())->SetScanFileName(outputname);

```

---

<div class="post-metadata">

**Author:** ![rootroot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rootroot/32/37811_2.png) [@rootroot](https://root-forum.cern.ch/u/rootroot)\
**Post date:** [March 6, 2019, 2:47pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/13 "2019-03-06T14:47:36Z")

</div>

> [@Pepe\_Le\_Pew](#):
>
> root -q dump.cxx \> dump.txt

dump.txt:

> * * *
> 
> | Welcome to ROOT 6.16/00 [https://root.cern](https://root.cern) |  
> | (c) 1995-2018, The ROOT Team |  
> | Built for linuxx8664gcc on Jan 23 2019, 09:06:13 |  
> | From tags/v6-16-00@v6-16-00 |
> 
> | Try ‘.help’, ‘.demo’, ‘.license’, ‘.credits’, ‘.quit’/‘.q’ |
> | --- |
> 
> Processing dump.cxx…

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [March 6, 2019, 3:25pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/14 "2019-03-06T15:25:34Z")

</div>

Indeed in that example ‘fTree’ should have been just ‘t’ …

---

<div class="post-metadata">

**Author:** ![rootroot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rootroot/32/37811_2.png) [@rootroot](https://root-forum.cern.ch/u/rootroot)\
**Post date:** [March 7, 2019, 8:54am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/15 "2019-03-07T08:54:34Z")

</div>

Thanks for your reply. No i am getting this error:

```auto
/home/local1/dnaphysics-build/d2.cxx:21:21: error: no member named 'GetPlayer' in 'TFile'
 ((TTreePlayer *)f->GetPlayer())->SetScanRedirect(kTRUE)
                 ~ ^
/home/local1/dnaphysics-build/d2.cxx:22:21: error: no member named 'GetPlayer' in 'TFile'
 ((TTreePlayer *)f->GetPlayer())->SetScanFileName(outputname);

```

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [March 12, 2019, 2:25am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/16 "2019-03-12T02:25:06Z")

</div>

" f " as in file is pointing to the TFile … you are looking for " t " as in tree.

---

<div class="post-metadata">

**Author:** ![11112](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/1/d78d45/32.png) [@11112](https://root-forum.cern.ch/u/11112)\
**Post date:** [March 12, 2019, 6:19am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/17 "2019-03-12T06:19:58Z")

</div>

Sorry. Change f to t and get this:

```auto
In file included from input_line_10:1:
/home/local1/dnaphysics-build/d2.cxx:22:2: error: called object type 'void' is not a function or function pointer
 ((TTreePlayer *)t->GetPlayer())->SetScanFileName(outputname);

```

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [March 12, 2019, 11:40am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/18 "2019-03-12T11:40:02Z")

</div>

sorry I am lost. Can you copy/paste the entire code?

---

<div class="post-metadata">

**Author:** ![rootroot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rootroot/32/37811_2.png) [@rootroot](https://root-forum.cern.ch/u/rootroot)\
**Post date:** [March 12, 2019, 12:28pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/19 "2019-03-12T12:28:41Z")

</div>

d2.cxx:

```auto
// Name this file “dump.cxx” and use as:
//
// root [0] .x dump.cxx("dump.txt")
//
// Produces “dump.txt” and “dump.xml” files.
//

void dump(const char *outputname = "dump.txt", const char *fname = "dna.root",
const char *nname = "ntuple")
{
if (!fname || !(*fname) || !nname || !(*nname)) return; // just a precaution

TFile *f = TFile::Open(fname, "READ");
if (!f) return; // just a precaution

TTree *t; f->GetObject(nname, t);
if (!t) { delete f; return; } // just a precaution

t->SetScanField(0);
 ((TTreePlayer *)t->GetPlayer())->SetScanRedirect(kTRUE)
 ((TTreePlayer *)t->GetPlayer())->SetScanFileName(outputname);
t->Scan("*");
t->SaveAs("dump.xml");

delete f; // no longer needed (automatically deletes "t")
}

```

Usage:

```auto
$root
root [0] .x d2.cxx("dna.txt")

```

Result:

```auto
In file included from input_line_10:1:
/home/local1/dnaphysics-build/d2.cxx:22:2: error: called object type 'void' is not a function or function pointer
 ((TTreePlayer *)t->GetPlayer())->SetScanFileName(outputname);
 ^

```

---

<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:** [March 12, 2019, 12:32pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/20 "2019-03-12T12:32:59Z")

</div>

At least one “;” is missing (in the end of the line with “SetScanRedirect”).

[Next page](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182.md?page=2)
