72 if(TestBit(kOwnData) && fSData)
136 bool includeWeights,
bool cloneData,
const char* newName):
150 if (!dynamic_cast<RooRealVar*>(arg)) {
152 << arg->
GetName() <<
" is not of type RooRealVar " << endl ;
153 throw string(
Form(
"SPlot::SPlot(%s) input argument %s is not of type RooRealVar",
GetName(),arg->
GetName())) ;
162 this->
AddSWeight(pdf, yieldsList, projDeps, includeWeights);
201 std::string varname(sVariable);
254 for (
Int_t i = 0; i < numSWeightVars; i++)
270 std::string varname(sVariable);
344 const RooArgSet &projDeps,
bool includeWeights)
355 std::vector<RooRealVar*> constVarHolder;
363 constVarHolder.push_back(varTemp);
373 std::vector<double> yieldsHolder;
376 yieldsHolder.push_back( ((
RooRealVar*) yieldsTmp.
at(i))->getVal());
399 std::vector<RooRealVar*> yieldvars ;
402 std::vector<Double_t> yieldvalues ;
403 for (
Int_t k = 0; k < nspec; ++k)
412 yieldvars.push_back(yieldinpdf) ;
413 yieldvalues.push_back(thisyield->
getVal()) ;
420 std::vector<std::vector<Double_t> > pdfvalues(numevents,std::vector<Double_t>(nspec,0)) ;
424 for(
Int_t m=0;
m<nspec; ++
m) yieldvars[
m]->setVal(0) ;
435 for (
Int_t ievt = 0; ievt <numevents; ievt++)
447 for(
Int_t k = 0; k < nspec; ++k)
450 if(yieldvars[k]->getMin() > 0)
452 coutW(
InputArguments) <<
"Minimum Range for " << yieldvars[k]->GetName() <<
" must be 0. ";
454 yieldvars[k]->setMin(0);
457 if(yieldvars[k]->getMax() < 1)
459 coutW(
InputArguments) <<
"Maximum Range for " << yieldvars[k]->GetName() <<
" must be 1. ";
461 yieldvars[k]->setMax(1);
465 yieldvars[k]->setVal( 1 ) ;
468 pdfvalues[ievt][k] = f_k ;
469 if( !(f_k>1 || f_k<1) )
470 coutW(
InputArguments) <<
"Strange pdf value: " << ievt <<
" " << k <<
" " << f_k << std::endl ;
471 yieldvars[k]->setVal( 0 ) ;
477 std::vector<Double_t>
norm(nspec,0) ;
478 for (
Int_t ievt = 0; ievt <numevents ; ievt++)
481 for(
Int_t k=0; k<nspec; ++k) dnorm += yieldvalues[k] * pdfvalues[ievt][k] ;
482 for(
Int_t j=0; j<nspec; ++j) norm[j] += pdfvalues[ievt][j]/dnorm ;
492 for (
Int_t i = 0; i < nspec; i++)
for (
Int_t j = 0; j < nspec; j++) covInv(i,j) = 0;
498 for (
Int_t ievt = 0; ievt < numevents; ++ievt)
508 for(
Int_t k = 0; k < nspec; ++k)
509 dsum += pdfvalues[ievt][k] * yieldvalues[k] ;
512 for(
Int_t j=0; j<nspec; ++j)
514 if(includeWeights ==
kTRUE)
515 covInv(
n,j) +=
fSData->
weight()*pdfvalues[ievt][
n]*pdfvalues[ievt][j]/(dsum*dsum) ;
517 covInv(
n,j) += pdfvalues[ievt][
n]*pdfvalues[ievt][j]/(dsum*dsum) ;
529 coutE(
Eval) <<
"SPlot Error: covariance matrix is singular; I can't invert it!" << std::endl;
539 coutI(
Eval) <<
"Checking Likelihood normalization: " << std::endl;
540 coutI(
Eval) <<
"Yield of specie Sum of Row in Matrix Norm" << std::endl;
541 for(
Int_t k=0; k<nspec; ++k)
544 for(
Int_t m=0;
m<nspec; ++
m) covnorm += covInv[k][
m]*yieldvalues[
m] ;
546 for(
Int_t m = 0;
m < nspec; ++
m) sumrow += covMatrix[k][
m] ;
547 coutI(
Eval) << yieldvalues[k] <<
" " << sumrow <<
" " << covnorm << endl ;
552 coutI(
Eval) <<
"Calculating sWeight" << std::endl;
553 std::vector<RooRealVar*> sweightvec ;
554 std::vector<RooRealVar*> pdfvec ;
562 for(
Int_t k=0; k<nspec; ++k)
564 std::string wname = std::string(yieldvars[k]->
GetName()) +
"_sw";
566 sweightvec.push_back( var) ;
567 sweightset.
add(*var) ;
570 wname =
"L_" + std::string(yieldvars[k]->
GetName());
571 var =
new RooRealVar(wname.c_str(),wname.c_str(),0) ;
572 pdfvec.push_back( var) ;
573 sweightset.
add(*var) ;
581 for(
Int_t ievt = 0; ievt < numevents; ++ievt)
588 for(
Int_t k = 0; k < nspec; ++k) dsum += pdfvalues[ievt][k] * yieldvalues[k] ;
593 for(
Int_t j=0; j<nspec; ++j) nsum += covMatrix(
n,j) * pdfvalues[ievt][j] ;
602 else sweightvec[
n]->setVal( nsum/dsum) ;
604 pdfvec[
n]->setVal( pdfvalues[ievt][
n] ) ;
606 if( !(
fabs(nsum/dsum)>=0 ) )
613 sWeightData->
add(sweightset) ;
626 ((
RooRealVar*) yieldsTmp.
at(i))->setVal(yieldsHolder.at(i));
630 for(
Int_t i=0; i < (
Int_t) constVarHolder.size(); i++)
631 constVarHolder.at(i)->setConstant(
kFALSE);
virtual void Clear(Option_t *="")
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
virtual const char * GetName() const
Returns name of object.
TIterator * createIterator(Bool_t dir=kIterForward) const
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
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...
virtual RooAbsArg * addClone(const RooAbsArg &var, Bool_t silent=kFALSE)
Add a clone of the specified argument to list.
RooCmdArg PrintLevel(Int_t code)
Double_t getVal(const RooArgSet *set=0) const
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
RooDataSet * GetSDataSet() const
RooFit::MsgLevel globalKillBelow() const
RooCmdArg PrintEvalErrors(Int_t numErrors)
static RooMsgService & instance()
Return reference to singleton instance.
virtual Double_t Determinant() const
Return the matrix determinant.
RooCmdArg Extended(Bool_t flag=kTRUE)
void attachDataSet(const RooAbsData &set)
Replace server nodes with names matching the dataset variable names with those data set variables...
Iterator abstract base class.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Double_t GetYieldFromSWeight(const char *sVariable) const
Sum the SWeights for a particular specie over all events This should equal the total (weighted) yield...
The TNamed class is the base class for all named ROOT classes.
Double_t GetSWeight(Int_t numEvent, const char *sVariable) const
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
void AddSWeight(RooAbsPdf *pdf, const RooArgList &yieldsTmp, const RooArgSet &projDeps=RooArgSet(), bool includeWeights=kTRUE)
Method which adds the sWeights to the dataset.
virtual Double_t weight() const
Return event weight of current event.
RooRealVar represents a fundamental (non-derived) real valued object.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
RooAbsArg * at(Int_t idx) const
void setConstant(Bool_t value=kTRUE)
char * Form(const char *fmt,...)
RooArgList GetSWeightVars() const
Return a RooArgList containing the SWeights.
RooDataSet is a container class to hold unbinned data.
Int_t GetNumSWeightVars() const
Return the number of SWeights In other words, return the number of species that we are trying to extr...
virtual const RooArgSet * get(Int_t index) const
Return RooArgSet with coordinates of event 'index'.
virtual void add(const RooArgSet &row, Double_t weight=1.0, Double_t weightError=0)
Add a data point, with its coordinates specified in the 'data' argset, to the data set...
RooCmdArg SumW2Error(Bool_t flag)
Namespace for the RooStats classes.
RooAbsArg * find(const char *name) const
Find object with given name in list.
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...
void Print(Option_t *name="") const
Print the matrix as a table of elements.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Bool_t merge(RooDataSet *data1, RooDataSet *data2=0, RooDataSet *data3=0, RooDataSet *data4=0, RooDataSet *data5=0, RooDataSet *data6=0)
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.
RooDataSet * SetSData(RooDataSet *data)
virtual TObject * Next()=0
SPlot()
Default constructor.
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.
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Double_t GetSumOfEventSWeight(Int_t numEvent) const
Sum the SWeights for a particular event.
double norm(double *x, double *p)
This class calculates sWeights used to create an sPlot.
Bool_t isConstant() const
virtual Int_t numEntries() const