Data and categories: using weights in unbinned datasets
Author: Wouter Verkerke
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, April 17, 2024 at 11:18 AM.
%%cpp -d
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooDataHist.h"
#include "RooGaussian.h"
#include "RooFormulaVar.h"
#include "RooGenericPdf.h"
#include "RooPolynomial.h"
#include "RooMinimizer.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
#include "RooFitResult.h"
using namespace RooFit;
Declare observable
RooRealVar x("x", "x", -10, 10);
x.setBins(40);
Construction a uniform pdf
RooPolynomial p0("px", "px", x);
Sample 1000 events from pdf
std::unique_ptr<RooDataSet> data{p0.generate(x, 1000)};
input_line_50:2:2: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration std::unique_ptr<RooDataSet> data{p0.generate(x, 1000)}; ^
Construct formula to calculate (fake) weight for events
RooFormulaVar wFunc("w", "event weight", "(x*x+10)", x);
Add column with variable w to previously generated dataset
RooRealVar *w = (RooRealVar *)data->addColumn(wFunc);
input_line_55:2:32: error: reference to 'data' is ambiguous RooRealVar *w = (RooRealVar *)data->addColumn(wFunc); ^ input_line_50:2:30: note: candidate found by name lookup is 'data' std::unique_ptr<RooDataSet> data{p0.generate(x, 1000)}; ^ /usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data' data(initializer_list<_Tp> __il) noexcept ^ /usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data' data(_Container& __cont) noexcept(noexcept(__cont.data())) ^ /usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data' data(const _Container& __cont) noexcept(noexcept(__cont.data())) ^ /usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data' data(_Tp (&__array)[_Nm]) noexcept ^
Dataset d is now a dataset with two observable (x,w) with 1000 entries
data->Print();
input_line_56:2:2: error: reference to 'data' is ambiguous data->Print(); ^ input_line_50:2:30: note: candidate found by name lookup is 'data' std::unique_ptr<RooDataSet> data{p0.generate(x, 1000)}; ^ /usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data' data(initializer_list<_Tp> __il) noexcept ^ /usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data' data(_Container& __cont) noexcept(noexcept(__cont.data())) ^ /usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data' data(const _Container& __cont) noexcept(noexcept(__cont.data())) ^ /usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data' data(_Tp (&__array)[_Nm]) noexcept ^
Instruct dataset wdata in interpret w as event weight rather than as observable
RooDataSet wdata(data->GetName(), data->GetTitle(), data.get(), *data->get(), 0, w->GetName());
input_line_57:2:19: error: reference to 'data' is ambiguous RooDataSet wdata(data->GetName(), data->GetTitle(), data.get(), *data->get(), 0, w->GetName()); ^ input_line_50:2:30: note: candidate found by name lookup is 'data' std::unique_ptr<RooDataSet> data{p0.generate(x, 1000)}; ^ /usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data' data(initializer_list<_Tp> __il) noexcept ^ /usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data' data(_Container& __cont) noexcept(noexcept(__cont.data())) ^ /usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data' data(const _Container& __cont) noexcept(noexcept(__cont.data())) ^ /usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data' data(_Tp (&__array)[_Nm]) noexcept ^ input_line_57:2:19: error: unknown type name 'data' RooDataSet wdata(data->GetName(), data->GetTitle(), data.get(), *data->get(), 0, w->GetName()); ^ input_line_57:2:23: error: expected ')' RooDataSet wdata(data->GetName(), data->GetTitle(), data.get(), *data->get(), 0, w->GetName()); ^ input_line_57:2:18: note: to match this '(' RooDataSet wdata(data->GetName(), data->GetTitle(), data.get(), *data->get(), 0, w->GetName()); ^
Dataset d is now a dataset with one observable (x) with 1000 entries and a sum of weights of ~430K
wdata.Print();
input_line_59:2:3: error: use of undeclared identifier 'wdata' (wdata.Print()) ^ Error in <HandleInterpreterException>: Error evaluating expression (wdata.Print()) Execution of your code was aborted.
Construction quadratic polynomial pdf for fitting
RooRealVar a0("a0", "a0", 1);
RooRealVar a1("a1", "a1", 0, -1, 1);
RooRealVar a2("a2", "a2", 1, 0, 10);
RooPolynomial p2("p2", "p2", x, RooArgList(a0, a1, a2), 0);
Fit quadratic polynomial to weighted data
NOTE: A plain Maximum likelihood fit to weighted data does in general NOT result in correct error estimates, unless individual event weights represent Poisson statistics themselves.
Fit with 'wrong' errors
std::unique_ptr<RooFitResult> r_ml_wgt{p2.fitTo(wdata, Save(), PrintLevel(-1))};
input_line_61:2:57: error: cannot initialize an array element of type 'void *' with an rvalue of type 'RooCmdArg (*)(bool)' std::unique_ptr<RooFitResult> r_ml_wgt{p2.fitTo(wdata, Save(), PrintLevel(-1))}; ^~~~ input_line_61:2:65: error: cannot initialize an array element of type 'void *' with an rvalue of type 'RooCmdArg (*)(Int_t)' (aka 'RooCmdArg (*)(int)') std::unique_ptr<RooFitResult> r_ml_wgt{p2.fitTo(wdata, Save(), PrintLevel(-1))}; ^~~~~~~~~~
A first order correction to estimated parameter errors in an (unbinned) ML fit can be obtained by calculating the covariance matrix as
V' = V C-1 V
where V is the covariance matrix calculated from a fit to -logL = - sum [ w_i log f(x_i) ] and C is the covariance matrix calculated from -logL' = -sum [ w_i^2 log f(x_i) ] (i.e. the weights are applied squared)
A fit in this mode can be performed as follows:
std::unique_ptr<RooFitResult> r_ml_wgt_corr{p2.fitTo(wdata, Save(), SumW2Error(true), PrintLevel(-1))};
input_line_62:2:62: error: cannot initialize an array element of type 'void *' with an rvalue of type 'RooCmdArg (*)(bool)' std::unique_ptr<RooFitResult> r_ml_wgt_corr{p2.fitTo(wdata, Save(), SumW2Error(true), PrintLevel(-1))}; ^~~~ input_line_62:2:70: error: cannot initialize an array element of type 'void *' with an rvalue of type 'RooCmdArg (*)(bool)' std::unique_ptr<RooFitResult> r_ml_wgt_corr{p2.fitTo(wdata, Save(), SumW2Error(true), PrintLevel(-1))}; ^~~~~~~~~~ input_line_62:2:88: error: cannot initialize an array element of type 'void *' with an rvalue of type 'RooCmdArg (*)(Int_t)' (aka 'RooCmdArg (*)(int)') std::unique_ptr<RooFitResult> r_ml_wgt_corr{p2.fitTo(wdata, Save(), SumW2Error(true), PrintLevel(-1))}; ^~~~~~~~~~
Construct plot frame
RooPlot *frame = x.frame(Title("Unbinned ML fit, binned chi^2 fit to weighted data"));
Plot data using sum-of-weights-squared error rather than Poisson errors
wdata.plotOn(frame, DataError(RooAbsData::SumW2));
input_line_64:2:32: error: cannot take the address of an rvalue of type 'RooAbsData::ErrorType' wdata.plotOn(frame, DataError(RooAbsData::SumW2)); ^~~~~~~~~~~~~~~~~ Error while creating dynamic expression for: wdata.plotOn(frame, DataError(RooAbsData::SumW2))
Overlay result of 2nd order polynomial fit to weighted data
p2.plotOn(frame);
Construct a pdf with the same shape as p0 after weighting
RooGenericPdf genPdf("genPdf", "x*x+10", x);
Sample a dataset with the same number of events as data
std::unique_ptr<RooDataSet> data2{genPdf.generate(x, 1000)};
[#1] INFO:NumericIntegration -- RooRealIntegral::init(genPdf_Int[x]) using numeric integrator RooIntegrator1D to calculate Int(x) [#1] INFO:NumericIntegration -- RooRealIntegral::init(genPdf_Int[x]) using numeric integrator RooIntegrator1D to calculate Int(x)
Sample a dataset with the same number of weights as data
std::unique_ptr<RooDataSet> data3{genPdf.generate(x, 43000)};
[#1] INFO:NumericIntegration -- RooRealIntegral::init(genPdf_Int[x]) using numeric integrator RooIntegrator1D to calculate Int(x) [#1] INFO:NumericIntegration -- RooRealIntegral::init(genPdf_Int[x]) using numeric integrator RooIntegrator1D to calculate Int(x)
Fit the 2nd order polynomial to both unweighted datasets and save the results for comparison
std::unique_ptr<RooFitResult> r_ml_unw10{p2.fitTo(*data2, Save(), PrintLevel(-1))};
std::unique_ptr<RooFitResult> r_ml_unw43{p2.fitTo(*data3, Save(), PrintLevel(-1))};
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { _ZNSt10unique_ptrI13RooLinkedListSt14default_deleteIS0_EEC2IS2_vEEPS0_, _ZNKSt15__uniq_ptr_implI12RooFitResultSt14default_deleteIS0_EE6_M_ptrEv, _ZNSt10unique_ptrI13RooLinkedListSt14default_deleteIS0_EE11get_deleterEv, _ZNSt10unique_ptrI12RooFitResultSt14default_deleteIS0_EEC1IS2_vEEPS0_, _ZNSt10unique_ptrI12RooFitResultSt14default_deleteIS0_EED2Ev, _ZSt12__get_helperILm0EP13RooLinkedListJSt14default_deleteIS0_EEERKT0_RKSt11_Tuple_implIXT_EJS4_DpT1_EE, _ZNKSt14default_deleteI13RooLinkedListEclEPS0_, _ZNSt5tupleIJP12RooFitResultSt14default_deleteIS0_EEEC1IS1_S3_Lb1EEEv, _ZSt3getILm0EJP10RooDataSetSt14default_deleteIS0_EEERKNSt13tuple_elementIXT_ESt5tupleIJDpT0_EEE4typeERKS8_, _ZNKSt10unique_ptrI13RooLinkedListSt14default_deleteIS0_EEptEv, _ZSt3getILm1EJP13RooLinkedListSt14default_deleteIS0_EEERNSt13tuple_elementIXT_ESt5tupleIJDpT0_EEE4typeERS8_, _ZSt11make_uniqueI13RooLinkedListJEENSt9_MakeUniqIT_E15__single_objectEDpOT0_, _ZNSt10_Head_baseILm0EP13RooLinkedListLb0EE7_M_headERS2_, _ZNSt10unique_ptrI12RooFitResultSt14default_deleteIS0_EE11get_deleterEv, _ZNKSt16initializer_listIPK9RooCmdArgE3endEv, _ZNSt15__uniq_ptr_implI13RooLinkedListSt14default_deleteIS0_EEC1EPS0_, _ZNSt11_Tuple_implILm1EJSt14default_deleteI13RooLinkedListEEE7_M_headERS3_, _ZNSt10unique_ptrI13RooLinkedListSt14default_deleteIS0_EED2Ev, _ZNKSt14default_deleteI12RooFitResultEclEPS0_, __orc_init_func.cling-module-331, _ZN12__cling_N53710r_ml_unw43E, _ZNSt10_Head_baseILm0EP12RooFitResultLb0EE7_M_headERKS2_, _ZN6RooFit6Detail13createCmdListIJPK9RooCmdArgEEESt10unique_ptrI13RooLinkedListSt14default_deleteIS6_EES4_DpOT_, _ZN9RooAbsPdf5fitToIJ9RooCmdArgS1_EEEP12RooFitResultR10RooAbsDataDpRKT_, _ZNSt11_Tuple_implILm0EJP12RooFitResultSt14default_deleteIS0_EEE7_M_headERKS4_, $.cling-module-331.__inits.0, _ZNSt10_Head_baseILm1ESt14default_deleteI13RooLinkedListELb1EE7_M_headERS3_, _ZN12__cling_N53716__cling_Un1Qu337EPv, _ZNSt15__uniq_ptr_implI12RooFitResultSt14default_deleteIS0_EE10_M_deleterEv, _ZNKSt10unique_ptrI10RooDataSetSt14default_deleteIS0_EEdeEv, __cxx_global_var_initcling_module_331_, _ZNSt15__uniq_ptr_implI12RooFitResultSt14default_deleteIS0_EEC1EPS0_, _ZSt3getILm0EJP13RooLinkedListSt14default_deleteIS0_EEERKNSt13tuple_elementIXT_ESt5tupleIJDpT0_EEE4typeERKS8_, _ZNSt10unique_ptrI13RooLinkedListSt14default_deleteIS0_EEC1IS2_vEEPS0_, _ZSt3getILm0EJP12RooFitResultSt14default_deleteIS0_EEERKNSt13tuple_elementIXT_ESt5tupleIJDpT0_EEE4typeERKS8_, _ZNSt11_Tuple_implILm1EJSt14default_deleteI13RooLinkedListEEEC2Ev, _ZNSt11_Tuple_implILm1EJSt14default_deleteI12RooFitResultEEEC2Ev, _ZNKSt15__uniq_ptr_implI10RooDataSetSt14default_deleteIS0_EE6_M_ptrEv, _ZNKSt10unique_ptrI13RooLinkedListSt14default_deleteIS0_EEdeEv, _ZNSt10_Head_baseILm0EP13RooLinkedListLb0EEC2Ev, _ZNSt15__uniq_ptr_implI13RooLinkedListSt14default_deleteIS0_EE6_M_ptrEv, _ZNSt10unique_ptrI12RooFitResultSt14default_deleteIS0_EED1Ev, _ZSt3getILm0EJP13RooLinkedListSt14default_deleteIS0_EEERNSt13tuple_elementIXT_ESt5tupleIJDpT0_EEE4typeERS8_, _ZNSt11_Tuple_implILm0EJP12RooFitResultSt14default_deleteIS0_EEEC2Ev, _ZN7TObjectnwEm, _ZNKSt10unique_ptrI12RooFitResultSt14default_deleteIS0_EE3getEv, _ZSt12__get_helperILm0EP10RooDataSetJSt14default_deleteIS0_EEERKT0_RKSt11_Tuple_implIXT_EJS4_DpT1_EE, _ZSt12__get_helperILm0EP13RooLinkedListJSt14default_deleteIS0_EEERT0_RSt11_Tuple_implIXT_EJS4_DpT1_EE, _ZNSt10unique_ptrI12RooFitResultSt14default_deleteIS0_EEC2IS2_vEEPS0_, _ZNSt10_Head_baseILm1ESt14default_deleteI12RooFitResultELb1EEC2Ev, _ZN12__cling_N53710r_ml_unw10E, _GLOBAL__sub_I_cling_module_331, _ZSt12__get_helperILm1ESt14default_deleteI13RooLinkedListEJEERT0_RSt11_Tuple_implIXT_EJS3_DpT1_EE, _ZNSt11_Tuple_implILm0EJP13RooLinkedListSt14default_deleteIS0_EEE7_M_headERS4_, _ZNSt10_Head_baseILm0EP10RooDataSetLb0EE7_M_headERKS2_, _ZNSt15__uniq_ptr_implI13RooLinkedListSt14default_deleteIS0_EE10_M_deleterEv, _ZNSt10_Head_baseILm0EP13RooLinkedListLb0EE7_M_headERKS2_, _ZNSt5tupleIJP12RooFitResultSt14default_deleteIS0_EEEC2IS1_S3_Lb1EEEv, _ZNKSt15__uniq_ptr_implI13RooLinkedListSt14default_deleteIS0_EE6_M_ptrEv, _ZNSt5tupleIJP13RooLinkedListSt14default_deleteIS0_EEEC1IS1_S3_Lb1EEEv, _ZNSt10_Head_baseILm1ESt14default_deleteI13RooLinkedListELb1EEC2Ev, _ZNSt15__uniq_ptr_implI13RooLinkedListSt14default_deleteIS0_EEC2EPS0_, _ZNKSt16initializer_listIPK9RooCmdArgE4sizeEv, _ZNSt11_Tuple_implILm0EJP10RooDataSetSt14default_deleteIS0_EEE7_M_headERKS4_, _ZNSt15__uniq_ptr_implI12RooFitResultSt14default_deleteIS0_EEC2EPS0_, _ZNSt10_Head_baseILm0EP12RooFitResultLb0EEC2Ev, _ZNSt11_Tuple_implILm0EJP13RooLinkedListSt14default_deleteIS0_EEE7_M_headERKS4_, _ZNSt15__uniq_ptr_implI12RooFitResultSt14default_deleteIS0_EE6_M_ptrEv, _ZNSt5tupleIJP13RooLinkedListSt14default_deleteIS0_EEEC2IS1_S3_Lb1EEEv, _ZNKSt10unique_ptrI10RooDataSetSt14default_deleteIS0_EE3getEv, _ZNSt10unique_ptrI13RooLinkedListSt14default_deleteIS0_EED1Ev, _ZNSt10unique_ptrI12RooFitResultSt14default_deleteIS0_EE7releaseEv, _ZNKSt16initializer_listIPK9RooCmdArgE5beginEv, _ZSt12__get_helperILm0EP12RooFitResultJSt14default_deleteIS0_EEERKT0_RKSt11_Tuple_implIXT_EJS4_DpT1_EE, __cxx_global_var_initcling_module_331_.1, _ZNSt11_Tuple_implILm0EJP13RooLinkedListSt14default_deleteIS0_EEEC2Ev, _ZNKSt10unique_ptrI13RooLinkedListSt14default_deleteIS0_EE3getEv, _ZN6RooFit13makeOwningPtrI12RooFitResultEEPT_OSt10unique_ptrIS2_St14default_deleteIS2_EE }) } IncrementalExecutor::executeFunction: symbol '_ZSt3getILm0EJP12RooFitResultSt14default_deleteIS0_EEERNSt13tuple_elementIXT_ESt5tupleIJDpT0_EEE4typeERS8_' unresolved while linking [cling interface function]! You are probably missing the definition of std::tuple_element<0ul, std::tuple<RooFitResult*, std::default_delete<RooFitResult> > >::type& std::get<0ul, RooFitResult*, std::default_delete<RooFitResult> >(std::tuple<RooFitResult*, std::default_delete<RooFitResult> >&) Maybe you need to load the corresponding shared library? IncrementalExecutor::executeFunction: symbol '_ZSt3getILm1EJP12RooFitResultSt14default_deleteIS0_EEERNSt13tuple_elementIXT_ESt5tupleIJDpT0_EEE4typeERS8_' unresolved while linking [cling interface function]! You are probably missing the definition of std::tuple_element<1ul, std::tuple<RooFitResult*, std::default_delete<RooFitResult> > >::type& std::get<1ul, RooFitResult*, std::default_delete<RooFitResult> >(std::tuple<RooFitResult*, std::default_delete<RooFitResult> >&) Maybe you need to load the corresponding shared library?
Construct binned clone of unbinned weighted dataset
std::unique_ptr<RooAbsData> binnedData{wdata.binnedClone()};
binnedData->Print("v");
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __orc_init_func.cling-module-332, _ZN12__cling_N53816__cling_Un1Qu338EPv, $.cling-module-332.__inits.0, _ZNSt10_Head_baseILm0EP10RooAbsDataLb0EE7_M_headERKS2_, _ZNKSt15__uniq_ptr_implI10RooAbsDataSt14default_deleteIS0_EE6_M_ptrEv, _ZNSt11_Tuple_implILm0EJP10RooAbsDataSt14default_deleteIS0_EEE7_M_headERKS4_, _GLOBAL__sub_I_cling_module_332, _ZN12__cling_N53824__dynamic__cling_Un1Qu32E, __cxx_global_var_initcling_module_332_, _ZNK5cling7runtime8internal15LifetimeHandler9getMemoryEv, _ZSt12__get_helperILm0EP10RooAbsDataJSt14default_deleteIS0_EEERKT0_RKSt11_Tuple_implIXT_EJS4_DpT1_EE, _ZNKSt10unique_ptrI10RooAbsDataSt14default_deleteIS0_EEptEv, _ZN12__cling_N53810binnedDataE, _ZSt3getILm0EJP10RooAbsDataSt14default_deleteIS0_EEERKNSt13tuple_elementIXT_ESt5tupleIJDpT0_EEE4typeERKS8_, __cxx_global_var_initcling_module_332_.2, _ZNKSt10unique_ptrI10RooAbsDataSt14default_deleteIS0_EE3getEv }) } IncrementalExecutor::executeFunction: symbol '_ZN5cling7runtime8internal15LifetimeHandlerD1Ev' unresolved while linking [cling interface function]! You are probably missing the definition of cling::runtime::internal::LifetimeHandler::~LifetimeHandler() Maybe you need to load the corresponding shared library? IncrementalExecutor::executeFunction: symbol '_ZN5cling7runtime8internal15LifetimeHandlerC1EPNS1_15DynamicExprInfoEPN5clang11DeclContextEPKcPNS_11InterpreterE' unresolved while linking [cling interface function]! You are probably missing the definition of cling::runtime::internal::LifetimeHandler::LifetimeHandler(cling::runtime::internal::DynamicExprInfo*, clang::DeclContext*, char const*, cling::Interpreter*) Maybe you need to load the corresponding shared library?
Perform chi2 fit to binned weighted dataset using sum-of-weights errors
NB: Within the usual approximations of a chi2 fit, a chi2 fit to weighted data using sum-of-weights-squared errors does give correct error estimates
std::unique_ptr<RooAbsReal> chi2{
p2.createChi2(static_cast<RooDataHist &>(*binnedData), DataError(RooAbsData::SumW2))};
RooMinimizer m(*chi2);
m.migrad();
m.hesse();
cling JIT session error: Failed to materialize symbols: { (main, { _ZNKSt10unique_ptrI10RooAbsDataSt14default_deleteIS0_EE3getEv }) } [runStaticInitializersOnce]: Failed to materialize symbols: { (main, { _ZN12__cling_N5394chi2E, _ZNSt15__uniq_ptr_implI10RooAbsRealSt14default_deleteIS0_EEC2EPS0_, _ZNSt15__uniq_ptr_implI10RooAbsRealSt14default_deleteIS0_EEC1EPS0_, __orc_init_func.cling-module-333, _GLOBAL__sub_I_cling_module_333, _ZSt12__get_helperILm0EP10RooAbsRealJSt14default_deleteIS0_EEERT0_RSt11_Tuple_implIXT_EJS4_DpT1_EE, _ZNSt10unique_ptrI10RooAbsRealSt14default_deleteIS0_EED1Ev, _ZN12__cling_N53916__cling_Un1Qu339EPv, _ZNSt10unique_ptrI10RooAbsRealSt14default_deleteIS0_EE11get_deleterEv, _ZNSt10unique_ptrI10RooAbsRealSt14default_deleteIS0_EEC1IS2_vEEPS0_, $.cling-module-333.__inits.0, __cxx_global_var_initcling_module_333_, _ZN12__cling_N5391mE, _ZN12RooMinimizer6ConfigC1Ev, _ZSt3getILm1EJP10RooAbsRealSt14default_deleteIS0_EEERNSt13tuple_elementIXT_ESt5tupleIJDpT0_EEE4typeERS8_, _ZNSt10unique_ptrI10RooAbsRealSt14default_deleteIS0_EEC2IS2_vEEPS0_, _ZSt12__get_helperILm0EP10RooAbsRealJSt14default_deleteIS0_EEERKT0_RKSt11_Tuple_implIXT_EJS4_DpT1_EE, __cxx_global_var_initcling_module_333_.1, _ZNSt10_Head_baseILm1ESt14default_deleteI10RooAbsRealELb1EEC2Ev, _ZNKSt15__uniq_ptr_implI10RooAbsRealSt14default_deleteIS0_EE6_M_ptrEv, _ZNSt15__uniq_ptr_implI10RooAbsRealSt14default_deleteIS0_EE6_M_ptrEv, _ZNSt10_Head_baseILm0EP10RooAbsRealLb0EE7_M_headERS2_, _ZNSt11_Tuple_implILm0EJP10RooAbsRealSt14default_deleteIS0_EEE7_M_headERKS4_, _ZNSt10_Head_baseILm0EP10RooAbsRealLb0EE7_M_headERKS2_, _ZNKSt10unique_ptrI10RooAbsRealSt14default_deleteIS0_EEdeEv, _ZNSt11_Tuple_implILm0EJP10RooAbsRealSt14default_deleteIS0_EEE7_M_headERS4_, _ZNKSt10unique_ptrI10RooAbsRealSt14default_deleteIS0_EE3getEv, _ZNSt15__uniq_ptr_implI10RooAbsRealSt14default_deleteIS0_EE10_M_deleterEv, _ZNSt5tupleIJP10RooAbsRealSt14default_deleteIS0_EEEC1IS1_S3_Lb1EEEv, _ZNSt11_Tuple_implILm1EJSt14default_deleteI10RooAbsRealEEEC2Ev, _ZN12RooMinimizer6ConfigC2Ev, _ZN12RooMinimizer6ConfigD1Ev, _ZNSt11_Tuple_implILm0EJP10RooAbsRealSt14default_deleteIS0_EEEC2Ev, _ZNKSt10unique_ptrI10RooAbsDataSt14default_deleteIS0_EEdeEv, _ZNSt10_Head_baseILm0EP10RooAbsRealLb0EEC2Ev, _ZSt12__get_helperILm1ESt14default_deleteI10RooAbsRealEJEERT0_RSt11_Tuple_implIXT_EJS3_DpT1_EE, _ZSt3getILm0EJP10RooAbsRealSt14default_deleteIS0_EEERNSt13tuple_elementIXT_ESt5tupleIJDpT0_EEE4typeERS8_, _ZSt3getILm0EJP10RooAbsRealSt14default_deleteIS0_EEERKNSt13tuple_elementIXT_ESt5tupleIJDpT0_EEE4typeERKS8_, _ZNSt11_Tuple_implILm1EJSt14default_deleteI10RooAbsRealEEE7_M_headERS3_, _ZNSt5tupleIJP10RooAbsRealSt14default_deleteIS0_EEEC2IS1_S3_Lb1EEEv, _ZNSt10_Head_baseILm1ESt14default_deleteI10RooAbsRealELb1EE7_M_headERS3_, _ZNSt10unique_ptrI10RooAbsRealSt14default_deleteIS0_EED2Ev, _ZN12RooMinimizer6ConfigD2Ev, _ZNKSt14default_deleteI10RooAbsRealEclEPS0_ }) }
Plot chi^2 fit result on frame as well
std::unique_ptr<RooFitResult> r_chi2_wgt{m.save()};
p2.plotOn(frame, LineStyle(kDashed), LineColor(kRed));
cling JIT session error: Failed to materialize symbols: { (main, { _ZNSt10unique_ptrI12RooFitResultSt14default_deleteIS0_EED1Ev }) } [runStaticInitializersOnce]: Failed to materialize symbols: { (main, { $.cling-module-334.__inits.0, _ZN12__cling_N54016__cling_Un1Qu340EPv, _GLOBAL__sub_I_cling_module_334, __cxx_global_var_initcling_module_334_, _ZN12__cling_N54010r_chi2_wgtE, __orc_init_func.cling-module-334 }) }
Note that ML fit on 1Kevt of weighted data is closer to result of ML fit on 43Kevt of unweighted data than to 1Kevt of unweighted data, whereas the reference chi^2 fit with SumW2 error gives a result closer to that of an unbinned ML fit to 1Kevt of unweighted data.
cout << "==> ML Fit results on 1K unweighted events" << endl;
r_ml_unw10->Print();
cout << "==> ML Fit results on 43K unweighted events" << endl;
r_ml_unw43->Print();
cout << "==> ML Fit results on 1K weighted events with a summed weight of 43K" << endl;
r_ml_wgt->Print();
cout << "==> Corrected ML Fit results on 1K weighted events with a summed weight of 43K" << endl;
r_ml_wgt_corr->Print();
cout << "==> Chi2 Fit results on 1K weighted events with a summed weight of 43K" << endl;
r_chi2_wgt->Print();
new TCanvas("rf403_weightedevts", "rf403_weightedevts", 600, 600);
gPad->SetLeftMargin(0.15);
frame->GetYaxis()->SetTitleOffset(1.8);
frame->Draw();
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __orc_init_func.cling-module-331 }) } cling JIT session error: Failed to materialize symbols: { (main, { _ZN12__cling_N53710r_ml_unw10E }) }
Draw all canvases
%jsroot on
gROOT->GetListOfCanvases()->Draw()