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(*
dynamic_cast<RooArgSet *
>(allVars->selectByAttrib(global_observables_tag.c_str(),
true)));
101 oocoutI(
nullptr,
Minimization) <<
"User-defined specification of global observables definition with tag named '"
102 << global_observables_tag <<
"'" << std::endl;
103 }
else if (global_observables.
empty()) {
109 <<
"p.d.f. provides built-in specification of global observables definition with tag named '"
110 << defGlobObsTag <<
"'" << std::endl;
111 std::unique_ptr<RooArgSet> allVars{pdf->
getVariables()};
112 global_observables.
add(*
dynamic_cast<RooArgSet *
>(allVars->selectByAttrib(defGlobObsTag,
true)));
118 if (!constrained_parameters.
empty()) {
119 std::unique_ptr<RooArgSet> constraints{
121 allConstraints.
add(*constraints);
123 if (!external_constraints.
empty()) {
124 allConstraints.
add(external_constraints);
127 return allConstraints;
151 std::string
const &global_observables_tag)
153 auto allConstraints = getConstraintsSet(pdf,
data, constrained_parameters, external_constraints, global_observables,
154 global_observables_tag);
156 std::unique_ptr<RooSubsidiaryL> subsidiary_likelihood;
158 if (!allConstraints.
empty()) {
160 oocoutI(
nullptr,
Minimization) <<
" Including the following constraint terms in minimization: " << allConstraints
162 if (!global_observables.
empty()) {
163 oocoutI(
nullptr,
Minimization) <<
"The following global observables have been defined: " << global_observables
166 std::string
name(
"likelihood for pdf ");
168 subsidiary_likelihood = std::make_unique<RooSubsidiaryL>(
169 name, allConstraints, (!global_observables.
empty()) ? global_observables : constrained_parameters);
172 return subsidiary_likelihood;
191 for (
const auto component : (static_cast<
RooProdPdf *>(pdf))->pdfList()) {
192 if (component->getAttribute(
"BinnedLikelihood") && component->IsA()->InheritsFrom(
RooRealSumPdf::Class())) {
193 binnedPdf =
static_cast<RooAbsPdf *
>(component);
222 TString simCatName(simCat.GetName());
225 std::unique_ptr<TList> dsetList{
_data.
split(*sim_pdf, process_empty_data_sets)};
227 throw std::logic_error(
228 "getSimultaneousComponents ERROR, index category of simultaneous pdf is missing in dataset, aborting");
232 std::size_t N_components = 0;
234 for (
const auto &catState : simCat) {
236 RooAbsPdf *component_pdf = sim_pdf->getPdf(catState.first.c_str());
237 auto *dset =
static_cast<RooAbsData *
>(dsetList->FindObject(catState.first.c_str()));
239 if (component_pdf && dset && (0. != dset->sumEntries() || process_empty_data_sets)) {
245 std::vector<std::unique_ptr<RooAbsL>> components;
246 components.reserve(N_components);
251 for (
const auto &catState : simCat) {
252 const std::string &catName = catState.first;
254 RooAbsPdf *component_pdf = sim_pdf->getPdf(catName.c_str());
255 auto *dset =
static_cast<RooAbsData *
>(dsetList->FindObject(catName.c_str()));
257 if (component_pdf && dset && (0. != dset->sumEntries() || process_empty_data_sets)) {
258 ooccoutI(
nullptr,
Fitting) <<
"getSimultaneousComponents: creating slave calculator #" <<
n <<
" for state "
259 << catName <<
" (" << dset->numEntries() <<
" dataset entries)" << std::endl;
261 RooAbsPdf *binnedPdf = getBinnedPdf(component_pdf);
262 bool binnedL = (binnedPdf !=
nullptr);
265 for (
const auto component : (
static_cast<RooProdPdf *
>(component_pdf))->pdfList()) {
266 if (component->getAttribute(
"MAIN_MEASUREMENT")) {
269 binnedPdf =
static_cast<RooAbsPdf *
>(component);
277 components.push_back(std::make_unique<RooBinnedL>((binnedPdf ? binnedPdf : component_pdf), dset));
279 components.push_back(
280 std::make_unique<RooUnbinnedL>((binnedPdf ? binnedPdf : component_pdf), dset,
_extended,
_evalBackend));
283 components.back()->setSimCount(N_components);
287 std::unique_ptr<RooArgSet> actualParams{binnedPdf ? binnedPdf->
getParameters(dset)
294 assert(selTargetParams.
equals(*components.back()->getParameters()));
298 if ((!dset || (0. != dset->sumEntries() && !process_empty_data_sets)) && component_pdf) {
299 ooccoutD(
nullptr,
Fitting) <<
"getSimultaneousComponents: state " << catName
300 <<
" has no data entries, no slave calculator created" << std::endl;
304 oocoutI(
nullptr,
Fitting) <<
"getSimultaneousComponents: created " <<
n <<
" slave calculators." << std::endl;
331 std::unique_ptr<RooAbsL> likelihood;
332 std::vector<std::unique_ptr<RooAbsL>> components;
336 }
else if (
auto binnedPdf = getBinnedPdf(&
_pdf)) {
337 likelihood = std::make_unique<RooBinnedL>(binnedPdf, &
_data);
346 components.push_back(std::move(likelihood));
350 if (!components.empty()) {
351 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...