Skip to content

Commit

Permalink
Merge pull request cms-sw#113 from nucleosynthesis/nckw-kip-initial-M…
Browse files Browse the repository at this point in the history
…DF-when-loading-snashot

Tested on Hgg bernstein cards. Closes cms-sw#30.
  • Loading branch information
adavidzh committed Mar 19, 2014
2 parents d8a6385 + ec41c1e commit 0ecb296
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions interface/MultiDimFit.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class MultiDimFit : public FitterAlgoBase {
static bool squareDistPoiStep_;
static bool fastScan_;
static bool hasMaxDeltaNLLForProf_;
static bool loadedSnapshot_;
static float maxDeltaNLLForProf_;

// initialize variables
Expand Down
13 changes: 10 additions & 3 deletions src/MultiDimFit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ unsigned int MultiDimFit::lastPoint_ = std::numeric_limits<unsigned int>::max()
bool MultiDimFit::floatOtherPOIs_ = false;
unsigned int MultiDimFit::nOtherFloatingPoi_ = 0;
bool MultiDimFit::fastScan_ = false;
bool MultiDimFit::loadedSnapshot_ = false;
bool MultiDimFit::hasMaxDeltaNLLForProf_ = false;
bool MultiDimFit::squareDistPoiStep_ = false;
float MultiDimFit::maxDeltaNLLForProf_ = 200;
Expand Down Expand Up @@ -79,6 +80,7 @@ void MultiDimFit::applyOptions(const boost::program_options::variables_map &vm)
fastScan_ = (vm.count("fastScan") > 0);
squareDistPoiStep_ = (vm.count("squareDistPoiStep") > 0);
hasMaxDeltaNLLForProf_ = !vm["maxDeltaNLLForProf"].defaulted();
loadedSnapshot_ = !vm["snapshotName"].defaulted();
}

bool MultiDimFit::runSpecific(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStats::ModelConfig *mc_b, RooAbsData &data, double &limit, double &limitErr, const double *hint) {
Expand All @@ -102,20 +104,25 @@ bool MultiDimFit::runSpecific(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooS

// start with a best fit
const RooCmdArg &constrainCmdArg = withSystematics ? RooFit::Constrain(*mc_s->GetNuisanceParameters()) : RooCmdArg();
std::auto_ptr<RooFitResult> res(doFit(pdf, data, (algo_ == Singles ? poiList_ : RooArgList()), constrainCmdArg, false, 1, true, false));
if (res.get() || keepFailures_) {
std::auto_ptr<RooFitResult> res;
if ( algo_ == Singles || !loadedSnapshot_ ){
res.reset(doFit(pdf, data, (algo_ == Singles ? poiList_ : RooArgList()), constrainCmdArg, false, 1, true, false));
}
if ( loadedSnapshot_ || res.get() || keepFailures_) {
for (int i = 0, n = poi_.size(); i < n; ++i) {
poiVals_[i] = poiVars_[i]->getVal();
}
if (algo_ != None) Combine::commitPoint(/*expected=*/false, /*quantile=*/1.); // otherwise we get it multiple times
}


std::auto_ptr<RooAbsReal> nll;
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());
if (!loadedSnapshot_) w->saveSnapshot("MultiDimFit",w->allVars());

switch(algo_) {
case None:
Expand Down

0 comments on commit 0ecb296

Please sign in to comment.