Filling new histograms from center bin of another histogram

Hello everyone,

Suppose I have produced a histogram called A.
Now getting the center bins from A, I will perform an operation for example: “each data point (from the center bins) - 1”, then using the new results to fill a new histogram B.
What is the proper way to complete the above operations in ROOT

Thank you.

Hi,

You can get the center of bins with GetCenter, then to fill the second histogram you can check tutorials like:

https://root.cern/doc/master/fillhistosauto2p_8C.html

Is this enough information for what you want to do?

@moneta might be able to complete my answer.

Hi,
Here is some simple code to get content from histogram histA and fill histogram histB:

for (int i = 1; i <= histA->GetNbinsX(); i++) {
     double x  = histA->GetXaxis()->GetBinCenter(i); 
     double cont = histB->GetBinContent(i); 
     // set now content in histogram b using contend of histogram A as weight
      histB->Fill( x, cont); 
}

Thank you.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.