34std::unique_ptr<RooAbsArg> createSimultaneousNLL(
RooSimultaneous const &simPdf,
bool isExtended,
41 for (
auto const &catState : simCat) {
42 std::string
const &catName = catState.
first;
47 if (!rangeName.empty()) {
50 auto simCatAsRooCategory =
dynamic_cast<RooCategory const *
>(&simCat);
51 if (simCatAsRooCategory && !simCatAsRooCategory->isStateInRange(rangeName.c_str(), catIndex)) {
57 auto name = std::string(
"nll_") + pdf->GetName();
58 std::unique_ptr<RooArgSet> observables(
59 static_cast<RooArgSet *
>(std::unique_ptr<RooArgSet>(pdf->getVariables())->selectByAttrib(
"__obs__",
true)));
60 auto nll = std::make_unique<RooNLLVarNew>(
name.c_str(),
name.c_str(), *pdf, *observables, isExtended,
offset);
62 nll->setPrefix(std::string(
"_") + catName +
"_");
68 nll->setSimCount(nllTerms.
size());
72 auto nll = std::make_unique<RooAddition>(
"mynll",
"mynll", nllTerms);
73 nll->addOwnedComponents(std::move(nllTerms));
77class RooAbsRealWrapper final :
public RooAbsReal {
79 RooAbsRealWrapper(std::unique_ptr<RooFitDriver> driver, std::string
const &rangeName,
RooSimultaneous const *simPdf,
80 bool takeGlobalObservablesFromData)
81 :
RooAbsReal{
"RooFitDriverWrapper",
"RooFitDriverWrapper"}, _driver{std::move(driver)},
82 _topNode(
"topNode",
"top node", this, _driver->topNode()), _rangeName{rangeName}, _simPdf{simPdf},
83 _takeGlobalObservablesFromData{takeGlobalObservablesFromData}
87 RooAbsRealWrapper(
const RooAbsRealWrapper &other,
const char *
name =
nullptr)
89 _topNode(
"topNode", this, other._topNode), _data{other._data}, _parameters{other._parameters},
90 _rangeName{other._rangeName}, _simPdf{other._simPdf}, _takeGlobalObservablesFromData{
91 other._takeGlobalObservablesFromData}
95 TObject *clone(
const char *newname)
const override {
return new RooAbsRealWrapper(*
this, newname); }
97 double defaultErrorLevel()
const override {
return _driver->topNode().defaultErrorLevel(); }
99 bool getParameters(
const RooArgSet *observables,
RooArgSet &outputSet,
bool )
const override
101 outputSet.
add(_parameters);
103 outputSet.
remove(*observables);
109 if (_takeGlobalObservablesFromData && _data->getGlobalObservables()) {
110 outputSet.
replace(*_data->getGlobalObservables());
122 _driver->topNode().getParameters(_data->get(), params,
true);
124 if (!param->getAttribute(
"__obs__")) {
125 _parameters.
add(*param);
129 _driver->setData(*_data, _rangeName, _simPdf,
true, _takeGlobalObservablesFromData);
135 void applyWeightSquared(
bool flag)
override
137 const_cast<RooAbsReal &
>(_driver->topNode()).applyWeightSquared(flag);
140 void printMultiline(std::ostream &os,
Int_t ,
bool =
false,
147 double evaluate()
const override {
return _driver ? _driver->getVal() : 0.0; }
150 std::shared_ptr<RooFitDriver> _driver;
154 std::string _rangeName;
156 const bool _takeGlobalObservablesFromData;
161std::unique_ptr<RooAbsReal>
163 std::unique_ptr<RooAbsReal> &&constraints, std::string
const &rangeName,
164 RooArgSet const &projDeps,
bool isExtended,
double integrateOverBinsPrecision,
166 bool takeGlobalObservablesFromData)
170 constraints->setData(
data,
false);
178 pdf->getObservables(
data.get(), observables);
179 observables.
remove(projDeps,
true,
true);
182 <<
") fixing normalization set for coefficient determination to observables in data"
184 pdf->fixAddCoefNormalization(observables,
false);
189 RooAbsPdf &finalPdf = wrappedPdf ? *wrappedPdf : *pdf;
191 binSamplingPdfs.
addOwned(std::move(wrappedPdf));
200 nllTerms.
addOwned(createSimultaneousNLL(*simPdf, isExtended, rangeName,
offset));
203 std::make_unique<RooNLLVarNew>(
"RooNLLVarNew",
"RooNLLVarNew", finalPdf, observables, isExtended,
offset));
206 nllTerms.
addOwned(std::move(constraints));
209 std::string nllName = std::string(
"nll_") + pdf->GetName() +
"_" +
data.GetName();
210 auto nll = std::make_unique<RooAddition>(nllName.c_str(), nllName.c_str(), nllTerms);
211 nll->addOwnedComponents(std::move(binSamplingPdfs));
212 nll->addOwnedComponents(std::move(nllTerms));
214 auto driver = std::make_unique<RooFitDriver>(*nll, batchMode);
217 std::make_unique<RooAbsRealWrapper>(std::move(driver), rangeName, simPdf, takeGlobalObservablesFromData);
218 driverWrapper->setData(
data,
false);
219 driverWrapper->addOwnedComponents(std::move(nll));
220 driverWrapper->addOwnedComponents(std::move(pdf));
222 return driverWrapper;
237 static std::pair<RooFit::BatchModeOption, bool> lastBatchMode;
238 if (lastBatchMode.second && lastBatchMode.first == batchMode)
240 lastBatchMode = {batchMode,
true};
243 auto log = [](std::string_view message) {
248 throw std::runtime_error(std::string(
"In: ") + __func__ +
"(), " + __FILE__ +
":" + __LINE__ +
249 ": Cuda implementation of the computing library is not available\n");
252 log(
"using generic CPU library compiled with no vectorizations");
254 log(std::string(
"using CPU computation library compiled with -m") +
258 log(
"using CUDA computation library");
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
RooAbsArg * first() const
virtual bool replace(const RooAbsArg &var1, const RooAbsArg &var2)
Replace var1 with var2 and return true for success.
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
RooAbsData is the common abstract base class for binned and unbinned datasets.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
static std::unique_ptr< RooAbsPdf > create(RooAbsPdf &pdf, RooAbsData const &data, double precision)
Creates a wrapping RooBinSamplingPdf if appropriate.
RooCategory is an object to represent discrete states.
static RooMsgService & instance()
Return reference to singleton instance.
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
RooAbsPdf * getPdf(RooStringView catName) const
Return the p.d.f associated with the given index category name.
void wrapPdfsInBinSamplingPdfs(RooAbsData const &data, double precision)
Wraps the components of this RooSimultaneous in RooBinSamplingPdfs.
const RooAbsCategoryLValue & indexCat() const
Mother of all ROOT objects.
R__EXTERN RooBatchComputeInterface * dispatchCUDA
R__EXTERN RooBatchComputeInterface * dispatchCPU
This dispatch pointer points to an implementation of the compute library, provided one has been loade...
std::unique_ptr< RooAbsReal > createNLL(std::unique_ptr< RooAbsPdf > &&pdf, RooAbsData &data, std::unique_ptr< RooAbsReal > &&constraints, std::string const &rangeName, RooArgSet const &projDeps, bool isExtended, double integrateOverBinsPrecision, RooFit::BatchModeOption batchMode, RooFit::OffsetMode offset, bool takeGlobalObservablesFromData)
void logArchitectureInfo(RooFit::BatchModeOption batchMode)
OffsetMode
For setting the offset mode with the Offset() command argument to RooAbsPdf::fitTo()
BatchModeOption
For setting the batch mode flag with the BatchMode() command argument to RooAbsPdf::fitTo()
void evaluate(typename Architecture_t::Tensor_t &A, EActivationFunction f)
Apply the given activation function to each value in the given tensor A.