# Rescaling of Histogram

Dear experts,

I have a naive question. Lets say I have two histograms with respect to number of events observed. For one histogram I have 50K data point and for the second one I have 20K data point. Now I don’t want to normalize with `h->Scale(1/h->Integral());` rather I want to change the scale so that I can compare both the histogram as if both the histograms have same number of data point. Is there a way to do so ?

Second question:
Now, consider I have 3 histograms, with first, second and third has 50k, 20k, 5k data points respectively.
for the third one it has (5/20) 1/4 th fraction of data points with respect to second histogram. Now , how could I rescale the third and second histogram so that, I can compare the three histogram, where first and second will have same number of data points and thrid one will have 1/4th of data points with respect to the new rescaled second histogram.

I would like to have something like this below picture.

Any help will be greatly appreciated.

Regards,

I think normalizing is the way to go (for instance as presented in this example).
To help you further you might post the histograms so we can understand better what you want to achieve.

Do you mean the root files?
Final plots should look like the picture I have posted in the first post.

for instance…

I don’t know if this helps or not. This is the solution as far as I have understood the question. As @couet mentioned a macro file or root file will help us understand question even better.

`> h->Scale(1/h->GetMaximum());`

Looks like it worked indeed.
I am posting the example macro scale.C to illustrate the matter I am trying to do. Please check and let me know is my understanding correct or not.

You can generate the plots just by executing the macro.

1. scale_v1.pdf - RAW distribution (histogram) I have that I want to use as input.
2. scale_v2.pdf - Normalized histogram with respect to area.
3. scale_v3.pdf - This is the thing I needed. Here I have use `h->Scale(1/h->GetMaximum())` to normalize the histograms. I wanted that histogram2 is normalized with respect to data points observed in histogram1. And normalize the histogram3, keeping that the fraction of events between histogram2 and histogram3 remains same before and after the normalization.

Let me inform you one more thing.

1. Histogram1 & Histogram2 can be considered Data and MC, respectively. So, they should match after rescalling or normalization.
2. Histogram3 is a part of Histogram2 . So, after normalization or rescaling Histogram1 & Histogram2 should match, and Histogram3 will be less than Histogram1 or Histogram2.
3. Also if I add Histogram4 which also a part of Histogram2 , should match the criteria of point 2.
4. Just like the plot I have posted in the question.

Hi,
I added a piece to your code. You can find it below.

Basically I added the scale factor

``````double scale_factor=hist1_cp3->Integral()/hist2_cp3->Integral();
``````

In this way the Histogram2 is scale to have the same area of Histogram1.
Then I used the same scale factor to scale Histogram3.

In this way Histogram2 and Histogram3 have the same ratio.

``````TCanvas* can4 = new TCanvas("can4", "Histogram", 800, 600);

TH1F* hist1_cp3 = (TH1F*)hist1->Clone();

TH1F* hist2_cp3 = (TH1F*)hist2->Clone();

double scale_factor=hist1_cp3->Integral()/hist2_cp3->Integral();

hist2_cp3->Scale(scale_factor);

TH1F* hist3_cp3 = (TH1F*)hist3->Clone();
hist3_cp3->Scale(scale_factor);
//hist3_cp2->Scale(hist2->Integral()/hist3_cp2->Integral());

hist1_cp3->SetTitle("can4");
hist1_cp3->SetStats(0);
hist1_cp3->GetYaxis()->SetRangeUser(0, 1.2 * hist1_cp3->GetMaximum());

hist1_cp3->SetLineColor(kBlue);
hist1_cp3->Draw("hist");
hist2_cp3->SetLineColor(kRed);
hist2_cp3->Draw("same hist");
hist3_cp3->SetLineColor(kGreen);
hist3_cp3->Draw("same hist");

TLegend* legend4 = new TLegend(0.7, 0.7, 0.8, 0.8);
legend4->SetBorderSize(0);