# \[question\] residual plot and chi2test

**URL:** <https://root-forum.cern.ch/t/question-residual-plot-and-chi2test/39107>\
**Category:** Newbie\
**Created:** [April 27, 2020, 6:41am UTC](https://root-forum.cern.ch/t/question-residual-plot-and-chi2test/39107 "2020-04-27T06:41:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shaggylee](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@Shaggylee](https://root-forum.cern.ch/u/Shaggylee)\
**Post date:** [April 27, 2020, 6:41am UTC](https://root-forum.cern.ch/t/question-residual-plot-and-chi2test/39107/1 "2020-04-27T06:41:51Z")

</div>

![resi](https://root-forum.cern.ch/uploads/default/original/3X/0/9/097a155a177de1910cb106f6ae7297e1e84f6fa7.png)

```auto
{
  TCanvas *c2 = new TCanvas("c2", "My Canavas", 1200, 450);
  c2->Divide(2,1);
  c2->cd(1);

  hQtot_Bi->SetNormFactor(1);
  hQtot_Bi->SetLineColor(kBlue);
  hQtot_Bi->SetLineWidth(2);
  hQtot_Bi->Draw("HIST");
  hQtot_Bi->SetStats(0);
  hQtot_Bi_d->Add(hQtot_Bi_g,-1);
  hQtot_Bi_d->SetNormFactor(1);
  hQtot_Bi_d->SetMarkerStyle(20);
  hQtot_Bi_d->SetMarkerSize(1);
  hQtot_Bi_d->Draw("PEsame");
  c2->Update();

  TCanvas *c3 = new TCanvas("c3", "residual", 1200, 900);
  hQtot_Bi->SetNormFactor(1);
  hQtot_Bi_d->SetNormFactor(1);
  TH1D *h1 = (TH1D*)hQtot_Bi->Clone("h1");
  h1->SetLineColor(kBlack);
  h1->SetLineWidth(2);
  h1->Sumw2();
  h1->SetStats(0);
  h1->Divide(hQtot_Bi_d);
  //h1->SetMinimum(0);
  //h1->SetMaximum(10000);
  hQtot_Bi->Chi2Test(hQtot_Bi_d, "WW P");
  h1->Draw("E0");
}

```

Hello Rooters.

I am attempting a residual plot of the spectrum obtained through MC simulation (blue line) and experiments (black dots). The experimental result is the spectrum excluding the background. The residual plot was done as shown in the figure below and the chi2 value was obtained. The chi2 value was 10576, the NDF value was 39. I am wondering if this code and the result obtained is correct. Please add a comment.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 27, 2020, 6:58am UTC](https://root-forum.cern.ch/t/question-residual-plot-and-chi2test/39107/2 "2020-04-27T06:58:19Z")

</div>

It looks fine. may be @moneta can comment.

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [April 27, 2020, 8:03am UTC](https://root-forum.cern.ch/t/question-residual-plot-and-chi2test/39107/3 "2020-04-27T08:03:25Z")

</div>

If you didn’t make any coding or analysis design mistakes then the result is correct 🙂 That said, the probability of ending up with chi2==10576 with NDF 39 is extremely small:

```auto
root [0] TMath::Prob(10576, 39)
(double) 0.0000000

```

That suggests that either the histogram uncertainties are incorrect (most likely) or there are other physics effects causing a discrepancy. I cannot see the uncertainties of `hQtot_Cs`; I don’t know the relation of `hQtot_Cs` or `hQtot_Cs_d` with `hQtot_Bi` and `hQtot_Bi_d`. But “is the uncertainty what I should expect” is a really good question to discuss with your physics group or supervisor.

Cheers, Axel.

---

<div class="post-metadata">

**Author:** ![Shaggylee](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@Shaggylee](https://root-forum.cern.ch/u/Shaggylee)\
**Post date:** [April 27, 2020, 8:08am UTC](https://root-forum.cern.ch/t/question-residual-plot-and-chi2test/39107/4 "2020-04-27T08:08:14Z")

</div>

Sorry for the confusion.  
hQtot\_Cs and hQtot\_Cs\_d are not included in the figure.  
Cs and Bi are seperate.

Thank you.
