Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 09:12:18

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 TObject ;
0037 class TH2 ;
0038 typedef RooArgSet* pRooArgSet ;
0039 
0040 class RooFitResult : public TNamed, public RooPrintable, public RooDirItem {
0041 public:
0042 
0043   // Constructors, assignment etc.
0044   RooFitResult(const char* name=nullptr, const char* title=nullptr) ;
0045   RooFitResult(const RooFitResult& other) ;
0046   TObject* Clone(const char* newname = nullptr) const override {
0047     RooFitResult* r =  new RooFitResult(*this) ;
0048     if (newname && *newname) r->SetName(newname) ;
0049     return r ;
0050   }
0051   virtual TObject* clone() const { return new RooFitResult(*this); }
0052   ~RooFitResult() override ;
0053 
0054   static RooFitResult *prefitResult(const RooArgList &paramList);
0055 
0056   // Printing interface (human readable)
0057   void printValue(std::ostream& os) const override ;
0058   void printName(std::ostream& os) const override ;
0059   void printTitle(std::ostream& os) const override ;
0060   void printClassName(std::ostream& os) const override ;
0061   void printArgs(std::ostream& os) const override ;
0062   void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent="") const override ;
0063 
0064   inline void Print(Option_t *options= nullptr) const override {
0065     // Printing interface
0066     printStream(defaultPrintStream(),defaultPrintContents(options),defaultPrintStyle(options));
0067   }
0068 
0069   Int_t defaultPrintContents(Option_t* opt) const override ;
0070   StyleOption defaultPrintStyle(Option_t* opt) const override ;
0071 
0072   RooAbsPdf* createHessePdf(const RooArgSet& params) const ;
0073 
0074   // Accessors
0075   /// Return MINUIT status code
0076   inline Int_t status() const {
0077     return _status ;
0078   }
0079 
0080   inline UInt_t numStatusHistory() const { return _statusHistory.size() ; }
0081   Int_t statusCodeHistory(UInt_t icycle) const ;
0082   const char* statusLabelHistory(UInt_t icycle) const ;
0083 
0084   /// Return MINUIT quality code of covariance matrix
0085   inline Int_t covQual() const {
0086     return _covQual ;
0087   }
0088   /// Return number of NLL evaluations with problems.
0089   inline Int_t numInvalidNLL() const {
0090     return _numBadNLL ;
0091   }
0092   /// Return estimated distance to minimum.
0093   inline double edm() const {
0094     return _edm ;
0095   }
0096   /// Return minimized -log(L) value.
0097   inline double minNll() const {
0098     return _minNLL ;
0099   }
0100   /// Return list of constant parameters.
0101   inline const RooArgList& constPars() const {
0102     return *_constPars ;
0103   }
0104   /// Return list of floating parameters before fit.
0105   inline const RooArgList& floatParsInit() const {
0106     return *_initPars ;
0107   }
0108   /// Return list of floating parameters after fit.
0109   inline const RooArgList& floatParsFinal() const {
0110     return *_finalPars ;
0111   }
0112 
0113   TH2* correlationHist(const char* name = "correlation_matrix") const ;
0114 
0115   /// Return correlation between par1 and par2.
0116   double correlation(const RooAbsArg& par1, const RooAbsArg& par2) const {
0117     return correlation(par1.GetName(),par2.GetName()) ;
0118   }
0119   /// Return pointer to list of correlations of all parameters with par.
0120   const RooArgList* correlation(const RooAbsArg& par) const {
0121     return correlation(par.GetName()) ;
0122   }
0123 
0124   double correlation(const char* parname1, const char* parname2) const ;
0125   const RooArgList* correlation(const char* parname) const ;
0126 
0127 
0128   const TMatrixDSym& covarianceMatrix() const ;
0129   const TMatrixDSym& correlationMatrix() const ;
0130   TMatrixDSym reducedCovarianceMatrix(const RooArgList& params) const ;
0131   TMatrixDSym conditionalCovarianceMatrix(const RooArgList& params) const ;
0132 
0133 
0134   // Global correlation accessors
0135   double globalCorr(const RooAbsArg& par) { return globalCorr(par.GetName()) ; }
0136   double globalCorr(const char* parname) ;
0137   const RooArgList* globalCorr() ;
0138 
0139 
0140   /// Add objects to a 2D plot.
0141   /// Plot error ellipse in par1 and par2 on frame.
0142   inline RooPlot *plotOn(RooPlot *frame, const RooAbsArg &par1, const RooAbsArg &par2,
0143           const char *options= "ME") const {
0144     return plotOn(frame,par1.GetName(),par2.GetName(),options);
0145   }
0146   RooPlot *plotOn(RooPlot *plot, const char *parName1, const char *parName2,
0147         const char *options= "ME") const;
0148 
0149   /// Generate random perturbations of the final parameters using the covariance matrix.
0150   const RooArgList& randomizePars() const;
0151 
0152   bool isIdenticalNoCov(const RooFitResult& other, double tol=1e-6, double tolErr=1e-3, bool verbose=true) const ;
0153   bool isIdentical(const RooFitResult& other, double tol=1e-6, double tolCorr=1e-4, bool verbose=true) const ;
0154 
0155   void SetName(const char *name) override ;
0156   void SetNameTitle(const char *name, const char* title) override ;
0157 
0158 
0159 
0160   void setCovarianceMatrix(TMatrixDSym& V) ;
0161   void setConstParList(const RooArgList& list) ;
0162   void setInitParList(const RooArgList& list) ;
0163   void setFinalParList(const RooArgList& list) ;
0164   inline void setMinNLL(double val) { _minNLL = val ; }
0165   inline void setEDM(double val) { _edm = val ; }
0166   inline void setStatus(Int_t val) { _status = val ; }
0167   inline void setCovQual(Int_t val) { _covQual = val ; }
0168   inline void setNumInvalidNLL(Int_t val) { _numBadNLL=val ; }
0169   void setStatusHistory(std::vector<std::pair<std::string,int> >& hist) { _statusHistory = hist ; }
0170   void fillCorrMatrix(const std::vector<double>& globalCC, const TMatrixDSym& corrs, const TMatrixDSym& covs) ;
0171 
0172 protected:
0173 
0174   void fillLegacyCorrMatrix() const ;
0175   void fillPrefitCorrMatrix();
0176   double correlation(Int_t row, Int_t col) const;
0177   double covariance(Int_t row, Int_t col) const;
0178 
0179   Int_t    _status ;          ///< MINUIT status code
0180   Int_t    _covQual ;         ///< MINUIT quality code of covariance matrix
0181   Int_t    _numBadNLL ;       ///< Number calls with bad (zero,negative) likelihood
0182   double _minNLL ;          ///< NLL at minimum
0183   double _edm ;             ///< Estimated distance to minimum
0184   RooArgList* _constPars = nullptr;    ///< List of constant parameters
0185   RooArgList* _initPars = nullptr;     ///< List of floating parameters with initial values
0186   RooArgList* _finalPars = nullptr;    ///< List of floating parameters with final values
0187 
0188   mutable RooArgList* _globalCorr = nullptr;   ///<! List of global correlation coefficients
0189   mutable TList       _corrMatrix ;   ///<! Correlation matrix (list of RooArgLists)
0190 
0191   mutable RooArgList *_randomPars = nullptr; ///<! List of floating parameters with most recent random perturbation applied
0192   mutable TMatrixF* _Lt = nullptr;           ///<! triangular matrix used for generate random perturbations
0193 
0194   TMatrixDSym* _CM = nullptr;  ///< Correlation matrix
0195   TMatrixDSym* _VM = nullptr;  ///< Covariance matrix
0196   TVectorD* _GC = nullptr;     ///< Global correlation coefficients
0197 
0198   std::vector<std::pair<std::string,int> > _statusHistory ; ///< History of status codes
0199 
0200   ClassDefOverride(RooFitResult,5) // Container class for fit result
0201 };
0202 
0203 #endif