Skip to content

Commit

Permalink
- regroup common options (but we still need a cleanup)
Browse files Browse the repository at this point in the history
- don't create temporary dir if not needed
  • Loading branch information
Giovanni Petrucciani committed Mar 23, 2011
1 parent a1dc43b commit 3208995
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 60 deletions.
59 changes: 19 additions & 40 deletions bin/combine.cpp
@@ -1,32 +1,3 @@
/**
Generic limit setting, with any model.
Takes as input:
- one label for the output root file
- one input datacard file
- a value of the higgs mass
- the name of the statistical method to apply
- the number of toys to run (0 means to create a single toy corresponding to the expected signal, the so called Asimov dataset)
- the seed for the random number generator
The datacard can be:
- a LandS-like datacard for a generic counting experiment with an arbitrary number of bins, processes and systematical uncertainties
- a RooStats model in the "High Level Factory" syntax, that has to define:
- a RooRealVar "r" corresponding to the cross section strength
- a RooArgSet "obs" with the observables, and a RooArgSet "poi" with the parameters of interest (just "r")
- RooAbsPdfs "model_s" and "model_b" for the (S+B) and B-only scenarios (not all statistical methods use both)
- if systematical uncertainties are enabled, it must also define a RooArgSet "nuisances" with the nuisance parameters,
and a RooAbsPdf "nuisancePdf" with the pdf for those. In this case "model_s" must already be the product of the pdf
for the observables and the pdf for the nuisances.
- the observed dataset will be constructed taking the default value of the observables as in the model.
The program will assume that a file ending in ".hlf" is a RooStats model, and anything else is a LandS datacard.
See higgsCombineSimple.cxx for the documentation of the other input parameters and of the output
*/
//#include "higgsCombine_Common.cxx"
#include "HiggsAnalysis/CombinedLimit/interface/Combine.h"
#include <TString.h>
#include <TSystem.h>
Expand Down Expand Up @@ -79,28 +50,36 @@ int main(int argc, char **argv) {
methodsDesc += i->first;
}

po::options_description desc("Allowed options");
po::options_description desc("Main options");
desc.add_options()
("help,h", "Produce help message")
("verbose,v", po::value<int>(&verbose)->default_value(1), "Verbosity level")
("name,n", po::value<string>(&name)->default_value("Test"), "Name of the job")
("datacard,d", po::value<string>(&datacard), "Datacard file")
("dataset,D", po::value<string>(&dataset)->default_value("data_obs"), "Dataset for observed limit")
("datacard,d", po::value<string>(&datacard), "Datacard file (can also be specified directly without the -d or --datacard)")
("method,M", po::value<string>(&whichMethod)->default_value("ProfileLikelihood"), methodsDesc.c_str())
("hintMethod,H", po::value<string>(&whichHintMethod)->default_value(""), "Run first this method to provide a hint on the result")
("mass,m", po::value<int>(&iMass)->default_value(120), "Higgs mass to store in the output tree")
("verbose,v", po::value<int>(&verbose)->default_value(1), "Verbosity level (-1 = very quiet; 0 = quiet, 1 = verbose, 2+ = debug)")
("help,h", "Produce help message")
;
combiner.statOptions().add_options()
("toys,t", po::value<int>(&runToys)->default_value(0), "Number of Toy MC extractions")
("seed,s", po::value<int>(&seed)->default_value(123456), "Toy MC random seed")
("saveToys,w", "Save results of toy MC")
("toysFile,f", po::value<string>(&toysFile)->default_value(""), "Toy MC input file")
("hintMethod,H", po::value<string>(&whichHintMethod)->default_value(""), "Run first this method to provide a hint on the result")
;
combiner.ioOptions().add_options()
("name,n", po::value<string>(&name)->default_value("Test"), "Name of the job, affects the name of the output tree")
("mass,m", po::value<int>(&iMass)->default_value(120), "Higgs mass to store in the output tree")
("dataset,D", po::value<string>(&dataset)->default_value("data_obs"), "Name of the dataset for observed limit")
("saveToys", "Save results of toy MC or other intermediate results")
("toysFile", po::value<string>(&toysFile)->default_value(""), "Read toy mc or other intermediate results from this file")
;
combiner.miscOptions().add_options()
("igpMem", "Setup support for memory profiling using IgProf")
("LoadLibrary,L", po::value<vector<string> >(&librariesToLoad), "Load library through gSystem->Load(...). Can specify multiple libraries using this option multiple times")
;
desc.add(combiner.options());
desc.add(combiner.statOptions());
desc.add(combiner.ioOptions());
for(map<string, LimitAlgo *>::const_iterator i = methods.begin(); i != methods.end(); ++i) {
if(i->second->options().options().size() != 0)
desc.add(i->second->options());
}
desc.add(combiner.miscOptions());
po::positional_options_description p;
p.add("datacard", -1);
po::variables_map vm;
Expand Down
20 changes: 14 additions & 6 deletions interface/Combine.h
Expand Up @@ -24,25 +24,33 @@ class Combine {
public:
Combine() ;

const boost::program_options::options_description & options() const { return options_; }
boost::program_options::options_description & statOptions() { return statOptions_; }
boost::program_options::options_description & ioOptions() { return ioOptions_; }
boost::program_options::options_description & miscOptions() { return miscOptions_; }
void applyOptions(const boost::program_options::variables_map &vm) ;

void run(TString hlfFile, const std::string &dataset, double &limit, double &limitErr, int &iToy, TTree *tree, int nToys);

private:
bool mklimit(RooWorkspace *w, RooAbsData &data, double &limit, double &limitErr) ;

boost::program_options::options_description options_;

bool unbinned_;
boost::program_options::options_description statOptions_, ioOptions_, miscOptions_;

// statistics-related variables
bool unbinned_, generateBinnedWorkaround_;
float rMin_, rMax_;
bool compiledExpr_;
std::string prior_;
bool hintUsesStatOnly_;
bool toysNoSystematics_;

// input-output related variables
bool saveWorkspace_;
std::string workspaceName_;
std::string modelConfigName_;
bool toysNoSystematics_;

// implementation-related variables
bool compiledExpr_;
bool makeTempDir_;
};

