59namespace TestStatistics {
65 std::string
const &global_observables_tag)
69 bool doStripDisconnected =
false;
74 bool did_default_constraint_algo =
false;
75 std::size_t N_default_constraints = 0;
77 if (constrained_parameters.
empty()) {
79 constrained_parameters.
add(*default_constraints);
80 doStripDisconnected =
true;
82 did_default_constraint_algo =
true;
83 N_default_constraints = default_constraints->size();
87 if (did_default_constraint_algo) {
88 assert(N_default_constraints ==
static_cast<std::size_t
>(constrained_parameters.
size()));
95 if (!global_observables_tag.empty()) {
96 if (!global_observables.
empty()) {
100 global_observables.
add(
101 *std::unique_ptr<RooArgSet>{allVars->selectByAttrib(global_observables_tag.c_str(),
true)});
102 oocoutI(
nullptr,
Minimization) <<
"User-defined specification of global observables definition with tag named '"
103 << global_observables_tag <<
"'" << std::endl;
104 }
else if (global_observables.
empty()) {
110 <<
"p.d.f. provides built-in specification of global observables definition with tag named '"
111 << defGlobObsTag <<
"'" << std::endl;
112 std::unique_ptr<RooArgSet> allVars{pdf->
getVariables()};
113 global_observables.
add(*std::unique_ptr<RooArgSet>{allVars->selectByAttrib(defGlobObsTag,
true)});
119 if (!constrained_parameters.
empty()) {
120 std::unique_ptr<RooArgSet> constraints{
122 allConstraints.
add(*constraints);
124 if (!external_constraints.
empty()) {
125 allConstraints.
add(external_constraints);
128 return allConstraints;
152 std::string
const &global_observables_tag)
154 auto allConstraints = getConstraintsSet(pdf,
data, constrained_parameters, external_constraints, global_observables,
155 global_observables_tag);
157 std::unique_ptr<RooSubsidiaryL> subsidiary_likelihood;
159 if (!allConstraints.
empty()) {
161 oocoutI(
nullptr,
Minimization) <<
" Including the following constraint terms in minimization: " << allConstraints
163 if (!global_observables.
empty()) {
164 oocoutI(
nullptr,
Minimization) <<
"The following global observables have been defined: " << global_observables
167 std::string
name(
"likelihood for pdf ");
169 subsidiary_likelihood = std::make_unique<RooSubsidiaryL>(
170 name, allConstraints, (!global_observables.
empty()) ? global_observables : constrained_parameters);
173 return subsidiary_likelihood;
192 for (
const auto component : (static_cast<
RooProdPdf *>(pdf))->pdfList()) {
193 if (component->getAttribute(
"BinnedLikelihood") && component->IsA()->InheritsFrom(
RooRealSumPdf::Class())) {
194 binnedPdf =
static_cast<RooAbsPdf *
>(component);
223 TString simCatName(simCat.GetName());
226 std::unique_ptr<TList> dsetList{
_data.
split(*sim_pdf, process_empty_data_sets)};
228 throw std::logic_error(
229 "getSimultaneousComponents ERROR, index category of simultaneous pdf is missing in dataset, aborting");
233 std::size_t N_components = 0;
235 for (
const auto &catState : simCat) {
237 RooAbsPdf *component_pdf = sim_pdf->getPdf(catState.first.c_str());
238 auto *dset =
static_cast<RooAbsData *
>(dsetList->FindObject(catState.first.c_str()));
240 if (component_pdf && dset && (0. != dset->sumEntries() || process_empty_data_sets)) {
246 std::vector<std::unique_ptr<RooAbsL>> components;
247 components.reserve(N_components);
252 for (
const auto &catState : simCat) {
253 const std::string &catName = catState.first;
255 RooAbsPdf *component_pdf = sim_pdf->getPdf(catName.c_str());
256 auto *dset =
static_cast<RooAbsData *
>(dsetList->FindObject(catName.c_str()));
258 if (component_pdf && dset && (0. != dset->sumEntries() || process_empty_data_sets)) {
259 ooccoutI(
nullptr,
Fitting) <<
"getSimultaneousComponents: creating slave calculator #" <<
n <<
" for state "
260 << catName <<
" (" << dset->numEntries() <<
" dataset entries)" << std::endl;
262 RooAbsPdf *binnedPdf = getBinnedPdf(component_pdf);
263 bool binnedL = (binnedPdf !=
nullptr);
266 for (
const auto component : (
static_cast<RooProdPdf *
>(component_pdf))->pdfList()) {
267 if (component->getAttribute(
"MAIN_MEASUREMENT")) {
270 binnedPdf =
static_cast<RooAbsPdf *
>(component);
278 components.push_back(std::make_unique<RooBinnedL>((binnedPdf ? binnedPdf : component_pdf), dset));
280 components.push_back(
281 std::make_unique<RooUnbinnedL>((binnedPdf ? binnedPdf : component_pdf), dset,
_extended,
_evalBackend));
284 components.back()->setSimCount(N_components);
288 std::unique_ptr<RooArgSet> actualParams{binnedPdf ? binnedPdf->
getParameters(dset)
295 assert(selTargetParams.
equals(*components.back()->getParameters()));
299 if ((!dset || (0. != dset->sumEntries() && !process_empty_data_sets)) && component_pdf) {
300 ooccoutD(
nullptr,
Fitting) <<
"getSimultaneousComponents: state " << catName
301 <<
" has no data entries, no slave calculator created" << std::endl;
305 oocoutI(
nullptr,
Fitting) <<
"getSimultaneousComponents: created " <<
n <<
" slave calculators." << std::endl;
332 std::unique_ptr<RooAbsL> likelihood;
333 std::vector<std::unique_ptr<RooAbsL>> components;
337 }
else if (
auto binnedPdf = getBinnedPdf(&
_pdf)) {
338 likelihood = std::make_unique<RooBinnedL>(binnedPdf, &
_data);
347 components.push_back(std::move(likelihood));
351 if (!components.empty()) {
352 likelihood = std::make_unique<RooSumL>(&
_pdf, &
_data, std::move(components),
_extended);
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
RooFit::OwningPtr< 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...
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key 'key'.
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
RooFit::OwningPtr< RooArgSet > getVariables(bool stripDisconnected=true) const
Return RooArgSet with all variables (tree leaf nodes of expression tree)
Abstract base class for objects that represent a discrete value that can be set from the outside,...
bool equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically-named contents.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
Abstract base class for binned and unbinned datasets.
virtual const RooArgSet * get() const
virtual RooFit::OwningPtr< TList > split(const RooAbsCategory &splitCat, bool createEmptyDataSets=false) const
Split the dataset into subsets based on states of a categorical variable in this dataset.
Abstract interface for all probability density functions.
TClass * IsA() const override
RooArgSet * getAllConstraints(const RooArgSet &observables, RooArgSet &constrainedParams, bool stripDisconnected=true) const
This helper function finds and collects all constraints terms of all component p.d....
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * selectCommon(const RooAbsCollection &refColl) const
Use RooAbsCollection::selecCommon(), but return as RooArgSet.
RooArgSet _globalObservables
RooFit::EvalBackend _evalBackend
std::unique_ptr< RooAbsL > build()
std::vector< std::unique_ptr< RooAbsL > > getSimultaneousComponents()
NLLFactory & EvalBackend(RooFit::EvalBackend evalBackend)
RooArgSet _externalConstraints
NLLFactory(RooAbsPdf &pdf, RooAbsData &data)
Create a likelihood builder for a given pdf and dataset.
std::string _globalObservablesTag
RooAbsL::Extended _extended
NLLFactory & ExternalConstraints(const RooArgSet &externalconstraints)
NLLFactory & Extended(RooAbsL::Extended extended)
NLLFactory & GlobalObservables(const RooArgSet &globalObservables)
NLLFactory & ConstrainedParameters(const RooArgSet &constrainedParameters)
RooArgSet _constrainedParameters
NLLFactory & GlobalObservablesTag(const char *globalObservablesTag)
static bool isExtendedHelper(RooAbsPdf *pdf, Extended extended)
Efficient implementation of a product of PDFs of the form.
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
const char * GetName() const override
Returns name of object.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...