Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions interface/Combine.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern bool doSignificance_, lowerLimit_;
extern float cl;
extern bool bypassFrequentistFit_;
extern std::string setPhysicsModelParameterExpression_;
extern std::string setParametersFromList_;
extern std::string setPhysicsModelParameterRangeExpression_;
extern std::string defineBackgroundOnlyModelParameterExpression_;

Expand Down
1 change: 1 addition & 0 deletions interface/MultiDimFit.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class MultiDimFit : public FitterAlgoBase {
static bool startFromPreFit_;
static bool alignEdges_;
static bool saveFitResult_;
static bool saveFitResultWithoutHesse_;
static std::string fixedPointPOIs_;
static float centeredRange_;
static std::string setParametersForGrid_;
Expand Down
1 change: 1 addition & 0 deletions interface/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ namespace utils {

// Set values of physics model parameters
void setModelParameters( const std::string & setPhysicsModelParameterExpression, const RooArgSet & params);
void setParametersFromList( const std::string & setParameterFile, const RooArgSet & params);
// Set range of physics model parameters
void setModelParameterRanges( const std::string & setPhysicsModelParameterRangeExpression, const RooArgSet & params);

Expand Down
10 changes: 10 additions & 0 deletions src/Combine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ bool g_fillTree_ = true;
TTree *Combine::tree_ = 0;

std::string setPhysicsModelParameterExpression_ = "";
std::string setParametersFromList_ = "";
std::string setPhysicsModelParameterRangeExpression_ = "";
std::string defineBackgroundOnlyModelParameterExpression_ = "";

Expand Down Expand Up @@ -123,6 +124,7 @@ Combine::Combine() :
("unbinned,U", "Generate unbinned datasets instead of binned ones (works only for extended pdfs)")
("generateBinnedWorkaround", "Make binned datasets generating unbinned ones and then binnning them. Workaround for a bug in RooFit.")
("setParameters", po::value<string>(&setPhysicsModelParameterExpression_)->default_value(""), "Set the values of relevant physics model parameters. Give a comma separated list of parameter value assignments. Example: CV=1.0,CF=1.0")
("setParametersFromList", po::value<string>(&setParametersFromList_)->default_value(""), "Set the values of relevant model parameters from a file containing a RooArgList with fit parameters")
("setParameterRanges", po::value<string>(&setPhysicsModelParameterRangeExpression_)->default_value(""), "Set the range of relevant physics model parameters. Give a colon separated list of parameter ranges. Example: CV=0.0,2.0:CF=0.0,5.0")
("defineBackgroundOnlyModelParameters", po::value<string>(&defineBackgroundOnlyModelParameterExpression_)->default_value(""), "If no background only (null) model is explicitly provided in physics model, one will be defined as these values of the POIs (default is r=0)")
("redefineSignalPOIs", po::value<string>(&redefineSignalPOIs_)->default_value(""), "Redefines the POIs to be this comma-separated list of variables from the workspace.")
Expand Down Expand Up @@ -430,6 +432,11 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do
// Possible that MH value was re-set above, so make sure mass is set to the correct value and not over-ridden later.
if (w->var("MH")) mass_ = w->var("MH")->getVal();
}
if (setParametersFromList_ != "" && !runtimedef::get("SETPARAMETERS_AFTER_NLL")) {
RooArgSet allParams(w->allVars());
allParams.add(w->allCats());
utils::setParametersFromList(setParametersFromList_, allParams);
}

} else {
std::cerr << "HLF not validated" << std::endl;
Expand Down Expand Up @@ -473,6 +480,9 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do
if (setPhysicsModelParameterExpression_ != "") {
utils::setModelParameters( setPhysicsModelParameterExpression_, w->allVars());
}
if (setParametersFromList_ != "") {
utils::setParametersFromList( setParametersFromList_, w->allVars());
}
}
gSystem->cd(pwd);

