Can the SumOfWeights be changed in a TH1?


I have a collection o histograms, some generated with mc@nlo. While doing a simple ABCD for the estimation of QCD, we subtract all of the MC processes from the Data histogram. However, the problem is that we end up with a histogram which has a negative SumOfWeights() but the bin contents are positive. Is there a function which allows to change the SumOfWeights of a histogram ? Any alternative solution to cure this ?



Hi Alex,

You can use hist->GetSumw2() and set its elements.

Note, though, that a negative sumw2 means that this is not a sumw2 anymore! I.e. I’d claim that there’s no point in calculating this; you might as well call hist->Sumw2(false).

Cheers, Axel.

Hi Axel

[quote=“Axel”]Hi Alex,

You can use hist->GetSumw2() and set its elements.

Could you give me an example how to do so ?



TArrayD* sumw2 = histWithNegSumw2->GetSumw2();

for (int i = 0, n = sumw2->GetSize(); i < n; ++i) {
  if (sumw2[i] < 0.) sumw2[i] = 0.;

should work. But again - I’d recommend to simply call


because those sums of weights are likely not to be used as bin uncertainties.

Cheers, Axel.