Normalizing histograms inside .root file


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.

	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):

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

So i would appreciate any help or tips.

Best Regards,
Caio Cesar.


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")


1 Like

It worked, thank you!