@@ -21,6 +21,8 @@ AddCacheElem::AddCacheElem(RooAbsPdf const &addPdf, RooArgList const &pdfList, R
2121 const RooArgSet *nset, const RooArgSet *iset, const char *rangeName, bool projectCoefs,
2222 RooArgSet const &refCoefNorm, TNamed const *refCoefRangeName, int verboseEval)
2323{
24+ _suppNormList.reserve (pdfList.size ());
25+
2426 // *** PART 1 : Create supplemental normalization list ***
2527
2628 // Retrieve the combined set of dependents of this PDF ;
@@ -50,27 +52,20 @@ AddCacheElem::AddCacheElem(RooAbsPdf const &addPdf, RooArgList const &pdfList, R
5052
5153 std::unique_ptr<RooAbsReal> snorm;
5254 auto name = std::string (addPdf.GetName ()) + " _" + pdf->GetName () + " _SupNorm" ;
53- _needSupNorm = false ;
5455 if (!supNSet.empty ()) {
5556 snorm = std::make_unique<RooRealIntegral>(name.c_str (), " Supplemental normalization integral" ,
5657 RooRealConstant::value (1.0 ), supNSet);
5758 oocxcoutD (&addPdf, Caching) << addPdf.ClassName () << " " << addPdf.GetName ()
5859 << " making supplemental normalization set " << supNSet << " for pdf component "
5960 << pdf->GetName () << std::endl;
60- _needSupNorm = true ;
61- } else {
62- snorm = std::make_unique<RooRealVar>(name.c_str (), " Unit Supplemental normalization integral" , 1.0 );
6361 }
64- _suppNormList.addOwned (std::move (snorm));
62+ _suppNormList.emplace_back (std::move (snorm));
6563 }
6664
6765 if (verboseEval > 1 ) {
6866 oocxcoutD (&addPdf, Caching) << addPdf.ClassName () << " ::syncSuppNormList(" << addPdf.GetName ()
6967 << " ) synching supplemental normalization list for norm"
7068 << (nset ? *nset : RooArgSet ()) << std::endl;
71- if oodologD (&addPdf, Caching) {
72- _suppNormList.Print (" v" );
73- }
7469 }
7570
7671 // *** PART 2 : Create projection coefficients ***
@@ -125,17 +120,11 @@ AddCacheElem::AddCacheElem(RooAbsPdf const &addPdf, RooArgList const &pdfList, R
125120 oocxcoutD (&addPdf, Caching) << addPdf.ClassName () << " (" << addPdf.GetName () << " )::getPC nset2(" << nset2
126121 << " )!=_refCoefNorm(" << refCoefNorm << " ) --> pdfProj = " << pdfProj->GetName ()
127122 << std::endl;
128- } else {
129- auto name = std::string (addPdf.GetName ()) + " _" + thePdf->GetName () + " _ProjectNorm" ;
130- pdfProj = std::make_unique<RooRealVar>(name.c_str (), " Unit Projection normalization integral" , 1.0 );
131- oocxcoutD (&addPdf, Caching) << addPdf.ClassName () << " (" << addPdf.GetName () << " )::getPC nset2(" << nset2
132- << " )==_refCoefNorm(" << refCoefNorm << " ) --> pdfProj = " << pdfProj->GetName ()
133- << std::endl;
123+ oocxcoutD (&addPdf, Caching) << " " << addPdf.ClassName () << " ::syncCoefProjList(" << addPdf.GetName ()
124+ << " ) PP = " << pdfProj->GetName () << std::endl;
134125 }
135126
136- oocxcoutD (&addPdf, Caching) << " " << addPdf.ClassName () << " ::syncCoefProjList(" << addPdf.GetName ()
137- << " ) PP = " << pdfProj->GetName () << std::endl;
138- _projList.addOwned (std::move (pdfProj));
127+ _projList.emplace_back (std::move (pdfProj));
139128
140129 // Calculation optional supplemental normalization term
141130 RooArgSet supNormSet (refCoefNorm);
@@ -147,13 +136,10 @@ AddCacheElem::AddCacheElem(RooAbsPdf const &addPdf, RooArgList const &pdfList, R
147136 if (!supNormSet.empty () && !nset2.equals (refCoefNorm)) {
148137 snorm = std::make_unique<RooRealIntegral>(name.c_str (), " Projection Supplemental normalization integral" ,
149138 RooRealConstant::value (1.0 ), supNormSet);
150- } else {
151- snorm =
152- std::make_unique<RooRealVar>(name.c_str (), " Unit Projection Supplemental normalization integral" , 1.0 );
139+ oocxcoutD (&addPdf, Caching) << " " << addPdf.ClassName () << " ::syncCoefProjList(" << addPdf.GetName ()
140+ << " ) SN = " << snorm->GetName () << std::endl;
153141 }
154- oocxcoutD (&addPdf, Caching) << " " << addPdf.ClassName () << " ::syncCoefProjList(" << addPdf.GetName ()
155- << " ) SN = " << snorm->GetName () << std::endl;
156- _suppProjList.addOwned (std::move (snorm));
142+ _suppProjList.emplace_back (std::move (snorm));
157143
158144 // Calculate reference range adjusted projection integral
159145 std::unique_ptr<RooAbsReal> rangeProj1;
@@ -189,15 +175,10 @@ AddCacheElem::AddCacheElem(RooAbsPdf const &addPdf, RooArgList const &pdfList, R
189175 std::unique_ptr<RooAbsReal>{thePdf->createIntegral (tmp, tmp, RooNameReg::str (refCoefRangeName))};
190176
191177 // rangeProj1->setOperMode(operMode()) ;
192-
193- } else {
194-
195- auto theName = std::string (addPdf.GetName ()) + " _" + thePdf->GetName () + " _RangeNorm1" ;
196- rangeProj1 = std::make_unique<RooRealVar>(theName.c_str (), " Unit range normalization integral" , 1.0 );
178+ oocxcoutD (&addPdf, Caching) << " " << addPdf.ClassName () << " ::syncCoefProjList(" << addPdf.GetName ()
179+ << " ) R1 = " << rangeProj1->GetName () << std::endl;
197180 }
198- oocxcoutD (&addPdf, Caching) << " " << addPdf.ClassName () << " ::syncCoefProjList(" << addPdf.GetName ()
199- << " ) R1 = " << rangeProj1->GetName () << std::endl;
200- _refRangeProjList.addOwned (std::move (rangeProj1));
181+ _refRangeProjList.emplace_back (std::move (rangeProj1));
201182
202183 // Calculate range adjusted projection integral
203184 std::unique_ptr<RooAbsReal> rangeProj2;
@@ -214,15 +195,10 @@ AddCacheElem::AddCacheElem(RooAbsPdf const &addPdf, RooArgList const &pdfList, R
214195 RooArgSet tmp;
215196 thePdf->getObservables (&refCoefNorm, tmp);
216197 rangeProj2 = std::unique_ptr<RooAbsReal>{thePdf->createIntegral (tmp, tmp, addPdf.normRange ())};
217-
218- } else {
219-
220- auto theName = std::string (addPdf.GetName ()) + " _" + thePdf->GetName () + " _RangeNorm2" ;
221- rangeProj2 = std::make_unique<RooRealVar>(theName.c_str (), " Unit range normalization integral" , 1.0 );
198+ oocxcoutD (&addPdf, Caching) << " " << addPdf.ClassName () << " ::syncCoefProjList(" << addPdf.GetName ()
199+ << " ) R2 = " << rangeProj2->GetName () << std::endl;
222200 }
223- oocxcoutD (&addPdf, Caching) << " " << addPdf.ClassName () << " ::syncCoefProjList(" << addPdf.GetName ()
224- << " ) R2 = " << rangeProj2->GetName () << std::endl;
225- _rangeProjList.addOwned (std::move (rangeProj2));
201+ _rangeProjList.emplace_back (std::move (rangeProj2));
226202 }
227203 }
228204}
@@ -233,10 +209,23 @@ AddCacheElem::AddCacheElem(RooAbsPdf const &addPdf, RooArgList const &pdfList, R
233209RooArgList AddCacheElem::containedArgs (Action)
234210{
235211 RooArgList allNodes;
236- allNodes.add (_projList);
237- allNodes.add (_suppProjList);
238- allNodes.add (_refRangeProjList);
239- allNodes.add (_rangeProjList);
212+ // need to iterate manually because _suppProjList can contain nullptr
213+ for (auto const &arg : _projList) {
214+ if (arg)
215+ allNodes.add (*arg);
216+ }
217+ for (auto const &arg : _suppProjList) {
218+ if (arg)
219+ allNodes.add (*arg);
220+ }
221+ for (auto const &arg : _refRangeProjList) {
222+ if (arg)
223+ allNodes.add (*arg);
224+ }
225+ for (auto const &arg : _rangeProjList) {
226+ if (arg)
227+ allNodes.add (*arg);
228+ }
240229
241230 return allNodes;
242231}
@@ -323,7 +312,7 @@ void RooAddHelpers::updateCoefficients(RooAbsPdf const &addPdf, RooArgList const
323312 }
324313
325314 // Stop here if not projection is required or needed
326- if ((!projectCoefs && !addPdf.normRange ()) || cache._projList . empty ()) {
315+ if ((!projectCoefs && !addPdf.normRange ()) || ! cache.doProjection ()) {
327316 return ;
328317 }
329318
@@ -333,15 +322,7 @@ void RooAddHelpers::updateCoefficients(RooAbsPdf const &addPdf, RooArgList const
333322 RooAbsReal::GlobalSelectComponentRAII compRAII (true );
334323
335324 for (std::size_t i = 0 ; i < pdfList.size (); i++) {
336-
337- RooAbsReal *pp = ((RooAbsReal *)cache._projList .at (i));
338- RooAbsReal *sn = ((RooAbsReal *)cache._suppProjList .at (i));
339- RooAbsReal *r1 = ((RooAbsReal *)cache._refRangeProjList .at (i));
340- RooAbsReal *r2 = ((RooAbsReal *)cache._rangeProjList .at (i));
341-
342- double proj = pp->getVal () / sn->getVal () * (r2->getVal () / r1->getVal ());
343-
344- coefCache[i] *= proj;
325+ coefCache[i] *= cache.projVal (i) / cache.projSuppNormVal (i) * cache.rangeProjScaleFactor (i);
345326 coefSum += coefCache[i];
346327 }
347328 }
0 commit comments