14#if !defined(R__ALPHA) && !defined(R__SOLARIS) && !defined(R__ACC) && !defined(R__FBSD)
31using std::endl, std::vector;
35 template<
class listT,
class stringT>
void getParameterNames(
const listT*
l,std::vector<stringT>& names){
38 for (
auto const *obj : *
l) {
39 names.push_back(obj->GetName());
43 for(
const auto& p:names){
63 double sb2 = sigma_b*sigma_b;
68 double bpsb2 =
b + sb2;
71 double za2 = 2.*( (spb)* std::log( ( spb)*(bpsb2)/(b2+ spb*sb2) ) -
72 (b2/sb2) * std::log(1. + ( sb2 * s)/(
b * bpsb2) ) );
77 double za2 = 2.*( (s+
b) * std::log(1. + s/
b) -s );
78 return std::sqrt(za2);
84 if (
auto prod =
dynamic_cast<RooProdPdf *
>(&pdf)) {
86 for (
int i = 0,
n = list.size(); i <
n; ++i) {
92 auto iter = pdf.
servers().begin();
93 assert(iter != pdf.
servers().end());
97 assert(sim !=
nullptr);
99 for (
int ic = 0, nc = cat->
numBins((
const char *)
nullptr); ic < nc; ++ic) {
103 if (catPdf !=
nullptr)
FactorizePdf(observables, *catPdf, obsTerms, constraints);
109 if (!constraints.
contains(pdf)) constraints.
add(pdf);
117 if (!model.GetObservables() ) {
118 oocoutE(
nullptr,InputArguments) <<
"RooStatsUtils::FactorizePdf - invalid input model: missing observables" << std::endl;
121 return FactorizePdf(*model.GetObservables(), pdf, obsTerms, constraints);
130 if(constraints.
empty()) {
131 oocoutW(
nullptr, Eval) <<
"RooStatsUtils::MakeNuisancePdf - no constraints found on nuisance parameters in the input model" << std::endl;
139 if (!model.GetPdf() || !model.GetObservables() ) {
140 oocoutE(
nullptr, InputArguments) <<
"RooStatsUtils::MakeNuisancePdf - invalid input model: missing pdf and/or observables" << std::endl;
148 if (
auto prod =
dynamic_cast<RooProdPdf *
>(&pdf)) {
152 for (
int i = 0,
n = list.size(); i <
n; ++i) {
155 if(newPdfi !=
nullptr) newList.
add(*newPdfi);
158 if (newList.
empty()) {
161 }
else if (newList.
size() == 1) {
166 TString::Format(
"%s without constraints", prod->GetTitle()).Data(), newList);
171 auto iter = pdf.
servers().begin();
173 auto uPdf =
dynamic_cast<RooAbsPdf *
>(*(iter++));
174 auto extended_term =
dynamic_cast<RooAbsReal *
>(*(iter++));
175 assert(uPdf !=
nullptr);
176 assert(extended_term !=
nullptr);
177 assert(iter == pdf.
servers().end());
180 if(newUPdf ==
nullptr)
return nullptr;
186 assert(sim !=
nullptr);
190 for (
int ic = 0, nc = cat->
numBins((
const char *)
nullptr); ic < nc; ++ic) {
196 if (newPdf ==
nullptr) {
delete cat;
return nullptr; }
197 pdfList.
add(*newPdf);
201 TString::Format(
"%s without constraints", sim->GetTitle()).Data(), pdfList, *cat);
213 if(!unconstrainedPdf) {
214 oocoutE(
nullptr, InputArguments) <<
"RooStats::MakeUnconstrainedPdf - invalid observable list passed (observables not found in original pdf) or invalid pdf passed (without observables)" << std::endl;
218 return unconstrainedPdf;
223 if(!model.GetPdf() || !model.GetObservables()) {
224 oocoutE(
nullptr, InputArguments) <<
"RooStatsUtils::MakeUnconstrainedPdf - invalid input model: missing pdf and/or observables" << std::endl;
237 BranchStore(
const vector<TString> ¶ms = vector<TString>(),
double _inval = -999.) :
fInval(_inval)
239 for (
unsigned int i = 0; i < params.size(); i++)
245 for(std::map<TString, double>::iterator it =
fVarVals.begin();it!=
fVarVals.end();++it) {
254 for(std::map<TString, double>::iterator it =
fVarVals.begin();it!=
fVarVals.end();++it) {
260 for(std::map<TString, double>::iterator it =
fVarVals.begin();it!=
fVarVals.end();++it) {
268 if (data.numEntries() == 0) {
275 V.push_back(rvar->GetName());
276 if (rvar->hasAsymError()) {
280 else if (rvar->hasError()) {
291 for(
int entry = 0;entry<data.numEntries();entry++) {
296 bs->
fVarVals[rvar->GetName()] = rvar->getValV();
297 if (rvar->hasAsymError()) {
301 else if (rvar->hasError()) {
322 for (std::size_t i = 0; i<
l.size(); ++i) {
338 bool copySnapshots,
const char *mcname,
339 const char *newmcname,
bool copyData) {
343 for (
auto it : objects) {
349 throw std::runtime_error(
"unable to retrieve ModelConfig");
354 std::vector<TString> poilist;
355 std::vector<TString> nplist;
356 std::vector<TString> obslist;
357 std::vector<TString> globobslist;
397 ::getArgs(newWS, poilist, poiset);
399 ::getArgs(newWS, nplist, npset);
401 ::getArgs(newWS, obslist, obsset);
403 ::getArgs(newWS, globobslist, globobsset);
ROOT::RRangeCast< T, true, Range_t > dynamic_range_cast(Range_t &&coll)
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
#define NamespaceImp(name)
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
virtual TObject * clone(const char *newname=nullptr) const =0
void SetName(const char *name) override
Set the name of the TNamed.
const RefCountList_t & servers() const
List of all servers of this object.
Abstract base class for objects that represent a discrete value that can be set from the outside,...
Int_t numBins(const char *rangeName=nullptr) const override
Return the number of fit bins ( = number of types ).
void setBin(Int_t ibin, const char *rangeName=nullptr) override
Set category to i-th fit bin, which is the i-th registered state.
virtual const char * getCurrentLabel() const
Return label string of current state.
bool contains(const char *name) const
Check if collection contains an argument with a specific name.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
Abstract interface for all probability density functions.
Abstract base class for objects that represent a real value and implements functionality common to al...
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Container class to hold unbinned data.
RooExtendPdf is a wrapper around an existing PDF that adds a parameteric extended likelihood term to ...
Efficient implementation of a product of PDFs of the form.
Variable that can be changed from the outside.
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
std::map< TString, double > fVarVals
void AssignToTTree(TTree &myTree)
BranchStore(const vector< TString > ¶ms=vector< TString >(), double _inval=-999.)
< A class that holds configuration information for a model using a workspace as a store
void SetParametersOfInterest(const RooArgSet &set)
Specify parameters of interest.
const RooArgSet * GetGlobalObservables() const
get RooArgSet for global observables (return nullptr if not existing)
void SetObservables(const RooArgSet &set)
Specify the observables.
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return nullptr if not existing)
void SetPdf(const RooAbsPdf &pdf)
Set the Pdf, add to the workspace if not already there.
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return nullptr if not existing)
const RooArgSet * GetObservables() const
get RooArgSet for observables (return nullptr if not existing)
RooAbsPdf * GetPdf() const
get model PDF (return nullptr if pdf has not been specified or does not exist)
void SetNuisanceParameters(const RooArgSet &set)
Specify the nuisance parameters (parameters that are not POI).
void SetGlobalObservables(const RooArgSet &set)
Specify the global observables.
Persistable container for RooFit projects.
TObject * obj(RooStringView name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name).
RooAbsPdf * pdf(RooStringView name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
bool saveSnapshot(RooStringView, const char *paramNames)
Save snapshot of values and attributes (including "Constant") of given parameters.
std::list< RooAbsData * > allData() const
Return list of all dataset in the workspace.
RooLinkedList const & getSnapshots() const
std::list< TObject * > allGenericObjects() const
Return list of all generic objects in the workspace.
RooRealVar * var(RooStringView name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
static void autoImportClassCode(bool flag)
If flag is true, source code of classes not the ROOT distribution is automatically imported if on obj...
bool import(const RooAbsArg &arg, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}, const RooCmdArg &arg9={})
Import a RooAbsArg object, e.g.
A TTree is a list of TBranches.
virtual void ResetAddress()
Reset the address of the branch.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
A TTree represents a columnar dataset.
virtual Int_t Fill()
Fill all branches.
TBranch * Branch(const char *name, T *obj, Int_t bufsize=32000, Int_t splitlevel=99)
Add a new branch, and infer the data type from the type of obj being passed.
RooCmdArg RecycleConflictNodes(bool flag=true)
Namespace for the RooStats classes.
TTree * GetAsTTree(TString name, TString desc, const RooDataSet &data)
Create a TTree with the given name and description. All RooRealVars in the RooDataSet are represented...
void FillTree(TTree &myTree, const RooDataSet &data)
BranchStore * CreateBranchStore(const RooDataSet &data)
RooAbsPdf * StripConstraints(RooAbsPdf &pdf, const RooArgSet &observables)
RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name)
extract constraint terms from pdf
void FactorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints)
RooStatsConfig & GetGlobalRooStatsConfig()
Retrieve the config object which can be used to set flags for things like offsetting the likelihood o...
double AsimovSignificance(double s, double b, double sigma_b=0.0)
Compute the Asimov Median significance for a Poisson process with s = expected number of signal event...
RooAbsPdf * MakeUnconstrainedPdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name=nullptr)
remove constraints from pdf and return the unconstrained pdf
RooWorkspace * MakeReducedWorkspace(RooWorkspace *oldWS, const char *newName, bool copySnapshots, const char *mcname, const char *newmcname, bool copyData=true)
function that clones a workspace, copying all needed components and discarding all others
void PrintListContent(const RooArgList &l, std::ostream &os=std::cout)
useful function to print in one line the content of a set with their values