52 _set1(
"set1",
"First set of components",this),
53 _takeGlobalObservablesFromData{takeGlobalObservablesFromData}
55 for (
const auto comp : constraintSet) {
57 coutE(InputArguments) <<
"RooConstraintSum::ctor(" <<
GetName() <<
") ERROR: component " << comp->GetName()
58 <<
" is not of type RooAbsPdf" << std::endl ;
73 _set1(
"set1",this,other._set1),
74 _paramSet(other._paramSet),
75 _takeGlobalObservablesFromData{other._takeGlobalObservablesFromData}
87 for (
const auto comp :
_set1) {
100 for (
const auto comp :
_set1) {
101 sum -= std::log(dataMap.
at(comp)[0]);
109 return std::make_unique<RooArgSet>(
_paramSet);
128std::unique_ptr<RooArgSet> getGlobalObservables(
129 RooAbsPdf const& pdf,
RooArgSet const* globalObservables,
const char* globalObservablesTag)
132 if(globalObservables && globalObservablesTag) {
134 std::string errMsg =
"RooAbsPdf::fitTo: GlobalObservables and GlobalObservablesTag options mutually exclusive!";
135 oocoutE(&pdf, Minimization) << errMsg << std::endl;
136 throw std::invalid_argument(errMsg);
138 if(globalObservables) {
140 return std::make_unique<RooArgSet>(*globalObservables);
143 if(globalObservablesTag) {
144 oocoutI(&pdf, Minimization) <<
"User-defined specification of global observables definition with tag named '"
145 << globalObservablesTag <<
"'" << std::endl;
150 if(
auto defaultGlobalObservablesTag = pdf.
getStringAttribute(
"DefaultGlobalObservablesTag")) {
151 oocoutI(&pdf, Minimization) <<
"p.d.f. provides built-in specification of global observables definition "
152 <<
"with tag named '" << defaultGlobalObservablesTag <<
"'" << std::endl;
153 globalObservablesTag = defaultGlobalObservablesTag;
157 if(globalObservablesTag) {
158 std::unique_ptr<RooArgSet> allVars{pdf.
getVariables()} ;
159 return std::unique_ptr<RooArgSet>{
static_cast<RooArgSet*
>(allVars->selectByAttrib(globalObservablesTag,
true))};
167RooArgSet const* tryToGetConstraintSetFromWorkspace(
169 if(!workspace)
return nullptr;
171 if(workspace->
set(constraintSetCacheName.c_str())) {
173 const RooArgSet *constr = workspace->
set(constraintSetCacheName.c_str());
175 <<
"createConstraintTerm picked up cached constraints from workspace with " << constr->
size()
176 <<
" entries" << std::endl;
220 std::string
const&
name,
226 const char* globalObservablesTag,
227 bool takeGlobalObservablesFromData,
232 bool doStripDisconnected = false ;
238 if(constrainedParameters) {
239 cPars.
add(*constrainedParameters);
242 doStripDisconnected =
true;
249 auto constraintSetCacheName = std::string(
"CACHE_CONSTR_OF_PDF_") + pdf.
GetName() +
"_FOR_OBS_" + observableNames;
251 if (
RooArgSet const* constr = tryToGetConstraintSetFromWorkspace(pdf, workspace, constraintSetCacheName)) {
252 allConstraints.
add(*constr);
255 if (!cPars.
empty()) {
256 std::unique_ptr<RooArgSet> internalConstraints{pdf.
getAllConstraints(observables, cPars, doStripDisconnected)};
257 allConstraints.
add(*internalConstraints);
259 if (externalConstraints) {
260 allConstraints.
add(*externalConstraints);
266 <<
"createConstraintTerm: caching constraint set under name "
267 << constraintSetCacheName <<
" with " << allConstraints.
size() <<
" entries" << std::endl;
272 if (!allConstraints.
empty()) {
274 oocoutI(&pdf, Minimization) <<
" Including the following constraint terms in minimization: "
275 << allConstraints << std::endl ;
278 auto glObs = getGlobalObservables(pdf, globalObservables, globalObservablesTag);
284 <<
"The following global observables have been automatically defined according to the dataset "
293 <<
"The following global observables have been defined: " << *glObs
294 <<
"," <<
" with the values of " << globalsFromDataset
295 <<
" obtained from the dataset and the other values from the model." << std::endl;
299 <<
"The following global observables have been defined and their values are taken from the model: "
300 << *glObs << std::endl;
302 takeGlobalObservablesFromData =
false;
306 <<
"The global observables are not defined , normalize constraints with respect to the parameters " << cPars
308 takeGlobalObservablesFromData =
false;
314 RooConstraintSum constraintTerm{
name.c_str(),
"nllCons", allConstraints, glObs ? *glObs : cPars,
315 takeGlobalObservablesFromData};
316 std::unique_ptr<RooAbsReal> constraintTermClone{
static_cast<RooAbsReal *
>(constraintTerm.cloneTree())};
323 constraintTerm.getParameters(
nullptr, allOriginalParams);
324 constraintTermClone->recursiveRedirectServers(allOriginalParams);
333 return constraintTermClone;
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
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)
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...
Bool_t recursiveRedirectServers(const RooAbsCollection &newServerList, Bool_t mustReplaceAll=kFALSE, Bool_t nameChange=kFALSE, Bool_t recurseInNewSet=kTRUE)
Recursively replace all servers with the new servers in newSet.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Storage_t::size_type size() const
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
RooArgSet const * getGlobalObservables() const
Returns snapshot of global observables stored in this data.
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....
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooConstraintSum calculates the sum of the -(log) likelihoods of a set of RooAbsPfs that represent co...
Double_t evaluate() const override
Return sum of -log of constraint p.d.f.s.
bool setData(RooAbsData const &data, bool cloneData=true)
Replace the variables in this RooConstraintSum with the global observables in the dataset if they mat...
RooListProxy _set1
Set of constraint terms.
void computeBatch(cudaStream_t *, double *output, size_t size, RooFit::Detail::DataMap const &) const override
Base function for computing multiple values of a RooAbsReal.
static 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, RooWorkspace *workspace)
Create the parameter constraint sum to add to the negative log-likelihood.
RooArgSet _paramSet
Set of parameters to which constraints apply.
std::unique_ptr< RooArgSet > fillNormSetForServer(RooArgSet const &normSet, RooAbsArg const &server) const override
Fills a RooArgSet to be used as the normalization set for a server, given a normalization set for thi...
const bool _takeGlobalObservablesFromData
If the global observable values are taken from data.
auto & at(RooAbsArg const *arg, RooAbsArg const *=nullptr)
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Reimplementation of standard RooArgList::add()
The RooWorkspace is a persistable container for RooFit projects.
Bool_t defineSetInternal(const char *name, const RooArgSet &aset)
const RooArgSet * set(const char *name)
Return pointer to previously defined named set with given nmame If no such set is found a null pointe...
virtual const char * GetName() const
Returns name of object.
std::string getColonSeparatedNameString(RooArgSet const &argSet)
Create a string with all sorted names of RooArgSet elements separated by colons.
static uint64_t sum(uint64_t i)
static void output(int code)