Generating Pseudo-experiments through a Multivariate Gaussian

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);
    }

Any help is appreciated
Thank you!

Dear @DTMsurf ,

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.

@jonas FYI

Cheers,
Vincenzo

Hi Vincenzo,

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!

Best,
Christopher

Dear @DTMsurf ,

From your last message, my understanding is that your question is:

Is it possible to convert a `RooArgSet*` to a `TMatrixD`?

Let me know if that’s what you are looking for. I will ask @jonas to help you with this question.

Cheers,
Vincenzo

Hi Vincenzo,

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.

Best,
Christopher

I have been able to solve this problem, Thank you!

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