//takes a varname which is supposed to represent a RooAbsReal in //the m_rws (RooWorkspace) member of the class. //changes it to a RooFormulaVar. //formula is used in the constructor of this RooFormulaVar //and dependents is a comma-separated list of other RooAbsReal //objects that are also present in m_rws upon which the RooFormulaVar //is dependent. void RooSimultaneousFitter::AddConstraint(const char* varname, const char* formula, const char* dependents) { //put dependents names in a vector std::vector dependents_vec; std::string dummy = (std::string)dependents; boost::split(dependents_vec,dummy,boost::is_any_of(",")); RooArgList depList; //m_rws is a RooWorkspace member of the class RooAbsReal* var; for (std::vector::iterator iter = dependents_vec.begin(); iter != dependents_vec.end(); iter++){ var = (RooAbsReal*)m_rws->obj(iter->c_str()); depList.add(*var); } //checking that the var we are constraining is there var = (RooAbsReal*)m_rws->obj(varname); //make the rooformulavar std::stringstream newname; newname << varname << "_function"; RooFormulaVar function(newname.str().c_str(),"",formula,depList); //import it first since import clones the object and to get the address of //it in the RooWorkspace one must get it again (I think) m_rws->import(function); RooAbsReal* newvar = (RooAbsReal*)m_rws->obj(newname.str().c_str()); //transfer the relationships of the old var to the new one. TIterator* iter = var->clientIterator(); RooAbsArg* client; while( (client=(RooAbsArg*)iter->Next()) ){ client->replaceServer(*var,*newvar,kTRUE,kTRUE); } delete iter; return; }