I am working on generating a plot of many chi^2 scores between a fit and pseudo experiments created around that fit from a function I wrote (Chi2test) and I was hoping to include bin to bin correlation using a multivariate gaussian. I have been following along the example: (ROOT: tutorials/roostats/MultivariateGaussianTest.C Source File) for guidance, however I am having some difficulty retrieving the the information from the RooDataSet. Additionally the function I wrote takes matrices as inputs so I have to convert the data structure into a matrix once I retrieve each set of toy data.

RooMultiVarGaussian mvg("mvg", "mvg", fit, mu, cov);
RooDataSet* data = mvg.generate(fit,1000);
RooWorkspace* w = new RooWorkspace("MVG");
ModelConfig modelConfig(w);
modelConfig.SetPdf(mvg);
auto hchi = new TH1F("hchi", "Corellated Pseudoexperiments; #chi^{2}; PDF",300,0,100);
for (int i=0; i < 1000;i++){
const RooArgSet* sim1;
sim1 = data->get(i);
TMatrixD sim(1,26);
for (int j=0;j<26;j++){
sim(1,j) = sim1->GetName("x%d",j)
}
double chi2 = Chi2test(fit_mat,sim,cov1);
hchi->Fill(chi2);
}

I am not sure what is your question by reading at the post. Could you be more explicit?

Meanwhile, I see that your code uses new without corresponding delete. I highly discourage you from using this pattern. Please create variables on the stack or use std::unique_ptr (and std::make_unique correspondingly) if strictly needed.

Apologies for the late response, does removing the new statement fix the issue you are referring to? In terms of the question I am asking, my goal is to create many toy data sets using the MVG, and then use them within a function that takes a 1xn matrix as an input. I am having difficulty converting from the output format of the mvg to the TMatrixD format. Please let me know if this is not explicit enough and I can try and go into more detail. I appreciate the help!

Yes Precisely, It is my understanding that the contents in the set that I am trying to extract values from are considered RooRealVar but I need them to be doubles in order to fill them into the TMatrixD.

on these steps:
We create the msg and then create toy data sets with these two lines:

RooMultiVarGaussian mvg("mvg", "mvg", fit, mu, cov);
RooDataSet* data = mvg.generate(fit,1000);

From this I am not sure how to take one of the sets of data within the RooDataSet and then the next step would be to convert that data into a TMatrix instead of what I assume is a RooArgList.