本文整理汇总了C++中ModelConfig::Clone方法的典型用法代码示例。如果您正苦于以下问题:C++ ModelConfig::Clone方法的具体用法?C++ ModelConfig::Clone怎么用?C++ ModelConfig::Clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelConfig
的用法示例。
在下文中一共展示了ModelConfig::Clone方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slrts
// internal routine to run the inverter
HypoTestInverterResult *
RooStats::HypoTestInvTool::RunInverter(RooWorkspace * w,
const char * modelSBName, const char * 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 = (ModelConfig*) w->obj(modelBName);
ModelConfig* sbModel = (ModelConfig*) w->obj(modelSBName);
if (!sbModel) {
Error("StandardHypoTestDemo","Not existing ModelConfig %s",modelSBName);
return 0;
}
// check the model
if (!sbModel->GetPdf()) {
Error("StandardHypoTestDemo","Model %s has no pdf ",modelSBName);
return 0;
}
if (!sbModel->GetParametersOfInterest()) {
Error("StandardHypoTestDemo","Model %s has no poi ",modelSBName);
return 0;
}
if (!sbModel->GetObservables()) {
Error("StandardHypoTestInvDemo","Model %s has no observables ",modelSBName);
return 0;
}
if (!sbModel->GetSnapshot() ) {
Info("StandardHypoTestInvDemo","Model %s has no snapshot - make one using model poi",modelSBName);
sbModel->SetSnapshot( *sbModel->GetParametersOfInterest() );
}
// 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 %s does not exist",modelBName);
Info("StandardHypoTestInvDemo","Copy it from ModelConfig %s and set POI to zero",modelSBName);
bModel = (ModelConfig*) sbModel->Clone();
bModel->SetName(TString(modelSBName)+TString("_with_poi_0"));
RooRealVar * var = dynamic_cast<RooRealVar*>(bModel->GetParametersOfInterest()->first());
if (!var) return 0;
double oldval = var->getVal();
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;
}
}
}
//.........这里部分代码省略.........
示例2: slrts
// internal routine to run the inverter
HypoTestInverterResult * RunInverter(RooWorkspace * w, const char * modelSBName, const char * modelBName,
const char * dataName, int type, int testStatType,
int npoints, double poimin, double poimax,
int ntoys, bool useCls )
{
std::cout << "Running HypoTestInverter on the workspace " << w->GetName() << std::endl;
w->Print();
RooAbsData * data = w->data(dataName);
if (!data) {
Error("RA2bHypoTestDemo","Not existing data %s",dataName);
return 0;
}
else
std::cout << "Using data set " << dataName << std::endl;
// get models from WS
// get the modelConfig out of the file
ModelConfig* bModel = (ModelConfig*) w->obj(modelBName);
ModelConfig* sbModel = (ModelConfig*) w->obj(modelSBName);
if (!sbModel) {
Error("RA2bHypoTestDemo","Not existing ModelConfig %s",modelSBName);
return 0;
}
// check the model
if (!sbModel->GetPdf()) {
Error("RA2bHypoTestDemo","Model %s has no pdf ",modelSBName);
return 0;
}
if (!sbModel->GetParametersOfInterest()) {
Error("RA2bHypoTestDemo","Model %s has no poi ",modelSBName);
return 0;
}
if (!sbModel->GetParametersOfInterest()) {
Error("RA2bHypoTestInvDemo","Model %s has no poi ",modelSBName);
return 0;
}
if (!sbModel->GetSnapshot() ) {
Info("RA2bHypoTestInvDemo","Model %s has no snapshot - make one using model poi",modelSBName);
sbModel->SetSnapshot( *sbModel->GetParametersOfInterest() );
}
if (!bModel || bModel == sbModel) {
Info("RA2bHypoTestInvDemo","The background model %s does not exist",modelBName);
Info("RA2bHypoTestInvDemo","Copy it from ModelConfig %s and set POI to zero",modelSBName);
bModel = (ModelConfig*) sbModel->Clone();
bModel->SetName(TString(modelSBName)+TString("_with_poi_0"));
RooRealVar * var = dynamic_cast<RooRealVar*>(bModel->GetParametersOfInterest()->first());
if (!var) return 0;
double oldval = var->getVal();
var->setVal(0);
bModel->SetSnapshot( RooArgSet(*var) );
var->setVal(oldval);
}
else {
if (!bModel->GetSnapshot() ) {
Info("RA2bHypoTestInvDemo","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("RA2bHypoTestInvDemo","Model %s has no valid poi",modelBName);
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);
//.........这里部分代码省略.........
示例3: StandardHypoTestDemo
//.........这里部分代码省略.........
// get the modelConfig out of the file
RooAbsData* data = w->data(dataName);
// make sure ingredients are found
if(!data || !sbModel){
w->Print();
cout << "data or ModelConfig was not found" <<endl;
return;
}
// make b model
ModelConfig* bModel = (ModelConfig*) w->obj(modelBName);
// 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 ) {
Info("StandardHypoTestInvDemo","The background model %s does not exist",modelBName);
Info("StandardHypoTestInvDemo","Copy it from ModelConfig %s and set POI to zero",modelSBName);
bModel = (ModelConfig*) sbModel->Clone();
bModel->SetName(TString(modelSBName)+TString("B_only"));
RooRealVar * var = dynamic_cast<RooRealVar*>(bModel->GetParametersOfInterest()->first());
if (!var) return;
double oldval = var->getVal();
var->setVal(0);
//bModel->SetSnapshot( RooArgSet(*var, *w->var("lumi")) );
bModel->SetSnapshot( RooArgSet(*var) );
var->setVal(oldval);
}
if (!sbModel->GetSnapshot() || poiValue > 0) {
Info("StandardHypoTestDemo","Model %s has no snapshot - make one using model poi",modelSBName);
RooRealVar * var = dynamic_cast<RooRealVar*>(sbModel->GetParametersOfInterest()->first());
if (!var) return;
double oldval = var->getVal();
if (poiValue > 0) var->setVal(poiValue);
//sbModel->SetSnapshot( RooArgSet(*var, *w->var("lumi") ) );
sbModel->SetSnapshot( RooArgSet(*var) );
if (poiValue > 0) var->setVal(oldval);
//sbModel->SetSnapshot( *sbModel->GetParametersOfInterest() );
}
// part 1, hypothesis testing
SimpleLikelihoodRatioTestStat * slrts = new SimpleLikelihoodRatioTestStat(*bModel->GetPdf(), *sbModel->GetPdf());
// null parameters must includes snapshot of poi plus the nuisance values
RooArgSet nullParams(*bModel->GetSnapshot());
if (bModel->GetNuisanceParameters()) nullParams.add(*bModel->GetNuisanceParameters());
示例4: StandardFrequentistDiscovery
double StandardFrequentistDiscovery(
const char* infile = "",
const char* workspaceName = "channel1",
const char* modelConfigNameSB = "ModelConfig",
const char* dataName = "obsData",
int toys = 1000,
double poiValueForBackground = 0.0,
double poiValueForSignal = 1.0
) {
// The workspace contains the model for s+b. The b model is "autogenerated"
// by copying s+b and setting the one parameter of interest to zero.
// To keep the script simple, multiple parameters of interest or different
// functional forms of the b model are not supported.
// for now, assume there is only one parameter of interest, and these are
// its values:
/////////////////////////////////////////////////////////////
// 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_channel1_GammaExample_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 -1;
#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 -1;
}
/////////////////////////////////////////////////////////////
// Tutorial starts here
////////////////////////////////////////////////////////////
TStopwatch *mn_t = new TStopwatch;
mn_t->Start();
// get the workspace out of the file
RooWorkspace* w = (RooWorkspace*) file->Get(workspaceName);
if (!w) {
cout << "workspace not found" << endl;
return -1.0;
}
// get the modelConfig out of the file
ModelConfig* mc = (ModelConfig*) w->obj(modelConfigNameSB);
// get the data 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 -1.0;
}
RooRealVar* firstPOI = (RooRealVar*) mc->GetParametersOfInterest()->first();
firstPOI->setVal(poiValueForSignal);
mc->SetSnapshot(*mc->GetParametersOfInterest());
// create null model
ModelConfig *mcNull = mc->Clone("ModelConfigNull");
firstPOI->setVal(poiValueForBackground);
mcNull->SetSnapshot(*(RooArgSet*)mcNull->GetParametersOfInterest()->snapshot());
// ----------------------------------------------------
// Configure a ProfileLikelihoodTestStat and a SimpleLikelihoodRatioTestStat
// to use simultaneously with ToyMCSampler
ProfileLikelihoodTestStat* plts = new ProfileLikelihoodTestStat(*mc->GetPdf());
plts->SetOneSidedDiscovery(true);
plts->SetVarName( "q_{0}/2" );
//.........这里部分代码省略.........
开发者ID:chunjie-sam-liu,项目名称:genome_resequencing_pipeline,代码行数:101,代码来源:StandardFrequentistDiscovery.C
示例5: significance
void significance(RooWorkspace& w ) {
ModelConfig* mc = (ModelConfig*)w.obj("mc");
RooDataSet* data = (RooDataSet*)w.data("data");
//data->Print();
// define the S+B snapshot (this is used for computing the expected significance)
ModelConfig* sbModel = mc->Clone();
sbModel->SetName("S+B Model");
RooRealVar* poi = (RooRealVar*) sbModel->GetParametersOfInterest()->first();
poi->setVal(50);
sbModel->SetSnapshot(*poi);
ModelConfig * bModel = (ModelConfig*) sbModel->Clone();
bModel->SetName("B model");
poi->setVal(0);
bModel->SetSnapshot(*poi);
vector<double> masses;
vector<double> p0values;
vector<double> p0valuesExpected;
vector<double> sigvalues;
double massMin = 200;
double massMax = 2500;
int nbins = 100;
// loop on the mass values
for ( double mass=massMin; mass<=massMax; mass += (massMax-massMin)/nbins ) {
w.var("mass")->setVal( mass );
// create the AsymptoticCalculator from data,alt model, null model
AsymptoticCalculator * ac = new AsymptoticCalculator(*data, *sbModel, *bModel);
ac->SetOneSidedDiscovery(true); // for one-side discovery test
AsymptoticCalculator::SetPrintLevel(-1);
// run the calculator
HypoTestResult* asymCalcResult = ac->GetHypoTest();
asymCalcResult->Print();
double pvalue = asymCalcResult->NullPValue();
double sigvalue = asymCalcResult->Significance();
double expectedP0 = AsymptoticCalculator::GetExpectedPValues(asymCalcResult->NullPValue(),asymCalcResult->AlternatePValue(), 0, false);
masses.push_back(mass);
p0values.push_back(pvalue);
p0valuesExpected.push_back(expectedP0);
sigvalues.push_back(sigvalue);
std::cout << "** Mass = " << mass << " p0-value = " << expectedP0 << " p-value = " << pvalue << " significance = " << sigvalue << std::endl;
}
TGraph* graph1 = new TGraph(masses.size(),&masses[0],&p0values[0]);
TGraph* graph2 = new TGraph(masses.size(),&masses[0],&p0valuesExpected[0]);
TGraph* graph3 = new TGraph(masses.size(),&masses[0],&sigvalues[0]);
TCanvas* c2 = new TCanvas("c2","Significance", 900, 700);
c2->Divide(1,2);
c2->cd(1);
graph1->SetMarkerStyle(10);
//graph1->Draw("APC");
graph1->Draw("AC");
graph2->SetLineStyle(2);
graph2->Draw("C");
graph1->GetXaxis()->SetTitle("Mass [GeV]");
graph1->GetYaxis()->SetTitle("p0 value");
graph1->SetTitle("P-value vs Mass");
graph1->SetMinimum(graph2->GetMinimum());
graph1->SetLineColor(kBlue);
graph2->SetLineColor(kRed);
gPad->SetLogy(true);
c2->cd(2);
graph3->SetMarkerStyle(10);
graph3->Draw("AC");
graph3->SetLineStyle(1);
graph3->SetLineColor(kRed);
graph3->GetXaxis()->SetTitle("Mass [GeV]");
graph3->GetYaxis()->SetTitle("Significance");
graph3->SetTitle("Significance vs Mass");
gPad->SetLogy(false);
c2->SaveAs("significance.pdf");
c2->SaveAs("significance.png");
}