Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooFitResult.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
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
17//////////////////////////////////////////////////////////////////////////////
18/// \class RooFitResult
19/// RooFitResult is a container class to hold the input and output
20/// of a PDF fit to a dataset. It contains:
21///
22/// * Values of all constant parameters
23/// * Initial and final values of floating parameters with error
24/// * Correlation matrix and global correlation coefficients
25/// * NLL and EDM at minimum
26///
27/// No references to the fitted PDF and dataset are stored
28///
29
30#include <iostream>
31#include <iomanip>
32
33#include "TBuffer.h"
34#include "TMath.h"
35#include "TMarker.h"
36#include "TLine.h"
37#include "TBox.h"
38#include "TGaxis.h"
39#include "TMatrix.h"
40#include "TVector.h"
41#include "TDirectory.h"
42#include "TClass.h"
43#include "RooFitResult.h"
44#include "RooArgSet.h"
45#include "RooArgList.h"
46#include "RooRealVar.h"
47#include "RooPlot.h"
48#include "RooEllipse.h"
49#include "RooRandom.h"
50#include "RooMsgService.h"
51#include "TH2D.h"
52#include "TMatrixDSym.h"
53#include "RooMultiVarGaussian.h"
54
55
56using std::ostream, std::string, std::pair, std::vector, std::setw;
57
58
59
60
61////////////////////////////////////////////////////////////////////////////////
62/// Constructor with name and title
63
64RooFitResult::RooFitResult(const char *name, const char *title) : TNamed(name, title) {}
65
66////////////////////////////////////////////////////////////////////////////////
67/// Copy constructor
68
70 : TNamed(other),
73 _status(other._status),
74 _covQual(other._covQual),
75 _numBadNLL(other._numBadNLL),
76 _minNLL(other._minNLL),
77 _edm(other._edm),
78 _constPars(new RooArgList),
79 _initPars(new RooArgList),
80 _finalPars(new RooArgList),
81 _statusHistory(other._statusHistory)
82{
83
84 other._constPars->snapshot(*_constPars);
85
86 other._initPars->snapshot(*_initPars);
87
88 other._finalPars->snapshot(*_finalPars);
89 if (other._randomPars) {
90 _randomPars = std::make_unique<RooArgList>();
91 other._randomPars->snapshot(*_randomPars);
92 }
93 if (other._Lt)
94 _Lt = std::make_unique<TMatrix>(*other._Lt);
95 if (other._VM) _VM = new TMatrixDSym(*other._VM) ;
96 if (other._CM) _CM = new TMatrixDSym(*other._CM) ;
97 if (other._GC)
98 _GC = new TVectorD(*other._GC);
99}
100
101
102
103////////////////////////////////////////////////////////////////////////////////
104/// Destructor
105
107{
108 if (_constPars) delete _constPars ;
109 if (_initPars) delete _initPars ;
110 if (_finalPars)
111 delete _finalPars;
112 if (_CM) delete _CM ;
113 if (_VM) delete _VM ;
114 if (_GC) delete _GC ;
115
118
119 removeFromDir(this) ;
120}
121
122
123////////////////////////////////////////////////////////////////////////////////
124/// Fill the list of constant parameters
125
127{
128 if (_constPars) delete _constPars ;
130 list.snapshot(*_constPars);
132 if (rrv) {
133 rrv->deleteSharedProperties() ;
134 }
135 }
136}
137
138
139
140////////////////////////////////////////////////////////////////////////////////
141/// Fill the list of initial values of the floating parameters
142
144{
145 if (_initPars) delete _initPars ;
146 _initPars = new RooArgList;
147 list.snapshot(*_initPars);
149 if (rrv) {
150 rrv->deleteSharedProperties() ;
151 }
152 }
153}
154
155
156
157////////////////////////////////////////////////////////////////////////////////
158/// Fill the list of final values of the floating parameters
159
161{
162 if (_finalPars) delete _finalPars ;
164 list.snapshot(*_finalPars);
165
167 if (rrv) {
168 rrv->deleteSharedProperties() ;
169 }
170 }
171}
172
173
174
175////////////////////////////////////////////////////////////////////////////////
176
178{
179 if (icycle>=_statusHistory.size()) {
180 coutE(InputArguments) << "RooFitResult::statusCodeHistory(" << GetName()
181 << " ERROR request for status history slot "
182 << icycle << " exceeds history count of " << _statusHistory.size() << std::endl ;
183 }
184 return _statusHistory[icycle].second ;
185}
186
187
188
189////////////////////////////////////////////////////////////////////////////////
190
192{
193 if (icycle>=_statusHistory.size()) {
194 coutE(InputArguments) << "RooFitResult::statusLabelHistory(" << GetName()
195 << " ERROR request for status history slot "
196 << icycle << " exceeds history count of " << _statusHistory.size() << std::endl ;
197 }
198 return _statusHistory[icycle].first.c_str() ;
199}
200
201
202
203////////////////////////////////////////////////////////////////////////////////
204/// Add objects to a 2D plot that represent the fit results for the
205/// two named parameters. The input frame with the objects added is
206/// returned, or zero in case of an error. Which objects are added
207/// are determined by the options string which should be a concatenation
208/// of the following (not case sensitive):
209///
210/// * M - a marker at the best fit result
211/// * E - an error ellipse calculated at 39%CL using the error matrix at the minimum
212/// * 1 - the 1-sigma error bar for parameter 1
213/// * 2 - the 1-sigma error bar for parameter 2
214/// * B - the bounding box for the error ellipse
215/// * H - a line and horizontal axis for reading off the correlation coefficient
216/// * V - a line and vertical axis for reading off the correlation coefficient
217/// * A - draw axes for reading off the correlation coefficients with the H or V options
218///
219/// You can change the attributes of objects in the returned RooPlot using the
220/// various `RooPlot::getAttXxx(name)` member functions, e.g.
221/// ```
222/// plot->getAttLine("contour")->SetLineStyle(kDashed);
223/// ```
224/// Use `plot->Print()` for a list of all objects and their names (unfortunately most
225/// of the ROOT builtin graphics objects like TLine are unnamed). Drag the left mouse
226/// button along the labels of either axis button to interactively zoom in a plot.
227
228RooPlot *RooFitResult::plotOn(RooPlot *frame, const char *parName1, const char *parName2,
229 const char *options) const
230{
231 // lookup the input parameters by name: we require that they were floated in our fit
232 const RooRealVar *par1= dynamic_cast<const RooRealVar*>(floatParsFinal().find(parName1));
233 if(nullptr == par1) {
234 coutE(InputArguments) << "RooFitResult::correlationPlot: parameter not floated in fit: " << parName1 << std::endl;
235 return nullptr;
236 }
237 const RooRealVar *par2= dynamic_cast<const RooRealVar*>(floatParsFinal().find(parName2));
238 if(nullptr == par2) {
239 coutE(InputArguments) << "RooFitResult::correlationPlot: parameter not floated in fit: " << parName2 << std::endl;
240 return nullptr;
241 }
242
243 // options are not case sensitive
244 TString opt(options);
245 opt.ToUpper();
246
247 // lookup the 2x2 covariance matrix elements for these variables
248 double x1= par1->getVal();
249 double x2= par2->getVal();
250 double s1= par1->getError();
251 double s2= par2->getError();
252 double rho= correlation(parName1, parName2);
253
254 // add a 39%CL error ellipse, if requested
255 if(opt.Contains("E")) {
256 RooEllipse *contour= new RooEllipse("contour",x1,x2,s1,s2,rho,100,1);
257 contour->SetLineWidth(2) ;
258 frame->addPlotable(contour);
259 }
260
261 // add the error bar for parameter 1, if requested
262 if(opt.Contains("1")) {
263 TLine *hline= new TLine(x1-s1,x2,x1+s1,x2);
264 hline->SetLineColor(kRed);
265 frame->addObject(hline);
266 }
267
268 if(opt.Contains("2")) {
269 TLine *vline= new TLine(x1,x2-s2,x1,x2+s2);
270 vline->SetLineColor(kRed);
271 frame->addObject(vline);
272 }
273
274 if(opt.Contains("B")) {
275 TBox *box= new TBox(x1-s1,x2-s2,x1+s1,x2+s2);
276 box->SetLineStyle(kDashed);
277 box->SetLineColor(kRed);
278 box->SetFillStyle(0);
279 frame->addObject(box);
280 }
281
282 if(opt.Contains("H")) {
283 TLine *line= new TLine(x1-rho*s1,x2-s2,x1+rho*s1,x2+s2);
286 line->SetLineWidth(2) ;
287 frame->addObject(line);
288 if(opt.Contains("A")) {
289 TGaxis *axis= new TGaxis(x1-s1,x2-s2,x1+s1,x2-s2,-1.,+1.,502,"-=");
290 axis->SetLineColor(kBlue);
291 frame->addObject(axis);
292 }
293 }
294
295 if(opt.Contains("V")) {
296 TLine *line= new TLine(x1-s1,x2-rho*s2,x1+s1,x2+rho*s2);
299 line->SetLineWidth(2) ;
300 frame->addObject(line);
301 if(opt.Contains("A")) {
302 TGaxis *axis= new TGaxis(x1-s1,x2-s2,x1-s1,x2+s2,-1.,+1.,502,"-=");
303 axis->SetLineColor(kBlue);
304 frame->addObject(axis);
305 }
306 }
307
308 // add a marker at the fitted value, if requested
309 if(opt.Contains("M")) {
310 TMarker *marker= new TMarker(x1,x2,20);
311 marker->SetMarkerColor(kBlack);
312 frame->addObject(marker);
313 }
314
315 return frame;
316}
317
318
319////////////////////////////////////////////////////////////////////////////////
320/// Return a list of floating parameter values that are perturbed from the final
321/// fit values by random amounts sampled from the covariance matrix. The returned
322/// object is overwritten with each call and belongs to the RooFitResult. Uses
323/// the "square root method" to decompose the covariance matrix, which makes inverting
324/// it unnecessary.
325
327{
328 Int_t nPar= _finalPars->size();
329 if (!_randomPars) { // first-time initialization
330 assert(nullptr != _finalPars);
331 // create the list of random values to fill
332 _randomPars = std::make_unique<RooArgList>();
334 // calculate the elements of the upper-triangular matrix L that gives Lt*L = C
335 // where Lt is the transpose of L (the "square-root method")
336 TMatrix L(nPar, nPar);
337 for (Int_t iPar = 0; iPar < nPar; iPar++) {
338 // calculate the diagonal term first
339 L(iPar, iPar) = covariance(iPar, iPar);
340 for (Int_t k = 0; k < iPar; k++) {
341 double tmp = L(k, iPar);
342 L(iPar, iPar) -= tmp * tmp;
343 }
344 L(iPar, iPar) = sqrt(L(iPar, iPar));
345 // then the off-diagonal terms
346 for (Int_t jPar = iPar + 1; jPar < nPar; jPar++) {
347 L(iPar, jPar) = covariance(iPar, jPar);
348 for (Int_t k = 0; k < iPar; k++) {
349 L(iPar, jPar) -= L(k, iPar) * L(k, jPar);
350 }
351 L(iPar, jPar) /= L(iPar, iPar);
352 }
353 }
354 // remember Lt
355 _Lt = std::make_unique<TMatrix>(TMatrix::kTransposed, L);
356 } else {
357 // reset to the final fit values
358 _randomPars->assign(*_finalPars);
359 }
360
361 // create a vector of unit Gaussian variables
362 TVector g(nPar);
363 for(Int_t k= 0; k < nPar; k++) g(k)= RooRandom::gaussian();
364 // multiply this vector by Lt to introduce the appropriate correlations
365 g*= (*_Lt);
366 // add the mean value offsets and store the results
367 Int_t index(0);
368 for(auto * par : static_range_cast<RooRealVar*>(*_randomPars)) {
369 par->setVal(par->getVal() + g(index++));
370 }
371
372 return *_randomPars;
373}
374
375
376////////////////////////////////////////////////////////////////////////////////
377/// Return the correlation between parameters 'par1' and 'par2'
378
379double RooFitResult::correlation(const char* parname1, const char* parname2) const
380{
383 if (idx1<0) {
384 coutE(InputArguments) << "RooFitResult::correlation(" << GetName() << ") parameter " << parname1 << " is not a floating fit parameter" << std::endl ;
385 return 0 ;
386 }
387 if (idx2<0) {
388 coutE(InputArguments) << "RooFitResult::correlation(" << GetName() << ") parameter " << parname2 << " is not a floating fit parameter" << std::endl ;
389 return 0 ;
390 }
391 return correlation(idx1,idx2) ;
392}
393
394
395
396////////////////////////////////////////////////////////////////////////////////
397/// Return the set of correlation coefficients of parameter 'par' with
398/// all other floating parameters
399
401{
402 if (_globalCorr==nullptr) {
404 }
405
407 if (!arg) {
408 coutE(InputArguments) << "RooFitResult::correlation: variable " << parname << " not a floating parameter in fit" << std::endl ;
409 return nullptr ;
410 }
411 return static_cast<RooArgList*>(_corrMatrix.At(_initPars->index(arg))) ;
412}
413
414
415
416////////////////////////////////////////////////////////////////////////////////
417/// Return the global correlation of the named parameter
418
420{
421 if (_globalCorr==nullptr) {
423 }
424
426 if (!arg) {
427 coutE(InputArguments) << "RooFitResult::globalCorr: variable " << parname << " not a floating parameter in fit" << std::endl ;
428 return 0 ;
429 }
430
431 if (_globalCorr) {
432 return (static_cast<RooAbsReal*>(_globalCorr->at(_initPars->index(arg))))->getVal() ;
433 } else {
434 return 1.0 ;
435 }
436}
437
438
439
440////////////////////////////////////////////////////////////////////////////////
441/// Return the list of all global correlations
442
444{
445 if (_globalCorr==nullptr) {
447 }
448
449 return _globalCorr.get();
450}
451
452
453
454////////////////////////////////////////////////////////////////////////////////
455/// Return a correlation matrix element addressed with numeric indices.
456
458{
459 return (*_CM)(row,col) ;
460}
461
462
463////////////////////////////////////////////////////////////////////////////////
464/// Return the covariance matrix element addressed with numeric indices.
465
467{
468 return (*_VM)(row,col) ;
469}
470
471
472
473////////////////////////////////////////////////////////////////////////////////
474/// Print fit result to stream 'os'. In Verbose mode, the constant parameters and
475/// the initial and final values of the floating parameters are printed.
476/// Standard mode only the final values of the floating parameters are printed
477
478void RooFitResult::printMultiline(ostream& os, Int_t /*contents*/, bool verbose, TString indent) const
479{
480
481 os << std::endl
482 << indent << " RooFitResult: minimized FCN value: " << _minNLL << ", estimated distance to minimum: " << _edm << std::endl
483 << indent << " covariance matrix quality: " ;
484 switch(_covQual) {
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 ;
490 }
491 os << std::endl ;
492 os << indent << " Status : " ;
493 for (vector<pair<string,int> >::const_iterator iter = _statusHistory.begin() ; iter != _statusHistory.end() ; ++iter) {
494 os << iter->first << "=" << iter->second << " " ;
495 }
496 os << std::endl << std::endl;
497
498 if (verbose) {
499 if (!_constPars->empty()) {
500 os << indent << " Constant Parameter Value " << std::endl
501 << indent << " -------------------- ------------" << std::endl ;
502
503 for (std::size_t i=0 ; i<_constPars->size() ; i++) {
504 os << indent << " " << setw(20) << _constPars->at(i)->GetName() << " " << setw(12);
505 if(RooRealVar* v = dynamic_cast<RooRealVar*>(_constPars->at(i))) {
506 os << TString::Format("%12.4e",v->getVal());
507 } else {
508 _constPars->at(i)->printValue(os); // for anything other than RooRealVar use printValue method to print
509 }
510 os << std::endl ;
511 }
512
513 os << std::endl ;
514 }
515
516 if (_globalCorr == nullptr && _GC) {
518 }
519
520 // Has any parameter asymmetric errors?
521 bool doAsymErr(false) ;
522 for (std::size_t i=0 ; i<_finalPars->size() ; i++) {
523 if (static_cast<RooRealVar*>(_finalPars->at(i))->hasAsymError()) {
525 break ;
526 }
527 }
528
529 if (doAsymErr) {
530 os << indent << " Floating Parameter InitialValue FinalValue (+HiError,-LoError) GblCorr." << std::endl
531 << indent << " -------------------- ------------ ---------------------------------- --------" << std::endl ;
532 } else {
533 os << indent << " Floating Parameter InitialValue FinalValue +/- Error GblCorr." << std::endl
534 << indent << " -------------------- ------------ -------------------------- --------" << std::endl ;
535 }
536
537 for (std::size_t i=0 ; i<_finalPars->size() ; i++) {
538 os << indent << " " << setw(20) << ((RooAbsArg*)_finalPars->at(i))->GetName() ;
539 os << indent << " " << setw(12) << Form("%12.4e",(static_cast<RooRealVar*>(_initPars->at(i)))->getVal())
540 << indent << " " << setw(12) << Form("%12.4e",(static_cast<RooRealVar*>(_finalPars->at(i)))->getVal()) ;
541
542 if ((static_cast<RooRealVar*>(_finalPars->at(i)))->hasAsymError()) {
543 os << setw(21) << Form(" (+%8.2e,-%8.2e)",(static_cast<RooRealVar*>(_finalPars->at(i)))->getAsymErrorHi(),
544 -1*(static_cast<RooRealVar*>(_finalPars->at(i)))->getAsymErrorLo()) ;
545 } else {
546 double err = (static_cast<RooRealVar*>(_finalPars->at(i)))->getError() ;
547 os << (doAsymErr?" ":"") << " +/- " << setw(9) << Form("%9.2e",err) ;
548 }
549
550 if (_globalCorr) {
551 os << " " << setw(8) << Form("%8.6f" ,(static_cast<RooRealVar*>(_globalCorr->at(i)))->getVal()) ;
552 } else {
553 os << " <none>" ;
554 }
555
556 os << std::endl ;
557 }
558
559 } else {
560 os << indent << " Floating Parameter FinalValue +/- Error " << std::endl
561 << indent << " -------------------- --------------------------" << std::endl ;
562
563 for (std::size_t i=0 ; i<_finalPars->size() ; i++) {
564 double err = (static_cast<RooRealVar*>(_finalPars->at(i)))->getError() ;
565 os << indent << " " << setw(20) << ((RooAbsArg*)_finalPars->at(i))->GetName()
566 << " " << setw(12) << Form("%12.4e",(static_cast<RooRealVar*>(_finalPars->at(i)))->getVal())
567 << " +/- " << setw(9) << Form("%9.2e",err)
568 << std::endl ;
569 }
570 }
571
572
573 os << std::endl ;
574}
575
576
577////////////////////////////////////////////////////////////////////////////////
578/// Function called by RooMinimizer
579
580void RooFitResult::fillCorrMatrix(const std::vector<double>& globalCC, const TMatrixDSym& corrs, const TMatrixDSym& covs)
581{
582 // Sanity check
583 if (globalCC.empty() || corrs.GetNoElements() < 1 || covs.GetNoElements() < 1) {
584 coutI(Minimization) << "RooFitResult::fillCorrMatrix: number of floating parameters is zero, correlation matrix not filled" << std::endl ;
585 return ;
586 }
587
588 if (!_initPars) {
589 coutE(Minimization) << "RooFitResult::fillCorrMatrix: ERROR: list of initial parameters must be filled first" << std::endl ;
590 return ;
591 }
592
593 // Delete eventual previous correlation data holders
594 if (_CM) delete _CM ;
595 if (_VM) delete _VM ;
596 if (_GC) delete _GC ;
597
598 // Build holding arrays for correlation coefficients
599 _CM = new TMatrixDSym(corrs) ;
600 _VM = new TMatrixDSym(covs) ;
601 _GC = new TVectorD(_CM->GetNcols()) ;
602 for(int i=0 ; i<_CM->GetNcols() ; i++) {
603 (*_GC)[i] = globalCC[i] ;
604 }
605 //fillLegacyCorrMatrix() ;
606}
607
608
609
610
611
612////////////////////////////////////////////////////////////////////////////////
613/// Sanity check
614
616{
617 if (!_CM) return ;
618
619 // Delete eventual previous correlation data holders
621
622 // Build holding arrays for correlation coefficients
623 _globalCorr = std::make_unique<RooArgList>("globalCorrelations");
624
625 for(RooAbsArg* arg : *_initPars) {
626 // Create global correlation value holder
627 std::string argName = arg->GetName();
628 std::string argTitle = arg->GetTitle();
629 std::string gcName = "GC[" + argName + "]";
630 std::string gcTitle = argTitle + " Global Correlation";
631 _globalCorr->addOwned(std::make_unique<RooRealVar>(gcName.c_str(), gcTitle.c_str(), 0.));
632
633 // Create array with correlation holders for this parameter
634 RooArgList *corrMatrixRow = new RooArgList(("C[" + argName + ",*]").c_str());
636 for(RooAbsArg* arg2 : *_initPars) {
637
638 std::string arg2Name = arg2->GetName();
639 std::string cName = "C[" + argName + "," + arg2Name + "]";
640 std::string cTitle = "Correlation between " + argName + " and " + arg2Name;
641 corrMatrixRow->addOwned(std::make_unique<RooRealVar>(cName.c_str(), cTitle.c_str(), 0.));
642 }
643 }
644
645 if (!_GC) return ;
646
647 for (unsigned int i = 0; i < static_cast<unsigned int>(_corrMatrix.GetSize()) ; ++i) {
648
649 // Find the next global correlation slot to fill, skipping fixed parameters
650 auto& gcVal = static_cast<RooRealVar&>((*_globalCorr)[i]);
651 gcVal.setVal((*_GC)(i)) ; // WVE FIX THIS
652
653 // Fill a row of the correlation matrix
654 auto corrMatrixCol = static_cast<RooArgList const&>(*_corrMatrix.At(i));
655 for (unsigned int it = 0; it < corrMatrixCol.size() ; ++it) {
656 auto& cVal = static_cast<RooRealVar&>(corrMatrixCol[it]);
657 double value = (*_CM)(i,it) ;
658 cVal.setVal(value);
659 (*_CM)(i,it) = value;
660 }
661 }
662}
663
664
665////////////////////////////////////////////////////////////////////////////////
666
668{
669
670 // Delete eventual previous correlation data holders
671 if (_CM)
672 delete _CM;
673 if (_VM)
674 delete _VM;
675 if (_GC)
676 delete _GC;
677
678 // Build holding arrays for correlation coefficients
679 _CM = new TMatrixDSym(_initPars->size());
680 _VM = new TMatrixDSym(_initPars->size());
681 _GC = new TVectorD(_initPars->size());
682
683 for (std::size_t ii = 0; ii < _finalPars->size(); ii++) {
684 (*_CM)(ii, ii) = 1;
685 (*_VM)(ii, ii) = static_cast<RooRealVar *>(_finalPars->at(ii))->getError() * static_cast<RooRealVar *>(_finalPars->at(ii))->getError();
686 (*_GC)(ii) = 0;
687 }
688}
689
690
691namespace {
692
693void isIdenticalErrMsg(std::string const& msgHead, const RooAbsReal* tv, const RooAbsReal* ov, bool verbose) {
694 if(!verbose) return;
695 std::cout << "RooFitResult::isIdentical: " << msgHead << " " << tv->GetName() << " differs in value:\t"
696 << tv->getVal() << " vs.\t" << ov->getVal()
697 << "\t(" << (tv->getVal()-ov->getVal())/ov->getVal() << ")" << std::endl;
698}
699
700void isErrorIdenticalErrMsg(std::string const& msgHead, const RooRealVar* tv, const RooRealVar* ov, bool verbose) {
701 if(!verbose) return;
702 std::cout << "RooFitResult::isIdentical: " << msgHead << " " << tv->GetName() << " differs in error:\t"
703 << tv->getError() << " vs.\t" << ov->getError()
704 << "\t(" << (tv->getError()-ov->getError())/ov->getError() << ")" << std::endl;
705}
706
707} // namespace
708
709
710////////////////////////////////////////////////////////////////////////////////
711/// Return true if this fit result is identical to other within tolerances, ignoring the correlation matrix.
712/// \param[in] other Fit result to test against.
713/// \param[in] tol **Relative** tolerance for parameters and NLL.
714/// \param[in] tolErr **Relative** tolerance for parameter errors.
715/// \param[in] verbose If this function will log to the standard output when comparisons fail.
716
717bool RooFitResult::isIdenticalNoCov(const RooFitResult& other, double tol, double tolErr, bool verbose) const
718{
719 bool ret = true;
720 auto deviation = [](const double left, const double right, double tolerance){
721 return right != 0. ? std::abs((left - right)/right) >= tolerance : std::abs(left) >= tolerance;
722 };
723
724 auto compare = [&](RooArgList const& pars, RooArgList const& otherpars, std::string const& prefix, bool isVerbose) {
725 bool out = true;
726
727 for (auto * tv : static_range_cast<const RooAbsReal*>(pars)) {
728 auto ov = static_cast<const RooAbsReal*>(otherpars.find(tv->GetName())) ;
729
730 // Check in the parameter is in the other fit result
731 if (!ov) {
732 if(verbose) std::cout << "RooFitResult::isIdentical: cannot find " << prefix << " " << tv->GetName() << " in reference" << std::endl ;
733 out = false;
734 }
735
736 // Compare parameter value
737 if (ov && deviation(tv->getVal(), ov->getVal(), tol)) {
738 isIdenticalErrMsg(prefix, tv, ov, isVerbose);
739 out = false;
740 }
741
742 // Compare parameter error if it's a RooRealVar
743 auto * rtv = dynamic_cast<RooRealVar const*>(tv);
744 auto * rov = dynamic_cast<RooRealVar const*>(ov);
745 if(rtv && rov) {
746 if (ov && deviation(rtv->getError(), rov->getError(), tolErr)) {
747 isErrorIdenticalErrMsg(prefix, rtv, rov, isVerbose);
748 out = false;
749 }
750 }
751 }
752
753 return out;
754 };
755
756 if (deviation(_minNLL, other._minNLL, tol)) {
757 if(verbose) std::cout << "RooFitResult::isIdentical: minimized value of -log(L) is different " << _minNLL << " vs. " << other._minNLL << std::endl;
758 ret = false;
759 }
760
761 ret &= compare(*_constPars, *other._constPars, "constant parameter", verbose);
762 ret &= compare(*_initPars, *other._initPars, "initial parameter", verbose);
763 ret &= compare(*_finalPars, *other._finalPars, "final parameter", verbose);
764
765 return ret;
766}
767
768
769////////////////////////////////////////////////////////////////////////////////
770/// Return true if this fit result is identical to other within tolerances.
771/// \param[in] other Fit result to test against.
772/// \param[in] tol **Relative** tolerance for parameters and NLL.
773/// \param[in] tolCorr **absolute** tolerance for correlation coefficients.
774/// \param[in] verbose If this function will log to the standard output when comparisons fail.
775///
776/// As the relative tolerance for the parameter errors, the default value of
777/// `1e-3` will be used.
778
779bool RooFitResult::isIdentical(const RooFitResult& other, double tol, double tolCorr, bool verbose) const
780{
781 bool ret = isIdenticalNoCov(other, tol, 1e-3 /* synced with default parameter*/, verbose);
782
783 auto deviationCorr = [tolCorr](const double left, const double right){
784 return std::abs(left - right) >= tolCorr;
785 };
786
787 // Only examine correlations for cases with >1 floating parameter
788 if (_finalPars->size()>1) {
789
791 other.fillLegacyCorrMatrix() ;
792
793 for (std::size_t i=0 ; i<_globalCorr->size() ; i++) {
794 auto tv = static_cast<const RooAbsReal*>(_globalCorr->at(i));
795 auto ov = static_cast<const RooAbsReal*>(other._globalCorr->find(_globalCorr->at(i)->GetName())) ;
796 if (!ov) {
797 if(verbose) std::cout << "RooFitResult::isIdentical: cannot find global correlation coefficient " << tv->GetName() << " in reference" << std::endl ;
798 ret = false ;
799 }
800 if (ov && deviationCorr(tv->getVal(), ov->getVal())) {
801 isIdenticalErrMsg("global correlation coefficient", tv, ov, verbose);
802 ret = false ;
803 }
804 }
805
806 for (Int_t j=0 ; j<_corrMatrix.GetSize() ; j++) {
807 RooArgList* row = static_cast<RooArgList*>(_corrMatrix.At(j)) ;
808 RooArgList* orow = static_cast<RooArgList*>(other._corrMatrix.At(j)) ;
809 for (std::size_t i=0 ; i<row->size() ; i++) {
810 auto tv = static_cast<const RooAbsReal*>(row->at(i));
811 auto ov = static_cast<const RooAbsReal*>(orow->find(tv->GetName())) ;
812 if (!ov) {
813 if(verbose) std::cout << "RooFitResult::isIdentical: cannot find correlation coefficient " << tv->GetName() << " in reference" << std::endl ;
814 ret = false ;
815 }
816 if (ov && deviationCorr(tv->getVal(), ov->getVal())) {
817 isIdenticalErrMsg("correlation coefficient", tv, ov, verbose);
818 ret = false ;
819 }
820 }
821 }
822 }
823
824 return ret ;
825}
826
827
828////////////////////////////////////////////////////////////////////////////////
829/// Import the results of the last fit performed by gMinuit, interpreting
830/// the fit parameters as the given varList of parameters.
831
833{
834 // Verify that all members of varList are of type RooRealVar
835 for(RooAbsArg * arg : paramList) {
836 if (!dynamic_cast<RooRealVar *>(arg)) {
837 oocoutE(nullptr, InputArguments) << "RooFitResult::lastMinuitFit: ERROR: variable '" << arg->GetName()
838 << "' is not of type RooRealVar" << std::endl;
839 return nullptr;
840 }
841 }
842
843 RooFitResult *r = new RooFitResult("lastMinuitFit", "Last MINUIT fit");
844
845 // Extract names of fit parameters from MINUIT
846 // and construct corresponding RooRealVars
847 RooArgList constPars("constPars");
848 RooArgList floatPars("floatPars");
849
850 for(RooAbsArg* arg : paramList) {
851 if (arg->isConstant()) {
852 constPars.addClone(*arg);
853 } else {
854 floatPars.addClone(*arg);
855 }
856 }
857
858 r->setConstParList(constPars);
859 r->setInitParList(floatPars);
860 r->setFinalParList(floatPars);
861 r->setMinNLL(0);
862 r->setEDM(0);
863 r->setCovQual(0);
864 r->setStatus(0);
865 r->fillPrefitCorrMatrix();
866
867 return r;
868}
869
870////////////////////////////////////////////////////////////////////////////////
871/// Store externally provided correlation matrix in this RooFitResult ;
872
874{
875 // Delete any previous matrices
876 if (_VM) {
877 delete _VM ;
878 }
879 if (_CM) {
880 delete _CM ;
881 }
882 if (_GC) {
883 delete _GC;
884 _GC = nullptr;
885 }
886 _globalCorr.reset();
887
888 // Clone input covariance matrix ;
889 _VM = static_cast<TMatrixDSym*>(V.Clone()) ;
890
891 // Now construct correlation matrix from it
892 _CM = static_cast<TMatrixDSym*>(_VM->Clone()) ;
893 for (Int_t i=0 ; i<_CM->GetNrows() ; i++) {
894 for (Int_t j=0 ; j<_CM->GetNcols() ; j++) {
895 if (i!=j) {
896 (*_CM)(i,j) = (*_CM)(i,j) / sqrt((*_CM)(i,i)*(*_CM)(j,j)) ;
897 }
898 }
899 }
900 for (Int_t i=0 ; i<_CM->GetNrows() ; i++) {
901 (*_CM)(i,i) = 1.0 ;
902 }
903
904 // Compute the global correlation coefficients from the correlation matrix:
905 // rho_k^2 = 1 - 1/[V_kk * (V^-1)_kk] = 1 - 1/(C^-1)_kk
907 double det = 0.0;
908 invC.Invert(&det);
909 if (det != 0.0) {
910 _GC = new TVectorD(_CM->GetNcols());
911 for (Int_t i = 0; i < _CM->GetNcols(); i++) {
912 const double rho2 = 1.0 - 1.0 / invC(i, i);
913 (*_GC)[i] = rho2 > 0.0 ? sqrt(rho2) : 0.0;
914 }
915 } else {
916 coutW(InputArguments) << "RooFitResult::setCovarianceMatrix(" << GetName()
917 << ") covariance matrix is singular, global correlation coefficients not available"
918 << std::endl;
919 }
920
921 _covQual = -1 ;
922}
923
924
925
926////////////////////////////////////////////////////////////////////////////////
927/// Return TH2D of correlation matrix
928
930{
931 Int_t n = _CM->GetNcols() ;
932
933 TH2D* hh = new TH2D(name,name,n,0,n,n,0,n) ;
934
935 for (Int_t i = 0 ; i<n ; i++) {
936 for (Int_t j = 0 ; j<n; j++) {
937 hh->Fill(i+0.5,n-j-0.5,(*_CM)(i,j)) ;
938 }
939 hh->GetXaxis()->SetBinLabel(i+1,_finalPars->at(i)->GetName()) ;
940 hh->GetYaxis()->SetBinLabel(n-i,_finalPars->at(i)->GetName()) ;
941 }
942 hh->SetMinimum(-1) ;
943 hh->SetMaximum(+1) ;
944
945
946 return hh ;
947}
948
949
950
951
952////////////////////////////////////////////////////////////////////////////////
953/// Return covariance matrix
954
956{
957 return *_VM ;
958}
959
960
961
962
963////////////////////////////////////////////////////////////////////////////////
964/// Return a reduced covariance matrix (Note that Vred _is_ a simple sub-matrix of V,
965/// row/columns are ordered to matched the convention given in input argument 'params'
966
968{
969 const TMatrixDSym& V = covarianceMatrix() ;
970
971
972 // Make sure that all given params were floating parameters in the represented fit
974 for(RooAbsArg* arg : params) {
975 if (_finalPars->find(arg->GetName())) {
976 params2.add(*arg) ;
977 } else {
978 coutW(InputArguments) << "RooFitResult::reducedCovarianceMatrix(" << GetName() << ") WARNING input variable "
979 << arg->GetName() << " was not a floating parameters in fit result and is ignored" << std::endl ;
980 }
981 }
982
983 // fix for bug ROOT-8044
984 // use same order given bby vector params
986 for (std::size_t i=0 ; i<params2.size() ; i++) {
988 assert(indexMap[i] < V.GetNrows());
989 }
990
991 TMatrixDSym Vred(indexMap.size());
992 for (int i = 0; i < Vred.GetNrows(); ++i) {
993 for (int j = 0; j < Vred.GetNcols(); ++j) {
994 Vred(i,j) = V( indexMap[i], indexMap[j]);
995 }
996 }
997 return Vred;
998}
999
1000
1001
1002////////////////////////////////////////////////////////////////////////////////
1003/// Return a reduced covariance matrix, which is calculated as
1004/// \f[
1005/// V_\mathrm{red} = \bar{V_{22}} = V_{11} - V_{12} \cdot V_{22}^{-1} \cdot V_{21},
1006/// \f]
1007/// where \f$ V_{11},V_{12},V_{21},V_{22} \f$ represent a block decomposition of the covariance matrix into observables that
1008/// are propagated (labeled by index '1') and that are not propagated (labeled by index '2'), and \f$ \bar{V_{22}} \f$
1009/// is the Shur complement of \f$ V_{22} \f$, calculated as shown above.
1010///
1011/// (Note that \f$ V_\mathrm{red} \f$ is *not* a simple sub-matrix of \f$ V \f$)
1012
1014{
1015 const TMatrixDSym& V = covarianceMatrix() ;
1016
1017 // Handle case where V==Vred here
1018 if (V.GetNcols()==int(params.size())) {
1019 return V ;
1020 }
1021
1022 double det = V.Determinant() ;
1023
1024 if (det<=0) {
1025 coutE(Eval) << "RooFitResult::conditionalCovarianceMatrix(" << GetName() << ") ERROR: covariance matrix is not positive definite (|V|="
1026 << det << ") cannot reduce it" << std::endl ;
1027 throw string("RooFitResult::conditionalCovarianceMatrix() ERROR, input covariance matrix is not positive definite") ;
1028 }
1029
1030 // Make sure that all given params were floating parameters in the represented fit
1032 for(RooAbsArg* arg : params) {
1033 if (_finalPars->find(arg->GetName())) {
1034 params2.add(*arg) ;
1035 } else {
1036 coutW(InputArguments) << "RooFitResult::conditionalCovarianceMatrix(" << GetName() << ") WARNING input variable "
1037 << arg->GetName() << " was not a floating parameters in fit result and is ignored" << std::endl ;
1038 }
1039 }
1040
1041 // Need to order params in vector in same order as in covariance matrix
1043 for(RooAbsArg* arg : *_finalPars) {
1044 if (params2.find(arg->GetName())) {
1045 params3.add(*arg) ;
1046 }
1047 }
1048
1049 // Find (subset) of parameters that are stored in the covariance matrix
1052 for (std::size_t i=0 ; i<_finalPars->size() ; i++) {
1053 if (params3.find(_finalPars->at(i)->GetName())) {
1054 map1.push_back(i) ;
1055 } else {
1056 map2.push_back(i) ;
1057 }
1058 }
1059
1060 // Rearrange matrix in block form with 'params' first and 'others' last
1061 // (preserving relative order)
1064 TMatrixD S12;
1065 TMatrixD S21;
1067
1068 // Constructed conditional matrix form -1
1069 // F(X1|X2) --> CovI --> S22bar = S11 - S12 S22 S21
1070
1071 // Do eigenvalue decomposition
1073 TMatrixD S22bar = S11 - S12 * (S22Inv * S21) ;
1074
1075 // Convert explicitly to symmetric form
1076 TMatrixDSym Vred(S22bar.GetNcols()) ;
1077 for (int i=0 ; i<Vred.GetNcols() ; i++) {
1078 for (int j=i ; j<Vred.GetNcols() ; j++) {
1079 Vred(i,j) = (S22bar(i,j) + S22bar(j,i))/2 ;
1080 Vred(j,i) = Vred(i,j) ;
1081 }
1082 }
1083
1084 return Vred ;
1085}
1086
1087
1088
1089////////////////////////////////////////////////////////////////////////////////
1090/// Return correlation matrix ;
1091
1093{
1094 return *_CM ;
1095}
1096
1097
1098
1099////////////////////////////////////////////////////////////////////////////////
1100/// Return a p.d.f that represents the fit result as a multi-variate probability densisty
1101/// function on the floating fit parameters, including correlations
1102
1104{
1105 const TMatrixDSym& V = covarianceMatrix() ;
1106 double det = V.Determinant() ;
1107
1108 if (det<=0) {
1109 coutE(Eval) << "RooFitResult::createHessePdf(" << GetName() << ") ERROR: covariance matrix is not positive definite (|V|="
1110 << det << ") cannot construct p.d.f" << std::endl ;
1111 return nullptr ;
1112 }
1113
1114 // Make sure that all given params were floating parameters in the represented fit
1116 for(RooAbsArg* arg : params) {
1117 if (_finalPars->find(arg->GetName())) {
1118 params2.add(*arg) ;
1119 } else {
1120 coutW(InputArguments) << "RooFitResult::createHessePdf(" << GetName() << ") WARNING input variable "
1121 << arg->GetName() << " was not a floating parameters in fit result and is ignored" << std::endl ;
1122 }
1123 }
1124
1125 // Need to order params in vector in same order as in covariance matrix
1127 for(RooAbsArg* arg : *_finalPars) {
1128 if (params2.find(arg->GetName())) {
1129 params3.add(*arg) ;
1130 }
1131 }
1132
1133
1134 // Handle special case of representing full covariance matrix here
1135 if (params3.size()==_finalPars->size()) {
1136
1137 RooArgList mu ;
1138 for (std::size_t i=0 ; i<_finalPars->size() ; i++) {
1139 RooRealVar* parclone = static_cast<RooRealVar*>(_finalPars->at(i)->Clone(Form("%s_centralvalue",_finalPars->at(i)->GetName()))) ;
1140 parclone->setConstant(true) ;
1141 mu.add(*parclone) ;
1142 }
1143
1144 string name = Form("pdf_%s",GetName()) ;
1145 string title = Form("P.d.f of %s",GetTitle()) ;
1146
1147 // Create p.d.f.
1148 RooAbsPdf* mvg = new RooMultiVarGaussian(name.c_str(),title.c_str(),params3,mu,V) ;
1149 mvg->addOwnedComponents(mu) ;
1150 return mvg ;
1151 }
1152
1153 // -> ->
1154 // Handle case of conditional p.d.f. MVG(p1|p2) here
1155
1156 // Find (subset) of parameters that are stored in the covariance matrix
1159 for (std::size_t i=0 ; i<_finalPars->size() ; i++) {
1160 if (params3.find(_finalPars->at(i)->GetName())) {
1161 map1.push_back(i) ;
1162 } else {
1163 map2.push_back(i) ;
1164 }
1165 }
1166
1167 // Rearrange matrix in block form with 'params' first and 'others' last
1168 // (preserving relative order)
1171 TMatrixD S12;
1172 TMatrixD S21;
1174
1175 // Calculate offset vectors mu1 and mu2
1176 RooArgList mu1 ;
1177 for (UInt_t i=0 ; i<map1.size() ; i++) {
1178 RooRealVar* parclone = static_cast<RooRealVar*>(_finalPars->at(map1[i])->Clone(Form("%s_centralvalue",_finalPars->at(map1[i])->GetName()))) ;
1179 parclone->setConstant(true) ;
1180 mu1.add(*parclone) ;
1181 }
1182
1183 // Constructed conditional matrix form -1
1184 // F(X1|X2) --> CovI --> S22bar = S11 - S12 S22 S21
1185
1186 // Do eigenvalue decomposition
1188 TMatrixD S22bar = S11 - S12 * (S22Inv * S21) ;
1189
1190 // Convert explicitly to symmetric form
1191 TMatrixDSym Vred(S22bar.GetNcols()) ;
1192 for (int i=0 ; i<Vred.GetNcols() ; i++) {
1193 for (int j=i ; j<Vred.GetNcols() ; j++) {
1194 Vred(i,j) = (S22bar(i,j) + S22bar(j,i))/2 ;
1195 Vred(j,i) = Vred(i,j) ;
1196 }
1197 }
1198 string name = Form("pdf_%s",GetName()) ;
1199 string title = Form("P.d.f of %s",GetTitle()) ;
1200
1201 // Create p.d.f.
1202 RooAbsPdf* ret = new RooMultiVarGaussian(name.c_str(),title.c_str(),params3,mu1,Vred) ;
1203 ret->addOwnedComponents(mu1) ;
1204 return ret ;
1205}
1206
1207
1208
1209////////////////////////////////////////////////////////////////////////////////
1210/// Change name of RooFitResult object
1211
1213{
1214 if (_dir) _dir->GetList()->Remove(this);
1216 if (_dir) _dir->GetList()->Add(this);
1217}
1218
1219
1220////////////////////////////////////////////////////////////////////////////////
1221/// Change name and title of RooFitResult object
1222
1223void RooFitResult::SetNameTitle(const char *name, const char* title)
1224{
1225 if (_dir) _dir->GetList()->Remove(this);
1226 TNamed::SetNameTitle(name,title) ;
1227 if (_dir) _dir->GetList()->Add(this);
1228}
1229
1230
1231////////////////////////////////////////////////////////////////////////////////
1232/// Print name of fit result
1233
1234void RooFitResult::printName(ostream& os) const
1235{
1236 os << GetName() ;
1237}
1238
1239
1240////////////////////////////////////////////////////////////////////////////////
1241/// Print title of fit result
1242
1243void RooFitResult::printTitle(ostream& os) const
1244{
1245 os << GetTitle() ;
1246}
1247
1248
1249////////////////////////////////////////////////////////////////////////////////
1250/// Print class name of fit result
1251
1252void RooFitResult::printClassName(ostream& os) const
1253{
1254 os << ClassName() ;
1255}
1256
1257
1258////////////////////////////////////////////////////////////////////////////////
1259/// Print arguments of fit result, i.e. the parameters of the fit
1260
1261void RooFitResult::printArgs(ostream& os) const
1262{
1263 os << "[constPars=" << *_constPars << ",floatPars=" << *_finalPars << "]" ;
1264}
1265
1266
1267
1268////////////////////////////////////////////////////////////////////////////////
1269/// Print the value of the fit result, i.e.g the status, minimized FCN, edm and covariance quality code
1270
1271void RooFitResult::printValue(ostream& os) const
1272{
1273 os << "(status=" << _status << ",FCNmin=" << _minNLL << ",EDM=" << _edm << ",covQual=" << _covQual << ")" ;
1274}
1275
1276
1277////////////////////////////////////////////////////////////////////////////////
1278/// Configure default contents to be printed
1279
1284
1285
1286////////////////////////////////////////////////////////////////////////////////
1287/// Configure mapping of Print() arguments to RooPrintable print styles
1288
1290{
1291 if (!opt || strlen(opt)==0) {
1292 return kStandard ;
1293 }
1295}
1296
1297
1298////////////////////////////////////////////////////////////////////////////////
1299/// Stream an object of class RooFitResult.
1300
1302{
1303 if (R__b.IsReading()) {
1304 UInt_t R__s;
1305 UInt_t R__c;
1306 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1307 if (R__v>3) {
1308 R__b.ReadClassBuffer(RooFitResult::Class(),this,R__v,R__s,R__c);
1311 } else {
1312 // backward compatibitily streaming
1316 R__b >> _status;
1317 R__b >> _covQual;
1318 R__b >> _numBadNLL;
1319 R__b >> _minNLL;
1320 R__b >> _edm;
1321 R__b >> _constPars;
1322 R__b >> _initPars;
1323 R__b >> _finalPars;
1325 R__b >> globalCorr;
1326 _globalCorr.reset(globalCorr);
1328 R__b.CheckByteCount(R__s, R__c, RooFitResult::IsA());
1329
1330 // Now fill new-style covariance and correlation matrix information
1331 // from legacy form
1332 _CM = new TMatrixDSym(_finalPars->size()) ;
1333 _VM = new TMatrixDSym(_CM->GetNcols()) ;
1334 _GC = new TVectorD(_CM->GetNcols()) ;
1335
1336 for (unsigned int i = 0; i < (unsigned int)_CM->GetNcols() ; ++i) {
1337
1338 // Find the next global correlation slot to fill, skipping fixed parameters
1339 auto& gcVal = static_cast<RooRealVar&>((*_globalCorr)[i]);
1340 (*_GC)(i) = gcVal.getVal() ;
1341
1342 // Fill a row of the correlation matrix
1343 auto corrMatrixCol = static_cast<RooArgList const&>(*_corrMatrix.At(i));
1344 for (unsigned int it = 0; it < (unsigned int)_CM->GetNcols() ; ++it) {
1345 auto& cVal = static_cast<RooRealVar&>(corrMatrixCol[it]);
1346 double value = cVal.getVal() ;
1347 (*_CM)(it,i) = value ;
1348 (*_CM)(i,it) = value;
1349 (*_VM)(it,i) = value*(static_cast<RooRealVar*>(_finalPars->at(i)))->getError()*(static_cast<RooRealVar*>(_finalPars->at(it)))->getError() ;
1350 (*_VM)(i,it) = (*_VM)(it,i) ;
1351 }
1352 }
1353 }
1354
1355 } else {
1356 R__b.WriteClassBuffer(RooFitResult::Class(),this);
1357 }
1358}
1359
#define g(i)
Definition RSha256.hxx:105
#define s1(x)
Definition RSha256.hxx:91
#define e(i)
Definition RSha256.hxx:103
#define coutI(a)
#define coutW(a)
#define oocoutE(o, a)
#define coutE(a)
short Version_t
Class version identifier (short)
Definition RtypesCore.h:80
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
@ kRed
Definition Rtypes.h:66
@ kBlack
Definition Rtypes.h:65
@ kBlue
Definition Rtypes.h:66
@ kDashed
Definition TAttLine.h:54
static void indent(ostringstream &buf, int indent_level)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
char name[80]
Definition TGX11.cxx:142
TMatrixTSym< Double_t > TMatrixDSym
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2571
TVectorT< Double_t > TVectorD
Definition TVectorDfwd.h:23
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:76
static void ioStreamerPass2Finalize()
Method called by workspace container to finalize schema evolution issues that cannot be handled in a ...
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
Definition RooAbsArg.h:88
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.
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
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.
Definition RooAbsPdf.h:32
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition RooArgList.h:110
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Utility base class for RooFit objects that are to be attached to ROOT directories.
Definition RooDirItem.h:22
virtual void Streamer(TBuffer &)
void removeFromDir(TObject *obj)
Remove object from directory it was added to.
TDirectory * _dir
! Associated directory
Definition RooDirItem.h:33
Two-dimensional ellipse that can be used to represent an error contour.
Definition RooEllipse.h:22
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
TMatrixDSym conditionalCovarianceMatrix(const RooArgList &params) 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 &params) 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 &paramList)
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
static TClass * Class()
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.
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 &params) 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.
Definition RooPlot.h:43
void addObject(TObject *obj, Option_t *drawOptions="", bool invisible=false)
Add a generic object to this plot.
Definition RooPlot.cxx:326
void addPlotable(RooPlotable *plotable, Option_t *drawOptions="", bool invisible=false, bool refreshNorm=false)
Add the specified plotable object to our plot.
Definition RooPlot.cxx:476
A 'mix-in' base class that define the standard RooFit plotting and printing methods.
virtual StyleOption defaultPrintStyle(Option_t *opt) const
virtual void Streamer(TBuffer &)
virtual void printValue(std::ostream &os) const
Interface to print value of object.
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.
Definition RooRealVar.h:37
bool hasAsymError(bool allowZero=true) const
Definition RooRealVar.h:65
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:46
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:47
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Create a Box.
Definition TBox.h:22
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual void RemoveAll(TCollection *col)
Remove all objects in collection col from this collection.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
virtual TList * GetList() const
Definition TDirectory.h:223
The axis painter class.
Definition TGaxis.h:26
2-D histogram with a double per channel (see TH1 documentation)
Definition TH2.h:400
Service class for 2-D histogram classes.
Definition TH2.h:30
Use the TLine constructor to create a simple line.
Definition TLine.h:22
void Streamer(TBuffer &) override
Stream all objects in the collection to or from the I/O buffer.
Definition TList.cxx:1323
void Add(TObject *obj) override
Definition TList.h:81
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:600
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:487
Manages Markers.
Definition TMarker.h:22
Int_t GetNrows() const
Int_t GetNcols() const
TMatrixT.
Definition TMatrixT.h:40
@ kTransposed
Definition TMatrixT.h:59
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
void Streamer(TBuffer &) override
Stream an object of class TObject.
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Definition TNamed.cxx:163
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition TObject.cxx:242
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:226
Basic string class.
Definition TString.h:137
void ToUpper()
Change string to upper case.
Definition TString.cxx:1203
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2460
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:642
TLine * line
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
const Int_t n
Definition legend1.C:16