# Can I save the data points from the histogram

**URL:** <https://root-forum.cern.ch/t/can-i-save-the-data-points-from-the-histogram/38936>\
**Category:** Newbie\
**Tags:** hist, root\
**Created:** [April 17, 2020, 5:13am UTC](https://root-forum.cern.ch/t/can-i-save-the-data-points-from-the-histogram/38936 "2020-04-17T05:13:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 17, 2020, 5:13am UTC](https://root-forum.cern.ch/t/can-i-save-the-data-points-from-the-histogram/38936/1 "2020-04-17T05:13:29Z")

</div>

Usually what we do is make a histogram from a given set of data points.  
By adding two histograms i have a final histogram.  
Does root offers to allow the saving of data points of the final histogram?

_ROOT Version:_ Not Provided  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<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:** [April 17, 2020, 6:26am UTC](https://root-forum.cern.ch/t/can-i-save-the-data-points-from-the-histogram/38936/2 "2020-04-17T06:26:06Z")

</div>

> [@robertfroast](#):
>
> Does root offers to allow the saving of data points of the final histogram?

ROOT offers several ways to save an histogram. The most common way would be to save it in a ROOT file.

```auto
auto f = new TFile("hist.root","RECREATE");
hist->Write();

```

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 17, 2020, 7:10am UTC](https://root-forum.cern.ch/t/can-i-save-the-data-points-from-the-histogram/38936/3 "2020-04-17T07:10:14Z")

</div>

Thanks @couet.  
But hist.root does not allowed me to see the final data. Does it?  
Actually I need to see the data at each and every point.

---

<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:** [April 17, 2020, 7:13am UTC](https://root-forum.cern.ch/t/can-i-save-the-data-points-from-the-histogram/38936/4 "2020-04-17T07:13:26Z")

</div>

The histogram is stored in the file hist.root. You can Draw it etc … like a normal histogram

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 17, 2020, 7:14am UTC](https://root-forum.cern.ch/t/can-i-save-the-data-points-from-the-histogram/38936/5 "2020-04-17T07:14:16Z")

</div>

@couet  
No I am not asking about drawing the histogram but rather want to see the points.

---

<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:** [April 17, 2020, 7:18am UTC](https://root-forum.cern.ch/t/can-i-save-the-data-points-from-the-histogram/38936/6 "2020-04-17T07:18:06Z")

</div>

```auto
 hpx->Print("all")

```

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 17, 2020, 7:36am UTC](https://root-forum.cern.ch/t/can-i-save-the-data-points-from-the-histogram/38936/7 "2020-04-17T07:36:29Z")

</div>

@couet.  
Thanks it works.

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 18, 2020, 2:15pm UTC](https://root-forum.cern.ch/t/can-i-save-the-data-points-from-the-histogram/38936/8 "2020-04-18T14:15:35Z")

</div>

@couet @Wile_E_Coyote.  
Still there is an issue that i am unable to understand i.e. when i try to write the data of the background it is showing the values of x from 325 to 12800 but i only want from 128 to 8192.  
[basic.root](https://root-forum.cern.ch/uploads/short-url/l6vaZUA2XwUTmj1EyWDdTZ4XTmV.root) (30.0 KB) [eu\_gu\_1.txt](https://root-forum.cern.ch/uploads/short-url/kn9woacPX2mqQI0v5OngH2uYeGm.C) (44.1 KB) [trio.C](https://root-forum.cern.ch/uploads/short-url/z3zA1cKtWkPrNj7qz4wVFzTTLFA.C) (3.4 KB)[int.txt](https://root-forum.cern.ch/uploads/short-url/pTnxQJhZdNgCu85MLg43TMtayzu.txt) (180.5 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:** [April 18, 2020, 3:26pm UTC](https://root-forum.cern.ch/t/can-i-save-the-data-points-from-the-histogram/38936/9 "2020-04-18T15:26:49Z")

</div>

At least:  
`float x=h2->GetBinCenter(h2->FindFixBin(i));`

Note also that you are adding histograms with different axis limits ("`diff->Add(h2,-1.0);`").

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 18, 2020, 3:45pm UTC](https://root-forum.cern.ch/t/can-i-save-the-data-points-from-the-histogram/38936/10 "2020-04-18T15:45:12Z")

</div>

Thanks @Wile_E_Coyote.

> [@Wile\_E\_Coyote](#):
>
> Note also that you are adding histograms with different axis limits (" `diff->Add(h2,-1.0);` ").

how can i correct the above warning? because i guess i am adding with same axis limit.  
Also, how can i write the data from histogram(diff) in another file?
