TH1D ProjectionX()

I have to project two separate TH2F to two TH1D. For that, I am using this code:

    TH2F *h2_s = (TH2F*)f->Get("hsig");
    TH2F *h2_b = (TH2F*)f->Get("hbg");
    TH1D *h1_s = h2_s->ProjectionX("",5,5);
    TH1D *h1_b = h2_b->ProjectionX("",5,5);

The problem is as soon as I project the background histogram signal, TH1D also fills up with the background.
I also found that in the ProjectionX() function page, it is mentioned that

NOTE that if a TH1D named “name” exists in the current directory or pad the histogram is reset and filled again with the projected contents of the TH2.

I am guessing this is the problem, but I am not sure how to fix this.


ROOT Version:6.24/02
Platform:(NAME=“HefftorLinux”,ID_LIKE=“arch”,VERSION_ID=v2021-02-05)
Compiler: gcc 11.1.0

    TH1D *h1_s = h2_s->ProjectionX("h1_s",5,5);
    TH1D *h1_b = h2_b->ProjectionX("h1_b",5,5);
1 Like

Thanks a lot!