56using std::ostream, std::string, std::pair, std::vector, std::setw;
90 _randomPars = std::make_unique<RooArgList>();
91 other._randomPars->snapshot(*_randomPars);
94 _Lt = std::make_unique<TMatrix>(*other.
_Lt);
133 rrv->deleteSharedProperties() ;
150 rrv->deleteSharedProperties() ;
168 rrv->deleteSharedProperties() ;
180 coutE(InputArguments) <<
"RooFitResult::statusCodeHistory(" <<
GetName()
181 <<
" ERROR request for status history slot "
182 << icycle <<
" exceeds history count of " <<
_statusHistory.size() << std::endl ;
194 coutE(InputArguments) <<
"RooFitResult::statusLabelHistory(" <<
GetName()
195 <<
" ERROR request for status history slot "
196 << icycle <<
" exceeds history count of " <<
_statusHistory.size() << std::endl ;
229 const char *options)
const
233 if(
nullptr == par1) {
234 coutE(InputArguments) <<
"RooFitResult::correlationPlot: parameter not floated in fit: " << parName1 << std::endl;
238 if(
nullptr == par2) {
239 coutE(InputArguments) <<
"RooFitResult::correlationPlot: parameter not floated in fit: " << parName2 << std::endl;
248 double x1= par1->
getVal();
249 double x2= par2->
getVal();
278 box->SetFillStyle(0);
286 line->SetLineWidth(2) ;
299 line->SetLineWidth(2) ;
337 for (
Int_t iPar = 0; iPar < nPar; iPar++) {
340 for (
Int_t k = 0; k < iPar; k++) {
341 double tmp = L(k, iPar);
342 L(iPar, iPar) -= tmp * tmp;
344 L(iPar, iPar) = sqrt(L(iPar, iPar));
346 for (
Int_t jPar = iPar + 1; jPar < nPar; jPar++) {
348 for (
Int_t k = 0; k < iPar; k++) {
349 L(iPar, jPar) -= L(k, iPar) * L(k, jPar);
351 L(iPar, jPar) /= L(iPar, iPar);
369 par->setVal(par->getVal() +
g(index++));
384 coutE(InputArguments) <<
"RooFitResult::correlation(" <<
GetName() <<
") parameter " << parname1 <<
" is not a floating fit parameter" << std::endl ;
388 coutE(InputArguments) <<
"RooFitResult::correlation(" <<
GetName() <<
") parameter " << parname2 <<
" is not a floating fit parameter" << std::endl ;
408 coutE(InputArguments) <<
"RooFitResult::correlation: variable " << parname <<
" not a floating parameter in fit" << std::endl ;
427 coutE(InputArguments) <<
"RooFitResult::globalCorr: variable " << parname <<
" not a floating parameter in fit" << std::endl ;
459 return (*
_CM)(row,col) ;
468 return (*
_VM)(row,col) ;
482 <<
indent <<
" RooFitResult: minimized FCN value: " <<
_minNLL <<
", estimated distance to minimum: " <<
_edm << std::endl
483 <<
indent <<
" covariance matrix quality: " ;
485 case -1 : os <<
"Unknown, matrix was externally provided" ;
break ;
486 case 0 : os <<
"Not calculated at all" ;
break ;
487 case 1 : os <<
"Approximation only, not accurate" ;
break ;
488 case 2 : os <<
"Full matrix, but forced positive-definite" ;
break ;
489 case 3 : os <<
"Full, accurate covariance matrix" ;
break ;
492 os <<
indent <<
" Status : " ;
494 os << iter->first <<
"=" << iter->second <<
" " ;
496 os << std::endl << std::endl;
500 os <<
indent <<
" Constant Parameter Value " << std::endl
501 <<
indent <<
" -------------------- ------------" << std::endl ;
503 for (std::size_t i=0 ; i<
_constPars->size() ; i++) {
504 os <<
indent <<
" " << setw(20) <<
_constPars->at(i)->GetName() <<
" " << setw(12);
517 bool doAsymErr(
false) ;
518 for (std::size_t i=0 ; i<
_finalPars->size() ; i++) {
526 os <<
indent <<
" Floating Parameter InitialValue FinalValue (+HiError,-LoError) GblCorr." << std::endl
527 <<
indent <<
" -------------------- ------------ ---------------------------------- --------" << std::endl ;
529 os <<
indent <<
" Floating Parameter InitialValue FinalValue +/- Error GblCorr." << std::endl
530 <<
indent <<
" -------------------- ------------ -------------------------- --------" << std::endl ;
533 for (std::size_t i=0 ; i<
_finalPars->size() ; i++) {
543 os << (doAsymErr?
" ":
"") <<
" +/- " << setw(9) <<
Form(
"%9.2e",
err) ;
556 os <<
indent <<
" Floating Parameter FinalValue +/- Error " << std::endl
557 <<
indent <<
" -------------------- --------------------------" << std::endl ;
559 for (std::size_t i=0 ; i<
_finalPars->size() ; i++) {
563 <<
" +/- " << setw(9) <<
Form(
"%9.2e",
err)
580 coutI(Minimization) <<
"RooFitResult::fillCorrMatrix: number of floating parameters is zero, correlation matrix not filled" << std::endl ;
585 coutE(Minimization) <<
"RooFitResult::fillCorrMatrix: ERROR: list of initial parameters must be filled first" << std::endl ;
598 for(
int i=0 ; i<
_CM->GetNcols() ; i++) {
599 (*_GC)[i] = globalCC[i] ;
619 _globalCorr = std::make_unique<RooArgList>(
"globalCorrelations");
623 std::string argName = arg->GetName();
624 std::string argTitle = arg->GetTitle();
625 std::string gcName =
"GC[" + argName +
"]";
626 std::string gcTitle = argTitle +
" Global Correlation";
627 _globalCorr->addOwned(std::make_unique<RooRealVar>(gcName.c_str(), gcTitle.c_str(), 0.));
634 std::string arg2Name = arg2->GetName();
635 std::string cName =
"C[" + argName +
"," + arg2Name +
"]";
636 std::string cTitle =
"Correlation between " + argName +
" and " + arg2Name;
637 corrMatrixRow->
addOwned(std::make_unique<RooRealVar>(cName.c_str(), cTitle.c_str(), 0.));
643 for (
unsigned int i = 0; i < static_cast<unsigned int>(
_corrMatrix.GetSize()) ; ++i) {
646 auto& gcVal =
static_cast<RooRealVar&
>((*_globalCorr)[i]);
651 for (
unsigned int it = 0; it < corrMatrixCol.size() ; ++it) {
652 auto& cVal =
static_cast<RooRealVar&
>(corrMatrixCol[it]);
653 double value = (*_CM)(i,it) ;
655 (*_CM)(i,it) = value;
679 for (std::size_t ii = 0; ii <
_finalPars->size(); ii++) {
689void isIdenticalErrMsg(std::string
const& msgHead,
const RooAbsReal* tv,
const RooAbsReal* ov,
bool verbose) {
691 std::cout <<
"RooFitResult::isIdentical: " << msgHead <<
" " << tv->
GetName() <<
" differs in value:\t"
696void isErrorIdenticalErrMsg(std::string
const& msgHead,
const RooRealVar* tv,
const RooRealVar* ov,
bool verbose) {
698 std::cout <<
"RooFitResult::isIdentical: " << msgHead <<
" " << tv->
GetName() <<
" differs in error:\t"
716 auto deviation = [](
const double left,
const double right,
double tolerance){
717 return right != 0. ? std::abs((left - right)/right) >= tolerance : std::abs(left) >= tolerance;
720 auto compare = [&](
RooArgList const& pars,
RooArgList const& otherpars, std::string
const& prefix,
bool isVerbose) {
728 if(verbose) std::cout <<
"RooFitResult::isIdentical: cannot find " << prefix <<
" " << tv->
GetName() <<
" in reference" << std::endl ;
734 isIdenticalErrMsg(prefix, tv, ov, isVerbose);
739 auto * rtv =
dynamic_cast<RooRealVar const*
>(tv);
740 auto * rov =
dynamic_cast<RooRealVar const*
>(ov);
742 if (ov && deviation(rtv->getError(), rov->getError(), tolErr)) {
743 isErrorIdenticalErrMsg(prefix, rtv, rov, isVerbose);
753 if(verbose) std::cout <<
"RooFitResult::isIdentical: minimized value of -log(L) is different " <<
_minNLL <<
" vs. " << other.
_minNLL << std::endl;
779 auto deviationCorr = [tolCorr](
const double left,
const double right){
780 return std::abs(left - right) >= tolCorr;
789 for (std::size_t i=0 ; i<
_globalCorr->size() ; i++) {
793 if(verbose) std::cout <<
"RooFitResult::isIdentical: cannot find global correlation coefficient " << tv->
GetName() <<
" in reference" << std::endl ;
797 isIdenticalErrMsg(
"global correlation coefficient", tv, ov, verbose);
805 for (std::size_t i=0 ; i<row->size() ; i++) {
806 auto tv =
static_cast<const RooAbsReal*
>(row->at(i));
809 if(verbose) std::cout <<
"RooFitResult::isIdentical: cannot find correlation coefficient " << tv->
GetName() <<
" in reference" << std::endl ;
813 isIdenticalErrMsg(
"correlation coefficient", tv, ov, verbose);
833 oocoutE(
nullptr, InputArguments) <<
"RooFitResult::lastMinuitFit: ERROR: variable '" << arg->GetName()
834 <<
"' is not of type RooRealVar" << std::endl;
847 if (arg->isConstant()) {
855 r->setInitParList(floatPars);
856 r->setFinalParList(floatPars);
861 r->fillPrefitCorrMatrix();
884 for (
Int_t i=0 ; i<
_CM->GetNrows() ; i++) {
885 for (
Int_t j=0 ; j<
_CM->GetNcols() ; j++) {
887 (*_CM)(i,j) = (*
_CM)(i,j) / sqrt((*
_CM)(i,i)*(*
_CM)(j,j)) ;
891 for (
Int_t i=0 ; i<
_CM->GetNrows() ; i++) {
909 for (
Int_t i = 0 ; i<
n ; i++) {
910 for (
Int_t j = 0 ; j<
n; j++) {
911 hh->
Fill(i+0.5,
n-j-0.5,(*
_CM)(i,j)) ;
952 coutW(InputArguments) <<
"RooFitResult::reducedCovarianceMatrix(" <<
GetName() <<
") WARNING input variable "
953 << arg->GetName() <<
" was not a floating parameters in fit result and is ignored" << std::endl ;
959 vector<int> indexMap(params2.
size());
960 for (std::size_t i=0 ; i<params2.
size() ; i++) {
962 assert(indexMap[i] < V.GetNrows());
966 for (
int i = 0; i < Vred.
GetNrows(); ++i) {
967 for (
int j = 0; j < Vred.
GetNcols(); ++j) {
968 Vred(i,j) = V( indexMap[i], indexMap[j]);
992 if (V.GetNcols()==
int(params.
size())) {
996 double det = V.Determinant() ;
999 coutE(Eval) <<
"RooFitResult::conditionalCovarianceMatrix(" <<
GetName() <<
") ERROR: covariance matrix is not positive definite (|V|="
1000 << det <<
") cannot reduce it" << std::endl ;
1001 throw string(
"RooFitResult::conditionalCovarianceMatrix() ERROR, input covariance matrix is not positive definite") ;
1010 coutW(InputArguments) <<
"RooFitResult::conditionalCovarianceMatrix(" <<
GetName() <<
") WARNING input variable "
1011 << arg->GetName() <<
" was not a floating parameters in fit result and is ignored" << std::endl ;
1018 if (params2.
find(arg->GetName())) {
1026 for (std::size_t i=0 ; i<
_finalPars->size() ; i++) {
1047 TMatrixD S22bar = S11 - S12 * (S22Inv * S21) ;
1051 for (
int i=0 ; i<Vred.GetNcols() ; i++) {
1052 for (
int j=i ; j<Vred.GetNcols() ; j++) {
1053 Vred(i,j) = (S22bar(i,j) + S22bar(j,i))/2 ;
1054 Vred(j,i) = Vred(i,j) ;
1080 double det = V.Determinant() ;
1083 coutE(Eval) <<
"RooFitResult::createHessePdf(" <<
GetName() <<
") ERROR: covariance matrix is not positive definite (|V|="
1084 << det <<
") cannot construct p.d.f" << std::endl ;
1094 coutW(InputArguments) <<
"RooFitResult::createHessePdf(" <<
GetName() <<
") WARNING input variable "
1095 << arg->GetName() <<
" was not a floating parameters in fit result and is ignored" << std::endl ;
1102 if (params2.
find(arg->GetName())) {
1112 for (std::size_t i=0 ; i<
_finalPars->size() ; i++) {
1133 for (std::size_t i=0 ; i<
_finalPars->size() ; i++) {
1151 for (
UInt_t i=0 ; i<map1.size() ; i++) {
1154 mu1.
add(*parclone) ;
1162 TMatrixD S22bar = S11 - S12 * (S22Inv * S21) ;
1166 for (
int i=0 ; i<Vred.GetNcols() ; i++) {
1167 for (
int j=i ; j<Vred.GetNcols() ; j++) {
1168 Vred(i,j) = (S22bar(i,j) + S22bar(j,i))/2 ;
1169 Vred(j,i) = Vred(i,j) ;
1177 ret->addOwnedComponents(mu1) ;
1188 if (
_dir)
_dir->GetList()->Remove(
this);
1190 if (
_dir)
_dir->GetList()->Add(
this);
1199 if (
_dir)
_dir->GetList()->Remove(
this);
1201 if (
_dir)
_dir->GetList()->Add(
this);
1265 if (!opt || strlen(opt)==0) {
1310 for (
unsigned int i = 0; i < (
unsigned int)
_CM->GetNcols() ; ++i) {
1313 auto& gcVal =
static_cast<RooRealVar&
>((*_globalCorr)[i]);
1314 (*_GC)(i) = gcVal.
getVal() ;
1318 for (
unsigned int it = 0; it < (
unsigned int)
_CM->GetNcols() ; ++it) {
1319 auto& cVal =
static_cast<RooRealVar&
>(corrMatrixCol[it]);
1320 double value = cVal.
getVal() ;
1321 (*_CM)(it,i) = value ;
1322 (*_CM)(i,it) = value;
1324 (*_VM)(i,it) = (*
_VM)(it,i) ;
ROOT::RRangeCast< T, true, Range_t > dynamic_range_cast(Range_t &&coll)
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
int Int_t
Signed integer 4 bytes (int).
short Version_t
Class version identifier (short).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
const char Option_t
Option string (const char).
static void indent(ostringstream &buf, int indent_level)
TMatrixTSym< Double_t > TMatrixDSym
TMatrixT< Double_t > TMatrixD
TMatrixT< Float_t > TMatrix
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
TVectorT< Double_t > TVectorD
TVectorT< Float_t > TVector
Common abstract base class for objects that represent a value and a "shape" in RooFit.
static void ioStreamerPass2Finalize()
Method called by workspace container to finalize schema evolution issues that cannot be handled in a ...
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
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)
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.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
virtual void Streamer(TBuffer &)
void removeFromDir(TObject *obj)
Remove object from directory it was added to.
TDirectory * _dir
! Associated directory
Two-dimensional ellipse that can be used to represent an error contour.
TMatrixDSym conditionalCovarianceMatrix(const RooArgList ¶ms) const
Return a reduced covariance matrix, which is calculated as.
double correlation(const RooAbsArg &par1, const RooAbsArg &par2) const
Return correlation between par1 and par2.
std::unique_ptr< RooArgList > _randomPars
! List of floating parameters with most recent random perturbation applied
~RooFitResult() override
Destructor.
TList _corrMatrix
! Correlation matrix (list of RooArgLists)
std::vector< std::pair< std::string, int > > _statusHistory
History of status codes.
const TMatrixDSym & covarianceMatrix() const
Return covariance matrix.
TMatrixDSym * _CM
Correlation matrix.
bool isIdentical(const RooFitResult &other, double tol=1e-6, double tolCorr=1e-4, bool verbose=true) const
Return true if this fit result is identical to other within tolerances.
void setConstParList(const RooArgList &list)
Fill the list of constant parameters.
Int_t statusCodeHistory(UInt_t icycle) const
void fillCorrMatrix(const std::vector< double > &globalCC, const TMatrixDSym &corrs, const TMatrixDSym &covs)
Function called by RooMinimizer.
double _minNLL
NLL at minimum.
Int_t _numBadNLL
Number calls with bad (zero,negative) likelihood.
TMatrixDSym * _VM
Covariance matrix.
void SetNameTitle(const char *name, const char *title) override
Change name and title of RooFitResult object.
Int_t defaultPrintContents(Option_t *opt) const override
Configure default contents to be printed.
void printClassName(std::ostream &os) const override
Print class name of fit result.
RooArgList * _initPars
List of floating parameters with initial values.
TClass * IsA() const override
RooFitResult(const char *name=nullptr, const char *title=nullptr)
Constructor with name and title.
TMatrixDSym reducedCovarianceMatrix(const RooArgList ¶ms) const
Return a reduced covariance matrix (Note that Vred is a simple sub-matrix of V, row/columns are order...
Int_t _covQual
MINUIT quality code of covariance matrix.
void fillPrefitCorrMatrix()
RooArgList * _constPars
List of constant parameters.
const RooArgList & randomizePars() const
Generate random perturbations of the final parameters using the covariance matrix.
std::unique_ptr< TMatrixF > _Lt
! triangular matrix used for generate random perturbations
const RooArgList * globalCorr()
Return the list of all global correlations.
static RooFitResult * prefitResult(const RooArgList ¶mList)
Import the results of the last fit performed by gMinuit, interpreting the fit parameters as the given...
void setCovarianceMatrix(TMatrixDSym &V)
Store externally provided correlation matrix in this RooFitResult ;.
RooArgList * _finalPars
List of floating parameters with final values.
const RooArgList & constPars() const
Return list of constant parameters.
Int_t _status
MINUIT status code.
bool isIdenticalNoCov(const RooFitResult &other, double tol=1e-6, double tolErr=1e-3, bool verbose=true) const
Return true if this fit result is identical to other within tolerances, ignoring the correlation matr...
void SetName(const char *name) override
Change name of RooFitResult object.
std::unique_ptr< RooArgList > _globalCorr
! List of global correlation coefficients
const char * statusLabelHistory(UInt_t icycle) const
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
void printValue(std::ostream &os) const override
Print the value of the fit result, i.e.g the status, minimized FCN, edm and covariance quality code.
void printTitle(std::ostream &os) const override
Print title of fit result.
double globalCorr(const RooAbsArg &par)
TH2 * correlationHist(const char *name="correlation_matrix") const
Return TH2D of correlation matrix.
void fillLegacyCorrMatrix() const
Sanity check.
void setInitParList(const RooArgList &list)
Fill the list of initial values of the floating parameters.
RooPlot * plotOn(RooPlot *frame, const RooAbsArg &par1, const RooAbsArg &par2, const char *options="ME") const
Add objects to a 2D plot.
void Streamer(TBuffer &) override
Stream an object of class RooFitResult.
StyleOption defaultPrintStyle(Option_t *opt) const override
Configure mapping of Print() arguments to RooPrintable print styles.
double covariance(Int_t row, Int_t col) const
Return the covariance matrix element addressed with numeric indices.
const RooArgList & floatParsFinal() const
Return list of floating parameters after fit.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Print fit result to stream 'os'.
TVectorD * _GC
Global correlation coefficients.
RooAbsPdf * createHessePdf(const RooArgSet ¶ms) const
Return a p.d.f that represents the fit result as a multi-variate probability densisty function on the...
double _edm
Estimated distance to minimum.
void setFinalParList(const RooArgList &list)
Fill the list of final values of the floating parameters.
void printArgs(std::ostream &os) const override
Print arguments of fit result, i.e. the parameters of the fit.
void printName(std::ostream &os) const override
Print name of fit result.
const TMatrixDSym & correlationMatrix() const
Return correlation matrix ;.
Multivariate Gaussian p.d.f.
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.
Plot frame and a container for graphics objects within that frame.
void addObject(TObject *obj, Option_t *drawOptions="", bool invisible=false)
Add a generic object to this plot.
void addPlotable(RooPlotable *plotable, Option_t *drawOptions="", bool invisible=false, bool refreshNorm=false)
Add the specified plotable object to our plot.
virtual StyleOption defaultPrintStyle(Option_t *opt) const
virtual void Streamer(TBuffer &)
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'.
bool hasAsymError(bool allowZero=true) const
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Buffer base class used for serializing objects.
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual void SetMaximum(Double_t maximum=-1111)
virtual void SetMinimum(Double_t minimum=-1111)
2-D histogram with a double per channel (see TH1 documentation)
Service class for 2-D histogram classes.
Int_t Fill(Double_t) override
Invalid Fill method.
Use the TLine constructor to create a simple line.
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Int_t GetNoElements() const
const char * GetName() const override
Returns name of object.
void Streamer(TBuffer &) override
Stream an object of class TObject.
const char * GetTitle() const override
Returns title of object.
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
virtual const char * ClassName() const
Returns name of class to which the object belongs.
void ToUpper()
Change string to upper case.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)