diff --git a/src/hepstats/hypotests/calculators/frequentist_calculator.py b/src/hepstats/hypotests/calculators/frequentist_calculator.py index a892e6a7..7416829e 100644 --- a/src/hepstats/hypotests/calculators/frequentist_calculator.py +++ b/src/hepstats/hypotests/calculators/frequentist_calculator.py @@ -83,7 +83,7 @@ def qnull( >>> poialt = POI(mean, 1.2) >>> q = calc.qnull(poinull, poialt) """ - toysresults = self.get_toys_null(poinull, poialt, qtilde) + toysresults = self.get_toys_null(poinull, poinull, qtilde) ret = {} for p in poinull: diff --git a/src/hepstats/hypotests/hypotests_object.py b/src/hepstats/hypotests/hypotests_object.py index d922954c..76091683 100644 --- a/src/hepstats/hypotests/hypotests_object.py +++ b/src/hepstats/hypotests/hypotests_object.py @@ -201,7 +201,6 @@ def sampler(self): >>> sampler = calc.sampler() """ - self.set_params_to_bestfit() nevents = [] for m, d in zip(self.loss.model, self.loss.data): nevents_data = get_nevents(d) @@ -251,8 +250,7 @@ def toys_loss(self, parameter_name: str): Example with `zfit`: >>> loss = calc.toys_loss(zfit.Parameter("mean")) """ - if parameter_name not in self._toys_loss: - parameter = self.get_parameter(parameter_name) - sampler = self.sampler() - self._toys_loss[parameter.name] = self.lossbuilder(self.model, sampler) + parameter = self.get_parameter(parameter_name) + sampler = self.sampler() + self._toys_loss[parameter.name] = self.lossbuilder(self.model, sampler) return self._toys_loss[parameter_name] diff --git a/src/hepstats/hypotests/toyutils.py b/src/hepstats/hypotests/toyutils.py index 5ad1fe22..868c2ea7 100644 --- a/src/hepstats/hypotests/toyutils.py +++ b/src/hepstats/hypotests/toyutils.py @@ -232,11 +232,18 @@ def generate_and_fit_toys( # TODO PROFILE THIS poieval: POI values to evaluate the loss function """ - self.set_params_to_bestfit() - minimizer = self.minimizer param = poigen.parameter + # generate toys from best fit at profile point + param.set_value(poigen.value) + is_poi_floating = param.floating + param.floating = False + profile_minimum = minimizer.minimize(loss=self.loss) + if not profile_minimum.valid: + print(poigen, "PROBLEM: profile fit not valid, toys won't be either") + param.floating = is_poi_floating + toys_loss = self.toys_loss(poigen.name) sampler = toys_loss.data