# Normalizing histograms inside .root file

**URL:** <https://root-forum.cern.ch/t/normalizing-histograms-inside-root-file/46256>\
**Category:** Newbie\
**Created:** [August 10, 2021, 12:16pm UTC](https://root-forum.cern.ch/t/normalizing-histograms-inside-root-file/46256 "2021-08-10T12:16:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cesar1](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/d9b06d/32.png) [@Cesar1](https://root-forum.cern.ch/u/Cesar1)\
**Post date:** [August 10, 2021, 12:16pm UTC](https://root-forum.cern.ch/t/normalizing-histograms-inside-root-file/46256/1 "2021-08-10T12:16:57Z")

</div>

Hello,

I am want to write a script so i can normalize the histograms in a .root file. i wrote the following script below, but the histograms inside the .root file are the same after i run the scripts, although the ones a plot are normalized.

the ster[] array is where i keep my histograms, and teste[] is where the name of the histograms go.

```auto

	for i in range(nHistograms):
		ster[i] = histFile.Get(teste[i])

	
	f = root.TFile("mc16e-LH-CVetoBVeto.root")
	w = f.Get("sumOfWeights")
	ws = w.GetBinContent(1)
	F = (1.01*0.85)/ws

	for i in range(nHistograms):
		ster[i].Scale(F/(ster[i].Integral()+1))

	for i in range(nHistograms):
		ster[i].SetDirectory (histFile)
		ster[i].Write()

```

So i would appreciate any help or tips.

Best Regards,  
Caio Cesar.

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [August 10, 2021, 3:49pm UTC](https://root-forum.cern.ch/t/normalizing-histograms-inside-root-file/46256/2 "2021-08-10T15:49:50Z")

</div>

Hi,

You should opened the TFile in writable mode. I would copy my original fills, in order not to loose it in case of a mistake and then do:  
`f = root.TFile("mc16e-LH-CVetoBVeto.root","UPDATE")`

Lorenzo

---

<div class="post-metadata">

**Author:** ![Cesar1](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/d9b06d/32.png) [@Cesar1](https://root-forum.cern.ch/u/Cesar1)\
**Post date:** [August 10, 2021, 4:54pm UTC](https://root-forum.cern.ch/t/normalizing-histograms-inside-root-file/46256/3 "2021-08-10T16:54:29Z")

</div>

It worked, thank you!
