# Fit histogram to another historgam

**URL:** <https://root-forum.cern.ch/t/fit-histogram-to-another-historgam/53407>\
**Category:** Newbie\
**Tags:** hist, root\
**Created:** [February 2, 2023, 10:54am UTC](https://root-forum.cern.ch/t/fit-histogram-to-another-historgam/53407 "2023-02-02T10:54:38Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [February 2, 2023, 12:04pm UTC](https://root-forum.cern.ch/t/fit-histogram-to-another-historgam/53407/4 "2023-02-02T12:04:21Z")

</div>

I guess, in general (when stretching/shrinking and scaling are needed), you would need to write your own “chi2” or “likelihood” function.  
See: [`${ROOTSYS}/tutorials/fit/`](https://root.cern/doc/master/group __tutorial__ fit.html)

You could also try to use (but the involved histograms need to have well “aligned” bins, I guess):

- [TFractionFitter](https://root.cern/doc/master/classTFractionFitter.html)

- an idea given in:

> [@Newbie Fit/RooFit Question](https://root-forum.cern.ch/t/newbie-fit-roofit-question/53334/3):
>
> Hi @katrina09, indeed, RooFit is well suited for this! You can find the necessary code snippets for your task in the [RooFit tutorials](https://root.cern.ch/doc/master/group __tutorial__ roofit.html). In particular, take a look at: [ROOT: tutorials/roofit/rf706\_histpdf.C File Reference](https://root.cern.ch/doc/master/rf706__histpdf_8C.html), which tells you how to build a pdf based of template histograms [ROOT: tutorials/roofit/rf201\_composite.C File Reference](https://root.cern.ch/doc/master/rf201__composite_8C.html), which tells you how to create the normalized sum of two pdfs Note that in ht e tutorial overview, there are also links to the Python version of both tu…

---

_[View the full topic](https://root-forum.cern.ch/t/fit-histogram-to-another-historgam/53407)._
