本文整理汇总了C++中ModelConfig::SetNuisanceParameters方法的典型用法代码示例。如果您正苦于以下问题:C++ ModelConfig::SetNuisanceParameters方法的具体用法?C++ ModelConfig::SetNuisanceParameters怎么用?C++ ModelConfig::SetNuisanceParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelConfig
的用法示例。
在下文中一共展示了ModelConfig::SetNuisanceParameters方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: upper_limit_Bayesian_MCMC
void upper_limit_Bayesian_MCMC(Model* model,double confidence,int Niters){
cout<<"///////////////////////////////////////////////////////////////////////////////////////////"<<endl;
cout<<"Calculating upper limit with the MCMC method"<<endl;
cout<<"///////////////////////////////////////////////////////////////////////////////////////////"<<endl;
RooWorkspace* wspace = new RooWorkspace("wspace");
ModelConfig* modelConfig = new ModelConfig("bayes");
modelConfig->SetWorkspace(*wspace);
modelConfig->SetPdf(*model->get_complete_likelihood());
modelConfig->SetPriorPdf(*model->get_POI_prior());
modelConfig->SetParametersOfInterest(*model->get_POI_set());
// modelConfig->SetNuisanceParameters();
modelConfig->SetNuisanceParameters(*model->get_nuisance_set());
//configure the calculator
//model->Print();
cout<<" POI size "<<model->get_POI_set()->getSize()<<endl;
RooRealVar* firstPOI = (RooRealVar*) modelConfig->GetParametersOfInterest()->first();
MCMCCalculator mcmccalc(*model->get_data(), *modelConfig );
mcmccalc.SetTestSize(1-confidence);
mcmccalc.SetLeftSideTailFraction(0);
mcmccalc.SetNumIters(Niters);
MCMCInterval* interval = mcmccalc.GetInterval();
double ul = interval->UpperLimit(*firstPOI);
cout<<"UpperLimit: "<<ul<<endl;
}
示例2: upper_limit_FC
double upper_limit_FC(Model* model,double confidence){
cout<<"///////////////////////////////////////////////////////////////////////////////////////////"<<endl;
cout<<"Calculating upper limit with the FC method"<<endl;
cout<<"///////////////////////////////////////////////////////////////////////////////////////////"<<endl;
RooWorkspace* wspace = new RooWorkspace("wspace");
ModelConfig* modelConfig = new ModelConfig("FC");
modelConfig->SetWorkspace(*wspace);
modelConfig->SetPdf(*model->get_complete_likelihood());
modelConfig->SetPriorPdf(*model->get_POI_prior());
modelConfig->SetParametersOfInterest(*model->get_POI_set());
//modelConfig->SetParametersOfInterest(*wspace->set("poi"));
//modelConfig->SetNuisanceParameters(*wspace->set("nuis"));
// modelConfig->SetNuisanceParameters();
modelConfig->SetNuisanceParameters(*model->get_nuisance_set());
RooDataSet* data = model->get_data();
RooArgSet* poi= model->get_POI_set();
//configure the calculator
//model->Print();
cout<<" POI size "<<model->get_POI_set()->getSize()<<endl;
// use FeldmaCousins (takes ~20 min)
FeldmanCousins fc(*data, *modelConfig);
fc.SetConfidenceLevel(0.95); //0.9 central limit=0.95 upper limit
//fc.SetTestSize(.1); // set size of test
//number counting: dataset always has 1 entry with N events observed
fc.FluctuateNumDataEntries(false);
fc.UseAdaptiveSampling(true);
fc.SetNBins(200);
PointSetInterval* fcInt = NULL;
//ConfInterval* interval = 0;
RooRealVar* firstPOI = (RooRealVar*) modelConfig->GetParametersOfInterest()->first();
// if(doFeldmanCousins){ // takes 7 minutes
fcInt = (PointSetInterval*) fc.GetInterval(); // fix cast
//xs}
//interval = (PointSetInterval*) fc.GetInterval();
cout<<" ["<<fcInt->LowerLimit( *firstPOI ) << ", " <<
fcInt->UpperLimit( *firstPOI ) << "]" << endl;
cout<<" ["<<fcInt->LowerLimit( *firstPOI ) << ", " <<
fcInt->UpperLimit( *firstPOI ) << "]" << endl;
double ul=fcInt->UpperLimit( *firstPOI );
//double ul=interval->UpperLimit( *firstPOI );
return ul;
}
示例3: workspace_preparer
//.........这里部分代码省略.........
RooArgSet poi(*newworkspace->var("sigma"), "poi");
//Set Nuisnaces
RooArgSet nuis(*newworkspace->var("prime_lumi"), *newworkspace->var("prime_eff"), *newworkspace->var("prime_rho"), *newworkspace->var("bprime"));
// priors (for Bayesian calculation)
newworkspace->factory("Uniform::prior_signal(sigma)"); // for parameter of interest
newworkspace->factory("Uniform::prior_bg_b(bprime)"); // for data driven nuisance parameter
newworkspace->factory("PROD::prior(prior_signal,prior_bg_b)"); // total prior
//Observed data is pulled from histogram.
//TFile *data_file = new TFile(data_file_name);
TFile *data_file = new TFile(data_file_name);
TH2D *data_hist = (TH2D *)data_file->Get(data_hist_name_in_file);
RooDataHist *pData = new RooDataHist("data", "data", obs, data_hist);
newworkspace->import(*pData);
// Now, we will draw our data from a RooDataHist.
/*TFile *data_file = new TFile(data_file_name);
TTree *data_tree = (TTree *) data_file->Get(data_hist_name_in_file);
RooDataSet *pData = new RooDataSet("data", "data", data_tree, obs);
newworkspace->import(*pData);*/
// Craft the signal+background model
ModelConfig * pSbModel = new ModelConfig("SbModel");
pSbModel->SetWorkspace(*newworkspace);
pSbModel->SetPdf(*newworkspace->pdf("model"));
pSbModel->SetPriorPdf(*newworkspace->pdf("prior"));
pSbModel->SetParametersOfInterest(poi);
pSbModel->SetNuisanceParameters(nuis);
pSbModel->SetObservables(obs);
pSbModel->SetGlobalObservables(globalObs);
// set all but obs, poi and nuisance to const
SetConstants(newworkspace, pSbModel);
newworkspace->import(*pSbModel);
// background-only model
// use the same PDF as s+b, with sig=0
// POI value under the background hypothesis
// (We will set the value to 0 later)
Double_t poiValueForBModel = 0.0;
ModelConfig* pBModel = new ModelConfig(*(RooStats::ModelConfig *)newworkspace->obj("SbModel"));
pBModel->SetName("BModel");
pBModel->SetWorkspace(*newworkspace);
newworkspace->import(*pBModel);
// find global maximum with the signal+background model
// with conditional MLEs for nuisance parameters
// and save the parameter point snapshot in the Workspace
// - safer to keep a default name because some RooStats calculators
// will anticipate it
RooAbsReal * pNll = pSbModel->GetPdf()->createNLL(*pData);
RooAbsReal * pProfile = pNll->createProfile(RooArgSet());
pProfile->getVal(); // this will do fit and set POI and nuisance parameters to fitted values
RooArgSet * pPoiAndNuisance = new RooArgSet();
if(pSbModel->GetNuisanceParameters())
pPoiAndNuisance->add(*pSbModel->GetNuisanceParameters());
pPoiAndNuisance->add(*pSbModel->GetParametersOfInterest());
cout << "\nWill save these parameter points that correspond to the fit to data" << endl;
示例4: TwoBinInstructional
// implementation
void TwoBinInstructional( void ){
// let's time this example
TStopwatch t;
t.Start();
// set RooFit random seed for reproducible results
RooRandom::randomGenerator()->SetSeed(4357);
// make model
RooWorkspace * pWs = new RooWorkspace("ws");
// derived from data
pWs->factory("xsec[0.2,0,2]"); // POI
pWs->factory("bg_b[10,0,50]"); // data driven nuisance
// predefined nuisances
pWs->factory("lumi[100,0,1000]");
pWs->factory("eff_a[0.2,0,1]");
pWs->factory("eff_b[0.05,0,1]");
pWs->factory("tau[0,1]");
pWs->factory("xsec_bg_a[0.05]"); // constant
pWs->var("xsec_bg_a")->setConstant(1);
// channel a (signal): lumi*xsec*eff_a + lumi*bg_a + tau*bg_b
pWs->factory("prod::sig_a(lumi,xsec,eff_a)");
pWs->factory("prod::bg_a(lumi,xsec_bg_a)");
pWs->factory("prod::tau_bg_b(tau, bg_b)");
pWs->factory("Poisson::pdf_a(na[14,0,100],sum::mu_a(sig_a,bg_a,tau_bg_b))");
// channel b (control): lumi*xsec*eff_b + bg_b
pWs->factory("prod::sig_b(lumi,xsec,eff_b)");
pWs->factory("Poisson::pdf_b(nb[11,0,100],sum::mu_b(sig_b,bg_b))");
// nuisance constraint terms (systematics)
pWs->factory("Lognormal::l_lumi(lumi,nom_lumi[100,0,1000],sum::kappa_lumi(1,d_lumi[0.1]))");
pWs->factory("Lognormal::l_eff_a(eff_a,nom_eff_a[0.20,0,1],sum::kappa_eff_a(1,d_eff_a[0.05]))");
pWs->factory("Lognormal::l_eff_b(eff_b,nom_eff_b[0.05,0,1],sum::kappa_eff_b(1,d_eff_b[0.05]))");
pWs->factory("Lognormal::l_tau(tau,nom_tau[0.50,0,1],sum::kappa_tau(1,d_tau[0.05]))");
//pWs->factory("Lognormal::l_bg_a(bg_a,nom_bg_a[0.05,0,1],sum::kappa_bg_a(1,d_bg_a[0.10]))");
// complete model PDF
pWs->factory("PROD::model(pdf_a,pdf_b,l_lumi,l_eff_a,l_eff_b,l_tau)");
// Now create sets of variables. Note that we could use the factory to
// create sets but in that case many of the sets would be duplicated
// when the ModelConfig objects are imported into the workspace. So,
// we create the sets outside the workspace, and only the needed ones
// will be automatically imported by ModelConfigs
// observables
RooArgSet obs(*pWs->var("na"), *pWs->var("nb"), "obs");
// global observables
RooArgSet globalObs(*pWs->var("nom_lumi"), *pWs->var("nom_eff_a"), *pWs->var("nom_eff_b"),
*pWs->var("nom_tau"),
"global_obs");
// parameters of interest
RooArgSet poi(*pWs->var("xsec"), "poi");
// nuisance parameters
RooArgSet nuis(*pWs->var("lumi"), *pWs->var("eff_a"), *pWs->var("eff_b"), *pWs->var("tau"), "nuis");
// priors (for Bayesian calculation)
pWs->factory("Uniform::prior_xsec(xsec)"); // for parameter of interest
pWs->factory("Uniform::prior_bg_b(bg_b)"); // for data driven nuisance parameter
pWs->factory("PROD::prior(prior_xsec,prior_bg_b)"); // total prior
// create data
pWs->var("na")->setVal(14);
pWs->var("nb")->setVal(11);
RooDataSet * pData = new RooDataSet("data","",obs);
pData->add(obs);
pWs->import(*pData);
//pData->Print();
// signal+background model
ModelConfig * pSbModel = new ModelConfig("SbModel");
pSbModel->SetWorkspace(*pWs);
pSbModel->SetPdf(*pWs->pdf("model"));
pSbModel->SetPriorPdf(*pWs->pdf("prior"));
pSbModel->SetParametersOfInterest(poi);
pSbModel->SetNuisanceParameters(nuis);
pSbModel->SetObservables(obs);
pSbModel->SetGlobalObservables(globalObs);
// set all but obs, poi and nuisance to const
SetConstants(pWs, pSbModel);
pWs->import(*pSbModel);
// background-only model
// use the same PDF as s+b, with xsec=0
// POI value under the background hypothesis
Double_t poiValueForBModel = 0.0;
ModelConfig* pBModel = new ModelConfig(*(RooStats::ModelConfig *)pWs->obj("SbModel"));
pBModel->SetName("BModel");
pBModel->SetWorkspace(*pWs);
//.........这里部分代码省略.........
示例5: new_RA4
void new_RA4(){
// let's time this challenging example
TStopwatch t;
t.Start();
// set RooFit random seed for reproducible results
RooRandom::randomGenerator()->SetSeed(4357);
// make model
RooWorkspace* wspace = new RooWorkspace("wspace");
wspace->factory("Gaussian::sigCons(prime_SigEff[0,-5,5], nom_SigEff[0,-5,5], 1)");
wspace->factory("expr::SigEff('1.0*pow(1.20,@0)',prime_SigEff)"); // // 1+-20%, 1.20=exp(20%)
wspace->factory("Poisson::on(non[0,50], sum::splusb(prod::SigUnc(s[0,0,50],SigEff),mainb[8.8,0,50],dilep[0.9,0,20],tau[2.3,0,20],QCD[0.,0,10],MC[0.1,0,4]))");
wspace->factory("Gaussian::mcCons(prime_rho[0,-5,5], nom_rho[0,-5,5], 1)");
wspace->factory("expr::rho('1.0*pow(1.39,@0)',prime_rho)"); // // 1+-39%
wspace->factory("Poisson::off(noff[0,200], prod::rhob(mainb,rho,mu_plus_e[0.74,0.01,10],1.08))");
wspace->factory("Gaussian::mcCons2(mu_plus_enom[0.74,0.01,4], mu_plus_e, sigmatwo[.05])");
wspace->factory("Gaussian::dilep_pred(dilep_nom[0.9,0,20], dilep, sigma3[2.2])");
wspace->factory("Gaussian::tau_pred(tau_nom[2.3,0,20], tau, sigma4[0.5])");
wspace->factory("Gaussian::QCD_pred(QCD_nom[0.0,0,10], QCD, sigma5[1.0])");
wspace->factory("Gaussian::MC_pred(MC_nom[0.1,0.01,4], MC, sigma7[0.14])");
wspace->factory("PROD::model(on,off,mcCons,mcCons2,sigCons,dilep_pred,tau_pred,QCD_pred,MC_pred)");
RooArgSet obs(*wspace->var("non"), *wspace->var("noff"), *wspace->var("mu_plus_enom"), *wspace->var("dilep_nom"), *wspace->var("tau_nom"), "obs");
obs.add(*wspace->var("QCD_nom")); obs.add(*wspace->var("MC_nom"));
RooArgSet globalObs(*wspace->var("nom_SigEff"), *wspace->var("nom_rho"), "global_obs");
// fix global observables to their nominal values
wspace->var("nom_SigEff")->setConstant();
wspace->var("nom_rho")->setConstant();
RooArgSet poi(*wspace->var("s"), "poi");
RooArgSet nuis(*wspace->var("mainb"), *wspace->var("prime_rho"), *wspace->var("prime_SigEff"), *wspace->var("mu_plus_e"), *wspace->var("dilep"), *wspace->var("tau"), "nuis");
nuis.add(*wspace->var("QCD")); nuis.add(*wspace->var("MC"));
wspace->factory("Uniform::prior_poi({s})");
wspace->factory("Uniform::prior_nuis({mainb,mu_plus_e,dilep,tau,QCD,MC})");
wspace->factory("PROD::prior(prior_poi,prior_nuis)");
wspace->var("non")->setVal(8); //observed
//wspace->var("non")->setVal(12); //expected observation
wspace->var("noff")->setVal(7); //observed events in control region
wspace->var("mu_plus_enom")->setVal(0.74);
wspace->var("dilep_nom")->setVal(0.9);
wspace->var("tau_nom")->setVal(2.3);
wspace->var("QCD")->setVal(0.0);
wspace->var("MC")->setVal(0.1);
RooDataSet * data = new RooDataSet("data","",obs);
data->add(obs);
wspace->import(*data);
/////////////////////////////////////////////////////
// Now the statistical tests
// model config
ModelConfig* pSbModel = new ModelConfig("SbModel");
pSbModel->SetWorkspace(*wspace);
pSbModel->SetPdf(*wspace->pdf("model"));
pSbModel->SetPriorPdf(*wspace->pdf("prior"));
pSbModel->SetParametersOfInterest(poi);
pSbModel->SetNuisanceParameters(nuis);
pSbModel->SetObservables(obs);
pSbModel->SetGlobalObservables(globalObs);
wspace->import(*pSbModel);
// set all but obs, poi and nuisance to const
SetConstants(wspace, pSbModel);
wspace->import(*pSbModel);
Double_t poiValueForBModel = 0.0;
ModelConfig* pBModel = new ModelConfig(*(RooStats::ModelConfig *)wspace->obj("SbModel"));
pBModel->SetName("BModel");
pBModel->SetWorkspace(*wspace);
wspace->import(*pBModel);
RooAbsReal * pNll = pSbModel->GetPdf()->createNLL(*data);
RooAbsReal * pProfile = pNll->createProfile(RooArgSet());
pProfile->getVal(); // this will do fit and set POI and nuisance parameters to fitted values
RooArgSet * pPoiAndNuisance = new RooArgSet();
//if(pSbModel->GetNuisanceParameters())
// pPoiAndNuisance->add(*pSbModel->GetNuisanceParameters());
pPoiAndNuisance->add(*pSbModel->GetParametersOfInterest());
cout << "\nWill save these parameter points that correspond to the fit to data" << endl;
pPoiAndNuisance->Print("v");
pSbModel->SetSnapshot(*pPoiAndNuisance);
delete pProfile;
delete pNll;
delete pPoiAndNuisance;
//.........这里部分代码省略.........
示例6: workspace
//.........这里部分代码省略.........
pdflist.add( *allNuisancePdfs ) ;
pdflist.Print() ;
printf("\n") ;
RooProdPdf* likelihood = new RooProdPdf( "likelihood", "hbb likelihood", pdflist ) ;
likelihood->Print() ;
//-------------------------------------------------------------------------
// printf("\n\n Running a test fit.\n\n") ;
// dsObserved -> Print() ;
// dsObserved -> printMultiline(cout, 1, kTRUE, "") ;
// printf("\n\n =============================================\n\n") ;
// likelihood -> fitTo( *dsObserved, PrintLevel(3), Hesse(0), Minos(0) ) ;
// printf("\n\n =============================================\n\n") ;
//-- Set up RooStats models.
printf("\n\n Setting up S+B model.\n\n") ;
RooArgSet poi( *rv_sig_strength, "poi" ) ;
RooUniform signal_prior( "signal_prior", "signal_prior", *rv_sig_strength ) ;
ModelConfig sbModel ("SbModel");
sbModel.SetWorkspace( workspace ) ;
sbModel.SetPdf( *likelihood ) ;
sbModel.SetParametersOfInterest( poi );
sbModel.SetPriorPdf(signal_prior);
sbModel.SetObservables( *observedParametersList );
sbModel.SetNuisanceParameters( *allNuisances );
sbModel.SetGlobalObservables( *globalObservables );
workspace.Print() ;
printf("\n\n Doing fit for S+B model.\n" ) ; fflush(stdout) ;
RooAbsReal* pNll = sbModel.GetPdf()->createNLL(*dsObserved);
RooAbsReal* pProfile = pNll->createProfile(RooArgSet());
pProfile->getVal();
RooArgSet* pPoiAndNuisance = new RooArgSet();
pPoiAndNuisance->add(*sbModel.GetParametersOfInterest());
if(sbModel.GetNuisanceParameters()) pPoiAndNuisance->add(*sbModel.GetNuisanceParameters());
printf("\n\n Will save these parameter points that correspond to the fit to data.\n\n") ; fflush(stdout) ;
pPoiAndNuisance->Print("v");
sbModel.SetSnapshot(*pPoiAndNuisance);
workspace.import (sbModel);
delete pProfile ;
delete pNll ;
delete pPoiAndNuisance ;
printf("\n\n Setting up BG-only model.\n\n") ;
ModelConfig bModel (*(RooStats::ModelConfig *)workspace.obj("SbModel"));
bModel.SetName("BModel");
bModel.SetWorkspace(workspace);
printf("\n\n Doing fit for BG-only model.\n" ) ; fflush(stdout) ;
pNll = bModel.GetPdf()->createNLL(*dsObserved);
pProfile = pNll->createProfile(*bModel.GetParametersOfInterest());
((RooRealVar *)(bModel.GetParametersOfInterest()->first()))->setVal(0.);
pProfile->getVal();
pPoiAndNuisance = new RooArgSet();
pPoiAndNuisance->add(*bModel.GetParametersOfInterest());
if(bModel.GetNuisanceParameters()) pPoiAndNuisance->add(*bModel.GetNuisanceParameters());
printf("\n\n Should use these parameter points to generate pseudo data for bkg only.\n\n") ; fflush(stdout) ;
pPoiAndNuisance->Print("v");
bModel.SetSnapshot(*pPoiAndNuisance);
workspace.import (bModel);
delete pProfile ;
delete pNll ;
delete pPoiAndNuisance ;
workspace.Print() ;
printf("\n\n Saving workspace in : %s\n\n", outfile ) ;
gSystem->Exec(" mkdir -p outputfiles " ) ;
workspace.writeToFile( outfile ) ;
} // build_hbb_workspace1.