Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooEvaluatorWrapper.cxx
Go to the documentation of this file.
1/// \cond ROOFIT_INTERNAL
2
3/*
4 * Project: RooFit
5 * Authors:
6 * Jonas Rembser, CERN 2023
7 *
8 * Copyright (c) 2023, CERN
9 *
10 * Redistribution and use in source and binary forms,
11 * with or without modification, are permitted according to the terms
12 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
13 */
14
15/**
16\internal
17\file RooEvaluatorWrapper.cxx
18\class RooEvaluatorWrapper
19\ingroup Roofitcore
20
21Wraps a RooFit::Evaluator that evaluates a RooAbsReal back into a RooAbsReal.
22**/
23
24#include "RooEvaluatorWrapper.h"
25
26#include <RooAbsData.h>
27#include <RooAbsPdf.h>
28#include <RooAbsReal.h>
29#include <RooHelpers.h>
30#include <RooMsgService.h>
31#include <RooRealVar.h>
32#include <RooSimultaneous.h>
33
34#include <TList.h>
35
36RooEvaluatorWrapper::RooEvaluatorWrapper(RooAbsReal &topNode, std::unique_ptr<RooFit::Evaluator> evaluator,
37 std::string const &rangeName, RooAbsPdf const *pdf,
38 bool takeGlobalObservablesFromData)
39 : RooAbsReal{"RooEvaluatorWrapper", "RooEvaluatorWrapper"},
40 _evaluator{std::move(evaluator)},
41 _topNode("topNode", "top node", this, topNode),
42 _rangeName{rangeName},
43 _pdf{pdf},
44 _takeGlobalObservablesFromData{takeGlobalObservablesFromData}
45{
46}
47
48RooEvaluatorWrapper::RooEvaluatorWrapper(const RooEvaluatorWrapper &other, const char *name)
49 : RooAbsReal{other, name},
50 _evaluator{other._evaluator},
51 _topNode("topNode", this, other._topNode),
52 _data{other._data},
54 _pdf{other._pdf},
56 _dataSpans{other._dataSpans}
57{
58}
59
60bool RooEvaluatorWrapper::getParameters(const RooArgSet *observables, RooArgSet &outputSet,
61 bool /*stripDisconnected*/) const
62{
63 outputSet.add(_evaluator->getParameters());
64 if (observables) {
65 outputSet.remove(*observables, /*silent*/ false, /*matchByNameOnly*/ true);
66 }
67 // Exclude the data variables from the parameters which are not global observables
68 for (auto const &item : _dataSpans) {
69 if (_data->getGlobalObservables() && _data->getGlobalObservables()->find(item.first->GetName())) {
70 continue;
71 }
72 RooAbsArg *found = outputSet.find(item.first->GetName());
73 if (found) {
74 outputSet.remove(*found);
75 }
76 }
77 // If we take the global observables as data, we have to return these as
78 // parameters instead of the parameters in the model. Otherwise, the
79 // constant parameters in the fit result that are global observables will
80 // not have the right values.
82 outputSet.replace(*_data->getGlobalObservables());
83 }
84 return false;
85}
86
87bool RooEvaluatorWrapper::setData(RooAbsData &data, bool /*cloneData*/)
88{
89 _data = &data;
90 std::stack<std::vector<double>>{}.swap(_vectorBuffers);
91 bool skipZeroWeights = !_pdf->getAttribute("BinnedLikelihoodActive");
92 _dataSpans = RooFit::Detail::BatchModeDataHelpers::getDataSpans(
93 *_data, _rangeName, dynamic_cast<RooSimultaneous const *>(_pdf), skipZeroWeights, _takeGlobalObservablesFromData,
94 _vectorBuffers);
95 for (auto const &item : _dataSpans) {
96 _evaluator->setInput(item.first->GetName(), item.second, false);
97 }
98 return true;
99}
100
101/// \endcond
const bool _takeGlobalObservablesFromData
If the global observable values are taken from data.
RooAbsData * _data
Pointer to original input dataset.
std::string _rangeName
Name of range in which to calculate test statistic.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
char name[80]
Definition TGX11.cxx:110
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
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.
virtual bool replace(const RooAbsArg &var1, const RooAbsArg &var2)
Replace var1 with var2 and return true for success.
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
RooArgSet const * getGlobalObservables() const
Returns snapshot of global observables stored in this data.
Definition RooAbsData.h:288
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.