91RooAbsOptTestStatistic::RooAbsOptTestStatistic(
const char *
name,
const char *title,
RooAbsReal &real,
93 RooAbsTestStatistic::Configuration
const &cfg)
94 : RooAbsTestStatistic(
name, title, real, indata, projDeps, cfg),
95 _integrateBinsPrecision(cfg.integrateOverBinsPrecision)
98 if (operMode() != Slave) {
102 initSlave(real, indata, projDeps, _rangeName.c_str(), _addCoefRangeName.c_str());
108RooAbsOptTestStatistic::RooAbsOptTestStatistic(
const RooAbsOptTestStatistic &other,
const char *
name)
109 : RooAbsTestStatistic(other,
name),
110 _sealed(other._sealed),
111 _sealNotice(other._sealNotice),
112 _integrateBinsPrecision(other._integrateBinsPrecision)
115 if (operMode() != Slave) {
117 if (other._normSet) {
119 other._normSet->
snapshot(*_normSet);
124 initSlave(*other._funcClone, *other._dataClone, other._projDeps ? *other._projDeps :
RooArgSet(),
125 other._rangeName.c_str(), other._addCoefRangeName.c_str());
133 const char* addCoefRangeName) {
140 _funcCloneSet = nullptr ;
143 _funcObsSet = std::unique_ptr<RooArgSet>{_funcClone->getObservables(indata)}.release();
145 if (_funcClone->getAttribute(
"BinnedLikelihood")) {
146 _funcClone->setAttribute(
"BinnedLikelihoodActive") ;
150 if (!projDeps.
empty()) {
151 std::unique_ptr<RooArgSet> projDataDeps{_funcObsSet->
selectCommon(projDeps)};
164 _paramSet.
add(*connPars) ;
168 _funcClone->getParameters(indata.
get(), _paramSet);
177 for (std::size_t i = 0; i < _funcObsSet->size(); ++i) {
179 if (realDepRLV && realDepRLV->isDerived()) {
181 realDepRLV->leafNodeServerList(&tmp2,
nullptr,
true);
182 _funcObsSet->
add(tmp2,
true);
194 for (
const auto arg : *_funcObsSet) {
198 if (!realReal) continue ;
200 if (!datReal) continue ;
205 coutE(InputArguments) <<
"RooAbsOptTestStatistic: ERROR minimum of FUNC observable " << arg->
GetName()
206 <<
"(" << realReal->
getMin() <<
") is smaller than that of "
207 << arg->GetName() <<
" in the dataset (" << datReal->
getMin() <<
")" << std::endl ;
213 coutE(InputArguments) <<
"RooAbsOptTestStatistic: ERROR maximum of FUNC observable " << arg->GetName()
214 <<
" is larger than that of " << arg->GetName() <<
" in the dataset" << std::endl ;
221 if (rangeName && strlen(rangeName)) {
233 std::unique_ptr<RooArgSet> origObsSet( real.
getObservables(indata) );
234 if (rangeName && strlen(rangeName)) {
235 cxcoutI(Fitting) <<
"RooAbsOptTestStatistic::ctor(" <<
GetName() <<
") constructing test statistic for sub-range named " << rangeName << std::endl ;
237 if(
auto pdfClone =
dynamic_cast<RooAbsPdf*
>(_funcClone)) {
238 pdfClone->setNormRange(rangeName);
242 for (
const auto arg : *_funcObsSet) {
244 if (
auto realObs =
dynamic_cast<RooRealVar*
>(arg)) {
247 for(std::string
const& token : tokens) {
248 if(!realObs->hasRange(token.c_str())) {
249 std::stringstream errMsg;
250 errMsg <<
"The observable \"" << realObs->GetName() <<
"\" doesn't define the requested range \""
251 << token <<
"\". Replacing it with the default range." << std::endl;
252 coutI(Fitting) << errMsg.str() << std::endl;
268 if (rangeName && strlen(rangeName)) {
271 _funcClone->fixAddCoefNormalization(*_dataClone->get(),
false) ;
273 if (addCoefRangeName && strlen(addCoefRangeName)) {
275 <<
") fixing interpretation of coefficients of any RooAddPdf component to range " << addCoefRangeName << std::endl ;
276 _funcClone->fixAddCoefRange(addCoefRangeName,
false) ;
282 _dataClone->attachBuffers(*_funcObsSet) ;
283 setEventCount(_dataClone->numEntries()) ;
293 if (!projDeps.
empty()) {
296 projDeps.
snapshot(*_projDeps,
false) ;
299 _normSet->
remove(*_projDeps,
true,
true) ;
308 coutI(Optimization) <<
"RooAbsOptTestStatistic::ctor(" <<
GetName() <<
") optimizing internal clone of p.d.f for likelihood evaluation."
309 <<
"Lazy evaluation and associated change tracking will disabled for all nodes that depend on observables" << std::endl ;
320 _funcClone->getVal(_normSet) ;
327 if(_takeGlobalObservablesFromData && _data->getGlobalObservables()) {
328 recursiveRedirectServers(*_data->getGlobalObservables()) ;
337RooAbsOptTestStatistic::~RooAbsOptTestStatistic()
339 if (operMode()==Slave) {
359double RooAbsOptTestStatistic::combinedValue(
RooAbsReal** array,
Int_t n)
const
364 for (
Int_t i = 0; i <
n; ++i) {
366 carry +=
reinterpret_cast<RooAbsOptTestStatistic*
>(array[i])->getCarry();
368 const double t =
sum +
y;
369 carry = (t -
sum) -
y;
381bool RooAbsOptTestStatistic::redirectServersHook(
const RooAbsCollection& newServerList,
bool mustReplaceAll,
bool nameChange,
bool isRecursive)
383 RooAbsTestStatistic::redirectServersHook(newServerList,mustReplaceAll,nameChange,isRecursive) ;
384 if (operMode()!=Slave)
return false ;
385 bool ret = _funcClone->recursiveRedirectServers(newServerList,
false,nameChange) ;
394void RooAbsOptTestStatistic::printCompactTreeHook(ostream& os,
const char*
indent)
396 RooAbsTestStatistic::printCompactTreeHook(os,
indent) ;
397 if (operMode()!=Slave) return ;
399 indent2 +=
"opt >>" ;
400 _funcClone->printCompactTree(os,indent2.Data()) ;
401 os << indent2 <<
" dataset clone = " << _dataClone <<
" first obs = " << _dataClone->get()->first() << std::endl ;
415void RooAbsOptTestStatistic::optimizeCaching()
419 _funcClone->getVal(_normSet) ;
422 _funcClone->optimizeCacheMode(*_funcObsSet) ;
425 _dataClone->setDirtyProp(
false) ;
435bool RooAbsOptTestStatistic::setDataSlave(
RooAbsData& indata,
bool cloneData,
bool ownNewData)
438 if (operMode()==SimMaster) {
448 std::unique_ptr<RooAbsData> oldOwnedData;
450 oldOwnedData.reset(_dataClone);
451 _dataClone = nullptr ;
454 if (!cloneData && !_rangeName.empty()) {
455 coutW(InputArguments) <<
"RooAbsOptTestStatistic::setData(" <<
GetName() <<
") WARNING: test statistic was constructed with range selection on data, "
456 <<
"ignoring request to _not_ clone the input dataset" << std::endl ;
468 _dataClone = &indata ;
469 _ownData = ownNewData ;
474 _dataClone->attachBuffers(*_funcObsSet) ;
475 _dataClone->setDirtyProp(
false) ;
486 if(_takeGlobalObservablesFromData && _data->getGlobalObservables()) {
487 recursiveRedirectServers(*_data->getGlobalObservables()) ;
501 bool notice = (sealNotice() && strlen(sealNotice())) ;
502 coutW(ObjectHandling) <<
"RooAbsOptTestStatistic::data(" <<
GetName()
503 <<
") WARNING: object sealed by creator - access to data is not permitted: "
504 << (notice?sealNotice():
"<no user notice>") << std::endl ;
514const RooAbsData& RooAbsOptTestStatistic::data()
const
517 bool notice = (sealNotice() && strlen(sealNotice())) ;
518 coutW(ObjectHandling) <<
"RooAbsOptTestStatistic::data(" <<
GetName()
519 <<
") WARNING: object sealed by creator - access to data is not permitted: "
520 << (notice?sealNotice():
"<no user notice>") << std::endl ;
535void RooAbsOptTestStatistic::setUpBinSampling() {
537 auto& pdf =
static_cast<RooAbsPdf&
>(*_funcClone);
540 _funcClone = newPdf.release();
548const char* RooAbsOptTestStatistic::cacheUniqueSuffix()
const {
549 return Form(
"_%lx", _dataClone->uniqueId().value()) ;
int Int_t
Signed integer 4 bytes (int)
static void indent(ostringstream &buf, int indent_level)
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
virtual RooAbsReal * highBoundFunc() const
Return pointer to RooAbsReal parameterized upper bound, if any.
virtual RooAbsReal * lowBoundFunc() const
Return pointer to RooAbsReal parameterized lower bound, if any.
Abstract container object that can hold multiple RooAbsArg objects.
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.
void setAttribAll(const Text_t *name, bool value=true)
Set given attribute in each element of the collection by calling each elements setAttribute() functio...
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract base class for binned and unbinned datasets.
virtual const RooArgSet * get() const
RooFit::OwningPtr< RooAbsData > reduce(const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}) const
Create a reduced copy of this dataset.
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Abstract interface for all probability density functions.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
Abstract base class for objects that represent a real value and implements functionality common to al...
virtual double getValV(const RooArgSet *normalisationSet=nullptr) const
Return value of object.
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursiveStep) override
Function that is called at the end of redirectServers().
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
RooArgSet * selectCommon(const RooAbsCollection &refColl) const
Use RooAbsCollection::selecCommon(), but return as RooArgSet.
static std::unique_ptr< RooAbsPdf > create(RooAbsPdf &pdf, RooAbsData const &data, double precision)
Creates a wrapping RooBinSamplingPdf if appropriate.
Container class to hold unbinned data.
static void softAbort()
Soft abort function that interrupts macro execution but doesn't kill ROOT.
Efficient implementation of a product of PDFs of the form.
RooArgSet * getConnectedParameters(const RooArgSet &observables) const
Return all parameter constraint p.d.f.s on parameters listed in constrainedParams.
Variable that can be changed from the outside.
const RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false, bool shared=true) const override
Return binning definition with name.
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
const char * GetName() const override
Returns name of object.
RooCmdArg SelectVars(const RooArgSet &vars)
RooCmdArg CutRange(const char *rangeName)
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
std::unique_ptr< T > cloneTreeWithSameParameters(T const &arg, RooArgSet const *observables=nullptr)
Clone RooAbsArg object and reattach to original parameters.
std::string GetName(TCppScope_t)
static uint64_t sum(uint64_t i)