80#define NoHistConst_Low "0"
81#define NoHistConst_High "2000"
94 fNomLumi(1.0), fLumiError(0),
95 fLowBin(0), fHighBin(0)
102 fSystToFix( measurement.GetConstantParams() ),
103 fParamValues( measurement.GetParamValues() ),
104 fNomLumi( measurement.GetLumi() ),
105 fLumiError( measurement.GetLumi()*measurement.GetLumiRelErr() ),
106 fLowBin( measurement.GetBinLow() ),
107 fHighBin( measurement.GetBinHigh() ) {
122 if( proto_config == NULL ) {
123 std::cout <<
"Error: Did not find 'ModelConfig' object in file: " << ws_single->
GetName()
128 std::vector<std::string> poi_list = measurement.
GetPOIList();
129 if( poi_list.size()==0 ) {
130 cxcoutWHF <<
"No Parametetrs of interest are set" << std::endl;
134 std::stringstream sstream;
135 sstream <<
"Setting Parameter(s) of Interest as: ";
136 for(
unsigned int i = 0; i < poi_list.size(); ++i) {
137 sstream << poi_list.at(i) <<
" ";
142 for(
unsigned int i = 0; i < poi_list.size(); ++i ) {
143 std::string poi_name = poi_list.at(i);
149 std::cout <<
"WARNING: Can't find parameter of interest: " << poi_name
150 <<
" in Workspace. Not setting in ModelConfig." << std::endl;
157 std::string NewModelName =
"newSimPdf";
171 proto_config->
SetPdf( *ws_single->
pdf(
"newSimPdf" ) );
178 std::cout <<
"Error: Failed to find dataset: " << expData
179 <<
" in workspace" << std::endl;
182 if(poi_list.size()!=0){
194 if( !pdf ) pdf = ws_single->
pdf( ModelName.c_str() );
195 const RooArgSet* observables = ws_single->
set(
"observables");
198 std::string SnapShotName =
"NominalParamValues";
205 std::string AsimovName = asimov.
GetName();
207 cxcoutPHF <<
"Generating additional Asimov Dataset: " << AsimovName << std::endl;
212 cxcoutPHF <<
"Importing Asimov dataset" << std::endl;
213 bool failure = ws_single->
import(*asimov_dataset,
Rename(AsimovName.c_str()));
215 std::cout <<
"Error: Failed to import Asimov dataset: " << AsimovName
217 delete asimov_dataset;
226 delete asimov_dataset;
248 string ch_name = channel.
GetName();
252 if( ws_single == NULL ) {
253 cxcoutF(
HistFactory) <<
"Error: Failed to make Single-Channel workspace for channel: " << ch_name
254 <<
" and measurement: " << measurement.
GetName() << std::endl;
284 vector<RooWorkspace*> channel_workspaces;
285 vector<string> channel_names;
287 for(
unsigned int chanItr = 0; chanItr < measurement.
GetChannels().size(); ++chanItr ) {
293 <<
" has uninitialized histogram pointers" << std::endl;
297 string ch_name = channel.
GetName();
298 channel_names.push_back(ch_name);
303 channel_workspaces.push_back(ws_single);
317 for (vector<RooWorkspace*>::iterator iter = channel_workspaces.begin() ; iter != channel_workspaces.end() ; ++iter) {
327 string prefix,
string productPrefix,
342 unsigned int histndim(1);
343 std::string classname = hist->
ClassName();
344 if (classname.find(
"TH1")==0) { histndim=1; }
345 else if (classname.find(
"TH2")==0) { histndim=2; }
346 else if (classname.find(
"TH3")==0) { histndim=3; }
352 for (
int idx=0; itr!=
fObsNameVec.end(); ++itr, ++idx ) {
353 if ( !
proto->var(itr->c_str()) ) {
354 const TAxis* axis(0);
355 if (idx==0) { axis = hist->
GetXaxis(); }
356 if (idx==1) { axis = hist->
GetYaxis(); }
357 if (idx==2) { axis = hist->
GetZaxis(); }
363 proto->var(itr->c_str())->setBins(nbins);
365 observables.
add( *
proto->var(itr->c_str()) );
371 proto->import(*histFunc);
374 proto->factory((
"prod:"+productPrefix+
"("+prefix+
"_nominal,"+systTerm+
")").c_str() );
387 for(
Int_t i=lowBin; i<highBin; ++i){
388 std::stringstream str;
395 for(
int i=lowBin; i<highBin; ++i){
396 for(
int j=0; j<highBin-lowBin; ++j){
397 if(i==j) { Cov(i,j) =
sqrt(mean(i)); }
398 else { Cov(i,j) = 0; }
405 floating, mean, Cov);
407 proto->import(constraint);
409 constraintTermNames.push_back(constraint.
GetName());
413 std::vector<HistoSys> histoSysList,
414 string prefix,
string productPrefix,
416 vector<string>& constraintTermNames){
426 unsigned int histndim(1);
427 std::string classname = nominal->
ClassName();
428 if (classname.find(
"TH1")==0) { histndim=1; }
429 else if (classname.find(
"TH2")==0) { histndim=2; }
430 else if (classname.find(
"TH3")==0) { histndim=3; }
437 for (
int idx=0; itr!=
fObsNameVec.end(); ++itr, ++idx ) {
438 if ( !
proto->var(itr->c_str()) ) {
439 const TAxis* axis(
nullptr);
440 if (idx==0) { axis = nominal->
GetXaxis(); }
441 else if (idx==1) { axis = nominal->
GetYaxis(); }
442 else if (idx==2) { axis = nominal->
GetZaxis(); }
444 std::cout <<
"Error: Too many observables. "
445 <<
"HistFactory only accepts up to 3 observables (3d) "
454 proto->var(itr->c_str())->setBins(nbins);
456 observables.
add( *
proto->var(itr->c_str()) );
468 for(
unsigned int j=0; j<histoSysList.size(); ++j){
469 std::stringstream str;
472 HistoSys& histoSys = histoSysList.at(j);
473 string histoSysName = histoSys.
GetName();
478 temp = (
RooRealVar*)
proto->factory((
"alpha_" + histoSysName + range).c_str());
481 string command=(
"Gaussian::alpha_"+histoSysName+
"Constraint(alpha_"+histoSysName+
",nom_alpha_"+histoSysName+
"[0.,-10,10],1.)");
483 constraintTermNames.push_back(
proto->factory( command.c_str() )->GetName() );
485 const_cast<RooArgSet*
>(
proto->set(
"globalObservables"))->add(*
proto->var((
"nom_alpha_"+histoSysName).c_str()));
492 vector<double> low, high;
495 for(
unsigned int j=0; j<histoSysList.size(); ++j){
496 std::stringstream str;
499 HistoSys& histoSys = histoSysList.at(j);
504 lowSet.
add(*lowFunc);
505 highSet.
add(*highFunc);
517 proto->import(interp);
520 proto->factory((
"prod:"+productPrefix+
"("+prefix+
","+systTerm+
")").c_str() );
526 string overallNorm_times_sigmaEpsilon ;
530 vector<string> normFactorNames, rangeNames;
532 if(normList.size() > 0){
534 for(vector<NormFactor>::iterator itr = normList.begin(); itr != normList.end(); ++itr){
539 if(!prodNames.empty()) prodNames +=
",";
541 varname = norm.
GetName() +
"_" + channel;
550 std::stringstream range;
553 if(
proto->obj(varname.c_str()) == NULL) {
556 proto->factory((varname + range.str()).c_str());
562 cxcoutW(
HistFactory) <<
"Const attribute to <NormFactor> tag is deprecated, will ignore." <<
563 " Instead, add \n\t<ParamSetting Const=\"True\">" << varname <<
"</ParamSetting>\n" <<
564 " to your top-level XML's <Measurment> entry" << endl;
567 rangeNames.push_back(range.str());
568 normFactorNames.push_back(varname);
571 overallNorm_times_sigmaEpsilon = sample.
GetName() +
"_" + channel +
"_overallNorm_x_sigma_epsilon";
572 proto->factory((
"prod::" + overallNorm_times_sigmaEpsilon +
"(" + prodNames +
"," + sigmaEpsilon +
")").c_str());
575 unsigned int rangeIndex=0;
576 for( vector<string>::iterator nit = normFactorNames.begin(); nit!=normFactorNames.end(); ++nit){
577 if( count (normFactorNames.begin(), normFactorNames.end(), *nit) > 1 ){
578 cxcoutI(
HistFactory) <<
"<NormFactor Name =\""<<*nit<<
"\"> is duplicated for <Sample Name=\""
579 << sample.
GetName() <<
"\">, but only one factor will be included. \n Instead, define something like"
580 <<
"\n\t<Function Name=\""<<*nit<<
"Squared\" Expresion=\""<<*nit<<
"*"<<*nit<<
"\" Var=\""<<*nit<<rangeNames.at(rangeIndex)
581 <<
"\"> \nin your top-level XML's <Measurment> entry and use <NormFactor Name=\""<<*nit<<
"Squared\" in your channel XML file."<< endl;
586 if(!overallNorm_times_sigmaEpsilon.empty())
587 return overallNorm_times_sigmaEpsilon;
594 std::vector<OverallSys>& systList,
595 vector<string>& constraintTermNames,
596 vector<string>& totSystTermNames) {
602 totSystTermNames.push_back(prefix);
605 vector<double> lowVec, highVec;
607 std::map<std::string, double>::iterator itconstr;
608 for(
unsigned int i = 0; i < systList.size(); ++i) {
611 std::string strname = sys.
GetName();
612 const char *
name = strname.c_str();
623 cxcoutI(
HistFactory) <<
"HistoToWorkspaceFast::AddConstraintTerm - zero uncertainty assigned - skip systematic " << sys.
GetName() << std::endl;
626 double tauVal = 1./(relerr*relerr);
627 double sqtau = 1./relerr;
641 alphaOfBeta->
Print(
"t");
644 constraintTermNames.push_back(gamma->GetName());
648 const_cast<RooArgSet*
>(
proto->set(
"globalObservables"))->add(*yvar);
651 params.
add(*alphaOfBeta);
661 double gaussSigma = 1;
664 cxcoutIHF <<
"Added a uniform constraint for " <<
name <<
" as a gaussian constraint with a very large sigma " << std::endl;
675 constraintTermNames.push_back( gausConstraint->
GetName() );
676 proto->var((
"nom_" + prefix + sys.
GetName()).c_str())->setConstant();
677 const_cast<RooArgSet*
>(
proto->set(
"globalObservables"))->add(*nomAlpha);
693 double tauVal = 1./relerr;
694 std::string tauName =
"tau_" + sys.
GetName();
696 double kappaVal = 1. + relerr;
697 std::string kappaName =
"kappa_" + sys.
GetName();
699 const char * alphaName = alpha->
GetName();
701 std::string alphaOfBetaName =
"alphaOfBeta_" + sys.
GetName();
703 tauName.c_str(),kappaName.c_str(),alphaName,
704 tauName.c_str(),kappaName.c_str(),alphaName ) );
708 alphaOfBeta->
Print(
"t");
709 params.
add(*alphaOfBeta);
714 double low = sys.
GetLow();
716 lowVec.push_back(low);
717 highVec.push_back(high);
721 if(systList.size() > 0){
726 assert(
int(lowVec.size()) == params.
getSize() );
728 FlexibleInterpVar interp( (interpName).c_str(),
"", params, 1., lowVec, highVec);
731 proto->import(interp);
736 proto->import(interp);
746 vector<string>& syst_x_expectedPrefixNames,
747 vector<string>& normByNames){
757 double binWidth(1.0);
758 std::string obsNameVecStr;
759 std::vector<std::string>::iterator itr =
fObsNameVec.begin();
761 std::string obsName = *itr;
762 binWidth *=
proto->var(obsName.c_str())->numBins()/(
proto->var(obsName.c_str())->getMax() -
proto->var(obsName.c_str())->getMin()) ;
763 if (obsNameVecStr.size()>0) { obsNameVecStr +=
"_"; }
764 obsNameVecStr += obsName;
768 for(
unsigned int j=0; j<syst_x_expectedPrefixNames.size();++j){
769 std::stringstream str;
773 command=string(
Form(
"binWidth_%s_%d[%e]",obsNameVecStr.c_str(),j,binWidth));
774 proto->factory(command.c_str());
775 proto->var(
Form(
"binWidth_%s_%d",obsNameVecStr.c_str(),j))->setConstant();
776 coeffList+=prepend+
"binWidth_"+obsNameVecStr+str.str();
778 command=
"prod::L_x_"+syst_x_expectedPrefixNames.at(j)+
"("+normByNames.at(j)+
","+syst_x_expectedPrefixNames.at(j)+
")";
780 proto->factory(command.c_str());
781 shapeList+=prepend+
"L_x_"+syst_x_expectedPrefixNames.at(j);
790 proto->defineSet(
"coefList",coeffList.c_str());
791 proto->defineSet(
"shapeList",shapeList.c_str());
825 vector<string>& likelihoodTermNames){
830 for(
Int_t i=lowBin; i<highBin; ++i){
831 std::stringstream str;
834 string command(
"Poisson::"+prefix+str.str()+
"("+obsPrefix+str.str()+
","+expPrefix+str.str()+
",1)");
838 cout <<
"Poisson Term " << command << endl;
842 likelihoodTermNames.push_back( temp->
GetName() );
845 proto->defineSet(prefix.c_str(),Pois);
855 for(
Int_t i=lowBin; i<highBin; ++i){
856 std::stringstream str;
859 cout <<
"expected number of events called: " << expPrefix << endl;
865 cout <<
"setting obs"+str.str()+
" to expected = " <<
exp->getVal() <<
" check: " << obs->
getVal() << endl;
868 obsForTree[i] =
exp->getVal();
869 tree->Branch((obsPrefix+str.str()).c_str(), obsForTree+i ,(obsPrefix+str.str()+
"/D").c_str());
872 cout <<
"problem retrieving obs or exp " << obsPrefix+str.str() << obs <<
" " << expPrefix+str.str() <<
exp << endl;
879 delete [] obsForTree;
881 proto->import(*data);
890 map<string,double> gammaSyst,
891 map<string,double> uniformSyst,
892 map<string,double> logNormSyst,
893 map<string,double> noSyst) {
894 string pdfName(pdfNameChar);
897 if( combined_config==NULL ) {
898 std::cout <<
"Error: Failed to find object 'ModelConfig' in workspace: "
904 string edit=
"EDIT::newSimPdf("+pdfName+
",";
906 string lastPdf=pdfName;
908 unsigned int numReplacements = 0;
909 unsigned int nskipped = 0;
910 map<string,double>::iterator it;
914 for(it=gammaSyst.begin(); it!=gammaSyst.end(); ++it) {
916 if(!
proto->var((
"alpha_"+it->first).c_str())){
923 double relativeUncertainty = it->second;
924 double scale = 1/
sqrt((1+1/
pow(relativeUncertainty,2)));
927 proto->factory(
Form(
"beta_%s[1,0,10]",it->first.c_str()));
928 proto->factory(
Form(
"y_%s[%f]",it->first.c_str(),1./
pow(relativeUncertainty,2))) ;
929 proto->factory(
Form(
"theta_%s[%f]",it->first.c_str(),
pow(relativeUncertainty,2))) ;
930 proto->factory(
Form(
"Gamma::beta_%sConstraint(beta_%s,sum::k_%s(y_%s,one[1]),theta_%s,zero[0])",
935 it->first.c_str())) ;
951 proto->factory(
Form(
"PolyVar::alphaOfBeta_%s(beta_%s,{%f,%f})",it->first.c_str(),it->first.c_str(),-1./scale,1./scale));
954 if(
proto->var(
Form(
"alpha_%s",it->first.c_str()))->isConstant()) {
955 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
true);
958 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
false);
964 editList+=precede +
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint";
966 editList+=precede +
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first;
976 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
977 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
981 cout <<
"Going to issue this edit command\n" << edit<< endl;
982 proto->factory( edit.c_str() );
985 cxcoutWHF <<
"---------------------\n WARNING: failed to make EDIT\n\n" << endl;
991 for(it=uniformSyst.begin(); it!=uniformSyst.end(); ++it) {
992 cout <<
"edit for " << it->first <<
"with rel uncert = " << it->second << endl;
993 if(!
proto->var((
"alpha_"+it->first).c_str())){
994 cout <<
"systematic not there" << endl;
1001 proto->factory(
Form(
"beta_%s[1,0,10]",it->first.c_str()));
1002 proto->factory(
Form(
"Uniform::beta_%sConstraint(beta_%s)",it->first.c_str(),it->first.c_str()));
1003 proto->factory(
Form(
"PolyVar::alphaOfBeta_%s(beta_%s,{-1,1})",it->first.c_str(),it->first.c_str()));
1006 if(
proto->var(
Form(
"alpha_%s",it->first.c_str()))->isConstant())
1007 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
true);
1009 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
false);
1014 cout <<
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint" << endl;
1015 editList+=precede +
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint";
1017 cout <<
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first << endl;
1018 editList+=precede +
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first;
1020 if(
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) &&
proto->var((
"alpha_"+it->first).c_str()) )
1021 cout <<
" checked they are there" <<
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) <<
" " <<
proto->var((
"alpha_"+it->first).c_str()) << endl;
1023 cout <<
"NOT THERE" << endl;
1026 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
1027 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
1031 cout << edit<< endl;
1032 proto->factory( edit.c_str() );
1035 cxcoutWHF <<
"---------------------\n WARNING: failed to make EDIT\n\n" << endl;
1045 for(it=logNormSyst.begin(); it!=logNormSyst.end(); ++it) {
1046 cout <<
"edit for " << it->first <<
"with rel uncert = " << it->second << endl;
1047 if(!
proto->var((
"alpha_"+it->first).c_str())){
1048 cout <<
"systematic not there" << endl;
1054 double relativeUncertainty = it->second;
1055 double kappa = 1+relativeUncertainty;
1059 double scale = relativeUncertainty;
1062 const char * cname = it->first.c_str();
1069 cname, cname, cname, cname)) ;
1070 proto->factory(
TString::Format(
"PolyVar::alphaOfBeta_%s(beta_%s,{%f,%f})",cname,cname,-1./scale,1./scale));
1082 cout <<
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint" << endl;
1083 editList+=precede +
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint";
1085 cout <<
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first << endl;
1086 editList+=precede +
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first;
1088 if(
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) &&
proto->var((
"alpha_"+it->first).c_str()) )
1089 cout <<
" checked they are there" <<
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) <<
" " <<
proto->var((
"alpha_"+it->first).c_str()) << endl;
1091 cout <<
"NOT THERE" << endl;
1094 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
1095 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
1099 cout << edit<< endl;
1100 proto->factory( edit.c_str() );
1103 cxcoutWHF <<
"\n\n ---------------------\n WARNING: failed to make EDIT\n\n" << endl;
1110 proto->removeSet(
"globalObservables");
1111 proto->defineSet(
"globalObservables",gobsNew);
1119 for(it=noSyst.begin(); it!=noSyst.end(); ++it) {
1121 cout <<
"remove constraint for parameter" << it->first << endl;
1122 if(!
proto->var((
"alpha_"+it->first).c_str()) || !
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) ) {
1123 cout <<
"systematic not there" << endl;
1130 if ( !
proto->var(
"one") ) {
proto->factory(
"one[1.0]"); }
1131 proto->var(
"one")->setConstant();
1134 cout <<
"alpha_"+it->first+
"Constraint=one" << endl;
1135 editList+=precede +
"alpha_"+it->first+
"Constraint=one";
1139 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
1140 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
1144 cout << edit << endl;
1145 proto->factory( edit.c_str() );
1148 cxcoutWHF <<
"---------------------\n WARNING: failed to make EDIT\n\n" << endl;
1156 edit=
"EDIT::newSimPdf("+lastPdf+
","+editList+
")";
1157 cout << edit<< endl;
1158 proto->factory( edit.c_str() );
1163 combined_config->
SetPdf(*newOne);
1166 cxcoutWHF <<
"\n\n ---------------------\n WARNING: failed to make EDIT\n\n" << endl;
1173 FILE* covFile = fopen ((filename).c_str(),
"w");
1178 fprintf(covFile,
" ") ;
1181 fprintf(covFile,
" & %s", myargi->
GetName());
1183 fprintf(covFile,
"\\\\ \\hline \n" );
1187 fprintf(covFile,
"%s", myargi->
GetName());
1192 fprintf(covFile,
" & %.2f", result->
correlation(*myargi, *myargj));
1195 fprintf(covFile,
" \\\\\n");
1208 Error(
"MakeSingleChannelWorkspace",
1209 "The input Channel does not contain any sample - return a nullptr");
1213 const TH1* channel_hist_template = channel.
GetSamples().front().GetHisto();
1214 if (channel_hist_template ==
nullptr) {
1216 channel_hist_template = channel.
GetSamples().front().GetHisto();
1218 if (channel_hist_template ==
nullptr) {
1219 std::ostringstream stream;
1220 stream <<
"The sample " << channel.
GetSamples().front().GetName()
1221 <<
" in channel " << channel.
GetName() <<
" does not contain a histogram. This is the channel:\n";
1222 channel.
Print(stream);
1223 Error(
"MakeSingleChannelWorkspace",
"%s", stream.str().c_str());
1228 std::cout <<
"MakeSingleChannelWorkspace: Channel: " << channel.
GetName()
1229 <<
" has uninitialized histogram pointers" << std::endl;
1243 string channel_name = channel.
GetName();
1253 for (
unsigned int idx=0; idx<
fObsNameVec.size(); ++idx ) {
1265 <<
"\tStarting to process '"
1266 << channel_name <<
"' channel with " <<
fObsNameVec.size() <<
" observables"
1267 <<
"\n-----------------------------------------\n" << endl;
1273 auto proto_config = make_unique<ModelConfig>(
"ModelConfig",
proto);
1274 proto_config->SetWorkspace(*
proto);
1280 proto->factory(funcIter->c_str());
1284 RooArgSet likelihoodTerms(
"likelihoodTerms"), constraintTerms(
"constraintTerms");
1285 vector<string> likelihoodTermNames, constraintTermNames, totSystTermNames, syst_x_expectedPrefixNames, normalizationNames;
1287 vector< pair<string,string> > statNamePairs;
1288 vector< pair<const TH1*, const TH1*> > statHistPairs;
1289 std::string statFuncName;
1290 std::string statNodeName;
1294 string prefix, range;
1299 std::stringstream lumiStr;
1302 proto->factory((
"Lumi"+lumiStr.str()).c_str());
1305 std::stringstream lumiErrorStr;
1307 proto->factory((
"Gaussian::lumiConstraint(Lumi,"+lumiErrorStr.str()+
")").c_str());
1308 proto->var(
"nominalLumi")->setConstant();
1309 proto->defineSet(
"globalObservables",
"nominalLumi");
1311 constraintTermNames.push_back(
"lumiConstraint");
1319 vector<Sample>::iterator it = channel.
GetSamples().begin();
1320 for(; it!=channel.
GetSamples().end(); ++it) {
1324 string overallSystName = sample.
GetName() +
"_" + channel_name +
"_epsilon";
1326 string systSourcePrefix =
"alpha_";
1334 overallSystName =
AddNormFactor(
proto, channel_name, overallSystName, sample, doRatio);
1339 string syst_x_expectedPrefix =
"";
1360 string expPrefix = sample.
GetName() +
"_" + channel_name;
1361 syst_x_expectedPrefix = sample.
GetName() +
"_" + channel_name +
"_overallSyst_x_Exp";
1369 string constraintPrefix = sample.
GetName() +
"_" + channel_name +
"_Hist_alpha";
1370 syst_x_expectedPrefix = sample.
GetName() +
"_" + channel_name +
"_overallSyst_x_HistSyst";
1375 constraintPrefix, syst_x_expectedPrefix, overallSystName,
1376 constraintTermNames);
1386 cxcoutF(
HistFactory) <<
"Cannot include Stat Error for histograms of more than 3 dimensions."
1396 <<
"for channel " << channel_name
1426 string UncertName = syst_x_expectedPrefix +
"_StatAbsolUncert";
1427 TH1* statErrorHist = NULL;
1432 <<
" Channel: " << channel_name
1433 <<
" Sample: " << sample.
GetName()
1445 <<
"\tChannel: " << channel_name
1446 <<
"\tSample: " << sample.
GetName()
1447 <<
"\tError Histogram: " << statErrorHist->
GetName() << std::endl;
1450 statErrorHist->
Multiply( nominal );
1451 statErrorHist->
SetName( UncertName.c_str() );
1456 statHistPairs.push_back( std::make_pair(nominal, statErrorHist) );
1473 statFuncName =
"mc_stat_" + channel_name;
1475 if( paramHist == NULL ) {
1481 for (
int idx=0; itr!=
fObsNameVec.end(); ++itr, ++idx ) {
1482 observables.
add( *
proto->var(itr->c_str()) );
1487 std::string ParamSetPrefix =
"gamma_stat_" + channel_name;
1491 ParamSetPrefix.c_str(),
1493 gammaMin, gammaMax);
1495 ParamHistFunc statUncertFunc(statFuncName.c_str(), statFuncName.c_str(),
1496 observables, statFactorParams );
1507 statNodeName = sample.
GetName() +
"_" + channel_name +
"_overallSyst_x_StatUncert";
1510 RooProduct nodeWithMcStat(statNodeName.c_str(), statNodeName.c_str(),
1518 syst_x_expectedPrefix = nodeWithMcStat.
GetName();
1531 cxcoutF(
HistFactory) <<
"Cannot include Stat Error for histograms of more than 3 dimensions."
1537 <<
" to be include a ShapeFactor."
1540 std::vector<ParamHistFunc*> paramHistFuncList;
1541 std::vector<std::string> shapeFactorNameList;
1547 std::string funcName = channel_name +
"_" + shapeFactor.
GetName() +
"_shapeFactor";
1549 if( paramHist == NULL ) {
1553 for (
int idx=0; itr!=
fObsNameVec.end(); ++itr, ++idx ) {
1554 observables.
add( *
proto->var(itr->c_str()) );
1558 std::string funcParams =
"gamma_" + shapeFactor.
GetName();
1564 observables, 0, 1000);
1567 ParamHistFunc shapeFactorFunc( funcName.c_str(), funcName.c_str(),
1568 observables, shapeFactorParams );
1574 <<
" to have initial shape from hist: "
1577 shapeFactorFunc.
setShape( initialShape );
1583 <<
" to be constant" << std::endl;
1592 paramHistFuncList.push_back(paramHist);
1593 shapeFactorNameList.push_back(funcName);
1602 std::string shapeFactorNodeName = syst_x_expectedPrefix;
1603 for(
unsigned int i=0; i < shapeFactorNameList.size(); ++i) {
1604 shapeFactorNodeName +=
"_x_" + shapeFactorNameList.at(i);
1609 for(
unsigned int i=0; i < paramHistFuncList.size(); ++i) {
1610 nodesForProduct.
add( *paramHistFuncList.at(i) );
1615 RooProduct nodeWithShapeFactor(shapeFactorNodeName.c_str(),
1616 shapeFactorNodeName.c_str(),
1624 syst_x_expectedPrefix = nodeWithShapeFactor.
GetName();
1637 cxcoutF(
HistFactory) <<
"Cannot include Stat Error for histograms of more than 3 dimensions."
1643 std::vector<string> ShapeSysNames;
1659 <<
" to include a ShapeSys." << std::endl;
1661 std::string funcName = channel_name +
"_" + shapeSys.
GetName() +
"_ShapeSys";
1662 ShapeSysNames.push_back( funcName );
1664 if( paramHist == NULL ) {
1672 observables.
add( *
proto->var(itr->c_str()) );
1676 std::string funcParams =
"gamma_" + shapeSys.
GetName();
1679 observables, 0, 10);
1682 ParamHistFunc shapeFactorFunc( funcName.c_str(), funcName.c_str(),
1683 observables, shapeFactorParams );
1706 Double_t minShapeUncertainty = 0.0;
1708 *paramHist, shapeErrorHist,
1710 minShapeUncertainty);
1718 std::string NodeName = syst_x_expectedPrefix;
1721 ShapeSysForNode.
add( *expFunc );
1722 for(
unsigned int i = 0; i < ShapeSysNames.size(); ++i ) {
1723 std::string ShapeSysName = ShapeSysNames.at(i);
1724 ShapeSysForNode.
add( *
proto->function(ShapeSysName.c_str()) );
1725 NodeName = NodeName +
"_x_" + ShapeSysName;
1729 RooProduct nodeWithShapeFactor(NodeName.c_str(), NodeName.c_str(), ShapeSysForNode );
1735 syst_x_expectedPrefix = nodeWithShapeFactor.
GetName();
1744 syst_x_expectedPrefixNames.push_back(syst_x_expectedPrefix);
1750 normalizationNames.push_back(
"Lumi" );
1754 lumiParamString += measurement.
GetLumi();
1756 normalizationNames.push_back(lumiParamString.
Data());
1764 if( statHistPairs.size() > 0 ) {
1769 if( fracStatError == NULL ) {
1771 << statNodeName << std::endl;
1779 << chanStatUncertFunc->
GetName()
1780 <<
" params: " << chanStatUncertFunc->
paramList()
1799 *chanStatUncertFunc, fracStatError.
get(),
1801 statRelErrorThreshold);
1805 for (
unsigned int i = 0; i < statHistPairs.size() ; ++i )
1806 delete statHistPairs[i].second;
1808 statHistPairs.clear();
1818 syst_x_expectedPrefixNames, normalizationNames);
1819 likelihoodTermNames.push_back(channel_name+
"_model");
1823 for(
unsigned int i=0; i<systToFix.size(); ++i){
1831 if(systToFix.at(i)==
"Lumi"){
1832 auxMeas =
proto->var(
"nominalLumi");
1838 const_cast<RooArgSet*
>(
proto->set(
"globalObservables"))->remove(*auxMeas);
1845 <<
" could not set it to constant" << endl;
1851 for(
unsigned int i=0; i<constraintTermNames.size(); ++i){
1852 RooAbsArg* proto_arg = (
proto->arg(constraintTermNames[i].c_str()));
1853 if( proto_arg==NULL ) {
1858 constraintTerms.
add( *proto_arg );
1861 for(
unsigned int i=0; i<likelihoodTermNames.size(); ++i){
1862 RooAbsArg* proto_arg = (
proto->arg(likelihoodTermNames[i].c_str()));
1863 if( proto_arg==NULL ) {
1868 likelihoodTerms.add( *proto_arg );
1870 proto->defineSet(
"constraintTerms",constraintTerms);
1871 proto->defineSet(
"likelihoodTerms",likelihoodTerms);
1876 std::string observablesStr;
1880 observables.
add( *
proto->var(itr->c_str()) );
1881 if (!observablesStr.empty()) { observablesStr +=
","; }
1882 observablesStr += *itr;
1894 <<
"\timport model into workspace"
1895 <<
"\n-----------------------------------------\n" << endl;
1897 auto model = make_unique<RooProdPdf>(
1898 (
"model_"+channel_name).c_str(),
1899 "product of Poissons accross bins for a single channel",
1900 constraintTerms,
Conditional(likelihoodTerms,observables));
1903 proto_config->SetPdf(*model);
1904 proto_config->SetObservables(observables);
1905 proto_config->SetGlobalObservables(*
proto->set(
"globalObservables"));
1909 proto->import(*proto_config,proto_config->GetName());
1910 proto->importClassCode();
1915 const char* weightName=
"weightVar";
1921 int asymcalcPrintLevel = 0;
1935 <<
" is NULL" << std::endl;
1940 auto obsDataUnbinned = make_unique<RooDataSet>(
"obsData",
"",*
proto->set(
"obsAndWeight"),weightName);
1979 proto->import(*obsDataUnbinned);
1986 std::string dataName = data.
GetName();
1990 <<
" with name: " << dataName <<
" is NULL" << std::endl;
1995 auto obsDataUnbinned = make_unique<RooDataSet>(dataName.c_str(), dataName.c_str(),
1996 *
proto->set(
"obsAndWeight"), weightName);
2034 proto->import(*obsDataUnbinned);
2048 std::vector<std::string> ObsNameVec) {
2054 if (ObsNameVec.empty() ) {
2055 Error(
"ConfigureHistFactoryDataset",
"Invalid input - return");
2065 for (
int i=1; i<=ax->
GetNbins(); ++i) {
2068 proto->var( ObsNameVec[0].c_str() )->setVal( xval );
2070 if(ObsNameVec.size()==1) {
2072 obsDataUnbinned->
add( *
proto->set(
"obsAndWeight"), fval );
2075 for(
int j=1; j<=ay->
GetNbins(); ++j) {
2077 proto->var( ObsNameVec[1].c_str() )->setVal( yval );
2079 if(ObsNameVec.size()==2) {
2081 obsDataUnbinned->
add( *
proto->set(
"obsAndWeight"), fval );
2084 for(
int k=1; k<=az->
GetNbins(); ++k) {
2086 proto->var( ObsNameVec[2].c_str() )->setVal( zval );
2088 obsDataUnbinned->
add( *
proto->set(
"obsAndWeight"), fval );
2101 unsigned int histndim(1);
2102 std::string classname = hist->
ClassName();
2103 if (classname.find(
"TH1")==0) { histndim=1; }
2104 else if (classname.find(
"TH2")==0) { histndim=2; }
2105 else if (classname.find(
"TH3")==0) { histndim=3; }
2107 for (
unsigned int idx=0; idx<histndim; ++idx ) {
2120 if (ch_names.empty() || chs.empty() ) {
2121 Error(
"MakeCombinedModel",
"Input vectors are empty - return a nullptr");
2124 if (chs.size() < ch_names.size() ) {
2125 Error(
"MakeCombinedModel",
"Input vector of workspace has an invalid size - return a nullptr");
2133 map<string, RooAbsPdf*> pdfMap;
2134 vector<RooAbsPdf*> models;
2137 for(
unsigned int i = 0; i< ch_names.size(); ++i){
2145 stringstream channelString;
2146 channelString <<
"channelCat[";
2147 for(
unsigned int i = 0; i< ch_names.size(); ++i){
2148 string channel_name=ch_names[i];
2149 if (i == 0 && isdigit(channel_name[0])) {
2150 throw std::invalid_argument(
"The first channel name for HistFactory cannot start with a digit. Got " + channel_name);
2152 if (channel_name.find(
',') != std::string::npos) {
2153 throw std::invalid_argument(
"Channel names for HistFactory cannot contain ','. Got " + channel_name);
2156 if (i == 0) channelString << channel_name ;
2157 else channelString <<
',' << channel_name ;
2160 RooAbsPdf* model = ch->
pdf((
"model_"+channel_name).c_str());
2161 if(!model) cout <<
"failed to find model for channel"<<endl;
2163 models.push_back(model);
2164 globalObs.
add(*ch->
set(
"globalObservables"));
2167 pdfMap[channel_name]=model;
2169 channelString <<
"]";
2172 <<
"\tEntering combination"
2173 <<
"\n-----------------------------------------\n" << endl;
2179 if (!channelCat)
throw std::runtime_error(
"Unable to construct a category from string " + channelString.str());
2186 combined->
import(globalObs);
2187 combined->
defineSet(
"globalObservables",globalObs);
2194 <<
"\tcreate toy data for " << channelString.str()
2195 <<
"\n-----------------------------------------\n" << endl;
2201 combined->
factory(
"weightVar[0,-1e10,1e10]");
2202 obsList.
add(*combined->
var(
"weightVar"));
2223 if( asimov_combined ) {
2224 combined->
import( *asimov_combined,
Rename(
"asimovData"));
2227 std::cout <<
"Error: Failed to create combined asimov dataset" << std::endl;
2230 delete asimov_combined;
2233 if(chs[0]->data(
"obsData") != NULL) {
2234 MergeDataSets(combined, chs, ch_names,
"obsData", obsList, channelCat);
2282 obsList.
add(*channelCat);
2283 combined->
defineSet(
"observables",obsList);
2290 <<
"\tImporting combined model"
2291 <<
"\n-----------------------------------------\n" << endl;
2297 std::map< std::string, double>::iterator param_itr =
fParamValues.begin();
2300 std::string paramName = param_itr->first;
2301 double paramVal = param_itr->second;
2305 temp->
setVal( paramVal );
2306 cxcoutI(
HistFactory) <<
"setting " << paramName <<
" to the value: " << paramVal << endl;
2308 cxcoutE(
HistFactory) <<
"could not find variable " << paramName <<
" could not set its value" << endl;
2312 for(
unsigned int i=0; i<
fSystToFix.size(); ++i){
2327 combined_config->
SetPdf(*simPdf);
2330 combined->
import(*combined_config,combined_config->
GetName());
2335 delete combined_config;
2343 std::vector<RooWorkspace*> wspace_vec,
2344 std::vector<std::string> channel_names,
2345 std::string dataSetName,
2354 for(
unsigned int i = 0; i< channel_names.size(); ++i){
2357 cxcoutPHF <<
"Merging data for channel " << channel_names[i].c_str() << std::endl;
2359 if( !obsDataInChannel ) {
2360 std::cout <<
"Error: Can't find DataSet: " << dataSetName
2361 <<
" in channel: " << channel_names.at(i)
2368 obsList,
Index(*channelCat),
2370 Import(channel_names[i].c_str(),*obsDataInChannel));
2372 simData->
append(*tempData);
2383 combined->
import(*simData,
Rename(dataSetName.c_str()));
2388 std::cout <<
"Error: Unable to merge observable datasets" << std::endl;
2407 Int_t binNumber = 0;
2410 for(
Int_t i_bin = 0; i_bin < numBins; ++i_bin) {
2421 if( histError != histError ) {
2422 std::cout <<
"Warning: In histogram " << Nominal->
GetName()
2423 <<
" bin error for bin " << i_bin
2424 <<
" is NAN. Not using Error!!!"
2432 if( histError < 0 ) {
2433 std::cout <<
"Warning: In histogram " << Nominal->
GetName()
2434 <<
" bin error for bin " << binNumber
2435 <<
" is < 0. Setting Error to 0"
2460 unsigned int numHists = HistVec.size();
2462 if( numHists == 0 ) {
2463 cxcoutE(
HistFactory) <<
"Warning: Empty Hist Vector, cannot create total uncertainty" << std::endl;
2467 const TH1* HistTemplate = HistVec.at(0).first;
2472 for(
unsigned int i = 0; i < HistVec.size(); ++i ) {
2474 const TH1* nominal = HistVec.at(i).first;
2475 const TH1* error = HistVec.at(i).second;
2487 std::vector<double> TotalBinContent( numBins, 0.0);
2488 std::vector<double> HistErrorsSqr( numBins, 0.0);
2490 Int_t binNumber = 0;
2493 for(
Int_t i_bins = 0; i_bins < numBins; ++i_bins) {
2500 for(
unsigned int i_hist = 0; i_hist < numHists; ++i_hist ) {
2502 const TH1* nominal = HistVec.at(i_hist).first;
2503 const TH1* error = HistVec.at(i_hist).second;
2518 if( histError != histError ) {
2520 <<
" bin error for bin " << binNumber
2521 <<
" is NAN. Not using error!!";
2525 TotalBinContent.at(i_bins) += histValue;
2526 HistErrorsSqr.at(i_bins) += histError*histError;
2538 for(
Int_t i = 0; i < numBins; ++i) {
2546 Double_t ErrorsSqr = HistErrorsSqr.at(i);
2547 Double_t TotalVal = TotalBinContent.at(i);
2549 if( TotalVal <= 0 ) {
2551 <<
" is <= 0. Setting error to 0"
2562 if( RelativeError != RelativeError ) {
2564 <<
" HistErrorsSqr: " << ErrorsSqr
2565 <<
" TotalVal: " << TotalVal;
2579 <<
" Error = " <<
sqrt(ErrorsSqr)
2580 <<
" CentralVal = " << TotalVal
2581 <<
" RelativeError = " << RelativeError <<
"\n";
2585 return std::unique_ptr<TH1>(ErrorHist);
2621 if( numBins != numParams ) {
2622 std::cout <<
"Error: In createStatConstraintTerms, encountered bad number of bins" << std::endl;
2623 std::cout <<
"Given histogram with " << numBins <<
" bins,"
2624 <<
" but require exactly " << numParams << std::endl;
2628 Int_t TH1BinNumber = 0;
2640 <<
". Type of constraint: " <<
type << std::endl;
2644 const double sigmaRel = uncertHist->
GetBinContent(TH1BinNumber);
2648 if( sigmaRel <= 0 ){
2651 <<
" because sigma = " << sigmaRel
2653 <<
" (TH1 bin number = " << TH1BinNumber <<
")"
2655 gamma.setConstant(
kTRUE);
2660 gamma.setMax( 1 + 5*sigmaRel );
2664 std::string constrName = string(gamma.GetName()) +
"_constraint";
2665 std::string nomName = string(
"nom_") + gamma.GetName();
2666 std::string sigmaName = string(gamma.GetName()) +
"_sigma";
2667 std::string poisMeanName = string(gamma.GetName()) +
"_poisMean";
2675 RooConstVar constrSigma( sigmaName.c_str(), sigmaName.c_str(), sigmaRel );
2678 RooRealVar constrNom(nomName.c_str(), nomName.c_str(), 1.0,0,10);
2682 RooGaussian gauss( constrName.c_str(), constrName.c_str(),
2683 constrNom, gamma, constrSigma );
2689 gamma.setError(sigmaRel);
2692 Double_t tau = 1/sigmaRel/sigmaRel;
2695 RooRealVar constrNom(nomName.c_str(), nomName.c_str(), tau);
2700 std::string scalingName = string(gamma.GetName()) +
"_tau";
2701 RooConstVar poissonScaling( scalingName.c_str(), scalingName.c_str(), tau);
2704 RooProduct constrMean( poisMeanName.c_str(), poisMeanName.c_str(),
RooArgSet(gamma, poissonScaling) );
2709 RooPoisson pois(constrName.c_str(), constrName.c_str(), constrNom, constrMean);
2713 if (std::string(gamma.GetName()).find(
"gamma_stat") != std::string::npos) {
2716 gamma.setError(sigmaRel);
2721 std::cout <<
"Error: Did not recognize Stat Error constraint term type: "
2722 <<
type <<
" for : " << paramHist.
GetName() << std::endl;
2729 if( sigmaRel < minSigma ) {
2731 <<
" and is < " << minSigma
2732 <<
". Setting: " << gamma.GetName() <<
" to constant"
2734 gamma.setConstant(
kTRUE);
2737 constraintTermNames.push_back( constrName );
2738 ConstraintTerms.
add( *
proto->pdf(constrName.c_str()) );
2745 if( ! globalSet->
contains(*nomVarInWorkspace) ) {
2746 globalSet->
add( *nomVarInWorkspace );
2751 return ConstraintTerms;
double pow(double, double)
char * Form(const char *fmt,...)
A class which maps the current values of a RooRealVar (or a set of RooRealVars) to one of a number of...
const RooArgSet * get(Int_t masterIdx) const
void setConstant(bool constant)
const RooArgList & paramList() const
static RooArgList createParamSet(RooWorkspace &w, const std::string &, const RooArgList &Vars)
Create the list of RooRealVar parameters which represent the height of the histogram bins.
void setShape(TH1 *shape)
The PiecewiseInterpolation is a class that can morph distributions into each other,...
Bool_t setBinIntegrator(RooArgSet &allVars)
void setAllInterpCodes(int code)
void setPositiveDefinite(bool flag=true)
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
virtual void Print(Option_t *options=0) const
Print the object to the defaultPrintStream().
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
Bool_t isConstant() const
Check if the "Constant" attribute is set.
Bool_t contains(const RooAbsArg &var) const
Check if collection contains an argument with the same name as var.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
const_iterator begin() const
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
RooAbsData is the common abstract base class for binned and unbinned datasets.
void setConstant(Bool_t value=kTRUE)
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
virtual void forceNumInt(Bool_t flag=kTRUE)
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Add element to non-owning set.
RooCategory is an object to represent discrete states.
virtual Bool_t setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
RooConstVar represent a constant real-valued object.
The RooDataHist is a container class to hold N-dimensional binned data.
RooDataSet is a container class to hold unbinned data.
void append(RooDataSet &data)
Add all data points of given data set to this data set.
virtual void add(const RooArgSet &row, Double_t weight=1.0, Double_t weightError=0) override
Add a data point, with its coordinates specified in the 'data' argset, to the data set.
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Double_t correlation(const RooAbsArg &par1, const RooAbsArg &par2) const
Return correlation between par1 and par2.
Switches the message service to a different level while the instance is alive.
RooHistFunc implements a real-valued function sampled from a multidimensional histogram.
static RooMsgService & instance()
Return reference to singleton instance.
Bool_t isActive(const RooAbsArg *self, RooFit::MsgTopic facility, RooFit::MsgLevel level)
Check if logging is active for given object/topic/RooFitMsgLevel combination.
Multivariate Gaussian p.d.f.
void setNoRounding(bool flag=kTRUE)
Switch off/on rounding of x to the nearest integer.
A RooProduct represents the product of a given set of RooAbsReal objects.
The class RooRealSumPdf implements a PDF constructed from a sum of functions:
RooRealVar represents a variable that can be changed from the outside.
void setMin(const char *name, Double_t value)
Set minimum of name range to given value.
virtual void setVal(Double_t value)
Set value of variable to 'value'.
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
static void SetPrintLevel(int level)
set print level (static function)
static RooAbsData * GenerateAsimovData(const RooAbsPdf &pdf, const RooArgSet &observables)
generate the asimov data for the observables (not the global ones) need to deal with the case of a si...
TODO Here, we are missing some documentation.
void ConfigureWorkspace(RooWorkspace *)
This class encapsulates all information for the statistical interpretation of one experiment.
std::vector< RooStats::HistFactory::Data > & GetAdditionalData()
retrieve vector of additional data objects
void Print(std::ostream &=std::cout)
HistFactory::StatErrorConfig & GetStatErrorConfig()
get information about threshold for statistical uncertainties and constraint term
RooStats::HistFactory::Data & GetData()
get data object
bool CheckHistograms() const
std::vector< RooStats::HistFactory::Sample > & GetSamples()
get vector of samples for this channel
std::string GetName() const
get name of channel
std::string GetName() const
void setAllInterpCodes(int code)
Configuration for a constrained, coherent shape variation of affected samples.
This class provides helper functions for creating likelihood models from histograms.
void ConfigureHistFactoryDataset(RooDataSet *obsData, TH1 *nominal, RooWorkspace *proto, std::vector< std::string > obsNameVec)
static void EditSyst(RooWorkspace *proto, const char *pdfNameChar, std::map< std::string, double > gammaSyst, std::map< std::string, double > uniformSyst, std::map< std::string, double > logNormSyst, std::map< std::string, double > noSyst)
RooWorkspace * MakeSingleChannelModel(Measurement &measurement, Channel &channel)
RooWorkspace * MakeSingleChannelWorkspace(Measurement &measurement, Channel &channel)
void GuessObsNameVec(const TH1 *hist)
void ProcessExpectedHisto(const TH1 *hist, RooWorkspace *proto, std::string prefix, std::string productPrefix, std::string systTerm)
void SetObsToExpected(RooWorkspace *proto, std::string obsPrefix, std::string expPrefix, int lowBin, int highBin)
std::vector< std::string > fPreprocessFunctions
void SetFunctionsToPreprocess(std::vector< std::string > lines)
std::vector< std::string > fObsNameVec
RooDataSet * MergeDataSets(RooWorkspace *combined, std::vector< RooWorkspace * > wspace_vec, std::vector< std::string > channel_names, std::string dataSetName, RooArgList obsList, RooCategory *channelCat)
virtual ~HistoToWorkspaceFactoryFast()
TH1 * MakeAbsolUncertaintyHist(const std::string &Name, const TH1 *Hist)
std::map< std::string, double > fParamValues
static void ConfigureWorkspaceForMeasurement(const std::string &ModelName, RooWorkspace *ws_single, Measurement &measurement)
RooArgList createStatConstraintTerms(RooWorkspace *proto, std::vector< std::string > &constraintTerms, ParamHistFunc ¶mHist, const TH1 *uncertHist, Constraint::Type type, Double_t minSigma)
void AddPoissonTerms(RooWorkspace *proto, std::string prefix, std::string obsPrefix, std::string expPrefix, int lowBin, int highBin, std::vector< std::string > &likelihoodTermNames)
static void PrintCovarianceMatrix(RooFitResult *result, RooArgSet *params, std::string filename)
std::vector< std::string > fSystToFix
void MakeTotalExpected(RooWorkspace *proto, std::string totName, std::vector< std::string > &syst_x_expectedPrefixNames, std::vector< std::string > &normByNames)
std::unique_ptr< TH1 > MakeScaledUncertaintyHist(const std::string &Name, std::vector< std::pair< const TH1 *, const TH1 * > > HistVec) const
void AddMultiVarGaussConstraint(RooWorkspace *proto, std::string prefix, int lowBin, int highBin, std::vector< std::string > &likelihoodTermNames)
std::string AddNormFactor(RooWorkspace *proto, std::string &channel, std::string &sigmaEpsilon, Sample &sample, bool doRatio)
void AddConstraintTerms(RooWorkspace *proto, Measurement &measurement, std::string prefix, std::string interpName, std::vector< OverallSys > &systList, std::vector< std::string > &likelihoodTermNames, std::vector< std::string > &totSystTermNames)
HistoToWorkspaceFactoryFast()
RooWorkspace * MakeCombinedModel(std::vector< std::string >, std::vector< RooWorkspace * >)
void LinInterpWithConstraint(RooWorkspace *proto, const TH1 *nominal, std::vector< HistoSys >, std::string prefix, std::string productPrefix, std::string systTerm, std::vector< std::string > &likelihoodTermNames)
const std::string & GetName() const
const TH1 * GetHistoHigh() const
const TH1 * GetHistoLow() const
The RooStats::HistFactory::Measurement class can be used to construct a model by combining multiple R...
std::map< std::string, double > & GetGammaSyst()
std::map< std::string, double > & GetLogNormSyst()
std::map< std::string, double > & GetNoSyst()
std::vector< std::string > & GetPOIList()
get vector of PoI names
std::map< std::string, double > & GetUniformSyst()
std::vector< std::string > & GetConstantParams()
get vector of all constant parameters
std::vector< RooStats::HistFactory::Channel > & GetChannels()
std::vector< RooStats::HistFactory::Asimov > & GetAsimovDatasets()
get vector of defined Asimov Datasets
std::vector< std::string > GetPreprocessFunctions() const
Returns a list of defined preprocess function expressions.
double GetLumi()
retrieve integrated luminosity
Configuration for an un- constrained overall systematic to scale sample normalisations.
std::string GetName() const
Configuration for a constrained overall systematic to scale sample normalisations.
const std::string & GetName() const
std::vector< RooStats::HistFactory::OverallSys > & GetOverallSysList()
std::string GetName() const
get name of sample
const TH1 * GetHisto() const
RooStats::HistFactory::StatError & GetStatError()
std::vector< RooStats::HistFactory::ShapeFactor > & GetShapeFactorList()
std::vector< RooStats::HistFactory::NormFactor > & GetNormFactorList()
std::vector< RooStats::HistFactory::HistoSys > & GetHistoSysList()
bool GetNormalizeByTheory() const
does the normalization scale with luminosity
std::vector< RooStats::HistFactory::ShapeSys > & GetShapeSysList()
*Un*constrained bin-by-bin variation of affected histogram.
const TH1 * GetInitialShape() const
Constrained bin-by-bin variation of affected histogram.
Constraint::Type GetConstraintType() const
const TH1 * GetErrorHist() const
double GetRelErrorThreshold() const
Constraint::Type GetConstraintType() const
const TH1 * GetErrorHist() const
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
virtual void SetObservables(const RooArgSet &set)
Specify the observables.
virtual void SetWorkspace(RooWorkspace &ws)
void GuessObsAndNuisance(const RooAbsData &data, bool printModelConfig=true)
Makes sensible guesses of observables, parameters of interest and nuisance parameters if one or multi...
virtual void SetParametersOfInterest(const RooArgSet &set)
Specify parameters of interest.
virtual void SetGlobalObservables(const RooArgSet &set)
Specify the global observables.
const RooArgSet * GetObservables() const
get RooArgSet for observables (return NULL if not existing)
virtual void SetPdf(const RooAbsPdf &pdf)
Set the Pdf, add to the the workspace if not already there.
The RooWorkspace is a persistable container for RooFit projects.
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
RooArgSet allVars() const
Return set with all variable objects.
Bool_t importClassCode(const char *pat="*", Bool_t doReplace=kFALSE)
Inport code of all classes in the workspace that have a class name that matches pattern 'pat' and whi...
void Print(Option_t *opts=0) const
Print contents of the workspace.
Bool_t defineSet(const char *name, const RooArgSet &aset, Bool_t importMissing=kFALSE)
Define a named RooArgSet with given constituents.
Bool_t saveSnapshot(const char *name, const char *paramNames)
Save snapshot of values and attributes (including "Constant") of given parameters.
Bool_t loadSnapshot(const char *name)
Load the values and attributes of the parameters in the snapshot saved with the given name.
RooRealVar * var(const char *name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
Bool_t import(const RooAbsArg &arg, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg())
Import a RooAbsArg object, e.g.
RooFactoryWSTool & factory()
Return instance to factory tool.
const RooArgSet * set(const char *name)
Return pointer to previously defined named set with given nmame If no such set is found a null pointe...
TObject * obj(const char *name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
Class to manage histogram axis.
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
TH1 is the base class of all histogram classes in ROOT.
virtual Bool_t Multiply(TF1 *f1, Double_t c1=1)
Performs the operation:
virtual Int_t GetNbinsY() const
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
virtual Int_t GetNbinsZ() const
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
virtual Int_t GetNbinsX() const
virtual void SetBinError(Int_t bin, Double_t error)
Set the bin Error Note that this resets the bin eror option to be of Normal Type and for the non-empt...
Bool_t IsBinUnderflow(Int_t bin, Int_t axis=0) const
Return true if the bin is underflow.
Bool_t IsBinOverflow(Int_t bin, Int_t axis=0) const
Return true if the bin is overflow.
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
virtual void SetName(const char *name)
Change the name of this histogram.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual const char * GetName() const
Returns name of object.
Mother of all ROOT objects.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
A TTree represents a columnar dataset.
RooCmdArg RecycleConflictNodes(Bool_t flag=kTRUE)
RooCmdArg Rename(const char *suffix)
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, Bool_t depsAreCond=kFALSE)
RooCmdArg WeightVar(const char *name, Bool_t reinterpretAsWeight=kFALSE)
RooCmdArg Index(RooCategory &icat)
RooCmdArg Import(const char *state, TH1 &histo)
RooCmdArg Name(const char *name)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Namespace for the RooStats classes.