# TProfile errors after SetBinContent in TH2

**URL:** <https://root-forum.cern.ch/t/tprofile-errors-after-setbincontent-in-th2/32590>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [February 5, 2019, 12:57pm UTC](https://root-forum.cern.ch/t/tprofile-errors-after-setbincontent-in-th2/32590 "2019-02-05T12:57:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aleopold](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@aleopold](https://root-forum.cern.ch/u/aleopold)\
**Post date:** [February 5, 2019, 12:57pm UTC](https://root-forum.cern.ch/t/tprofile-errors-after-setbincontent-in-th2/32590/1 "2019-02-05T12:57:56Z")

</div>

* * *

_ROOT Version:_ 6.10.04-x86\_64-slc6-gcc62-opt  
_Platform:_ lxplus  
_Compiler:_ Not Provided

* * *

Hi!

I have a TH2F histogram, that I am scaling per “line” in y along the x axis. I already know this sounds confusing, so I will just add here the function that does that for me:

```auto
void ScaleLineX(TH2F* hist,int bin_x_max, int bin_y_max){

  double integral_line=0;
  for(int x=0; x<=bin_x_max; x++){
    integral_line = hist->Integral(x, x, 0, bin_y_max);
    if(integral_line>0){
      for(int y=1; y<=bin_y_max; y++){
        hist->SetBinContent(x, y, hist->GetBinContent(x,y)/integral_line);
      }
    }
  }
}

```

that I call with

`ScaleLineX(hist, hist->GetNbinsX()+1, hist->GetNbinsY()+1);`

if I have scaled the histogram like this, the errors on a ProfileX (called without options) on that histogram seem to be now the RMS instead of the RMS/sqrt(n).

I am not sure I understand the behaviour, would be happy if somebody has an explanation!

Thanks a lot,  
Alex

PS: I have put for testing the rootfile I use on lxplus (/afs/cern.ch/user/a/aleopold/public/rootforum/output.root, the th2f called “hist\_nhits\_over\_eta”)

---

<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:** [February 5, 2019, 2:28pm UTC](https://root-forum.cern.ch/t/tprofile-errors-after-setbincontent-in-th2/32590/2 "2019-02-05T14:28:44Z")

</div>

Hi,

When you are scaling an histogram you should also scale the errors, otherwise they will just be the sqrt(content) and probably not correct in your case.  
For scaling with just a constant value, can use the TH1::Scale function which does it automatically, if you call TH1::Sumw2() before.

Lorenzo
