# Optimal way to compare and validate simulation and experimental data

**URL:** <https://root-forum.cern.ch/t/optimal-way-to-compare-and-validate-simulation-and-experimental-data/50207>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [June 1, 2022, 2:22am UTC](https://root-forum.cern.ch/t/optimal-way-to-compare-and-validate-simulation-and-experimental-data/50207 "2022-06-01T02:22:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fr4nk](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fr4nk/32/24294_2.png) [@Fr4nk](https://root-forum.cern.ch/u/Fr4nk)\
**Post date:** [June 1, 2022, 2:22am UTC](https://root-forum.cern.ch/t/optimal-way-to-compare-and-validate-simulation-and-experimental-data/50207/1 "2022-06-01T02:22:46Z")

</div>

Hi All,

I currently have two histograms, both TH1F, 75 bins, one experimental data, the other data from a Geant4 simulation. The histograms represent frequency of photoelectrons detected in a photomultiplier tube; counts vs number of photoelectrons.

I am curious to learn of any built in ROOT methods that will allow me to compare these two datasets, and determine if the simulation is a decent model of the experiment. All and any suggestions are greatly appreciated.

Thank you in advance!

-Frank

_ROOT Version:_ 6.22/06  
_Platform:_ MacOS Big Sur  
_Compiler:_ gcc

* * *

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 1, 2022, 7:12am UTC](https://root-forum.cern.ch/t/optimal-way-to-compare-and-validate-simulation-and-experimental-data/50207/2 "2022-06-01T07:12:25Z")

</div>

[TRatioPlot](https://root.cern/doc/master/classTRatioPlot.html)  
[TH1::AndersonDarlingTest](https://root.cern/doc/master/classTH1.html#aa6b386786876dc304d73ab6b2606d4f6)  
[TH1::Chi2Test](https://root.cern/doc/master/classTH1.html#a6c281eebc0c0a848e7a0d620425090a5)  
[TH1::KolmogorovTest](https://root.cern/doc/master/classTH1.html#aeadcf087afe6ba203bcde124cfabbee4)

---

<div class="post-metadata">

**Author:** ![Fr4nk](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fr4nk/32/24294_2.png) [@Fr4nk](https://root-forum.cern.ch/u/Fr4nk)\
**Post date:** [June 1, 2022, 1:09pm UTC](https://root-forum.cern.ch/t/optimal-way-to-compare-and-validate-simulation-and-experimental-data/50207/3 "2022-06-01T13:09:13Z")

</div>

@Wile_E_Coyote,

Thanks so much! With regards to the chi-squared test, would you happen to know or have any suggestion as to how to determine the degrees of freedom for my data?

From my understanding, given that I have 75 bins, each representing a number of photoelectrons, that the degrees of freedom would be: 75-1 = 74. Is this wildly off?

Thanks again for all of your help!

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 1, 2022, 6:32pm UTC](https://root-forum.cern.ch/t/optimal-way-to-compare-and-validate-simulation-and-experimental-data/50207/4 "2022-06-01T18:32:22Z")

</div>

You can use [the `"P"` TH1::Chi2Test option](https://root.cern/doc/master/classTH1.html#a6c281eebc0c0a848e7a0d620425090a5) to print “NDF”.  
I guess: “NDF” = “number of histogram bins” - 1 - “number of bins which are 0 in both histograms simultaneously”.

---

<div class="post-metadata">

**Author:** ![Fr4nk](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fr4nk/32/24294_2.png) [@Fr4nk](https://root-forum.cern.ch/u/Fr4nk)\
**Post date:** [June 1, 2022, 9:30pm UTC](https://root-forum.cern.ch/t/optimal-way-to-compare-and-validate-simulation-and-experimental-data/50207/5 "2022-06-01T21:30:25Z")

</div>

@Wile_E_Coyote ,

Thank you so much. I misread the reference for the chi squared test you provided. I thought that the user would have to supply the degrees of freedom.

Thank you again for your time and help.

-Frank