#endif
40 changes: 26 additions & 14 deletions src/Combine.cc
Expand Up @@ -63,25 +63,33 @@ float cl = 0.95;


Combine::Combine() :
options_("Common options"),
statOptions_("Common statistics options"),
ioOptions_("Common input-output options"),
miscOptions_("Common miscellaneous options"),
rMin_(std::numeric_limits<float>::quiet_NaN()),
rMax_(std::numeric_limits<float>::quiet_NaN()) {
namespace po = boost::program_options;
options_.add_options()
statOptions_.add_options()
("systematics,S", po::value<bool>(&withSystematics)->default_value(true), "Add systematic uncertainties")
("cl,C", po::value<float>(&cl)->default_value(0.95), "Confidence Level")
("rMin", po::value<float>(&rMin_), "Override minimum value for signal strength")
("rMax", po::value<float>(&rMax_), "Override maximum value for signal strength")
("prior", po::value<std::string>(&prior_)->default_value("flat"), "Prior to use, for methods that require it and if it's not already in the input file: 'flat' (default), '1/sqrt(r)'")
("unbinned,U", "Generate unbinned datasets instead of binned ones (works only for extended pdfs)")
("compile", "Compile expressions instead of interpreting them")
("significance", "Compute significance instead of upper limit")
("hintStatOnly", "Ignore systematics when computing the hint")
("saveWorkspace", "Save workspace to output root file")
("toysNoSystematics", "Generate all toys with the central value of the nuisance parameters, without fluctuating them")
("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.")
;
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.")
("modelConfigName,w", po::value<std::string>(&modelConfigName_)->default_value("ModelConfig"), "ModelConfig name, when reading it from or writing it to a rootfile.")
("modelConfigName", po::value<std::string>(&modelConfigName_)->default_value("ModelConfig"), "ModelConfig name, when reading it from or writing it to a rootfile.")
;
miscOptions_.add_options()
("compile", "Compile expressions instead of interpreting them")
("tempDir", po::value<bool>(&makeTempDir_)->default_value(false), "Run the program from a temporary directory (automatically on if 'compile' is activated)")
;
}

void Combine::applyOptions(const boost::program_options::variables_map &vm) {
Expand All @@ -91,7 +99,9 @@ void Combine::applyOptions(const boost::program_options::variables_map &vm) {
std::cout << ">>> no systematics included" << std::endl;
}
unbinned_ = vm.count("unbinned");
compiledExpr_ = vm.count("compile");
generateBinnedWorkaround_ = vm.count("generateBinnedWorkaround");
if (unbinned_ && generateBinnedWorkaround_) throw std::logic_error("You can't set generateBinnedWorkaround and unbinned options at the same time");
compiledExpr_ = vm.count("compile"); if (compiledExpr_) makeTempDir_ = true;
doSignificance_ = vm.count("significance");
hintUsesStatOnly_ = vm.count("hintStatOnly");
saveWorkspace_ = vm.count("saveWorkspace");
Expand Down Expand Up @@ -131,10 +141,12 @@ bool Combine::mklimit(RooWorkspace *w, RooAbsData &data, double &limit, double &
}

void Combine::run(TString hlfFile, const std::string &dataset, double &limit, double &limitErr, int &iToy, TTree *tree, int nToys) {
TString pwd(gSystem->pwd());
TString tmpDir = "roostats-XXXXXX";
mkdtemp(const_cast<char *>(tmpDir.Data()));
gSystem->cd(tmpDir.Data());
TString tmpDir = "", pwd(gSystem->pwd());
if (makeTempDir_) {
tmpDir = "roostats-XXXXXX";
mkdtemp(const_cast<char *>(tmpDir.Data()));
gSystem->cd(tmpDir.Data());
}

bool isTextDatacard = false, isBinary = false;
TString fileToLoad = (hlfFile[0] == '/' ? hlfFile : pwd+"/"+hlfFile);
Expand Down Expand Up @@ -449,13 +461,13 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do
}

} catch (std::logic_error &le) {
boost::filesystem::remove_all(tmpDir.Data());
if (tmpDir) boost::filesystem::remove_all(tmpDir.Data());
throw le;
} catch (std::runtime_error &re) {
boost::filesystem::remove_all(tmpDir.Data());
if (tmpDir) boost::filesystem::remove_all(tmpDir.Data());
throw re;
}

boost::filesystem::remove_all(tmpDir.Data());
if (tmpDir) boost::filesystem::remove_all(tmpDir.Data());
}

0 comments on commit 3208995

Please sign in to comment.