Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-31 09:46:30

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooFitResult.h,v 1.28 2007/05/11 09:11:30 verkerke Exp $
0005  * Authors:                                                                  *
0006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
0007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
0008  *                                                                           *
0009  * Copyright (c) 2000-2005, Regents of the University of California          *
0010  *                          and Stanford University. All rights reserved.    *
0011  *                                                                           *
0012  * Redistribution and use in source and binary forms,                        *
0013  * with or without modification, are permitted according to the terms        *
0014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
0015  *****************************************************************************/
0016 #ifndef ROO_FIT_RESULT
0017 #define ROO_FIT_RESULT
0018 
0019 #include "RooAbsArg.h"
0020 #include "RooPrintable.h"
0021 #include "RooDirItem.h"
0022 #include "RooArgList.h"
0023 
0024 #include "RVersion.h"
0025 #include "TMatrixFfwd.h"
0026 #include "TMatrixDSym.h"
0027 #include "TList.h"
0028 
0029 #include <vector>
0030 #include <string>
0031 #include <utility>
0032 
0033 class RooArgSet ;
0034 class RooAbsPdf ;
0035 class RooPlot;
0036 class TH2;
0037 
0038 class RooFitResult : public TNamed, public RooPrintable, public RooDirItem {
0039 public:
0040 
0041   // Constructors, assignment etc.
0042   RooFitResult(const char* name=nullptr, const char* title=nullptr) ;
0043   RooFitResult(const RooFitResult& other) ;
0044   TObject* Clone(const char* newname = nullptr) const override {
0045     RooFitResult* r =  new RooFitResult(*this) ;
0046     if (newname && *newname) r->SetName(newname) ;
0047     return r ;
0048   }
0049   virtual TObject* clone() const { return new RooFitResult(*this); }
0050   ~RooFitResult() override ;
0051 
0052   static RooFitResult *prefitResult(const RooArgList &paramList);
0053 
0054   // Printing interface (human readable)
0055   void printValue(std::ostream& os) const override ;
0056   void printName(std::ostream& os) const override ;
0057   void printTitle(std::ostream& os) const override ;
0058   void printClassName(std::ostream& os) const override ;
0059   void printArgs(std::ostream& os) const override ;
0060   void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent="") const override ;
0061 
0062   inline void Print(Option_t *options= nullptr) const override {
0063     // Printing interface
0064     printStream(defaultPrintStream(),defaultPrintContents(options),defaultPrintStyle(options));
0065   }
0066 
0067   Int_t defaultPrintContents(Option_t* opt) const override ;
0068   StyleOption defaultPrintStyle(Option_t* opt) const override ;
0069 
0070   RooAbsPdf* createHessePdf(const RooArgSet& params) const ;
0071 
0072   // Accessors
0073   /// Return MINUIT status code
0074   inline Int_t status() const {
0075     return _status ;
0076   }
0077 
0078   inline UInt_t numStatusHistory() const { return _statusHistory.size() ; }
0079   Int_t statusCodeHistory(UInt_t icycle) const ;
0080   const char* statusLabelHistory(UInt_t icycle) const ;
0081 
0082   /// Return MINUIT quality code of covariance matrix
0083   inline Int_t covQual() const {
0084     return _covQual ;
0085   }
0086   /// Return number of NLL evaluations with problems.
0087   inline Int_t numInvalidNLL() const {
0088     return _numBadNLL ;
0089   }
0090   /// Return estimated distance to minimum.
0091   inline double edm() const {
0092     return _edm ;
0093   }
0094   /// Return minimized -log(L) value.
0095   inline double minNll() const {
0096     return _minNLL ;
0097   }
0098   /// Return list of constant parameters.
0099   inline const RooArgList& constPars() const {
0100     return *_constPars ;
0101   }
0102   /// Return list of floating parameters before fit.
0103   inline const RooArgList& floatParsInit() const {
0104     return *_initPars ;
0105   }
0106   /// Return list of floating parameters after fit.
0107   inline const RooArgList& floatParsFinal() const {
0108     return *_finalPars ;
0109   }
0110 
0111   TH2* correlationHist(const char* name = "correlation_matrix") const ;
0112 
0113   /// Return correlation between par1 and par2.
0114   double correlation(const RooAbsArg& par1, const RooAbsArg& par2) const {
0115     return correlation(par1.GetName(),par2.GetName()) ;
0116   }
0117   /// Return pointer to list of correlations of all parameters with par.
0118   const RooArgList* correlation(const RooAbsArg& par) const {
0119     return correlation(par.GetName()) ;
0120   }
0121 
0122   double correlation(const char* parname1, const char* parname2) const ;
0123   const RooArgList* correlation(const char* parname) const ;
0124 
0125 
0126   const TMatrixDSym& covarianceMatrix() const ;
0127   const TMatrixDSym& correlationMatrix() const ;
0128   TMatrixDSym reducedCovarianceMatrix(const RooArgList& params) const ;
0129   TMatrixDSym conditionalCovarianceMatrix(const RooArgList& params) const ;
0130 
0131 
0132   // Global correlation accessors
0133   double globalCorr(const RooAbsArg& par) { return globalCorr(par.GetName()) ; }
0134   double globalCorr(const char* parname) ;
0135   const RooArgList* globalCorr() ;
0136 
0137 
0138   /// Add objects to a 2D plot.
0139   /// Plot error ellipse in par1 and par2 on frame.
0140   inline RooPlot *plotOn(RooPlot *frame, const RooAbsArg &par1, const RooAbsArg &par2,
0141           const char *options= "ME") const {
0142     return plotOn(frame,par1.GetName(),par2.GetName(),options);
0143   }
0144   RooPlot *plotOn(RooPlot *plot, const char *parName1, const char *parName2,
0145         const char *options= "ME") const;
0146 
0147   /// Generate random perturbations of the final parameters using the covariance matrix.
0148   const RooArgList& randomizePars() const;
0149 
0150   bool isIdenticalNoCov(const RooFitResult& other, double tol=1e-6, double tolErr=1e-3, bool verbose=true) const ;
0151   bool isIdentical(const RooFitResult& other, double tol=1e-6, double tolCorr=1e-4, bool verbose=true) const ;
0152 
0153   void SetName(const char *name) override ;
0154   void SetNameTitle(const char *name, const char* title) override ;
0155 
0156 
0157 
0158   void setCovarianceMatrix(TMatrixDSym& V) ;
0159   void setConstParList(const RooArgList& list) ;
0160   void setInitParList(const RooArgList& list) ;
0161   void setFinalParList(const RooArgList& list) ;
0162   inline void setMinNLL(double val) { _minNLL = val ; }
0163   inline void setEDM(double val) { _edm = val ; }
0164   inline void setStatus(Int_t val) { _status = val ; }
0165   inline void setCovQual(Int_t val) { _covQual = val ; }
0166   inline void setNumInvalidNLL(Int_t val) { _numBadNLL=val ; }
0167   void setStatusHistory(std::vector<std::pair<std::string,int> >& hist) { _statusHistory = hist ; }
0168   void fillCorrMatrix(const std::vector<double>& globalCC, const TMatrixDSym& corrs, const TMatrixDSym& covs) ;
0169 
0170 protected:
0171 
0172   void fillLegacyCorrMatrix() const ;
0173   void fillPrefitCorrMatrix();
0174   double correlation(Int_t row, Int_t col) const;
0175   double covariance(Int_t row, Int_t col) const;
0176 
0177   Int_t    _status ;          ///< MINUIT status code
0178   Int_t    _covQual ;         ///< MINUIT quality code of covariance matrix
0179   Int_t    _numBadNLL ;       ///< Number calls with bad (zero,negative) likelihood
0180   double _minNLL ;          ///< NLL at minimum
0181   double _edm ;             ///< Estimated distance to minimum
0182   RooArgList* _constPars = nullptr;    ///< List of constant parameters
0183   RooArgList* _initPars = nullptr;     ///< List of floating parameters with initial values
0184   RooArgList* _finalPars = nullptr;    ///< List of floating parameters with final values
0185 
0186   mutable std::unique_ptr<RooArgList> _globalCorr; ///<! List of global correlation coefficients
0187   mutable TList       _corrMatrix ;   ///<! Correlation matrix (list of RooArgLists)
0188 
0189   mutable std::unique_ptr<RooArgList>
0190      _randomPars;                        ///<! List of floating parameters with most recent random perturbation applied
0191   mutable std::unique_ptr<TMatrixF> _Lt; ///<! triangular matrix used for generate random perturbations
0192 
0193   TMatrixDSym* _CM = nullptr;  ///< Correlation matrix
0194   TMatrixDSym* _VM = nullptr;  ///< Covariance matrix
0195   TVectorD* _GC = nullptr;     ///< Global correlation coefficients
0196 
0197   std::vector<std::pair<std::string,int> > _statusHistory ; ///< History of status codes
0198 
0199   ClassDefOverride(RooFitResult,5) // Container class for fit result
0200 };
0201 
0202 #endif