diff --git a/roofit/histfactory/inc/RooStats/HistFactory/Detail/HistFactoryImpl.h b/roofit/histfactory/inc/RooStats/HistFactory/Detail/HistFactoryImpl.h index 02e0846e76dda..744726f506972 100644 --- a/roofit/histfactory/inc/RooStats/HistFactory/Detail/HistFactoryImpl.h +++ b/roofit/histfactory/inc/RooStats/HistFactory/Detail/HistFactoryImpl.h @@ -13,15 +13,24 @@ #ifndef HistFactoryImplHelpers_h #define HistFactoryImplHelpers_h -#include - #include #include #include -namespace RooStats { -namespace HistFactory { +namespace RooStats::HistFactory { + +namespace Constraint { + +enum Type { + Gaussian, + Poisson +}; +std::string Name(Type type); +Type GetType(const std::string &Name); + +} // namespace Constraint + namespace Detail { namespace MagicConstants { @@ -49,15 +58,13 @@ void configureConstrainedGammas(RooArgList const &gammas, std::span> constraints; - std::vector globalObservables; + std::vector globalObservables; }; -CreateGammaConstraintsOutput createGammaConstraints(RooArgList const ¶mList, - std::span relSigmas, double minSigma, - Constraint::Type type); +CreateGammaConstraintsOutput createGammaConstraints(RooArgList const ¶mList, std::span relSigmas, + double minSigma, Constraint::Type type); } // namespace Detail -} // namespace HistFactory -} // namespace RooStats +} // namespace RooStats::HistFactory #endif diff --git a/roofit/histfactory/inc/RooStats/HistFactory/Measurement.h b/roofit/histfactory/inc/RooStats/HistFactory/Measurement.h index 8c8cf30dc0bd8..1389c5615f6ef 100644 --- a/roofit/histfactory/inc/RooStats/HistFactory/Measurement.h +++ b/roofit/histfactory/inc/RooStats/HistFactory/Measurement.h @@ -13,6 +13,8 @@ #include +#include + #include #include #include @@ -27,17 +29,6 @@ class RooWorkspace; namespace RooStats::HistFactory { -namespace Constraint { - -enum Type { - Gaussian, - Poisson -}; -std::string Name(Type type); -Type GetType(const std::string &Name); - -} // namespace Constraint - /** \class OverallSys * \ingroup HistFactory * Configuration for a constrained overall systematic to scale sample normalisations. @@ -257,12 +248,24 @@ class ShapeFactor : public HistogramUncertaintyBase { } const std::string &GetHistoPath() const { return fHistoPathHigh; } + double GetVal() const { return fValue; } + + double GetMin() const { return fMinVal; } + double GetMax() const { return fMaxVal; } + + void SetVal(double value) { fValue = value; } + + void SetMin(double minVal) { fMinVal = minVal; } + void SetMax(double maxVal) { fMaxVal = maxVal; } + protected: bool fConstant = false; - - // A histogram representing - // the initial shape bool fHasInitialShape = false; + double fValue = 1.0; + // GHL: Again, we are putting hard ranges on the gammas by default. + // We should change this to range from 0 to /inf. + double fMinVal = Detail::MagicConstants::defaultGammaMin; + double fMaxVal = Detail::MagicConstants::defaultShapeFactorGammaMax; }; /** \class StatError @@ -484,6 +487,7 @@ class Sample { void AddHistoFactor(const HistoFactor &Factor); void AddShapeFactor(std::string Name); + void AddShapeFactor(std::string Name, double initialVal, double minVal, double maxVal); void AddShapeFactor(const ShapeFactor &Factor); void AddShapeSys(std::string Name, Constraint::Type ConstraintType, std::string HistoName, std::string HistoFile, diff --git a/roofit/histfactory/src/ConfigParser.cxx b/roofit/histfactory/src/ConfigParser.cxx index 54a937b8cae15..b4776a4fbe748 100644 --- a/roofit/histfactory/src/ConfigParser.cxx +++ b/roofit/histfactory/src/ConfigParser.cxx @@ -1253,6 +1253,15 @@ HistFactory::ShapeFactor ConfigParser::MakeShapeFactor( TXMLNode* node ) { else if( attrName == TString( "Name" ) ) { shapeFactor.SetName( attrVal ); } + else if( attrName == TString( "Val" ) ) { + shapeFactor.SetVal( toDouble(attrVal) ); + } + else if( attrName == TString( "Min" ) ) { + shapeFactor.SetMin( toDouble(attrVal) ); + } + else if( attrName == TString( "Max" ) ) { + shapeFactor.SetMax( toDouble(attrVal) ); + } else if( attrName == TString( "Const" ) ) { shapeFactor.SetConstant( CheckTrueFalse(attrVal, "ShapeFactor" ) ); } diff --git a/roofit/histfactory/src/HistoToWorkspaceFactoryFast.cxx b/roofit/histfactory/src/HistoToWorkspaceFactoryFast.cxx index a1b72e95f6c90..6268188ddde24 100644 --- a/roofit/histfactory/src/HistoToWorkspaceFactoryFast.cxx +++ b/roofit/histfactory/src/HistoToWorkspaceFactoryFast.cxx @@ -1032,13 +1032,18 @@ RooArgList HistoToWorkspaceFactoryFast::createObservables(const TH1 *hist, RooWo } // Create the Parameters - std::string funcParams = "gamma_" + shapeFactor.GetName(); - - // GHL: Again, we are putting hard ranges on the gamma's - // We should change this to range from 0 to /inf RooArgList shapeFactorParams = ParamHistFunc::createParamSet(proto, - funcParams, - theObservables, defaultGammaMin, defaultShapeFactorGammaMax); + "gamma_" + shapeFactor.GetName(), + theObservables); + for (auto *comp : shapeFactorParams) { + // If the gamma is subject to a preprocess function, it is a RooAbsReal and + // we don't need to set the initial value. + if(auto var = dynamic_cast(comp)) { + var->setVal(shapeFactor.GetVal()); + var->setMin(shapeFactor.GetMin()); + var->setMax(shapeFactor.GetMax()); + } + } // Create the Function ParamHistFunc shapeFactorFunc( funcName.c_str(), funcName.c_str(), diff --git a/roofit/histfactory/src/Measurement.cxx b/roofit/histfactory/src/Measurement.cxx index bc7b84e43e673..6fc74fba160b7 100644 --- a/roofit/histfactory/src/Measurement.cxx +++ b/roofit/histfactory/src/Measurement.cxx @@ -994,9 +994,18 @@ void Sample::AddHistoFactor(const HistoFactor &Factor) void Sample::AddShapeFactor(std::string SysName) { - ShapeFactor factor; - factor.SetName(SysName); - fShapeFactorList.push_back(factor); + fShapeFactorList.emplace_back(); + fShapeFactorList.back().SetName(SysName); +} + +void Sample::AddShapeFactor(std::string SysName, double value, double minVal, double maxVal) +{ + + fShapeFactorList.emplace_back(); + fShapeFactorList.back().SetName(SysName); + fShapeFactorList.back().SetVal(value); + fShapeFactorList.back().SetMin(minVal); + fShapeFactorList.back().SetMax(maxVal); } void Sample::AddShapeFactor(const ShapeFactor &Factor) @@ -1904,6 +1913,8 @@ void ShapeFactor::Print(std::ostream &stream) const << " Shape Hist Name: " << fHistoNameHigh << " Shape Hist Path Name: " << fHistoPathHigh << " Shape Hist FileName: " << fInputFileHigh << std::endl; } + // Print value and range in RooRealVar style + stream << "\t \t Value: " << GetVal() << " L(" << GetMin() << " - " << GetMax() << ")\n"; if (fConstant) { stream << "\t \t ( Constant ): " << std::endl; @@ -1937,6 +1948,9 @@ void ShapeFactor::PrintXML(std::ostream &xml) const << " HistoName=\"" << GetHistoName() << "\" " << " HistoPath=\"" << GetHistoPath() << "\" "; } + xml << " Value=\"" << GetVal() << "\" " + << " Min=\"" << GetMin() << "\" " + << " Max=\"" << GetMax() << "\" "; xml << " /> " << std::endl; }