本文整理汇总了C++中RooRealVar::setMin方法的典型用法代码示例。如果您正苦于以下问题:C++ RooRealVar::setMin方法的具体用法?C++ RooRealVar::setMin怎么用?C++ RooRealVar::setMin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RooRealVar
的用法示例。
在下文中一共展示了RooRealVar::setMin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: StandardTestStatDistributionDemo
void StandardTestStatDistributionDemo(const char* infile = "",
const char* workspaceName = "combined",
const char* modelConfigName = "ModelConfig",
const char* dataName = "obsData"){
// the number of toy MC used to generate the distribution
int nToyMC = 1000;
// The parameter below is needed for asymptotic distribution to be chi-square,
// but set to false if your model is not numerically stable if mu<0
bool allowNegativeMu=true;
/////////////////////////////////////////////////////////////
// First part is just to access a user-defined file
// or create the standard example file if it doesn't exist
////////////////////////////////////////////////////////////
const char* filename = "";
if (!strcmp(infile,"")) {
filename = "results/example_combined_GaussExample_model.root";
bool fileExist = !gSystem->AccessPathName(filename); // note opposite return code
// if file does not exists generate with histfactory
if (!fileExist) {
#ifdef _WIN32
cout << "HistFactory file cannot be generated on Windows - exit" << endl;
return;
#endif
// Normally this would be run on the command line
cout <<"will run standard hist2workspace example"<<endl;
gROOT->ProcessLine(".! prepareHistFactory .");
gROOT->ProcessLine(".! hist2workspace config/example.xml");
cout <<"\n\n---------------------"<<endl;
cout <<"Done creating example input"<<endl;
cout <<"---------------------\n\n"<<endl;
}
}
else
filename = infile;
// Try to open the file
TFile *file = TFile::Open(filename);
// if input file was specified byt not found, quit
if(!file ){
cout <<"StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl;
return;
}
/////////////////////////////////////////////////////////////
// Now get the data and workspace
////////////////////////////////////////////////////////////
// get the workspace out of the file
RooWorkspace* w = (RooWorkspace*) file->Get(workspaceName);
if(!w){
cout <<"workspace not found" << endl;
return;
}
// get the modelConfig out of the file
ModelConfig* mc = (ModelConfig*) w->obj(modelConfigName);
// get the modelConfig out of the file
RooAbsData* data = w->data(dataName);
// make sure ingredients are found
if(!data || !mc){
w->Print();
cout << "data or ModelConfig was not found" <<endl;
return;
}
mc->Print();
/////////////////////////////////////////////////////////////
// Now find the upper limit based on the asymptotic results
////////////////////////////////////////////////////////////
RooRealVar* firstPOI = (RooRealVar*) mc->GetParametersOfInterest()->first();
ProfileLikelihoodCalculator plc(*data,*mc);
LikelihoodInterval* interval = plc.GetInterval();
double plcUpperLimit = interval->UpperLimit(*firstPOI);
delete interval;
cout << "\n\n--------------------------------------"<<endl;
cout <<"Will generate sampling distribution at " << firstPOI->GetName() << " = " << plcUpperLimit <<endl;
int nPOI = mc->GetParametersOfInterest()->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");
}
/////////////////////////////////////////////
// create thte test stat sampler
ProfileLikelihoodTestStat ts(*mc->GetPdf());
// to avoid effects from boundary and simplify asymptotic comparison, set min=-max
if(allowNegativeMu)
firstPOI->setMin(-1*firstPOI->getMax());
// temporary RooArgSet
//.........这里部分代码省略.........
示例2: StandardBayesianNumericalDemo
//.........这里部分代码省略.........
RooAbsData* data = w->data(dataName);
// make sure ingredients are found
if(!data || !mc){
w->Print();
cout << "data or ModelConfig was not found" <<endl;
return;
}
/////////////////////////////////////////////
// create and use the BayesianCalculator
// to find and plot the 95% credible interval
// on the parameter of interest as specified
// in the model config
// before we do that, we must specify our prior
// it belongs in the model config, but it may not have
// been specified
RooUniform prior("prior","",*mc->GetParametersOfInterest());
w->import(prior);
mc->SetPriorPdf(*w->pdf("prior"));
// do without systematics
//mc->SetNuisanceParameters(RooArgSet() );
if (nSigmaNuisance > 0) {
RooAbsPdf * pdf = mc->GetPdf();
assert(pdf);
RooFitResult * res = pdf->fitTo(*data, Save(true), Minimizer(ROOT::Math::MinimizerOptions::DefaultMinimizerType().c_str()), Hesse(true),
PrintLevel(ROOT::Math::MinimizerOptions::DefaultPrintLevel()-1) );
res->Print();
RooArgList nuisPar(*mc->GetNuisanceParameters());
for (int i = 0; i < nuisPar.getSize(); ++i) {
RooRealVar * v = dynamic_cast<RooRealVar*> (&nuisPar[i] );
assert( v);
v->setMin( TMath::Max( v->getMin(), v->getVal() - nSigmaNuisance * v->getError() ) );
v->setMax( TMath::Min( v->getMax(), v->getVal() + nSigmaNuisance * v->getError() ) );
std::cout << "setting interval for nuisance " << v->GetName() << " : [ " << v->getMin() << " , " << v->getMax() << " ]" << std::endl;
}
}
BayesianCalculator bayesianCalc(*data,*mc);
bayesianCalc.SetConfidenceLevel(confLevel); // 95% interval
// default of the calculator is central interval. here use shortest , central or upper limit depending on input
// doing a shortest interval might require a longer time since it requires a scan of the posterior function
if (intervalType == 0) bayesianCalc.SetShortestInterval(); // for shortest interval
if (intervalType == 1) bayesianCalc.SetLeftSideTailFraction(0.5); // for central interval
if (intervalType == 2) bayesianCalc.SetLeftSideTailFraction(0.); // for upper limit
if (!integrationType.IsNull() ) {
bayesianCalc.SetIntegrationType(integrationType); // set integrationType
bayesianCalc.SetNumIters(nToys); // set number of ietrations (i.e. number of toys for MC integrations)
}
// in case of toyMC make a nnuisance pdf
if (integrationType.Contains("TOYMC") ) {
RooAbsPdf * nuisPdf = RooStats::MakeNuisancePdf(*mc, "nuisance_pdf");
cout << "using TOYMC integration: make nuisance pdf from the model " << std::endl;
nuisPdf->Print();
bayesianCalc.ForceNuisancePdf(*nuisPdf);
scanPosterior = true; // for ToyMC the posterior is scanned anyway so used given points
}
// compute interval by scanning the posterior function
if (scanPosterior)
bayesianCalc.SetScanOfPosterior(nScanPoints);
RooRealVar* poi = (RooRealVar*) mc->GetParametersOfInterest()->first();
if (maxPOI != -999 && maxPOI > poi->getMin())
poi->setMax(maxPOI);
SimpleInterval* interval = bayesianCalc.GetInterval();
// print out the iterval on the first Parameter of Interest
cout << "\n>>>> RESULT : " << confLevel*100 << "% interval on " << poi->GetName()<<" is : ["<<
interval->LowerLimit() << ", "<<
interval->UpperLimit() <<"] "<<endl;
// make a plot
// since plotting may take a long time (it requires evaluating
// the posterior in many points) this command will speed up
// by reducing the number of points to plot - do 50
// ignore errors of PDF if is zero
RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::Ignore) ;
cout << "\nDrawing plot of posterior function....." << endl;
// always plot using numer of scan points
bayesianCalc.SetScanOfPosterior(nScanPoints);
RooPlot * plot = bayesianCalc.GetPosteriorPlot();
plot->Draw();
}
示例3: slrts
// internal routine to run the inverter
HypoTestInverterResult *
RooStats::HypoTestInvTool::RunInverter(RooWorkspace * w,
ModelConfig * modelSBName, ModelConfig * modelBName,
const char * dataName, int type, int testStatType,
bool useCLs, int npoints, double poimin, double poimax,
int ntoys,
bool useNumberCounting,
const char * nuisPriorName ){
std::cout << "Running HypoTestInverter on the workspace " << w->GetName() << std::endl;
w->Print();
RooAbsData * data = w->data(dataName);
if (!data) {
Error("StandardHypoTestDemo","Not existing data %s",dataName);
return 0;
}
else
std::cout << "Using data set " << dataName << std::endl;
if (mUseVectorStore) {
RooAbsData::setDefaultStorageType(RooAbsData::Vector);
data->convertToVectorStore() ;
}
// get models from WS
// get the modelConfig out of the file
ModelConfig* bModel = modelBName;
ModelConfig* sbModel = modelSBName;
if (!sbModel) {
Error("StandardHypoTestDemo","Not existing ModelConfig %i",modelSBName);
return 0;
}
// check the model
if (!sbModel->GetPdf()) {
Error("StandardHypoTestDemo","Model %i has no pdf ",modelSBName);
return 0;
}
if (!sbModel->GetParametersOfInterest()) {
Error("StandardHypoTestDemo","Model %i has no poi ",modelSBName);
return 0;
}
if (!sbModel->GetObservables()) {
Error("StandardHypoTestInvDemo","Model %i has no observables ",modelSBName);
return 0;
}
if (!sbModel->GetSnapshot() ) {
Info("StandardHypoTestInvDemo","Model %i has no snapshot - make one using model poi",modelSBName);
sbModel->SetSnapshot( *sbModel->GetParametersOfInterest() );
}
cout << "observables: " << sbModel->GetObservables()->getSize() << endl;
// case of no systematics
// remove nuisance parameters from model
if (noSystematics) {
const RooArgSet * nuisPar = sbModel->GetNuisanceParameters();
if (nuisPar && nuisPar->getSize() > 0) {
std::cout << "StandardHypoTestInvDemo" << " - Switch off all systematics by setting them constant to their initial values" << std::endl;
RooStats::SetAllConstant(*nuisPar);
}
if (bModel) {
const RooArgSet * bnuisPar = bModel->GetNuisanceParameters();
if (bnuisPar)
RooStats::SetAllConstant(*bnuisPar);
}
}
if (!bModel || bModel == sbModel) {
Info("StandardHypoTestInvDemo","The background model %i does not exist",modelBName);
Info("StandardHypoTestInvDemo","Copy it from ModelConfig %i and set POI to zero",modelSBName);
bModel = (ModelConfig*) sbModel->Clone();
bModel->SetName(TString(modelSBName->GetName())+TString("_with_poi_0"));
RooRealVar * var = dynamic_cast<RooRealVar*>(bModel->GetParametersOfInterest()->first());
if (!var) return 0;
double oldval = var->getVal();
var->setMin(0);
var->setVal(0);
bModel->SetSnapshot( RooArgSet(*var) );
var->setVal(oldval);
}
else {
if (!bModel->GetSnapshot() ) {
Info("StandardHypoTestInvDemo","Model %s has no snapshot - make one using model poi and 0 values ",modelBName);
RooRealVar * var = dynamic_cast<RooRealVar*>(bModel->GetParametersOfInterest()->first());
if (var) {
double oldval = var->getVal();
var->setVal(0);
bModel->SetSnapshot( RooArgSet(*var) );
var->setVal(oldval);
}
else {
Error("StandardHypoTestInvDemo","Model %s has no valid poi",modelBName);
return 0;
}
//.........这里部分代码省略.........