54namespace TestStatistics {
59 ExternalConstraints external_constraints, GlobalObservables global_observables,
60 std::string global_observables_tag)
69 bool did_default_constraint_algo =
false;
70 std::size_t N_default_constraints = 0;
72 if (constrained_parameters.set.getSize() == 0) {
74 constrained_parameters.set.
add(*default_constraints);
75 doStripDisconnected =
kTRUE;
77 did_default_constraint_algo =
true;
78 N_default_constraints = default_constraints->getSize();
82 if (did_default_constraint_algo) {
83 assert(N_default_constraints ==
static_cast<std::size_t
>(constrained_parameters.set.getSize()));
90 if (!global_observables_tag.empty()) {
91 if (global_observables.set.getSize() > 0) {
95 global_observables.set.
add(
96 *
dynamic_cast<RooArgSet *
>(allVars->selectByAttrib(global_observables_tag.c_str(),
kTRUE)));
98 <<
"User-defined specification of global observables definition with tag named '" << global_observables_tag
100 }
else if (global_observables.set.getSize() == 0) {
106 <<
"p.d.f. provides built-in specification of global observables definition with tag named '"
107 << defGlobObsTag <<
"'" << std::endl;
108 std::unique_ptr<RooArgSet> allVars{pdf->
getVariables()};
109 global_observables.set.
add(*
dynamic_cast<RooArgSet *
>(allVars->selectByAttrib(defGlobObsTag,
kTRUE)));
115 if (constrained_parameters.set.getSize() > 0) {
116 std::unique_ptr<RooArgSet> constraints{
118 allConstraints.
add(*constraints);
120 if (external_constraints.set.getSize() > 0) {
121 allConstraints.
add(external_constraints.set);
124 return allConstraints;
146std::unique_ptr<RooSubsidiaryL>
147buildSubsidiaryL(
RooAbsPdf *pdf,
RooAbsData *data, ConstrainedParameters constrained_parameters,
148 ExternalConstraints external_constraints, GlobalObservables global_observables,
149 std::string global_observables_tag)
151 auto allConstraints = getConstraintsSet(pdf, data, constrained_parameters, external_constraints, global_observables,
152 global_observables_tag);
154 std::unique_ptr<RooSubsidiaryL> subsidiary_likelihood;
156 if (allConstraints.
getSize() > 0) {
159 <<
" Including the following contraint terms in minimization: " << allConstraints << std::endl;
160 if (global_observables.set.getSize() > 0) {
162 <<
"The following global observables have been defined: " << global_observables.set << std::endl;
164 std::string
name(
"likelihood for pdf ");
166 subsidiary_likelihood = std::make_unique<RooSubsidiaryL>(
167 name, allConstraints,
168 (global_observables.set.getSize() > 0) ? global_observables.set : constrained_parameters.set);
171 return subsidiary_likelihood;
177 return sim_pdf !=
nullptr;
194 }
else if (pdf->IsA()->
InheritsFrom(RooProdPdf::Class())) {
196 for (
const auto component : ((
RooProdPdf *)pdf)->pdfList()) {
197 if (component->getAttribute(
"BinnedLikelihood") && component->IsA()->InheritsFrom(RooRealSumPdf::Class())) {
217std::vector<std::unique_ptr<RooAbsL>>
233 std::unique_ptr<TList> dsetList{data->
split(*sim_pdf, process_empty_data_sets)};
235 throw std::logic_error(
236 "getSimultaneousComponents ERROR, index category of simultaneous pdf is missing in dataset, aborting");
240 std::size_t N_components = 0;
242 for (
const auto &catState : simCat) {
244 RooAbsPdf *component_pdf = sim_pdf->getPdf(catState.first.c_str());
247 if (component_pdf && dset && (0. != dset->sumEntries() || process_empty_data_sets)) {
253 std::vector<std::unique_ptr<RooAbsL>> components;
254 components.reserve(N_components);
259 for (
const auto &catState : simCat) {
260 const std::string &catName = catState.first;
262 RooAbsPdf *component_pdf = sim_pdf->getPdf(catName.c_str());
265 if (component_pdf && dset && (0. != dset->sumEntries() || process_empty_data_sets)) {
267 <<
"getSimultaneousComponents: creating slave calculator #" <<
n <<
" for state " << catName <<
" ("
268 << dset->numEntries() <<
" dataset entries)" << std::endl;
270 RooAbsPdf *binnedPdf = getBinnedPdf(component_pdf);
271 Bool_t binnedL = (binnedPdf !=
nullptr);
272 if (binnedPdf ==
nullptr && component_pdf->IsA()->
InheritsFrom(RooProdPdf::Class())) {
274 for (
const auto component : ((
RooProdPdf *)component_pdf)->pdfList()) {
275 if (component->getAttribute(
"MAIN_MEASUREMENT")) {
286 components.push_back(std::make_unique<RooBinnedL>((binnedPdf ? binnedPdf : component_pdf), dset));
288 components.push_back(std::make_unique<RooUnbinnedL>((binnedPdf ? binnedPdf : component_pdf), dset));
291 components.back()->setSimCount(N_components);
295 std::unique_ptr<RooArgSet> actualParams{binnedPdf ? binnedPdf->
getParameters(dset)
297 std::unique_ptr<RooArgSet> selTargetParams{
300 assert(selTargetParams->equals(*components.back()->getParameters()));
304 if ((!dset || (0. != dset->sumEntries() && !process_empty_data_sets)) && component_pdf) {
306 <<
" has no data entries, no slave calculator created" << std::endl;
310 oocoutI((
TObject *)
nullptr,
Fitting) <<
"getSimultaneousComponents: created " <<
n <<
" slave calculators."
352 std::string global_observables_tag)
354 std::unique_ptr<RooAbsL> likelihood;
355 std::vector<std::unique_ptr<RooAbsL>> components;
357 if (isSimultaneous(pdf)) {
358 components = getSimultaneousComponents(pdf, data, extended);
359 }
else if (
auto binnedPdf = getBinnedPdf(pdf)) {
360 likelihood = std::make_unique<RooBinnedL>(binnedPdf, data);
362 likelihood = std::make_unique<RooUnbinnedL>(pdf, data, extended);
365 auto subsidiary = buildSubsidiaryL(pdf, data, constrained_parameters, external_constraints, global_observables, global_observables_tag);
368 components.push_back(std::move(likelihood));
372 if (components.size() > 0) {
373 likelihood = std::make_unique<RooSumL>(pdf, data, std::move(components), extended);
379std::unique_ptr<RooAbsL>
384std::unique_ptr<RooAbsL>
389std::unique_ptr<RooAbsL>
394std::unique_ptr<RooAbsL>
399std::unique_ptr<RooAbsL>
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key 'key'.
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Bool_t getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
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...
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
bool selectCommon(const RooAbsCollection &refColl, RooAbsCollection &outColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
RooAbsData is the common abstract base class for binned and unbinned datasets.
virtual const RooArgSet * get() const
virtual TList * split(const RooAbsCategory &splitCat, Bool_t createEmptyDataSets=kFALSE) const
Split dataset into subsets based on states of given splitCat in this dataset.
virtual RooArgSet * getAllConstraints(const RooArgSet &observables, RooArgSet &constrainedParams, Bool_t stripDisconnected=kTRUE) 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.
static bool isExtendedHelper(RooAbsPdf *pdf, Extended extended)
RooProdPdf is an efficient implementation of a product of PDFs of the form.
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
virtual const char * GetName() const
Returns name of object.
Mother of all ROOT objects.
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
std::unique_ptr< RooAbsL > buildLikelihood(RooAbsPdf *pdf, RooAbsData *data, RooAbsL::Extended extended=RooAbsL::Extended::Auto, ConstrainedParameters constrained_parameters={}, ExternalConstraints external_constraints={}, GlobalObservables global_observables={}, std::string global_observables_tag={})
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Optional parameter used in buildLikelihood(), see documentation there.
Optional parameter used in buildLikelihood(), see documentation there.
Optional parameter used in buildLikelihood(), see documentation there.