201 bool useWeights,
bool cloneData,
const char* newName,
213 for (
const auto arg : yieldsList) {
216 << arg->GetName() <<
" is not of type RooRealVar (or RooLinearVar)."
217 <<
"\nRooStats must be able to set it to 0 and to 1 to probe the PDF." << endl ;
218 throw std::invalid_argument(
Form(
"SPlot::SPlot(%s) input argument %s is not of type RooRealVar/RooLinearVar",
GetName(),arg->GetName())) ;
226 this->
AddSWeight(pdf, yieldsList, projDeps, useWeights, arg5, arg6, arg7, arg8);
268 std::string varname(sVariable);
321 for (
Int_t i = 0; i < numSWeightVars; i++)
337 std::string varname(sVariable);
421 const RooArgSet &projDeps,
bool includeWeights,
428 for (
unsigned int i=0; i < constParameters->
size(); ++i) {
430 auto& par = (*constParameters)[i];
431 if (std::any_of(yieldsTmp.
begin(), yieldsTmp.
end(), [&](
const RooAbsArg* yield){ return yield->dependsOn(par); })) {
440 std::vector<RooAbsRealLValue*> constVarHolder;
448 constVarHolder.push_back(varTemp);
457 std::vector<double> yieldsHolder;
482 std::vector<RooAbsRealLValue*> yieldvars ;
486 std::vector<Double_t> yieldvalues ;
487 for (
Int_t k = 0; k < nspec; ++k) {
488 auto thisyield =
static_cast<const RooAbsReal*
>(yields.
at(k)) ;
493 coutI(
InputArguments)<<
"yield in pdf: " << yieldinpdf->GetName() <<
" " << thisyield->getVal() << endl;
495 yieldvars.push_back(yieldinpdf) ;
496 yieldvalues.push_back(thisyield->getVal()) ;
511 if (theVar->getMin() > 0) {
512 coutE(
InputArguments) <<
"Yield variables need to have a range that includes at least [0, 1]. Minimum for "
513 << theVar->GetName() <<
" is " << theVar->getMin() << std::endl;
518 throw std::invalid_argument(std::string(
"Yield variable ") + theVar->GetName() +
" must have a range that includes 0.");
522 if (theVar->getMax() < 1) {
523 coutW(
InputArguments) <<
"Yield variables need to have a range that includes at least [0, 1]. Maximum for "
524 << theVar->GetName() <<
" is " << theVar->getMax() << std::endl;
529 throw std::invalid_argument(std::string(
"Yield variable ") + theVar->GetName() +
" must have a range that includes 1.");
542 std::vector<std::vector<Double_t> > pdfvalues(numevents,std::vector<Double_t>(nspec,0)) ;
544 for (
Int_t ievt = 0; ievt <numevents; ievt++)
550 for(
Int_t k = 0; k < nspec; ++k) {
557 pdfvalues[ievt][k] = f_k ;
558 if( !(f_k>1 || f_k<1) )
559 coutW(
InputArguments) <<
"Strange pdf value: " << ievt <<
" " << k <<
" " << f_k << std::endl ;
560 theVar->setVal( 0 ) ;
566 std::vector<Double_t> norm(nspec,0) ;
567 for (
Int_t ievt = 0; ievt <numevents ; ievt++)
570 for(
Int_t k=0; k<nspec; ++k) dnorm += yieldvalues[k] * pdfvalues[ievt][k] ;
571 for(
Int_t j=0; j<nspec; ++j) norm[j] += pdfvalues[ievt][j]/dnorm ;
581 for (
Int_t i = 0; i < nspec; i++)
for (
Int_t j = 0; j < nspec; j++) covInv(i,j) = 0;
587 for (
Int_t ievt = 0; ievt < numevents; ++ievt)
597 for(
Int_t k = 0; k < nspec; ++k)
598 dsum += pdfvalues[ievt][k] * yieldvalues[k] ;
601 for(
Int_t j=0; j<nspec; ++j)
604 covInv(
n,j) +=
fSData->
weight()*pdfvalues[ievt][
n]*pdfvalues[ievt][j]/(dsum*dsum) ;
606 covInv(
n,j) += pdfvalues[ievt][
n]*pdfvalues[ievt][j]/(dsum*dsum) ;
618 coutE(
Eval) <<
"SPlot Error: covariance matrix is singular; I can't invert it!" << std::endl;
627 coutI(
Eval) <<
"Checking Likelihood normalization: " << std::endl;
628 coutI(
Eval) <<
"Yield of specie Sum of Row in Matrix Norm" << std::endl;
629 for(
Int_t k=0; k<nspec; ++k)
632 for(
Int_t m=0;
m<nspec; ++
m) covnorm += covInv[k][
m]*yieldvalues[
m] ;
634 for(
Int_t m = 0;
m < nspec; ++
m) sumrow += covMatrix[k][
m] ;
635 coutI(
Eval) << yieldvalues[k] <<
" " << sumrow <<
" " << covnorm << endl ;
640 coutI(
Eval) <<
"Calculating sWeight" << std::endl;
641 std::vector<RooRealVar*> sweightvec ;
642 std::vector<RooRealVar*> pdfvec ;
650 for(
Int_t k=0; k<nspec; ++k)
652 std::string wname = std::string(yieldvars[k]->
GetName()) +
"_sw";
654 sweightvec.push_back( var) ;
655 sweightset.
add(*var) ;
658 wname =
"L_" + std::string(yieldvars[k]->
GetName());
659 var =
new RooRealVar(wname.c_str(),wname.c_str(),0) ;
660 pdfvec.push_back( var) ;
661 sweightset.
add(*var) ;
669 for(
Int_t ievt = 0; ievt < numevents; ++ievt)
676 for(
Int_t k = 0; k < nspec; ++k) dsum += pdfvalues[ievt][k] * yieldvalues[k] ;
681 for(
Int_t j=0; j<nspec; ++j) nsum += covMatrix(
n,j) * pdfvalues[ievt][j] ;
689 if(includeWeights) sweightvec[
n]->setVal(
fSData->
weight() * nsum/dsum) ;
690 else sweightvec[
n]->setVal( nsum/dsum) ;
692 pdfvec[
n]->setVal( pdfvalues[ievt][
n] ) ;
694 if( !(
fabs(nsum/dsum)>=0 ) )
701 sWeightData->
add(sweightset) ;
718 for(
Int_t i=0; i < (
Int_t) constVarHolder.size(); i++)
719 constVarHolder.at(i)->setConstant(
kFALSE);
char * Form(const char *fmt,...)
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Bool_t dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=0, Bool_t valueOnly=kFALSE) const
Test whether we depend on (ie, are served by) any object in the specified collection.
void treeNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=0, Bool_t doBranch=kTRUE, Bool_t doLeaf=kTRUE, Bool_t valueOnly=kFALSE, Bool_t recurseNonDerived=kFALSE) const
Fill supplied list with nodes of the arg tree, following all server links, starting with ourself as t...
RooArgSet * getParameters(const RooAbsData *data, Bool_t stripDisconnected=kTRUE) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Bool_t isConstant() const
Check if the "Constant" attribute is set.
void attachDataSet(const RooAbsData &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents.
virtual RooAbsArg * addClone(const RooAbsArg &var, Bool_t silent=kFALSE)
Add a clone of the specified argument to list.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
const_iterator end() const
Double_t getRealValue(const char *name, Double_t defVal=0, Bool_t verbose=kFALSE) const
Get value of a RooAbsReal stored in set with given name.
Storage_t::size_type size() const
const_iterator begin() const
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
RooAbsArg * find(const char *name) const
Find object with given name in list.
virtual Int_t numEntries() const
virtual RooFitResult * fitTo(RooAbsData &data, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Fit PDF to given dataset.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual void setVal(Double_t value)=0
void setConstant(Bool_t value=kTRUE)
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
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.
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
RooDataSet is a container class to hold unbinned data.
virtual TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
virtual const RooArgSet * get(Int_t index) const override
Return RooArgSet with coordinates of event 'index'.
Bool_t merge(RooDataSet *data1, RooDataSet *data2=0, RooDataSet *data3=0, RooDataSet *data4=0, RooDataSet *data5=0, RooDataSet *data6=0)
virtual void add(const RooArgSet &row, Double_t weight=1.0, Double_t weightError=0) override
Add a data point, with its coordinates specified in the 'data' argset, to the data set.
virtual Double_t weight() const override
Return event weight of current event.
static RooMsgService & instance()
Return reference to singleton instance.
Bool_t isActive(const RooAbsArg *self, RooFit::MsgTopic facility, RooFit::MsgLevel level)
Check if logging is active for given object/topic/RooFit::MsgLevel combination.
RooRealVar represents a variable that can be changed from the outside.
A class to calculate "sWeights" used to create an "sPlot".
void AddSWeight(RooAbsPdf *pdf, const RooArgList &yieldsTmp, const RooArgSet &projDeps=RooArgSet(), bool includeWeights=kTRUE, const RooCmdArg &fitToarg5=RooCmdArg::none(), const RooCmdArg &fitToarg6=RooCmdArg::none(), const RooCmdArg &fitToarg7=RooCmdArg::none(), const RooCmdArg &fitToarg8=RooCmdArg::none())
Method which adds the sWeights to the dataset.
Double_t GetYieldFromSWeight(const char *sVariable) const
Sum the SWeights for a particular species over all events.
Double_t GetSWeight(Int_t numEvent, const char *sVariable) const
Retrieve an s weight.
RooArgList GetSWeightVars() const
Return a RooArgList containing all paramters that have s weights.
SPlot()
Default constructor.
Int_t GetNumSWeightVars() const
Return the number of SWeights In other words, return the number of species that we are trying to extr...
RooDataSet * SetSData(RooDataSet *data)
Set dataset (if not passed in constructor).
RooDataSet * GetSDataSet() const
Retrieve s-weighted data.
Double_t GetSumOfEventSWeight(Int_t numEvent) const
Sum the SWeights for a particular event.
void Print(Option_t *name="") const
Print the matrix as a table of elements.
virtual Double_t Determinant() const
Return the matrix determinant.
The TNamed class is the base class for all named ROOT classes.
virtual const char * GetName() const
Returns name of object.
virtual void Clear(Option_t *="")
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
RooCmdArg SumW2Error(Bool_t flag)
RooCmdArg Extended(Bool_t flag=kTRUE)
RooCmdArg PrintEvalErrors(Int_t numErrors)
RooCmdArg PrintLevel(Int_t code)
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
Namespace for the RooStats classes.
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)