# Using RDataFrame Vary function and save histograms

**URL:** <https://root-forum.cern.ch/t/using-rdataframe-vary-function-and-save-histograms/57782>\
**Category:** Newbie\
**Tags:** rdataframe, root\
**Created:** [January 9, 2024, 3:25pm UTC](https://root-forum.cern.ch/t/using-rdataframe-vary-function-and-save-histograms/57782 "2024-01-09T15:25:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eneb](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/87869e/32.png) [@eneb](https://root-forum.cern.ch/u/eneb)\
**Post date:** [January 9, 2024, 3:25pm UTC](https://root-forum.cern.ch/t/using-rdataframe-vary-function-and-save-histograms/57782/1 "2024-01-09T15:25:44Z")

</div>

Hello experts,

i have a question regarding the Vary function and usage of these histograms afterwards. In short, I want to use the Vary function for bootstrapping. Afterwards, I want to save all the histograms in a root file. I am using python. The code for filling the different histograms looks like this

```auto
histogram_dictionary[hist_1] = df.Filter(selection).Vary("weight", "Rndweight * weight", [f"weight_{j}" for j in range(1000)].Histo1D((name,name,number of bins, bin0, bin1), "event numbers", "weight"))

```

And then I want to get and save all the histograms like this:

```auto
hx = ROOT.RDF.Experimental.VariationsFor(histogram_dictionary[hist_1])
for i in range(1000):
     hx[f"weight:weight_{i}"].Write("",ROOT.TObject.kOverwrite)
histogram_dictionary[hist_1].Write("",ROOT.TObject.kOverwrite)

```

It appears only the nominal histogram is getting saved (last line) and not all the histograms with different weights. Even though these are computed (at least the code takes longer than without the bootstrapping histograms). To me it seems like I am missing something obvious. I hope you can help me.

Thanks in advance!

---

<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 10, 2024, 4:18am UTC](https://root-forum.cern.ch/t/using-rdataframe-vary-function-and-save-histograms/57782/2 "2024-01-10T04:18:58Z")

</div>

> [@eneb](#):
>
> `Write("",ROOT.TObject.kOverwrite)`

You are saving all under the same (empty) name “”; try giving to each its own name.

---

<div class="post-metadata">

**Author:** ![eneb](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/87869e/32.png) [@eneb](https://root-forum.cern.ch/u/eneb)\
**Post date:** [January 10, 2024, 8:37am UTC](https://root-forum.cern.ch/t/using-rdataframe-vary-function-and-save-histograms/57782/3 "2024-01-10T08:37:12Z")

</div>

Thanks for spotting this! I used the empty name, as ROOT then automatically takes the name from GetName function, but I did not realize, that also all the bootstrapping histograms have the same name, so it gets overwritten every time. I changed the names and now it works!
