Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
RooChi2MCSModule.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/** \class RooChi2MCSModule
18 \ingroup Roofit
19
20RooChi2MCSModule is an add-on module to RooMCStudy that
21calculates the chi-squared of fitted p.d.f with respect to a binned
22version of the data. For each fit the chi-squared, the reduced chi-squared
23the number of degrees of freedom and the probability of the chi-squared
24is store in the summary dataset.
25**/
26
27#include "Riostream.h"
28
29#include "RooAbsPdf.h"
30#include "RooDataSet.h"
31#include "RooRealVar.h"
32#include "RooFitResult.h"
33#include "RooChi2MCSModule.h"
34#include "RooMsgService.h"
35#include "RooDataHist.h"
36#include "TMath.h"
37#include "RooGlobalFunc.h"
38
39
40////////////////////////////////////////////////////////////////////////////////
41
42RooChi2MCSModule::RooChi2MCSModule() : RooAbsMCStudyModule("RooChi2MCSModule", "RooChi2Module") {}
43
44////////////////////////////////////////////////////////////////////////////////
45/// Copy constructor
46
48
49////////////////////////////////////////////////////////////////////////////////
50/// Destructor
51
53
54////////////////////////////////////////////////////////////////////////////////
55/// Initialize module after attachment to RooMCStudy object
56
58{
59 // Construct variable that holds -log(L) fit with null hypothesis for given parameter
60 _chi2 = std::make_unique<RooRealVar>("chi2", "chi^2", 0);
61 _ndof = std::make_unique<RooRealVar>("ndof", "number of degrees of freedom", 0);
62 _chi2red = std::make_unique<RooRealVar>("chi2red", "reduced chi^2", 0);
63 _prob = std::make_unique<RooRealVar>("prob", "prob(chi2,ndof)", 0);
64
65 // Create new dataset to be merged with RooMCStudy::fitParDataSet
66 _data = std::make_unique<RooDataSet>("Chi2Data", "Additional data for Chi2 study",
68
69 return true;
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Initialize module at beginning of RooCMStudy run
74
76{
77 _data->reset() ;
78 return true ;
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Return auxiliary dataset with results of chi2 analysis
83/// calculations of this module so that it is merged with
84/// RooMCStudy::fitParDataSet() by RooMCStudy
85
90
91////////////////////////////////////////////////////////////////////////////////
92/// Bin dataset and calculate chi2 of p.d.f w.r.t binned dataset
93
95{
97 std::unique_ptr<RooDataHist> binnedDataOwned;
98 RooDataHist* binnedData = dynamic_cast<RooDataHist*>(data) ;
99 if (!binnedData) {
100 binnedDataOwned = std::unique_ptr<RooDataHist>{static_cast<RooDataSet*>(data)->binnedClone()};
102 }
103
105
106 std::unique_ptr<RooArgSet> floatPars{fitParams()->selectByAttrib("Constant",false)};
107
108 _chi2->setVal(chi2Var->getVal()) ;
109 _ndof->setVal(binnedData->numEntries()-floatPars->size()-1) ;
110 _chi2red->setVal(_chi2->getVal()/_ndof->getVal()) ;
111 _prob->setVal(TMath::Prob(_chi2->getVal(),static_cast<int>(_ndof->getVal()))) ;
112
114
115 return true ;
116}
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 data
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
Base class for add-on modules to RooMCStudy that can perform additional calculations on each generate...
bool extendedGen()
If true extended mode generation is requested.
RooAbsData * genSample()
Return generate sample.
RooAbsPdf * fitModel()
Return fit model.
RooArgSet * fitParams()
Return current value of parameters of fit model.
virtual RooFit::OwningPtr< RooAbsReal > createChi2(RooDataHist &data, const RooLinkedList &cmdList)
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
RooArgSet * selectByAttrib(const char *name, bool value) const
Use RooAbsCollection::selectByAttrib(), but return as RooArgSet.
Definition RooArgSet.h:144
RooChi2MCSModule is an add-on module to RooMCStudy that calculates the chi-squared of fitted p....
~RooChi2MCSModule() override
Destructor.
std::unique_ptr< RooRealVar > _prob
bool processAfterFit(Int_t) override
Bin dataset and calculate chi2 of p.d.f w.r.t binned dataset.
std::unique_ptr< RooRealVar > _ndof
bool initializeRun(Int_t) override
Initialize module at beginning of RooCMStudy run.
std::unique_ptr< RooDataSet > _data
std::unique_ptr< RooRealVar > _chi2
bool initializeInstance() override
Initialize module after attachment to RooMCStudy object.
RooDataSet * finalizeRun() override
Return auxiliary dataset with results of chi2 analysis calculations of this module so that it is merg...
std::unique_ptr< RooRealVar > _chi2red
Container class to hold N-dimensional binned data.
Definition RooDataHist.h:40
Container class to hold unbinned data.
Definition RooDataSet.h:34
RooCmdArg DataError(Int_t)
RooCmdArg Extended(bool flag=true)
Double_t Prob(Double_t chi2, Int_t ndf)
Computation of the probability for a certain Chi-squared (chi2) and number of degrees of freedom (ndf...
Definition TMath.cxx:637