Filling a matrix of RooFormulaVars

Hi all,

I am having difficulty filling a 2D vector (matrix) of RooForumulaVar*.

I keep getting formula evaluation errors back at run time when I try to feed a vector into RooForumulaVar. I appear to be missing some syntax or making some rookie error!

I have pasted a short code snippet (with the appropriate lines) below and the error I am seeing.

Thanks in advance :slight_smile:


RooRealVar gamma("gamma","gamma",1.4,0.9,1.9);
std::vector<RooRealVar *> attack_parameters (num_teams);  
std::vector<RooRealVar *> defence_parameters (num_teams);  
std::vector<std::vector<RooFormulaVar *>> H_RATES;  
std::vector<std::vector<RooFormulaVar *>> A_RATES;   
std::vector<std::vector<RooDataSet *>> DATA_SETS; 

H_RATES.resize(num_teams, std::vector<RooFormulaVar *>(num_teams, 0));
A_RATES.resize(num_teams, std::vector<RooFormulaVar *>(num_teams, 0));
DATA_SETS.resize(num_teams, std::vector<RooDataSet *>(num_teams, 0));

for (int i = 0; i < num_teams; i++) { 
	for (int j = 0; j < num_teams; j++) {	   
  	// Cut the subdataset for i,j
 	DATA_SETS[i][j] = (RooDataSet*)data->reduce(game_cut);
        int dataset_entries = DATA_SETS[i][j]->numEntries();
 	cout << "Number of sub-dataset entries = " << dataset_entries << endl;
        cout << "DATA_SETS[i][j] exists = " << DATA_SETS[i][j] << endl;
         // Define the RooFormulaVars required
	 H_RATES[i][j] = new RooFormulaVar(hratename,"attack_parameters[i]*defence_parameters[j]*gamma", RooArgList(*attack_parameters[i],*defence_parameters[j],gamma));

	cout << "H_RATES[i][j] exists = " << H_RATES[i][j] << endl;
  	A_RATES[i][j] = new RooFormulaVar(aratename, "attack_parameters[j]*defence_parameters[i]", RooArgList(*attack_parameters[j],*defence_parameters[i]));	
	cout << "A_RATES[i][j] exists = " << A_RATES[i][j] << endl;

Number of sub-dataset entries = 9
DATA_SETS[i][j] exists = 0x5055f74
i=2, j=0
hratename = h_rate_2_0
H_RATES[i][j] exists = 0x586dbc0
Error in <RooFormula::Compile>:  Bad numerical expression : "attack_parameters[j]"
[#0] ERROR:InputArguments -- RooFormula::RooFormula(a_rate_2_0): compile error
[#0] ERROR:Eval -- RooFormula::eval(a_rate_2_0): Formula doesn't compile: attack_parameters[j]*defence_parameters[i]
A_RATES[i][j] exists = 0x586d260


In the RooFormulaVar you should defined the variables (RooRealVar) by their names and not their C++ instances.
For example when defining:

H_RATES[i][j] = new RooFormulaVar(hratename,"attack_parameters[i]*defence_parameters[j]*gamma", RooArgList(*attack_parameters[i],*defence_parameters[j],gamma));

You should use in the string


instead of attack_parameters[i]


Hi Lorenzo,
Iā€™m having the same problem.

sigma1[i][i1]= new  RooRealVar(sigma1b,"width of gaussians",  2.15958e+00,0,4 ) ;
sigma2[i][i1]=  new RooRealVar(sigma2b,"width of gaussians",3.98919e+00,1,10) ;
sig6frac[i][i1]=  new RooRealVar(sig6fracb,"fraction of component 1 in signal",   7.58530e-01,0.,1.) ; 
       TString a =sig6frac[i][i1]->GetName();
       TString b =sigma1[i][i1]->GetName();  
       TString c =sigma2[i][i1]->GetName();  

       rms_2625[i][i1]=  new RooFormulaVar(Rms_2625,"sqrt(a*b*b + (1-a)*c*c)",RooArgList(*sig6frac[i][i1],*sigma1[i][i1],*sigma2[i][i1])) ;

What am I doing wrong?