Home | News | Documentation | Download

Correlation between two histograms

Hi ,
I have a small problem. I have a root file which has only histograms ( no trees and branches) , now I want to have a correlation between the two histogram/histogram variables in this root file . I am unable to do so . I am attaching a code ( which is not working ) please have a look at it and see one of you can help me. Thank you
corr.C (1.46 KB)

Hi,

[quote=“sircar”]Hi ,
I have a small problem. I have a root file which has only histograms ( no trees and branches) , now I want to have a correlation between the two histogram/histogram variables in this root file . I am unable to do so . I am attaching a code ( which is not working ) please have a look at it and see one of you can help me. Thank you[/quote]

If you have two 1D histograms of different variables, there is no way to get the correlations between the two variables as the information is lost. At the very least, you need a 2D histogram of the two variables in question.

Cheers,
Charles

Hi–

If you have distributions for two variables (each TH1’s) and want to find the correlation coefficient for these two variables, I’d imagine you’d create a TH2 with the appropriate number of bins for each axis, and then use the TH2::GetCorrelationFactor method:
https://root.cern.ch/doc/master/TH2_8cxx_source.html#l01025
which will return a double value.

Best,
Andrew