11 #include "TDirectory.h" 13 #include "RooPoisson.h" 14 #include "RooDataSet.h" 15 #include "RooRealVar.h" 17 #include "RooStats/ModelConfig.h" 28 const set<Block> &blocks,
29 const set<Process> &backgrounds,
32 const string &systematics_file,
35 backgrounds_(backgrounds),
39 inject_other_signal_(false),
43 systematics_file_(systematics_file),
45 sig_strength_(sig_strength),
46 sig_xsec_f_(sig_xsec_f),
57 do_systematics_(true),
59 do_mc_kappa_correction_(true),
69 w_.writeToFile(file_name.c_str());
75 cout << *
this << endl;
78 cout << endl <<
"Wrote workspace to file " << file_name << endl<< endl;
167 const Cut &cut)
const{
180 const RooArgSet *obs_orig =
w_.set(
"observables");
181 if(obs_orig ==
nullptr)
ERROR(
"Could not get observables list for toy generation");
182 RooArgSet obs(*obs_orig);
186 RooDataSet data_new((
"data_obs_"+to_string(itoy)).c_str(), (
"data_obs_"+to_string(itoy)).c_str(), obs);
224 TIterator *iter_ptr = obs.createIterator();
225 if(iter_ptr ==
nullptr)
ERROR(
"Could not generator iterator to set up toys");
226 for(; iter_ptr !=
nullptr && *(*iter_ptr) !=
nullptr; iter_ptr->Next()){
227 RooAbsReal *arg =
static_cast<RooAbsReal*
>(*(*iter_ptr));
228 if(arg ==
nullptr)
continue;
229 string name = arg->GetName();
230 if(
Contains(name,
"nobsmc"))
continue;
231 double value = arg->getVal();
240 TIterator *iter_ptr = obs.createIterator();
241 if(iter_ptr ==
nullptr)
ERROR(
"Could not generator iterator to set up toys");
242 for(; iter_ptr !=
nullptr && *(*iter_ptr) !=
nullptr; iter_ptr->Next()){
243 RooRealVar *arg =
static_cast<RooRealVar*
>(*(*iter_ptr));
244 if(arg ==
nullptr)
continue;
245 string name = arg->GetName();
246 if(
Contains(name,
"nobsmc"))
continue;
254 TIterator *iter_ptr = obs.createIterator();
255 if(iter_ptr ==
nullptr)
ERROR(
"Could not generator iterator to set up toys");
256 for(; iter_ptr !=
nullptr && *(*iter_ptr) !=
nullptr; iter_ptr->Next()){
257 RooRealVar *arg =
static_cast<RooRealVar*
>(*(*iter_ptr));
258 if(arg ==
nullptr)
continue;
259 string name = arg->GetName();
260 if(
Contains(name,
"nobsmc"))
continue;
270 generate_n(sd.begin(), sd.size(), ref(r));
271 seed_seq ss(begin(sd), end(sd));
272 return mt19937_64(ss);
276 using param_t = decltype(
dist_)::param_type;
277 dist_.param(param_t{rate});
283 string old_name =
w_.GetName();
285 gDirectory->Delete(old_name.c_str());
287 w_ = RooWorkspace(
"w");
300 for(
const auto &block:
blocks_){
325 w_.factory((
"r[1.,0.,"+to_string(
rmax_)+
"]").c_str());
332 vector<string> lines;
334 while(getline(file, one_line)){
337 lines.push_back(one_line);
341 vector<vector<string> > words;
342 for(
const auto &line: lines){
343 vector<string> these_words =
Tokenize(line);
344 words.push_back(these_words);
350 auto process_list = all_prc;
351 process_list.clear();
356 for(
const auto &line: words){
359 for(
const auto &word: line) out += word;
360 ERROR(
"Bad systematics line: "+out);
362 if(line.at(0) ==
"SYSTEMATIC"){
368 }
else if(line[0] ==
"PROCESSES"){
369 process_list.clear();
370 for(
size_t iword = 1; iword < line.size(); ++iword){
372 vector<string> names =
Tokenize(line.at(iword),
", ");
373 for(
const auto &
name: names){
374 for(
const auto &prc: all_prc){
375 if(
name == prc.Name()){
376 Append(process_list, prc);
381 ERROR(
"Systematic "+this_systematic.
Name()
382 +
" could not be applied to process "+line.at(iword));
388 string clean_line(line.at(0));
391 for(
const auto &block:
blocks_){
392 for(
const auto &vbin: block.Bins()){
393 for(
const auto &bin: vbin){
394 if(bin.Name() != clean_line)
continue;
395 for(
const auto &prc: process_list){
396 float syst(atof(line.at(1).c_str()));
398 DBG(
"Systematic " << this_systematic.
Name() <<
" is NaN for bin " 399 << bin.Name() <<
", process " << prc.Name());
403 DBG(
"Systematic " << this_systematic.
Name() <<
" is infinite for bin " 404 << bin.Name() <<
", process " << prc.Name());
411 if(syst>=0) this_systematic.
Strength(bin, prc) = log(1+syst);
412 else this_systematic.
Strength(bin, prc) = -log(1+fabs(syst));
420 ERROR(
"Systematic "+this_systematic.
Name()
421 +
" could not be applied to bin "+line.at(0));
436 }
while (line != old);
437 while(line.size() > 0 && line[0] ==
' '){
438 line = line.substr(1);
440 if(line.size() > 0 && line[0] ==
'#'){
448 set<Block> new_blocks;
449 for(
const auto &block:
blocks_){
450 Block new_block = block;
451 for(
auto &vbin: new_block.
Bins()){
452 for(
auto &bin: vbin){
458 if(dilep_bin.
Blind()){
460 dilep_gp +=
GetYield(dilep_bin, bkg, dilep_baseline);
466 double strength = 1.;
467 string name =
"dilep_"+bin.Name();
468 if(dilep_gp.
Yield()>1.){
469 strength = 1./sqrt(dilep_gp.
Yield());
472 bin.AddSystematic(syst);
475 Append(new_blocks, new_block);
477 blocks_ = new_blocks;
482 return Contains(static_cast<string>(bin.
Cut()),
"mt>")
483 && (
Contains(static_cast<string>(bin.
Cut()),
"(nels+nmus)==1")
484 ||
Contains(static_cast<string>(bin.
Cut()),
"(nmus+nels)==1")
485 ||
Contains(static_cast<string>(bin.
Cut()),
"nels+nmus==1")
486 ||
Contains(static_cast<string>(bin.
Cut()),
"nmus+nels==1")
487 ||
Contains(static_cast<string>(bin.
Cut()),
"nleps==1")
497 DBG(bin <<
", " << dilep_bin <<
", " << dilep_cut);
500 dilep_bin.
Name(
"dilep_"+dilep_bin.
Name());
502 dilep_bin.
Cut().
Replace(
"(nels+nmus)==1",
"(nels+nmus)==2");
503 dilep_bin.
Cut().
Replace(
"(nmus+nels)==1",
"(nmus+nels)==2");
504 dilep_bin.
Cut().
Replace(
"nels+nmus==1",
"nels+nmus==2");
505 dilep_bin.
Cut().
Replace(
"nmus+nels==1",
"nmus+nels==2");
506 dilep_bin.
Cut().
Replace(
"nleps==1",
"nleps==2");
507 dilep_bin.
Cut().
RmCutOn(
"nbm",
"nbm>=1&&nbm<=2");
508 dilep_bin.
Cut().
RmCutOn(
"met",
"met>200&&met<=400");
510 dilep_cut.
Replace(
"(nels+nmus)==1",
"(nels+nmus)==2");
511 dilep_cut.
Replace(
"(nmus+nels)==1",
"(nmus+nels)==2");
512 dilep_cut.
Replace(
"nels+nmus==1",
"nels+nmus==2");
513 dilep_cut.
Replace(
"nmus+nels==1",
"nmus+nels==2");
514 dilep_cut.
Replace(
"nleps==1",
"nleps==2");
515 dilep_cut.
RmCutOn(
"nbm",
"nbm>=1&&nbm<=2");
516 dilep_cut.
RmCutOn(
"met",
"met>200&&met<=400");
522 for(
const auto &block:
blocks_){
523 for(
const auto &vbin: block.Bins()){
524 for(
const auto &bin: vbin){
525 for(
const auto &syst: bin.Systematics()){
527 string full_name = syst.Name()+
"_BLK_"+block.Name()+
"_BIN_"+bin.Name();
529 oss <<
"strength_" << full_name <<
"[" << syst.Strength() <<
"]" << flush;
530 w_.factory(oss.str().c_str());
532 oss <<
"expr::" << full_name
533 <<
"('exp(@0*@1)',strength_" << full_name <<
"," << syst.Name() <<
")" << flush;
534 w_.factory(oss.str().c_str());
542 for(
const auto &bkg: all_prcs){
543 for(
const auto &syst: bkg.Systematics()){
545 string full_name = syst.Name()+
"_PRC_"+bkg.Name();
547 oss <<
"strength_" << full_name <<
"[" << syst.Strength() <<
"]" << flush;
548 w_.factory(oss.str().c_str());
550 oss <<
"expr::" << full_name
551 <<
"('exp(@0*@1)',strength_" << full_name <<
"," << syst.Name() <<
")" << flush;
552 w_.factory(oss.str().c_str());
558 for(
const auto &block: blocks_){
559 for(
const auto &vbin: block.Bins()){
560 for(
const auto &bin: vbin){
561 for(
const auto &prc: all_prcs){
562 if(!syst.HasEntry(bin, prc))
continue;
563 string full_name = syst.Name()+
"_BIN_"+bin.Name()+
"_PRC_"+prc.Name();
565 oss <<
"strength_" << full_name <<
"[" << syst.Strength(bin, prc) <<
"]" << flush;
566 w_.factory(oss.str().c_str());
568 oss <<
"expr::" << full_name
569 <<
"('exp(@0*@1)',strength_" << full_name <<
"," << syst.Name() <<
")" << flush;
570 w_.factory(oss.str().c_str());
583 oss << name <<
"_0" << flush;
585 oss <<
"[0.]" << flush;
586 w_.factory(oss.str().c_str());
587 w_.factory((
"RooGaussian::constraint_"+name+
"("+name+
"[0.,-10.,10.],"+name+
"_0,1.)").c_str());
594 for(
const auto &vbin: block.
Bins()){
595 for(
const auto &bin: vbin){
612 oss <<
"nobs_BLK_" << block.
Name()
613 <<
"_BIN_" << bin.Name() << flush;
617 oss <<
"[" << gps.
Yield() <<
"]" << flush;
618 w_.factory(oss.str().c_str());
625 for(
const auto &vbin: block.
Bins()){
626 for(
const auto &bin: vbin){
628 string var =
"expr::frac_BIN_"+bin.Name()+
"_PRC_"+bkg.Name()
629 +
"('@0/@1',ymc_BLK_"+block.
Name()+
"_BIN_"+bin.Name()+
"_PRC_"+bkg.Name()
630 +
",ymc_BLK_"+block.
Name()+
"_BIN_"+bin.Name()+
")";
631 w_.factory(var.c_str());
641 ostringstream rxss, ryss;
642 rxss <<
"sum::rxnorm_BLK_" << block.
Name() <<
"(1.,";
643 ryss <<
"sum::rynorm_BLK_" << block.
Name() <<
"(1.,";
645 oss <<
"norm_BLK_" << block.
Name() << flush;
647 oss <<
"[" << max(1., 0.8*by.
Total().
Yield()) <<
",0.," 648 << max(5.*by.
Total().
Yield(), 20.) <<
"]" << flush;
649 w_.factory(oss.str().c_str());
650 for(
size_t irow = 0; irow < by.
RowSums().size(); ++irow){
651 if(irow == by.
MaxRow())
continue;
653 oss <<
"ry" << (irow+1) << (by.
MaxRow()+1) <<
"_BLK_" << block.
Name() << flush;
654 ryss <<
"," << oss.str();
657 <<
",0.,10.]" << flush;
658 w_.factory(oss.str().c_str());
660 ryss <<
")" << flush;
661 w_.factory(ryss.str().c_str());
662 for(
size_t icol = 0; icol < by.
ColSums().size(); ++icol){
663 if(icol == by.
MaxCol())
continue;
665 oss <<
"rx" << (icol+1) << (by.
MaxCol()+1) <<
"_BLK_" << block.
Name() << flush;
666 rxss <<
"," << oss.str();
669 <<
",0.,10.]" << flush;
670 w_.factory(oss.str().c_str());
672 rxss <<
")" << flush;
673 w_.factory(rxss.str().c_str());
675 oss <<
"prod::rnorm_BLK_" << block.
Name()
676 <<
"(rxnorm_BLK_" << block.
Name()
677 <<
",rynorm_BLK_" << block.
Name() <<
")" << flush;
678 w_.factory(oss.str().c_str());
680 oss <<
"expr::rscale_BLK_" << block.
Name()
681 <<
"('@0/@1',norm_BLK_" << block.
Name()
682 <<
",rnorm_BLK_" << block.
Name() <<
")" << flush;
683 w_.factory(oss.str().c_str());
689 size_t max_row = by.
MaxRow();
690 size_t max_col = by.
MaxCol();
691 for(
size_t irow = 0; irow < block.
Bins().size(); ++irow){
692 for(
size_t icol = 0; icol < block.
Bins().at(irow).size(); ++icol){
693 const Bin &bin = block.
Bins().at(irow).at(icol);
694 string bb_name =
"BLK_"+block.
Name()+
"_BIN_"+bin.
Name();
695 vector<string> prod_list;
697 string prod_name =
"rate_"+bb_name+
"_PRC_"+bkg.Name();
698 Append(prod_list, prod_name);
699 string factory_string =
"prod::"+prod_name+
"(rscale_BLK_"+block.
Name();
702 oss <<
",rx" << (icol+1) << (max_col+1) <<
"_BLK_" << block.
Name() << flush;
703 factory_string += oss.str();
707 oss <<
",ry" << (irow+1) << (max_row+1) <<
"_BLK_" << block.
Name() << flush;
708 factory_string += oss.str();
710 factory_string += (
",frac_BIN_"+bin.
Name()+
"_PRC_"+bkg.Name());
712 for(
const auto &syst: bkg.Systematics()){
713 factory_string += (
","+syst.Name()+
"_PRC_"+bkg.Name());
716 if(syst.HasEntry(bin, bkg)){
717 factory_string += (
","+syst.Name()+
"_BIN_"+bin.
Name()+
"_PRC_"+bkg.Name());
721 factory_string +=
")";
722 w_.factory(factory_string.c_str());
724 string factory_string=
"sum::nbkg_raw_"+bb_name+
"(";
725 for(
auto prod = prod_list.cbegin(); prod != prod_list.cend(); ++prod){
726 if(prod != prod_list.cbegin()) factory_string +=
",";
727 factory_string += *prod;
729 factory_string +=
")";
730 w_.factory(factory_string.c_str());
746 for(
const auto &vbin: block.
Bins()){
747 for(
const auto &bin: vbin){
748 string bb_name =
"BLK_"+block.
Name()+
"_BIN_"+bin.Name();
752 for(
const auto &bkg: all_prcs){
755 string bbp_name = bb_name +
"_PRC_"+bkg.Name();
757 oss <<
"nobsmc_" << bbp_name << flush;
759 oss <<
"[" << gp.
NEffective() <<
"]" << flush;
760 w_.factory(oss.str().c_str());
762 oss <<
"nmc_" << bbp_name << flush;
765 <<
",0.," << max(5.*gp.
NEffective(), 20.) <<
"]" << flush;
766 w_.factory(oss.str().c_str());
768 oss <<
"wmc_" << bbp_name <<
"[" << gp.
Weight() <<
"]" << flush;
769 w_.factory(oss.str().c_str());
771 oss <<
"prod::ymc_" << bbp_name
772 <<
"(nmc_" << bbp_name
773 <<
",wmc_" << bbp_name <<
")" << flush;
774 w_.factory(oss.str().c_str());
784 string factory_string =
"PROD::pdf_mc_"+block.
Name()+
"(";
785 for(
const auto &vbin: block.
Bins()){
786 for(
const auto &bin: vbin){
789 for(
const auto &bkg: all_prcs){
790 string bbp_name =
"BLK_"+block.
Name()+
"_BIN_"+bin.Name()+
"_PRC_"+bkg.Name();
792 if(first) first =
false;
793 else factory_string +=
",";
794 factory_string +=
"pdf_mc_"+bbp_name;
798 factory_string +=
")";
799 w_.factory(factory_string.c_str());
804 for(
const auto &vbin: block.
Bins()){
805 for(
const auto &bin: vbin){
807 string bb_name =
"BLK_"+block.
Name()+
"_BIN_"+bin.Name();
808 oss <<
"sum::ymc_" << bb_name <<
"(";
811 string name =
"ymc_"+bb_name+
"_PRC_"+bkg->Name();
814 name =
"ymc_"+bb_name+
"_PRC_"+bkg->Name();
819 w_.factory(oss.str().c_str());
826 for(
size_t irow = 0; irow < block.
Bins().size(); ++irow){
828 oss <<
"sum::rowmc" << (irow+1) <<
"_BLK_" << block.
Name() <<
"(";
829 auto bin = block.
Bins().at(irow).cbegin();
830 oss <<
"ymc_BLK_" << block.
Name() <<
"_BIN_" << bin->Name();
831 for(++bin; bin != block.
Bins().at(irow).cend(); ++bin){
832 oss <<
",ymc_BLK_" << block.
Name() <<
"_BIN_" << bin->Name();
835 w_.factory(oss.str().c_str());
841 if(block.
Bins().size() > 0 && block.
Bins().at(0).size() > 0){
842 for(
size_t icol = 0; icol < block.
Bins().at(0).size(); ++icol){
844 oss <<
"sum::colmc" << (icol+1) <<
"_BLK_" << block.
Name() <<
"(";
846 oss <<
"ymc_BLK_" << block.
Name() <<
"_BIN_" << block.
Bins().at(irow).at(icol).Name();
847 for(irow = 1; irow < block.
Bins().size(); ++irow){
848 if(icol < block.
Bins().at(irow).size()){
849 oss <<
",ymc_BLK_" << block.
Name() <<
"_BIN_" << block.
Bins().at(irow).at(icol).Name();
852 oss <<
")" << flush;;
853 w_.factory(oss.str().c_str());
861 oss <<
"sum::totmc_BLK_" << block.
Name() <<
"(";
862 if(block.
Bins().size() > 0){
863 oss <<
"rowmc1_BLK_" << block.
Name();
864 for(
size_t irow = 1; irow < block.
Bins().size(); ++irow){
865 oss <<
",rowmc" << (irow+1) <<
"_BLK_" << block.
Name();
869 w_.factory(oss.str().c_str());
874 for(
size_t irow = 0; irow < block.
Bins().size(); ++irow){
875 for(
size_t icol = 0; icol < block.
Bins().at(irow).size(); ++icol){
876 const Bin &bin = block.
Bins().at(irow).at(icol);
878 oss <<
"expr::predmc_BLK_" << block.
Name() <<
"_BIN_" << bin.
Name() <<
"(" 879 <<
"'(@0*@1)/@2',rowmc" << (irow+1) <<
"_BLK_" << block.
Name()
880 <<
",colmc" << (icol+1) <<
"_BLK_" << block.
Name()
881 <<
",totmc_BLK_" << block.
Name() <<
")" << flush;
882 w_.factory(oss.str().c_str());
889 for(
size_t irow = 0; irow < block.
Bins().size(); ++irow){
890 for(
size_t icol = 0; icol < block.
Bins().at(irow).size(); ++icol){
891 const Bin &bin = block.
Bins().at(irow).at(icol);
892 string bb_name =
"BLK_"+block.
Name()+
"_BIN_"+bin.
Name();
894 oss <<
"expr::kappamc_" << bb_name <<
"(" 895 <<
"'@0/@1',ymc_" << bb_name
896 <<
",predmc_" << bb_name
898 w_.factory(oss.str().c_str());
905 for(
const auto &vbin: block.
Bins()){
906 for(
const auto &bin: vbin){
907 string bb_name =
"BLK_"+block.
Name()+
"_BIN_"+bin.Name();
909 oss <<
"prod::nbkg_" << bb_name <<
"(" 910 <<
"nbkg_raw_" << bb_name;
911 for(
const auto &syst: bin.Systematics()){
913 oss <<
"," << syst.Name() <<
"_" << bb_name;
918 for(
const auto &syst: prc.Systematics()){
919 oss <<
"," << syst.Name() <<
"_BIN_" << bin.Name() <<
"_PRC_" << prc.Name();
924 oss <<
",kappamc_" << bb_name;
927 w_.factory(oss.str().c_str());
934 for(
const auto &vbin: block.
Bins()){
935 for(
const auto &bin: vbin){
938 oss <<
"prod::nsig_BLK_" << block.
Name()
939 <<
"_BIN_" << bin.Name()
941 <<
"ymc_BLK_" << block.
Name()
942 <<
"_BIN_" << bin.Name()
946 oss <<
"," << syst.Name() <<
"_BIN_" << bin.Name() <<
"_PRC_" <<
signal_.
Name();
949 if(!syst.HasEntry(bin,
signal_))
continue;
950 oss <<
"," << syst.Name() <<
"_BIN_" << bin.Name() <<
"_PRC_" <<
signal_.
Name();
954 w_.factory(oss.str().c_str());
961 string null_list =
"", alt_list =
"";
962 bool is_first =
true;
963 for(
const auto &vbin: block.
Bins()){
964 for(
const auto &bin: vbin){
969 string bb_name =
"_BLK_"+block.
Name() +
"_BIN_"+bin.Name();
970 string null_name =
"pdf_null"+bb_name;
971 string alt_name =
"pdf_alt"+bb_name;
972 w_.factory((
"sum::nexp"+bb_name+
"(nbkg"+bb_name+
",nsig"+bb_name+
")").c_str());
974 null_list += null_name;
975 alt_list += alt_name;
976 AddPoisson(
"pdf_null"+bb_name,
"nobs"+bb_name,
"nbkg"+bb_name,
false);
977 AddPoisson(
"pdf_alt"+bb_name,
"nobs"+bb_name,
"nexp"+bb_name,
false);
982 w_.factory((
"PROD:pdf_null_BLK_"+block.
Name()+
"("+null_list+
")").c_str());
983 w_.factory((
"PROD:pdf_alt_BLK_"+block.
Name()+
"("+alt_list+
")").c_str());
988 const auto &bins = block.
Bins();
989 for(
size_t iy = 1; iy < bins.size(); ++iy){
990 for(
size_t ix = 1; ix < bins.at(iy).size(); ++ix){
991 const auto &r1 =
"BLK_"+block.
Name()+
"_BIN_"+bins.at(0).at(0).Name();
992 const auto &r2 =
"BLK_"+block.
Name()+
"_BIN_"+bins.at(0).at(ix).Name();
993 const auto &r3 =
"BLK_"+block.
Name()+
"_BIN_"+bins.at(iy).at(0).Name();
994 const auto &r4 =
"BLK_"+block.
Name()+
"_BIN_"+bins.at(iy).at(ix).Name();
995 w_.factory((
"expr::syskappa_"+r4+
"('(@0*@1)/(@2*@3)',nbkg_"+r4+
",nbkg_"+r1+
",nbkg_"+r2+
",nbkg_"+r3+
")").c_str());
996 w_.factory((
"expr::nosyskappa_"+r4+
"('(@0*@1)/(@2*@3)',ymc_"+r4+
",ymc_"+r1+
",ymc_"+r2+
",ymc_"+r3+
")").c_str());
1002 w_.factory(
"RooGaussian::pdf_dummy_nuisance(dummy_nuisance[0.,-10.,10.],0.,1.)");
1008 string null_list =
"";
1009 string alt_list =
"";
1010 bool is_first =
true;
1011 for(
const auto &block:
blocks_){
1012 null_list += (is_first ?
"pdf_null_BLK_" :
",pdf_null_BLK_") +block.Name();
1013 alt_list += (is_first ?
"pdf_alt_BLK_" :
",pdf_alt_BLK_" ) +block.Name();
1018 null_list += (
",constraint_"+syst);
1019 alt_list += (
",constraint_"+syst);
1022 for(
const auto & block: blocks_){
1023 null_list += (
",pdf_mc_"+block.Name());
1024 alt_list += (
",pdf_mc_"+block.Name());
1026 w_.factory((
"PROD::model_b("+null_list+
")").c_str());
1027 w_.factory((
"PROD::model_s("+alt_list+
")").c_str());
1036 auto xxx =
w_.set(
"observables");
1037 RooDataSet data_obs{
"data_obs",
"data_obs", *xxx};
1038 data_obs.add(*
w_.set(
"observables"));
1039 w_.import(data_obs);
1045 if(var_names.size()==0){
1046 w_.defineSet(set_name.c_str(),
"");
1048 w_.defineSet(set_name.c_str(), var_names.cbegin()->c_str());
1049 for(
auto name = ++var_names.cbegin();
1050 name != var_names.cend();
1052 w_.extendSet(set_name.c_str(),
name->c_str());
1059 RooStats::ModelConfig model_config(
"ModelConfig", &
w_);
1060 model_config.SetPdf(*
w_.pdf(
"model_s"));
1061 model_config.SetParametersOfInterest(*
w_.set(
"POI"));
1062 model_config.SetObservables(*
w_.set(
"observables"));
1063 model_config.SetNuisanceParameters(*
w_.set(
"nuisances"));
1064 model_config.SetGlobalObservables(*
w_.set(
"globalObservables"));
1066 RooStats::ModelConfig model_config_bonly(
"ModelConfig_bonly", &
w_);
1067 model_config_bonly.SetPdf(*
w_.pdf(
"model_b"));
1068 model_config_bonly.SetParametersOfInterest(*
w_.set(
"POI"));
1069 model_config_bonly.SetObservables(*
w_.set(
"observables"));
1070 model_config_bonly.SetNuisanceParameters(*
w_.set(
"nuisances"));
1071 model_config_bonly.SetGlobalObservables(*
w_.set(
"globalObservables"));
1073 w_.import(model_config);
1074 w_.import(model_config_bonly);
1078 const string &n_name,
1079 const string &mu_name,
1081 RooAbsReal *v_mu =
w_.var(mu_name.c_str());
1082 if(!v_mu) v_mu =
w_.function(mu_name.c_str());
1083 if(!v_mu) v_mu =
w_.var(n_name.c_str());
1084 if(!v_mu) v_mu =
w_.function(n_name.c_str());
1085 double mu = v_mu->getVal();
1086 if(mu <= 50. || !allow_approx){
1087 w_.factory((
"RooPoisson::"+pdf_name+
"("+n_name+
","+mu_name+
")").c_str());
1088 (
static_cast<RooPoisson*
>(
w_.pdf(pdf_name.c_str())))->setNoRounding();
1089 (
static_cast<RooPoisson*
>(
w_.pdf(pdf_name.c_str())))->protectNegativeMean();
1091 w_.factory((
"expr::sqrt_"+mu_name+
"('sqrt(@0)',"+mu_name+
")").c_str());
1092 w_.factory((
"RooGaussian::"+pdf_name+
"("+n_name+
","+mu_name+
",sqrt_"+mu_name+
")").c_str());
1097 for(
const auto &block: wg.
blocks_){
1098 for(
const auto &vbin: block.Bins()){
1099 for(
const auto &bin: vbin){
1114 DBG(bin <<
", " << process <<
", " << block);
1123 name << (process.
IsData() ?
"nobs" : process.
IsSignal() ?
"ymc" :
"rate")
1124 <<
"_BLK_" << block.
Name()
1125 <<
"_BIN_" << bin.
Name();
1127 name <<
"_PRC_" << process.
Name();
1131 stream << setw(64) << name.str() <<
": " 1132 << setw(8) << gp.
Yield()
1135 RooAbsReal *fp =
w_.function(name.str().c_str());
1137 stream << setw(8) << fp->getVal() << endl;
1139 stream <<
"Not found" << endl;
void Append(T &collection, const typename T::value_type &value)
WorkspaceGenerator & SetLuminosity(double luminosity)
void SetupToys(const RooArgSet &obs)
std::set< std::string > observables_
double CorrectedUncertainty() const
void AddFullBackgroundPredictions(const Block &block)
WorkspaceGenerator(const Cut &baseline, const std::set< Block > &blocks, const std::set< Process > &backgrounds, const Process &signal, const Process &data, const std::string &systematics_file="", const bool use_r4=true, const double sig_strength=0., const double sig_xsec_f=1.)
bool inject_other_signal_
WorkspaceGenerator & SetRMax(double rmax)
const std::string & Name() const
std::set< std::string > poi_
Cut & RmCutOn(const Cut &to_rm, const Cut &rep=Cut())
void AddRawBackgroundPredictions(const Block &block)
WorkspaceGenerator & SetDoSystematics(bool do_systematics)
void AddMCTotal(const Block &block)
std::set< std::string > nuisances_
const SystCollection & Systematics() const
WorkspaceGenerator & SetInjectionModel(const Process &injection)
void MakeDileptonBin(const Bin &bin, Bin &dilep_bin, Cut &dilep_cut) const
std::string systematics_file_
bool UseGausApprox() const
void AddMCRowSums(const Block &block)
double Strength(const Bin &bin, const Process &process) const
Cut & Replace(const Cut &orig, const Cut &rep)
void ReplaceAll(std::string &str, const std::string &orig, const std::string &rep)
bool Contains(const std::string &str, const std::string &pat)
static void CleanLine(std::string &line)
bool GetDefaultInjectionModel() const
bool GetDoSystematics() const
friend std::ostream & operator<<(std::ostream &stream, const WorkspaceGenerator &wg)
std::vector< GammaParams > RowSums() const
std::map< std::string, std::poisson_distribution<> > obs_gens_
static std::mt19937_64 prng_
void AddKappas(const Block &block)
void AddMCPrediction(const Block &block)
void AddMCKappa(const Block &block)
std::map< std::string, double > obs_vals_
const bool & IsData() const
std::tuple< Bin, Process, Cut > YieldKey
WorkspaceGenerator & SetKappaCorrected(bool do_kappa_correction)
void AddSignalPredictions(const Block &block)
void AddSystematicGenerator(const std::string &name)
std::set< std::string > systematics_
WorkspaceGenerator & SetDoDilepton(bool do_systematics)
void AddABCDParameters(const Block &block)
const class Cut & Cut() const
void AddMCColSums(const Block &block)
void WriteToFile(const std::string &file_name)
GammaParams Total() const
void AddMCYields(const Block &block)
bool NeedsDileptonBin(const Bin &bin) const
static int GetPoisson(double rate)
std::set< std::string > glob_observables_
void DefineParameterSet(const std::string &cat_name, const std::set< std::string > &var_names)
void ReadSystematicsFile()
static std::poisson_distribution dist_
static YieldManager yields_
std::set< Block > blocks_
std::set< FreeSystematic > free_systematics_
void AddPdfs(const Block &block)
void GenerateToys(RooArgSet &obs)
const bool & IsSignal() const
GammaParams GetYield(const YieldKey &key) const
void AddSystematicsGenerators()
const Process & GetInjectionModel() const
void PrintComparison(std::ostream &stream, const Bin &bin, const Process &process, const Block &block) const
bool do_mc_kappa_correction_
void ResetToys(RooArgSet &obs)
void AddData(const Block &block)
void AddMCPdfs(const Block &block)
std::set< Process > backgrounds_
const std::string & Name() const
const std::string & Name() const
PrintLevel GetPrintLevel() const
GammaParams GetYield(const YieldKey &key) const
const std::vector< std::vector< Bin > > & Bins() const
WorkspaceGenerator & SetDefaultInjectionModel()
void AddDileptonSystematic()
void AddMCProcessSums(const Block &block)
const double & Luminosity() const
void AddBackgroundFractions(const Block &block)
WorkspaceGenerator & SetPrintLevel(PrintLevel print_level)
bool GetKappaCorrected() const
double NEffective() const
const std::string & Name() const
bool GetDoDilepton() const
void AddDebug(const Block &block)
double GetLuminosity() const
std::vector< GammaParams > ColSums() const
static std::mt19937_64 InitializePRNG()
size_t AddToys(size_t num_toys=0)
std::vector< std::string > Tokenize(const std::string &input, const std::string &tokens=" ")
void AddPoisson(const std::string &pdf_name, const std::string &n_name, const std::string &mu_name, bool allow_approx)