#include "TFile.h" #include "TTree.h" #include "TH1D.h" #include "TF1.h" #include "TRandom3.h" void troubleshootFillRandom() { TH1D *templateHist = new TH1D("templateHist", "", 20, -10, 10); TF1* myGaus = new TF1("myGaus", "gaus", -10, 10); myGaus->SetParameter(0, 1); myGaus->SetParameter(1, 0); myGaus->SetParameter(2, 3); templateHist->FillRandom("myGaus", 10000); //templateHist->Draw(); TF1 *unif = new TF1("unif", "1.0", -10, 10); Double_t chi2 = 0; TH1D *hist1 = new TH1D("hist1", "", 20, -10, 10); TH1D *hist2 = new TH1D("hist2", "", 20, -10, 10); // hist1->Sumw2(); // hist2->Sumw2(); // TH1D *ratio = (TH1D*)hist1->Clone("ratio"); TFile *fileOut = new TFile("troubleshootFillRandom.root", "RECREATE"); TTree *treeOut = new TTree("results", ""); treeOut->Branch("chi2", &chi2); for(Int_t i=0; i<=100000; i++) { gRandom->SetSeed(0); hist1->FillRandom(templateHist, 10000); gRandom->SetSeed(0); hist2->FillRandom(templateHist, 10000); // ratio->Divide(hist1, hist2, 1.0/hist1->Integral(), 1.0/hist2->Integral()); // chi2 = ratio->Chisquare(unif); chi2 = hist1->Chi2Test(hist2, "UU CHI2"); treeOut->Fill(); } fileOut->Write(); fileOut->Close(); }