Logo ROOT   6.16/01
Reference Guide
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 mininum
26///
27/// No references to the fitted PDF and dataset are stored
28///
29
30#include "RooFit.h"
31#include "Riostream.h"
32
33#include <iomanip>
34#include "TMinuit.h"
35#include "TMath.h"
36#include "TMarker.h"
37#include "TLine.h"
38#include "TBox.h"
39#include "TGaxis.h"
40#include "TMatrix.h"
41#include "TVector.h"
42#include "TDirectory.h"
43#include "TClass.h"
44#include "RooFitResult.h"
45#include "RooArgSet.h"
46#include "RooArgList.h"
47#include "RooRealVar.h"
48#include "RooPlot.h"
49#include "RooEllipse.h"
50#include "RooRandom.h"
51#include "RooMsgService.h"
52#include "TH2D.h"
53#include "TText.h"
54#include "TMatrixDSym.h"
55#include "RooMultiVarGaussian.h"
56
57
58
59using namespace std;
60
62;
63
64
65
66////////////////////////////////////////////////////////////////////////////////
67/// Constructor with name and title
68
69RooFitResult::RooFitResult(const char* name, const char* title) :
70 TNamed(name,title), _constPars(0), _initPars(0), _finalPars(0), _globalCorr(0), _randomPars(0), _Lt(0),
71 _CM(0), _VM(0), _GC(0)
72{
73 if (name) appendToDir(this,kTRUE) ;
74}
75
76
77////////////////////////////////////////////////////////////////////////////////
78/// Copy constructor
79
81 TNamed(other),
82 RooPrintable(other),
83 RooDirItem(other),
84 _status(other._status),
85 _covQual(other._covQual),
86 _numBadNLL(other._numBadNLL),
87 _minNLL(other._minNLL),
88 _edm(other._edm),
89 _globalCorr(0),
90 _randomPars(0),
91 _Lt(0),
92 _CM(0),
93 _VM(0),
94 _GC(0)
95{
99 if (other._randomPars) _randomPars = (RooArgList*) other._randomPars->snapshot() ;
100 if (other._Lt) _Lt = new TMatrix(*other._Lt);
101 if (other._VM) _VM = new TMatrixDSym(*other._VM) ;
102 if (other._CM) _CM = new TMatrixDSym(*other._CM) ;
103 if (other._GC) _GC = new TVectorD(*other._GC) ;
104
105 if (GetName())
106 appendToDir(this, kTRUE);
107}
108
109
110
111////////////////////////////////////////////////////////////////////////////////
112/// Destructor
113
115{
116 if (_constPars) delete _constPars ;
117 if (_initPars) delete _initPars ;
118 if (_finalPars) delete _finalPars ;
119 if (_globalCorr) delete _globalCorr;
120 if (_randomPars) delete _randomPars;
121 if (_Lt) delete _Lt;
122 if (_CM) delete _CM ;
123 if (_VM) delete _VM ;
124 if (_GC) delete _GC ;
125
128
129 removeFromDir(this) ;
130}
131
132
133////////////////////////////////////////////////////////////////////////////////
134/// Fill the list of constant parameters
135
137{
138 if (_constPars) delete _constPars ;
139 _constPars = (RooArgList*) list.snapshot() ;
141 RooAbsArg* arg ;
142 while((arg=(RooAbsArg*)iter->Next())) {
143 RooRealVar* rrv = dynamic_cast<RooRealVar*>(arg) ;
144 if (rrv) {
146 }
147 }
148 delete iter ;
149}
150
151
152
153////////////////////////////////////////////////////////////////////////////////
154/// Fill the list of initial values of the floating parameters
155
157{
158 if (_initPars) delete _initPars ;
159 _initPars = (RooArgList*) list.snapshot() ;
161 RooAbsArg* arg ;
162 while((arg=(RooAbsArg*)iter->Next())) {
163 RooRealVar* rrv = dynamic_cast<RooRealVar*>(arg) ;
164 if (rrv) {
166 }
167 }
168 delete iter ;
169}
170
171
172
173////////////////////////////////////////////////////////////////////////////////
174/// Fill the list of final values of the floating parameters
175
177{
178 if (_finalPars) delete _finalPars ;
179 _finalPars = (RooArgList*) list.snapshot() ;
180
182 RooAbsArg* arg ;
183 while((arg=(RooAbsArg*)iter->Next())) {
184 RooRealVar* rrv = dynamic_cast<RooRealVar*>(arg) ;
185 if (rrv) {
187 }
188 }
189 delete iter ;
190}
191
192
193
194////////////////////////////////////////////////////////////////////////////////
195
197{
198 if (icycle>=_statusHistory.size()) {
199 coutE(InputArguments) << "RooFitResult::statusCodeHistory(" << GetName()
200 << " ERROR request for status history slot "
201 << icycle << " exceeds history count of " << _statusHistory.size() << endl ;
202 }
203 return _statusHistory[icycle].second ;
204}
205
206
207
208////////////////////////////////////////////////////////////////////////////////
209
210const char* RooFitResult::statusLabelHistory(UInt_t icycle) const
211{
212 if (icycle>=_statusHistory.size()) {
213 coutE(InputArguments) << "RooFitResult::statusLabelHistory(" << GetName()
214 << " ERROR request for status history slot "
215 << icycle << " exceeds history count of " << _statusHistory.size() << endl ;
216 }
217 return _statusHistory[icycle].first.c_str() ;
218}
219
220
221
222////////////////////////////////////////////////////////////////////////////////
223/// Add objects to a 2D plot that represent the fit results for the
224/// two named parameters. The input frame with the objects added is
225/// returned, or zero in case of an error. Which objects are added
226/// are determined by the options string which should be a concatenation
227/// of the following (not case sensitive):
228///
229/// * M - a marker at the best fit result
230/// * E - an error ellipse calculated at 1-sigma using the error matrix at the minimum
231/// * 1 - the 1-sigma error bar for parameter 1
232/// * 2 - the 1-sigma error bar for parameter 2
233/// * B - the bounding box for the error ellipse
234/// * H - a line and horizontal axis for reading off the correlation coefficient
235/// * V - a line and vertical axis for reading off the correlation coefficient
236/// * A - draw axes for reading off the correlation coefficients with the H or V options
237///
238/// You can change the attributes of objects in the returned RooPlot using the
239/// various `RooPlot::getAttXxx(name)` member functions, e.g.
240/// ```
241/// plot->getAttLine("contour")->SetLineStyle(kDashed);
242/// ```
243/// Use `plot->Print()` for a list of all objects and their names (unfortunately most
244/// of the ROOT builtin graphics objects like TLine are unnamed). Drag the left mouse
245/// button along the labels of either axis button to interactively zoom in a plot.
246
247RooPlot *RooFitResult::plotOn(RooPlot *frame, const char *parName1, const char *parName2,
248 const char *options) const
249{
250 // lookup the input parameters by name: we require that they were floated in our fit
251 const RooRealVar *par1= dynamic_cast<const RooRealVar*>(floatParsFinal().find(parName1));
252 if(0 == par1) {
253 coutE(InputArguments) << "RooFitResult::correlationPlot: parameter not floated in fit: " << parName1 << endl;
254 return 0;
255 }
256 const RooRealVar *par2= dynamic_cast<const RooRealVar*>(floatParsFinal().find(parName2));
257 if(0 == par2) {
258 coutE(InputArguments) << "RooFitResult::correlationPlot: parameter not floated in fit: " << parName2 << endl;
259 return 0;
260 }
261
262 // options are not case sensitive
263 TString opt(options);
264 opt.ToUpper();
265
266 // lookup the 2x2 covariance matrix elements for these variables
267 Double_t x1= par1->getVal();
268 Double_t x2= par2->getVal();
269 Double_t s1= par1->getError();
270 Double_t s2= par2->getError();
271 Double_t rho= correlation(parName1, parName2);
272
273 // add a 1-sigma error ellipse, if requested
274 if(opt.Contains("E")) {
275 RooEllipse *contour= new RooEllipse("contour",x1,x2,s1,s2,rho);
276 contour->SetLineWidth(2) ;
277 frame->addPlotable(contour);
278 }
279
280 // add the error bar for parameter 1, if requested
281 if(opt.Contains("1")) {
282 TLine *hline= new TLine(x1-s1,x2,x1+s1,x2);
283 hline->SetLineColor(kRed);
284 frame->addObject(hline);
285 }
286
287 if(opt.Contains("2")) {
288 TLine *vline= new TLine(x1,x2-s2,x1,x2+s2);
289 vline->SetLineColor(kRed);
290 frame->addObject(vline);
291 }
292
293 if(opt.Contains("B")) {
294 TBox *box= new TBox(x1-s1,x2-s2,x1+s1,x2+s2);
295 box->SetLineStyle(kDashed);
296 box->SetLineColor(kRed);
297 box->SetFillStyle(0);
298 frame->addObject(box);
299 }
300
301 if(opt.Contains("H")) {
302 TLine *line= new TLine(x1-rho*s1,x2-s2,x1+rho*s1,x2+s2);
305 line->SetLineWidth(2) ;
306 frame->addObject(line);
307 if(opt.Contains("A")) {
308 TGaxis *axis= new TGaxis(x1-s1,x2-s2,x1+s1,x2-s2,-1.,+1.,502,"-=");
309 axis->SetLineColor(kBlue);
310 frame->addObject(axis);
311 }
312 }
313
314 if(opt.Contains("V")) {
315 TLine *line= new TLine(x1-s1,x2-rho*s2,x1+s1,x2+rho*s2);
318 line->SetLineWidth(2) ;
319 frame->addObject(line);
320 if(opt.Contains("A")) {
321 TGaxis *axis= new TGaxis(x1-s1,x2-s2,x1-s1,x2+s2,-1.,+1.,502,"-=");
322 axis->SetLineColor(kBlue);
323 frame->addObject(axis);
324 }
325 }
326
327 // add a marker at the fitted value, if requested
328 if(opt.Contains("M")) {
329 TMarker *marker= new TMarker(x1,x2,20);
330 marker->SetMarkerColor(kBlack);
331 frame->addObject(marker);
332 }
333
334 return frame;
335}
336
337
338////////////////////////////////////////////////////////////////////////////////
339/// Return a list of floating parameter values that are perturbed from the final
340/// fit values by random amounts sampled from the covariance matrix. The returned
341/// object is overwritten with each call and belongs to the RooFitResult. Uses
342/// the "square root method" to decompose the covariance matrix, which makes inverting
343/// it unnecessary.
344
346{
347 Int_t nPar= _finalPars->getSize();
348 if(0 == _randomPars) { // first-time initialization
349 assert(0 != _finalPars);
350 // create the list of random values to fill
352 // calculate the elements of the upper-triangular matrix L that gives Lt*L = C
353 // where Lt is the transpose of L (the "square-root method")
354 TMatrix L(nPar,nPar);
355 for(Int_t iPar= 0; iPar < nPar; iPar++) {
356 // calculate the diagonal term first
357 L(iPar,iPar)= covariance(iPar,iPar);
358 for(Int_t k= 0; k < iPar; k++) {
359 Double_t tmp= L(k,iPar);
360 L(iPar,iPar)-= tmp*tmp;
361 }
362 L(iPar,iPar)= sqrt(L(iPar,iPar));
363 // then the off-diagonal terms
364 for(Int_t jPar= iPar+1; jPar < nPar; jPar++) {
365 L(iPar,jPar)= covariance(iPar,jPar);
366 for(Int_t k= 0; k < iPar; k++) {
367 L(iPar,jPar)-= L(k,iPar)*L(k,jPar);
368 }
369 L(iPar,jPar)/= L(iPar,iPar);
370 }
371 }
372 // remember Lt
374 }
375 else {
376 // reset to the final fit values
378 }
379
380 // create a vector of unit Gaussian variables
381 TVector g(nPar);
382 for(Int_t k= 0; k < nPar; k++) g(k)= RooRandom::gaussian();
383 // multiply this vector by Lt to introduce the appropriate correlations
384 g*= (*_Lt);
385 // add the mean value offsets and store the results
387 RooRealVar *par(0);
388 Int_t index(0);
389 while((0 != (par= (RooRealVar*)iter->Next()))) {
390 par->setVal(par->getVal() + g(index++));
391 }
392 delete iter;
393
394 return *_randomPars;
395}
396
397
398////////////////////////////////////////////////////////////////////////////////
399/// Return the correlation between parameters 'par1' and 'par2'
400
401Double_t RooFitResult::correlation(const char* parname1, const char* parname2) const
402{
403 Int_t idx1 = _finalPars->index(parname1) ;
404 Int_t idx2 = _finalPars->index(parname2) ;
405 if (idx1<0) {
406 coutE(InputArguments) << "RooFitResult::correlation(" << GetName() << ") parameter " << parname1 << " is not a floating fit parameter" << endl ;
407 return 0 ;
408 }
409 if (idx2<0) {
410 coutE(InputArguments) << "RooFitResult::correlation(" << GetName() << ") parameter " << parname2 << " is not a floating fit parameter" << endl ;
411 return 0 ;
412 }
413 return correlation(idx1,idx2) ;
414}
415
416
417
418////////////////////////////////////////////////////////////////////////////////
419/// Return the set of correlation coefficients of parameter 'par' with
420/// all other floating parameters
421
422const RooArgList* RooFitResult::correlation(const char* parname) const
423{
424 if (_globalCorr==0) {
426 }
427
428 RooAbsArg* arg = _initPars->find(parname) ;
429 if (!arg) {
430 coutE(InputArguments) << "RooFitResult::correlation: variable " << parname << " not a floating parameter in fit" << endl ;
431 return 0 ;
432 }
433 return (RooArgList*)_corrMatrix.At(_initPars->index(arg)) ;
434}
435
436
437
438////////////////////////////////////////////////////////////////////////////////
439/// Return the global correlation of the named parameter
440
442{
443 if (_globalCorr==0) {
445 }
446
447 RooAbsArg* arg = _initPars->find(parname) ;
448 if (!arg) {
449 coutE(InputArguments) << "RooFitResult::globalCorr: variable " << parname << " not a floating parameter in fit" << endl ;
450 return 0 ;
451 }
452
453 if (_globalCorr) {
454 return ((RooAbsReal*)_globalCorr->at(_initPars->index(arg)))->getVal() ;
455 } else {
456 return 1.0 ;
457 }
458}
459
460
461
462////////////////////////////////////////////////////////////////////////////////
463/// Return the list of all global correlations
464
466{
467 if (_globalCorr==0) {
469 }
470
471 return _globalCorr ;
472}
473
474
475
476////////////////////////////////////////////////////////////////////////////////
477/// Return a correlation matrix element addressed with numeric indices.
478
480{
481 return (*_CM)(row,col) ;
482}
483
484
485////////////////////////////////////////////////////////////////////////////////
486/// Return the covariance matrix element addressed with numeric indices.
487
489{
490 return (*_VM)(row,col) ;
491}
492
493
494
495////////////////////////////////////////////////////////////////////////////////
496/// Print fit result to stream 'os'. In Verbose mode, the constant parameters and
497/// the initial and final values of the floating parameters are printed.
498/// Standard mode only the final values of the floating parameters are printed
499
500void RooFitResult::printMultiline(ostream& os, Int_t /*contents*/, Bool_t verbose, TString indent) const
501{
502
503 os << endl
504 << indent << " RooFitResult: minimized FCN value: " << _minNLL << ", estimated distance to minimum: " << _edm << endl
505 << indent << " covariance matrix quality: " ;
506 switch(_covQual) {
507 case -1 : os << "Unknown, matrix was externally provided" ; break ;
508 case 0 : os << "Not calculated at all" ; break ;
509 case 1 : os << "Approximation only, not accurate" ; break ;
510 case 2 : os << "Full matrix, but forced positive-definite" ; break ;
511 case 3 : os << "Full, accurate covariance matrix" ; break ;
512 }
513 os << endl ;
514 os << indent << " Status : " ;
515 for (vector<pair<string,int> >::const_iterator iter = _statusHistory.begin() ; iter != _statusHistory.end() ; ++iter) {
516 os << iter->first << "=" << iter->second << " " ;
517 }
518 os << endl << endl ;;
519
520 Int_t i ;
521 if (verbose) {
522 if (_constPars->getSize()>0) {
523 os << indent << " Constant Parameter Value " << endl
524 << indent << " -------------------- ------------" << endl ;
525
526 for (i=0 ; i<_constPars->getSize() ; i++) {
527 os << indent << " " << setw(20) << ((RooAbsArg*)_constPars->at(i))->GetName()
528 << " " << setw(12) << Form("%12.4e",((RooRealVar*)_constPars->at(i))->getVal())
529 << endl ;
530 }
531
532 os << endl ;
533 }
534
535 // Has any parameter asymmetric errors?
536 Bool_t doAsymErr(kFALSE) ;
537 for (i=0 ; i<_finalPars->getSize() ; i++) {
538 if (((RooRealVar*)_finalPars->at(i))->hasAsymError()) {
539 doAsymErr=kTRUE ;
540 break ;
541 }
542 }
543
544 if (doAsymErr) {
545 os << indent << " Floating Parameter InitialValue FinalValue (+HiError,-LoError) GblCorr." << endl
546 << indent << " -------------------- ------------ ---------------------------------- --------" << endl ;
547 } else {
548 os << indent << " Floating Parameter InitialValue FinalValue +/- Error GblCorr." << endl
549 << indent << " -------------------- ------------ -------------------------- --------" << endl ;
550 }
551
552 for (i=0 ; i<_finalPars->getSize() ; i++) {
553 os << indent << " " << setw(20) << ((RooAbsArg*)_finalPars->at(i))->GetName() ;
554 os << indent << " " << setw(12) << Form("%12.4e",((RooRealVar*)_initPars->at(i))->getVal())
555 << indent << " " << setw(12) << Form("%12.4e",((RooRealVar*)_finalPars->at(i))->getVal()) ;
556
557 if (((RooRealVar*)_finalPars->at(i))->hasAsymError()) {
558 os << setw(21) << Form(" (+%8.2e,-%8.2e)",((RooRealVar*)_finalPars->at(i))->getAsymErrorHi(),
559 -1*((RooRealVar*)_finalPars->at(i))->getAsymErrorLo()) ;
560 } else {
561 Double_t err = ((RooRealVar*)_finalPars->at(i))->getError() ;
562 os << (doAsymErr?" ":"") << " +/- " << setw(9) << Form("%9.2e",err) ;
563 }
564
565 if (_globalCorr) {
566 os << " " << setw(8) << Form("%8.6f" ,((RooRealVar*)_globalCorr->at(i))->getVal()) ;
567 } else {
568 os << " <none>" ;
569 }
570
571 os << endl ;
572 }
573
574 } else {
575 os << indent << " Floating Parameter FinalValue +/- Error " << endl
576 << indent << " -------------------- --------------------------" << endl ;
577
578 for (i=0 ; i<_finalPars->getSize() ; i++) {
579 Double_t err = ((RooRealVar*)_finalPars->at(i))->getError() ;
580 os << indent << " " << setw(20) << ((RooAbsArg*)_finalPars->at(i))->GetName()
581 << " " << setw(12) << Form("%12.4e",((RooRealVar*)_finalPars->at(i))->getVal())
582 << " +/- " << setw(9) << Form("%9.2e",err)
583 << endl ;
584 }
585 }
586
587
588 os << endl ;
589}
590
591
592////////////////////////////////////////////////////////////////////////////////
593/// Function called by RooMinimizer
594
595void RooFitResult::fillCorrMatrix(const std::vector<double>& globalCC, const TMatrixDSym& corrs, const TMatrixDSym& covs)
596{
597 // Sanity check
598 if (globalCC.empty() || corrs.GetNoElements() < 1 || covs.GetNoElements() < 1) {
599 coutI(Minimization) << "RooFitResult::fillCorrMatrix: number of floating parameters is zero, correlation matrix not filled" << endl ;
600 return ;
601 }
602
603 if (!_initPars) {
604 coutE(Minimization) << "RooFitResult::fillCorrMatrix: ERROR: list of initial parameters must be filled first" << endl ;
605 return ;
606 }
607
608 // Delete eventual prevous correlation data holders
609 if (_CM) delete _CM ;
610 if (_VM) delete _VM ;
611 if (_GC) delete _GC ;
612
613 // Build holding arrays for correlation coefficients
614 _CM = new TMatrixDSym(corrs) ;
615 _VM = new TMatrixDSym(covs) ;
616 _GC = new TVectorD(_CM->GetNcols()) ;
617 for(int i=0 ; i<_CM->GetNcols() ; i++) {
618 (*_GC)[i] = globalCC[i] ;
619 }
620 //fillLegacyCorrMatrix() ;
621}
622
623
624
625
626
627////////////////////////////////////////////////////////////////////////////////
628/// Sanity check
629
631{
632 if (!_CM) return ;
633
634 // Delete eventual prevous correlation data holders
635 if (_globalCorr) delete _globalCorr ;
637
638 // Build holding arrays for correlation coefficients
639 _globalCorr = new RooArgList("globalCorrelations") ;
640
642 RooAbsArg* arg ;
643 Int_t idx(0) ;
644 while((arg=(RooAbsArg*)vIter->Next())) {
645 // Create global correlation value holder
646 TString gcName("GC[") ;
647 gcName.Append(arg->GetName()) ;
648 gcName.Append("]") ;
649 TString gcTitle(arg->GetTitle()) ;
650 gcTitle.Append(" Global Correlation") ;
651 _globalCorr->addOwned(*(new RooRealVar(gcName.Data(),gcTitle.Data(),0.))) ;
652
653 // Create array with correlation holders for this parameter
654 TString name("C[") ;
655 name.Append(arg->GetName()) ;
656 name.Append(",*]") ;
657 RooArgList* corrMatrixRow = new RooArgList(name.Data()) ;
658 _corrMatrix.Add(corrMatrixRow) ;
659 TIterator* vIter2 = _initPars->createIterator() ;
660 RooAbsArg* arg2 ;
661 while((arg2=(RooAbsArg*)vIter2->Next())) {
662
663 TString cName("C[") ;
664 cName.Append(arg->GetName()) ;
665 cName.Append(",") ;
666 cName.Append(arg2->GetName()) ;
667 cName.Append("]") ;
668 TString cTitle("Correlation between ") ;
669 cTitle.Append(arg->GetName()) ;
670 cTitle.Append(" and ") ;
671 cTitle.Append(arg2->GetName()) ;
672 corrMatrixRow->addOwned(*(new RooRealVar(cName.Data(),cTitle.Data(),0.))) ;
673 }
674 delete vIter2 ;
675 idx++ ;
676 }
677 delete vIter ;
678
680 TIterator *parIter = _finalPars->createIterator() ;
681 RooRealVar* gcVal = 0;
682 for (unsigned int i = 0; i < (unsigned int)_CM->GetNcols() ; ++i) {
683
684 // Find the next global correlation slot to fill, skipping fixed parameters
685 gcVal = (RooRealVar*) gcIter->Next() ;
686 gcVal->setVal((*_GC)(i)) ; // WVE FIX THIS
687
688 // Fill a row of the correlation matrix
689 TIterator* cIter = ((RooArgList*)_corrMatrix.At(i))->createIterator() ;
690 for (unsigned int it = 0; it < (unsigned int)_CM->GetNcols() ; ++it) {
691 RooRealVar* cVal = (RooRealVar*) cIter->Next() ;
692 double value = (*_CM)(i,it) ;
693 cVal->setVal(value);
694 (*_CM)(i,it) = value;
695 }
696 delete cIter ;
697 }
698
699 delete gcIter ;
700 delete parIter ;
701
702}
703
704
705
706
707
708////////////////////////////////////////////////////////////////////////////////
709/// Internal utility method to extract the correlation matrix and the
710/// global correlation coefficients from the MINUIT memory buffer and
711/// fill the internal arrays.
712
714{
715 // Sanity check
716 if (gMinuit->fNpar < 1) {
717 coutI(Minimization) << "RooFitResult::fillCorrMatrix: number of floating parameters is zero, correlation matrix not filled" << endl ;
718 return ;
719 }
720
721 if (!_initPars) {
722 coutE(Minimization) << "RooFitResult::fillCorrMatrix: ERROR: list of initial parameters must be filled first" << endl ;
723 return ;
724 }
725
726 // Delete eventual prevous correlation data holders
727 if (_CM) delete _CM ;
728 if (_VM) delete _VM ;
729 if (_GC) delete _GC ;
730
731 // Build holding arrays for correlation coefficients
732 _CM = new TMatrixDSym(_initPars->getSize()) ;
733 _VM = new TMatrixDSym(_initPars->getSize()) ;
734 _GC = new TVectorD(_initPars->getSize()) ;
735
736 // Extract correlation information for MINUIT (code taken from TMinuit::mnmatu() )
737
738 // WVE: This code directly manipulates minuit internal workspace,
739 // if TMinuit code changes this may need updating
740 Int_t ndex, i, j, m, n, it /* nparm,id,ix */ ;
741 Int_t ndi, ndj /*, iso, isw2, isw5*/;
742 for (i = 1; i <= gMinuit->fNpar; ++i) {
743 ndi = i*(i + 1) / 2;
744 for (j = 1; j <= gMinuit->fNpar; ++j) {
745 m = TMath::Max(i,j);
746 n = TMath::Min(i,j);
747 ndex = m*(m-1) / 2 + n;
748 ndj = j*(j + 1) / 2;
749 gMinuit->fMATUvline[j-1] = gMinuit->fVhmat[ndex-1] / TMath::Sqrt(TMath::Abs(gMinuit->fVhmat[ndi-1]*gMinuit->fVhmat[ndj-1]));
750 }
751
752 (*_GC)(i-1) = gMinuit->fGlobcc[i-1] ;
753
754 // Fill a row of the correlation matrix
755 for (it = 1; it <= gMinuit->fNpar ; ++it) {
756 (*_CM)(i-1,it-1) = gMinuit->fMATUvline[it-1] ;
757 }
758 }
759
760 for (int ii=0 ; ii<_finalPars->getSize() ; ii++) {
761 for (int jj=0 ; jj<_finalPars->getSize() ; jj++) {
762 (*_VM)(ii,jj) = (*_CM)(ii,jj) * ((RooRealVar*)_finalPars->at(ii))->getError() * ((RooRealVar*)_finalPars->at(jj))->getError() ;
763 }
764 }
765}
766
767////////////////////////////////////////////////////////////////////////////////
768
770{
771
772 // Delete eventual prevous correlation data holders
773 if (_CM)
774 delete _CM;
775 if (_VM)
776 delete _VM;
777 if (_GC)
778 delete _GC;
779
780 // Build holding arrays for correlation coefficients
783 _GC = new TVectorD(_initPars->getSize());
784
785 for (int ii = 0; ii < _finalPars->getSize(); ii++) {
786 (*_CM)(ii, ii) = 1;
787 (*_VM)(ii, ii) = ((RooRealVar *)_finalPars->at(ii))->getError() * ((RooRealVar *)_finalPars->at(ii))->getError();
788 (*_GC)(ii) = 0;
789 }
790}
791
792////////////////////////////////////////////////////////////////////////////////
793/// Return true if this fit result is identical to other within tolerance 'tol' on fitted values
794/// and tolerance 'tolCor' on correlation coefficients
795
796Bool_t RooFitResult::isIdentical(const RooFitResult& other, Double_t tol, Double_t tolCorr, Bool_t /*verbose*/) const
797{
798 Bool_t ret = kTRUE ;
799
800 if (fabs(_minNLL-other._minNLL)>=tol) {
801 cout << "RooFitResult::isIdentical: minimized value of -log(L) is different " << _minNLL << " vs. " << other._minNLL << endl ;
802 ret = kFALSE ;
803 }
804
805 for (Int_t i=0 ; i<_constPars->getSize() ; i++) {
806 RooAbsReal* ov = static_cast<RooAbsReal*>(other._constPars->find(_constPars->at(i)->GetName())) ;
807 if (!ov) {
808 cout << "RooFitResult::isIdentical: cannot find constant parameter " << _constPars->at(i)->GetName() << " in reference" << endl ;
809 ret = kFALSE ;
810 }
811 if (ov && fabs(static_cast<RooAbsReal*>(_constPars->at(i))->getVal()-ov->getVal())>=tol) {
812 cout << "RooFitResult::isIdentical: constant parameter " << _constPars->at(i)->GetName()
813 << " differs in value: " << static_cast<RooAbsReal*>(_constPars->at(i))->getVal() << " vs. " << ov->getVal() << endl ;
814 ret = kFALSE ;
815 }
816 }
817
818 for (Int_t i=0 ; i<_initPars->getSize() ; i++) {
819 RooAbsReal* ov = static_cast<RooAbsReal*>(other._initPars->find(_initPars->at(i)->GetName())) ;
820 if (!ov) {
821 cout << "RooFitResult::isIdentical: cannot find initial parameter " << _initPars->at(i)->GetName() << " in reference" << endl ;
822 ret = kFALSE ;
823 }
824 if (ov && fabs(static_cast<RooAbsReal*>(_initPars->at(i))->getVal()-ov->getVal())>=tol) {
825 cout << "RooFitResult::isIdentical: initial parameter " << _initPars->at(i)->GetName()
826 << " differs in value: " << static_cast<RooAbsReal*>(_initPars->at(i))->getVal() << " vs. " << ov->getVal() << endl ;
827 ret = kFALSE ;
828 }
829 }
830
831 for (Int_t i=0 ; i<_finalPars->getSize() ; i++) {
832 RooAbsReal* ov = static_cast<RooAbsReal*>(other._finalPars->find(_finalPars->at(i)->GetName())) ;
833 if (!ov) {
834 cout << "RooFitResult::isIdentical: cannot find final parameter " << _finalPars->at(i)->GetName() << " in reference" << endl ;
835 ret = kFALSE ;
836 }
837 if (ov && fabs(static_cast<RooAbsReal*>(_finalPars->at(i))->getVal()-ov->getVal())>=tol) {
838 cout << "RooFitResult::isIdentical: final parameter " << _finalPars->at(i)->GetName()
839 << " differs in value: " << static_cast<RooAbsReal*>(_finalPars->at(i))->getVal() << " vs. " << ov->getVal() << endl ;
840 ret = kFALSE ;
841 }
842 }
843
844 // Only examine correlations for cases with >1 floating parameter
845 if (_finalPars->getSize()>1) {
846
848 other.fillLegacyCorrMatrix() ;
849
850 for (Int_t i=0 ; i<_globalCorr->getSize() ; i++) {
851 RooAbsReal* ov = static_cast<RooAbsReal*>(other._globalCorr->find(_globalCorr->at(i)->GetName())) ;
852 if (!ov) {
853 cout << "RooFitResult::isIdentical: cannot find global correlation coefficient " << _globalCorr->at(i)->GetName() << " in reference" << endl ;
854 ret = kFALSE ;
855 }
856 if (ov && fabs(static_cast<RooAbsReal*>(_globalCorr->at(i))->getVal()-ov->getVal())>=tolCorr) {
857 cout << "RooFitResult::isIdentical: global correlation coefficient " << _globalCorr->at(i)->GetName()
858 << " differs in value: " << static_cast<RooAbsReal*>(_globalCorr->at(i))->getVal() << " vs. " << ov->getVal() << endl ;
859 ret = kFALSE ;
860 }
861 }
862
863 for (Int_t j=0 ; j<_corrMatrix.GetSize() ; j++) {
864 RooArgList* row = (RooArgList*) _corrMatrix.At(j) ;
865 RooArgList* orow = (RooArgList*) other._corrMatrix.At(j) ;
866 for (Int_t i=0 ; i<row->getSize() ; i++) {
867 RooAbsReal* ov = static_cast<RooAbsReal*>(orow->find(row->at(i)->GetName())) ;
868 if (!ov) {
869 cout << "RooFitResult::isIdentical: cannot find correlation coefficient " << row->at(i)->GetName() << " in reference" << endl ;
870 ret = kFALSE ;
871 }
872 if (ov && fabs(static_cast<RooAbsReal*>(row->at(i))->getVal()-ov->getVal())>=tolCorr) {
873 cout << "RooFitResult::isIdentical: correlation coefficient " << row->at(i)->GetName()
874 << " differs in value: " << static_cast<RooAbsReal*>(row->at(i))->getVal() << " vs. " << ov->getVal() << endl ;
875 ret = kFALSE ;
876 }
877 }
878 }
879 }
880
881 return ret ;
882}
883
884
885
886////////////////////////////////////////////////////////////////////////////////
887/// Import the results of the last fit performed by gMinuit, interpreting
888/// the fit parameters as the given varList of parameters.
889
891{
892 // Verify length of supplied varList
893 if (varList.getSize()>0 && varList.getSize()!=gMinuit->fNu) {
894 oocoutE((TObject*)0,InputArguments) << "RooFitResult::lastMinuitFit: ERROR: supplied variable list must be either empty " << endl
895 << " or match the number of variables of the last fit (" << gMinuit->fNu << ")" << endl ;
896 return 0 ;
897 }
898
899 // Verify that all members of varList are of type RooRealVar
900 TIterator* iter = varList.createIterator() ;
901 RooAbsArg* arg ;
902 while((arg=(RooAbsArg*)iter->Next())) {
903 if (!dynamic_cast<RooRealVar*>(arg)) {
904 oocoutE((TObject*)0,InputArguments) << "RooFitResult::lastMinuitFit: ERROR: variable '" << arg->GetName() << "' is not of type RooRealVar" << endl ;
905 return 0 ;
906 }
907 }
908 delete iter ;
909
910 RooFitResult* r = new RooFitResult("lastMinuitFit","Last MINUIT fit") ;
911
912 // Extract names of fit parameters from MINUIT
913 // and construct corresponding RooRealVars
914 RooArgList constPars("constPars") ;
915 RooArgList floatPars("floatPars") ;
916
917 Int_t i ;
918 for (i = 1; i <= gMinuit->fNu; ++i) {
919 if (gMinuit->fNvarl[i-1] < 0) continue;
920 Int_t l = gMinuit->fNiofex[i-1];
921 TString varName(gMinuit->fCpnam[i-1]) ;
922 Bool_t isConst(l==0) ;
923
924 Double_t xlo = gMinuit->fAlim[i-1];
925 Double_t xhi = gMinuit->fBlim[i-1];
926 Double_t xerr = gMinuit->fWerr[l-1];
927 Double_t xval = gMinuit->fU[i-1] ;
928
929 RooRealVar* var ;
930 if (varList.getSize()==0) {
931
932 if ((xlo<xhi) && !isConst) {
933 var = new RooRealVar(varName,varName,xval,xlo,xhi) ;
934 } else {
935 var = new RooRealVar(varName,varName,xval) ;
936 }
937 var->setConstant(isConst) ;
938 } else {
939
940 var = (RooRealVar*) varList.at(i-1)->Clone() ;
941 var->setConstant(isConst) ;
942 var->setVal(xval) ;
943 if (xlo<xhi) {
944 var->setRange(xlo,xhi) ;
945 }
946 if (varName.CompareTo(var->GetName())) {
947 oocoutI((TObject*)0,Eval) << "RooFitResult::lastMinuitFit: fit parameter '" << varName
948 << "' stored in variable '" << var->GetName() << "'" << endl ;
949 }
950
951 }
952
953 if (isConst) {
954 constPars.addOwned(*var) ;
955 } else {
956 var->setError(xerr) ;
957 floatPars.addOwned(*var) ;
958 }
959 }
960
961 Int_t icode,npari,nparx ;
962 Double_t fmin,edm,errdef ;
963 gMinuit->mnstat(fmin,edm,errdef,npari,nparx,icode) ;
964
965 r->setConstParList(constPars) ;
966 r->setInitParList(floatPars) ;
967 r->setFinalParList(floatPars) ;
968 r->setMinNLL(fmin) ;
969 r->setEDM(edm) ;
970 r->setCovQual(icode) ;
971 r->setStatus(gMinuit->fStatus) ;
972 r->fillCorrMatrix() ;
973
974 return r ;
975}
976
977
978
979////////////////////////////////////////////////////////////////////////////////
980/// Import the results of the last fit performed by gMinuit, interpreting
981/// the fit parameters as the given varList of parameters.
982
984{
985 // Verify that all members of varList are of type RooRealVar
986 TIterator *iter = paramList.createIterator();
987 RooAbsArg *arg;
988 while ((arg = (RooAbsArg *)iter->Next())) {
989 if (!dynamic_cast<RooRealVar *>(arg)) {
990 oocoutE((TObject *)0, InputArguments) << "RooFitResult::lastMinuitFit: ERROR: variable '" << arg->GetName()
991 << "' is not of type RooRealVar" << endl;
992 return 0;
993 }
994 }
995
996 RooFitResult *r = new RooFitResult("lastMinuitFit", "Last MINUIT fit");
997
998 // Extract names of fit parameters from MINUIT
999 // and construct corresponding RooRealVars
1000 RooArgList constPars("constPars");
1001 RooArgList floatPars("floatPars");
1002
1003 iter->Reset();
1004 while ((arg = (RooAbsArg *)iter->Next())) {
1005 if (arg->isConstant()) {
1006 constPars.addClone(*arg);
1007 } else {
1008 floatPars.addClone(*arg);
1009 }
1010 }
1011 delete iter;
1012
1013 r->setConstParList(constPars);
1014 r->setInitParList(floatPars);
1015 r->setFinalParList(floatPars);
1016 r->setMinNLL(0);
1017 r->setEDM(0);
1018 r->setCovQual(0);
1019 r->setStatus(0);
1020 r->fillPrefitCorrMatrix();
1021
1022 return r;
1023}
1024
1025////////////////////////////////////////////////////////////////////////////////
1026/// Store externally provided correlation matrix in this RooFitResult ;
1027
1029{
1030 // Delete any previous matrices
1031 if (_VM) {
1032 delete _VM ;
1033 }
1034 if (_CM) {
1035 delete _CM ;
1036 }
1037
1038 // Clone input covariance matrix ;
1039 _VM = (TMatrixDSym*) V.Clone() ;
1040
1041 // Now construct correlation matrix from it
1042 _CM = (TMatrixDSym*) _VM->Clone() ;
1043 for (Int_t i=0 ; i<_CM->GetNrows() ; i++) {
1044 for (Int_t j=0 ; j<_CM->GetNcols() ; j++) {
1045 if (i!=j) {
1046 (*_CM)(i,j) = (*_CM)(i,j) / sqrt((*_CM)(i,i)*(*_CM)(j,j)) ;
1047 }
1048 }
1049 }
1050 for (Int_t i=0 ; i<_CM->GetNrows() ; i++) {
1051 (*_CM)(i,i) = 1.0 ;
1052 }
1053
1054 _covQual = -1 ;
1055}
1056
1057
1058
1059////////////////////////////////////////////////////////////////////////////////
1060/// Return TH2D of correlation matrix
1061
1063{
1064 Int_t n = _CM->GetNcols() ;
1065
1066 TH2D* hh = new TH2D(name,name,n,0,n,n,0,n) ;
1067
1068 for (Int_t i = 0 ; i<n ; i++) {
1069 for (Int_t j = 0 ; j<n; j++) {
1070 hh->Fill(i+0.5,n-j-0.5,(*_CM)(i,j)) ;
1071 }
1072 hh->GetXaxis()->SetBinLabel(i+1,_finalPars->at(i)->GetName()) ;
1073 hh->GetYaxis()->SetBinLabel(n-i,_finalPars->at(i)->GetName()) ;
1074 }
1075 hh->SetMinimum(-1) ;
1076 hh->SetMaximum(+1) ;
1077
1078
1079 return hh ;
1080}
1081
1082
1083
1084
1085////////////////////////////////////////////////////////////////////////////////
1086/// Return covariance matrix
1087
1089{
1090 return *_VM ;
1091}
1092
1093
1094
1095
1096////////////////////////////////////////////////////////////////////////////////
1097/// Return a reduced covariance matrix (Note that Vred _is_ a simple sub-matrix of V,
1098/// row/columns are ordered to matched the convention given in input argument 'params'
1099
1101{
1102 const TMatrixDSym& V = covarianceMatrix() ;
1103
1104
1105 // Make sure that all given params were floating parameters in the represented fit
1106 RooArgList params2 ;
1107 TIterator* iter = params.createIterator() ;
1108 RooAbsArg* arg ;
1109 while((arg=(RooAbsArg*)iter->Next())) {
1110 if (_finalPars->find(arg->GetName())) {
1111 params2.add(*arg) ;
1112 } else {
1113 coutW(InputArguments) << "RooFitResult::reducedCovarianceMatrix(" << GetName() << ") WARNING input variable "
1114 << arg->GetName() << " was not a floating parameters in fit result and is ignored" << endl ;
1115 }
1116 }
1117 delete iter ;
1118
1119 // fix for bug ROOT-8044
1120 // use same order given bby vector params
1121 vector<int> indexMap(params2.getSize());
1122 for (int i=0 ; i<params2.getSize() ; i++) {
1123 indexMap[i] = _finalPars->index(params2[i].GetName());
1124 assert(indexMap[i] < V.GetNrows());
1125 }
1126
1127 TMatrixDSym Vred(indexMap.size());
1128 for (int i = 0; i < Vred.GetNrows(); ++i) {
1129 for (int j = 0; j < Vred.GetNcols(); ++j) {
1130 Vred(i,j) = V( indexMap[i], indexMap[j]);
1131 }
1132 }
1133 return Vred;
1134}
1135
1136
1137
1138////////////////////////////////////////////////////////////////////////////////
1139/// Return a reduced covariance matrix, which is calculated as
1140/// \f[
1141/// V_\mathrm{red} = \bar{V_{22}} = V_{11} - V_{12} \cdot V_{22}^{-1} \cdot V_{21},
1142/// \f]
1143/// where \f$ V_{11},V_{12},V_{21},V_{22} \f$ represent a block decomposition of the covariance matrix into observables that
1144/// are propagated (labeled by index '1') and that are not propagated (labeled by index '2'), and \f$ \bar{V_{22}} \f$
1145/// is the Shur complement of \f$ V_{22} \f$, calculated as shown above.
1146///
1147/// (Note that \f$ V_\mathrm{red} \f$ is *not* a simple sub-matrix of \f$ V \f$)
1148
1150{
1151 const TMatrixDSym& V = covarianceMatrix() ;
1152
1153 // Handle case where V==Vred here
1154 if (V.GetNcols()==params.getSize()) {
1155 return V ;
1156 }
1157
1158 Double_t det = V.Determinant() ;
1159
1160 if (det<=0) {
1161 coutE(Eval) << "RooFitResult::conditionalCovarianceMatrix(" << GetName() << ") ERROR: covariance matrix is not positive definite (|V|="
1162 << det << ") cannot reduce it" << endl ;
1163 throw string("RooFitResult::conditionalCovarianceMatrix() ERROR, input covariance matrix is not positive definite") ;
1164 }
1165
1166 // Make sure that all given params were floating parameters in the represented fit
1167 RooArgList params2 ;
1168 TIterator* iter = params.createIterator() ;
1169 RooAbsArg* arg ;
1170 while((arg=(RooAbsArg*)iter->Next())) {
1171 if (_finalPars->find(arg->GetName())) {
1172 params2.add(*arg) ;
1173 } else {
1174 coutW(InputArguments) << "RooFitResult::conditionalCovarianceMatrix(" << GetName() << ") WARNING input variable "
1175 << arg->GetName() << " was not a floating parameters in fit result and is ignored" << endl ;
1176 }
1177 }
1178 delete iter ;
1179
1180 // Need to order params in vector in same order as in covariance matrix
1181 RooArgList params3 ;
1182 iter = _finalPars->createIterator() ;
1183 while((arg=(RooAbsArg*)iter->Next())) {
1184 if (params2.find(arg->GetName())) {
1185 params3.add(*arg) ;
1186 }
1187 }
1188 delete iter ;
1189
1190 // Find (subset) of parameters that are stored in the covariance matrix
1191 vector<int> map1, map2 ;
1192 for (int i=0 ; i<_finalPars->getSize() ; i++) {
1193 if (params3.find(_finalPars->at(i)->GetName())) {
1194 map1.push_back(i) ;
1195 } else {
1196 map2.push_back(i) ;
1197 }
1198 }
1199
1200 // Rearrange matrix in block form with 'params' first and 'others' last
1201 // (preserving relative order)
1202 TMatrixDSym S11, S22 ;
1203 TMatrixD S12, S21 ;
1204 RooMultiVarGaussian::blockDecompose(V,map1,map2,S11,S12,S21,S22) ;
1205
1206 // Constructed conditional matrix form -1
1207 // F(X1|X2) --> CovI --> S22bar = S11 - S12 S22 S21
1208
1209 // Do eigenvalue decomposition
1210 TMatrixD S22Inv(TMatrixD::kInverted,S22) ;
1211 TMatrixD S22bar = S11 - S12 * (S22Inv * S21) ;
1212
1213 // Convert explicitly to symmetric form
1214 TMatrixDSym Vred(S22bar.GetNcols()) ;
1215 for (int i=0 ; i<Vred.GetNcols() ; i++) {
1216 for (int j=i ; j<Vred.GetNcols() ; j++) {
1217 Vred(i,j) = (S22bar(i,j) + S22bar(j,i))/2 ;
1218 Vred(j,i) = Vred(i,j) ;
1219 }
1220 }
1221
1222 return Vred ;
1223}
1224
1225
1226
1227////////////////////////////////////////////////////////////////////////////////
1228/// Return correlation matrix ;
1229
1231{
1232 return *_CM ;
1233}
1234
1235
1236
1237////////////////////////////////////////////////////////////////////////////////
1238/// Return a p.d.f that represents the fit result as a multi-variate probability densisty
1239/// function on the floating fit parameters, including correlations
1240
1242{
1243 const TMatrixDSym& V = covarianceMatrix() ;
1244 Double_t det = V.Determinant() ;
1245
1246 if (det<=0) {
1247 coutE(Eval) << "RooFitResult::createHessePdf(" << GetName() << ") ERROR: covariance matrix is not positive definite (|V|="
1248 << det << ") cannot construct p.d.f" << endl ;
1249 return 0 ;
1250 }
1251
1252 // Make sure that all given params were floating parameters in the represented fit
1253 RooArgList params2 ;
1254 TIterator* iter = params.createIterator() ;
1255 RooAbsArg* arg ;
1256 while((arg=(RooAbsArg*)iter->Next())) {
1257 if (_finalPars->find(arg->GetName())) {
1258 params2.add(*arg) ;
1259 } else {
1260 coutW(InputArguments) << "RooFitResult::createHessePdf(" << GetName() << ") WARNING input variable "
1261 << arg->GetName() << " was not a floating parameters in fit result and is ignored" << endl ;
1262 }
1263 }
1264 delete iter ;
1265
1266 // Need to order params in vector in same order as in covariance matrix
1267 RooArgList params3 ;
1268 iter = _finalPars->createIterator() ;
1269 while((arg=(RooAbsArg*)iter->Next())) {
1270 if (params2.find(arg->GetName())) {
1271 params3.add(*arg) ;
1272 }
1273 }
1274 delete iter ;
1275
1276
1277 // Handle special case of representing full covariance matrix here
1278 if (params3.getSize()==_finalPars->getSize()) {
1279
1280 RooArgList mu ;
1281 for (Int_t i=0 ; i<_finalPars->getSize() ; i++) {
1282 RooRealVar* parclone = (RooRealVar*) _finalPars->at(i)->Clone(Form("%s_centralvalue",_finalPars->at(i)->GetName())) ;
1283 parclone->setConstant(kTRUE) ;
1284 mu.add(*parclone) ;
1285 }
1286
1287 string name = Form("pdf_%s",GetName()) ;
1288 string title = Form("P.d.f of %s",GetTitle()) ;
1289
1290 // Create p.d.f.
1291 RooAbsPdf* mvg = new RooMultiVarGaussian(name.c_str(),title.c_str(),params3,mu,V) ;
1292 mvg->addOwnedComponents(mu) ;
1293 return mvg ;
1294 }
1295
1296 // -> ->
1297 // Handle case of conditional p.d.f. MVG(p1|p2) here
1298
1299 // Find (subset) of parameters that are stored in the covariance matrix
1300 vector<int> map1, map2 ;
1301 for (int i=0 ; i<_finalPars->getSize() ; i++) {
1302 if (params3.find(_finalPars->at(i)->GetName())) {
1303 map1.push_back(i) ;
1304 } else {
1305 map2.push_back(i) ;
1306 }
1307 }
1308
1309 // Rearrange matrix in block form with 'params' first and 'others' last
1310 // (preserving relative order)
1311 TMatrixDSym S11, S22 ;
1312 TMatrixD S12, S21 ;
1313 RooMultiVarGaussian::blockDecompose(V,map1,map2,S11,S12,S21,S22) ;
1314
1315 // Calculate offset vectors mu1 and mu2
1316 RooArgList mu1 ;
1317 for (UInt_t i=0 ; i<map1.size() ; i++) {
1318 RooRealVar* parclone = (RooRealVar*) _finalPars->at(map1[i])->Clone(Form("%s_centralvalue",_finalPars->at(map1[i])->GetName())) ;
1319 parclone->setConstant(kTRUE) ;
1320 mu1.add(*parclone) ;
1321 }
1322
1323 // Constructed conditional matrix form -1
1324 // F(X1|X2) --> CovI --> S22bar = S11 - S12 S22 S21
1325
1326 // Do eigenvalue decomposition
1327 TMatrixD S22Inv(TMatrixD::kInverted,S22) ;
1328 TMatrixD S22bar = S11 - S12 * (S22Inv * S21) ;
1329
1330 // Convert explicitly to symmetric form
1331 TMatrixDSym Vred(S22bar.GetNcols()) ;
1332 for (int i=0 ; i<Vred.GetNcols() ; i++) {
1333 for (int j=i ; j<Vred.GetNcols() ; j++) {
1334 Vred(i,j) = (S22bar(i,j) + S22bar(j,i))/2 ;
1335 Vred(j,i) = Vred(i,j) ;
1336 }
1337 }
1338 string name = Form("pdf_%s",GetName()) ;
1339 string title = Form("P.d.f of %s",GetTitle()) ;
1340
1341 // Create p.d.f.
1342 RooAbsPdf* ret = new RooMultiVarGaussian(name.c_str(),title.c_str(),params3,mu1,Vred) ;
1343 ret->addOwnedComponents(mu1) ;
1344 return ret ;
1345}
1346
1347
1348
1349////////////////////////////////////////////////////////////////////////////////
1350/// Change name of RooFitResult object
1351
1352void RooFitResult::SetName(const char *name)
1353{
1354 if (_dir) _dir->GetList()->Remove(this);
1356 if (_dir) _dir->GetList()->Add(this);
1357}
1358
1359
1360////////////////////////////////////////////////////////////////////////////////
1361/// Change name and title of RooFitResult object
1362
1363void RooFitResult::SetNameTitle(const char *name, const char* title)
1364{
1365 if (_dir) _dir->GetList()->Remove(this);
1366 TNamed::SetNameTitle(name,title) ;
1367 if (_dir) _dir->GetList()->Add(this);
1368}
1369
1370
1371////////////////////////////////////////////////////////////////////////////////
1372/// Print name of fit result
1373
1374void RooFitResult::printName(ostream& os) const
1375{
1376 os << GetName() ;
1377}
1378
1379
1380////////////////////////////////////////////////////////////////////////////////
1381/// Print title of fit result
1382
1383void RooFitResult::printTitle(ostream& os) const
1384{
1385 os << GetTitle() ;
1386}
1387
1388
1389////////////////////////////////////////////////////////////////////////////////
1390/// Print class name of fit result
1391
1392void RooFitResult::printClassName(ostream& os) const
1393{
1394 os << IsA()->GetName() ;
1395}
1396
1397
1398////////////////////////////////////////////////////////////////////////////////
1399/// Print arguments of fit result, i.e. the parameters of the fit
1400
1401void RooFitResult::printArgs(ostream& os) const
1402{
1403 os << "[constPars=" << *_constPars << ",floatPars=" << *_finalPars << "]" ;
1404}
1405
1406
1407
1408////////////////////////////////////////////////////////////////////////////////
1409/// Print the value of the fit result, i.e.g the status, minimized FCN, edm and covariance quality code
1410
1411void RooFitResult::printValue(ostream& os) const
1412{
1413 os << "(status=" << _status << ",FCNmin=" << _minNLL << ",EDM=" << _edm << ",covQual=" << _covQual << ")" ;
1414}
1415
1416
1417////////////////////////////////////////////////////////////////////////////////
1418/// Configure default contents to be printed
1419
1421{
1422 return kName|kClassName|kArgs|kValue ;
1423}
1424
1425
1426////////////////////////////////////////////////////////////////////////////////
1427/// Configure mapping of Print() arguments to RooPrintable print styles
1428
1430{
1431 if (!opt || strlen(opt)==0) {
1432 return kStandard ;
1433 }
1435}
1436
1437
1438////////////////////////////////////////////////////////////////////////////////
1439/// Stream an object of class RooFitResult.
1440
1441void RooFitResult::Streamer(TBuffer &R__b)
1442{
1443 if (R__b.IsReading()) {
1444 UInt_t R__s, R__c;
1445 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1446 if (R__v>3) {
1447 R__b.ReadClassBuffer(RooFitResult::Class(),this,R__v,R__s,R__c);
1450 } else {
1451 // backward compatibitily streaming
1452 TNamed::Streamer(R__b);
1453 RooPrintable::Streamer(R__b);
1454 RooDirItem::Streamer(R__b);
1455 R__b >> _status;
1456 R__b >> _covQual;
1457 R__b >> _numBadNLL;
1458 R__b >> _minNLL;
1459 R__b >> _edm;
1460 R__b >> _constPars;
1461 R__b >> _initPars;
1462 R__b >> _finalPars;
1463 R__b >> _globalCorr;
1464 _corrMatrix.Streamer(R__b);
1465 R__b.CheckByteCount(R__s, R__c, RooFitResult::IsA());
1466
1467 // Now fill new-style covariance and correlation matrix information
1468 // from legacy form
1469 _CM = new TMatrixDSym(_finalPars->getSize()) ;
1470 _VM = new TMatrixDSym(_CM->GetNcols()) ;
1471 _GC = new TVectorD(_CM->GetNcols()) ;
1472
1473 TIterator *gcIter = _globalCorr->createIterator() ;
1474 TIterator *parIter = _finalPars->createIterator() ;
1475 RooRealVar* gcVal = 0;
1476 for (unsigned int i = 0; i < (unsigned int)_CM->GetNcols() ; ++i) {
1477
1478 // Find the next global correlation slot to fill, skipping fixed parameters
1479 gcVal = (RooRealVar*) gcIter->Next() ;
1480 (*_GC)(i) = gcVal->getVal() ;
1481
1482 // Fill a row of the correlation matrix
1483 TIterator* cIter = ((RooArgList*)_corrMatrix.At(i))->createIterator() ;
1484 for (unsigned int it = 0; it < (unsigned int)_CM->GetNcols() ; ++it) {
1485 RooRealVar* cVal = (RooRealVar*) cIter->Next() ;
1486 double value = cVal->getVal() ;
1487 (*_CM)(it,i) = value ;
1488 (*_CM)(i,it) = value;
1489 (*_VM)(it,i) = value*((RooRealVar*)_finalPars->at(i))->getError()*((RooRealVar*)_finalPars->at(it))->getError() ;
1490 (*_VM)(i,it) = (*_VM)(it,i) ;
1491 }
1492 delete cIter ;
1493 }
1494
1495 delete gcIter ;
1496 delete parIter ;
1497 }
1498
1499 } else {
1501 }
1502}
1503
void Class()
Definition: Class.C:29
ROOT::R::TRInterface & r
Definition: Object.C:4
#define g(i)
Definition: RSha256.hxx:105
#define s1(x)
Definition: RSha256.hxx:91
static const double x2[5]
static const double x1[5]
#define coutI(a)
Definition: RooMsgService.h:31
#define coutW(a)
Definition: RooMsgService.h:33
#define oocoutE(o, a)
Definition: RooMsgService.h:47
#define oocoutI(o, a)
Definition: RooMsgService.h:44
#define coutE(a)
Definition: RooMsgService.h:34
int Int_t
Definition: RtypesCore.h:41
short Version_t
Definition: RtypesCore.h:61
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:363
@ kRed
Definition: Rtypes.h:63
@ kBlack
Definition: Rtypes.h:62
@ kBlue
Definition: Rtypes.h:63
@ kDashed
Definition: TAttLine.h:48
double sqrt(double)
TMatrixTSym< Double_t > TMatrixDSym
TMatrixT< Float_t > TMatrix
Definition: TMatrix.h:24
R__EXTERN TMinuit * gMinuit
Definition: TMinuit.h:271
char * Form(const char *fmt,...)
TVectorT< Double_t > TVectorD
Definition: TVectorDfwd.h:22
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
static void ioStreamerPass2Finalize()
Method called by workspace container to finalize schema evolution issues that cannot be handled in a ...
Definition: RooAbsArg.cxx:2467
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Definition: RooAbsArg.h:75
Bool_t addOwnedComponents(const RooArgSet &comps)
Take ownership of the contents of 'comps'.
Definition: RooAbsArg.cxx:2274
Bool_t isConstant() const
Definition: RooAbsArg.h:266
Int_t getSize() const
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
virtual RooAbsArg * addClone(const RooAbsArg &var, Bool_t silent=kFALSE)
Add a clone of the specified argument to list.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
TIterator * createIterator(Bool_t dir=kIterForward) const
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
void setConstant(Bool_t value=kTRUE)
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
Double_t getVal(const RooArgSet *set=0) const
Evaluate object. Returns either cached value or triggers a recalculation.
Definition: RooAbsReal.h:64
RooAbsArg * at(Int_t idx) const
Definition: RooArgList.h:84
Int_t index(const RooAbsArg *arg) const
Definition: RooArgList.h:76
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooDirItem is a utility base class for RooFit objects that are to be attached to ROOT directories.
Definition: RooDirItem.h:22
void appendToDir(TObject *obj, Bool_t forceMemoryResident=kFALSE)
Append object to directory.
Definition: RooDirItem.cxx:86
void removeFromDir(TObject *obj)
Remove object from directory it was added to.
Definition: RooDirItem.cxx:71
TDirectory * _dir
Definition: RooDirItem.h:33
A RooEllipse is a 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.
Definition: RooFitResult.h:40
TMatrixDSym conditionalCovarianceMatrix(const RooArgList &params) const
Return a reduced covariance matrix, which is calculated as.
void fillCorrMatrix()
Internal utility method to extract the correlation matrix and the global correlation coefficients fro...
TList _corrMatrix
List of global correlation coefficients.
Definition: RooFitResult.h:191
std::vector< std::pair< std::string, int > > _statusHistory
Definition: RooFitResult.h:200
const TMatrixDSym & covarianceMatrix() const
Return covariance matrix.
RooFitResult(const char *name=0, const char *title=0)
Constructor with name and title.
TMatrixDSym * _CM
triangular matrix used for generate random perturbations
Definition: RooFitResult.h:196
void setConstParList(const RooArgList &list)
Fill the list of constant parameters.
Int_t statusCodeHistory(UInt_t icycle) const
virtual ~RooFitResult()
Destructor.
virtual Int_t defaultPrintContents(Option_t *opt) const
Configure default contents to be printed.
virtual void printTitle(std::ostream &os) const
Print title of fit result.
Bool_t isIdentical(const RooFitResult &other, Double_t tol=5e-5, Double_t tolCorr=1e-4, Bool_t verbose=kTRUE) const
Return true if this fit result is identical to other within tolerance 'tol' on fitted values and tole...
Int_t _numBadNLL
Definition: RooFitResult.h:183
TMatrixDSym * _VM
Definition: RooFitResult.h:197
Double_t correlation(const RooAbsArg &par1, const RooAbsArg &par2) const
Definition: RooFitResult.h:117
RooArgList * _initPars
Definition: RooFitResult.h:187
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...
void fillPrefitCorrMatrix()
RooArgList * _constPars
Definition: RooFitResult.h:186
void SetNameTitle(const char *name, const char *title)
Change name and title of RooFitResult object.
RooArgList * _globalCorr
Definition: RooFitResult.h:190
Double_t edm() const
Definition: RooFitResult.h:94
const RooArgList & randomizePars() const
Return a list of floating parameter values that are perturbed from the final fit values by random amo...
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 ;.
virtual StyleOption defaultPrintStyle(Option_t *opt) const
Configure mapping of Print() arguments to RooPrintable print styles.
RooArgList * _finalPars
Definition: RooFitResult.h:188
const RooArgList & constPars() const
Definition: RooFitResult.h:102
void SetName(const char *name)
Change name of RooFitResult object.
Double_t covariance(Int_t row, Int_t col) const
Return the covariance matrix element addressed with numeric indices.
virtual void printClassName(std::ostream &os) const
Print class name of fit result.
const char * statusLabelHistory(UInt_t icycle) const
Double_t _edm
Definition: RooFitResult.h:185
Double_t _minNLL
Definition: RooFitResult.h:184
void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Print fit result to stream 'os'.
virtual void printArgs(std::ostream &os) const
Print arguments of fit result, i.e. the parameters of the fit.
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
Definition: RooFitResult.h:143
TMatrixF * _Lt
List of floating parameters with most recent random perturbation applied.
Definition: RooFitResult.h:194
virtual void printName(std::ostream &os) const
Print name of fit result.
const RooArgList & floatParsFinal() const
Definition: RooFitResult.h:110
RooArgList * _randomPars
Correlation matrix (list of RooArgLists)
Definition: RooFitResult.h:193
static RooFitResult * lastMinuitFit(const RooArgList &varList=RooArgList())
Import the results of the last fit performed by gMinuit, interpreting the fit parameters as the given...
virtual void printValue(std::ostream &os) const
Print the value of the fit result, i.e.g the status, minimized FCN, edm and covariance quality code.
TVectorD * _GC
Definition: RooFitResult.h:198
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...
void setFinalParList(const RooArgList &list)
Fill the list of final values of the floating parameters.
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.
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:41
void addObject(TObject *obj, Option_t *drawOptions="", Bool_t invisible=kFALSE)
Add a generic object to this plot.
Definition: RooPlot.cxx:391
void addPlotable(RooPlotable *plotable, Option_t *drawOptions="", Bool_t invisible=kFALSE, Bool_t refreshNorm=kFALSE)
Add the specified plotable object to our plot.
Definition: RooPlot.cxx:446
RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and printing methods.
Definition: RooPrintable.h:25
virtual StyleOption defaultPrintStyle(Option_t *opt) const
static Double_t gaussian(TRandom *generator=randomGenerator())
Return a Gaussian random variable with mean 0 and variance 1.
Definition: RooRandom.cxx:111
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
void setError(Double_t value)
Definition: RooRealVar.h:55
void setRange(const char *name, Double_t min, Double_t max)
Set range named 'name to [min,max].
Definition: RooRealVar.cxx:448
void deleteSharedProperties()
No longer used?
Double_t getError() const
Definition: RooRealVar.h:53
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:204
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:42
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:38
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition: TAxis.cxx:809
Create a Box.
Definition: TBox.h:24
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
Bool_t IsReading() const
Definition: TBuffer.h:83
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
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.
Definition: TCollection.h:182
virtual TList * GetList() const
Definition: TDirectory.h:149
The axis painter class.
Definition: TGaxis.h:24
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:316
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:394
TAxis * GetYaxis()
Definition: TH1.h:317
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:395
2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:291
Service class for 2-Dim histogram classes.
Definition: TH2.h:30
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:292
Iterator abstract base class.
Definition: TIterator.h:30
virtual void Reset()=0
virtual TObject * Next()=0
A simple line.
Definition: TLine.h:23
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:818
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:354
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:467
Manages Markers.
Definition: TMarker.h:23
Int_t GetNrows() const
Definition: TMatrixTBase.h:124
Int_t GetNoElements() const
Definition: TMatrixTBase.h:128
Int_t GetNcols() const
Definition: TMatrixTBase.h:127
virtual Double_t Determinant() const
TMatrixT.
Definition: TMatrixT.h:39
@ kTransposed
Definition: TMatrixT.h:58
Double_t * fU
Definition: TMinuit.h:68
Int_t fNu
Definition: TMinuit.h:130
Double_t * fGlobcc
Definition: TMinuit.h:74
TString * fCpnam
Character to be plotted at the X,Y contour positions.
Definition: TMinuit.h:165
Int_t * fNvarl
Definition: TMinuit.h:126
Double_t * fMATUvline
Definition: TMinuit.h:107
Double_t * fBlim
Definition: TMinuit.h:70
Double_t * fWerr
Definition: TMinuit.h:73
Int_t fStatus
Definition: TMinuit.h:154
Int_t fNpar
Definition: TMinuit.h:41
Double_t * fAlim
Definition: TMinuit.h:69
Int_t * fNiofex
Definition: TMinuit.h:127
Double_t * fVhmat
Definition: TMinuit.h:89
virtual void mnstat(Double_t &fmin, Double_t &fedm, Double_t &errdef, Int_t &npari, Int_t &nparx, Int_t &istat)
Returns concerning the current status of the minimization.
Definition: TMinuit.cxx:7645
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Definition: TNamed.cxx:154
Mother of all ROOT objects.
Definition: TObject.h:37
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:144
TVectorT.
Definition: TVectorT.h:27
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
for(Int_t i=0;i< n;i++)
Definition: legend1.C:18
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
@ Minimization
Definition: RooGlobalFunc.h:57
@ InputArguments
Definition: RooGlobalFunc.h:58
static constexpr double L
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
Double_t Sqrt(Double_t x)
Definition: TMath.h:679
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180
Short_t Abs(Short_t d)
Definition: TMathBase.h:120
STL namespace.
auto * m
Definition: textangle.C:8
auto * l
Definition: textangle.C:4