# Pull distribution is not equal to 1

**URL:** <https://root-forum.cern.ch/t/pull-distribution-is-not-equal-to-1/51054>\
**Category:** Newbie\
**Created:** [August 3, 2022, 5:17pm UTC](https://root-forum.cern.ch/t/pull-distribution-is-not-equal-to-1/51054 "2022-08-03T17:17:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edesa\_Behaj](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edesa_behaj/32/30282_2.png) [@Edesa\_Behaj](https://root-forum.cern.ch/u/Edesa_Behaj)\
**Post date:** [August 3, 2022, 5:17pm UTC](https://root-forum.cern.ch/t/pull-distribution-is-not-equal-to-1/51054/1 "2022-08-03T17:17:31Z")

</div>

hello, i am performing a gaussian toy study, but there seems to be a problem with my pull distribution, it’s not centered at 1, but 0.5, anyone can help?

```auto
void histogram () {

        TCanvas *c = new TCanvas("Toy study","Toy Study", 1000, 700);
                c->Divide(2,2);

                        c->cd(1);

        TF1 *f1= new TF1("f1","gaus(x)",-100,100);

                double mu_gen=0;
                double sigma=10;
                double cons=100;
                f1->SetParameter(0,cons);
                f1->SetParameter(1,mu_gen);
                f1->SetParameter(2,sigma);

        TH1F *h=new TH1F("h", "My histogram ; Gaussian mean 0 ; Number of entries",100,-60,60);
        TH1F *h_pull=new TH1F("h_pull","Pull distribution; (mu_gen-mu_fit)/mu_error; Number of entries ", 100, -2,2);
        TH1F *h_mu_difference= new TH1F("h_mu_difference","Mu_gen-Mu_fit; mu_gen-mu_fit; Number of entries",100,-0.1,0.1);
        TH1F *h_error= new TH1F("h_error","Error; error of mu; Number of entries ",100,-0.1,0.2);

for (int j=0; j<10000; j++){
//std::cout<<"iterations "<<j<<std::endl;

                h->FillRandom("f1",10000);

                        h->Fit("f1","R");

        double mu_fit=f1->GetParameter(1);
        double mu_error=f1->GetParError(1);
        double pull=( abs((mu_gen-mu_fit))/mu_error);

//std::cout<<"pull distribution"<<pull<<std::endl;

        double difference= mu_gen-mu_fit;
 h_mu_difference->Fill(difference);
                h_error->Fill(mu_error);
                h_pull->Fill(pull);

                f1->SetParameter(0,cons);
                f1->SetParameter(1,mu_gen);
                f1->SetParameter(2,sigma);

}
        std::cout<<"mu_fit"<<mu_fit<<std::endl;
        double error=f1->GetParError(1);
        legend->AddEntry(

        c->Draw();
        h->Draw();

        c->cd(2);

        h_pull->Draw();

        c->cd(3);

        h_error->Draw();

        c->cd(4);

        h_mu_difference->Draw();

}

```

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [August 3, 2022, 8:32pm UTC](https://root-forum.cern.ch/t/pull-distribution-is-not-equal-to-1/51054/2 "2022-08-03T20:32:33Z")

</div>

@moneta could you have a look please? Thanks!

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [August 4, 2022, 8:16am UTC](https://root-forum.cern.ch/t/pull-distribution-is-not-equal-to-1/51054/3 "2022-08-04T08:16:46Z")

</div>

Hi,  
Your code is not correct. You need to reset the histogram you are fitting for each iteration, otherwise you are increasing its content and you need to use for the toy generation always the same function parameters.  
Here is the code corrected, getting the right pull. Note that you should use option `L` to get better pull result since the default least square fit is biased when fitting histograms.

Cheers

Lorenzo  
[histogram.c](https://root-forum.cern.ch/uploads/short-url/lcRdRyyHP8NBidDKsWT9FvKN6jB.c) (1.7 KB)
