Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@
#ifndef HistFactoryImplHelpers_h
#define HistFactoryImplHelpers_h

#include <RooStats/HistFactory/Measurement.h>

#include <RooGlobalFunc.h>
#include <RooWorkspace.h>

#include <ROOT/RSpan.hxx>

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 {
Expand Down Expand Up @@ -49,15 +58,13 @@ void configureConstrainedGammas(RooArgList const &gammas, std::span<const double

struct CreateGammaConstraintsOutput {
std::vector<std::unique_ptr<RooAbsPdf>> constraints;
std::vector<RooRealVar*> globalObservables;
std::vector<RooRealVar *> globalObservables;
};

CreateGammaConstraintsOutput createGammaConstraints(RooArgList const &paramList,
std::span<const double> relSigmas, double minSigma,
Constraint::Type type);
CreateGammaConstraintsOutput createGammaConstraints(RooArgList const &paramList, std::span<const double> relSigmas,
double minSigma, Constraint::Type type);

} // namespace Detail
} // namespace HistFactory
} // namespace RooStats
} // namespace RooStats::HistFactory

#endif
32 changes: 18 additions & 14 deletions roofit/histfactory/inc/RooStats/HistFactory/Measurement.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include <TNamed.h>

#include <RooStats/HistFactory/Detail/HistFactoryImpl.h>

#include <fstream>
#include <iostream>
#include <map>
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions roofit/histfactory/src/ConfigParser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
}
Expand Down
17 changes: 11 additions & 6 deletions roofit/histfactory/src/HistoToWorkspaceFactoryFast.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<RooRealVar*>(comp)) {
var->setVal(shapeFactor.GetVal());
var->setMin(shapeFactor.GetMin());
var->setMax(shapeFactor.GetMax());
}
}

// Create the Function
ParamHistFunc shapeFactorFunc( funcName.c_str(), funcName.c_str(),
Expand Down
20 changes: 17 additions & 3 deletions roofit/histfactory/src/Measurement.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Loading