46 assert(gammas.
size() == relSigmas.size());
48 for (std::size_t i = 0; i < gammas.
size(); ++i) {
50 double sigmaRel = relSigmas[i];
54 gamma.setConstant(
true);
59 gamma.setMax(1. + 5. * sigmaRel);
62 gamma.setError(sigmaRel);
72 gamma.setError(sigmaRel);
76 if (sigmaRel < minSigma) {
78 <<
"Warning: relative sigma " << sigmaRel <<
" for \"" << gamma.GetName() <<
"\" falls below threshold of "
79 << minSigma <<
". Setting: " << gamma.GetName() <<
" to constant" << std::endl;
80 gamma.setConstant(
true);
88 std::span<const double> relSigmas,
double minSigma,
94 if (relSigmas.size() != paramSet.
size()) {
95 std::cout <<
"Error: In createGammaConstraints, encountered bad number of relative sigmas" << std::endl;
96 std::cout <<
"Given vector with " << relSigmas.size() <<
" bins,"
97 <<
" but require exactly " << paramSet.
size() << std::endl;
103 for (std::size_t i = 0; i < paramSet.
size(); ++i) {
108 <<
"Creating constraint for: " << gamma.GetName() <<
". Type of constraint: " << type << std::endl;
110 const double sigmaRel = relSigmas[i];
116 <<
"Not creating constraint term for " << gamma.GetName() <<
" because sigma = " << sigmaRel
118 <<
" (bin number = " << i <<
")" << std::endl;
123 std::string constrName = std::string(gamma.GetName()) +
"_constraint";
124 std::string nomName = std::string(
"nom_") + gamma.GetName();
131 std::string sigmaName = std::string(gamma.GetName()) +
"_sigma";
132 auto constrSigma = std::make_unique<RooConstVar>(sigmaName.c_str(), sigmaName.c_str(), sigmaRel);
135 auto constrNom = std::make_unique<RooRealVar>(nomName.c_str(), nomName.c_str(), 1.0, 0, 10);
136 constrNom->setConstant(
true);
139 auto term = std::make_unique<RooGaussian>(constrName.c_str(), constrName.c_str(), *constrNom, gamma, *constrSigma);
143 term->addOwnedComponents(std::move(constrSigma));
144 term->addOwnedComponents(std::move(constrNom));
150 const double tau = 1. / (sigmaRel * sigmaRel);
153 auto constrNom = std::make_unique<RooRealVar>(nomName.c_str(), nomName.c_str(), tau);
154 constrNom->setMin(0);
155 constrNom->setConstant(
true);
158 std::string scalingName = std::string(gamma.GetName()) +
"_tau";
159 auto poissonScaling = std::make_unique<RooConstVar>(scalingName.c_str(), scalingName.c_str(), tau);
162 std::string poisMeanName = std::string(gamma.GetName()) +
"_poisMean";
163 auto constrMean = std::make_unique<RooProduct>(poisMeanName.c_str(), poisMeanName.c_str(), gamma, *poissonScaling);
166 auto term = std::make_unique<RooPoisson>(constrName.c_str(), constrName.c_str(), *constrNom, *constrMean);
167 term->setNoRounding(
true);
171 term->addOwnedComponents(std::move(poissonScaling));
172 term->addOwnedComponents(std::move(constrMean));
173 term->addOwnedComponents(std::move(constrNom));
178 std::cout <<
"Error: Did not recognize Stat Error constraint term type: " << type
179 <<
" for : " << gamma.GetName() << std::endl;