@@ -100,6 +100,16 @@ using RooFit::Detail::JSONTree;
100100
101101namespace {
102102
103+ std::vector<std::string> valsToStringVec (JSONNode const &node)
104+ {
105+ std::vector<std::string> out;
106+ out.reserve (node.num_children ());
107+ for (JSONNode const &elem : node.children ()) {
108+ out.push_back (elem.val ());
109+ }
110+ return out;
111+ }
112+
103113/* *
104114 * @brief Check if the number of components in CombinedData matches the number of categories in the RooSimultaneous PDF.
105115 *
@@ -587,16 +597,13 @@ void importAnalysis(const JSONNode &rootnode, const JSONNode &analysisNode, cons
587597 auto *mc = static_cast <RooStats::ModelConfig *>(workspace.obj (mcname));
588598 mc->SetWS (workspace);
589599
590- std::vector<std::string> nllDistNames;
591600 std::vector<std::string> nllDataNames;
592601
593602 auto *nllNode = RooJSONFactoryWSTool::findNamedChild (likelihoodsNode, analysisNode[" likelihood" ].val ());
594603 if (!nllNode) {
595604 throw std::runtime_error (" likelihood node not found!" );
596605 }
597- for (auto &nameNode : (*nllNode)[" distributions" ].children ()) {
598- nllDistNames.push_back (nameNode.val ());
599- }
606+ std::vector<std::string> nllDistNames = valsToStringVec ((*nllNode)[" distributions" ]);
600607 RooArgSet extConstraints;
601608 for (auto &nameNode : (*nllNode)[" aux_distributions" ].children ()) {
602609 RooAbsArg *extConstraint = workspace.arg (nameNode.val ());
@@ -699,18 +706,12 @@ void combinePdfs(const JSONNode &rootnode, RooWorkspace &ws)
699706 // parse the information
700707 std::string combinedName = info.key ();
701708 std::string indexCatName = info[" index_cat" ].val ();
702- std::vector<std::string> labels;
709+ std::vector<std::string> labels = valsToStringVec (info[ " labels " ]) ;
703710 std::vector<int > indices;
704- std::vector<std::string> pdfNames;
711+ std::vector<std::string> pdfNames = valsToStringVec (info[ " distributions " ]) ;
705712 for (auto &n : info[" indices" ].children ()) {
706713 indices.push_back (n.val_int ());
707714 }
708- for (auto &n : info[" labels" ].children ()) {
709- labels.push_back (n.val ());
710- }
711- for (auto &n : info[" distributions" ].children ()) {
712- pdfNames.push_back (n.val ());
713- }
714715
715716 RooCategory indexCat{indexCatName.c_str (), indexCatName.c_str ()};
716717 std::map<std::string, RooAbsPdf *> pdfMap;
@@ -739,14 +740,11 @@ void combineDatasets(const JSONNode &rootnode, std::vector<std::unique_ptr<RooAb
739740 // parse the information
740741 std::string combinedName = info.key ();
741742 std::string indexCatName = info[" index_cat" ].val ();
742- std::vector<std::string> labels;
743+ std::vector<std::string> labels = valsToStringVec (info[ " labels " ]) ;
743744 std::vector<int > indices;
744745 for (auto &n : info[" indices" ].children ()) {
745746 indices.push_back (n.val_int ());
746747 }
747- for (auto &n : info[" labels" ].children ()) {
748- labels.push_back (n.val ());
749- }
750748 if (indices.size () != labels.size ()) {
751749 RooJSONFactoryWSTool::error (" mismatch in number of indices and labels!" );
752750 }
0 commit comments