# Transforming a graph into a histogram

**URL:** <https://root-forum.cern.ch/t/transforming-a-graph-into-a-histogram/47740>\
**Category:** Newbie\
**Created:** [November 19, 2021, 10:05pm UTC](https://root-forum.cern.ch/t/transforming-a-graph-into-a-histogram/47740 "2021-11-19T22:05:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SarahHamad](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/8797f3/32.png) [@SarahHamad](https://root-forum.cern.ch/u/SarahHamad)\
**Post date:** [November 19, 2021, 10:05pm UTC](https://root-forum.cern.ch/t/transforming-a-graph-into-a-histogram/47740/1 "2021-11-19T22:05:21Z")

</div>

Hello,  
I am working to get the probability distribution of a conditional statement ( probability of giving birth tomorrow if the mother didn’t give birth yet , the mean and standard deviation are given). I am thinking of modeling it as a gaussian distribution first giving the probability of giving birth as function of time ( in days) .(unconditional statement ). Then, transform the gaussian distribution into a histogram taking the width of the bins dt is 1 day, so the conditional probability we need becomes the area of the bin of the histogram at time t+1 ( probability of giving birth tomorrow) over 1- the integral of the gaussian from zero to t ( which is the error function) [probability of not giving birth till today]  
To transform the gaussian into a histogram, I am thinking of taking points with difference 1 between them, getting their probability and plotting the histogram, but is there a better way to do that ? And I would appreciate it if you have a comment on my approach to the problem if it is a good one or there is a flaw.

---

<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:** [November 20, 2021, 8:33am UTC](https://root-forum.cern.ch/t/transforming-a-graph-into-a-histogram/47740/2 "2021-11-20T08:33:23Z")

</div>

```cpp
{
  const int n_weeks = 66;
  TF1 *f = new TF1("f", "[0] * TMath::Gaus(x, [1], [2], 1)", 0., n_weeks * 7.);
  f->SetParNames("Constant", "Mean", "Sigma");
  f->SetNpx(n_weeks * 7 * 24); // "one per hour"
  // f->Print();
  // https://en.wikipedia.org/wiki/Gestational_age
  f->SetParameters(1., 283.4, 16.); // last menstrual period
  // f->SetParameters(1., 280.6, 14.); // second/first-trimester ultrasound
  TH1D *h =
    new TH1D("EDD",
             "Estimated Date of Delivery;Gestational age [day];Probability density [day^{-1}]",
             n_weeks * 7, 0., n_weeks * 7.); // one bin per day
  h->Sumw2(kFALSE); // just a precaution
  h->Eval(f, ""); // "fill" the histogram from the function
  h->ResetStats(); // calculate statistics from bin content
  TCanvas *c = new TCanvas("c", "EDD");
  h->Draw();
  f->Draw("same");
  gPad->SetGrid(1, 1);
}

```
