Skip to content

Commit

Permalink
Merge pull request cms-sw#79 from bendavid/snapshotLoading
Browse files Browse the repository at this point in the history
save post-fit snapshot in workspace for MultiDimFit and add ability to l...
  • Loading branch information
gpetruc committed Jan 20, 2014
2 parents 9985d0e + 2aedcc3 commit eb8b141
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions interface/Combine.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Combine {
// input-output related variables
bool saveWorkspace_;
std::string workspaceName_;
std::string snapshotName_;
std::string modelConfigName_, modelConfigNameB_;
bool validateModel_;
bool saveToys_;
Expand Down
17 changes: 11 additions & 6 deletions src/Combine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Combine::Combine() :
ioOptions_.add_options()
("saveWorkspace", "Save workspace to output root file")
("workspaceName,w", po::value<std::string>(&workspaceName_)->default_value("w"), "Workspace name, when reading it from or writing it to a rootfile.")
("snapshotName", po::value<std::string>(&snapshotName_)->default_value(""), "Default snapshot name for pre-fit snapshot for reading or writing to workspace")
("modelConfigName", po::value<std::string>(&modelConfigName_)->default_value("ModelConfig"), "ModelConfig name, when reading it from or writing it to a rootfile.")
("modelConfigNameB", po::value<std::string>(&modelConfigNameB_)->default_value("%s_bonly"), "Name of the ModelConfig for b-only hypothesis.\n"
"If not present, it will be made from the singal model taking zero signal strength.\n"
Expand Down Expand Up @@ -299,6 +300,9 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do
mc_bonly = new RooStats::ModelConfig(*mc);
mc_bonly->SetPdf(*model_b);
}
if (snapshotName_ != "") {
w->loadSnapshot(snapshotName_.c_str());
}
} else {
hlf.reset(new RooStats::HLFactory("factory", fileToLoad));
w = hlf->GetWs();
Expand Down Expand Up @@ -441,12 +445,7 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do
addPOI(POI);

w->saveSnapshot("clean", w->allVars());

if (saveWorkspace_) {
w->SetName(workspaceName_.c_str());
outputFile->WriteTObject(w,workspaceName_.c_str());
}


tree_ = tree;

bool isExtended = mc_bonly->GetPdf()->canBeExtended();
Expand Down Expand Up @@ -627,6 +626,12 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do
cout << " 95% expected band : " << lo95 << " < r < " << hi95 << endl;
}
}

if (saveWorkspace_) {
w->SetName(workspaceName_.c_str());
w->loadSnapshot("clean");
outputFile->WriteTObject(w,workspaceName_.c_str());
}

}

Expand Down
4 changes: 4 additions & 0 deletions src/MultiDimFit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ bool MultiDimFit::runSpecific(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooS
if (algo_ != None && algo_ != Singles) {
nll.reset(pdf.createNLL(data, constrainCmdArg, RooFit::Extended(pdf.canBeExtended())));
}

//set snapshot for best fit
w->saveSnapshot("MultiDimFit",w->allVars());

switch(algo_) {
case None:
if (verbose > 0) {
Expand Down

0 comments on commit eb8b141

Please sign in to comment.