40using std::string, std::list, std::map, std::vector;
48 _x(
"x",
"Observables",this,true,false),
49 _mu(
"mu",
"Offset vector",this,true,false),
51 _covI{cov.GetNrows()},
54 if(!cov.IsSymmetric()) {
55 std::stringstream errorMsg;
56 errorMsg <<
"RooMultiVarGaussian::RooMultiVarGaussian(" <<
GetName()
57 <<
") input covariance matrix is not symmetric!";
58 coutE(InputArguments) << errorMsg.str() << std::endl;
59 throw std::invalid_argument(errorMsg.str().c_str());
81 _x(
"x",
"Observables", this, true, false),
82 _mu(
"mu",
"Offset vector", this, true, false),
83 _cov(reduceToConditional ? fr.conditionalCovarianceMatrix(xvec) : fr.reducedCovarianceMatrix(xvec)),
85 _det(_cov.Determinant()),
90 list<string> munames ;
92 for (std::size_t i=0 ; i<fpf.size() ; i++) {
93 if (xvec.
find(fpf.at(i)->GetName())) {
94 std::unique_ptr<RooRealVar> parclone{
static_cast<RooRealVar*
>(fpf.at(i)->Clone(
Form(
"%s_centralvalue",fpf.at(i)->GetName())))};
97 munames.push_back(fpf.at(i)->GetName()) ;
102 for (list<string>::iterator iter=munames.begin() ; iter!=munames.end() ; ++iter) {
117 for (
int i = 0; i < mu.
GetNrows(); i++) {
126 for (std::size_t i = 0; i <
n; i++) {
155 RooAbsPdf(other,
name), _aicMap(other._aicMap), _x(
"x",this,other._x), _mu(
"mu",this,other._mu),
156 _cov(other._cov), _covI(other._covI), _det(other._det), _z(other._z)
167 for (std::size_t i=0 ; i<
_mu.
size() ; i++) {
179 for (std::size_t i=0 ; i<
_x.
size() ; i++) {
187 double alpha = x_min_mu * (
_covI * x_min_mu) ;
188 return exp(-0.5*alpha) ;
198 for (std::size_t i=0 ; i<
_x.
size() ; i++) {
206 if (allVars.
size()==
_x.
size() && !rangeName) {
207 analVars.add(allVars) ;
216 coutW(Integration) <<
"RooMultiVarGaussian::getAnalyticalIntegral(" <<
GetName() <<
") WARNING: p.d.f. has " <<
_x.
size()
217 <<
" observables, analytical integration is only implemented for the first 127 observables" << std::endl ;
224 bool anyBits(
false) ;
226 for (std::size_t i=0 ; i<
_x.
size() ; i++) {
233 cxcoutD(Integration) <<
"RooMultiVarGaussian::getAnalyticalIntegral(" <<
GetName()
234 <<
") Advertising analytical integral over " << xi->
GetName() <<
" as range is >" <<
_z <<
" sigma" << std::endl ;
239 cxcoutD(Integration) <<
"RooMultiVarGaussian::getAnalyticalIntegral(" <<
GetName() <<
") Range of " << xi->
GetName() <<
" is <"
240 <<
_z <<
" sigma, relying on numeric integral" << std::endl ;
249 cxcoutD(Integration) <<
"RooMultiVarGaussian::getAnalyticalIntegral(" <<
GetName()
250 <<
") Advertising analytical integral over " << pi->
GetName() <<
" as range is >" <<
_z <<
" sigma" << std::endl ;
255 cxcoutD(Integration) <<
"RooMultiVarGaussian::getAnalyticalIntegral(" <<
GetName() <<
") Range of " << pi->
GetName() <<
" is <"
256 <<
_z <<
" sigma, relying on numeric integral" << std::endl ;
290 return pow(2*3.14159268,
_x.
size()/2.)*sqrt(std::abs(
_det)) ;
301 for (
UInt_t i=0 ; i<aid.pmap.size() ; i++) {
306 double ret = pow(2*3.14159268,aid.nint/2.)/sqrt(std::abs(aid.S22det))*exp(-0.5*u*(aid.S22bar*u)) ;
317 map<int,AnaIntData>::iterator iter =
_anaIntCache.find(code) ;
319 return iter->second ;
354 TMatrixD S22bar = S11 - S12*S22inv*S21 ;
358 cacheData.S22bar.ResizeTo(S22bar) ;
359 cacheData.S22bar=S22bar ;
361 cacheData.pmap = map1 ;
362 cacheData.nint = map2.size() ;
374 if (directVars.size()==
_x.
size()) {
375 generateVars.add(directVars) ;
382 coutW(Integration) <<
"RooMultiVarGaussian::getGenerator(" <<
GetName() <<
") WARNING: p.d.f. has " <<
_x.
size()
383 <<
" observables, partial internal generation is only implemented for the first 127 observables" << std::endl ;
390 for (std::size_t i=0 ; i<
_x.
size() ; i++) {
395 generateVars.add(*arg) ;
436 Int_t nobs = TU.GetNcols() ;
437 vector<int>& omap = gd.omap ;
443 for(
Int_t k= 0; k <nobs; k++) {
463 for (
UInt_t i=0 ; i<gd.pmap.size() ; i++) {
466 mubar += gd.S12S22I * (
x2 - gd.mu2) ;
474 for (
int i=0 ; i<nobs ; i++) {
502 map<int,GenData>::iterator iter =
_genCache.find(code) ;
504 return iter->second ;
519 cacheData.UT.ResizeTo(TU) ;
521 cacheData.omap.resize(
_x.
size()) ;
522 for (std::size_t i=0 ; i<
_x.
size() ; i++) {
523 cacheData.omap[i] = i ;
526 cacheData.mu1.ResizeTo(
_muVec) ;
551 TMatrixD S22bar = S11 - S12 * (S22Inv * S21) ;
563 for (
UInt_t i=0 ; i<map1.size() ; i++) {
564 mu1(i) =
_muVec(map1[i]) ;
566 for (
UInt_t i=0 ; i<map2.size() ; i++) {
567 mu2(i) =
_muVec(map2[i]) ;
576 cacheData.omap = map1 ;
577 cacheData.pmap = map2 ;
579 cacheData.mu2.ResizeTo(mu2) ;
580 cacheData.mu1 = mu1 ;
581 cacheData.mu2 = mu2 ;
582 cacheData.S12S22I.
ResizeTo(S12S22Inv) ;
583 cacheData.S12S22I = S12S22Inv ;
601 std::cout <<
"RooMultiVarGaussian::decodeCode(" <<
GetName() <<
") ERROR don't have bit pattern for code " << code << std::endl ;
602 throw string(
"RooMultiVarGaussian::decodeCode() ERROR don't have bit pattern for code") ;
608 for (std::size_t i=0 ; i<
_x.
size() ; i++) {
625 S11.ResizeTo(map1.size(),map1.size()) ;
626 S12.ResizeTo(map1.size(),map2.size()) ;
627 S21.ResizeTo(map2.size(),map1.size()) ;
628 S22.ResizeTo(map2.size(),map2.size()) ;
630 for (
UInt_t i=0 ; i<map1.size() ; i++) {
631 for (
UInt_t j=0 ; j<map1.size() ; j++)
632 S11(i,j) =
input(map1[i],map1[j]) ;
633 for (
UInt_t j=0 ; j<map2.size() ; j++)
634 S12(i,j) =
input(map1[i],map2[j]) ;
636 for (
UInt_t i=0 ; i<map2.size() ; i++) {
637 for (
UInt_t j=0 ; j<map1.size() ; j++)
638 S21(i,j) =
input(map2[i],map1[j]) ;
639 for (
UInt_t j=0 ; j<map2.size() ; j++)
640 S22(i,j) =
input(map2[i],map2[j]) ;
648 if (ibit<32) {
b0 |= (1<<ibit) ; return ; }
649 if (ibit<64) {
b1 |= (1<<(ibit-32)) ; return ; }
650 if (ibit<96) {
b2 |= (1<<(ibit-64)) ; return ; }
651 if (ibit<128) {
b3 |= (1<<(ibit-96)) ; return ; }
656 if (ibit<32)
return (b0 & (1<<ibit)) ;
657 if (ibit<64)
return (b1 & (1<<(ibit-32))) ;
658 if (ibit<96)
return (b2 & (1<<(ibit-64))) ;
659 if (ibit<128)
return (b3 & (1<<(ibit-96))) ;
665 if (lhs.b0 != rhs.b0)
667 if (lhs.b1 != rhs.b1)
669 if (lhs.b2 != rhs.b2)
671 if (lhs.b3 != rhs.b3)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char x2
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
bool contains(const char *name) const
Check if collection contains an argument with a specific name.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract interface for all probability density functions.
void setConstant(bool value=true)
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
Abstract base class for objects that represent a real value and implements functionality common to al...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
bool operator==(double value) const
Equality operator comparing to a double.
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.
bool addOwned(RooAbsArg &var, bool silent=false) override
Overloaded RooCollection_t::addOwned() method insert object into owning set and registers object as s...
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
const RooArgList & floatParsFinal() const
Return list of floating parameters after fit.
Multivariate Gaussian p.d.f.
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Handle full integral here.
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const override
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
void decodeCode(Int_t code, std::vector< int > &map1, std::vector< int > &map2) const
Decode analytical integration/generation code into index map of integrated/generated (map2) and non-i...
std::vector< BitBlock > _aicMap
!
static void blockDecompose(const TMatrixD &input, const std::vector< int > &map1, const std::vector< int > &map2, TMatrixDSym &S11, TMatrixD &S12, TMatrixD &S21, TMatrixDSym &S22)
Block decomposition of covI according to given maps of observables.
AnaIntData & anaIntData(Int_t code) const
Check if cache entry was previously created.
double evaluate() const override
Represent observables as vector.
std::map< int, GenData > _genCache
!
TVectorD _muVec
! Do not persist
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, bool staticInitOK=true) const override
Special case: generate all observables.
void initGenerator(Int_t code) override
Clear the GenData cache as its content is not invariant under changes in the mu vector.
GenData & genData(Int_t code) const
WVE – CHECK THAT GENDATA IS VALID GIVEN CURRENT VALUES OF _MU.
std::map< int, AnaIntData > _anaIntCache
!
void generateEvent(Int_t code) override
Retrieve generator config from cache.
static double gaussian(TRandom *generator=randomGenerator())
Return a Gaussian random variable with mean 0 and variance 1.
Variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
Cholesky Decomposition class.
virtual TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t nr_nonzeros=-1)=0
TMatrixTSym< Element > & SetSub(Int_t row_lwb, const TMatrixTBase< Element > &source)
Insert matrix source starting at [row_lwb][row_lwb], thereby overwriting the part [row_lwb....
Double_t Determinant() const override
TMatrixTSym< Element > & Invert(Double_t *det=nullptr)
Invert the matrix and calculate its determinant Notice that the LU decomposition is used instead of B...
Double_t Determinant() const override
Return the matrix determinant.
TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1) override
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
const char * GetName() const override
Returns name of object.
TVectorT< Element > & ResizeTo(Int_t lwb, Int_t upb)
Resize the vector to [lwb:upb] .
RooConstVar & RooConst(double val)