22std::unique_ptr<RooArgSet>
23getGlobalObservables(
RooAbsPdf const &pdf,
RooArgSet const *globalObservables,
const char *globalObservablesTag)
26 if (globalObservables && globalObservablesTag) {
28 std::string errMsg =
"RooAbsPdf::fitTo: GlobalObservables and GlobalObservablesTag options mutually exclusive!";
29 oocoutE(&pdf, Minimization) << errMsg << std::endl;
30 throw std::invalid_argument(errMsg);
32 if (globalObservables) {
34 return std::make_unique<RooArgSet>(*globalObservables);
37 if (globalObservablesTag) {
38 oocoutI(&pdf, Minimization) <<
"User-defined specification of global observables definition with tag named '"
39 << globalObservablesTag <<
"'" << std::endl;
44 if (
auto defaultGlobalObservablesTag = pdf.
getStringAttribute(
"DefaultGlobalObservablesTag")) {
45 oocoutI(&pdf, Minimization) <<
"p.d.f. provides built-in specification of global observables definition "
46 <<
"with tag named '" << defaultGlobalObservablesTag <<
"'" << std::endl;
47 globalObservablesTag = defaultGlobalObservablesTag;
51 if (globalObservablesTag) {
53 return std::unique_ptr<RooArgSet>{
static_cast<RooArgSet *
>(allVars->selectByAttrib(globalObservablesTag,
true))};
98 RooArgSet const *globalObservables,
const char *globalObservablesTag,
99 bool takeGlobalObservablesFromData,
bool removeConstraintsFromPdf)
103 bool doStripDisconnected =
false;
109 if (constrainedParameters) {
110 cPars.
add(*constrainedParameters);
113 doStripDisconnected =
true;
120 auto constraintSetCacheName = std::string(
"CACHE_CONSTR_OF_PDF_") + pdf.
GetName() +
"_FOR_OBS_" + observableNames;
122 if (!cPars.
empty()) {
123 std::unique_ptr<RooArgSet> internalConstraints{
124 pdf.
getAllConstraints(observables, cPars, doStripDisconnected, removeConstraintsFromPdf)};
125 allConstraints.
add(*internalConstraints);
127 if (externalConstraints) {
128 allConstraints.
add(*externalConstraints);
131 if (!allConstraints.
empty()) {
133 oocoutI(&pdf, Minimization) <<
" Including the following constraint terms in minimization: " << allConstraints
137 auto glObs = getGlobalObservables(pdf, globalObservables, globalObservablesTag);
138 if (
data.getGlobalObservables() && takeGlobalObservablesFromData) {
143 <<
"The following global observables have been automatically defined according to the dataset "
144 <<
"which also provides their values: " << *
data.getGlobalObservables() << std::endl;
145 glObs = std::make_unique<RooArgSet>(*
data.getGlobalObservables());
150 data.getGlobalObservables()->selectCommon(*glObs, globalsFromDataset);
151 oocoutI(&pdf, Minimization) <<
"The following global observables have been defined: " << *glObs <<
","
152 <<
" with the values of " << globalsFromDataset
153 <<
" obtained from the dataset and the other values from the model."
158 <<
"The following global observables have been defined and their values are taken from the model: "
159 << *glObs << std::endl;
161 takeGlobalObservablesFromData =
false;
165 <<
"The global observables are not defined , normalize constraints with respect to the parameters "
166 << cPars << std::endl;
167 takeGlobalObservablesFromData =
false;
170 return std::make_unique<RooConstraintSum>(
name.c_str(),
"nllCons", allConstraints, glObs ? *glObs : cPars,
171 takeGlobalObservablesFromData);
std::unique_ptr< RooAbsReal > createConstraintTerm(std::string const &name, RooAbsPdf const &pdf, RooAbsData const &data, RooArgSet const *constrainedParameters, RooArgSet const *externalConstraints, RooArgSet const *globalObservables, const char *globalObservablesTag, bool takeGlobalObservablesFromData, bool removeConstraintsFromPdf)
Create the parameter constraint sum to add to the negative log-likelihood.
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'.
RooFit::OwningPtr< RooArgSet > getVariables(bool stripDisconnected=true) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooAbsData is the common abstract base class for binned and unbinned datasets.
RooArgSet * getAllConstraints(const RooArgSet &observables, RooArgSet &constrainedParams, bool stripDisconnected=true, bool removeConstraintsFromPdf=false) 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.
const char * GetName() const override
Returns name of object.
std::string getColonSeparatedNameString(RooArgSet const &argSet)
Create a string with all sorted names of RooArgSet elements separated by colons.