本文整理汇总了C++中ToyMCSampler::SetParametersForTestStat方法的典型用法代码示例。如果您正苦于以下问题:C++ ToyMCSampler::SetParametersForTestStat方法的具体用法?C++ ToyMCSampler::SetParametersForTestStat怎么用?C++ ToyMCSampler::SetParametersForTestStat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ToyMCSampler
的用法示例。
在下文中一共展示了ToyMCSampler::SetParametersForTestStat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: statTest
void statTest(double mu_pe, double mu_hyp, ModelConfig *mc , RooDataSet *data ){
int nToyMC = 5;
// set roofit seed
RooRandom::randomGenerator()->SetSeed();
cout << endl;
cout << endl;
cout << "Will generate " << nToyMC << " pseudo-experiments for : " << endl;
cout << " - mu[pseudo-data] = " << mu_pe << endl;
cout << " - mu[stat-test] = " << mu_hyp << endl;
cout << endl;
// Check number of POI (for Wald approx)
RooArgSet *ParamOfInterest = (RooArgSet*) mc->GetParametersOfInterest();
int nPOI = ParamOfInterest->getSize();
if(nPOI>1){
cout <<"not sure what to do with other parameters of interest, but here are their values"<<endl;
mc->GetParametersOfInterest()->Print("v");
}
RooRealVar* firstPOI = (RooRealVar*) ParamOfInterest->first();
RooAbsPdf *simPdf = (mc->GetPdf());
//PrintAllParametersAndValues( *mc->GetGlobalObservables() );
//PrintAllParametersAndValues( *mc->GetObservables() );
firstPOI->setVal(0.0); // FIXME
//simPdf->fitTo( *data, Hesse(kTRUE), Minos(kTRUE), PrintLevel(1) );
simPdf->fitTo( *data );
// set up the sampler
ToyMCSampler sampler;
sampler.SetPdf(*mc->GetPdf());
sampler.SetObservables(*mc->GetObservables());
sampler.SetNToys(nToyMC);
sampler.SetGlobalObservables(*mc->GetGlobalObservables());
sampler.SetParametersForTestStat(*mc->GetParametersOfInterest());
RooArgSet* poiset = dynamic_cast<RooArgSet*>(ParamOfInterest->Clone());
// only unconditional fit
MinNLLTestStat *minNll = new MinNLLTestStat(*mc->GetPdf());
minNll->EnableDetailedOutput(true);
sampler.AddTestStatistic(minNll);
// enable PROOF if desired
//ProofConfig pc(*w, 8, "workers=8", kFALSE);
//sampler.SetProofConfig(&pc);
// evaluate the test statistics - this is where most of our time will be spent
cout << "Generating " << nToyMC << " toys...this will take a few minutes" << endl;
TStopwatch *mn_t = new TStopwatch;
mn_t->Start();
RooDataSet* sd = sampler.GetSamplingDistributions(*poiset);
cout << "Toy generation complete :" << endl;
// stop timing
mn_t->Stop();
cout << " total CPU time: " << mn_t->CpuTime() << endl;
cout << " total real time: " << mn_t->RealTime() << endl;
// now sd contains all information about our test statistics, including detailed output
// we might eg. want to explore the results either directly, or first converting to a TTree
// do the conversion
TFile f("mytoys.root", "RECREATE");
TTree *toyTree = RooStats::GetAsTTree("toyTree", "TTree created from test statistics", *sd);
// save result to file, but in general do whatever you like
f.cd();
toyTree->Write();
f.Close();
/*
TFile* tmpFile = new TFile("mytoys.root","READ");
TTree* myTree = (TTree*)tmpFile->Get("toyTree");
// get boundaries for histograms
TIter nextLeaf( (myTree->GetListOfLeaves())->MakeIterator() );
TObject* leafObj(0);
map<TString, float> xMaxs;
map<TString, float> xMins;
for(int i(0); i<myTree->GetEntries(); i++) {
myTree->GetEntry(i);
nextLeaf = ( (myTree->GetListOfLeaves())->MakeIterator() );
while( (leafObj = nextLeaf.Next()) ) {
TString name(leafObj->GetName());
float value(myTree->GetLeaf( leafObj->GetName() )->GetValue());
if(value > xMaxs[name]) { xMaxs[name] = value; }
if(value < xMins[name]) { xMins[name] = value; }
} // loop over leaves
} // loop over tree entries
// plot everything in the tree
myTree->GetEntry(0);
nextLeaf = ( (myTree->GetListOfLeaves())->MakeIterator() );
leafObj = 0;
// make a histogram per leaf
map<TString, TH1F*> hists;
myTree->GetEntry(0);
while( (leafObj = nextLeaf.Next()) ) {
if(!leafObj) { continue; }
//cout << leafObj->GetName() << endl;
TString name(leafObj->GetName());
// special ones : fit related things
//.........这里部分代码省略.........
示例2: fit_toy
result fit_toy(RooWorkspace* wspace, int n, const RooArgSet* globals) {
RooRandom::randomGenerator()->SetSeed(0);
// TFile f(filename);
// RooWorkspace *wspace = (RooWorkspace*)f.Get("combined");
ModelConfig* model = (ModelConfig*)wspace->obj("ModelConfig");
RooAbsPdf* pdf;
pdf = model->GetPdf();
RooAbsPdf* top_constraint = (RooAbsPdf*)wspace->obj("top_ratio_constraint");
RooAbsPdf* vv_constraint = (RooAbsPdf*)wspace->obj("vv_ratio_constraint");
RooAbsPdf* top_vv_constraint_sf = (RooAbsPdf*)wspace->obj("top_vv_ratio_sf_constraint");
RooAbsPdf* top_vv_constraint_of = (RooAbsPdf*)wspace->obj("top_vv_ratio_of_constraint");
// generate constraint global observables
RooRealVar *nom_top_ratio = (RooRealVar*)wspace->obj("nom_top_ratio");
nom_top_ratio->setRange(0, 100);
RooRealVar *nom_vv_ratio = (RooRealVar*)wspace->obj("nom_vv_ratio");
nom_vv_ratio->setRange(0,100);
RooRealVar *nom_top_vv_ratio_sf = (RooRealVar*)wspace->obj("nom_top_vv_ratio_sf");
nom_top_vv_ratio_sf->setRange(0,100);
RooRealVar *nom_top_vv_ratio_of = (RooRealVar*)wspace->obj("nom_top_vv_ratio_of");
nom_top_vv_ratio_of->setRange(0,100);
RooDataSet *nom_top_generated = top_constraint->generateSimGlobal(RooArgSet(*nom_top_ratio), 1);
nom_top_ratio->setVal(((RooRealVar*)nom_top_generated->get(0)->find("nom_top_ratio"))->getVal());
RooDataSet *nom_vv_generated = vv_constraint->generateSimGlobal(RooArgSet(*nom_vv_ratio), 1);
nom_vv_ratio->setVal(((RooRealVar*)nom_vv_generated->get(0)->find("nom_vv_ratio"))->getVal());
RooDataSet *nom_top_vv_sf_generated = top_vv_constraint_sf->generateSimGlobal(RooArgSet(*nom_top_vv_ratio_sf), 1);
nom_top_vv_ratio_sf->setVal(((RooRealVar*)nom_top_vv_sf_generated->get(0)->find("nom_top_vv_ratio_sf"))->getVal());
RooDataSet *nom_top_vv_of_generated = top_vv_constraint_of->generateSimGlobal(RooArgSet(*nom_top_vv_ratio_of), 1);
nom_top_vv_ratio_of->setVal(((RooRealVar*)nom_top_vv_of_generated->get(0)->find("nom_top_vv_ratio_of"))->getVal());
NumEventsTestStat* dummy = new NumEventsTestStat(*pdf);
ToyMCSampler* mc = new ToyMCSampler(*dummy, 1);
mc->SetPdf(*pdf);
mc->SetObservables(*model->GetObservables());
mc->SetGlobalObservables(*globals);
mc->SetNuisanceParameters(*model->GetNuisanceParameters());
mc->SetParametersForTestStat(*model->GetParametersOfInterest());
mc->SetNEventsPerToy(n);
RooArgSet constr;
constr.add(*(model->GetNuisanceParameters()));
RemoveConstantParameters(&constr);
RooDataSet* toy_data = (RooDataSet*)mc->GenerateToyData(*const_cast<RooArgSet*>(model->GetSnapshot()));
RooFitResult *res = pdf->fitTo(*toy_data, Constrain(constr), PrintLevel(0), Save(),
Range("fitRange"), InitialHesse(),
ExternalConstraints(RooArgSet(*top_constraint, *vv_constraint, *top_vv_constraint_sf, *top_vv_constraint_of)));
result yield = get_results(wspace, res);
yield.of.generated_sum.val = toy_data->sumEntries("(channelCat==channelCat::of) & (obs_x_of>120)");
yield.sf.generated_sum.val = toy_data->sumEntries("(channelCat==channelCat::sf) & (obs_x_sf>120)");
delete mc;
delete dummy;
// f.Close();
return yield;
}