88#define NoHistConst_Low "0"
89#define NoHistConst_High "2000"
102 fNomLumi(1.0), fLumiError(0),
103 fLowBin(0), fHighBin(0)
110 fSystToFix( measurement.GetConstantParams() ),
111 fParamValues( measurement.GetParamValues() ),
112 fNomLumi( measurement.GetLumi() ),
113 fLumiError( measurement.GetLumi()*measurement.GetLumiRelErr() ),
114 fLowBin( measurement.GetBinLow() ),
115 fHighBin( measurement.GetBinHigh() ) {
130 if( proto_config == NULL ) {
131 std::cout <<
"Error: Did not find 'ModelConfig' object in file: " << ws_single->
GetName()
136 std::vector<std::string> poi_list = measurement.
GetPOIList();
137 if( poi_list.size()==0 ) {
138 cxcoutWHF <<
"No Parametetrs of interest are set" << std::endl;
142 std::stringstream sstream;
143 sstream <<
"Setting Parameter(s) of Interest as: ";
144 for(
unsigned int i = 0; i < poi_list.size(); ++i) {
145 sstream << poi_list.at(i) <<
" ";
150 for(
unsigned int i = 0; i < poi_list.size(); ++i ) {
151 std::string poi_name = poi_list.at(i);
157 std::cout <<
"WARNING: Can't find parameter of interest: " << poi_name
158 <<
" in Workspace. Not setting in ModelConfig." << std::endl;
165 std::string NewModelName =
"newSimPdf";
179 proto_config->
SetPdf( *ws_single->
pdf(
"newSimPdf" ) );
186 std::cout <<
"Error: Failed to find dataset: " << expData
187 <<
" in workspace" << std::endl;
190 if(poi_list.size()!=0){
202 if( !pdf ) pdf = ws_single->
pdf( ModelName.c_str() );
203 const RooArgSet* observables = ws_single->
set(
"observables");
206 std::string SnapShotName =
"NominalParamValues";
213 std::string AsimovName = asimov.
GetName();
215 cxcoutPHF <<
"Generating additional Asimov Dataset: " << AsimovName << std::endl;
220 cxcoutPHF <<
"Importing Asimov dataset" << std::endl;
221 bool failure = ws_single->
import(*asimov_dataset,
Rename(AsimovName.c_str()));
223 std::cout <<
"Error: Failed to import Asimov dataset: " << AsimovName
225 delete asimov_dataset;
234 delete asimov_dataset;
256 string ch_name = channel.
GetName();
260 if( ws_single == NULL ) {
261 cxcoutF(
HistFactory) <<
"Error: Failed to make Single-Channel workspace for channel: " << ch_name
262 <<
" and measurement: " << measurement.
GetName() << std::endl;
292 vector<RooWorkspace*> channel_workspaces;
293 vector<string> channel_names;
295 for(
unsigned int chanItr = 0; chanItr < measurement.
GetChannels().size(); ++chanItr ) {
301 <<
" has uninitialized histogram pointers" << std::endl;
305 string ch_name = channel.
GetName();
306 channel_names.push_back(ch_name);
311 channel_workspaces.push_back(ws_single);
325 for (vector<RooWorkspace*>::iterator iter = channel_workspaces.begin() ; iter != channel_workspaces.end() ; ++iter) {
335 string prefix,
string productPrefix,
350 unsigned int histndim(1);
351 std::string classname = hist->
ClassName();
352 if (classname.find(
"TH1")==0) { histndim=1; }
353 else if (classname.find(
"TH2")==0) { histndim=2; }
354 else if (classname.find(
"TH3")==0) { histndim=3; }
359 std::vector<std::string>::iterator itr =
fObsNameVec.begin();
360 for (
int idx=0; itr!=
fObsNameVec.end(); ++itr, ++idx ) {
361 if ( !
proto->var(itr->c_str()) ) {
362 const TAxis* axis(0);
363 if (idx==0) { axis = hist->
GetXaxis(); }
364 if (idx==1) { axis = hist->
GetYaxis(); }
365 if (idx==2) { axis = hist->
GetZaxis(); }
371 proto->var(itr->c_str())->setBins(nbins);
373 observables.
add( *
proto->var(itr->c_str()) );
379 proto->import(*histFunc);
382 proto->factory((
"prod:"+productPrefix+
"("+prefix+
"_nominal,"+systTerm+
")").c_str() );
395 for(
Int_t i=lowBin; i<highBin; ++i){
396 std::stringstream str;
403 for(
int i=lowBin; i<highBin; ++i){
404 for(
int j=0; j<highBin-lowBin; ++j){
405 if(i==j) { Cov(i,j) =
sqrt(mean(i)); }
406 else { Cov(i,j) = 0; }
413 floating, mean, Cov);
415 proto->import(constraint);
417 constraintTermNames.push_back(constraint.
GetName());
421 std::vector<HistoSys> histoSysList,
422 string prefix,
string productPrefix,
424 vector<string>& constraintTermNames){
434 unsigned int histndim(1);
435 std::string classname = nominal->
ClassName();
436 if (classname.find(
"TH1")==0) { histndim=1; }
437 else if (classname.find(
"TH2")==0) { histndim=2; }
438 else if (classname.find(
"TH3")==0) { histndim=3; }
444 std::vector<std::string>::iterator itr =
fObsNameVec.begin();
445 for (
int idx=0; itr!=
fObsNameVec.end(); ++itr, ++idx ) {
446 if ( !
proto->var(itr->c_str()) ) {
447 const TAxis* axis(
nullptr);
448 if (idx==0) { axis = nominal->
GetXaxis(); }
449 else if (idx==1) { axis = nominal->
GetYaxis(); }
450 else if (idx==2) { axis = nominal->
GetZaxis(); }
452 std::cout <<
"Error: Too many observables. "
453 <<
"HistFactory only accepts up to 3 observables (3d) "
462 proto->var(itr->c_str())->setBins(nbins);
464 observables.
add( *
proto->var(itr->c_str()) );
476 for(
unsigned int j=0; j<histoSysList.size(); ++j){
477 std::stringstream str;
480 HistoSys& histoSys = histoSysList.at(j);
481 string histoSysName = histoSys.
GetName();
486 temp = (
RooRealVar*)
proto->factory((
"alpha_" + histoSysName + range).c_str());
489 string command=(
"Gaussian::alpha_"+histoSysName+
"Constraint(alpha_"+histoSysName+
",nom_alpha_"+histoSysName+
"[0.,-10,10],1.)");
491 constraintTermNames.push_back(
proto->factory( command.c_str() )->GetName() );
492 proto->var((
"nom_alpha_"+histoSysName).c_str())->setConstant();
493 const_cast<RooArgSet*
>(
proto->set(
"globalObservables"))->add(*
proto->var((
"nom_alpha_"+histoSysName).c_str()));
500 vector<double> low, high;
503 for(
unsigned int j=0; j<histoSysList.size(); ++j){
504 std::stringstream str;
507 HistoSys& histoSys = histoSysList.at(j);
512 lowSet.
add(*lowFunc);
513 highSet.
add(*highFunc);
525 proto->import(interp);
528 proto->factory((
"prod:"+productPrefix+
"("+prefix+
","+systTerm+
")").c_str() );
534 string overallNorm_times_sigmaEpsilon ;
538 vector<string> normFactorNames, rangeNames;
540 if(normList.size() > 0){
542 for(vector<NormFactor>::iterator itr = normList.begin(); itr != normList.end(); ++itr){
547 if(!prodNames.empty()) prodNames +=
",";
549 varname = norm.
GetName() +
"_" + channel;
558 std::stringstream range;
561 if(
proto->obj(varname.c_str()) == NULL) {
564 proto->factory((varname + range.str()).c_str());
570 cxcoutW(
HistFactory) <<
"Const attribute to <NormFactor> tag is deprecated, will ignore." <<
571 " Instead, add \n\t<ParamSetting Const=\"True\">" << varname <<
"</ParamSetting>\n" <<
572 " to your top-level XML's <Measurment> entry" << endl;
575 rangeNames.push_back(range.str());
576 normFactorNames.push_back(varname);
579 overallNorm_times_sigmaEpsilon = sample.
GetName() +
"_" + channel +
"_overallNorm_x_sigma_epsilon";
580 proto->factory((
"prod::" + overallNorm_times_sigmaEpsilon +
"(" + prodNames +
"," + sigmaEpsilon +
")").c_str());
583 unsigned int rangeIndex=0;
584 for( vector<string>::iterator nit = normFactorNames.begin(); nit!=normFactorNames.end(); ++nit){
585 if( count (normFactorNames.begin(), normFactorNames.end(), *nit) > 1 ){
586 cxcoutI(
HistFactory) <<
"<NormFactor Name =\""<<*nit<<
"\"> is duplicated for <Sample Name=\""
587 << sample.
GetName() <<
"\">, but only one factor will be included. \n Instead, define something like"
588 <<
"\n\t<Function Name=\""<<*nit<<
"Squared\" Expresion=\""<<*nit<<
"*"<<*nit<<
"\" Var=\""<<*nit<<rangeNames.at(rangeIndex)
589 <<
"\"> \nin your top-level XML's <Measurment> entry and use <NormFactor Name=\""<<*nit<<
"Squared\" in your channel XML file."<< endl;
594 if(!overallNorm_times_sigmaEpsilon.empty())
595 return overallNorm_times_sigmaEpsilon;
602 std::vector<OverallSys>& systList,
603 vector<string>& constraintTermNames,
604 vector<string>& totSystTermNames) {
610 totSystTermNames.push_back(prefix);
613 vector<double> lowVec, highVec;
615 std::map<std::string, double>::iterator itconstr;
616 for(
unsigned int i = 0; i < systList.size(); ++i) {
619 std::string strname = sys.
GetName();
620 const char *
name = strname.c_str();
631 cxcoutI(
HistFactory) <<
"HistoToWorkspaceFast::AddConstraintTerm - zero uncertainty assigned - skip systematic " << sys.
GetName() << std::endl;
634 double tauVal = 1./(relerr*relerr);
635 double sqtau = 1./relerr;
649 alphaOfBeta->
Print(
"t");
652 constraintTermNames.push_back(
gamma->GetName());
656 const_cast<RooArgSet*
>(
proto->set(
"globalObservables"))->add(*yvar);
659 params.
add(*alphaOfBeta);
669 double gaussSigma = 1;
672 cxcoutIHF <<
"Added a uniform constraint for " <<
name <<
" as a gaussian constraint with a very large sigma " << std::endl;
683 constraintTermNames.push_back( gausConstraint->
GetName() );
684 proto->var((
"nom_" + prefix + sys.
GetName()).c_str())->setConstant();
685 const_cast<RooArgSet*
>(
proto->set(
"globalObservables"))->add(*nomAlpha);
701 double tauVal = 1./relerr;
702 std::string tauName =
"tau_" + sys.
GetName();
704 double kappaVal = 1. + relerr;
705 std::string kappaName =
"kappa_" + sys.
GetName();
707 const char * alphaName = alpha->
GetName();
709 std::string alphaOfBetaName =
"alphaOfBeta_" + sys.
GetName();
711 tauName.c_str(),kappaName.c_str(),alphaName,
712 tauName.c_str(),kappaName.c_str(),alphaName ) );
716 alphaOfBeta->
Print(
"t");
717 params.
add(*alphaOfBeta);
722 double low = sys.
GetLow();
724 lowVec.push_back(low);
725 highVec.push_back(high);
729 if(systList.size() > 0){
734 assert(
int(lowVec.size()) == params.
getSize() );
736 FlexibleInterpVar interp( (interpName).c_str(),
"", params, 1., lowVec, highVec);
739 proto->import(interp);
744 proto->import(interp);
754 vector<string>& syst_x_expectedPrefixNames,
755 vector<string>& normByNames){
765 double binWidth(1.0);
766 std::string obsNameVecStr;
767 std::vector<std::string>::iterator itr =
fObsNameVec.begin();
769 std::string obsName = *itr;
770 binWidth *=
proto->var(obsName.c_str())->numBins()/(
proto->var(obsName.c_str())->getMax() -
proto->var(obsName.c_str())->getMin()) ;
771 if (obsNameVecStr.size()>0) { obsNameVecStr +=
"_"; }
772 obsNameVecStr += obsName;
776 for(
unsigned int j=0; j<syst_x_expectedPrefixNames.size();++j){
777 std::stringstream str;
781 command=string(
Form(
"binWidth_%s_%d[%e]",obsNameVecStr.c_str(),j,binWidth));
782 proto->factory(command.c_str());
783 proto->var(
Form(
"binWidth_%s_%d",obsNameVecStr.c_str(),j))->setConstant();
784 coeffList+=prepend+
"binWidth_"+obsNameVecStr+str.str();
786 command=
"prod::L_x_"+syst_x_expectedPrefixNames.at(j)+
"("+normByNames.at(j)+
","+syst_x_expectedPrefixNames.at(j)+
")";
788 proto->factory(command.c_str());
789 shapeList+=prepend+
"L_x_"+syst_x_expectedPrefixNames.at(j);
798 proto->defineSet(
"coefList",coeffList.c_str());
799 proto->defineSet(
"shapeList",shapeList.c_str());
833 vector<string>& likelihoodTermNames){
838 for(
Int_t i=lowBin; i<highBin; ++i){
839 std::stringstream str;
842 string command(
"Poisson::"+prefix+str.str()+
"("+obsPrefix+str.str()+
","+expPrefix+str.str()+
",1)");
846 cout <<
"Poisson Term " << command << endl;
850 likelihoodTermNames.push_back( temp->
GetName() );
853 proto->defineSet(prefix.c_str(),Pois);
863 for(
Int_t i=lowBin; i<highBin; ++i){
864 std::stringstream str;
867 cout <<
"expected number of events called: " << expPrefix << endl;
873 cout <<
"setting obs"+str.str()+
" to expected = " <<
exp->getVal() <<
" check: " << obs->
getVal() << endl;
876 obsForTree[i] =
exp->getVal();
877 tree->Branch((obsPrefix+str.str()).c_str(), obsForTree+i ,(obsPrefix+str.str()+
"/D").c_str());
880 cout <<
"problem retrieving obs or exp " << obsPrefix+str.str() << obs <<
" " << expPrefix+str.str() <<
exp << endl;
887 delete [] obsForTree;
889 proto->import(*data);
898 map<string,double> gammaSyst,
899 map<string,double> uniformSyst,
900 map<string,double> logNormSyst,
901 map<string,double> noSyst) {
902 string pdfName(pdfNameChar);
905 if( combined_config==NULL ) {
906 std::cout <<
"Error: Failed to find object 'ModelConfig' in workspace: "
907 <<
proto->GetName() << std::endl;
912 string edit=
"EDIT::newSimPdf("+pdfName+
",";
914 string lastPdf=pdfName;
916 unsigned int numReplacements = 0;
917 unsigned int nskipped = 0;
918 map<string,double>::iterator it;
922 for(it=gammaSyst.begin(); it!=gammaSyst.end(); ++it) {
924 if(!
proto->var((
"alpha_"+it->first).c_str())){
931 double relativeUncertainty = it->second;
932 double scale = 1/
sqrt((1+1/
pow(relativeUncertainty,2)));
935 proto->factory(
Form(
"beta_%s[1,0,10]",it->first.c_str()));
936 proto->factory(
Form(
"y_%s[%f]",it->first.c_str(),1./
pow(relativeUncertainty,2))) ;
937 proto->factory(
Form(
"theta_%s[%f]",it->first.c_str(),
pow(relativeUncertainty,2))) ;
938 proto->factory(
Form(
"Gamma::beta_%sConstraint(beta_%s,sum::k_%s(y_%s,one[1]),theta_%s,zero[0])",
943 it->first.c_str())) ;
959 proto->factory(
Form(
"PolyVar::alphaOfBeta_%s(beta_%s,{%f,%f})",it->first.c_str(),it->first.c_str(),-1./scale,1./scale));
962 if(
proto->var(
Form(
"alpha_%s",it->first.c_str()))->isConstant()) {
963 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
true);
966 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
false);
972 editList+=precede +
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint";
974 editList+=precede +
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first;
984 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
985 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
989 cout <<
"Going to issue this edit command\n" << edit<< endl;
990 proto->factory( edit.c_str() );
993 cxcoutWHF <<
"---------------------\n WARNING: failed to make EDIT\n\n" << endl;
999 for(it=uniformSyst.begin(); it!=uniformSyst.end(); ++it) {
1000 cout <<
"edit for " << it->first <<
"with rel uncert = " << it->second << endl;
1001 if(!
proto->var((
"alpha_"+it->first).c_str())){
1002 cout <<
"systematic not there" << endl;
1009 proto->factory(
Form(
"beta_%s[1,0,10]",it->first.c_str()));
1010 proto->factory(
Form(
"Uniform::beta_%sConstraint(beta_%s)",it->first.c_str(),it->first.c_str()));
1011 proto->factory(
Form(
"PolyVar::alphaOfBeta_%s(beta_%s,{-1,1})",it->first.c_str(),it->first.c_str()));
1014 if(
proto->var(
Form(
"alpha_%s",it->first.c_str()))->isConstant())
1015 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
true);
1017 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
false);
1022 cout <<
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint" << endl;
1023 editList+=precede +
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint";
1025 cout <<
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first << endl;
1026 editList+=precede +
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first;
1028 if(
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) &&
proto->var((
"alpha_"+it->first).c_str()) )
1029 cout <<
" checked they are there" <<
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) <<
" " <<
proto->var((
"alpha_"+it->first).c_str()) << endl;
1031 cout <<
"NOT THERE" << endl;
1034 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
1035 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
1039 cout << edit<< endl;
1040 proto->factory( edit.c_str() );
1043 cxcoutWHF <<
"---------------------\n WARNING: failed to make EDIT\n\n" << endl;
1053 for(it=logNormSyst.begin(); it!=logNormSyst.end(); ++it) {
1054 cout <<
"edit for " << it->first <<
"with rel uncert = " << it->second << endl;
1055 if(!
proto->var((
"alpha_"+it->first).c_str())){
1056 cout <<
"systematic not there" << endl;
1062 double relativeUncertainty = it->second;
1063 double kappa = 1+relativeUncertainty;
1067 double scale = relativeUncertainty;
1070 const char * cname = it->first.c_str();
1077 cname, cname, cname, cname)) ;
1078 proto->factory(
TString::Format(
"PolyVar::alphaOfBeta_%s(beta_%s,{%f,%f})",cname,cname,-1./scale,1./scale));
1090 cout <<
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint" << endl;
1091 editList+=precede +
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint";
1093 cout <<
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first << endl;
1094 editList+=precede +
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first;
1096 if(
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) &&
proto->var((
"alpha_"+it->first).c_str()) )
1097 cout <<
" checked they are there" <<
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) <<
" " <<
proto->var((
"alpha_"+it->first).c_str()) << endl;
1099 cout <<
"NOT THERE" << endl;
1102 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
1103 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
1107 cout << edit<< endl;
1108 proto->factory( edit.c_str() );
1111 cxcoutWHF <<
"\n\n ---------------------\n WARNING: failed to make EDIT\n\n" << endl;
1118 proto->removeSet(
"globalObservables");
1119 proto->defineSet(
"globalObservables",gobsNew);
1127 for(it=noSyst.begin(); it!=noSyst.end(); ++it) {
1129 cout <<
"remove constraint for parameter" << it->first << endl;
1130 if(!
proto->var((
"alpha_"+it->first).c_str()) || !
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) ) {
1131 cout <<
"systematic not there" << endl;
1138 if ( !
proto->var(
"one") ) {
proto->factory(
"one[1.0]"); }
1139 proto->var(
"one")->setConstant();
1142 cout <<
"alpha_"+it->first+
"Constraint=one" << endl;
1143 editList+=precede +
"alpha_"+it->first+
"Constraint=one";
1147 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
1148 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
1152 cout << edit << endl;
1153 proto->factory( edit.c_str() );
1156 cxcoutWHF <<
"---------------------\n WARNING: failed to make EDIT\n\n" << endl;
1164 edit=
"EDIT::newSimPdf("+lastPdf+
","+editList+
")";
1165 cout << edit<< endl;
1166 proto->factory( edit.c_str() );
1171 combined_config->
SetPdf(*newOne);
1174 cxcoutWHF <<
"\n\n ---------------------\n WARNING: failed to make EDIT\n\n" << endl;
1181 FILE* covFile = fopen ((filename).c_str(),
"w");
1186 fprintf(covFile,
" ") ;
1189 fprintf(covFile,
" & %s", myargi->
GetName());
1191 fprintf(covFile,
"\\\\ \\hline \n" );
1195 fprintf(covFile,
"%s", myargi->
GetName());
1200 fprintf(covFile,
" & %.2f", result->
correlation(*myargi, *myargj));
1203 fprintf(covFile,
" \\\\\n");
1216 Error(
"MakeSingleChannelWorkspace",
1217 "The input Channel does not contain any sample - return a nullptr");
1221 const TH1* channel_hist_template = channel.
GetSamples().front().GetHisto();
1222 if (channel_hist_template ==
nullptr) {
1224 channel_hist_template = channel.
GetSamples().front().GetHisto();
1226 if (channel_hist_template ==
nullptr) {
1227 std::ostringstream stream;
1228 stream <<
"The sample " << channel.
GetSamples().front().GetName()
1229 <<
" in channel " << channel.
GetName() <<
" does not contain a histogram. This is the channel:\n";
1230 channel.
Print(stream);
1231 Error(
"MakeSingleChannelWorkspace",
"%s", stream.str().c_str());
1236 std::cout <<
"MakeSingleChannelWorkspace: Channel: " << channel.
GetName()
1237 <<
" has uninitialized histogram pointers" << std::endl;
1251 string channel_name = channel.
GetName();
1261 for (
unsigned int idx=0; idx<
fObsNameVec.size(); ++idx ) {
1273 <<
"\tStarting to process '"
1274 << channel_name <<
"' channel with " <<
fObsNameVec.size() <<
" observables"
1275 <<
"\n-----------------------------------------\n" << endl;
1281 auto proto_config = make_unique<ModelConfig>(
"ModelConfig",
proto);
1282 proto_config->SetWorkspace(*
proto);
1288 proto->factory(funcIter->c_str());
1292 RooArgSet likelihoodTerms(
"likelihoodTerms"), constraintTerms(
"constraintTerms");
1293 vector<string> likelihoodTermNames, constraintTermNames, totSystTermNames, syst_x_expectedPrefixNames, normalizationNames;
1295 vector< pair<string,string> > statNamePairs;
1296 vector< pair<const TH1*, const TH1*> > statHistPairs;
1297 std::string statFuncName;
1298 std::string statNodeName;
1302 string prefix, range;
1307 std::stringstream lumiStr;
1310 proto->factory((
"Lumi"+lumiStr.str()).c_str());
1313 std::stringstream lumiErrorStr;
1315 proto->factory((
"Gaussian::lumiConstraint(Lumi,"+lumiErrorStr.str()+
")").c_str());
1316 proto->var(
"nominalLumi")->setConstant();
1317 proto->defineSet(
"globalObservables",
"nominalLumi");
1319 constraintTermNames.push_back(
"lumiConstraint");
1327 vector<Sample>::iterator it = channel.
GetSamples().begin();
1328 for(; it!=channel.
GetSamples().end(); ++it) {
1332 string overallSystName = sample.
GetName() +
"_" + channel_name +
"_epsilon";
1334 string systSourcePrefix =
"alpha_";
1342 overallSystName =
AddNormFactor(
proto, channel_name, overallSystName, sample, doRatio);
1347 string syst_x_expectedPrefix =
"";
1368 string expPrefix = sample.
GetName() +
"_" + channel_name;
1369 syst_x_expectedPrefix = sample.
GetName() +
"_" + channel_name +
"_overallSyst_x_Exp";
1377 string constraintPrefix = sample.
GetName() +
"_" + channel_name +
"_Hist_alpha";
1378 syst_x_expectedPrefix = sample.
GetName() +
"_" + channel_name +
"_overallSyst_x_HistSyst";
1383 constraintPrefix, syst_x_expectedPrefix, overallSystName,
1384 constraintTermNames);
1394 cxcoutF(
HistFactory) <<
"Cannot include Stat Error for histograms of more than 3 dimensions."
1404 <<
"for channel " << channel_name
1434 string UncertName = syst_x_expectedPrefix +
"_StatAbsolUncert";
1435 TH1* statErrorHist = NULL;
1440 <<
" Channel: " << channel_name
1441 <<
" Sample: " << sample.
GetName()
1453 <<
"\tChannel: " << channel_name
1454 <<
"\tSample: " << sample.
GetName()
1455 <<
"\tError Histogram: " << statErrorHist->
GetName() << std::endl;
1458 statErrorHist->
Multiply( nominal );
1459 statErrorHist->
SetName( UncertName.c_str() );
1464 statHistPairs.push_back( std::make_pair(nominal, statErrorHist) );
1481 statFuncName =
"mc_stat_" + channel_name;
1483 if( paramHist == NULL ) {
1488 std::vector<std::string>::iterator itr =
fObsNameVec.begin();
1489 for (
int idx=0; itr!=
fObsNameVec.end(); ++itr, ++idx ) {
1490 observables.
add( *
proto->var(itr->c_str()) );
1495 std::string ParamSetPrefix =
"gamma_stat_" + channel_name;
1499 ParamSetPrefix.c_str(),
1501 gammaMin, gammaMax);
1503 ParamHistFunc statUncertFunc(statFuncName.c_str(), statFuncName.c_str(),
1504 observables, statFactorParams );
1515 statNodeName = sample.
GetName() +
"_" + channel_name +
"_overallSyst_x_StatUncert";
1518 RooProduct nodeWithMcStat(statNodeName.c_str(), statNodeName.c_str(),
1526 syst_x_expectedPrefix = nodeWithMcStat.
GetName();
1539 cxcoutF(
HistFactory) <<
"Cannot include Stat Error for histograms of more than 3 dimensions."
1545 <<
" to be include a ShapeFactor."
1548 std::vector<ParamHistFunc*> paramHistFuncList;
1549 std::vector<std::string> shapeFactorNameList;
1555 std::string funcName = channel_name +
"_" + shapeFactor.
GetName() +
"_shapeFactor";
1557 if( paramHist == NULL ) {
1560 std::vector<std::string>::iterator itr =
fObsNameVec.begin();
1561 for (
int idx=0; itr!=
fObsNameVec.end(); ++itr, ++idx ) {
1562 observables.
add( *
proto->var(itr->c_str()) );
1566 std::string funcParams =
"gamma_" + shapeFactor.
GetName();
1572 observables, 0, 1000);
1575 ParamHistFunc shapeFactorFunc( funcName.c_str(), funcName.c_str(),
1576 observables, shapeFactorParams );
1582 <<
" to have initial shape from hist: "
1585 shapeFactorFunc.
setShape( initialShape );
1591 <<
" to be constant" << std::endl;
1600 paramHistFuncList.push_back(paramHist);
1601 shapeFactorNameList.push_back(funcName);
1610 std::string shapeFactorNodeName = syst_x_expectedPrefix;
1611 for(
unsigned int i=0; i < shapeFactorNameList.size(); ++i) {
1612 shapeFactorNodeName +=
"_x_" + shapeFactorNameList.at(i);
1617 for(
unsigned int i=0; i < paramHistFuncList.size(); ++i) {
1618 nodesForProduct.
add( *paramHistFuncList.at(i) );
1623 RooProduct nodeWithShapeFactor(shapeFactorNodeName.c_str(),
1624 shapeFactorNodeName.c_str(),
1632 syst_x_expectedPrefix = nodeWithShapeFactor.
GetName();
1645 cxcoutF(
HistFactory) <<
"Cannot include Stat Error for histograms of more than 3 dimensions."
1651 std::vector<string> ShapeSysNames;
1667 <<
" to include a ShapeSys." << std::endl;
1669 std::string funcName = channel_name +
"_" + shapeSys.
GetName() +
"_ShapeSys";
1670 ShapeSysNames.push_back( funcName );
1672 if( paramHist == NULL ) {
1678 std::vector<std::string>::iterator itr =
fObsNameVec.begin();
1680 observables.
add( *
proto->var(itr->c_str()) );
1684 std::string funcParams =
"gamma_" + shapeSys.
GetName();
1687 observables, 0, 10);
1690 ParamHistFunc shapeFactorFunc( funcName.c_str(), funcName.c_str(),
1691 observables, shapeFactorParams );
1714 Double_t minShapeUncertainty = 0.0;
1716 *paramHist, shapeErrorHist,
1718 minShapeUncertainty);
1726 std::string NodeName = syst_x_expectedPrefix;
1729 ShapeSysForNode.
add( *expFunc );
1730 for(
unsigned int i = 0; i < ShapeSysNames.size(); ++i ) {
1731 std::string ShapeSysName = ShapeSysNames.at(i);
1732 ShapeSysForNode.
add( *
proto->function(ShapeSysName.c_str()) );
1733 NodeName = NodeName +
"_x_" + ShapeSysName;
1737 RooProduct nodeWithShapeFactor(NodeName.c_str(), NodeName.c_str(), ShapeSysForNode );
1743 syst_x_expectedPrefix = nodeWithShapeFactor.
GetName();
1752 syst_x_expectedPrefixNames.push_back(syst_x_expectedPrefix);
1758 normalizationNames.push_back(
"Lumi" );
1762 lumiParamString += measurement.
GetLumi();
1764 normalizationNames.push_back(lumiParamString.
Data());
1772 if( statHistPairs.size() > 0 ) {
1777 if( fracStatError == NULL ) {
1779 << statNodeName << std::endl;
1787 << chanStatUncertFunc->
GetName()
1788 <<
" params: " << chanStatUncertFunc->
paramList()
1807 *chanStatUncertFunc, fracStatError.
get(),
1809 statRelErrorThreshold);
1813 for (
unsigned int i = 0; i < statHistPairs.size() ; ++i )
1814 delete statHistPairs[i].
second;
1816 statHistPairs.clear();
1826 syst_x_expectedPrefixNames, normalizationNames);
1827 likelihoodTermNames.push_back(channel_name+
"_model");
1831 for(
unsigned int i=0; i<systToFix.size(); ++i){
1839 if(systToFix.at(i)==
"Lumi"){
1840 auxMeas =
proto->var(
"nominalLumi");
1846 const_cast<RooArgSet*
>(
proto->set(
"globalObservables"))->remove(*auxMeas);
1853 <<
" could not set it to constant" << endl;
1859 for(
unsigned int i=0; i<constraintTermNames.size(); ++i){
1860 RooAbsArg* proto_arg = (
proto->arg(constraintTermNames[i].c_str()));
1861 if( proto_arg==NULL ) {
1863 <<
" in workspace: " <<
proto->GetName() << std::endl;
1866 constraintTerms.
add( *proto_arg );
1869 for(
unsigned int i=0; i<likelihoodTermNames.size(); ++i){
1870 RooAbsArg* proto_arg = (
proto->arg(likelihoodTermNames[i].c_str()));
1871 if( proto_arg==NULL ) {
1873 <<
" in workspace: " <<
proto->GetName() << std::endl;
1876 likelihoodTerms.add( *proto_arg );
1878 proto->defineSet(
"constraintTerms",constraintTerms);
1879 proto->defineSet(
"likelihoodTerms",likelihoodTerms);
1884 std::string observablesStr;
1886 std::vector<std::string>::iterator itr =
fObsNameVec.begin();
1888 observables.
add( *
proto->var(itr->c_str()) );
1889 if (!observablesStr.empty()) { observablesStr +=
","; }
1890 observablesStr += *itr;
1902 <<
"\timport model into workspace"
1903 <<
"\n-----------------------------------------\n" << endl;
1905 auto model = make_unique<RooProdPdf>(
1906 (
"model_"+channel_name).c_str(),
1907 "product of Poissons accross bins for a single channel",
1908 constraintTerms,
Conditional(likelihoodTerms,observables));
1911 proto_config->SetPdf(*model);
1912 proto_config->SetObservables(observables);
1913 proto_config->SetGlobalObservables(*
proto->set(
"globalObservables"));
1917 proto->import(*proto_config,proto_config->GetName());
1918 proto->importClassCode();
1923 const char* weightName=
"weightVar";
1929 int asymcalcPrintLevel = 0;
1943 <<
" is NULL" << std::endl;
1948 auto obsDataUnbinned = make_unique<RooDataSet>(
"obsData",
"",*
proto->set(
"obsAndWeight"),weightName);
1987 proto->import(*obsDataUnbinned);
1994 std::string dataName = data.
GetName();
1998 <<
" with name: " << dataName <<
" is NULL" << std::endl;
2003 auto obsDataUnbinned = make_unique<RooDataSet>(dataName.c_str(), dataName.c_str(),
2004 *
proto->set(
"obsAndWeight"), weightName);
2042 proto->import(*obsDataUnbinned);
2056 std::vector<std::string> ObsNameVec) {
2062 if (ObsNameVec.empty() ) {
2063 Error(
"ConfigureHistFactoryDataset",
"Invalid input - return");
2073 for (
int i=1; i<=ax->
GetNbins(); ++i) {
2076 proto->var( ObsNameVec[0].c_str() )->setVal( xval );
2078 if(ObsNameVec.size()==1) {
2080 obsDataUnbinned->
add( *
proto->set(
"obsAndWeight"), fval );
2083 for(
int j=1; j<=ay->
GetNbins(); ++j) {
2085 proto->var( ObsNameVec[1].c_str() )->setVal( yval );
2087 if(ObsNameVec.size()==2) {
2089 obsDataUnbinned->
add( *
proto->set(
"obsAndWeight"), fval );
2092 for(
int k=1; k<=az->
GetNbins(); ++k) {
2094 proto->var( ObsNameVec[2].c_str() )->setVal( zval );
2096 obsDataUnbinned->
add( *
proto->set(
"obsAndWeight"), fval );
2109 unsigned int histndim(1);
2110 std::string classname = hist->
ClassName();
2111 if (classname.find(
"TH1")==0) { histndim=1; }
2112 else if (classname.find(
"TH2")==0) { histndim=2; }
2113 else if (classname.find(
"TH3")==0) { histndim=3; }
2115 for (
unsigned int idx=0; idx<histndim; ++idx ) {
2128 if (ch_names.empty() || chs.empty() ) {
2129 Error(
"MakeCombinedModel",
"Input vectors are empty - return a nullptr");
2132 if (chs.size() < ch_names.size() ) {
2133 Error(
"MakeCombinedModel",
"Input vector of workspace has an invalid size - return a nullptr");
2141 map<string, RooAbsPdf*> pdfMap;
2142 vector<RooAbsPdf*> models;
2145 for(
unsigned int i = 0; i< ch_names.size(); ++i){
2153 stringstream channelString;
2154 channelString <<
"channelCat[";
2155 for(
unsigned int i = 0; i< ch_names.size(); ++i){
2156 string channel_name=ch_names[i];
2157 if (i == 0 && isdigit(channel_name[0])) {
2158 throw std::invalid_argument(
"The first channel name for HistFactory cannot start with a digit. Got " + channel_name);
2160 if (channel_name.find(
',') != std::string::npos) {
2161 throw std::invalid_argument(
"Channel names for HistFactory cannot contain ','. Got " + channel_name);
2164 if (i == 0) channelString << channel_name ;
2165 else channelString <<
',' << channel_name ;
2168 RooAbsPdf* model = ch->
pdf((
"model_"+channel_name).c_str());
2169 if(!model) cout <<
"failed to find model for channel"<<endl;
2171 models.push_back(model);
2172 globalObs.
add(*ch->
set(
"globalObservables"));
2175 pdfMap[channel_name]=model;
2177 channelString <<
"]";
2180 <<
"\tEntering combination"
2181 <<
"\n-----------------------------------------\n" << endl;
2187 if (!channelCat)
throw std::runtime_error(
"Unable to construct a category from string " + channelString.str());
2194 combined->
import(globalObs);
2195 combined->
defineSet(
"globalObservables",globalObs);
2202 <<
"\tcreate toy data for " << channelString.str()
2203 <<
"\n-----------------------------------------\n" << endl;
2209 combined->
factory(
"weightVar[0,-1e10,1e10]");
2210 obsList.
add(*combined->
var(
"weightVar"));
2231 if( asimov_combined ) {
2232 combined->
import( *asimov_combined,
Rename(
"asimovData"));
2235 std::cout <<
"Error: Failed to create combined asimov dataset" << std::endl;
2238 delete asimov_combined;
2241 if(chs[0]->data(
"obsData") != NULL) {
2242 MergeDataSets(combined, chs, ch_names,
"obsData", obsList, channelCat);
2290 obsList.
add(*channelCat);
2291 combined->
defineSet(
"observables",obsList);
2298 <<
"\tImporting combined model"
2299 <<
"\n-----------------------------------------\n" << endl;
2305 std::map< std::string, double>::iterator param_itr =
fParamValues.begin();
2308 std::string paramName = param_itr->first;
2309 double paramVal = param_itr->second;
2313 temp->
setVal( paramVal );
2314 cxcoutI(
HistFactory) <<
"setting " << paramName <<
" to the value: " << paramVal << endl;
2316 cxcoutE(
HistFactory) <<
"could not find variable " << paramName <<
" could not set its value" << endl;
2320 for(
unsigned int i=0; i<
fSystToFix.size(); ++i){
2335 combined_config->
SetPdf(*simPdf);
2338 combined->
import(*combined_config,combined_config->
GetName());
2343 delete combined_config;
2351 std::vector<RooWorkspace*> wspace_vec,
2352 std::vector<std::string> channel_names,
2353 std::string dataSetName,
2362 for(
unsigned int i = 0; i< channel_names.size(); ++i){
2365 cxcoutPHF <<
"Merging data for channel " << channel_names[i].c_str() << std::endl;
2367 if( !obsDataInChannel ) {
2368 std::cout <<
"Error: Can't find DataSet: " << dataSetName
2369 <<
" in channel: " << channel_names.at(i)
2376 obsList,
Index(*channelCat),
2378 Import(channel_names[i].c_str(),*obsDataInChannel));
2380 simData->
append(*tempData);
2391 combined->
import(*simData,
Rename(dataSetName.c_str()));
2396 std::cout <<
"Error: Unable to merge observable datasets" << std::endl;
2415 Int_t binNumber = 0;
2418 for(
Int_t i_bin = 0; i_bin < numBins; ++i_bin) {
2429 if( histError != histError ) {
2430 std::cout <<
"Warning: In histogram " << Nominal->
GetName()
2431 <<
" bin error for bin " << i_bin
2432 <<
" is NAN. Not using Error!!!"
2440 if( histError < 0 ) {
2441 std::cout <<
"Warning: In histogram " << Nominal->
GetName()
2442 <<
" bin error for bin " << binNumber
2443 <<
" is < 0. Setting Error to 0"
2468 unsigned int numHists = HistVec.size();
2470 if( numHists == 0 ) {
2471 cxcoutE(
HistFactory) <<
"Warning: Empty Hist Vector, cannot create total uncertainty" << std::endl;
2475 const TH1* HistTemplate = HistVec.at(0).first;
2480 for(
unsigned int i = 0; i < HistVec.size(); ++i ) {
2482 const TH1* nominal = HistVec.at(i).first;
2483 const TH1* error = HistVec.at(i).second;
2495 std::vector<double> TotalBinContent( numBins, 0.0);
2496 std::vector<double> HistErrorsSqr( numBins, 0.0);
2498 Int_t binNumber = 0;
2501 for(
Int_t i_bins = 0; i_bins < numBins; ++i_bins) {
2508 for(
unsigned int i_hist = 0; i_hist < numHists; ++i_hist ) {
2510 const TH1* nominal = HistVec.at(i_hist).first;
2511 const TH1* error = HistVec.at(i_hist).second;
2526 if( histError != histError ) {
2528 <<
" bin error for bin " << binNumber
2529 <<
" is NAN. Not using error!!";
2533 TotalBinContent.at(i_bins) += histValue;
2534 HistErrorsSqr.at(i_bins) += histError*histError;
2546 for(
Int_t i = 0; i < numBins; ++i) {
2554 Double_t ErrorsSqr = HistErrorsSqr.at(i);
2555 Double_t TotalVal = TotalBinContent.at(i);
2557 if( TotalVal <= 0 ) {
2559 <<
" is <= 0. Setting error to 0"
2570 if( RelativeError != RelativeError ) {
2572 <<
" HistErrorsSqr: " << ErrorsSqr
2573 <<
" TotalVal: " << TotalVal;
2587 <<
" Error = " <<
sqrt(ErrorsSqr)
2588 <<
" CentralVal = " << TotalVal
2589 <<
" RelativeError = " << RelativeError <<
"\n";
2593 return std::unique_ptr<TH1>(ErrorHist);
2629 if( numBins != numParams ) {
2630 std::cout <<
"Error: In createStatConstraintTerms, encountered bad number of bins" << std::endl;
2631 std::cout <<
"Given histogram with " << numBins <<
" bins,"
2632 <<
" but require exactly " << numParams << std::endl;
2636 Int_t TH1BinNumber = 0;
2648 <<
". Type of constraint: " <<
type << std::endl;
2652 const double sigmaRel = uncertHist->
GetBinContent(TH1BinNumber);
2656 if( sigmaRel <= 0 ){
2659 <<
" because sigma = " << sigmaRel
2661 <<
" (TH1 bin number = " << TH1BinNumber <<
")"
2668 gamma.setMax( 1 + 5*sigmaRel );
2672 std::string constrName = string(
gamma.GetName()) +
"_constraint";
2673 std::string nomName = string(
"nom_") +
gamma.GetName();
2674 std::string sigmaName = string(
gamma.GetName()) +
"_sigma";
2675 std::string poisMeanName = string(
gamma.GetName()) +
"_poisMean";
2683 RooConstVar constrSigma( sigmaName.c_str(), sigmaName.c_str(), sigmaRel );
2686 RooRealVar constrNom(nomName.c_str(), nomName.c_str(), 1.0,0,10);
2691 constrNom,
gamma, constrSigma );
2697 gamma.setError(sigmaRel);
2700 Double_t tau = 1/sigmaRel/sigmaRel;
2703 RooRealVar constrNom(nomName.c_str(), nomName.c_str(), tau);
2708 std::string scalingName = string(
gamma.GetName()) +
"_tau";
2709 RooConstVar poissonScaling( scalingName.c_str(), scalingName.c_str(), tau);
2717 RooPoisson pois(constrName.c_str(), constrName.c_str(), constrNom, constrMean);
2721 if (std::string(
gamma.GetName()).find(
"gamma_stat") != std::string::npos) {
2724 gamma.setError(sigmaRel);
2729 std::cout <<
"Error: Did not recognize Stat Error constraint term type: "
2730 <<
type <<
" for : " << paramHist.
GetName() << std::endl;
2737 if( sigmaRel < minSigma ) {
2739 <<
" and is < " << minSigma
2740 <<
". Setting: " <<
gamma.GetName() <<
" to constant"
2745 constraintTermNames.push_back( constrName );
2746 ConstraintTerms.
add( *
proto->pdf(constrName.c_str()) );
2753 if( ! globalSet->
contains(*nomVarInWorkspace) ) {
2754 globalSet->
add( *nomVarInWorkspace );
2759 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)
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 (of arbitrary type) an...
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.
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.
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
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
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/RooFit::MsgLevel combination.
Multivariate Gaussian p.d.f.
void setNoRounding(bool flag=kTRUE)
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
std::string GetName()
get name of channel
std::vector< RooStats::HistFactory::Sample > & GetSamples()
get vector of samples for this channel
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
double GetLumi()
retrieve integrated luminosity
std::vector< std::string > GetPreprocessFunctions()
Returns a list of defined preprocess function expressions.
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.
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.
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)
double beta(double x, double y)
Calculates the beta function.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Namespace for the RooStats classes.
static constexpr double second
static constexpr double gauss