本文整理汇总了C++中ToyMCSampler::AddTestStatistic方法的典型用法代码示例。如果您正苦于以下问题:C++ ToyMCSampler::AddTestStatistic方法的具体用法?C++ ToyMCSampler::AddTestStatistic怎么用?C++ ToyMCSampler::AddTestStatistic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ToyMCSampler
的用法示例。
在下文中一共展示了ToyMCSampler::AddTestStatistic方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
//.........这里部分代码省略.........