Expand Down
8 changes: 6 additions & 2 deletions src/MultiDimFit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ bool MultiDimFit::hasMaxDeltaNLLForProf_ = false;
bool MultiDimFit::squareDistPoiStep_ = false;
bool MultiDimFit::skipInitialFit_ = false;
bool MultiDimFit::saveFitResult_ = false;
bool MultiDimFit::saveFitResultWithoutHesse_ = false;
float MultiDimFit::maxDeltaNLLForProf_ = 200;
float MultiDimFit::autoRange_ = -1.0;
std::string MultiDimFit::fixedPointPOIs_ = "";
Expand Down Expand Up @@ -106,6 +107,7 @@ MultiDimFit::MultiDimFit() :
("alignEdges", boost::program_options::value<bool>(&alignEdges_)->default_value(alignEdges_), "Align the grid points such that the endpoints of the ranges are included")
("setParametersForGrid", boost::program_options::value<std::string>(&setParametersForGrid_)->default_value(""), "Set the values of relevant physics model parameters. Give a comma separated list of parameter value assignments. Example: CV=1.0,CF=1.0")
("saveFitResult", "Save RooFitResult to multidimfit.root")
("saveFitResultWithoutHesse", "Save RooFitResult to multidimfit.root, without invoking Hesse")
("out", boost::program_options::value<std::string>(&out_)->default_value(out_), "Directory to put the diagnostics output file in")
("robustHesse", boost::program_options::value<bool>(&robustHesse_)->default_value(robustHesse_), "Use a more robust calculation of the hessian/covariance matrix")
("robustHesseLoad", boost::program_options::value<std::string>(&robustHesseLoad_)->default_value(robustHesseLoad_), "Load the pre-calculated Hessian")
Expand Down Expand Up @@ -149,6 +151,7 @@ void MultiDimFit::applyOptions(const boost::program_options::variables_map &vm)
massName_ = vm["massName"].as<std::string>();
toyName_ = vm["toyName"].as<std::string>();
saveFitResult_ = (vm.count("saveFitResult") > 0);
saveFitResultWithoutHesse_ = (vm.count("saveFitResultWithoutHesse") > 0);
}

bool MultiDimFit::runSpecific(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStats::ModelConfig *mc_b, RooAbsData &data, double &limit, double &limitErr, const double *hint) {
Expand Down Expand Up @@ -184,9 +187,10 @@ bool MultiDimFit::runSpecific(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooS
const RooCmdArg &constrainCmdArg = withSystematics ? RooFit::Constrain(*mc_s->GetNuisanceParameters()) : RooCmdArg();
std::auto_ptr<RooFitResult> res;
if (verbose <= 3) RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CountErrors);
bool doHesse = (algo_ == Singles || algo_ == Impact) || (saveFitResult_) ;
if( saveFitResultWithoutHesse_) saveFitResult_ = true;
bool doHesse = ((algo_ == Singles || algo_ == Impact) || (saveFitResult_) ) && !(saveFitResultWithoutHesse_);
if ( !skipInitialFit_){
res.reset(doFit(pdf, data, (doHesse ? poiList_ : RooArgList()), constrainCmdArg, (saveFitResult_ && !robustHesse_), 1, true, false));
res.reset(doFit(pdf, data, (doHesse ? poiList_ : RooArgList()), constrainCmdArg, (saveFitResult_ && !robustHesse_ && !saveFitResultWithoutHesse_), 1, true, saveFitResultWithoutHesse_));
if (!res.get()) {
std::cout << "\n " <<std::endl;
std::cout << "\n ---------------------------" <<std::endl;
Expand Down
33 changes: 33 additions & 0 deletions src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <TIterator.h>
#include <TString.h>
#include <TFile.h>

#include <RooAbsData.h>
#include <RooAbsPdf.h>
Expand Down Expand Up @@ -811,6 +812,38 @@ void utils::setModelParameters( const std::string & setPhysicsModelParameterExpr

}

void utils::setParametersFromList( const std::string & setParameterFile, const RooArgSet & params) {

TFile* filewithparams = TFile::Open(setParameterFile.c_str());
RooArgList* paramlist = (RooArgList*) filewithparams->Get("fitpars");
for (Int_t p = 0; p < paramlist->getSize(); ++p) {
RooAbsArg *tmp = (RooAbsArg*)params.find(paramlist->at(p)->GetName());
if (tmp){
bool isrvar = tmp->IsA()->InheritsFrom(RooRealVar::Class()); // check its type
if (isrvar) {
RooRealVar *tmpParameter = dynamic_cast<RooRealVar*>(tmp);
RooRealVar *parFromList = (RooRealVar*) paramlist->at(p);
double PhysicsParameterValue = parFromList->getVal();
cout << "Set Default Value of Parameter " << parFromList->GetName()
<< " To : " << PhysicsParameterValue << "\n";
tmpParameter->setVal(PhysicsParameterValue);
} else {
RooCategory *tmpCategory = dynamic_cast<RooCategory*>(tmp);
RooCategory *catFromList = (RooCategory*) paramlist->at(p);
int PhysicsParameterValue = catFromList->getIndex();
cout << "Set Default Index of Parameter " << catFromList->GetName()
<< " To : " << PhysicsParameterValue
<< " (was: " << tmpCategory->getIndex() << " )\n";
tmpCategory->setIndex(PhysicsParameterValue);
}
}
else {
std::cout << "Warning: Did not find a parameter with name " << paramlist->at(p)->GetName() << endl;
}
}
}


void utils::setModelParameterRanges( const std::string & setPhysicsModelParameterRangeExpression, const RooArgSet & params) {

vector<string> SetParameterRangeExpressionList;
Expand Down