void demo() { RooWorkspace w("w",1) ; w.factory("SUM::genmodel(1000*Gaussian::g(x[-10,10],mg[0],3),1000*Uniform::u(x))") ; w::x.setBins(10) ; // The 'observed' data RooDataSet* obsData = w::genmodel.generate(w::x,AllBinned(),NumEvents(2000)) ; // Make HistFuncs for sigma and background to serve as templates RooDataHist* dh_bkg = w::u.generateBinned(w::x,1000) ; RooDataHist* dh_sig = w::g.generateBinned(w::x,1000) ; RooRealVar Asig("Asig","Asig",1,0.01,10) ; RooRealVar Abkg("Abkg","Abkg",1,0.01,10) ; // ***** Case 0 - 'Rigid templates' ***** // Construct histogram shapes for signal and background RooHistFunc p_h_sig("p_h_sig","p_h_sig",w::x,*dh_sig) ; RooHistFunc p_h_bkg("p_h_bkg","p_h_bkg",w::x,*dh_bkg) ; // Construct the sum of these RooRealSumPdf model0("model0","model0",RooArgList(p_h_sig,p_h_bkg),RooArgList(Asig,Abkg),kTRUE) ; // ***** Case 1 - 'Beeston Barlow' ***** // Construct parameterized histogram shapes for signal and background RooParamHistFunc p_ph_sig("p_ph_sig","p_ph_sig",*dh_sig) ; RooParamHistFunc p_ph_bkg("p_ph_bkg","p_ph_bkg",*dh_bkg) ; // Construct the sum of these RooRealSumPdf model_tmp("sp_ph","sp_ph",RooArgList(p_ph_sig,p_ph_bkg),RooArgList(Asig,Abkg),kTRUE) ; // Construct the subsidiary poisson measurements constraining the histogram parameters RooHistConstraint hc_sig("hc_sig","hc_sig",p_ph_sig) ; RooHistConstraint hc_bkg("hc_bkg","hc_bkg",p_ph_bkg) ; // Construct the joint model RooProdPdf model1("model1","model1",RooArgSet(hc_sig,hc_bkg),Conditional(model_tmp,w::x)) ; // ***** Case 2 - 'Beeston Barlow' light ***** // Construct the background histogram shape, using the same parameters as the signal histogram RooParamHistFunc p_ph_bkg2("p_ph_bkg","p_ph_bkg",*dh_bkg,p_ph_sig,1) ; // Construct the sum of signal and background2 RooRealSumPdf model2_tmp("sp_ph","sp_ph",RooArgList(p_ph_sig,p_ph_bkg2),RooArgList(Asig,Abkg),kTRUE) ; // Construct the subsidiary poisson measurements constraining the sum of the histograms RooHistConstraint hc_sigbkg("hc_sigbkg","hc_sigbkg",RooArgSet(p_ph_sig,p_ph_bkg2)) ; // Construct the joint model RooProdPdf model2("model2","model2",hc_sigbkg,Conditional(model2_tmp,w::x)) ; model0.fitTo(*obsData) ; Double_t asig_val0 = Asig.getVal() ; Double_t asig_err0 = Asig.getError() ; model1.fitTo(*obsData) ; Double_t asig_val1 = Asig.getVal() ; Double_t asig_err1 = Asig.getError() ; model2.fitTo(*obsData) ; Double_t asig_val2 = Asig.getVal() ; Double_t asig_err2 = Asig.getError() ; cout << "Asig [normal ] = " << asig_val0 << " +/- " << asig_err0 << endl ; cout << "Asig [BB ] = " << asig_val1 << " +/- " << asig_err1 << endl ; cout << "Asig [BBlight] = " << asig_val2 << " +/- " << asig_err2 << endl ; }