Generate a new histogram using center bins from another histogram

Hello everyone,

Please refer to to code below could draw a histogram h_enu_sub by getting the content from h_ibd_sub (which is a returned value / histogram that have been generated), Now I need to use the bin center of the “old” histogram “h_ibd_sub” to generate a new histogram “h_enu_sub”

TH1F* h_enu_sub (TH1F* enu, h_ibd_sub->GetBinContent(ibin));
for ( int ibin = 1; ibin <= h_ibd_sub->GetNbinsX(); ++ibin) {

float ep = h_ibd_sub->GetBinCenter(ibin);

float cos = 1;

float e = 0.51099895;

float p = 938.27208816;

float n = 939.56542052;

float k = ep - 2 * e;

float q = sqrt (k * k + 2 * e * k)

float enu = (k * k - 2 * k * p + 2 * e * k - n * n + p * p - 2 * e * p - q * q + e * e) / (2 * (-cos * q + e + k - p));

TH1F* h_enu_sub = (TH1F*) h_enu_sub->Fill(enu, h_ibd_sub->GetBinContent(ibin));

return h_enu_sub

}

Your help will be appreciated

One way is creating the new histogram using an array that contains the lower edges of each bin, see this constructor.
To create the array, you can just do, for each bin: lower_edge = bin_centre - bin_width/2; e.g. in your loop over the bins:

low_e = h_ibd_sub->GetXaxis()->GetBinCenter(ibin) - h_ibd_sub->GetXaxis()->GetBinWidth(ibin)/2;
edges[ibin] = low_e;

GetBinCenter, GetBinWidth are described in the same page above.