84#define NoHistConst_Low "0"
85#define NoHistConst_High "2000"
98 fNomLumi(1.0), fLumiError(0),
99 fLowBin(0), fHighBin(0)
106 fSystToFix( measurement.GetConstantParams() ),
107 fParamValues( measurement.GetParamValues() ),
108 fNomLumi( measurement.GetLumi() ),
109 fLumiError( measurement.GetLumi()*measurement.GetLumiRelErr() ),
110 fLowBin( measurement.GetBinLow() ),
111 fHighBin( measurement.GetBinHigh() ) {
126 if( proto_config == NULL ) {
127 std::cout <<
"Error: Did not find 'ModelConfig' object in file: " << ws_single->
GetName()
132 std::vector<std::string> poi_list = measurement.
GetPOIList();
133 if( poi_list.size()==0 ) {
134 std::cout <<
"Warining: No Parametetrs of interest are set" << std::endl;
137 cout <<
"Setting Parameter(s) of Interest as: ";
138 for(
unsigned int i = 0; i < poi_list.size(); ++i) {
139 cout << 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";
173 proto_config->
SetPdf( *ws_single->
pdf(
"newSimPdf" ) );
180 std::cout <<
"Error: Failed to find dataset: " << expData
181 <<
" in workspace" << std::endl;
184 if(poi_list.size()!=0){
196 if( !pdf ) pdf = ws_single->
pdf( ModelName.c_str() );
197 const RooArgSet* observables = ws_single->
set(
"observables");
200 std::string SnapShotName =
"NominalParamValues";
207 std::string AsimovName = asimov.
GetName();
209 std::cout <<
"Generating additional Asimov Dataset: " << AsimovName << std::endl;
214 std::cout <<
"Importing Asimov dataset" << std::endl;
215 bool failure = ws_single->
import(*asimov_dataset,
Rename(AsimovName.c_str()));
217 std::cout <<
"Error: Failed to import Asimov dataset: " << AsimovName
219 delete asimov_dataset;
228 delete asimov_dataset;
250 string ch_name = channel.
GetName();
254 if( ws_single == NULL ) {
255 std::cout <<
"Error: Failed to make Single-Channel workspace for channel: " << ch_name
256 <<
" and measurement: " << measurement.
GetName() << std::endl;
284 vector<RooWorkspace*> channel_workspaces;
285 vector<string> channel_names;
287 for(
unsigned int chanItr = 0; chanItr < measurement.
GetChannels().size(); ++chanItr ) {
292 std::cout <<
"MakeModelAndMeasurementsFast: Channel: " << channel.
GetName()
293 <<
" has uninitialized histogram pointers" << std::endl;
297 string ch_name = channel.
GetName();
298 channel_names.push_back(ch_name);
303 channel_workspaces.push_back(ws_single);
317 for (vector<RooWorkspace*>::iterator iter = channel_workspaces.begin() ; iter != channel_workspaces.end() ; ++iter) {
327 string prefix,
string productPrefix,
330 cout <<
"processing hist " << hist->
GetName() << endl;
332 cout <<
"hist is empty" << endl;
342 unsigned int histndim(1);
343 std::string classname = hist->
ClassName();
344 if (classname.find(
"TH1")==0) { histndim=1; }
345 else if (classname.find(
"TH2")==0) { histndim=2; }
346 else if (classname.find(
"TH3")==0) { histndim=3; }
351 std::vector<std::string>::iterator itr =
fObsNameVec.begin();
352 for (
int idx=0; itr!=
fObsNameVec.end(); ++itr, ++idx ) {
353 if ( !
proto->var(itr->c_str()) ) {
354 const TAxis* axis(0);
355 if (idx==0) { axis = hist->
GetXaxis(); }
356 if (idx==1) { axis = hist->
GetYaxis(); }
357 if (idx==2) { axis = hist->
GetZaxis(); }
363 proto->var(itr->c_str())->setBins(nbins);
365 observables.
add( *
proto->var(itr->c_str()) );
371 proto->import(*histFunc);
374 proto->factory((
"prod:"+productPrefix+
"("+prefix+
"_nominal,"+systTerm+
")").c_str() );
387 for(
Int_t i=lowBin; i<highBin; ++i){
388 std::stringstream str;
395 for(
int i=lowBin; i<highBin; ++i){
396 for(
int j=0; j<highBin-lowBin; ++j){
397 if(i==j) { Cov(i,j) =
sqrt(mean(i)); }
398 else { Cov(i,j) = 0; }
405 floating, mean, Cov);
407 proto->import(constraint);
409 constraintTermNames.push_back(constraint.
GetName());
413 std::vector<HistoSys> histoSysList,
414 string prefix,
string productPrefix,
416 vector<string>& constraintTermNames){
426 unsigned int histndim(1);
427 std::string classname = nominal->
ClassName();
428 if (classname.find(
"TH1")==0) { histndim=1; }
429 else if (classname.find(
"TH2")==0) { histndim=2; }
430 else if (classname.find(
"TH3")==0) { histndim=3; }
436 std::vector<std::string>::iterator itr =
fObsNameVec.begin();
437 for (
int idx=0; itr!=
fObsNameVec.end(); ++itr, ++idx ) {
438 if ( !
proto->var(itr->c_str()) ) {
439 const TAxis* axis(
nullptr);
440 if (idx==0) { axis = nominal->
GetXaxis(); }
441 else if (idx==1) { axis = nominal->
GetYaxis(); }
442 else if (idx==2) { axis = nominal->
GetZaxis(); }
444 std::cout <<
"Error: Too many observables. "
445 <<
"HistFactory only accepts up to 3 observables (3d) "
454 proto->var(itr->c_str())->setBins(nbins);
456 observables.
add( *
proto->var(itr->c_str()) );
468 for(
unsigned int j=0; j<histoSysList.size(); ++j){
469 std::stringstream str;
472 HistoSys& histoSys = histoSysList.at(j);
473 string histoSysName = histoSys.
GetName();
478 temp = (
RooRealVar*)
proto->factory((
"alpha_" + histoSysName + range).c_str());
481 string command=(
"Gaussian::alpha_"+histoSysName+
"Constraint(alpha_"+histoSysName+
",nom_alpha_"+histoSysName+
"[0.,-10,10],1.)");
482 cout << command << endl;
483 constraintTermNames.push_back(
proto->factory( command.c_str() )->
GetName() );
484 proto->var((
"nom_alpha_"+histoSysName).c_str())->setConstant();
485 const_cast<RooArgSet*
>(
proto->set(
"globalObservables"))->add(*
proto->var((
"nom_alpha_"+histoSysName).c_str()));
492 vector<double> low, high;
495 for(
unsigned int j=0; j<histoSysList.size(); ++j){
496 std::stringstream str;
499 HistoSys& histoSys = histoSysList.at(j);
504 lowSet.
add(*lowFunc);
505 highSet.
add(*highFunc);
517 proto->import(interp);
520 proto->factory((
"prod:"+productPrefix+
"("+prefix+
","+systTerm+
")").c_str() );
526 string overallNorm_times_sigmaEpsilon ;
530 vector<string> normFactorNames, rangeNames;
532 if(normList.size() > 0){
534 for(vector<NormFactor>::iterator itr = normList.begin(); itr != normList.end(); ++itr){
539 if(!prodNames.empty()) prodNames +=
",";
541 varname = norm.
GetName() +
"_" + channel;
550 std::stringstream range;
553 if(
proto->obj(varname.c_str()) == NULL) {
554 cout <<
"making normFactor: " << norm.
GetName() << endl;
556 proto->factory((varname + range.str()).c_str());
562 cout <<
"WARNING: Const attribute to <NormFactor> tag is deprecated, will ignore." <<
563 " Instead, add \n\t<ParamSetting Const=\"True\">" << varname <<
"</ParamSetting>\n" <<
564 " to your top-level XML's <Measurment> entry" << endl;
567 rangeNames.push_back(range.str());
568 normFactorNames.push_back(varname);
571 overallNorm_times_sigmaEpsilon = sample.
GetName() +
"_" + channel +
"_overallNorm_x_sigma_epsilon";
572 proto->factory((
"prod::" + overallNorm_times_sigmaEpsilon +
"(" + prodNames +
"," + sigmaEpsilon +
")").c_str());
575 unsigned int rangeIndex=0;
576 for( vector<string>::iterator nit = normFactorNames.begin(); nit!=normFactorNames.end(); ++nit){
577 if( count (normFactorNames.begin(), normFactorNames.end(), *nit) > 1 ){
578 cout <<
"WARNING: <NormFactor Name =\""<<*nit<<
"\"> is duplicated for <Sample Name=\""
579 << sample.
GetName() <<
"\">, but only one factor will be included. \n Instead, define something like"
580 <<
"\n\t<Function Name=\""<<*nit<<
"Squared\" Expresion=\""<<*nit<<
"*"<<*nit<<
"\" Var=\""<<*nit<<rangeNames.at(rangeIndex)
581 <<
"\"> \nin your top-level XML's <Measurment> entry and use <NormFactor Name=\""<<*nit<<
"Squared\" in your channel XML file."<< endl;
586 if(!overallNorm_times_sigmaEpsilon.empty())
587 return overallNorm_times_sigmaEpsilon;
594 std::vector<OverallSys>& systList,
595 vector<string>& constraintTermNames,
596 vector<string>& totSystTermNames) {
602 totSystTermNames.push_back(prefix);
605 vector<double> lowVec, highVec;
607 std::map<std::string, double>::iterator itconstr;
608 for(
unsigned int i = 0; i < systList.size(); ++i) {
611 std::string strname = sys.
GetName();
612 const char *
name = strname.c_str();
616 std::cout <<
"HistoToWorkspaceFast::AddConstraintTerm - skip systematic " << sys.
GetName() << std::endl;
623 std::cout <<
"HistoToWorkspaceFast::AddConstraintTerm - zero uncertainty assigned - skip systematic " << sys.
GetName() << std::endl;
626 double tauVal = 1./(relerr*relerr);
627 double sqtau = 1./relerr;
640 alphaOfBeta->
Print(
"t");
642 constraintTermNames.push_back(
gamma->GetName());
646 const_cast<RooArgSet*
>(
proto->set(
"globalObservables"))->add(*yvar);
649 params.
add(*alphaOfBeta);
650 std::cout <<
"Added a gamma constraint for " <<
name << std::endl;
659 double gaussSigma = 1;
662 std::cout <<
"Added a uniform constraint for " <<
name <<
" as a gaussian constraint with a very large sigma " << std::endl;
673 constraintTermNames.push_back( gausConstraint->
GetName() );
674 proto->var((
"nom_" + prefix + sys.
GetName()).c_str())->setConstant();
675 const_cast<RooArgSet*
>(
proto->set(
"globalObservables"))->add(*nomAlpha);
691 double tauVal = 1./relerr;
692 std::string tauName =
"tau_" + sys.
GetName();
694 double kappaVal = 1. + relerr;
695 std::string kappaName =
"kappa_" + sys.
GetName();
697 const char * alphaName = alpha->
GetName();
699 std::string alphaOfBetaName =
"alphaOfBeta_" + sys.
GetName();
701 tauName.c_str(),kappaName.c_str(),alphaName,
702 tauName.c_str(),kappaName.c_str(),alphaName ) );
704 std::cout <<
"Added a log-normal constraint for " <<
name << std::endl;
705 alphaOfBeta->
Print(
"t");
706 params.
add(*alphaOfBeta);
711 double low = sys.
GetLow();
713 lowVec.push_back(low);
714 highVec.push_back(high);
718 if(systList.size() > 0){
723 assert(
int(lowVec.size()) == params.
getSize() );
725 FlexibleInterpVar interp( (interpName).c_str(),
"", params, 1., lowVec, highVec);
728 proto->import(interp);
733 proto->import(interp);
743 vector<string>& syst_x_expectedPrefixNames,
744 vector<string>& normByNames){
754 double binWidth(1.0);
755 std::string obsNameVecStr;
756 std::vector<std::string>::iterator itr =
fObsNameVec.begin();
758 std::string obsName = *itr;
759 binWidth *=
proto->var(obsName.c_str())->numBins()/(
proto->var(obsName.c_str())->getMax() -
proto->var(obsName.c_str())->getMin()) ;
760 if (obsNameVecStr.size()>0) { obsNameVecStr +=
"_"; }
761 obsNameVecStr += obsName;
765 for(
unsigned int j=0; j<syst_x_expectedPrefixNames.size();++j){
766 std::stringstream str;
770 command=string(
Form(
"binWidth_%s_%d[%e]",obsNameVecStr.c_str(),j,binWidth));
771 proto->factory(command.c_str());
772 proto->var(
Form(
"binWidth_%s_%d",obsNameVecStr.c_str(),j))->setConstant();
773 coeffList+=prepend+
"binWidth_"+obsNameVecStr+str.str();
775 command=
"prod::L_x_"+syst_x_expectedPrefixNames.at(j)+
"("+normByNames.at(j)+
","+syst_x_expectedPrefixNames.at(j)+
")";
777 proto->factory(command.c_str());
778 shapeList+=prepend+
"L_x_"+syst_x_expectedPrefixNames.at(j);
787 proto->defineSet(
"coefList",coeffList.c_str());
788 proto->defineSet(
"shapeList",shapeList.c_str());
822 vector<string>& likelihoodTermNames){
827 for(
Int_t i=lowBin; i<highBin; ++i){
828 std::stringstream str;
831 string command(
"Poisson::"+prefix+str.str()+
"("+obsPrefix+str.str()+
","+expPrefix+str.str()+
",1)");
835 cout <<
"Poisson Term " << command << endl;
839 likelihoodTermNames.push_back( temp->
GetName() );
842 proto->defineSet(prefix.c_str(),Pois);
852 for(
Int_t i=lowBin; i<highBin; ++i){
853 std::stringstream str;
856 cout <<
"expected number of events called: " << expPrefix << endl;
862 cout <<
"setting obs"+str.str()+
" to expected = " <<
exp->getVal() <<
" check: " << obs->
getVal() << endl;
865 obsForTree[i] =
exp->getVal();
866 tree->Branch((obsPrefix+str.str()).c_str(), obsForTree+i ,(obsPrefix+str.str()+
"/D").c_str());
869 cout <<
"problem retrieving obs or exp " << obsPrefix+str.str() << obs <<
" " << expPrefix+str.str() <<
exp << endl;
876 delete [] obsForTree;
878 proto->import(*data);
887 map<string,double> gammaSyst,
888 map<string,double> uniformSyst,
889 map<string,double> logNormSyst,
890 map<string,double> noSyst) {
891 string pdfName(pdfNameChar);
894 if( combined_config==NULL ) {
895 std::cout <<
"Error: Failed to find object 'ModelConfig' in workspace: "
896 <<
proto->GetName() << std::endl;
901 string edit=
"EDIT::newSimPdf("+pdfName+
",";
903 string lastPdf=pdfName;
905 unsigned int numReplacements = 0;
906 unsigned int nskipped = 0;
907 map<string,double>::iterator it;
911 for(it=gammaSyst.begin(); it!=gammaSyst.end(); ++it) {
913 if(!
proto->var((
"alpha_"+it->first).c_str())){
920 double relativeUncertainty = it->second;
921 double scale = 1/
sqrt((1+1/
pow(relativeUncertainty,2)));
924 proto->factory(
Form(
"beta_%s[1,0,10]",it->first.c_str()));
925 proto->factory(
Form(
"y_%s[%f]",it->first.c_str(),1./
pow(relativeUncertainty,2))) ;
926 proto->factory(
Form(
"theta_%s[%f]",it->first.c_str(),
pow(relativeUncertainty,2))) ;
927 proto->factory(
Form(
"Gamma::beta_%sConstraint(beta_%s,sum::k_%s(y_%s,one[1]),theta_%s,zero[0])",
932 it->first.c_str())) ;
948 proto->factory(
Form(
"PolyVar::alphaOfBeta_%s(beta_%s,{%f,%f})",it->first.c_str(),it->first.c_str(),-1./scale,1./scale));
951 if(
proto->var(
Form(
"alpha_%s",it->first.c_str()))->isConstant()) {
952 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
true);
955 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
false);
961 editList+=precede +
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint";
963 editList+=precede +
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first;
973 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
974 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
978 cout <<
"Going to issue this edit command\n" << edit<< endl;
979 proto->factory( edit.c_str() );
982 cout <<
"\n\n ---------------------\n WARNING: failed to make EDIT\n\n" << endl;
988 for(it=uniformSyst.begin(); it!=uniformSyst.end(); ++it) {
989 cout <<
"edit for " << it->first <<
"with rel uncert = " << it->second << endl;
990 if(!
proto->var((
"alpha_"+it->first).c_str())){
991 cout <<
"systematic not there" << endl;
998 proto->factory(
Form(
"beta_%s[1,0,10]",it->first.c_str()));
999 proto->factory(
Form(
"Uniform::beta_%sConstraint(beta_%s)",it->first.c_str(),it->first.c_str()));
1000 proto->factory(
Form(
"PolyVar::alphaOfBeta_%s(beta_%s,{-1,1})",it->first.c_str(),it->first.c_str()));
1003 if(
proto->var(
Form(
"alpha_%s",it->first.c_str()))->isConstant())
1004 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
true);
1006 proto->var(
Form(
"beta_%s",it->first.c_str()))->setConstant(
false);
1011 cout <<
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint" << endl;
1012 editList+=precede +
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint";
1014 cout <<
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first << endl;
1015 editList+=precede +
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first;
1017 if(
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) &&
proto->var((
"alpha_"+it->first).c_str()) )
1018 cout <<
" checked they are there" <<
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) <<
" " <<
proto->var((
"alpha_"+it->first).c_str()) << endl;
1020 cout <<
"NOT THERE" << endl;
1023 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
1024 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
1028 cout << edit<< endl;
1029 proto->factory( edit.c_str() );
1032 cout <<
"\n\n ---------------------\n WARNING: failed to make EDIT\n\n" << endl;
1042 for(it=logNormSyst.begin(); it!=logNormSyst.end(); ++it) {
1043 cout <<
"edit for " << it->first <<
"with rel uncert = " << it->second << endl;
1044 if(!
proto->var((
"alpha_"+it->first).c_str())){
1045 cout <<
"systematic not there" << endl;
1051 double relativeUncertainty = it->second;
1052 double kappa = 1+relativeUncertainty;
1056 double scale = relativeUncertainty;
1059 const char * cname = it->first.c_str();
1066 cname, cname, cname, cname)) ;
1067 proto->factory(
TString::Format(
"PolyVar::alphaOfBeta_%s(beta_%s,{%f,%f})",cname,cname,-1./scale,1./scale));
1079 cout <<
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint" << endl;
1080 editList+=precede +
"alpha_"+it->first+
"Constraint=beta_" + it->first+
"Constraint";
1082 cout <<
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first << endl;
1083 editList+=precede +
"alpha_"+it->first+
"=alphaOfBeta_"+ it->first;
1085 if(
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) &&
proto->var((
"alpha_"+it->first).c_str()) )
1086 cout <<
" checked they are there" <<
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) <<
" " <<
proto->var((
"alpha_"+it->first).c_str()) << endl;
1088 cout <<
"NOT THERE" << endl;
1091 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
1092 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
1096 cout << edit<< endl;
1097 proto->factory( edit.c_str() );
1100 cout <<
"\n\n ---------------------\n WARNING: failed to make EDIT\n\n" << endl;
1107 proto->removeSet(
"globalObservables");
1108 proto->defineSet(
"globalObservables",gobsNew);
1116 for(it=noSyst.begin(); it!=noSyst.end(); ++it) {
1118 cout <<
"remove constraint for parameter" << it->first << endl;
1119 if(!
proto->var((
"alpha_"+it->first).c_str()) || !
proto->pdf((
"alpha_"+it->first+
"Constraint").c_str()) ) {
1120 cout <<
"systematic not there" << endl;
1127 if ( !
proto->var(
"one") ) {
proto->factory(
"one[1.0]"); }
1128 proto->var(
"one")->setConstant();
1131 cout <<
"alpha_"+it->first+
"Constraint=one" << endl;
1132 editList+=precede +
"alpha_"+it->first+
"Constraint=one";
1136 if(numReplacements%10 == 0 && numReplacements+nskipped!=gammaSyst.size()){
1137 edit=
"EDIT::"+lastPdf+
"_("+lastPdf+
","+editList+
")";
1141 cout << edit << endl;
1142 proto->factory( edit.c_str() );
1144 if(!newOne) { cout <<
"\n\n ---------------------\n WARNING: failed to make EDIT\n\n" << endl; }
1151 edit=
"EDIT::newSimPdf("+lastPdf+
","+editList+
")";
1152 cout << edit<< endl;
1153 proto->factory( edit.c_str() );
1158 combined_config->
SetPdf(*newOne);
1161 cout <<
"\n\n ---------------------\n WARNING: failed to make EDIT\n\n" << endl;
1168 FILE* covFile = fopen ((filename).c_str(),
"w");
1173 fprintf(covFile,
" ") ;
1176 fprintf(covFile,
" & %s", myargi->
GetName());
1178 fprintf(covFile,
"\\\\ \\hline \n" );
1182 fprintf(covFile,
"%s", myargi->
GetName());
1187 fprintf(covFile,
" & %.2f", result->
correlation(*myargi, *myargj));
1190 fprintf(covFile,
" \\\\\n");
1203 Error(
"MakeSingleChannelWorkspace",
1204 "The input Channel does not contain any sample - return a nullptr");
1208 const TH1* channel_hist_template = channel.
GetSamples().front().GetHisto();
1209 if (channel_hist_template ==
nullptr) {
1211 channel_hist_template = channel.
GetSamples().front().GetHisto();
1213 if (channel_hist_template ==
nullptr) {
1214 std::ostringstream stream;
1215 stream <<
"The sample " << channel.
GetSamples().front().GetName()
1216 <<
" in channel " << channel.
GetName() <<
" does not contain a histogram. This is the channel:\n";
1217 channel.
Print(stream);
1218 Error(
"MakeSingleChannelWorkspace",
"%s", stream.str().c_str());
1223 std::cout <<
"MakeSingleChannelWorkspace: Channel: " << channel.
GetName()
1224 <<
" has uninitialized histogram pointers" << std::endl;
1238 string channel_name = channel.
GetName();
1248 for (
unsigned int idx=0; idx<
fObsNameVec.size(); ++idx ) {
1259 cout <<
"\n\n-------------------\nStarting to process " << channel_name <<
" channel with " <<
fObsNameVec.size() <<
" observables" << endl;
1265 auto proto_config = make_unique<ModelConfig>(
"ModelConfig",
proto);
1266 proto_config->SetWorkspace(*
proto);
1271 cout <<
"will preprocess this line: " << *funcIter <<endl;
1272 proto->factory(funcIter->c_str());
1276 RooArgSet likelihoodTerms(
"likelihoodTerms"), constraintTerms(
"constraintTerms");
1277 vector<string> likelihoodTermNames, constraintTermNames, totSystTermNames, syst_x_expectedPrefixNames, normalizationNames;
1279 vector< pair<string,string> > statNamePairs;
1280 vector< pair<const TH1*, const TH1*> > statHistPairs;
1281 std::string statFuncName;
1282 std::string statNodeName;
1286 string prefix, range;
1291 std::stringstream lumiStr;
1294 proto->factory((
"Lumi"+lumiStr.str()).c_str());
1295 cout <<
"lumi str = " << lumiStr.str() << endl;
1297 std::stringstream lumiErrorStr;
1299 proto->factory((
"Gaussian::lumiConstraint(Lumi,"+lumiErrorStr.str()+
")").c_str());
1300 proto->var(
"nominalLumi")->setConstant();
1301 proto->defineSet(
"globalObservables",
"nominalLumi");
1303 constraintTermNames.push_back(
"lumiConstraint");
1304 cout <<
"lumi Error str = " << lumiErrorStr.str() << endl;
1311 vector<Sample>::iterator it = channel.
GetSamples().begin();
1312 for(; it!=channel.
GetSamples().end(); ++it) {
1316 string overallSystName = sample.
GetName() +
"_" + channel_name +
"_epsilon";
1318 string systSourcePrefix =
"alpha_";
1326 overallSystName =
AddNormFactor(
proto, channel_name, overallSystName, sample, doRatio);
1331 string syst_x_expectedPrefix =
"";
1351 cout << sample.
GetName() +
"_" + channel_name +
" has no variation histograms " << endl;
1352 string expPrefix = sample.
GetName() +
"_" + channel_name;
1353 syst_x_expectedPrefix = sample.
GetName() +
"_" + channel_name +
"_overallSyst_x_Exp";
1361 string constraintPrefix = sample.
GetName() +
"_" + channel_name +
"_Hist_alpha";
1362 syst_x_expectedPrefix = sample.
GetName() +
"_" + channel_name +
"_overallSyst_x_HistSyst";
1367 constraintPrefix, syst_x_expectedPrefix, overallSystName,
1368 constraintTermNames);
1378 std::cout <<
"Cannot include Stat Error for histograms of more than 3 dimensions."
1387 std::cout <<
"Sample: " << sample.
GetName() <<
" to be included in Stat Error "
1388 <<
"for channel " << channel_name
1418 string UncertName = syst_x_expectedPrefix +
"_StatAbsolUncert";
1419 TH1* statErrorHist = NULL;
1423 std::cout <<
"Making Statistical Uncertainty Hist for "
1424 <<
" Channel: " << channel_name
1425 <<
" Sample: " << sample.
GetName()
1436 std::cout <<
"Using external histogram for Stat Errors for "
1437 <<
" Channel: " << channel_name
1438 <<
" Sample: " << sample.
GetName()
1440 std::cout <<
"Error Histogram: " << statErrorHist->
GetName() << std::endl;
1443 statErrorHist->
Multiply( nominal );
1444 statErrorHist->
SetName( UncertName.c_str() );
1449 statHistPairs.push_back( std::make_pair(nominal, statErrorHist) );
1466 statFuncName =
"mc_stat_" + channel_name;
1468 if( paramHist == NULL ) {
1473 std::vector<std::string>::iterator itr =
fObsNameVec.begin();
1474 for (
int idx=0; itr!=
fObsNameVec.end(); ++itr, ++idx ) {
1475 observables.
add( *
proto->var(itr->c_str()) );
1480 std::string ParamSetPrefix =
"gamma_stat_" + channel_name;
1484 ParamSetPrefix.c_str(),
1486 gammaMin, gammaMax);
1488 ParamHistFunc statUncertFunc(statFuncName.c_str(), statFuncName.c_str(),
1489 observables, statFactorParams );
1500 statNodeName = sample.
GetName() +
"_" + channel_name +
"_overallSyst_x_StatUncert";
1503 RooProduct nodeWithMcStat(statNodeName.c_str(), statNodeName.c_str(),
1511 syst_x_expectedPrefix = nodeWithMcStat.
GetName();
1524 std::cout <<
"Cannot include Stat Error for histograms of more than 3 dimensions."
1529 std::cout <<
"Sample: " << sample.
GetName() <<
" in channel: " << channel_name
1530 <<
" to be include a ShapeFactor."
1533 std::vector<ParamHistFunc*> paramHistFuncList;
1534 std::vector<std::string> shapeFactorNameList;
1540 std::string funcName = channel_name +
"_" + shapeFactor.
GetName() +
"_shapeFactor";
1542 if( paramHist == NULL ) {
1545 std::vector<std::string>::iterator itr =
fObsNameVec.begin();
1546 for (
int idx=0; itr!=
fObsNameVec.end(); ++itr, ++idx ) {
1547 observables.
add( *
proto->var(itr->c_str()) );
1551 std::string funcParams =
"gamma_" + shapeFactor.
GetName();
1557 observables, 0, 1000);
1560 ParamHistFunc shapeFactorFunc( funcName.c_str(), funcName.c_str(),
1561 observables, shapeFactorParams );
1566 std::cout <<
"Setting Shape Factor: " << shapeFactor.
GetName()
1567 <<
" to have initial shape from hist: "
1570 shapeFactorFunc.
setShape( initialShape );
1575 std::cout <<
"Setting Shape Factor: " << shapeFactor.
GetName()
1576 <<
" to be constant" << std::endl;
1585 paramHistFuncList.push_back(paramHist);
1586 shapeFactorNameList.push_back(funcName);
1595 std::string shapeFactorNodeName = syst_x_expectedPrefix;
1596 for(
unsigned int i=0; i < shapeFactorNameList.size(); ++i) {
1597 shapeFactorNodeName +=
"_x_" + shapeFactorNameList.at(i);
1602 for(
unsigned int i=0; i < paramHistFuncList.size(); ++i) {
1603 nodesForProduct.
add( *paramHistFuncList.at(i) );
1608 RooProduct nodeWithShapeFactor(shapeFactorNodeName.c_str(),
1609 shapeFactorNodeName.c_str(),
1617 syst_x_expectedPrefix = nodeWithShapeFactor.
GetName();
1630 std::cout <<
"Cannot include Stat Error for histograms of more than 3 dimensions."
1636 std::vector<string> ShapeSysNames;
1651 std::cout <<
"Sample: " << sample.
GetName() <<
" in channel: " << channel_name
1652 <<
" to include a ShapeSys." << std::endl;
1654 std::string funcName = channel_name +
"_" + shapeSys.
GetName() +
"_ShapeSys";
1655 ShapeSysNames.push_back( funcName );
1657 if( paramHist == NULL ) {
1663 std::vector<std::string>::iterator itr =
fObsNameVec.begin();
1665 observables.
add( *
proto->var(itr->c_str()) );
1669 std::string funcParams =
"gamma_" + shapeSys.
GetName();
1672 observables, 0, 10);
1675 ParamHistFunc shapeFactorFunc( funcName.c_str(), funcName.c_str(),
1676 observables, shapeFactorParams );
1699 Double_t minShapeUncertainty = 0.0;
1701 *paramHist, shapeErrorHist,
1703 minShapeUncertainty);
1711 std::string NodeName = syst_x_expectedPrefix;
1714 ShapeSysForNode.
add( *expFunc );
1715 for(
unsigned int i = 0; i < ShapeSysNames.size(); ++i ) {
1716 std::string ShapeSysName = ShapeSysNames.at(i);
1717 ShapeSysForNode.
add( *
proto->function(ShapeSysName.c_str()) );
1718 NodeName = NodeName +
"_x_" + ShapeSysName;
1722 RooProduct nodeWithShapeFactor(NodeName.c_str(), NodeName.c_str(), ShapeSysForNode );
1728 syst_x_expectedPrefix = nodeWithShapeFactor.
GetName();
1737 syst_x_expectedPrefixNames.push_back(syst_x_expectedPrefix);
1743 normalizationNames.push_back(
"Lumi" );
1747 lumiParamString += measurement.
GetLumi();
1749 normalizationNames.push_back(lumiParamString.
Data());
1757 if( statHistPairs.size() > 0 ) {
1762 if( fracStatError == NULL ) {
1763 std::cout <<
"Error: Failed to make ScaledUncertaintyHist for: "
1764 << statNodeName << std::endl;
1771 std::cout <<
"About to create Constraint Terms from: "
1772 << chanStatUncertFunc->
GetName()
1773 <<
" params: " << chanStatUncertFunc->
paramList()
1784 std::cout <<
"Using Gaussian StatErrors in channel: " << channel.
GetName() << std::endl;
1787 std::cout <<
"Using Poisson StatErrors in channel: " << channel.
GetName() << std::endl;
1792 *chanStatUncertFunc, fracStatError,
1794 statRelErrorThreshold);
1798 for (
unsigned int i = 0; i < statHistPairs.size() ; ++i )
1799 delete statHistPairs[i].
second;
1801 statHistPairs.clear();
1803 delete fracStatError;
1813 syst_x_expectedPrefixNames, normalizationNames);
1814 likelihoodTermNames.push_back(channel_name+
"_model");
1818 for(
unsigned int i=0; i<systToFix.size(); ++i){
1826 if(systToFix.at(i)==
"Lumi"){
1827 auxMeas =
proto->var(
"nominalLumi");
1833 const_cast<RooArgSet*
>(
proto->set(
"globalObservables"))->remove(*auxMeas);
1835 cout <<
"could not corresponding auxiliary measurement "
1839 cout <<
"could not find variable " << systToFix.at(i)
1840 <<
" could not set it to constant" << endl;
1846 for(
unsigned int i=0; i<constraintTermNames.size(); ++i){
1847 RooAbsArg* proto_arg = (
proto->arg(constraintTermNames[i].c_str()));
1848 if( proto_arg==NULL ) {
1849 std::cout <<
"Error: Cannot find arg set: " << constraintTermNames.at(i)
1850 <<
" in workspace: " <<
proto->GetName() << std::endl;
1853 constraintTerms.
add( *proto_arg );
1856 for(
unsigned int i=0; i<likelihoodTermNames.size(); ++i){
1857 RooAbsArg* proto_arg = (
proto->arg(likelihoodTermNames[i].c_str()));
1858 if( proto_arg==NULL ) {
1859 std::cout <<
"Error: Cannot find arg set: " << likelihoodTermNames.at(i)
1860 <<
" in workspace: " <<
proto->GetName() << std::endl;
1863 likelihoodTerms.add( *proto_arg );
1865 proto->defineSet(
"constraintTerms",constraintTerms);
1866 proto->defineSet(
"likelihoodTerms",likelihoodTerms);
1871 std::string observablesStr;
1873 std::vector<std::string>::iterator itr =
fObsNameVec.begin();
1875 observables.
add( *
proto->var(itr->c_str()) );
1876 if (!observablesStr.empty()) { observablesStr +=
","; }
1877 observablesStr += *itr;
1888 cout <<
"-----------------------------------------"<<endl;
1889 cout <<
"import model into workspace" << endl;
1891 auto model = make_unique<RooProdPdf>(
1892 (
"model_"+channel_name).c_str(),
1893 "product of Poissons accross bins for a single channel",
1894 constraintTerms,
Conditional(likelihoodTerms,observables));
1897 proto_config->SetPdf(*model);
1898 proto_config->SetObservables(observables);
1899 proto_config->SetGlobalObservables(*
proto->set(
"globalObservables"));
1903 proto->import(*proto_config,proto_config->GetName());
1904 proto->importClassCode();
1909 const char* weightName=
"weightVar";
1919 RooDataSet* asimovDataUnbinned = new RooDataSet("asimovData","",*proto->set("obsAndWeight"),weightName);
1920 for(int i=0; i<asimov_data->numEntries(); ++i){
1921 asimov_data->get(i)->Print("v");
1922 //cout << "GREPME : " << i << " " << data->weight() <<endl;
1923 asimovDataUnbinned->add( *asimov_data->get(i), asimov_data->weight() );
1925 proto->import(*asimovDataUnbinned);
1939 std::cout <<
"Error: Data histogram for channel: " << channel.
GetName()
1940 <<
" is NULL" << std::endl;
1945 auto obsDataUnbinned = make_unique<RooDataSet>(
"obsData",
"",*
proto->set(
"obsAndWeight"),weightName);
1984 proto->import(*obsDataUnbinned);
1991 std::string dataName = data.
GetName();
1994 std::cout <<
"Error: Additional Data histogram for channel: " << channel.
GetName()
1995 <<
" with name: " << dataName <<
" is NULL" << std::endl;
2000 auto obsDataUnbinned = make_unique<RooDataSet>(dataName.c_str(), dataName.c_str(),
2001 *
proto->set(
"obsAndWeight"), weightName);
2039 proto->import(*obsDataUnbinned);
2051 std::vector<std::string> ObsNameVec) {
2057 if (ObsNameVec.empty() ) {
2058 Error(
"ConfigureHistFactoryDataset",
"Invalid input - return");
2068 for (
int i=1; i<=ax->
GetNbins(); ++i) {
2071 proto->var( ObsNameVec[0].c_str() )->setVal( xval );
2073 if(ObsNameVec.size()==1) {
2075 obsDataUnbinned->
add( *
proto->set(
"obsAndWeight"), fval );
2078 for(
int j=1; j<=ay->
GetNbins(); ++j) {
2080 proto->var( ObsNameVec[1].c_str() )->setVal( yval );
2082 if(ObsNameVec.size()==2) {
2084 obsDataUnbinned->
add( *
proto->set(
"obsAndWeight"), fval );
2087 for(
int k=1; k<=az->
GetNbins(); ++k) {
2089 proto->var( ObsNameVec[2].c_str() )->setVal( zval );
2091 obsDataUnbinned->
add( *
proto->set(
"obsAndWeight"), fval );
2104 unsigned int histndim(1);
2105 std::string classname = hist->
ClassName();
2106 if (classname.find(
"TH1")==0) { histndim=1; }
2107 else if (classname.find(
"TH2")==0) { histndim=2; }
2108 else if (classname.find(
"TH3")==0) { histndim=3; }
2110 for (
unsigned int idx=0; idx<histndim; ++idx ) {
2123 if (ch_names.empty() || chs.empty() ) {
2124 Error(
"MakeCombinedModel",
"Input vectors are empty - return a nullptr");
2127 if (chs.size() < ch_names.size() ) {
2128 Error(
"MakeCombinedModel",
"Input vector of workspace has an invalid size - return a nullptr");
2136 map<string, RooAbsPdf*> pdfMap;
2137 vector<RooAbsPdf*> models;
2141 for(
unsigned int i = 0; i< ch_names.size(); ++i){
2145 cout <<
"full list of observables:"<<endl;
2149 for(
unsigned int i = 0; i< ch_names.size(); ++i){
2150 string channel_name=ch_names[i];
2152 if (ss.str().empty()) ss << channel_name ;
2153 else ss <<
',' << channel_name ;
2156 RooAbsPdf* model = ch->
pdf((
"model_"+channel_name).c_str());
2157 if(!model) cout <<
"failed to find model for channel"<<endl;
2159 models.push_back(model);
2160 globalObs.
add(*ch->
set(
"globalObservables"));
2163 pdfMap[channel_name]=model;
2167 cout <<
"\n\n------------------\n Entering combination" << endl;
2178 combined->
import(globalObs);
2179 combined->
defineSet(
"globalObservables",globalObs);
2185 cout <<
"-----------------------------------------"<<endl;
2186 cout <<
"create toy data for " << ss.str() << endl;
2192 combined->
factory(
"weightVar[0,-1e10,1e10]");
2193 obsList.
add(*combined->
var(
"weightVar"));
2214 if( asimov_combined ) {
2215 combined->
import( *asimov_combined,
Rename(
"asimovData"));
2218 std::cout <<
"Error: Failed to create combined asimov dataset" << std::endl;
2221 delete asimov_combined;
2224 if(chs[0]->data(
"obsData") != NULL) {
2225 MergeDataSets(combined, chs, ch_names,
"obsData", obsList, channelCat);
2273 obsList.
add(*channelCat);
2274 combined->
defineSet(
"observables",obsList);
2279 cout <<
"\n\n----------------\n Importing combined model" << endl;
2285 std::map< std::string, double>::iterator param_itr =
fParamValues.begin();
2288 std::string paramName = param_itr->first;
2289 double paramVal = param_itr->second;
2293 temp->
setVal( paramVal );
2294 cout <<
"setting " << paramName <<
" to the value: " << paramVal << endl;
2296 cout <<
"could not find variable " << paramName <<
" could not set its value" << endl;
2300 for(
unsigned int i=0; i<
fSystToFix.size(); ++i){
2305 cout <<
"setting " <<
fSystToFix.at(i) <<
" constant" << endl;
2307 cout <<
"could not find variable " <<
fSystToFix.at(i) <<
" could not set it to constant" << endl;
2315 combined_config->
SetPdf(*simPdf);
2318 combined->
import(*combined_config,combined_config->
GetName());
2323 delete combined_config;
2331 std::vector<RooWorkspace*> wspace_vec,
2332 std::vector<std::string> channel_names,
2333 std::string dataSetName,
2342 for(
unsigned int i = 0; i< channel_names.size(); ++i){
2345 std::cout <<
"Merging data for channel " << channel_names[i].c_str() << std::endl;
2347 if( !obsDataInChannel ) {
2348 std::cout <<
"Error: Can't find DataSet: " << dataSetName
2349 <<
" in channel: " << channel_names.at(i)
2356 obsList,
Index(*channelCat),
2358 Import(channel_names[i].c_str(),*obsDataInChannel));
2360 simData->
append(*tempData);
2371 combined->
import(*simData,
Rename(dataSetName.c_str()));
2376 std::cout <<
"Error: Unable to merge observable datasets" << std::endl;
2395 Int_t binNumber = 0;
2398 for(
Int_t i_bin = 0; i_bin < numBins; ++i_bin) {
2409 if( histError != histError ) {
2410 std::cout <<
"Warning: In histogram " << Nominal->
GetName()
2411 <<
" bin error for bin " << i_bin
2412 <<
" is NAN. Not using Error!!!"
2420 if( histError < 0 ) {
2421 std::cout <<
"Warning: In histogram " << Nominal->
GetName()
2422 <<
" bin error for bin " << binNumber
2423 <<
" is < 0. Setting Error to 0"
2449 unsigned int numHists = HistVec.size();
2451 if( numHists == 0 ) {
2452 std::cout <<
"Warning: Empty Hist Vector, cannot create total uncertainty" << std::endl;
2456 const TH1* HistTemplate = HistVec.at(0).first;
2461 for(
unsigned int i = 0; i < HistVec.size(); ++i ) {
2463 const TH1* nominal = HistVec.at(i).first;
2464 const TH1* error = HistVec.at(i).second;
2467 std::cout <<
"Error: Provided hists have unequal bins" << std::endl;
2471 std::cout <<
"Error: Provided hists have unequal bins" << std::endl;
2476 std::vector<double> TotalBinContent( numBins, 0.0);
2477 std::vector<double> HistErrorsSqr( numBins, 0.0);
2479 Int_t binNumber = 0;
2482 for(
Int_t i_bins = 0; i_bins < numBins; ++i_bins) {
2489 for(
unsigned int i_hist = 0; i_hist < numHists; ++i_hist ) {
2491 const TH1* nominal = HistVec.at(i_hist).first;
2492 const TH1* error = HistVec.at(i_hist).second;
2507 if( histError != histError ) {
2508 std::cout <<
"Warning: In histogram " << error->
GetName()
2509 <<
" bin error for bin " << binNumber
2510 <<
" is NAN. Not using error!!"
2516 TotalBinContent.at(i_bins) += histValue;
2517 HistErrorsSqr.at(i_bins) += histError*histError;
2529 for(
Int_t i = 0; i < numBins; ++i) {
2537 Double_t ErrorsSqr = HistErrorsSqr.at(i);
2538 Double_t TotalVal = TotalBinContent.at(i);
2540 if( TotalVal <= 0 ) {
2541 std::cout <<
"Warning: Sum of histograms for bin: " << binNumber
2542 <<
" is <= 0. Setting error to 0"
2553 if( RelativeError != RelativeError ) {
2554 std::cout <<
"Error: bin " << i <<
" error is NAN" << std::endl;
2555 std::cout <<
" HistErrorsSqr: " << ErrorsSqr
2556 <<
" TotalVal: " << TotalVal
2570 std::cout <<
"Making Total Uncertainty for bin " << binNumber
2571 <<
" Error = " <<
sqrt(ErrorsSqr)
2572 <<
" Val = " << TotalVal
2573 <<
" RelativeError = " << RelativeError
2615 if( numBins != numParams ) {
2616 std::cout <<
"Error: In createStatConstraintTerms, encountered bad number of bins" << std::endl;
2617 std::cout <<
"Given histogram with " << numBins <<
" bins,"
2618 <<
" but require exactly " << numParams << std::endl;
2622 Int_t TH1BinNumber = 0;
2633 std::cout <<
"Creating constraint for: " <<
gamma.GetName()
2634 <<
". Type of constraint: " <<
type << std::endl;
2638 const double sigmaRel = uncertHist->
GetBinContent(TH1BinNumber);
2642 if( sigmaRel <= 0 ){
2643 std::cout <<
"Not creating constraint term for "
2645 <<
" because sigma = " << sigmaRel
2647 <<
" (TH1 bin number = " << TH1BinNumber <<
")"
2654 gamma.setMax( 1 + 5*sigmaRel );
2658 std::string constrName = string(
gamma.GetName()) +
"_constraint";
2659 std::string nomName = string(
"nom_") +
gamma.GetName();
2660 std::string sigmaName = string(
gamma.GetName()) +
"_sigma";
2661 std::string poisMeanName = string(
gamma.GetName()) +
"_poisMean";
2669 RooConstVar constrSigma( sigmaName.c_str(), sigmaName.c_str(), sigmaRel );
2672 RooRealVar constrNom(nomName.c_str(), nomName.c_str(), 1.0,0,10);
2677 constrNom,
gamma, constrSigma );
2683 gamma.setError(sigmaRel);
2686 Double_t tau = 1/sigmaRel/sigmaRel;
2689 RooRealVar constrNom(nomName.c_str(), nomName.c_str(), tau);
2694 std::string scalingName = string(
gamma.GetName()) +
"_tau";
2695 RooConstVar poissonScaling( scalingName.c_str(), scalingName.c_str(), tau);
2703 RooPoisson pois(constrName.c_str(), constrName.c_str(), constrNom, constrMean);
2709 gamma.setError(sigmaRel);
2713 std::cout <<
"Error: Did not recognize Stat Error constraint term type: "
2714 <<
type <<
" for : " << paramHist.
GetName() << std::endl;
2721 if( sigmaRel < minSigma ) {
2722 std::cout <<
"Warning: Bin " << i <<
" = " << sigmaRel
2723 <<
" and is < " << minSigma
2724 <<
". Setting: " <<
gamma.GetName() <<
" to constant"
2729 constraintTermNames.push_back( constrName );
2730 ConstraintTerms.
add( *
proto->pdf(constrName.c_str()) );
2737 if( ! globalSet->
contains(*nomVarInWorkspace) ) {
2738 globalSet->
add( *nomVarInWorkspace );
2743 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...
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
Bool_t contains(const RooAbsArg &var) const
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 R__SUGGEST_ALTERNATIVE("begin()
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 represents a fundamental (non-derived) discrete value object.
virtual Bool_t setLabel(const char *label, Bool_t printError=kTRUE)
Set value by specifying the name of the desired state If printError is set, a message will be printed...
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
RooHistFunc implements a real-valued function sampled from a multidimensional histogram.
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 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.
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)
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)
TH1 * MakeScaledUncertaintyHist(const std::string &Name, std::vector< std::pair< const TH1 *, const TH1 * > > HistVec)
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)
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)
void GuessObsAndNuisance(const RooAbsData &data)
Makes sensible guesses of observables, parameters of interest and nuisance parameters if one or multi...
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.
virtual const char * GetName() const
Returns name of object.
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.
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...
RooCmdArg WeightVar(const char *name, Bool_t reinterpretAsWeight=kFALSE)
RooCmdArg RecycleConflictNodes(Bool_t flag=kTRUE)
RooCmdArg Index(RooCategory &icat)
RooCmdArg Rename(const char *suffix)
RooCmdArg Import(const char *state, TH1 &histo)
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, Bool_t depsAreCond=kFALSE)
Namespace for the RooStats classes.
static constexpr double second
static constexpr double gauss