Problem with Draw option "norm"

One of my tuples does not appear to be normalizing correctly.
I’m comparing data and MC for several conditions and am plotting normalized histograms on top of each other for this comparison. Most of these work fine; the histograms clearly have the same area and peak at a height around 0.05.
For one of my tuples, however, both branches of it that I Draw normalized peak at a height about 0.12 and clearly have a much larger area than the normalized branches of other tuples. These also are drawn with an xaxis range much larger than is apparently necessary, suggesting that something is wrong with the tuple, but I don’t know what it could be. Here is a code snippet:

[code] gROOT->SetBatch(kTRUE);
TFile *f1 = TFile::Open("[redacted]");
TFile *f2 = TFile::Open("[redacted]");
TFile *f3 = TFile::Open("[redacted]");
TFile *f4 = TFile::Open("[redacted]");

THStack *hs1 = new THStack(“hs1”,"");
TCanvas *c1 = new TCanvas(“c1”,“2011nTracks”,1200,800);
gStyle->SetOptStat("");
f1->cd(“tupleb2D0Mu”);
tupleb2D0Mu->Draw(“nTracks>>h11”,"",“norm”);
TH1F h11 = (TH1F)gPad->GetPrimitive(“h11”);
hs1->Add(h11);
f2->cd(“Tuple_b2D0MuX”);
DecayTree->SetLineColor(kRed);
DecayTree->Draw(“nTracks>>h12”,"",“norm”);
TH1F h12 = (TH1F)gPad->GetPrimitive(“h12”);
hs1->Add(h12);
hs1->SetTitle(“2011: B^{-}->(D^{0}->K^{-} #pi^{+})#mu^{-}: nTracks”);
hs1->Draw(“nostack”);
c1->Print(“tracksplots.pdf(”);
[/code]

This generates the expected image; both histograms appear on top of each other just as they do when drawn separately. But h11 clearly has a much larger area than h12. Furthermore, normalized branches plotted from f2, f3, and f4 using the same formula all appear to have the same area under the curve. Any thoughts?

Can you provide a small running reproducer ?

I’m sorry, I’m not sure what that means.

We can’t run the piece of code you sent.
Can you provide something we can run ? so we can see what goes wrong ?

Well the root files I open are multiple GB, so I’m not sure how to give that to you. I’ve attached the relevant output. Here is a modified version of the fragment I provided that should run (apart from the lack of files of course):

void maketracksplots(  ) {
  gROOT->SetBatch(kTRUE);
  TFile *f1 = TFile::Open("[redacted].root");
  TFile *f2 = TFile::Open("[redacted].root");
  TFile *f3 = TFile::Open("[redacted].root");
  TFile *f4 = TFile::Open("[redacted].root");
 
  THStack *hs1 = new THStack("hs1","");
  TCanvas *c1 = new TCanvas("c1","2011nTracks",1200,800);
  gStyle->SetOptStat("");
  f1->cd("tupleb2D0Mu");
  tupleb2D0Mu->Draw("nTracks>>h11","","norm");
  TH1F *h11 = (TH1F*)gPad->GetPrimitive("h11");
  hs1->Add(h11);
  f2->cd("Tuple_b2D0MuX");
  DecayTree->SetLineColor(kRed);
  DecayTree->Draw("nTracks>>h12","","norm");
  TH1F *h12 = (TH1F*)gPad->GetPrimitive("h12");
  hs1->Add(h12);
  hs1->SetTitle("2011: B^{-}->(D^{0}->K^{-} #pi^{+})#mu^{-}: nTracks");
  hs1->Draw("nostack");
  c1->Print("tracksplots.pdf(");
  
  THStack *hs2 = new THStack("hs2","");
  TCanvas *c2 = new TCanvas("c2","2011nLongTracks",1200,800);
  gStyle->SetOptStat("");
  f1->cd("tupleb2D0Mu");
  tupleb2D0Mu->Draw("nLongTracks>>h21","","norm");
  TH1F *h21 = (TH1F*)gPad->GetPrimitive("h21");
  hs2->Add(h21);
  f2->cd("Tuple_b2D0MuX");
  DecayTree->SetLineColor(kRed);
  DecayTree->Draw("nLongTracks>>h22","","norm");
  TH1F *h22 = (TH1F*)gPad->GetPrimitive("h22");
  hs2->Add(h22);
  hs2->SetTitle("2011: B^{-}->(D^{0}->K^{-} #pi^{+})#mu^{-}: nLongTracks");
  hs2->Draw("nostack");
  c2->Print("tracksplots.pdf)");
}

tracksplots2.pdf (32.3 KB)

One of my coworkers figured it out. Turns out it’s an issue with the binning. Root was assigning more bins to the smaller histogram it seems and this was throwing it off. This code works: THStack *hs1 = new THStack("hs1",""); TCanvas *c1 = new TCanvas("c1","2011nTracks",1200,800); gStyle->SetOptStat(""); f1->cd("tupleb2D0Mu"); TH1F *h11 = new TH1F("h11","nTracks",107,0,2140); tupleb2D0Mu->Draw("nTracks>>h11","","norm"); hs1->Add(h11); f2->cd("Tuple_b2D0MuX"); TH1F *h12 = new TH1F("h12","nTracks",107,0,2140); h12->SetLineColor(kRed); DecayTree->Draw("nTracks>>h12","","norm"); hs1->Add(h12); hs1->SetTitle("2011: B^{-}->(D^{0}->K^{-} #pi^{+})#mu^{-}: nTracks"); hs1->Draw("nostack"); c1->Print("tracksplots.pdf(");
So we manually set the binning ahead of drawing the histogram to ensure they are binned the same. The binning was found by doing c1->SaveAs(“file.C”); and looking at the construction of the histogram in the resulting file. With the binning set the same, the histograms come out the same size. Note that I had to change how the line color was set from a property of the tree to a property of the histogram; not sure why this was the case.