#include "TF1.h" #include "TH1F.h" #include "TCanvas.h" TH1F* Calibrate(TH1F* h, TF1* f, int n, float fmin, float fmax) { // here, we draw a TH1F from the function, fit and compute the chi2. // we iterate to extract the "chi2 distribution". // this is for the result TH1F* chisqu = new TH1F("chisqu","chisqu",1000,0,10); // we clone the fit function. We will use it to fill pseudo-experiments TF1* ff = (TF1*)f->Clone("ff"); ff->SetName("ff"); // we clone the histogram. We will use it to have the right binning, etc. // we extract also the number of entries. //TH1F* h = new TH1F("histo","histo",1000,0,4096); int entries = h->GetEntries(); TH1F* hh = (TH1F*)h->Clone("hh"); for(int i = 0;iClear(); hh->Reset(); hh->FillRandom("user",entries); hh->Fit("ff","LQ0","",fmin,fmax); chisqu->Fill(ff->GetChisquare()/ff->GetNDF()); } new TCanvas; chisqu->Draw(); return chisqu; }