Chi-square test help

_ROOT Version:6.26.04_1
_Platform: macOS Monterey
_Compiler: C++

I am working on a macro that applies a chi-square test to many different histograms and then creates a chi-square distribution using the outputted chi square scores. I am able to find the chi-square scores pretty easily using Chi2Test(); however I am unsure how to use these scores to fill another graph as chi2 is not the correct variable name although the class reference guide says " [out] chi2 " which led me to assume that if I wanted to input this in a graph I would just use g->Fill(chi2,other value).

{



  g = new TGraph();

  int i;

  for(int i = 1; i < 26; i++)
    {
      //h1 is the predicted value
      
      TH1F *h1 = new TH1F("h1", "Predict;x;y", 25, 0, 2500);
      
      //h2 represents second histogram (data collected)
      
      TH1F *h2 = new TH1F("h2", "Data;x;y", 25, 0, 2500);
      
      int k;
      

      for(int k = 0; k < i*500; k++)
      {
	h1->Fill( gRandom->Landau(1000, 300)  );
	h2->Fill( gRandom->Landau(1000, 300)  );
      }

      Double_t res[25], x[25];
      h1->Chi2Test(h2,"UU P", res);



      g->SetPoint(i, chi2, i*500);

      
   }


  g->Draw();
  
 }

This is the line of code I have written in which a for loop runs a chi-square test between two identical distributions at a varied number of total event counts.

TLDR; What is the variable name of the output for chi2 using TH1::Chi2Test()

Hi @DTMsurf, welcome to the ROOT forum!

The TH1::Chi2Test() method gives you the chi2 value as a return value, which you need to assign to a variable yourself:

double chi2 = h1->Chi2Test(h2,"UU P");

g->SetPoint(i, chi2, i*500);

I hope this helps you to continue for now, let me know if you have follow-up questions!

Jonas

This helped greatly and I was able to complete the macro, Thank you!