67using std::endl, std::ostream;
140 const char* addCoefRangeName) {
152 if (
_funcClone->getAttribute(
"BinnedLikelihood")) {
153 _funcClone->setAttribute(
"BinnedLikelihoodActive") ;
157 if (!projDeps.
empty()) {
158 std::unique_ptr<RooArgSet> projDataDeps{
_funcObsSet->selectCommon(projDeps)};
159 projDataDeps->setAttribAll(
"projectedDependent") ;
186 if (realDepRLV && realDepRLV->isDerived()) {
188 realDepRLV->leafNodeServerList(&tmp2,
nullptr,
true);
205 if (!realReal) continue ;
207 if (!datReal) continue ;
212 coutE(InputArguments) <<
"RooAbsOptTestStatistic: ERROR minimum of FUNC observable " << arg->GetName()
213 <<
"(" << realReal->
getMin() <<
") is smaller than that of "
214 << arg->GetName() <<
" in the dataset (" << datReal->
getMin() <<
")" << endl ;
220 coutE(InputArguments) <<
"RooAbsOptTestStatistic: ERROR maximum of FUNC observable " << arg->GetName()
221 <<
" is larger than that of " << arg->GetName() <<
" in the dataset" << endl ;
228 if (rangeName && strlen(rangeName)) {
241 std::unique_ptr<RooArgSet> origObsSet( real.
getObservables(indata) );
242 if (rangeName && strlen(rangeName)) {
243 cxcoutI(Fitting) <<
"RooAbsOptTestStatistic::ctor(" <<
GetName() <<
") constructing test statistic for sub-range named " << rangeName << endl ;
246 pdfClone->setNormRange(rangeName);
252 if (
auto realObs =
dynamic_cast<RooRealVar*
>(arg)) {
255 for(std::string
const& token : tokens) {
256 if(!realObs->hasRange(token.c_str())) {
257 std::stringstream errMsg;
258 errMsg <<
"The observable \"" << realObs->GetName() <<
"\" doesn't define the requested range \""
259 << token <<
"\". Replacing it with the default range." << std::endl;
260 coutI(Fitting) << errMsg.str() << std::endl;
276 if (rangeName && strlen(rangeName)) {
281 if (addCoefRangeName && strlen(addCoefRangeName)) {
283 <<
") fixing interpretation of coefficients of any RooAddPdf component to range " << addCoefRangeName << endl ;
284 _funcClone->fixAddCoefRange(addCoefRangeName,
false) ;
301 if (!projDeps.
empty()) {
316 coutI(Optimization) <<
"RooAbsOptTestStatistic::ctor(" <<
GetName() <<
") optimizing internal clone of p.d.f for likelihood evaluation."
317 <<
"Lazy evaluation and associated change tracking will disabled for all nodes that depend on observables" << endl ;
376 const double t =
sum +
y;
377 carry = (t -
sum) -
y;
393 bool ret =
_funcClone->recursiveRedirectServers(newServerList,
false,nameChange) ;
407 indent2 +=
"opt >>" ;
409 os << indent2 <<
" dataset clone = " <<
_dataClone <<
" first obs = " <<
_dataClone->get()->first() << endl ;
431 cxcoutW(Optimization) <<
"RooAbsOptTestStatistic::constOptimize(" <<
GetName()
432 <<
") dataset cache is owned by another object, no constant term optimization can be applied" << endl ;
439 cxcoutI(Optimization) <<
"RooAbsOptTestStatistic::constOptimize(" <<
GetName()
440 <<
") function caching prohibited by test statistic, no constant term optimization is applied" << endl ;
451 cxcoutI(Optimization) <<
"RooAbsOptTestStatistic::constOptimize(" <<
GetName()
452 <<
") optimizing evaluation of test statistic by finding all nodes in p.d.f that depend exclusively"
453 <<
" on observables and constant parameters and precalculating their values" << endl ;
458 cxcoutI(Optimization) <<
"RooAbsOptTestStatistic::constOptimize(" <<
GetName()
459 <<
") deactivating optimization of constant terms in test statistic" << endl ;
464 cxcoutI(Optimization) <<
"RooAbsOptTestStatistic::constOptimize(" <<
GetName()
465 <<
") one ore more parameter were changed from constant to floating or vice versa, "
466 <<
"re-evaluating constant term optimization" << endl ;
472 cxcoutI(Optimization) <<
"RooAbsOptTestStatistic::constOptimize(" <<
GetName()
473 <<
") the value of one ore more constant parameter were changed re-evaluating constant term optimization" << endl ;
538 if (
_funcClone->getAttribute(
"NoOptimizeLevel1")) {
539 coutI(Minimization) <<
" Optimization customization: Level-1 constant-term optimization prohibited by attribute NoOptimizeLevel1 set on top-level pdf "
543 if (
_funcClone->getAttribute(
"NoOptimizeLevel2")) {
544 coutI(Minimization) <<
" Optimization customization: Level-2 constant-term optimization prohibited by attribute NoOptimizeLevel2 set on top-level pdf "
546 applyTrackingOpt=false ;
558 if (applyTrackingOpt) {
560 coutW(Optimization) <<
"RooAbsOptTestStatistic::optimizeConstantTerms(" <<
GetName()
561 <<
") WARNING Cache-and-track optimization (Optimize level 2) is only available for datasets"
562 <<
" implement in terms of RooVectorDataStore - ignoring this option for current dataset" << endl ;
563 applyTrackingOpt = false ;
567 if (applyTrackingOpt) {
570 for (
auto arg : branches) {
571 arg->setCacheAndTrackHints(trackNodes);
574 trackNodes.
remove(*std::unique_ptr<RooAbsCollection>{trackNodes.
selectByAttrib(
"Constant",
true)});
593 std::unique_ptr<RooAbsCollection> constNodes{
_cachedNodes.selectByAttrib(
"ConstantExpressionCached",
true)};
595 actualTrackNodes.
remove(*constNodes) ;
596 if (!constNodes->empty()) {
597 if (constNodes->size()<20) {
598 coutI(Minimization) <<
" The following expressions have been identified as constant and will be precalculated and cached: " << *constNodes << endl ;
600 coutI(Minimization) <<
" A total of " << constNodes->size() <<
" expressions have been identified as constant and will be precalculated and cached." << endl ;
603 if (!actualTrackNodes.
empty()) {
604 if (actualTrackNodes.
size()<20) {
605 coutI(Minimization) <<
" The following expressions will be evaluated in cache-and-track mode: " << actualTrackNodes << endl ;
607 coutI(Minimization) <<
" A total of " << constNodes->size() <<
" expressions will be evaluated in cache-and-track-mode." << endl ;
661 std::unique_ptr<RooAbsData> oldOwnedData;
668 coutW(InputArguments) <<
"RooAbsOptTestStatistic::setData(" <<
GetName() <<
") WARNING: test statistic was constructed with range selection on data, "
669 <<
"ignoring request to _not_ clone the input dataset" << endl ;
724 coutW(ObjectHandling) <<
"RooAbsOptTestStatistic::data(" <<
GetName()
725 <<
") WARNING: object sealed by creator - access to data is not permitted: "
726 << (notice?
sealNotice():
"<no user notice>") << endl ;
740 coutW(ObjectHandling) <<
"RooAbsOptTestStatistic::data(" <<
GetName()
741 <<
") WARNING: object sealed by creator - access to data is not permitted: "
742 << (notice?
sealNotice():
"<no user notice>") << endl ;
759 auto& pdf =
static_cast<RooAbsPdf&
>(*_funcClone);
true
Register systematic variations for multiple existing columns using auto-generated tags.
static void indent(ostringstream &buf, int indent_level)
return
Invalidate stored TCling state for declarations included in transaction âTâ.
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
bool recursiveRedirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
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.
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
friend class RooAbsCollection
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.
RooAbsCollection * selectByAttrib(const char *name, bool value) const
Create a subset of the current collection, consisting only of those elements with the specified attri...
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our 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...
Storage_t::size_type size() const
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={})
Create a reduced copy of this dataset.
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Abstract base class for test statistics objects that evaluate a function or PDF at each point of a gi...
bool setDataSlave(RooAbsData &data, bool cloneData=true, bool ownNewDataAnyway=false) override
Change dataset that is used to given one.
~RooAbsOptTestStatistic() override
Destructor.
RooAbsReal * _funcClone
Pointer to internal clone of input function.
bool _sealed
Is test statistic sealed â i.e. no access to data.
void optimizeConstantTerms(bool, bool=true)
Driver function to activate global constant term optimization.
double combinedValue(RooAbsReal **gofArray, Int_t nVal) const override
Method to combined test statistic results calculated into partitions into the global result.
void runRecalculateCache(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const override
bool _ownData
Do we own the dataset.
void optimizeCaching()
This method changes the value caching logic for all nodes that depends on any of the observables as d...
const char * sealNotice() const
bool _skipZeroWeights
! Whether to skip entries with weight zero in the evaluation
virtual bool allowFunctionCache()
RooArgSet * _funcObsSet
List of observables in the pdf expression.
RooAbsOptTestStatistic(const char *name, const char *title, RooAbsReal &real, RooAbsData &data, const RooArgSet &projDeps, RooAbsTestStatistic::Configuration const &cfg)
Create a test statistic, and optimise its calculation.
void constOptimizeTestStatistic(ConstOpCode opcode, bool doAlsoTrackingOpt=true) override
Driver function to propagate constant term optimizations in test statistic.
void setUpBinSampling()
Inspect PDF to find out if we are doing a binned fit to a 1-dimensional unbinned PDF.
friend class RooAbsTestStatistic
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive) override
Catch server redirect calls and forward to internal clone of function.
RooArgSet _cachedNodes
! List of nodes that are cached as constant expressions
void initSlave(RooAbsReal &real, RooAbsData &indata, const RooArgSet &projDeps, const char *rangeName, const char *addCoefRangeName)
TString _sealNotice
User-defined notice shown when reading a sealed likelihood.
void printCompactTreeHook(std::ostream &os, const char *indent="") override
Catch print hook function and forward to function clone.
RooArgSet * _normSet
Pointer to set with observables used for normalization.
const char * cacheUniqueSuffix() const override
Returns a suffix string that is unique for RooAbsOptTestStatistic instances that don't share the same...
RooArgSet * _funcCloneSet
Set owning all components of internal clone of input function.
RooAbsData * _dataClone
Pointer to internal clone if input data.
virtual RooArgSet requiredExtraObservables() const
double _integrateBinsPrecision
RooArgSet * _projDeps
Set of projected observable.
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.
virtual double getValV(const RooArgSet *normalisationSet=nullptr) const
Return value of object.
friend class RooVectorDataStore
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursiveStep) override
Function that is called at the end of redirectServers().
double _evalCarry
! carry of Kahan sum in evaluatePartition
std::string _addCoefRangeName
Name of reference to be used for RooAddPdf components.
GOFOpMode operMode() const
RooSetProxy _paramSet
Parameters of the test statistic (=parameters of the input function)
RooAbsReal * _func
Pointer to original input function.
void printCompactTreeHook(std::ostream &os, const char *indent="") override
Add extra information on component test statistics when printing itself as part of a tree structure.
std::string _rangeName
Name of range in which to calculate test statistic.
void constOptimizeTestStatistic(ConstOpCode opcode, bool doAlsoTrackingOpt=true) override
Forward constant term optimization management calls to component test statistics.
void setEventCount(Int_t nEvents)
virtual double getCarry() const
RooAbsData * _data
Pointer to original input dataset.
const bool _takeGlobalObservablesFromData
If the global observable values are taken from data.
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive) override
Forward server redirect calls to component test statistics.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
static std::unique_ptr< RooAbsPdf > create(RooAbsPdf &pdf, RooAbsData const &data, double precision)
Creates a wrapping RooBinSamplingPdf if appropriate.
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) 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.
const char * Data() const
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.
static uint64_t sum(uint64_t i)