Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RooFitResult.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id: RooFitResult.h,v 1.28 2007/05/11 09:11:30 verkerke Exp $
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 #ifndef ROO_FIT_RESULT
17 #define ROO_FIT_RESULT
18 
19 #include "RooAbsArg.h"
20 #include "RooPrintable.h"
21 #include "RooDirItem.h"
22 #include "RooArgList.h"
23 
24 #include "RVersion.h"
25 #include "TMatrixFfwd.h"
26 #include "TMatrixDSym.h"
27 #include "TRootIOCtor.h"
28 
29 #include <vector>
30 #include <string>
31 #include <map>
32 
33 class RooArgSet ;
34 class RooAbsPdf ;
35 class RooPlot;
36 class TObject ;
37 class TH2 ;
38 typedef RooArgSet* pRooArgSet ;
39 
40 class RooFitResult : public TNamed, public RooPrintable, public RooDirItem {
41 public:
42 
43  // Constructors, assignment etc.
44  RooFitResult(const char* name=0, const char* title=0) ;
45  RooFitResult(const RooFitResult& other) ;
46  virtual TObject* Clone(const char* newname = 0) const {
47  RooFitResult* r = new RooFitResult(*this) ;
48  if (newname && *newname) r->SetName(newname) ;
49  return r ;
50  }
51  virtual TObject* clone() const { return new RooFitResult(*this); }
52  virtual ~RooFitResult() ;
53 
54  static RooFitResult* lastMinuitFit(const RooArgList& varList=RooArgList()) ;
55 
56  static RooFitResult *prefitResult(const RooArgList &paramList);
57 
58  // Printing interface (human readable)
59  virtual void printValue(std::ostream& os) const ;
60  virtual void printName(std::ostream& os) const ;
61  virtual void printTitle(std::ostream& os) const ;
62  virtual void printClassName(std::ostream& os) const ;
63  virtual void printArgs(std::ostream& os) const ;
64  void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;
65 
66  inline virtual void Print(Option_t *options= 0) const {
67  // Printing interface
68  printStream(defaultPrintStream(),defaultPrintContents(options),defaultPrintStyle(options));
69  }
70 
71  virtual Int_t defaultPrintContents(Option_t* opt) const ;
72  virtual StyleOption defaultPrintStyle(Option_t* opt) const ;
73 
74  RooAbsPdf* createHessePdf(const RooArgSet& params) const ;
75 
76  // Accessors
77  inline Int_t status() const {
78  // Return MINUIT status code
79  return _status ;
80  }
81 
82  inline UInt_t numStatusHistory() const { return _statusHistory.size() ; }
83  Int_t statusCodeHistory(UInt_t icycle) const ;
84  const char* statusLabelHistory(UInt_t icycle) const ;
85 
86  inline Int_t covQual() const {
87  // Return MINUIT quality code of covariance matrix
88  return _covQual ;
89  }
90  inline Int_t numInvalidNLL() const {
91  // Return number of NLL evaluations with problems
92  return _numBadNLL ;
93  }
94  inline Double_t edm() const {
95  // Return estimated distance to minimum
96  return _edm ;
97  }
98  inline Double_t minNll() const {
99  // Return minimized -log(L) value
100  return _minNLL ;
101  }
102  inline const RooArgList& constPars() const {
103  // Return list of constant parameters
104  return *_constPars ;
105  }
106  inline const RooArgList& floatParsInit() const {
107  // Return list of floating parameters before fit
108  return *_initPars ;
109  }
110  inline const RooArgList& floatParsFinal() const {
111  // Return list of floarting parameters after fit
112  return *_finalPars ;
113  }
114 
115  TH2* correlationHist(const char* name = "correlation_matrix") const ;
116 
117  Double_t correlation(const RooAbsArg& par1, const RooAbsArg& par2) const {
118  // Return correlation between par1 and par2
119  return correlation(par1.GetName(),par2.GetName()) ;
120  }
121  const RooArgList* correlation(const RooAbsArg& par) const {
122  // Return pointer to list of correlations of all parameters with par
123  return correlation(par.GetName()) ;
124  }
125 
126  Double_t correlation(const char* parname1, const char* parname2) const ;
127  const RooArgList* correlation(const char* parname) const ;
128 
129 
130  const TMatrixDSym& covarianceMatrix() const ;
131  const TMatrixDSym& correlationMatrix() const ;
132  TMatrixDSym reducedCovarianceMatrix(const RooArgList& params) const ;
133  TMatrixDSym conditionalCovarianceMatrix(const RooArgList& params) const ;
134 
135 
136  // Global correlation accessors
137  Double_t globalCorr(const RooAbsArg& par) { return globalCorr(par.GetName()) ; }
138  Double_t globalCorr(const char* parname) ;
139  const RooArgList* globalCorr() ;
140 
141 
142  // Add objects to a 2D plot
143  inline RooPlot *plotOn(RooPlot *frame, const RooAbsArg &par1, const RooAbsArg &par2,
144  const char *options= "ME") const {
145  // Plot error ellipse in par1 and par2 on frame
146  return plotOn(frame,par1.GetName(),par2.GetName(),options);
147  }
148  RooPlot *plotOn(RooPlot *plot, const char *parName1, const char *parName2,
149  const char *options= "ME") const;
150 
151  // Generate random perturbations of the final parameters using the covariance matrix
152  const RooArgList& randomizePars() const;
153 
154  Bool_t isIdentical(const RooFitResult& other, Double_t tol=1e-6, Double_t tolCorr=1e-4, Bool_t verbose=kTRUE) const ;
155 
156  void SetName(const char *name) ;
157  void SetNameTitle(const char *name, const char* title) ;
158 
159 protected:
160 
161  friend class RooMinuit ;
162  friend class RooMinimizer ;
163  void setCovarianceMatrix(TMatrixDSym& V) ;
164  void setConstParList(const RooArgList& list) ;
165  void setInitParList(const RooArgList& list) ;
166  void setFinalParList(const RooArgList& list) ;
167  inline void setMinNLL(Double_t val) { _minNLL = val ; }
168  inline void setEDM(Double_t val) { _edm = val ; }
169  inline void setStatus(Int_t val) { _status = val ; }
170  inline void setCovQual(Int_t val) { _covQual = val ; }
171  inline void setNumInvalidNLL(Int_t val) { _numBadNLL=val ; }
172  void fillCorrMatrix() ;
173  void fillCorrMatrix(const std::vector<double>& globalCC, const TMatrixDSym& corrs, const TMatrixDSym& covs) ;
174  void fillLegacyCorrMatrix() const ;
175  void fillPrefitCorrMatrix();
176  void setStatusHistory(std::vector<std::pair<std::string,int> >& hist) { _statusHistory = hist ; }
177 
178  Double_t correlation(Int_t row, Int_t col) const;
179  Double_t covariance(Int_t row, Int_t col) const;
180 
181  Int_t _status ; // MINUIT status code
182  Int_t _covQual ; // MINUIT quality code of covariance matrix
183  Int_t _numBadNLL ; // Number calls with bad (zero,negative) likelihood
184  Double_t _minNLL ; // NLL at minimum
185  Double_t _edm ; // Estimated distance to minimum
186  RooArgList* _constPars ; // List of constant parameters
187  RooArgList* _initPars ; // List of floating parameters with initial values
188  RooArgList* _finalPars ; // List of floating parameters with final values
189 
190  mutable RooArgList* _globalCorr ; //! List of global correlation coefficients
191  mutable TList _corrMatrix ; //! Correlation matrix (list of RooArgLists)
192 
193  mutable RooArgList *_randomPars; //! List of floating parameters with most recent random perturbation applied
194  mutable TMatrixF* _Lt; //! triangular matrix used for generate random perturbations
195 
196  TMatrixDSym* _CM ; // Correlation matrix
197  TMatrixDSym* _VM ; // Covariance matrix
198  TVectorD* _GC ; // Global correlation coefficients
199 
200  std::vector<std::pair<std::string,int> > _statusHistory ; // History of status codes
201 
202  ClassDef(RooFitResult,5) // Container class for fit result
203 };
204 
205 #endif