38 bool isExtended, std::string
const &rangeName)
43 for (
auto const &catItem : simPdf.
indexCat()) {
44 auto const &catName = catItem.
first;
46 auto nllName = std::string(
"nll_") + pdf->
GetName();
47 auto *nll =
new RooNLLVarNew(nllName.c_str(), nllName.c_str(), *pdf, observables, isExtended, rangeName);
49 newObservables.
add(nll->prefixObservableAndWeightNames(std::string(
"_") + catName +
"_"));
55 observables.
add(newObservables);
58 return std::make_unique<RooAddition>(
"mynll",
"mynll", nllTerms,
true);
63std::unique_ptr<RooAbsReal>
65 std::string
const &rangeName, std::string
const &addCoefRangeName,
66 RooArgSet const &projDeps,
bool isExtended,
double integrateOverBinsPrecision,
69 std::unique_ptr<RooFitDriver> driver;
73 observables.
remove(projDeps,
true,
true);
76 <<
") fixing normalization set for coefficient determination to observables in data"
79 if (!addCoefRangeName.empty()) {
81 <<
") fixing interpretation of coefficients of any component to range "
82 << addCoefRangeName <<
"\n";
88 std::unique_ptr<RooAbsPdf> wrappedPdf;
90 RooAbsPdf &finalPdf = wrappedPdf ? *wrappedPdf : pdf;
92 binSamplingPdfs.
addOwned(std::move(wrappedPdf));
102 nllTerms.
addOwned(prepareSimultaneousModelForBatchMode(*simPdfClone, observables, isExtended, rangeName));
105 std::make_unique<RooNLLVarNew>(
"RooNLLVarNew",
"RooNLLVarNew", finalPdf, observables, isExtended, rangeName));
108 nllTerms.
addOwned(std::move(constraints));
111 std::string nllName = std::string(
"nll_") + pdf.
GetName() +
"_" +
data.GetName();
112 auto nll = std::make_unique<RooAddition>(nllName.c_str(), nllName.c_str(), nllTerms);
113 nll->addOwnedComponents(std::move(binSamplingPdfs));
114 nll->addOwnedComponents(std::move(nllTerms));
119 nll->recursiveRedirectServers(parameters);
120 driver = std::make_unique<RooFitDriver>(*nll, observables, batchMode);
123 driver = std::make_unique<RooFitDriver>(*nll, observables, batchMode);
124 driver->setData(
data, rangeName);
128 if (!rangeName.empty()) {
130 std::string fitrangeValue;
132 for (
auto const &subrange : subranges) {
133 if (subrange.empty())
135 std::string fitrangeValueSubrange = std::string(
"fit_") + nll->GetName();
136 if (subranges.size() > 1) {
137 fitrangeValueSubrange +=
"_" + subrange;
139 fitrangeValue += fitrangeValueSubrange +
",";
140 for (
auto *observable : static_range_cast<RooRealVar *>(observables)) {
141 observable->setRange(fitrangeValueSubrange.c_str(), observable->getMin(subrange.c_str()),
142 observable->getMax(subrange.c_str()));
145 fitrangeValue = fitrangeValue.substr(0, fitrangeValue.size() - 1);
150 driverWrapper->addOwnedComponents(std::move(nll));
152 return driverWrapper;
166 static std::pair<RooFit::BatchModeOption, bool> lastBatchMode;
167 if (lastBatchMode.second && lastBatchMode.first == batchMode)
169 lastBatchMode = {batchMode,
true};
177 throw std::runtime_error(std::string(
"In: ") + __func__ +
"(), " + __FILE__ +
":" + __LINE__ +
178 ": Cuda implementation of the computing library is not available\n");
181 log(
"using generic CPU library compiled with no vectorizations");
183 log(std::string(
"using CPU computation library compiled with -m") +
187 log(
"using CUDA computation library");
193class RooAbsRealWrapper final :
public RooAbsReal {
195 RooAbsRealWrapper() {}
197 :
RooAbsReal{
"RooFitDriverWrapper",
"RooFitDriverWrapper"}, _driver{&driver}, _ownsDriver{ownsDriver}
199 _driver->topNode().getParameters(&observables, _parameters,
true);
202 RooAbsRealWrapper(
const RooAbsRealWrapper &other,
const char *
name = 0)
203 :
RooAbsReal{other,
name}, _driver{other._driver}, _parameters{other._parameters}
207 ~RooAbsRealWrapper()
override
213 TObject *clone(
const char *newname)
const override {
return new RooAbsRealWrapper(*
this, newname); }
215 double defaultErrorLevel()
const override {
return _driver->topNode().defaultErrorLevel(); }
218 bool )
const override
220 outputSet.
add(_parameters);
226 void applyWeightSquared(
bool flag)
override
228 const_cast<RooAbsReal &
>(_driver->topNode()).applyWeightSquared(flag);
232 double evaluate()
const override {
return _driver ? _driver->getVal() : 0.0; }
244std::unique_ptr<RooAbsReal>
248 return std::unique_ptr<RooAbsReal>{
new RooAbsRealWrapper{*driver.release(), observables,
true}};
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
virtual RooAbsArg * cloneTree(const char *newname=0) const
Clone tree expression of objects.
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
RooArgSet * getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
RooArgSet * getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
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.
RooAbsArg * first() const
void clear()
Clear contents. If the collection is owning, it will also delete the contents.
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...
virtual void fixAddCoefNormalization(const RooArgSet &addNormSet=RooArgSet(), bool force=true)
Fix the interpretation of the coefficient of any RooAddPdf component in the expression tree headed by...
virtual void fixAddCoefRange(const char *rangeName=0, bool force=true)
Fix the interpretation of the coefficient of any RooAddPdf component in the expression tree headed by...
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.
static RooMsgService & instance()
Return reference to singleton instance.
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
void wrapPdfsInBinSamplingPdfs(RooAbsData const &data, double precision)
Wraps the components of this RooSimultaneous in RooBinSamplingPdfs.
const RooAbsCategoryLValue & indexCat() const
RooAbsPdf * getPdf(const char *catName) const
Return the p.d.f associated with the given index category name.
const char * GetName() const override
Returns name of object.
Mother of all ROOT objects.
RVec< PromoteType< T > > log(const RVec< T > &v)
basic_string_view< char > string_view
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
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(RooAbsPdf &pdf, RooAbsData &data, std::unique_ptr< RooAbsReal > &&constraints, std::string const &rangeName, std::string const &addCoefRangeName, RooArgSet const &projDeps, bool isExtended, double integrateOverBinsPrecision, RooFit::BatchModeOption batchMode)
void logArchitectureInfo(RooFit::BatchModeOption batchMode)
std::unique_ptr< RooAbsReal > makeDriverAbsRealWrapper(std::unique_ptr< ROOT::Experimental::RooFitDriver > driver, RooArgSet const &observables)
Static method to create a RooAbsRealWrapper that owns a given RooFitDriver passed by smart pointer.
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.