Get values from projection

Hi!

I have no clue how this code works for you, because the TH1F *hist pointer is uninitialized and then you are dereferencing it in hist->Fill() :slight_smile:

Anyway, I think in principle what you do wrong is this: in your new histogram, you want to set the bin content exactly like in the projection histogram. With Fill(), you are only increasing the bin count by one in the bin that the value falls into, which is absolutely not what you want because the value is a bin count itself.

You should use TH1::SetBinContent() instead:

    for(int i(1); i<=entries; i++)
    {
        value = proj->GetBinContent(i);
        hist->SetBinContent(i, value);
    }

I hope this helps!

Jonas

1 Like