Normalization of Histograms

Hi Rooters . Hope so you are all doing well .
I have seven histograms from seven different root files now i want to normalize them to unit area .
what i am doing is

   TFile *f1 = new TFile("ww.root");
  TFile *f2 = new TFile("TT.root");
  TFile *f3 = new TFile("TTZT.root");

  TH1F *h1 = (TH1F*)f1->Get("W_Tran_mass");
  TH1F *h2 = (TH1F*)f2->Get("W_Tran_mass");
  TH1F *h3 = (TH1F*)f3->Get("W_Tran_mass");
  
  Double_t scale = 1/(h1->GetEntries());
  h1->Scale(scale);
 
  Double_t scale = 1/(h2->GetEntries());
  h2->Scale(scale);
  
 Double_t scale = 1/(h3->GetEntries());
  h3->Scale(scale);
  
  h1->Draw();
   h2->Draw("same");
  h3->Draw("same")
}

getting nothing .try diiferent root tutorials but getting no idea how i do it .
Kindly Help me.

Best Regards

Somehow I have your root files already. If I do:

{
   TFile *f1 = new TFile("WW.root");
   TFile *f2 = new TFile("TT.root");
   TFile *f3 = new TFile("TTZT.root");

   TH1F *h1 = (TH1F*)f1->Get("W_Tran_mass");
   TH1F *h2 = (TH1F*)f2->Get("W_Tran_mass");
   TH1F *h3 = (TH1F*)f3->Get("W_Tran_mass");

   Double_t scale = 1./(h1->GetEntries());
   h1->Scale(scale);

   scale = 1./(h2->GetEntries());
   h2->Scale(scale);

   scale = 1./(h3->GetEntries());
   h3->Scale(scale);
   h1->Draw("hist");
   h2->SetLineColor(kRed);  h2->Draw("hist same");
   h2->SetLineColor(kGreen);h3->Draw("hist same");
}

I get:

Note that in the version of your files I have h2 and h3 are exactly the same that’s why we do not see any red histogram as it is exactly covered by the green one

1 Like

yup i do it and get a little bit different from yours .
Thank you so much for your quick reply:smiley:

Best Regards

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