#include #include #include #include #include #include #include "PLFit.h" #include "PLUtil.h" #include "fitPar.h" #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; PLFit* plf; // must be global to communicate with fcn (see below) int main(int argc, char *argv[]) { // Important parameter values double nuTot = 10000; // mean total number of entries int nBin = 50; double xMin = 0.; double xMax = 1.; int nparFitMax = 6; // Set up histograms, function objects, etc. TFile* file = new TFile("PLFit.root", "recreate"); vector chi2Hist; for (int i=0; i<=nparFitMax; i++){ stringstream ss1, ss2; string istr1, istr2; ss1 << max(i-1,0); ss1 >> istr1; ss2 << i; ss2 >> istr2; string histName = "h_chi2_" + istr1 + istr2; string histTitle = "chi2_" + istr1 + istr2; TH1D* h = new TH1D(histName.c_str(), histTitle.c_str(), 400, 0., 400.); chi2Hist.push_back(h); } vector deltaChi2Hist; for (int i=0; i> istr1; ss2 << i+1; ss2 >> istr2; string histName = "h_deltaChi2_" + istr1 + istr2; string histTitle = "deltaCchi2_" + istr1 + istr2; TH1D* h = new TH1D(histName.c_str(), histTitle.c_str(), 400, 0., 400.); deltaChi2Hist.push_back(h); } int nBern = 2; int npar = nBern+1; vector trueBeta(npar); trueBeta[0] = 1.; trueBeta[1] = 0.5; trueBeta[2] = 1.5; int fitOption = 0; vector truePdfPar; plf = new PLFit(xMin, xMax, nBin, truePdfPar, nuTot, trueBeta, fitOption); vector modelBeta(npar); for (int i=0; i pdfPar; pdfPar = truePdfPar; plf->setModelHist(pdfPar, modelBeta); plf->generateData(ran); // test hypothetical distribution using the data set vector chi2Array; for (int nparFit=0; nparFit<=nparFitMax; nparFit++){ // fit parameters and compute profile likelihood ratio vector parVec; vector > V; // covariance matrix of fitted parameters for (int i=0; i > rho; for (int k=0; k rowK; for (int l=0; lintegrateModel(30, 39, y, sigma, parVec, V); // cout << nparFit << " " << y << " " << sigma << endl; if ( j%max(numExp/10,1) == 0 && j > 0 && nparFit == nparFitMax ) { cout << "generated experiment " << j << endl; } // cout << nparFit << " " << chi2Min << " " << pval << endl; } // end loop over number of fitted parameters for (int n=0; n<=nparFitMax; n++){ chi2Hist[n]->Fill(chi2Array[n]); int ndof = plf->nBin() - n; double pval0 = TMath::Prob(chi2Array[n], ndof); if ( n < nparFitMax ) { double deltaChi2 = chi2Array[n] - chi2Array[n+1]; deltaChi2Hist[n]->Fill(deltaChi2); double pval01 = TMath::Prob(deltaChi2, 1); cout << n << " & " << chi2Array[n] << " & " << pval0 << " & " << deltaChi2 << " & " << pval01 << " \\\\ " << endl; } else { cout << n << " " << chi2Array[n] << " " << pval0 << endl; } } } // end loop over experiments // store histograms and close up file->Write(); file->Close(); return 0; }