Applying sWeights to mitigate background¶
Sideband subtraction and fit-and-count are great, but they both have their downsides: sideband subtraction can only be used in a few clean cases; fit-and-count takes a while for large binning schemes and can have trouble converging. What if we could have our cake and eat it?
We can instead apply the sPlot method to determine per-event weights which can then be used to remove background. For this, we need to fit again, but only the the global distributions of each category, rather than bin-by-bin.
We start again with some imports:
import matplotlib.pyplot as plt
import mplhep as hep
import numpy as np
import ROOT as R
from triggercalib import HltEff
from triggercalib.utils.helpers import tgraph_to_np
hep.style.use("LHCb2")
R.EnableImplicitMT(8)
Welcome to JupyROOT 6.30/04
The configuration is the same as before as we can use the same observable and PDF here:
model_description = {
"signal" : { # Name of component
"model" : "CrystalBall", # Name of PDF to be used
"params" : { # Parameters to be used
"mu" : [5279.4, 5275, 5285],
"sigma" : [8.75, 6, 12],
"alphal" : [1.4, 1.4, 1.4],
"nl" : [7, 7, 7],
"alphar" : [1.4, 1.4, 1.4],
"nr" : [7, 7, 7],
},
"yield" : [10000, 0, 1000000] # Associated yield
},
"combinatorial" : {
"model": "Exponential",
"params" : {
"exponent" : [-0.001, -0.01, -0.0001]
},
"yield": [1000, 0, 1000000]
}
}
def build_roofit_pdf(ws, model_description):
model_build_string = "SUM::pdf("
for component_name, component_description in model_description.items():
component_build_string = f"{component_description['model']}::{component_name}_pdf(B_DTF_Jpsi_MASS"
for param_name, (param_val, param_min, param_max) in component_description['params'].items():
component_build_string += f", {component_name}_{param_name}[{param_val}, {param_min}, {param_max}]"
component_build_string += ")"
print(f"Constructing '{component_name}_pdf' using description '{component_build_string}'")
ws.factory(component_build_string)
if "yield" in component_description:
yield_val, yield_min, yield_max = component_description["yield"]
model_build_string += f", {component_name}_yield[{yield_val}, {yield_min}, {yield_max}]*{component_name}_pdf"
model_build_string += ")"
print(f"Constructing 'pdf' using description '{model_build_string}'")
pdf = ws.factory(model_build_string)
return ws, pdf
ws = R.RooWorkspace("ws")
observable = ws.factory("B_DTF_Jpsi_MASS[5200, 5500]")
ws, pdf = build_roofit_pdf(ws, model_description)
Constructing 'signal_pdf' using description 'CrystalBall::signal_pdf(B_DTF_Jpsi_MASS, signal_mu[5279.4, 5275, 5285], signal_sigma[8.75, 6, 12], signal_alphal[1.4, 1.4, 1.4], signal_nl[7, 7, 7], signal_alphar[1.4, 1.4, 1.4], signal_nr[7, 7, 7])' Constructing 'combinatorial_pdf' using description 'Exponential::combinatorial_pdf(B_DTF_Jpsi_MASS, combinatorial_exponent[-0.001, -0.01, -0.0001])' Constructing 'pdf' using description 'SUM::pdf(, signal_yield[10000, 0, 1000000]*signal_pdf, combinatorial_yield[1000, 0, 1000000]*combinatorial_pdf)'
We can configure HltEff much the same as in the fit-and-count tutorial, only that this time we need to specify sweights
, which will take as a value the name of the yield of our component of interest, here signal_yield
. We can also ramp up the binning scheme again since we won't need to perform fits in each bin as before:
binning = {
"B_PT" : {
"bins" : [
2e3, 3e3, 4e3, 5e3,
6e3, 7e3, 8e3, 9e3,
10e3, 11e3, 12e3, 13e3,
14e3, 15e3, 16e3, 17e3,
18e3, 19e3, 20e3, 21e3,
22e3, 25e3
]
}
}
hlt_eff = HltEff(
"simple_example",
"root://eoslhcb.cern.ch//eos/lhcb/wg/rta/WP4/TriggerCalib/Bu2JpsiK_Jpsi2MuMu_block1_ntuple.root:Tuple/DecayTree",
tos="Hlt1TrackMVA",
tis=["Hlt1TrackMVA", "Hlt1TwoTrackMVA"],
particle="B",
binning=binning,
observable=observable,
pdf=pdf,
fit_kwargs={
"NumCPU" : 8,
},
output_path="sweights/",
plots=True,
trig_effs=False, # Avoids running fit for 'trig' category (only interested in TOS and TISTOS here)
sweights="signal_yield"
)
================================================ Fit performed with RooFit from ROOT 6.30/04 Initial parameters: combinatorial_exponent: -0.001 +/- 0.0 combinatorial_yield: 1000.0 +/- 0.0 signal_alphal: 1.4 +/- 0.0 signal_alphar: 1.4 +/- 0.0 signal_mu: 5279.4 +/- 0.0 signal_nl: 7.0 +/- 0.0 signal_nr: 7.0 +/- 0.0 signal_sigma: 8.75 +/- 0.0 signal_yield: 10000.0 +/- 0.0 Final parameters: combinatorial_exponent: -0.0019919954378112992 +/- 0.00012431460337454015 combinatorial_yield: 11777.41330996984 +/- 140.4892030150204 signal_alphal: 1.4 +/- 0.0 signal_alphar: 1.4 +/- 0.0 signal_mu: 5279.59863863204 +/- 0.04382781240201439 signal_nl: 7.0 +/- 0.0 signal_nr: 7.0 +/- 0.0 signal_sigma: 8.849793128825226 +/- 0.039710898775308756 signal_yield: 61327.05004362774 +/- 263.22125759115806 Covariance quality: 3 Fit status: 0 Minimum value: -422622.4951147965 ================================================ ================================================ Fit performed with RooFit from ROOT 6.30/04 Initial parameters: combinatorial_exponent: -0.001 +/- 0.0 combinatorial_yield: 1000.0 +/- 0.0 signal_alphal: 1.4 +/- 0.0 signal_alphar: 1.4 +/- 0.0 signal_mu: 5279.4 +/- 0.0 signal_nl: 7.0 +/- 0.0 signal_nr: 7.0 +/- 0.0 signal_sigma: 8.75 +/- 0.0 signal_yield: 10000.0 +/- 0.0 Final parameters: combinatorial_exponent: -0.002421092799213809 +/- 8.153435691750257e-05 combinatorial_yield: 28701.283652222734 +/- 229.08588326945392 signal_alphal: 1.4 +/- 0.0 signal_alphar: 1.4 +/- 0.0 signal_mu: 5279.625592759526 +/- 0.019689331495555962 signal_nl: 7.0 +/- 0.0 signal_nr: 7.0 +/- 0.0 signal_sigma: 8.819019003797916 +/- 0.01737113969559001 signal_yield: 292080.49060211907 +/- 562.0168543642503 Covariance quality: 3 Fit status: 0 Minimum value: -2400432.982109026 ================================================ ================================================ Fit performed with RooFit from ROOT 6.30/04 Initial parameters: combinatorial_exponent: -0.001 +/- 0.0 combinatorial_yield: 1000.0 +/- 0.0 signal_alphal: 1.4 +/- 0.0 signal_alphar: 1.4 +/- 0.0 signal_mu: 5279.4 +/- 0.0 signal_nl: 7.0 +/- 0.0 signal_nr: 7.0 +/- 0.0 signal_sigma: 8.75 +/- 0.0 signal_yield: 10000.0 +/- 0.0 Final parameters: combinatorial_exponent: -0.0020598436881618136 +/- 0.00018983728117589755 combinatorial_yield: 5271.518568160812 +/- 97.05406465981423 signal_alphal: 1.4 +/- 0.0 signal_alphar: 1.4 +/- 0.0 signal_mu: 5279.602176769985 +/- 0.05308299772514147 signal_nl: 7.0 +/- 0.0 signal_nr: 7.0 +/- 0.0 signal_sigma: 8.993093727877318 +/- 0.0473475981913376 signal_yield: 42254.417646482536 +/- 215.40734435071136 Covariance quality: 3 Fit status: 0 Minimum value: -260803.203987964 ================================================ ================================================ Fit performed with RooFit from ROOT 6.30/04 Initial parameters: combinatorial_exponent: -0.001 +/- 0.0 combinatorial_yield: 1000.0 +/- 0.0 signal_alphal: 1.4 +/- 0.0 signal_alphar: 1.4 +/- 0.0 signal_mu: 5279.4 +/- 0.0 signal_nl: 7.0 +/- 0.0 signal_nr: 7.0 +/- 0.0 signal_sigma: 8.75 +/- 0.0 signal_yield: 10000.0 +/- 0.0 Final parameters: combinatorial_exponent: -0.0022865953068676513 +/- 5.3993340383068746e-05 combinatorial_yield: 62854.462159648785 +/- 328.3689290946859 signal_alphal: 1.4 +/- 0.0 signal_alphar: 1.4 +/- 0.0 signal_mu: 5279.59684760958 +/- 0.01608458128202983 signal_nl: 7.0 +/- 0.0 signal_nr: 7.0 +/- 0.0 signal_sigma: 8.690748119708669 +/- 0.014375779916931286 signal_yield: 431772.055636186 +/- 690.4614600895729 Covariance quality: 3 Fit status: 0 Minimum value: -3862425.1034731898 ================================================ [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 383241 out-of-range events [#1] INFO:Eval -- RooAbsTestStatistic::initMPMode: started 8 remote server process. [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization [#1] INFO:Minimization -- RooAbsMinimizerFcn::optimizeConstantTerms: set of constant parameters changed, rerunning const optimizer Minuit2Minimizer: Minimize with max-calls 4500 convergence for edm < 1 strategy 1 [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) Minuit2Minimizer : Valid minimum - status = 0 FVAL = -422622.495114796504 Edm = 0.000818236306727528322 Nfcn = 151 combinatorial_exponent = -0.001992 +/- 0.000124264 (limited) combinatorial_yield = 11777.4 +/- 140.42 (limited) signal_alphal = 1.4 (fixed) signal_alphar = 1.4 (fixed) signal_mu = 5279.6 +/- 0.0438269 (limited) signal_nl = 7 (fixed) signal_nr = 7 (fixed) signal_sigma = 8.84979 +/- 0.0396961 (limited) signal_yield = 61327.1 +/- 263.178 (limited) [#1] INFO:Minimization -- RooAbsMinimizerFcn::optimizeConstantTerms: set of constant parameters changed, rerunning const optimizer [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization [#1] INFO:Plotting -- RooAbsPdf::plotOn(tis_pdf) directly selected PDF components: (signal_pdf) [#1] INFO:Plotting -- RooAbsPdf::plotOn(tis_pdf) indirectly selected PDF components: () [#1] INFO:Plotting -- RooAbsPdf::plotOn(tis_pdf) directly selected PDF components: (combinatorial_pdf) [#1] INFO:Plotting -- RooAbsPdf::plotOn(tis_pdf) indirectly selected PDF components: () [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization [#1] INFO:Minimization -- The following expressions have been identified as constant and will be precalculated and cached: (signal_pdf,combinatorial_pdf) [#1] INFO:Fitting -- RooAbsPdf::fitTo(tis_pdf) Calculating sum-of-weights-squared correction matrix for covariance matrix [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization [#1] INFO:InputArguments -- yield in pdf: signal_yield 61327.5 [#1] INFO:InputArguments -- yield in pdf: combinatorial_yield 11777.5 [#1] INFO:Eval -- Calculating sWeight [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 1136258 out-of-range events [#1] INFO:Eval -- RooAbsTestStatistic::initMPMode: started 8 remote server process. [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization [#1] INFO:Minimization -- RooAbsMinimizerFcn::optimizeConstantTerms: set of constant parameters changed, rerunning const optimizer Minuit2Minimizer: Minimize with max-calls 4500 convergence for edm < 1 strategy 1 [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 1136258 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 1136258 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 1136258 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 1136258 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 1136258 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 1136258 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 1136258 out-of-range events [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 1136258 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) Minuit2Minimizer : Valid minimum - status = 0 FVAL = -2400432.98210902605 Edm = 0.000426890986020935881 Nfcn = 252 combinatorial_exponent = -0.00242109 +/- 8.15269e-05 (limited) combinatorial_yield = 28701.3 +/- 229.057 (limited) signal_alphal = 1.4 (fixed) signal_alphar = 1.4 (fixed) signal_mu = 5279.63 +/- 0.0196885 (limited) signal_nl = 7 (fixed) signal_nr = 7 (fixed) signal_sigma = 8.81902 +/- 0.0173713 (limited) signal_yield = 292080 +/- 561.989 (limited) [#1] INFO:Minimization -- RooAbsMinimizerFcn::optimizeConstantTerms: set of constant parameters changed, rerunning const optimizer [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization [#1] INFO:Plotting -- RooAbsPdf::plotOn(tos_pdf) directly selected PDF components: (signal_pdf) [#1] INFO:Plotting -- RooAbsPdf::plotOn(tos_pdf) indirectly selected PDF components: () [#1] INFO:Plotting -- RooAbsPdf::plotOn(tos_pdf) directly selected PDF components: (combinatorial_pdf) [#1] INFO:Plotting -- RooAbsPdf::plotOn(tos_pdf) indirectly selected PDF components: () [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization [#1] INFO:Minimization -- The following expressions have been identified as constant and will be precalculated and cached: (signal_pdf,combinatorial_pdf) [#1] INFO:Fitting -- RooAbsPdf::fitTo(tos_pdf) Calculating sum-of-weights-squared correction matrix for covariance matrix [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization [#1] INFO:InputArguments -- yield in pdf: signal_yield 292074 [#1] INFO:InputArguments -- yield in pdf: combinatorial_yield 28705.3 [#1] INFO:Eval -- Calculating sWeight [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 198409 out-of-range events [#1] INFO:Eval -- RooAbsTestStatistic::initMPMode: started 8 remote server process. [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization [#1] INFO:Minimization -- RooAbsMinimizerFcn::optimizeConstantTerms: set of constant parameters changed, rerunning const optimizer Minuit2Minimizer: Minimize with max-calls 4500 convergence for edm < 1 strategy 1 [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 198409 out-of-range events [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 198409 out-of-range events [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 198409 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 198409 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 198409 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 198409 out-of-range events [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 198409 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 198409 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) Minuit2Minimizer : Valid minimum - status = 0 FVAL = -260803.203987963992 Edm = 0.000419259833584276805 Nfcn = 136 combinatorial_exponent = -0.00205984 +/- 0.000189753 (limited) combinatorial_yield = 5271.52 +/- 97.003 (limited) signal_alphal = 1.4 (fixed) signal_alphar = 1.4 (fixed) signal_mu = 5279.6 +/- 0.0530823 (limited) signal_nl = 7 (fixed) signal_nr = 7 (fixed) signal_sigma = 8.99309 +/- 0.0473316 (limited) signal_yield = 42254.4 +/- 215.379 (limited) [#1] INFO:Minimization -- RooAbsMinimizerFcn::optimizeConstantTerms: set of constant parameters changed, rerunning const optimizer [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization [#1] INFO:Plotting -- RooAbsPdf::plotOn(tistos_pdf) directly selected PDF components: (signal_pdf) [#1] INFO:Plotting -- RooAbsPdf::plotOn(tistos_pdf) indirectly selected PDF components: () [#1] INFO:Plotting -- RooAbsPdf::plotOn(tistos_pdf) directly selected PDF components: (combinatorial_pdf) [#1] INFO:Plotting -- RooAbsPdf::plotOn(tistos_pdf) indirectly selected PDF components: () [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization [#1] INFO:Minimization -- The following expressions have been identified as constant and will be precalculated and cached: (signal_pdf,combinatorial_pdf) [#1] INFO:Fitting -- RooAbsPdf::fitTo(tistos_pdf) Calculating sum-of-weights-squared correction matrix for covariance matrix [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization [#1] INFO:InputArguments -- yield in pdf: signal_yield 42256.3 [#1] INFO:InputArguments -- yield in pdf: combinatorial_yield 5270.75 [#1] INFO:Eval -- Calculating sWeight [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 2265409 out-of-range events [#1] INFO:Eval -- RooAbsTestStatistic::initMPMode: started 8 remote server process. [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization [#1] INFO:Minimization -- RooAbsMinimizerFcn::optimizeConstantTerms: set of constant parameters changed, rerunning const optimizer Minuit2Minimizer: Minimize with max-calls 4500 convergence for edm < 1 strategy 1 [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 2265409 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 2265409 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 2265409 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 2265409 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 2265409 out-of-range events [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 2265409 out-of-range events [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 2265409 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#0] WARNING:DataHandling -- RooDataSet.from_numpy() Ignored 2265409 out-of-range events [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) Minuit2Minimizer : Valid minimum - status = 0 FVAL = -3862425.10347318975 Edm = 4.68242134326841487e-05 Nfcn = 213 combinatorial_exponent = -0.0022866 +/- 5.39761e-05 (limited) combinatorial_yield = 62854.5 +/- 328.208 (limited) signal_alphal = 1.4 (fixed) signal_alphar = 1.4 (fixed) signal_mu = 5279.6 +/- 0.0160841 (limited) signal_nl = 7 (fixed) signal_nr = 7 (fixed) signal_sigma = 8.69075 +/- 0.0143701 (limited) signal_yield = 431772 +/- 690.352 (limited) [#1] INFO:Minimization -- RooAbsMinimizerFcn::optimizeConstantTerms: set of constant parameters changed, rerunning const optimizer [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- The following expressions will be evaluated in cache-and-track mode: (signal_pdf,combinatorial_pdf) [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization [#1] INFO:Plotting -- RooAbsPdf::plotOn(sel_pdf) directly selected PDF components: (signal_pdf) [#1] INFO:Plotting -- RooAbsPdf::plotOn(sel_pdf) indirectly selected PDF components: () [#1] INFO:Plotting -- RooAbsPdf::plotOn(sel_pdf) directly selected PDF components: (combinatorial_pdf) [#1] INFO:Plotting -- RooAbsPdf::plotOn(sel_pdf) indirectly selected PDF components: () [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization [#1] INFO:Minimization -- The following expressions have been identified as constant and will be precalculated and cached: (signal_pdf,combinatorial_pdf) [#1] INFO:Fitting -- RooAbsPdf::fitTo(sel_pdf) Calculating sum-of-weights-squared correction matrix for covariance matrix [#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization [#1] INFO:InputArguments -- yield in pdf: signal_yield 431776 [#1] INFO:InputArguments -- yield in pdf: combinatorial_yield 62854.6 [#1] INFO:Eval -- Calculating sWeight
Info in <Minuit2>: MnSeedGenerator Computing seed using NumericalGradient calculator Info in <Minuit2>: MnSeedGenerator Initial state: FCN = -345126.8492 Edm = 54410.96487 NCalls = 21 Info in <Minuit2>: MnSeedGenerator Initial state Minimum value : -345126.8492 Edm : 54410.96487 Internal parameters: [ 0.9582415885 -1.507540228 -0.1202898824 -0.08343008661 -1.370461484] Internal gradient : [ -121.4685862 -277979.8916 -474.6758704 -1401.67914 -530450.507] Internal covariance matrix: [[ 0.0030352835 0 0 0 0] [ 0 6.7547956e-07 0 0 0] [ 0 0 0.00014845902 0 0] [ 0 0 0 0.00027765213 0] [ 0 0 0 0 5.8577452e-07]]] Info in <Minuit2>: VariableMetricBuilder Start iterating until Edm is < 0.001 with call limit = 4500 Info in <Minuit2>: VariableMetricBuilder 0 - FCN = -345126.8492 Edm = 54410.96487 NCalls = 21 Info in <Minuit2>: VariableMetricBuilder 1 - FCN = -421829.9626 Edm = 357.1392859 NCalls = 39 Info in <Minuit2>: VariableMetricBuilder 2 - FCN = -422546.5893 Edm = 64.71493714 NCalls = 54 Info in <Minuit2>: VariableMetricBuilder 3 - FCN = -422592.172 Edm = 14.25248205 NCalls = 68 Info in <Minuit2>: VariableMetricBuilder 4 - FCN = -422607.5473 Edm = 4.292058979 NCalls = 80 Info in <Minuit2>: VariableMetricBuilder 5 - FCN = -422620.7069 Edm = 1.151988008 NCalls = 92 Info in <Minuit2>: VariableMetricBuilder 6 - FCN = -422622.317 Edm = 0.1249211629 NCalls = 104 Info in <Minuit2>: VariableMetricBuilder 7 - FCN = -422622.4951 Edm = 0.0007570988581 NCalls = 116 Info in <Minuit2>: VariableMetricBuilder After Hessian Info in <Minuit2>: VariableMetricBuilder 8 - FCN = -422622.4951 Edm = 0.0008182363067 NCalls = 151 Info in <Minuit2>: Minuit2Minimizer::Hesse Using max-calls 4500 Info in <Minuit2>: Minuit2Minimizer::Hesse Hesse is valid - matrix is accurate Info in <TCanvas::Print>: pdf file sweights/plots/tis_plot.pdf has been created Info in <Minuit2>: MnSeedGenerator Computing seed using NumericalGradient calculator Info in <Minuit2>: MnSeedGenerator Initial state: FCN = -1628011.829 Edm = 350757.1573 NCalls = 25 Info in <Minuit2>: MnSeedGenerator Initial state Minimum value : -1628011.829 Edm : 350757.1573 Internal parameters: [ 0.9582415885 -1.507540228 -0.1202898824 -0.08343008661 -1.370461484] Internal gradient : [ 708.0703879 -860309.8797 -2750.964198 -1143.702952 -2811887.165] Internal covariance matrix: [[ 0.0064315794 0 0 0 0] [ 0 3.8498779e-07 0 0 0] [ 0 0 3.1168727e-05 0 0] [ 0 0 0 5.9176903e-05 0] [ 0 0 0 0 1.4096238e-07]]] Info in <Minuit2>: VariableMetricBuilder Start iterating until Edm is < 0.001 with call limit = 4500 Info in <Minuit2>: VariableMetricBuilder 0 - FCN = -1628011.829 Edm = 350757.1573 NCalls = 25 Info in <Minuit2>: VariableMetricBuilder 1 - FCN = -2360918.618 Edm = 13251.12766 NCalls = 48 Info in <Minuit2>: VariableMetricBuilder 2 - FCN = -2382650.032 Edm = 16790.59838 NCalls = 68 Info in <Minuit2>: VariableMetricBuilder 3 - FCN = -2387882.102 Edm = 5528.86368 NCalls = 84 Warning in <Minuit2>: DavidonErrorUpdator delgam < 0 : first derivatives increasing along search line (details in info log) Info in <Minuit2>: DavidonErrorUpdator Explanation: The distance from the minimum cannot be estimated, since the minimized function seems not to be strictly convex in the space probed by the fit. That is expected if the starting parameters are e.g. close to a local maximum of the minimized function. If this function is expected to be fully convex in the probed range or Minuit is already close to the function minimum, this may hint to numerical or analytical issues with the minimized function. This was found by projecting the difference of gradients at two points, s0 and p1, onto the direction given by the difference of s0 and p1, where: * s0: [ 44.13026878 -1.058162882 -0.3332315224 -2.828099364 -0.5460974149] * p1: [ 41.5981186 -1.061196049 -0.1920336478 -2.834987519 -0.5454850142] * gradient at s0: [ 1051.060967 72907.3352 -16636.56234 2584.611499 -62747.08391] * gradient at p1: [ 3139.739659 64569.87693 -9095.819007 989.5376878 -59487.10199] To understand whether this hints to an issue in the minimized function, the minimized function can be plotted along points between s0 and p1 to look for unexpected behavior. Info in <Minuit2>: VariableMetricBuilder 4 - FCN = -2388555.156 Edm = 26329.08259 NCalls = 98 Warning in <Minuit2>: VariableMetricBuilder Matrix not pos.def, gdel = 13595.5 > 0 Warning in <Minuit2>: MnPosDef non-positive diagonal element in covariance matrix[ 0 ] = -0.00131934 Warning in <Minuit2>: MnPosDef Added to diagonal of Error matrix a value 0.501319 Warning in <Minuit2>: VariableMetricBuilder gdel = -3.91106e+09 Warning in <Minuit2>: VariableMetricBuilder No improvement in line search Info in <Minuit2>: VariableMetricBuilder 5 - FCN = -2388555.156 Edm = 26329.08259 NCalls = 109 Warning in <Minuit2>: VariableMetricBuilder Iterations finish without convergence; Edm 251889 Requested 0.001 Info in <Minuit2>: VariableMetricBuilder After Hessian Info in <Minuit2>: VariableMetricBuilder 6 - FCN = -2388555.156 Edm = 42970.88685 NCalls = 140 Info in <Minuit2>: VariableMetricBuilder Tolerance not sufficient, continue minimization; Edm 42970.9 Required 0.001 Info in <Minuit2>: VariableMetricBuilder 7 - FCN = -2398549.26 Edm = 2112.454866 NCalls = 154 Info in <Minuit2>: VariableMetricBuilder 8 - FCN = -2400261.728 Edm = 349.7313646 NCalls = 167 Info in <Minuit2>: VariableMetricBuilder 9 - FCN = -2400338.878 Edm = 182.6454132 NCalls = 181 Info in <Minuit2>: VariableMetricBuilder 10 - FCN = -2400426.584 Edm = 6.585989422 NCalls = 194 Info in <Minuit2>: VariableMetricBuilder 11 - FCN = -2400432.859 Edm = 0.1190194961 NCalls = 206 Info in <Minuit2>: VariableMetricBuilder 12 - FCN = -2400432.982 Edm = 0.0005035746925 NCalls = 217 Info in <Minuit2>: VariableMetricBuilder After Hessian Info in <Minuit2>: VariableMetricBuilder 13 - FCN = -2400432.982 Edm = 0.000426890986 NCalls = 252 Info in <Minuit2>: Minuit2Minimizer::Hesse Using max-calls 4500 Info in <Minuit2>: Minuit2Minimizer::Hesse Hesse is valid - matrix is accurate Info in <TCanvas::Print>: pdf file sweights/plots/tos_plot.pdf has been created Info in <Minuit2>: MnSeedGenerator Computing seed using NumericalGradient calculator Info in <Minuit2>: MnSeedGenerator Initial state: FCN = -227672.2543 Edm = 26480.8762 NCalls = 21 Info in <Minuit2>: MnSeedGenerator Initial state Minimum value : -227672.2543 Edm : 26480.8762 Internal parameters: [ 0.9582415885 -1.507540228 -0.1202898824 -0.08343008661 -1.370461484] Internal gradient : [ 42.95100047 -123164.5287 -352.2713879 -644.7526329 -324676.3268] Internal covariance matrix: [[ 0.01151718 0 0 0 0] [ 0 1.3548469e-06 0 0 0] [ 0 0 0.00021840014 0 0] [ 0 0 0 0.00039949126 0] [ 0 0 0 0 8.0782584e-07]]] Info in <Minuit2>: VariableMetricBuilder Start iterating until Edm is < 0.001 with call limit = 4500 Info in <Minuit2>: VariableMetricBuilder 0 - FCN = -227672.2543 Edm = 26480.8762 NCalls = 21 Info in <Minuit2>: VariableMetricBuilder 1 - FCN = -260093.5752 Edm = 456.9122084 NCalls = 41 Info in <Minuit2>: VariableMetricBuilder 2 - FCN = -260345.361 Edm = 550.5579162 NCalls = 55 Info in <Minuit2>: VariableMetricBuilder 3 - FCN = -260671.2753 Edm = 62.69973081 NCalls = 67 Info in <Minuit2>: VariableMetricBuilder 4 - FCN = -260801.9902 Edm = 0.8783016907 NCalls = 79 Info in <Minuit2>: VariableMetricBuilder 5 - FCN = -260803.1046 Edm = 0.07343889071 NCalls = 91 Info in <Minuit2>: VariableMetricBuilder 6 - FCN = -260803.204 Edm = 0.0004126222935 NCalls = 103 Info in <Minuit2>: VariableMetricBuilder After Hessian Info in <Minuit2>: VariableMetricBuilder 7 - FCN = -260803.204 Edm = 0.0004192598336 NCalls = 136 Info in <Minuit2>: Minuit2Minimizer::Hesse Using max-calls 4500 Info in <Minuit2>: Minuit2Minimizer::Hesse Hesse is valid - matrix is accurate Info in <TCanvas::Print>: pdf file sweights/plots/tistos_plot.pdf has been created Info in <Minuit2>: MnSeedGenerator Computing seed using NumericalGradient calculator Info in <Minuit2>: MnSeedGenerator Initial state: FCN = -2461466.085 Edm = 552083.0566 NCalls = 25 Info in <Minuit2>: MnSeedGenerator Initial state Minimum value : -2461466.085 Edm : 552083.0566 Internal parameters: [ 0.9582415885 -1.507540228 -0.1202898824 -0.08343008661 -1.370461484] Internal gradient : [ 191.370879 -1704163.264 -3404.894391 -3535.448316 -4276499.714] Internal covariance matrix: [[ 0.00083543233 0 0 0 0] [ 0 1.5914505e-07 0 0 0] [ 0 0 2.0815314e-05 0 0] [ 0 0 0 4.0451628e-05 0] [ 0 0 0 0 9.5435646e-08]]] Info in <Minuit2>: VariableMetricBuilder Start iterating until Edm is < 0.001 with call limit = 4500 Info in <Minuit2>: VariableMetricBuilder 0 - FCN = -2461466.085 Edm = 552083.0566 NCalls = 25 Info in <Minuit2>: VariableMetricBuilder 1 - FCN = -3829992.405 Edm = 11145.73175 NCalls = 50 Info in <Minuit2>: VariableMetricBuilder 2 - FCN = -3835262.499 Edm = 10367.41179 NCalls = 69 Info in <Minuit2>: VariableMetricBuilder 3 - FCN = -3842728.146 Edm = 892.869915 NCalls = 82 Info in <Minuit2>: VariableMetricBuilder 4 - FCN = -3846364.338 Edm = 2321.715969 NCalls = 99 Info in <Minuit2>: VariableMetricBuilder 5 - FCN = -3856982.012 Edm = 884.1235867 NCalls = 113 Info in <Minuit2>: VariableMetricBuilder 6 - FCN = -3859344.941 Edm = 1006.850032 NCalls = 125 Info in <Minuit2>: VariableMetricBuilder 7 - FCN = -3862358.079 Edm = 67.5693934 NCalls = 137 Info in <Minuit2>: VariableMetricBuilder 8 - FCN = -3862424.913 Edm = 0.1636460912 NCalls = 149 Info in <Minuit2>: VariableMetricBuilder 9 - FCN = -3862425.095 Edm = 0.006832541899 NCalls = 161 Info in <Minuit2>: VariableMetricBuilder 10 - FCN = -3862425.103 Edm = 5.392632468e-05 NCalls = 174 Info in <Minuit2>: VariableMetricBuilder After Hessian Info in <Minuit2>: VariableMetricBuilder 11 - FCN = -3862425.103 Edm = 4.682421343e-05 NCalls = 213 Info in <Minuit2>: Minuit2Minimizer::Hesse Using max-calls 4500 Info in <Minuit2>: Minuit2Minimizer::Hesse Hesse is valid - matrix is accurate Info in <TCanvas::Print>: pdf file sweights/plots/sel_plot.pdf has been created
There we have it, efficiencies ready to plot:
hist = hlt_eff.get_eff("tos_efficiency_B_PT")
midpoints, values, xerrors, yerrors = tgraph_to_np(hist, xscale=1e-3)
xmin = midpoints[0] - xerrors[0][0]
xmax = midpoints[-1] + xerrors[1][-1]
# Plot the efficiency #
plt.figure(figsize=(12,10))
plt.gca()
plt.plot((xmin, xmax), (1,1), color='k', ls='dashed', lw=2)
plt.errorbar(
x=midpoints, y=values, xerr=xerrors, yerr=yerrors,
color='r', elinewidth=2, ls="none", marker='.', markersize=8,
)
plt.xlim(xmin, xmax)
plt.xlabel(r"Transverse momentum, $p_T\left(B^+\right)$ / $\mathrm{GeV}c^{-1}$")
plt.ylim(0, 1.1)
plt.ylabel(r"TOS efficiency, $\varepsilon_\mathrm{TOS}$")
hep.lhcb.label(loc=0, rlabel=r"$B^+\to J/\psi\left(\mu\mu\right)K^+$ 2024 MC")
plt.savefig("tos_efficiencies.pdf")
plt.show()
Now you might be thinking, what's the catch? Well this method only works if your discriminant variable (the variable of the fit) and control variable(s) (the variable(s) of the histogram) are independent.