48 assert(gammas.
size() == relSigmas.size());
50 for (std::size_t i = 0; i < gammas.
size(); ++i) {
51 auto *gammaVar =
dynamic_cast<RooRealVar *
>(gammas.
at(i));
55 auto &gamma = *gammaVar;
56 double sigmaRel = relSigmas[i];
60 gamma.setConstant(
true);
65 gamma.setMax(1. + 5. * sigmaRel);
68 gamma.setError(sigmaRel);
78 gamma.setError(sigmaRel);
82 if (sigmaRel < minSigma) {
84 <<
"Warning: relative sigma " << sigmaRel <<
" for \"" << gamma.GetName() <<
"\" falls below threshold of "
85 << minSigma <<
". Setting: " << gamma.GetName() <<
" to constant" << std::endl;
86 gamma.setConstant(
true);
94 std::span<const double> relSigmas,
double minSigma,
100 if (relSigmas.size() != paramSet.
size()) {
101 std::cout <<
"Error: In createGammaConstraints, encountered bad number of relative sigmas" << std::endl;
102 std::cout <<
"Given vector with " << relSigmas.size() <<
" bins,"
103 <<
" but require exactly " << paramSet.
size() << std::endl;
109 for (std::size_t i = 0; i < paramSet.
size(); ++i) {
112 auto &gamma =
static_cast<RooAbsReal &
>(paramSet[i]);
115 <<
"Creating constraint for: " << gamma.GetName() <<
". Type of constraint: " <<
type << std::endl;
117 const double sigmaRel = relSigmas[i];
123 <<
"Not creating constraint term for " << gamma.GetName() <<
" because sigma = " << sigmaRel
125 <<
" (bin number = " << i <<
")" << std::endl;
130 std::string constrName = std::string(gamma.GetName()) +
"_constraint";
131 std::string nomName = std::string(
"nom_") + gamma.GetName();
138 std::string sigmaName = std::string(gamma.GetName()) +
"_sigma";
139 auto constrSigma = std::make_unique<RooConstVar>(sigmaName.c_str(), sigmaName.c_str(), sigmaRel);
142 auto constrNom = std::make_unique<RooRealVar>(nomName.c_str(), nomName.c_str(), 1.0, 0, 10);
143 constrNom->setConstant(
true);
146 auto term = std::make_unique<RooGaussian>(constrName.c_str(), constrName.c_str(), *constrNom, gamma, *constrSigma);
150 term->addOwnedComponents(std::move(constrSigma));
151 term->addOwnedComponents(std::move(constrNom));
157 const double tau = 1. / (sigmaRel * sigmaRel);
160 auto constrNom = std::make_unique<RooRealVar>(nomName.c_str(), nomName.c_str(), tau);
161 constrNom->setMin(0);
162 constrNom->setConstant(
true);
165 std::string scalingName = std::string(gamma.GetName()) +
"_tau";
166 auto poissonScaling = std::make_unique<RooConstVar>(scalingName.c_str(), scalingName.c_str(), tau);
169 std::string poisMeanName = std::string(gamma.GetName()) +
"_poisMean";
170 auto constrMean = std::make_unique<RooProduct>(poisMeanName.c_str(), poisMeanName.c_str(), gamma, *poissonScaling);
173 auto term = std::make_unique<RooPoisson>(constrName.c_str(), constrName.c_str(), *constrNom, *constrMean);
174 term->setNoRounding(
true);
178 term->addOwnedComponents(std::move(poissonScaling));
179 term->addOwnedComponents(std::move(constrMean));
180 term->addOwnedComponents(std::move(constrNom));
185 std::cout <<
"Error: Did not recognize Stat Error constraint term type: " <<
type
186 <<
" for : " << gamma.GetName() << std::endl;