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