math::GOFtest error

hi dears;
please this is my code :slight_smile:

 #include <cassert>
 #include "TCanvas.h"
 #include "TPaveText.h"
 #include "TH1.h"
 #include "TF1.h"
 #include "Math/GoFTest.h"
 #include "Math/Functor.h"
 #include "TRandom3.h"
 #include "Math/DistFunc.h"
 
 // need to use Functor1D
 double landau(double x) {
   return ROOT::Math::landau_pdf(x);
 }
 
 void goftest() {
 
    // ------------------------------------------------------------------------
    // Case 1: Create logNormal random sample
    
 
    UInt_t nEvents1 = 200;
  // Define Histograms.

TFile* file1= new TFile("tung101kv.root","READ");
TFile* file= new TFile("spcmesure1.root","READ");
TH1D*h1=(TH1D*) file1->Get("energySpectrumFluenceTrack");
TH1D*h2=(TH1D*) file->Get("energySpectrumFluenceTrack");
double a[h1->GetNbinsX()], y[h1->GetNbinsX()];
for(int i=0;i<200;i++){
a[i]=h1->GetBinCenter(i+1);
y[i]=h1->GetBinContent(i+1)/18300;
}

double e[h2->GetNbinsX()], b[h2->GetNbinsX()];
for(int i=0;i<200;i++){
e[i]=h2->GetBinCenter(i+1);
b[i]=h2->GetBinContent(i+1)/1700000;
}

  h1->SetEntries(35168);
  h2->SetEntries(988329);

TCanvas*canvas=new TCanvas();
canvas->Divide(2,2);
canvas->cd(1);

TGraph*graph=new TGraph(h1->GetNbinsX(),a,y);
graph->SetLineColor(4);
graph->SetLineWidth(2);
graph->SetTitle("Spectrum");
graph->GetXaxis()->SetTitle("Energy(MeV)");
graph->Draw();

TGraph*graph1=new TGraph(h2->GetNbinsX(),e,b);
graph1->SetLineColor(3);
graph1->SetLineWidth(2);
graph1->SetTitle("Spectrumtun");
graph1->GetXaxis()->SetTitle("Energy(MeV)");
graph1->Draw("same");

TLegend*Legend=new TLegend(0.7,0.7,0.9,0.9);
Legend->AddEntry(graph,"spectre tungstene", "lp");
Legend->AddEntry(graph1,"spectre tungmesure", "lp");
Legend->Draw();
// -----------------------------------------
    // Create GoFTest object
    
 
    ROOT::Math::GoFTest* goftest_1 = new ROOT::Math::GoFTest(nEvents1, h1, ROOT::Math::GoFTest::kLogNormal);
    //----------------------------------------------------
    // Possible calls for the Anderson - DarlingTest test 
    // a) Returning the Anderson-Darling standardized test statistic 
    Double_t A2_1 = goftest_1-> AndersonDarlingTest("t");
    Double_t A2_2 = (*goftest_1)(ROOT::Math::GoFTest::kAD, "t");
    assert(A2_1 == A2_2);
 
    // b) Returning the p-value for the Anderson-Darling test statistic 
    Double_t pvalueAD_1 = goftest_1-> AndersonDarlingTest(); // p-value is the default choice
    Double_t pvalueAD_2 = (*goftest_1)(); // p-value and Anderson - Darling Test are the default choices
    assert(pvalueAD_1 == pvalueAD_2);
 
    // Rebuild the test using the default 1-sample construtor 
    delete goftest_1;
    goftest_1 = new ROOT::Math::GoFTest(nEvents1, h1 ); // User must then input a distribution type option
    goftest_1->SetDistribution(h2);
 
    //--------------------------------------------------
    // Possible calls for the Kolmogorov - Smirnov test 
    // a) Returning the Kolmogorov-Smirnov standardized test statistic 
    Double_t Dn_1 = goftest_1-> KolmogorovSmirnovTest("t");
    Double_t Dn_2 = (*goftest_1)(ROOT::Math::GoFTest::kKS, "t");
    assert(Dn_1 == Dn_2);
 
    // b) Returning the p-value for the Kolmogorov-Smirnov test statistic 
    Double_t pvalueKS_1 = goftest_1-> KolmogorovSmirnovTest();
    Double_t pvalueKS_2 = (*goftest_1)(ROOT::Math::GoFTest::kKS);
    assert(pvalueKS_1 == pvalueKS_2);
 
    // Valid but incorrect calls for the 2-samples methods of the 1-samples constructed goftest_1
 #ifdef TEST_ERROR_MESSAGE
     Double_t A2 = (*goftest_1)(ROOT::Math::GoFTest::kAD2s, "t");     // Issues error message
     Double_t pvalueKS = (*goftest_1)(ROOT::Math::GoFTest::kKS2s);    // Issues error message
     assert(A2 == pvalueKS);
 #endif
 
    TPaveText* pt1 = new TPaveText(0.58, 0.6, 0.88, 0.80, "brNDC");
    Char_t str1[50];
    sprintf(str1, "p-value for A-D 1-smp test: %f", pvalueAD_1);
    pt1->AddText(str1);
    pt1->SetFillColor(18);
    pt1->SetTextFont(20);
    pt1->SetTextColor(4);
    Char_t str2[50];
    sprintf(str2, "p-value for K-S 1-smp test: %f", pvalueKS_1);
    pt1->AddText(str2);
    pt1->Draw();

 
    
}

when i compile it, i have this problem :

error: no matching constructor for initialization of 'ROOT::Math::GoFTest'
  ...= new ROOT::Math::GoFTest(nEvents1, h1, ROOT::Math::GoFTest::kLogNormal);

i need your help please

Hi Hassan,

I think you try to use this ctor. If so, its second parameter should be const Double_t* and not a TH1D*.

yus, thank you so much
i appreciate your help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.