本文整理汇总了C++中ModelConfig::SetGlobalObservables方法的典型用法代码示例。如果您正苦于以下问题:C++ ModelConfig::SetGlobalObservables方法的具体用法?C++ ModelConfig::SetGlobalObservables怎么用?C++ ModelConfig::SetGlobalObservables使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelConfig
的用法示例。
在下文中一共展示了ModelConfig::SetGlobalObservables方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: workspace_preparer
//.........这里部分代码省略.........
//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;
pPoiAndNuisance->Print("v");
pSbModel->SetSnapshot(*pPoiAndNuisance);
示例2: slrts
//.........这里部分代码省略.........
}
}
toymcs->SetTestStatistic(testStat);
if (data->isWeighted() && !mGenerateBinned) {
Info("StandardHypoTestInvDemo","Data set is weighted, nentries = %d and sum of weights = %8.1f but toy generation is unbinned - it would be faster to set mGenerateBinned to true\n",data->numEntries(), data->sumEntries());
}
toymcs->SetGenerateBinned(mGenerateBinned);
toymcs->SetUseMultiGen(mOptimize);
if (mGenerateBinned && sbModel->GetObservables()->getSize() > 2) {
Warning("StandardHypoTestInvDemo","generate binned is activated but the number of ovservable is %d. Too much memory could be needed for allocating all the bins",sbModel->GetObservables()->getSize() );
}
// set the random seed if needed
if (mRandomSeed >= 0) RooRandom::randomGenerator()->SetSeed(mRandomSeed);
}
// specify if need to re-use same toys
if (reuseAltToys) {
hc->UseSameAltToys();
}
if (type == 1) {
HybridCalculator *hhc = dynamic_cast<HybridCalculator*> (hc);
assert(hhc);
hhc->SetToys(ntoys,ntoys/mNToysRatio); // can use less ntoys for b hypothesis
// remove global observables from ModelConfig (this is probably not needed anymore in 5.32)
bModel->SetGlobalObservables(RooArgSet() );
sbModel->SetGlobalObservables(RooArgSet() );
// check for nuisance prior pdf in case of nuisance parameters
if (bModel->GetNuisanceParameters() || sbModel->GetNuisanceParameters() ) {
// fix for using multigen (does not work in this case)
toymcs->SetUseMultiGen(false);
ToyMCSampler::SetAlwaysUseMultiGen(false);
RooAbsPdf * nuisPdf = 0;
if (nuisPriorName) nuisPdf = w->pdf(nuisPriorName);
// use prior defined first in bModel (then in SbModel)
if (!nuisPdf) {
Info("StandardHypoTestInvDemo","No nuisance pdf given for the HybridCalculator - try to deduce pdf from the model");
if (bModel->GetPdf() && bModel->GetObservables() )
nuisPdf = RooStats::MakeNuisancePdf(*bModel,"nuisancePdf_bmodel");
else
nuisPdf = RooStats::MakeNuisancePdf(*sbModel,"nuisancePdf_sbmodel");
}
if (!nuisPdf ) {
if (bModel->GetPriorPdf()) {
nuisPdf = bModel->GetPriorPdf();
Info("StandardHypoTestInvDemo","No nuisance pdf given - try to use %s that is defined as a prior pdf in the B model",nuisPdf->GetName());
}
else {
Error("StandardHypoTestInvDemo","Cannnot run Hybrid calculator because no prior on the nuisance parameter is specified or can be derived");
return 0;
}
}
assert(nuisPdf);
Info("StandardHypoTestInvDemo","Using as nuisance Pdf ... " );
示例3: 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;
//.........这里部分代码省略.........
示例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: 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.