# Saving histogram data as a map or vector pair

**URL:** <https://root-forum.cern.ch/t/saving-histogram-data-as-a-map-or-vector-pair/48564>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [January 25, 2022, 11:09pm UTC](https://root-forum.cern.ch/t/saving-histogram-data-as-a-map-or-vector-pair/48564 "2022-01-25T23:09:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![abunka](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@abunka](https://root-forum.cern.ch/u/abunka)\
**Post date:** [January 25, 2022, 11:09pm UTC](https://root-forum.cern.ch/t/saving-histogram-data-as-a-map-or-vector-pair/48564/1 "2022-01-25T23:09:40Z")

</div>

What would be the easiest way to save the contents of a histogram as a map or vector pair of bin centers and values? I would like to have something similar to the result of Print('range"), where the bin centers and histogram values are nicely paired up, but as an easily usable cpp item.  
I am using root 6.20/06, on lxplus.  
Thanks!

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [January 26, 2022, 4:58am UTC](https://root-forum.cern.ch/t/saving-histogram-data-as-a-map-or-vector-pair/48564/2 "2022-01-26T04:58:55Z")

</div>

Just loop over the bins (1 to nbins, or whatever range) and use GetXaxis()-\>GetBinCenter and GetBinContent for x and y, saving them in vectors.  
[https://root.cern/doc/master/classTH1.html#a0ee88e02b75d885985097dcde0a9eaa1](https://root.cern/doc/master/classTH1.html#a0ee88e02b75d885985097dcde0a9eaa1)
