2727
2828#include < string>
2929
30+ using ROOT::Experimental::RooFitDriver;
31+ using ROOT::Experimental::RooNLLVarNew;
32+
3033namespace {
3134
3235std::unique_ptr<RooAbsArg> prepareSimultaneousModelForBatchMode (RooSimultaneous &simPdf, RooArgSet &observables,
@@ -40,8 +43,8 @@ std::unique_ptr<RooAbsArg> prepareSimultaneousModelForBatchMode(RooSimultaneous
4043 auto const &catName = catItem.first ;
4144 auto *pdf = simPdf.getPdf (catName.c_str ());
4245 auto nllName = std::string (" nll_" ) + pdf->GetName ();
43- nllTerms.add (* new ROOT::Experimental::RooNLLVarNew (nllName. c_str (), nllName. c_str (), *pdf, observables, weight,
44- isExtended, rangeName));
46+ nllTerms.add (
47+ * new RooNLLVarNew (nllName. c_str (), nllName. c_str (), *pdf, observables, weight, isExtended, rangeName));
4548 }
4649
4750 RooArgSet newObservables;
@@ -50,22 +53,8 @@ std::unique_ptr<RooAbsArg> prepareSimultaneousModelForBatchMode(RooSimultaneous
5053 std::size_t iNLL = 0 ;
5154 for (auto const &catItem : simPdf.indexCat ()) {
5255 auto const &catName = catItem.first ;
53- auto &nll = nllTerms[iNLL];
54- RooArgSet pdfObs;
55- nll.getObservables (&observables, pdfObs);
56- if (weight)
57- pdfObs.add (*weight);
58- RooArgSet obsClones;
59- pdfObs.snapshot (obsClones);
60- for (RooAbsArg *arg : obsClones) {
61- auto newName = std::string (" _" ) + catName + " _" + arg->GetName ();
62- arg->setAttribute ((std::string (" ORIGNAME:" ) + arg->GetName ()).c_str ());
63- arg->SetName (newName.c_str ());
64- }
65- nll.recursiveRedirectServers (obsClones, false , true );
66- newObservables.add (obsClones);
67- static_cast <ROOT::Experimental::RooNLLVarNew &>(nll).setObservables (obsClones);
68- nll.addOwnedComponents (std::move (obsClones));
56+ auto &nll = static_cast <RooNLLVarNew &>(nllTerms[iNLL]);
57+ newObservables.add (nll.prefixObservableAndWeightNames (std::string (" _" ) + catName + " _" ));
6958 ++iNLL;
7059 }
7160
@@ -86,7 +75,7 @@ RooFit::BatchModeHelpers::createNLL(RooAbsPdf &pdf, RooAbsData &data, std::uniqu
8675{
8776 std::unique_ptr<RooRealVar> weightVar;
8877
89- std::unique_ptr<ROOT::Experimental:: RooFitDriver> driver;
78+ std::unique_ptr<RooFitDriver> driver;
9079
9180 RooArgSet observables;
9281 pdf.getObservables (data.get (), observables);
@@ -104,16 +93,9 @@ RooFit::BatchModeHelpers::createNLL(RooAbsPdf &pdf, RooAbsData &data, std::uniqu
10493 }
10594
10695 if (data.isWeighted ()) {
107- std::string weightVarName = " _weight" ;
108- if (auto *dataSet = dynamic_cast <RooDataSet const *>(&data)) {
109- if (dataSet->weightVar ())
110- weightVarName = dataSet->weightVar ()->GetName ();
111- }
112-
113- // make a clone of the weight variable (or an initial instance, if it doesn't exist)
114- // the clone will hold the weight value (or values as a batch) and will participate
115- // in the computation graph of the RooFit driver.
116- weightVar = std::make_unique<RooRealVar>(weightVarName.c_str (), " Weight(s) of events" , data.weight ());
96+ // RooRealVar for the weight value (or values as a batch) that will
97+ // participate in the computation graph of the RooFit driver.
98+ weightVar = std::make_unique<RooRealVar>(RooNLLVarNew::weightVarName, " Weight(s) of events" , data.weight ());
11799 }
118100
119101 // Deal with the IntegrateBins argument
@@ -135,8 +117,8 @@ RooFit::BatchModeHelpers::createNLL(RooAbsPdf &pdf, RooAbsData &data, std::uniqu
135117 nllTerms.addOwned (
136118 prepareSimultaneousModelForBatchMode (*simPdfClone, observables, weightVar.get (), isExtended, rangeName));
137119 } else {
138- nllTerms.addOwned (std::make_unique<ROOT::Experimental:: RooNLLVarNew>(
139- " RooNLLVarNew " , " RooNLLVarNew " , finalPdf, observables, weightVar.get (), isExtended, rangeName));
120+ nllTerms.addOwned (std::make_unique<RooNLLVarNew>(" RooNLLVarNew " , " RooNLLVarNew " , finalPdf, observables,
121+ weightVar.get (), isExtended, rangeName));
140122 }
141123 if (constraints) {
142124 nllTerms.addOwned (std::move (constraints));
@@ -151,10 +133,9 @@ RooFit::BatchModeHelpers::createNLL(RooAbsPdf &pdf, RooAbsData &data, std::uniqu
151133 RooArgSet parameters;
152134 pdf.getParameters (data.get (), parameters);
153135 nll->recursiveRedirectServers (parameters);
154- driver = std::make_unique<ROOT::Experimental::RooFitDriver>(data, *nll, observables, batchMode, rangeName,
155- &simPdf->indexCat ());
136+ driver = std::make_unique<RooFitDriver>(data, *nll, observables, batchMode, rangeName, &simPdf->indexCat ());
156137 } else {
157- driver = std::make_unique<ROOT::Experimental:: RooFitDriver>(data, *nll, observables, batchMode, rangeName);
138+ driver = std::make_unique<RooFitDriver>(data, *nll, observables, batchMode, rangeName);
158139 }
159140
160141 // Set the fitrange attribute so that RooPlot can automatically plot the fitting range by default
@@ -179,7 +160,7 @@ RooFit::BatchModeHelpers::createNLL(RooAbsPdf &pdf, RooAbsData &data, std::uniqu
179160 pdf.setStringAttribute (" fitrange" , fitrangeValue.c_str ());
180161 }
181162
182- auto driverWrapper = ROOT::Experimental:: RooFitDriver::makeAbsRealWrapper (std::move (driver));
163+ auto driverWrapper = RooFitDriver::makeAbsRealWrapper (std::move (driver));
183164 driverWrapper->addOwnedComponents (std::move (nll));
184165 if (weightVar)
185166 driverWrapper->addOwnedComponents (std::move (weightVar));
0 commit comments