11 #include "RooArgList.h" 12 #include "RooRealVar.h" 18 int main(
int argc,
char *argv[]){
19 for(
int argi = 1; argi < argc; ++argi){
20 execute(
"export blah=$(pwd); cd ~/cmssw/CMSSW_7_1_5/src; eval `scramv1 runtime -sh`; cd $blah; combine -M MaxLikelihoodFit --saveWorkspace "+
string(argv[argi]));
22 TFile w_file(
"higgsCombineTest.MaxLikelihoodFit.mH120.root",
"read");
23 if(!w_file.IsOpen())
continue;
24 RooWorkspace *w =
static_cast<RooWorkspace*
>(w_file.Get(
"w"));
25 if(w ==
nullptr)
continue;
27 TFile fit_file(
"mlfit.root",
"read");
28 if(!fit_file.IsOpen())
continue;
29 RooFitResult *fit_b =
static_cast<RooFitResult*
>(fit_file.Get(
"fit_b"));
30 if(fit_b ==
nullptr)
continue;
36 out <<
"SYSTEMATIC dilep_closure\n";
37 out <<
" PROCESS ttbar,other\n";
39 for(
const auto &bin_name: bin_names){
43 double frac = yield > 0. ? uncert/yield : 2.;
44 out <<
" " << bin_name <<
' ' << frac <<
'\n';
47 ofstream outfile(outname);
49 cout <<
"Dilepton closure written to " << outname <<
":\n";
50 cout << out.str() << endl;
56 TIter iter(w.allFunctions().createIterator());
57 int size = w.allFunctions().getSize();
60 while((obj = iter()) && i < size){
62 RooAbsArg *arg =
static_cast<RooAbsArg*
>(obj);
63 if(arg ==
nullptr)
continue;
64 string name = arg->GetName();
65 if(name.substr(0,9) !=
"nexp_BLK_")
continue;
66 auto bpos = name.find(
"_BIN_");
67 auto ppos = name.find(
"_PRC_");
68 if(bpos == string::npos)
continue;
69 string bin_name = name.substr(bpos+5, ppos-bpos-5);
73 reverse(names.begin(), names.end());
78 const string &bin_name){
79 TIter iter(w.allFunctions().createIterator());
80 int size = w.allFunctions().getSize();
83 while((obj = iter()) && i < size){
85 RooAbsArg *arg =
static_cast<RooAbsArg*
>(obj);
86 if(arg ==
nullptr)
continue;
87 string name = arg->GetName();
88 if(name.substr(0,9) !=
"nbkg_BLK_")
continue;
89 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
90 if(
Contains(name,
"_PRC_"))
continue;
91 return static_cast<RooRealVar*
>(arg)->getVal();
98 const RooFitResult &
f,
99 const string &bin_name){
100 TIter iter(w.allFunctions().createIterator());
101 int size = w.allFunctions().getSize();
104 while((obj = iter()) && i < size){
106 RooAbsArg *arg =
static_cast<RooAbsArg*
>(obj);
107 if(arg ==
nullptr)
continue;
108 string name = arg->GetName();
109 if(name.substr(0,9) !=
"nbkg_BLK_")
continue;
110 if(!(
Contains(name,
"_BIN_"+bin_name)))
continue;
111 if(
Contains(name,
"_PRC_"))
continue;
112 return static_cast<RooRealVar*
>(arg)->getPropagatedError(f);
119 const RooFitResult &
f){
121 RooArgList pars = f.floatParsFinal();
122 for(
int ipar = 0; ipar < pars.getSize(); ++ipar){
123 RooRealVar *fit_var =
static_cast<RooRealVar*
>(pars.at(ipar));
124 if(fit_var ==
nullptr)
continue;
125 RooRealVar *w_var = w.var(fit_var->GetName());
126 if(w_var ==
nullptr)
continue;
127 w_var->setVal(fit_var->getVal());
128 if(fit_var->GetName() == string(
"r")) set_r =
true;
130 RooRealVar *r_var =
static_cast<RooRealVar*
>(w.var(
"r"));
131 if(r_var !=
nullptr){
134 r_var->setConstant(
true);
136 r_var->setConstant(
false);
void Append(T &collection, const typename T::value_type &value)
double GetBkgPredErr(const RooWorkspace &w, const RooFitResult &f, const string &bin_name)
bool Contains(const std::string &str, const std::string &pat)
std::string execute(const std::string &cmd)
int main(int argc, char *argv[])
std::string ChangeExtension(std::string path, const std::string &new_ext)
double GetBkgPred(const RooWorkspace &w, const string &bin_name)
RooRealVar * SetVariables(RooWorkspace &w, const RooFitResult &f)
vector< string > GetBinNames(const RooWorkspace &w)