82#define NoHistConst_Low "0"
83#define NoHistConst_High "2000"
96 fNomLumi(1.0), fLumiError(0),
97 fLowBin(0), fHighBin(0)
104 fSystToFix( measurement.GetConstantParams() ),
105 fParamValues( measurement.GetParamValues() ),
106 fNomLumi( measurement.GetLumi() ),
107 fLumiError( measurement.GetLumi()*measurement.GetLumiRelErr() ),
108 fLowBin( measurement.GetBinLow() ),
109 fHighBin( measurement.GetBinHigh() ) {
124 if( proto_config == NULL ) {
125 std::cout <<
"Error: Did not find 'ModelConfig' object in file: " << ws_single->
GetName()
130 std::vector<std::string> poi_list = measurement.
GetPOIList();
131 if( poi_list.size()==0 ) {
132 cxcoutWHF <<
"No Parametetrs of interest are set" << std::endl;
136 std::stringstream sstream;
137 sstream <<
"Setting Parameter(s) of Interest as: ";
138 for(
unsigned int i = 0; i < poi_list.size(); ++i) {
139 sstream << poi_list.at(i) <<
" ";
144 for(
unsigned int i = 0; i < poi_list.size(); ++i ) {
145 std::string poi_name = poi_list.at(i);
151 std::cout <<
"WARNING: Can't find parameter of interest: " << poi_name
152 <<
" in Workspace. Not setting in ModelConfig." << std::endl;
159 std::string NewModelName =
"newSimPdf";
164 std::cout <<
"Error: Failed to find dataset: " << expData
165 <<
" in workspace" << std::endl;
168 if(poi_list.size()!=0){
180 if( !pdf ) pdf = ws_single->
pdf( ModelName.c_str() );
181 const RooArgSet* observables = ws_single->
set(
"observables");
184 std::string SnapShotName =
"NominalParamValues";
191 std::string AsimovName = asimov.
GetName();
193 cxcoutPHF <<
"Generating additional Asimov Dataset: " << AsimovName << std::endl;
197 cxcoutPHF <<
"Importing Asimov dataset" << std::endl;
198 bool failure = ws_single->
import(*asimov_dataset,
Rename(AsimovName.c_str()));
200 std::cout <<
"Error: Failed to import Asimov dataset: " << AsimovName
228 string ch_name = channel.
GetName();
232 if( ws_single == NULL ) {
233 cxcoutF(
HistFactory) <<
"Error: Failed to make Single-Channel workspace for channel: " << ch_name
234 <<
" and measurement: " << measurement.
GetName() << std::endl;
264 vector<std::unique_ptr<RooWorkspace>> channel_workspaces;
265 vector<string> channel_names;
267 for(
unsigned int chanItr = 0; chanItr < measurement.
GetChannels().
size(); ++chanItr ) {
273 <<
" has uninitialized histogram pointers" << std::endl;
277 string ch_name = channel.
GetName();
278 channel_names.push_back(ch_name);
283 channel_workspaces.emplace_back(ws_single);
305 for (
unsigned int idx=0; idx <
fObsNameVec.size(); ++idx) {
317 obs->setBinning(binning);
339 unsigned int histndim(1);
340 std::string classname = hist->
ClassName();
341 if (classname.find(
"TH1")==0) { histndim=1; }
342 else if (classname.find(
"TH2")==0) { histndim=2; }
343 else if (classname.find(
"TH3")==0) { histndim=3; }
346 prefix +=
"_Hist_alphanominal";
348 RooDataHist histDHist((prefix +
"DHist").c_str(),
"",observables,hist);
349 RooHistFunc histFunc(prefix.c_str(),
"",observables,histDHist,0);
360 std::vector<std::string> & constraintTermNames) {
361 std::string paramName = param.
GetName();
362 std::string constraintName = paramName +
"Constraint";
365 if(
proto.pdf(constraintName.c_str()))
return;
369 const double gaussSigma = isUniform ? 100. : 1.0;
371 cxcoutIHF <<
"Added a uniform constraint for " << paramName <<
" as a Gaussian constraint with a very large sigma " << std::endl;
374 std::stringstream command;
375 command <<
"Gaussian::" << constraintName <<
"(" << paramName <<
",nom_" << paramName <<
"[0.,-10,10],"
376 << gaussSigma <<
")";
377 constraintTermNames.emplace_back(
proto.factory( command.str().c_str() )->GetName());
378 auto * normParam =
proto.var((std::string(
"nom_") + paramName).c_str());
379 normParam->setConstant();
380 const_cast<RooArgSet*
>(
proto.set(
"globalObservables"))->add(*normParam);
390 for(
auto const& histoSys : histoSysList) {
391 const std::string histoSysName = histoSys.GetName();
394 temp = (
RooRealVar*)
proto.factory((
"alpha_" + histoSysName + range).c_str());
407 const string& prefix,
412 vector<double> low, high;
415 for(
unsigned int j=0; j<histoSysList.size(); ++j){
416 std::stringstream str;
419 const HistoSys& histoSys = histoSysList.at(j);
420 RooDataHist* lowDHist =
new RooDataHist((prefix+str.str()+
"lowDHist").c_str(),
"",observables, histoSys.GetHistoLow());
421 RooDataHist* highDHist =
new RooDataHist((prefix+str.str()+
"highDHist").c_str(),
"",observables, histoSys.GetHistoHigh());
424 lowSet.
add(*lowFunc);
425 highSet.
add(*highFunc);
430 interp.setPositiveDefinite();
431 interp.setAllInterpCodes(4);
434 interp.setBinIntegrator(observableSet);
435 interp.forceNumInt();
439 auto interpInWS =
proto->arg(prefix.c_str());
450 std::vector<string> prodNames;
453 vector<string> normFactorNames, rangeNames;
456 string overallNorm_times_sigmaEpsilon = sample.
GetName() +
"_" + channel +
"_scaleFactors";
457 auto sigEps =
proto->arg(sigmaEpsilon.c_str());
459 auto normFactor = std::make_unique<RooProduct>(overallNorm_times_sigmaEpsilon.c_str(), overallNorm_times_sigmaEpsilon.c_str(),
RooArgList(*sigEps));
461 if(normList.size() > 0){
463 for(vector<NormFactor>::iterator itr = normList.begin(); itr != normList.end(); ++itr){
469 varname = norm.
GetName() +
"_" + channel;
478 std::stringstream range;
481 if(
proto->obj(varname.c_str()) == NULL) {
484 proto->factory((varname + range.str()).c_str());
490 cxcoutW(
HistFactory) <<
"Const attribute to <NormFactor> tag is deprecated, will ignore." <<
491 " Instead, add \n\t<ParamSetting Const=\"True\"> " << varname <<
" </ParamSetting>\n" <<
492 " to your top-level XML's <Measurement> entry" << endl;
494 prodNames.push_back(varname);
495 rangeNames.push_back(range.str());
496 normFactorNames.push_back(varname);
500 for (
const auto&
name : prodNames) {
503 normFactor->addTerm(arg);
508 unsigned int rangeIndex=0;
509 for( vector<string>::iterator nit = normFactorNames.begin(); nit!=normFactorNames.end(); ++nit){
510 if( count (normFactorNames.begin(), normFactorNames.end(), *nit) > 1 ){
511 cxcoutI(
HistFactory) <<
"<NormFactor Name =\""<<*nit<<
"\"> is duplicated for <Sample Name=\""
512 << sample.
GetName() <<
"\">, but only one factor will be included. \n Instead, define something like"
513 <<
"\n\t<Function Name=\""<<*nit<<
"Squared\" Expression=\""<<*nit<<
"*"<<*nit<<
"\" Var=\""<<*nit<<rangeNames.at(rangeIndex)
514 <<
"\"> \nin your top-level XML's <Measurment> entry and use <NormFactor Name=\""<<*nit<<
"Squared\" in your channel XML file."<< endl;
524 std::vector<OverallSys>& systList,
525 vector<string>& constraintTermNames,
526 vector<string>& totSystTermNames) {
532 totSystTermNames.push_back(prefix);
535 vector<double> lowVec, highVec;
537 std::map<std::string, double>::iterator itconstr;
538 for(
unsigned int i = 0; i < systList.size(); ++i) {
541 std::string strname = sys.
GetName();
542 const char *
name = strname.c_str();
553 cxcoutI(
HistFactory) <<
"HistoToWorkspaceFast::AddConstraintTerm - zero uncertainty assigned - skip systematic " << sys.
GetName() << std::endl;
556 double tauVal = 1./(relerr*relerr);
557 double sqtau = 1./relerr;
571 alphaOfBeta->
Print(
"t");
574 constraintTermNames.push_back(gamma->GetName());
578 const_cast<RooArgSet*
>(
proto->set(
"globalObservables"))->add(*yvar);
581 params.
add(*alphaOfBeta);
592 makeGaussianConstraint(*alpha, *
proto, isUniform, constraintTermNames);
603 double tauVal = 1./relerr;
604 std::string tauName =
"tau_" + sys.
GetName();
606 double kappaVal = 1. + relerr;
607 std::string kappaName =
"kappa_" + sys.
GetName();
609 const char * alphaName = alpha->
GetName();
611 std::string alphaOfBetaName =
"alphaOfBeta_" + sys.
GetName();
613 tauName.c_str(),kappaName.c_str(),alphaName,
614 tauName.c_str(),kappaName.c_str(),alphaName ) );
618 alphaOfBeta->
Print(
"t");
619 params.
add(*alphaOfBeta);
624 double low = sys.
GetLow();
626 lowVec.push_back(low);
627 highVec.push_back(high);
631 if(systList.size() > 0){
636 assert(
int(lowVec.size()) == params.
getSize() );
638 FlexibleInterpVar interp( (interpName).c_str(),
"", params, 1., lowVec, highVec);
641 proto->import(interp);
646 proto->import(interp);
656 const vector<RooProduct*>& sampleScaleFactors, std::vector<vector<RooAbsArg*>>& sampleHistFuncs)
const {
657 assert(sampleScaleFactors.size() == sampleHistFuncs.size());
662 throw std::logic_error(
"HistFactory didn't process the observables correctly. Please file a bug report.");
664 auto firstHistFunc =
dynamic_cast<const RooHistFunc*
>(sampleHistFuncs.front().front());
665 if (!firstHistFunc) {
667 firstHistFunc =
dynamic_cast<const RooHistFunc*
>(piecewiseInt->nominalHist());
669 assert(firstHistFunc);
672 const std::string binWidthFunctionName = totName +
"_binWidth";
673 RooBinWidthFunction binWidth(binWidthFunctionName.c_str(),
"Divide by bin width to obtain probability density", *firstHistFunc,
true);
674 proto->import(binWidth);
675 auto binWidthWS =
proto->function(binWidthFunctionName.c_str());
681 for (
unsigned int i=0; i < sampleHistFuncs.size(); ++i) {
682 assert(!sampleHistFuncs[i].empty());
683 coefList.
add(*sampleScaleFactors[i]);
685 std::vector<RooAbsArg*>& thisSampleHistFuncs = sampleHistFuncs[i];
686 thisSampleHistFuncs.push_back(binWidthWS);
688 if (thisSampleHistFuncs.size() == 1) {
690 shapeList.
add(*thisSampleHistFuncs.front());
693 std::string
name = thisSampleHistFuncs.front()->GetName();
694 auto pos =
name.find(
"Hist_alpha");
695 if (pos != std::string::npos) {
696 name =
name.substr(0, pos) +
"shapes";
697 }
else if ( (pos =
name.find(
"nominal")) != std::string::npos) {
698 name =
name.substr(0, pos) +
"shapes";
708 RooRealSumPdf tot(totName.c_str(), totName.c_str(), shapeList, coefList,
true);
721 vector<string>& likelihoodTermNames){
726 for(
Int_t i=lowBin; i<highBin; ++i){
727 std::stringstream str;
730 string command(
"Poisson::"+prefix+str.str()+
"("+obsPrefix+str.str()+
","+expPrefix+str.str()+
",1)");
734 cout <<
"Poisson Term " << command << endl;
738 likelihoodTermNames.push_back( temp->
GetName() );
741 proto->defineSet(prefix.c_str(),Pois);
751 for(
Int_t i=lowBin; i<highBin; ++i){
752 std::stringstream str;
755 cout <<
"expected number of events called: " << expPrefix << endl;
761 cout <<
"setting obs"+str.str()+
" to expected = " << exp->
getVal() <<
" check: " << obs->
getVal() << endl;
764 obsForTree[i] = exp->
getVal();
765 tree->Branch((obsPrefix+str.str()).c_str(), obsForTree+i ,(obsPrefix+str.str()+
"/D").c_str());
768 cout <<
"problem retrieving obs or exp " << obsPrefix+str.str() << obs <<
" " << expPrefix+str.str() << exp << endl;
775 delete [] obsForTree;
777 proto->import(*data);
786 map<string,double> gammaSyst,
787 map<string,double> uniformSyst,
788 map<string,double> logNormSyst,
789 map<string,double> noSyst) {
790 string pdfName(pdfNameChar);
793 if( combined_config==NULL ) {
794 std::cout <<
"Error: Failed to find object 'ModelConfig' in workspace: "
800 string edit=
"EDIT::newSimPdf("+pdfName+
",";
802 string lastPdf=pdfName;
804 unsigned int numReplacements = 0;
805 unsigned int nskipped = 0;
806 map<string,double>::iterator it;
810 for(it=gammaSyst.begin(); it!=gammaSyst.end(); ++it) {
812 if(!
proto->var((
"alpha_"+it->first).c_str())){
819 double relativeUncertainty = it->second;
820 double scale = 1/sqrt((1+1/pow(relativeUncertainty,2)));
823 proto->factory(
Form(
"beta_%s[1,0,10]",it->first.c_str()));
824 proto->factory(
Form(
"y_%s[%f]",it->first.c_str(),1./pow(relativeUncertainty,2))) ;
825 proto->factory(
Form(
"theta_%s[%f]",it->first.c_str(),pow(relativeUncertainty,2))) ;
826 proto->factory(
Form(
"Gamma::beta_%sConstraint(beta_%s,sum::k_%s(y_%s,one[1]),theta_%s,zero[0])",
831 it->first.c_str())) ;
847 proto->factory(
Form(
"PolyVar::alphaOfBeta_%s(beta_%s,{%f,%f})",it->first.c_str(),it->first.c_str(),-1./scale,1./scale));
850 if(
proto->var(
Form(
"alpha_%s",it->first.c_str()))->isConstant()) {
851 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
true);
854 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
false);
860 editList+=precede +
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint";
862 editList+=precede +
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first;
872 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
873 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
877 cout <<
"Going to issue this edit command\n" << edit<< endl;
878 proto->factory( edit.c_str() );
881 cxcoutWHF <<
"---------------------\n WARNING: failed to make EDIT\n\n" << endl;
887 for(it=uniformSyst.begin(); it!=uniformSyst.end(); ++it) {
888 cout <<
"edit for " << it->first <<
"with rel uncert = " << it->second << endl;
889 if(!
proto->var((
"alpha_"+it->first).c_str())){
890 cout <<
"systematic not there" << endl;
897 proto->factory(
Form(
"beta_%s[1,0,10]",it->first.c_str()));
898 proto->factory(
Form(
"Uniform::beta_%sConstraint(beta_%s)",it->first.c_str(),it->first.c_str()));
899 proto->factory(
Form(
"PolyVar::alphaOfBeta_%s(beta_%s,{-1,1})",it->first.c_str(),it->first.c_str()));
902 if(
proto->var(
Form(
"alpha_%s",it->first.c_str()))->isConstant())
903 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
true);
905 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
false);
910 cout <<
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint" << endl;
911 editList+=precede +
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint";
913 cout <<
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first << endl;
914 editList+=precede +
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first;
916 if(
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) &&
proto->var((
"alpha_"+it->first).c_str()) )
917 cout <<
" checked they are there" <<
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) <<
" " <<
proto->var((
"alpha_"+it->first).c_str()) << endl;
919 cout <<
"NOT THERE" << endl;
922 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
923 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
928 proto->factory( edit.c_str() );
931 cxcoutWHF <<
"---------------------\n WARNING: failed to make EDIT\n\n" << endl;
941 for(it=logNormSyst.begin(); it!=logNormSyst.end(); ++it) {
942 cout <<
"edit for " << it->first <<
"with rel uncert = " << it->second << endl;
943 if(!
proto->var((
"alpha_"+it->first).c_str())){
944 cout <<
"systematic not there" << endl;
950 double relativeUncertainty = it->second;
951 double kappa = 1+relativeUncertainty;
955 double scale = relativeUncertainty;
958 const char * cname = it->first.c_str();
965 cname, cname, cname, cname)) ;
966 proto->factory(
TString::Format(
"PolyVar::alphaOfBeta_%s(beta_%s,{%f,%f})",cname,cname,-1./scale,1./scale));
978 cout <<
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint" << endl;
979 editList+=precede +
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint";
981 cout <<
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first << endl;
982 editList+=precede +
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first;
984 if(
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) &&
proto->var((
"alpha_"+it->first).c_str()) )
985 cout <<
" checked they are there" <<
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) <<
" " <<
proto->var((
"alpha_"+it->first).c_str()) << endl;
987 cout <<
"NOT THERE" << endl;
990 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
991 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
996 proto->factory( edit.c_str() );
999 cxcoutWHF <<
"\n\n ---------------------\n WARNING: failed to make EDIT\n\n" << endl;
1006 proto->removeSet(
"globalObservables");
1007 proto->defineSet(
"globalObservables",gobsNew);
1015 for(it=noSyst.begin(); it!=noSyst.end(); ++it) {
1017 cout <<
"remove constraint for parameter" << it->first << endl;
1018 if(!
proto->var((
"alpha_"+it->first).c_str()) || !
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) ) {
1019 cout <<
"systematic not there" << endl;
1026 if ( !
proto->var(
"one") ) {
proto->factory(
"one[1.0]"); }
1027 proto->var(
"one")->setConstant();
1030 cout <<
"alpha_"+it->first+
"Constraint=one" << endl;
1031 editList+=precede +
"alpha_"+it->first+
"Constraint=one";
1035 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
1036 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
1040 cout << edit << endl;
1041 proto->factory( edit.c_str() );
1044 cxcoutWHF <<
"---------------------\n WARNING: failed to make EDIT\n\n" << endl;
1052 edit=
"EDIT::newSimPdf("+lastPdf+
","+editList+
")";
1053 cout << edit<< endl;
1054 proto->factory( edit.c_str() );
1059 combined_config->
SetPdf(*newOne);
1062 cxcoutWHF <<
"\n\n ---------------------\n WARNING: failed to make EDIT\n\n" << endl;
1069 FILE* covFile = fopen ((filename).c_str(),
"w");
1074 fprintf(covFile,
" ") ;
1077 fprintf(covFile,
" & %s", myargi->
GetName());
1079 fprintf(covFile,
"\\\\ \\hline \n" );
1083 fprintf(covFile,
"%s", myargi->
GetName());
1088 fprintf(covFile,
" & %.2f", result->
correlation(*myargi, *myargj));
1091 fprintf(covFile,
" \\\\\n");
1104 Error(
"MakeSingleChannelWorkspace",
1105 "The input Channel does not contain any sample - return a nullptr");
1109 const TH1* channel_hist_template = channel.
GetSamples().front().GetHisto();
1110 if (channel_hist_template ==
nullptr) {
1112 channel_hist_template = channel.
GetSamples().front().GetHisto();
1114 if (channel_hist_template ==
nullptr) {
1115 std::ostringstream stream;
1116 stream <<
"The sample " << channel.
GetSamples().front().GetName()
1117 <<
" in channel " << channel.
GetName() <<
" does not contain a histogram. This is the channel:\n";
1118 channel.
Print(stream);
1119 Error(
"MakeSingleChannelWorkspace",
"%s", stream.str().c_str());
1124 std::cout <<
"MakeSingleChannelWorkspace: Channel: " << channel.
GetName()
1125 <<
" has uninitialized histogram pointers" << std::endl;
1139 string channel_name = channel.
GetName();
1149 for (
unsigned int idx=0; idx<
fObsNameVec.size(); ++idx ) {
1159 throw hf_exc(
"HistFactory is limited to 1- to 3-dimensional histograms.");
1163 <<
"\tStarting to process '"
1164 << channel_name <<
"' channel with " <<
fObsNameVec.size() <<
" observables"
1165 <<
"\n-----------------------------------------\n" << endl;
1171 auto proto_config = make_unique<ModelConfig>(
"ModelConfig",
proto);
1172 proto_config->SetWorkspace(*
proto);
1178 proto->factory(funcIter->c_str());
1182 RooArgSet likelihoodTerms(
"likelihoodTerms"), constraintTerms(
"constraintTerms");
1183 vector<string> likelihoodTermNames, constraintTermNames, totSystTermNames;
1185 std::vector<std::vector<RooAbsArg*>> allSampleHistFuncs;
1186 std::vector<RooProduct*> sampleScaleFactors;
1188 std::vector< pair<string,string> > statNamePairs;
1189 std::vector< pair<const TH1*, std::unique_ptr<TH1>> > statHistPairs;
1190 const std::string statFuncName =
"mc_stat_" + channel_name;
1192 string prefix, range;
1197 std::stringstream lumiStr;
1200 proto->factory(lumiStr.str().c_str());
1203 std::stringstream lumiErrorStr;
1205 proto->factory((
"Gaussian::lumiConstraint(Lumi,"+lumiErrorStr.str()+
")").c_str());
1206 proto->var(
"nominalLumi")->setConstant();
1207 proto->defineSet(
"globalObservables",
"nominalLumi");
1209 constraintTermNames.push_back(
"lumiConstraint");
1218 string overallSystName = sample.GetName() +
"_" + channel_name +
"_epsilon";
1220 string systSourcePrefix =
"alpha_";
1225 sample.GetOverallSysList(), constraintTermNames , totSystTermNames);
1227 allSampleHistFuncs.emplace_back();
1228 std::vector<RooAbsArg*>& sampleHistFuncs = allSampleHistFuncs.back();
1232 assert(normFactors);
1241 const TH1* nominal = sample.GetHisto();
1253 string expPrefix = sample.
GetName() +
"_" + channel_name;
1257 assert(nominalHistFunc);
1259 if(sample.GetHistoSysList().size() == 0) {
1261 cxcoutI(
HistFactory) << sample.GetName() +
"_" + channel_name +
" has no variation histograms " << endl;
1263 sampleHistFuncs.push_back(nominalHistFunc);
1267 string constraintPrefix = sample.GetName() +
"_" + channel_name +
"_Hist_alpha";
1270 RooArgList interpParams = makeInterpolationParameters(sample.GetHistoSysList(), *
proto);
1273 for(std::size_t i = 0; i < interpParams.
size(); ++i) {
1274 bool isUniform = measurement.
GetUniformSyst().count(sample.GetHistoSysList()[i].GetName()) > 0;
1275 makeGaussianConstraint(interpParams[i], *
proto, isUniform, constraintTermNames);
1279 sampleHistFuncs.push_back( makeLinInterp(interpParams, nominalHistFunc,
proto,
1280 sample.GetHistoSysList(), constraintPrefix, observables) );
1287 if( sample.GetStatError().GetActivate() ) {
1290 cxcoutF(
HistFactory) <<
"Cannot include Stat Error for histograms of more than 3 dimensions."
1299 cxcoutI(
HistFactory) <<
"Sample: " << sample.GetName() <<
" to be included in Stat Error "
1300 <<
"for channel " << channel_name
1303 string UncertName = sample.GetName() +
"_" + channel_name +
"_StatAbsolUncert";
1304 std::unique_ptr<TH1> statErrorHist;
1306 if( sample.GetStatError().GetErrorHist() == NULL ) {
1309 <<
" Channel: " << channel_name
1310 <<
" Sample: " << sample.GetName()
1317 statErrorHist.reset(
static_cast<TH1*
>(sample.GetStatError().GetErrorHist()->Clone()));
1322 <<
"\tChannel: " << channel_name
1323 <<
"\tSample: " << sample.GetName()
1324 <<
"\tError Histogram: " << statErrorHist->GetName() << std::endl;
1327 statErrorHist->Multiply( nominal );
1328 statErrorHist->SetName( UncertName.c_str() );
1333 statHistPairs.emplace_back(nominal, std::move(statErrorHist));
1351 if( paramHist ==
nullptr ) {
1357 for (
int idx=0; itr!=
fObsNameVec.end(); ++itr, ++idx ) {
1358 theObservables.
add( *
proto->var(itr->c_str()) );
1363 std::string ParamSetPrefix =
"gamma_stat_" + channel_name;
1367 ParamSetPrefix.c_str(),
1369 gammaMin, gammaMax);
1371 ParamHistFunc statUncertFunc(statFuncName.c_str(), statFuncName.c_str(),
1372 theObservables, statFactorParams );
1380 sampleHistFuncs.push_back(paramHist);
1389 if( sample.GetShapeFactorList().size() > 0 ) {
1392 cxcoutF(
HistFactory) <<
"Cannot include Stat Error for histograms of more than 3 dimensions."
1397 cxcoutI(
HistFactory) <<
"Sample: " << sample.GetName() <<
" in channel: " << channel_name
1398 <<
" to be include a ShapeFactor."
1401 for(
unsigned int i=0; i < sample.GetShapeFactorList().
size(); ++i) {
1403 ShapeFactor& shapeFactor = sample.GetShapeFactorList().at(i);
1405 std::string funcName = channel_name +
"_" + shapeFactor.
GetName() +
"_shapeFactor";
1407 if( paramHist ==
nullptr ) {
1411 for (
int idx=0; itr!=
fObsNameVec.end(); ++itr, ++idx ) {
1412 theObservables.
add( *
proto->var(itr->c_str()) );
1416 std::string funcParams =
"gamma_" + shapeFactor.
GetName();
1422 theObservables, 0, 1000);
1425 ParamHistFunc shapeFactorFunc( funcName.c_str(), funcName.c_str(),
1426 theObservables, shapeFactorParams );
1432 <<
" to have initial shape from hist: "
1435 shapeFactorFunc.
setShape( initialShape );
1441 <<
" to be constant" << std::endl;
1450 sampleHistFuncs.push_back(paramHist);
1460 if( sample.GetShapeSysList().size() != 0 ) {
1463 cxcoutF(
HistFactory) <<
"Cannot include Stat Error for histograms of more than 3 dimensions."
1469 std::vector<string> ShapeSysNames;
1471 for(
unsigned int i = 0; i < sample.GetShapeSysList().
size(); ++i) {
1485 <<
" to include a ShapeSys." << std::endl;
1487 std::string funcName = channel_name +
"_" + shapeSys.
GetName() +
"_ShapeSys";
1488 ShapeSysNames.push_back( funcName );
1490 if( paramHist == NULL ) {
1498 theObservables.
add( *
proto->var(itr->c_str()) );
1502 std::string funcParams =
"gamma_" + shapeSys.
GetName();
1505 theObservables, 0, 10);
1508 ParamHistFunc shapeFactorFunc( funcName.c_str(), funcName.c_str(),
1509 theObservables, shapeFactorParams );
1532 Double_t minShapeUncertainty = 0.0;
1534 *paramHist, shapeErrorHist,
1536 minShapeUncertainty);
1545 for(
unsigned int i = 0; i < ShapeSysNames.size(); ++i ) {
1546 auto func =
proto->function(ShapeSysNames.at(i).c_str());
1548 sampleHistFuncs.push_back(func);
1559 auto lumi =
proto->arg(
"Lumi");
1560 if( !sample.GetNormalizeByTheory() ) {
1563 lumiParamString += measurement.
GetLumi();
1565 lumi =
proto->factory((
"Lumi[" + lumiParamString +
"]").
Data());
1571 normFactors->addTerm(lumi);
1577 auto normFactorsInWS =
dynamic_cast<RooProduct*
>(
proto->arg(normFactors->GetName()));
1578 assert(normFactorsInWS);
1580 sampleScaleFactors.push_back(normFactorsInWS);
1585 if(!statHistPairs.empty()) {
1590 if( fracStatError == NULL ) {
1592 << channel_name +
"_StatUncert" +
"_RelErr" << std::endl;
1600 << chanStatUncertFunc->
GetName()
1601 <<
" params: " << chanStatUncertFunc->
paramList()
1620 *chanStatUncertFunc, fracStatError.
get(),
1622 statRelErrorThreshold);
1630 sampleScaleFactors, allSampleHistFuncs);
1631 likelihoodTermNames.push_back(channel_name+
"_model");
1635 for(
unsigned int i=0; i<systToFix.size(); ++i){
1643 if(systToFix.at(i)==
"Lumi"){
1644 auxMeas =
proto->var(
"nominalLumi");
1650 const_cast<RooArgSet*
>(
proto->set(
"globalObservables"))->remove(*auxMeas);
1657 <<
" could not set it to constant" << endl;
1663 for(
unsigned int i=0; i<constraintTermNames.size(); ++i){
1664 RooAbsArg* proto_arg = (
proto->arg(constraintTermNames[i].c_str()));
1665 if( proto_arg==NULL ) {
1670 constraintTerms.
add( *proto_arg );
1673 for(
unsigned int i=0; i<likelihoodTermNames.size(); ++i){
1674 RooAbsArg* proto_arg = (
proto->arg(likelihoodTermNames[i].c_str()));
1675 if( proto_arg==NULL ) {
1680 likelihoodTerms.add( *proto_arg );
1682 proto->defineSet(
"constraintTerms",constraintTerms);
1683 proto->defineSet(
"likelihoodTerms",likelihoodTerms);
1687 std::string observablesStr;
1691 observables.
add( *
proto->var(itr->c_str()) );
1692 if (!observablesStr.empty()) { observablesStr +=
","; }
1693 observablesStr += *itr;
1705 <<
"\timport model into workspace"
1706 <<
"\n-----------------------------------------\n" << endl;
1708 auto model = make_unique<RooProdPdf>(
1709 (
"model_"+channel_name).c_str(),
1710 "product of Poissons accross bins for a single channel",
1711 constraintTerms,
Conditional(likelihoodTerms,observables));
1714 proto_config->SetPdf(*model);
1715 proto_config->SetObservables(observables);
1716 proto_config->SetGlobalObservables(*
proto->set(
"globalObservables"));
1720 proto->import(*proto_config,proto_config->GetName());
1721 proto->importClassCode();
1726 const char* weightName=
"weightVar";
1732 int asymcalcPrintLevel = 0;
1743 RooDataSet dataset{
"obsData",
"",*
proto->set(
"obsAndWeight"),weightName};
1745 proto->import(dataset);
1750 if(data.GetName().empty()) {
1752 <<
" has no name! The name always needs to be set for additional datasets, "
1753 <<
"either via the \"Name\" tag in the XML or via RooStats::HistFactory::Data::SetName()." << std::endl;
1756 std::string
const& dataName = data.GetName();
1757 TH1 const* mnominal = data.GetHisto();
1760 <<
" with name: " << dataName <<
" is NULL" << std::endl;
1765 RooDataSet dataset{dataName.c_str(),
"", *
proto->set(
"obsAndWeight"), weightName};
1767 proto->import(dataset);
1779 TH1 const& mnominal,
1781 std::vector<std::string>
const& obsNameVec) {
1787 if (obsNameVec.empty() ) {
1788 Error(
"ConfigureHistFactoryDataset",
"Invalid input - return");
1796 for (
int i=1; i<=ax->
GetNbins(); ++i) {
1799 proto.var( obsNameVec[0].c_str() )->setVal( xval );
1801 if(obsNameVec.size()==1) {
1803 obsDataUnbinned.
add( *
proto.set(
"obsAndWeight"), fval );
1806 for(
int j=1; j<=ay->
GetNbins(); ++j) {
1808 proto.var( obsNameVec[1].c_str() )->setVal( yval );
1810 if(obsNameVec.size()==2) {
1812 obsDataUnbinned.
add( *
proto.set(
"obsAndWeight"), fval );
1815 for(
int k=1; k<=az->
GetNbins(); ++k) {
1817 proto.var( obsNameVec[2].c_str() )->setVal( zval );
1819 obsDataUnbinned.
add( *
proto.set(
"obsAndWeight"), fval );
1832 unsigned int histndim(1);
1833 std::string classname = hist->
ClassName();
1834 if (classname.find(
"TH1")==0) { histndim=1; }
1835 else if (classname.find(
"TH2")==0) { histndim=2; }
1836 else if (classname.find(
"TH3")==0) { histndim=3; }
1838 for (
unsigned int idx=0; idx<histndim; ++idx ) {
1851 if (ch_names.empty() || chs.empty() ) {
1852 Error(
"MakeCombinedModel",
"Input vectors are empty - return a nullptr");
1855 if (chs.size() < ch_names.size() ) {
1856 Error(
"MakeCombinedModel",
"Input vector of workspace has an invalid size - return a nullptr");
1864 map<string, RooAbsPdf*> pdfMap;
1865 vector<RooAbsPdf*> models;
1868 for(
unsigned int i = 0; i< ch_names.size(); ++i){
1875 stringstream channelString;
1876 channelString <<
"channelCat[";
1877 for(
unsigned int i = 0; i< ch_names.size(); ++i){
1878 string channel_name=ch_names[i];
1879 if (i == 0 && isdigit(channel_name[0])) {
1880 throw std::invalid_argument(
"The first channel name for HistFactory cannot start with a digit. Got " + channel_name);
1882 if (channel_name.find(
',') != std::string::npos) {
1883 throw std::invalid_argument(
"Channel names for HistFactory cannot contain ','. Got " + channel_name);
1886 if (i == 0) channelString << channel_name ;
1887 else channelString <<
',' << channel_name ;
1890 RooAbsPdf* model = ch->
pdf((
"model_"+channel_name).c_str());
1891 if(!model) cout <<
"failed to find model for channel"<<endl;
1893 models.push_back(model);
1894 globalObs.
add(*ch->
set(
"globalObservables"),
true);
1897 pdfMap[channel_name]=model;
1899 channelString <<
"]";
1902 <<
"\tEntering combination"
1903 <<
"\n-----------------------------------------\n" << endl;
1909 if (!channelCat)
throw std::runtime_error(
"Unable to construct a category from string " + channelString.str());
1911 auto simPdf= std::make_unique<RooSimultaneous>(
"simPdf",
"",pdfMap, *channelCat);
1912 auto combined_config = std::make_unique<ModelConfig>(
"ModelConfig", combined);
1913 combined_config->SetWorkspace(*combined);
1916 combined->
import(globalObs);
1917 combined->
defineSet(
"globalObservables",globalObs);
1918 combined_config->SetGlobalObservables(*combined->
set(
"globalObservables"));
1924 <<
"\tcreate toy data for " << channelString.str()
1925 <<
"\n-----------------------------------------\n" << endl;
1931 combined->
factory(
"weightVar[0,-1e10,1e10]");
1932 obsList.
add(*combined->
var(
"weightVar"));
1937 if( asimov_combined ) {
1938 combined->
import( *asimov_combined,
Rename(
"asimovData"));
1941 std::cout <<
"Error: Failed to create combined asimov dataset" << std::endl;
1949 if(
dynamic_cast<RooDataSet*
>(data) && !combined->
data(data->GetName())) {
1955 obsList.
add(*channelCat);
1956 combined->
defineSet(
"observables",obsList);
1957 combined_config->SetObservables(*combined->
set(
"observables"));
1963 <<
"\tImporting combined model"
1964 <<
"\n-----------------------------------------\n" << endl;
1970 std::map< std::string, double>::iterator param_itr =
fParamValues.begin();
1973 std::string paramName = param_itr->first;
1974 double paramVal = param_itr->second;
1977 temp->
setVal( paramVal );
1978 cxcoutI(
HistFactory) <<
"setting " << paramName <<
" to the value: " << paramVal << endl;
1980 cxcoutE(
HistFactory) <<
"could not find variable " << paramName <<
" could not set its value" << endl;
1984 for(
unsigned int i=0; i<
fSystToFix.size(); ++i){
1998 combined_config->SetPdf(*simPdf);
2001 combined->
import(*combined_config,combined_config->GetName());
2010 std::vector<std::unique_ptr<RooWorkspace>>& wspace_vec,
2011 std::vector<std::string>
const& channel_names,
2012 std::string
const& dataSetName,
2017 std::unique_ptr<RooDataSet> simData;
2021 for(
unsigned int i = 0; i< channel_names.size(); ++i){
2024 cxcoutPHF <<
"Merging data for channel " << channel_names[i].c_str() << std::endl;
2026 if( !obsDataInChannel ) {
2027 std::cout <<
"Error: Can't find DataSet: " << dataSetName
2028 <<
" in channel: " << channel_names.at(i)
2034 auto tempData = std::make_unique<RooDataSet>(channel_names[i].c_str(),
"",
2035 obsList,
Index(*channelCat),
2037 Import(channel_names[i].c_str(),*obsDataInChannel));
2039 simData->append(*tempData);
2042 simData = std::move(tempData);
2049 combined->
import(*simData,
Rename(dataSetName.c_str()));
2050 return static_cast<RooDataSet*
>(combined->
data(dataSetName.c_str()));
2053 std::cout <<
"Error: Unable to merge observable datasets" << std::endl;
2070 Int_t binNumber = 0;
2073 for(
Int_t i_bin = 0; i_bin < numBins; ++i_bin) {
2084 if( histError != histError ) {
2085 std::cout <<
"Warning: In histogram " << Nominal->
GetName()
2086 <<
" bin error for bin " << i_bin
2087 <<
" is NAN. Not using Error!!!"
2095 if( histError < 0 ) {
2096 std::cout <<
"Warning: In histogram " << Nominal->
GetName()
2097 <<
" bin error for bin " << binNumber
2098 <<
" is < 0. Setting Error to 0"
2123 unsigned int numHists = HistVec.size();
2125 if( numHists == 0 ) {
2126 cxcoutE(
HistFactory) <<
"Warning: Empty Hist Vector, cannot create total uncertainty" << std::endl;
2130 const TH1* HistTemplate = HistVec.at(0).first;
2135 for(
unsigned int i = 0; i < HistVec.size(); ++i ) {
2137 const TH1* nominal = HistVec.at(i).first;
2138 const TH1* error = HistVec.at(i).second.get();
2150 std::vector<double> TotalBinContent( numBins, 0.0);
2151 std::vector<double> HistErrorsSqr( numBins, 0.0);
2153 Int_t binNumber = 0;
2156 for(
Int_t i_bins = 0; i_bins < numBins; ++i_bins) {
2163 for(
unsigned int i_hist = 0; i_hist < numHists; ++i_hist ) {
2165 const TH1* nominal = HistVec.at(i_hist).first;
2166 const TH1* error = HistVec.at(i_hist).second.get();
2181 if( histError != histError ) {
2183 <<
" bin error for bin " << binNumber
2184 <<
" is NAN. Not using error!!";
2188 TotalBinContent.at(i_bins) += histValue;
2189 HistErrorsSqr.at(i_bins) += histError*histError;
2201 for(
Int_t i = 0; i < numBins; ++i) {
2209 Double_t ErrorsSqr = HistErrorsSqr.at(i);
2210 Double_t TotalVal = TotalBinContent.at(i);
2212 if( TotalVal <= 0 ) {
2214 <<
" is <= 0. Setting error to 0"
2221 Double_t RelativeError = sqrt(ErrorsSqr) / TotalVal;
2225 if( RelativeError != RelativeError ) {
2227 <<
" HistErrorsSqr: " << ErrorsSqr
2228 <<
" TotalVal: " << TotalVal;
2242 <<
" Error = " << sqrt(ErrorsSqr)
2243 <<
" CentralVal = " << TotalVal
2244 <<
" RelativeError = " << RelativeError <<
"\n";
2248 return std::unique_ptr<TH1>(ErrorHist);
2284 if( numBins != numParams ) {
2285 std::cout <<
"Error: In createStatConstraintTerms, encountered bad number of bins" << std::endl;
2286 std::cout <<
"Given histogram with " << numBins <<
" bins,"
2287 <<
" but require exactly " << numParams << std::endl;
2291 Int_t TH1BinNumber = 0;
2303 <<
". Type of constraint: " <<
type << std::endl;
2307 const double sigmaRel = uncertHist->
GetBinContent(TH1BinNumber);
2311 if( sigmaRel <= 0 ){
2314 <<
" because sigma = " << sigmaRel
2316 <<
" (TH1 bin number = " << TH1BinNumber <<
")"
2318 gamma.setConstant(
kTRUE);
2323 gamma.setMax( 1 + 5*sigmaRel );
2327 std::string constrName = string(gamma.GetName()) +
"_constraint";
2328 std::string nomName = string(
"nom_") + gamma.GetName();
2329 std::string sigmaName = string(gamma.GetName()) +
"_sigma";
2330 std::string poisMeanName = string(gamma.GetName()) +
"_poisMean";
2338 RooConstVar constrSigma( sigmaName.c_str(), sigmaName.c_str(), sigmaRel );
2341 RooRealVar constrNom(nomName.c_str(), nomName.c_str(), 1.0,0,10);
2345 RooGaussian gauss( constrName.c_str(), constrName.c_str(),
2346 constrNom, gamma, constrSigma );
2352 gamma.setError(sigmaRel);
2355 Double_t tau = 1/sigmaRel/sigmaRel;
2358 RooRealVar constrNom(nomName.c_str(), nomName.c_str(), tau);
2363 std::string scalingName = string(gamma.GetName()) +
"_tau";
2364 RooConstVar poissonScaling( scalingName.c_str(), scalingName.c_str(), tau);
2367 RooProduct constrMean( poisMeanName.c_str(), poisMeanName.c_str(),
RooArgSet(gamma, poissonScaling) );
2372 RooPoisson pois(constrName.c_str(), constrName.c_str(), constrNom, constrMean);
2376 if (std::string(gamma.GetName()).find(
"gamma_stat") != std::string::npos) {
2379 gamma.setError(sigmaRel);
2384 std::cout <<
"Error: Did not recognize Stat Error constraint term type: "
2385 <<
type <<
" for : " << paramHist.
GetName() << std::endl;
2392 if( sigmaRel < minSigma ) {
2394 <<
" and is < " << minSigma
2395 <<
". Setting: " << gamma.GetName() <<
" to constant"
2397 gamma.setConstant(
kTRUE);
2400 constraintTermNames.push_back( constrName );
2401 ConstraintTerms.
add( *
proto->pdf(constrName.c_str()) );
2408 if( ! globalSet->
contains(*nomVarInWorkspace) ) {
2409 globalSet->
add( *nomVarInWorkspace );
2414 return ConstraintTerms;
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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,...
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.
Storage_t::size_type size() const
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.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
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)
static void setEvalErrorLoggingMode(ErrorLoggingMode m)
Set evaluation error logging mode.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooBinWidthFunction is a class that returns the bin width (or volume) given a RooHistFunc.
Class RooBinning is an implements RooAbsBinning in terms of an array of boundary values,...
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.
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.
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.
void setBins(Int_t nBins, const char *name=0)
Create a uniform binning under name 'name' for this variable.
virtual void setVal(Double_t value)
Set value of variable to 'value'.
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
void setAllInterpCodes(int code)
This class provides helper functions for creating likelihood models from histograms.
std::unique_ptr< RooProduct > CreateNormFactor(RooWorkspace *proto, std::string &channel, std::string &sigmaEpsilon, Sample &sample, bool doRatio)
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 SetObsToExpected(RooWorkspace *proto, std::string obsPrefix, std::string expPrefix, int lowBin, int highBin)
std::unique_ptr< TH1 > MakeScaledUncertaintyHist(const std::string &Name, std::vector< std::pair< const TH1 *, std::unique_ptr< TH1 > > > const &HistVec) const
std::vector< std::string > fPreprocessFunctions
void SetFunctionsToPreprocess(std::vector< std::string > lines)
std::vector< std::string > fObsNameVec
virtual ~HistoToWorkspaceFactoryFast()
RooHistFunc * MakeExpectedHistFunc(const TH1 *hist, RooWorkspace *proto, std::string prefix, const RooArgList &observables) const
Create the nominal hist function from hist, and register it in the workspace.
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 MakeTotalExpected(RooWorkspace *proto, const std::string &totName, const std::vector< RooProduct * > &sampleScaleFactors, std::vector< std::vector< RooAbsArg * > > &sampleHistFuncs) const
void AddPoissonTerms(RooWorkspace *proto, std::string prefix, std::string obsPrefix, std::string expPrefix, int lowBin, int highBin, std::vector< std::string > &likelihoodTermNames)
void ConfigureHistFactoryDataset(RooDataSet &obsData, TH1 const &nominal, RooWorkspace &proto, std::vector< std::string > const &obsNameVec)
static void PrintCovarianceMatrix(RooFitResult *result, RooArgSet *params, std::string filename)
std::vector< std::string > fSystToFix
RooDataSet * MergeDataSets(RooWorkspace *combined, std::vector< std::unique_ptr< RooWorkspace > > &wspace_vec, std::vector< std::string > const &channel_names, std::string const &dataSetName, RooArgList obsList, RooCategory *channelCat)
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)
RooArgList createObservables(const TH1 *hist, RooWorkspace *proto) const
Create observables of type RooRealVar. Creates 1 to 3 observables, depending on the type of the histo...
HistoToWorkspaceFactoryFast()
RooWorkspace * MakeCombinedModel(std::vector< std::string >, std::vector< std::unique_ptr< RooWorkspace > > &)
const std::string & GetName() 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::string GetName() const
get name of sample
std::vector< RooStats::HistFactory::NormFactor > & GetNormFactorList()
*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
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
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.
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 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.
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.
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.
const Double_t * GetArray() const
Class to manage histogram axis.
Bool_t IsVariableBinSize() const
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
const TArrayD * GetXbins() const
TH1 is the base class of all histogram classes in ROOT.
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 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.
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.