I am trying to get the ratio of 2 TProfile histograms. Can someone help me with this? I have n idea about the TRatioplot. I tried dividing the two histograms but I obtain a blank histogram with no entries. I have tried various other process that I found online but I don’t get any results.
PLEASE HELP.
Thanks!
void Ratio()
{
TFile* fa = new TFile("n=2, S = 0 + S = 1.root", "READ");
TProfile* A = (TProfile*) fa->Get("hprof5");
TFile* fb = new TFile("n=3, S = 0 + S = 1.root", "READ");
TProfile* B = (TProfile*) fb->Get("hprof6");
printf("%f %f\n",A->GetEntries(),B->GetEntries());
}
Actually I have 4 different histograms. In A histogram I combined the first 2 histograms and in B the other two. Then I want to find the ratio between A and B histogram.
The thing is I need to put A and B in one Histogram. And C and D in another single histogram. Then find the ratio between these two. So what do you suggest I do?
Using S.C I was combining A and B into one root file. And C and D into another root file. Then I was trying to plot the ratio using Ratio.C. But as you said A and B are empty.
I just created hprof6 to plot A and B in the same histogram. Is there a better way to do it? Like I have all 4 histograms in the root files. I need to combine the 2_S0 with 2_s1 and 3_S0 with 3_S1. And after that plot the ratio between them.
hprof6 is just an empt frame you are using to draw the axis. You draw C and D on top of it (or A and B) . But that’s simply graphics when you save hprof6 you save an empty frame.
Okay so I decided to remove the hprof6(empty histogram). So how do I extract the histogram after Drawing A and B in the same canvas by using Draw(“SAMES”);?
I am not sure I understand what you mean by “extract” … you have two histogram A and B … you plot them. Fine that’s graphics… Use them directly in TRatioPlot for instance. It depends what you want to do.
Okay so I have 4 histograms A B C and D. I want A+B as one histogram, like in one canvas. And I want C+D as one histogram, in one canvas. Lets say A+B = F histogram. And C+D = G histogram. Now I want the ratio between F and G histograms.
Processing S.C…
Error in TProfileHelper::Add: Attempt to add profiles with different number of bins
I am getting this error. But all the TProfiles that I have created are by using the following command:
TProfile *hprof1 = new TProfile(“hprof1”, “Eccentricity vs b for n = 2 for S = 0”, 40, 0, 20);
TProfile *hprof1 = new TProfile(“hprof1”, “Eccentricity vs b for n = 2 for S = 0”, 40, 0, 20);
TProfile *hprof2 = new TProfile(“hprof2”, “Eccentricity vs b for n =2 for S = 1”, 40, 0, 20);
TProfile *sum = new TProfile(“sum”, “sum”, 40, 0, 20);
sum->Add(hprof1,hprof2);
This solution that you gave it works. Thank you very much and I really appreciate it.
But is there a way to change the color of the entries of hprof1 and hprof2 in the sum histogram. Because in sum all the entries are in same color. So is it possible to distinguish between them?