本文整理汇总了C++中ToyMCSampler::SetNEventsPerToy方法的典型用法代码示例。如果您正苦于以下问题:C++ ToyMCSampler::SetNEventsPerToy方法的具体用法?C++ ToyMCSampler::SetNEventsPerToy怎么用?C++ ToyMCSampler::SetNEventsPerToy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ToyMCSampler
的用法示例。
在下文中一共展示了ToyMCSampler::SetNEventsPerToy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slrts
//.........这里部分代码省略.........
// else if (type == 3 ) hc = new AsymptoticCalculator(*data, *bModel, *sbModel, true, mAsimovBins); // for using Asimov data generated with nominal values
else if (type == 2 ) hc = new AsymptoticCalculator(*data, *bModel, *sbModel, false );
else if (type == 3 ) hc = new AsymptoticCalculator(*data, *bModel, *sbModel, true ); // for using Asimov data generated with nominal values
else {
Error("StandardHypoTestInvDemo","Invalid - calculator type = %d supported values are only :\n\t\t\t 0 (Frequentist) , 1 (Hybrid) , 2 (Asymptotic) ",type);
return 0;
}
// set the test statistic
TestStatistic * testStat = 0;
if (testStatType == 0) testStat = &slrts;
if (testStatType == 1 || testStatType == 11) testStat = &ropl;
if (testStatType == 2 || testStatType == 3 || testStatType == 4) testStat = &profll;
if (testStatType == 5) testStat = &maxll;
if (testStatType == 6) testStat = &nevtts;
if (testStat == 0) {
Error("StandardHypoTestInvDemo","Invalid - test statistic type = %d supported values are only :\n\t\t\t 0 (SLR) , 1 (Tevatron) , 2 (PLR), 3 (PLR1), 4(MLE)",testStatType);
return 0;
}
ToyMCSampler *toymcs = (ToyMCSampler*)hc->GetTestStatSampler();
if (toymcs && (type == 0 || type == 1) ) {
// look if pdf is number counting or extended
if (sbModel->GetPdf()->canBeExtended() ) {
if (useNumberCounting) Warning("StandardHypoTestInvDemo","Pdf is extended: but number counting flag is set: ignore it ");
}
else {
// for not extended pdf
if (!useNumberCounting ) {
int nEvents = data->numEntries();
Info("StandardHypoTestInvDemo","Pdf is not extended: number of events to generate taken from observed data set is %d",nEvents);
toymcs->SetNEventsPerToy(nEvents);
}
else {
Info("StandardHypoTestInvDemo","using a number counting pdf");
toymcs->SetNEventsPerToy(1);
}
}
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);
示例2: frequentist
//void RunToyScan5(TString fileName, double startVal, double stopVal, TString outFile) {
void frequentist(TString fileName) {
cout << "Starting frequentist " << time(NULL) << endl;
double startVal = 0;
double stopVal = 200;
TString outFile = "";
int nToys = 1 ;
int nscanpoints = 2 ;
/*
gROOT->LoadMacro("RooBetaPdf.cxx+") ;
gROOT->LoadMacro("RooRatio.cxx+") ;
gROOT->LoadMacro("RooPosDefCorrGauss.cxx+") ;
*/
// get relevant objects out of the "ws" file
TFile *file = TFile::Open(fileName);
if(!file){
cout <<"file not found" << endl;
return;
}
RooWorkspace* w = (RooWorkspace*) file->Get("workspace");
if(!w){
cout <<"workspace not found" << endl;
return;
}
ModelConfig* mc = (ModelConfig*) w->obj("S+B_model");
RooAbsData* data = w->data("data");
if( !data || !mc ){
w->Print();
cout << "data or ModelConfig was not found" <<endl;
return;
}
RooRealVar* myPOI = (RooRealVar*) mc->GetParametersOfInterest()->first();
myPOI->setRange(0, 1000.);
ModelConfig* bModel = (ModelConfig*) w->obj("B_model");
ModelConfig* sbModel = (ModelConfig*) w->obj("S+B_model");
ProfileLikelihoodTestStat profll(*sbModel->GetPdf());
profll.SetPrintLevel(2);
profll.SetOneSided(1);
TestStatistic * testStat = &profll;
HypoTestCalculatorGeneric * hc = 0;
hc = new FrequentistCalculator(*data, *bModel, *sbModel);
ToyMCSampler *toymcs = (ToyMCSampler*)hc->GetTestStatSampler();
toymcs->SetMaxToys(10000);
toymcs->SetNEventsPerToy(1);
toymcs->SetTestStatistic(testStat);
((FrequentistCalculator *)hc)->SetToys(nToys,nToys);
HypoTestInverter calc(*hc);
calc.SetConfidenceLevel(0.95);
calc.UseCLs(true);
//calc.SetVerbose(true);
calc.SetVerbose(2);
cout << "About to set fixed scan " << time(NULL) << endl;
calc.SetFixedScan(nscanpoints,startVal,stopVal);
cout << "About to do inverter " << time(NULL) << endl;
HypoTestInverterResult * res_toysCLs_calculator = calc.GetInterval();
cout << "CLs = " << res_toysCLs_calculator->UpperLimit()
<< " CLs_exp = " << res_toysCLs_calculator->GetExpectedUpperLimit(0)
<< " CLs_exp(-1s) = " << res_toysCLs_calculator->GetExpectedUpperLimit(-1)
<< " CLs_exp(+1s) = " << res_toysCLs_calculator->GetExpectedUpperLimit(1) << endl ;
/*
// dump results string to output file
ofstream outStream ;
outStream.open(outFile,ios::app) ;
outStream << "CLs = " << res_toysCLs_calculator->UpperLimit()
<< " CLs_exp = " << res_toysCLs_calculator->GetExpectedUpperLimit(0)
<< " CLs_exp(-1s) = " << res_toysCLs_calculator->GetExpectedUpperLimit(-1)
<< " CLs_exp(+1s) = " << res_toysCLs_calculator->GetExpectedUpperLimit(1) << endl ;
outStream.close() ;
*/
cout << "End of frequentist " << time(NULL) << endl;
return ;
}
示例3: StandardHypoTestDemo
//.........这里部分代码省略.........
}
}
assert(nuisPdf);
Info("StandardHypoTestDemo","Using as nuisance Pdf ... " );
nuisPdf->Print();
const RooArgSet * nuisParams = (bModel->GetNuisanceParameters() ) ? bModel->GetNuisanceParameters() : sbModel->GetNuisanceParameters();
RooArgSet * np = nuisPdf->getObservables(*nuisParams);
if (np->getSize() == 0) {
Warning("StandardHypoTestDemo","Prior nuisance does not depend on nuisance parameters. They will be smeared in their full range");
}
delete np;
((HybridCalculator*)hypoCalc)->ForcePriorNuisanceAlt(*nuisPdf);
((HybridCalculator*)hypoCalc)->ForcePriorNuisanceNull(*nuisPdf);
}
// hypoCalc->ForcePriorNuisanceAlt(*sbModel->GetPriorPdf());
// hypoCalc->ForcePriorNuisanceNull(*bModel->GetPriorPdf());
ToyMCSampler * sampler = (ToyMCSampler *)hypoCalc->GetTestStatSampler();
if (sampler && (calcType == 0 || calcType == 1) ) {
// look if pdf is number counting or extended
if (sbModel->GetPdf()->canBeExtended() ) {
if (useNC) Warning("StandardHypoTestDemo","Pdf is extended: but number counting flag is set: ignore it ");
}
else {
// for not extended pdf
if (!useNC) {
int nEvents = data->numEntries();
Info("StandardHypoTestDemo","Pdf is not extended: number of events to generate taken from observed data set is %d",nEvents);
sampler->SetNEventsPerToy(nEvents);
}
else {
Info("StandardHypoTestDemo","using a number counting pdf");
sampler->SetNEventsPerToy(1);
}
}
if (data->isWeighted() && !generateBinned) {
Info("StandardHypoTestDemo","Data set is weighted, nentries = %d and sum of weights = %8.1f but toy generation is unbinned - it would be faster to set generateBinned to true\n",data->numEntries(), data->sumEntries());
}
if (generateBinned) sampler->SetGenerateBinned(generateBinned);
// set the test statistic
if (testStatType == 0) sampler->SetTestStatistic(slrts);
if (testStatType == 1) sampler->SetTestStatistic(ropl);
if (testStatType == 2 || testStatType == 3) sampler->SetTestStatistic(profll);
}
HypoTestResult * htr = hypoCalc->GetHypoTest();
htr->SetPValueIsRightTail(true);
htr->SetBackgroundAsAlt(false);
htr->Print(); // how to get meaningfull CLs at this point?
delete sampler;
delete slrts;
delete ropl;
delete profll;
if (calcType != 2) {
HypoTestPlot * plot = new HypoTestPlot(*htr,100);
示例4: slrts
//.........这里部分代码省略.........
return 0;
}
}
}
SimpleLikelihoodRatioTestStat slrts(*sbModel->GetPdf(),*bModel->GetPdf());
if (sbModel->GetSnapshot()) slrts.SetNullParameters(*sbModel->GetSnapshot());
if (bModel->GetSnapshot()) slrts.SetAltParameters(*bModel->GetSnapshot());
// ratio of profile likelihood - need to pass snapshot for the alt
RatioOfProfiledLikelihoodsTestStat
ropl(*sbModel->GetPdf(), *bModel->GetPdf(), bModel->GetSnapshot());
ropl.SetSubtractMLE(false);
//MyProfileLikelihoodTestStat profll(*sbModel->GetPdf());
ProfileLikelihoodTestStat profll(*sbModel->GetPdf());
if (testStatType == 3) profll.SetOneSided(1);
if (optimize) profll.SetReuseNLL(true);
TestStatistic * testStat = &slrts;
if (testStatType == 1) testStat = &ropl;
if (testStatType == 2 || testStatType == 3) testStat = &profll;
HypoTestCalculatorGeneric * hc = 0;
if (type == 0) hc = new FrequentistCalculator(*data, *bModel, *sbModel);
else hc = new HybridCalculator(*data, *bModel, *sbModel);
ToyMCSampler *toymcs = (ToyMCSampler*)hc->GetTestStatSampler();
//=== DEBUG
///// toymcs->SetWS( w ) ;
//=== DEBUG
toymcs->SetNEventsPerToy(1);
toymcs->SetTestStatistic(testStat);
if (optimize) toymcs->SetUseMultiGen(true);
if (type == 1) {
HybridCalculator *hhc = (HybridCalculator*) hc;
hhc->SetToys(ntoys,ntoys);
// check for nuisance prior pdf
if (bModel->GetPriorPdf() && sbModel->GetPriorPdf() ) {
hhc->ForcePriorNuisanceAlt(*bModel->GetPriorPdf());
hhc->ForcePriorNuisanceNull(*sbModel->GetPriorPdf());
}
else {
if (bModel->GetNuisanceParameters() || sbModel->GetNuisanceParameters() ) {
Error("RA2bHypoTestInvDemo","Cannnot run Hybrid calculator because no prior on the nuisance parameter is specified");
return 0;
}
}
}
else
((FrequentistCalculator*) hc)->SetToys(ntoys,ntoys);
// Get the result
RooMsgService::instance().getStream(1).removeTopic(RooFit::NumIntegration);
TStopwatch tw; tw.Start();
const RooArgSet * poiSet = sbModel->GetParametersOfInterest();
RooRealVar *poi = (RooRealVar*)poiSet->first();
// fit the data first
示例5: 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;
}