How to fill histogram with values and errors?


I want to fill a TH1D with some values and their errors calculated by myself.
At the moment I fill the TH1 in a loop (i++) with

but I have no idea how to add my own errors (for the values :wink: )?

Cheers & Thanks,




What if I want to use the option hist->Fill(x,weight) option instead of hist->SetBinContent and hist->SetBinError? Would it still work and how should be the weights included as errors? I am asking so because the SetBinContent option filled hist is not very good for physics analysis

Search for occurrences of the string “weight” in the TH1 class reference.

The hist->Fill(x,w) has w as a weight, so I do not understand what you mean by search weight. I want a formula that can give a smaller weight to a value with more significant errors. In my opinion, one way will be to use hist->Fill(x,1/error) but I am not sure

What @Wile_E_Coyote means is that if you search the string “weight” in the page he pointed you willl get all the explanations you are looking for.