$SplitParam is also splitting the expressions

Hi guys

I am building a model within a workspace with this code

w.factory("SUM::loc_norm(nS[0,400]*Uniform::unif(Z),nB[-10,10]*unif)")

# Create a new model norm_loc, starting from loc_norm
w.factory(f"EDIT::norm_LOc(loc_norm, nB=expr('nruns*Rloc*{tlocmax-tlocmin}',nruns[6],Rloc[{ncosmrateloc},0.,0.6]), nS=expr('S/K*(1+E*D)/(1-D*D)',S[1000,50,500],D[0.,-0.8,0.8],E[0.,-2.,2.],K[1.30,0.7,1.6]))")          

# Now with the defined expressions for the nB and nS, build the composite model with the templates
w.factory("SUM::model(nU[900,1500]*pdf_pbarUp,nD[900,1500]*pdf_pbarDn,nB*pdf_cosm)")

w.factory("expr::nU_expr('0.5*S*(1+E)', S, E)") # expression for nU
w.factory("expr::nD_expr('0.5*S*(1-E)', S, E)") # expression for nD
w.factory(f"expr::nB_expr('nruns*R*{tmagbmax-tmagbmin}*KK',nruns,R[{ncosmrate},0.,20], KK[1])") # expression for nB

w.factory(f"EDIT::model_MAGB(model, nB=nB_expr, nU=nU_expr, nD=nD_expr)")

w.factory(f"Gaussian::Rconstr(R,{ncosmrate},{ecosmrate})") # constrain su R, rate cosmici

# Define a R variable, used to adjust the background
R = w.var('R')
R.setMin(ncosmrate-6*ecosmrate)
R.setMax(ncosmrate+6*ecosmrate)
R.setVal(ncosmrate)

w.factory(f"Gaussian::Dconstr(D,{Dmu},{Dsigma})") # constrain on D, efficiency

w.factory("SIMCLONE::model_fit( model_MAGB, $SplitParam({S,E,nruns, KK},biaskey) )") # for the variable in the list, a different one for each bias key

w.Print() 

I am wondering if SplitParam at the end is splitting the expression nB, nU, and ND or if it is splitting only the variables, and the model then relies on the old expression nU and nB that are not splitted.

@jonas do you think you can help here?

I have something else to report.

In my code, I am trying to create a simulation based on the fitted model. The model is defined as above. To organize my repository, I have decided to save the workspace in a root file and open it in a separate script, where I intend to develop the simulation.

I have saved the workspace with

w.writeToFile("workspace_S_Bias.root")

My issue is that when I try to open it, I receive the following error

##> Simulation code for [xxxx]. 
###> Import the workspace and generate the data

import ROOT # import ROOT

# read the workspace from a file
# -------------------------------------

# open the input file with workspace
file = ROOT.TFile("workspace_S_Bias.root")

w = file.Get("w")

w.allVars().Print("v")
print("-"*10)
w.allPdfs().Print()

w.allFunctions().Print("v")

And I receive the following error:

  1) 0x631cf5b02480 RooFormulaVar::     norm_LOc_2[ actualVars=(nruns,Rloc) formula="nruns*Rloc*13.1" ] = 5.21693  "norm_LOc_2"
  2) 0x631cf5af2b90 RooFormulaVar::     norm_LOc_3[ actualVars=(S,D,E,K) formula="S/K*(1+E*D)/(1-D*D)" ] = 384.615  "norm_LOc_3"
  3) 0x631cf5b02eb0 RooFormulaVar::   model_MAGB_2[ actualVars=(nruns,R,KK) formula="nruns*R*10*KK" ] = 2.47554  "model_MAGB_2"
  4) 0x631cf5af2360 RooFormulaVar::   model_MAGB_3[ actualVars=(S,E) formula="0.5*S*(1+E)" ] = 250  "model_MAGB_3"
  5) 0x631cf5af60e0 RooFormulaVar::   model_MAGB_4[ actualVars=(S,E) formula="0.5*S*(1-E)" ] = 250  "model_MAGB_4"
  6) 0x631cf5b0cc20 RooFormulaVar::model_MAGB_3_+0.5g[ actualVars=(S_+0.5g,E_+0.5g) formula="0.5*S*(1+E)" ] = [#0] FATAL:InputArguments -- RooFormula 'model_MAGB_3_+0.5g' did not compile or is invalid.
Input:
	0.5*S*(1+E)
Passed over to TFormula:
	0.5*S*(1+E)
input_line_119:2:60: error: use of undeclared identifier 'S'
Double_t TFormula____id15526844310874100094(){ return 0.5*{S}*(1+{E}) ; }
                                                           ^
input_line_119:2:67: error: use of undeclared identifier 'E'
Double_t TFormula____id15526844310874100094(){ return 0.5*{S}*(1+{E}) ; }
                                                                  ^
input_line_120:2:60: error: use of undeclared identifier 'S'
Double_t TFormula____id15526844310874100094(){ return 0.5*{S}*(1+{E}) ; }
                                                           ^
input_line_120:2:67: error: use of undeclared identifier 'E'
Double_t TFormula____id15526844310874100094(){ return 0.5*{S}*(1+{E}) ; }
                                                                  ^
Error in <prepareMethod>: Can't compile function TFormula____id15526844310874100094 prototype with arguments 
Error in <TFormula::InputFormulaIntoCling>: Error compiling formula expression in Cling
Error in <TFormula::ProcessFormula>: "S" has not been matched in the formula expression
Error in <TFormula::ProcessFormula>: "E" has not been matched in the formula expression
Error in <TFormula::ProcessFormula>: Formula "0.5*S*(1+E)" is invalid !

I tried to change several things in the model definition. The problem is that when i save and open the workspace and root try to rebuilt the Roo expression, it is failing to link the correct variables. I do not reiceive the error if i generate the data directly in the same script, without doing this intermediate passage. However I would like to save the workspace, because it is usefull