19iparB = np.array([0, 2], dtype=np.int32)
36 def __init__(self, f1, f2):
40 def __call__(self, par):
45 par_arr = np.frombuffer(par, dtype=np.float64, count=6)
50 return self._f1(p1) + self._f2(p2)
53hB = ROOT.TH1D(
"hB",
"histo B", 100, 0, 100)
54hSB = ROOT.TH1D(
"hSB",
"histo S+B", 100, 0, 100)
56fB = ROOT.TF1(
"fB",
"expo", 0, 100)
57fB.SetParameters(1, -0.05)
60fS = ROOT.TF1(
"fS",
"gaus", 0, 100)
61fS.SetParameters(1, 30, 5)
63hSB.FillRandom(
"fB", 2000)
64hSB.FillRandom(
"fS", 1000)
68fSB = ROOT.TF1(
"fSB",
"expo + gaus(2)", 0, 100)
76rangeB.SetRange(10, 90)
81rangeSB.SetRange(10, 50)
88globalChi2 = GlobalChi2(chi2_B, chi2_SB)
93par0 = np.array([5, 5, -0.1, 100, 30, 10])
96fitter.Config().SetParamsSettings(6, par0)
98fitter.Config().ParSettings(4).Fix()
100fitter.Config().ParSettings(2).SetLimits(-10, -1.0e-4)
101fitter.Config().ParSettings(3).SetLimits(0, 10000)
102fitter.Config().ParSettings(3).SetStepSize(5)
104fitter.Config().MinimizerOptions().SetPrintLevel(0)
105fitter.Config().SetMinimizer(
"Minuit2",
"Migrad")
113fitter.FitFCN(globalChi2Functor, 0, dataB.Size() + dataSB.Size(),
True)
114result = fitter.Result()
115result.Print(ROOT.std.cout)
117c1 = ROOT.TCanvas(
"Simfit",
"Simultaneous fit of two histograms", 10, 10, 700, 700)
120ROOT.gStyle.SetOptFit(1111)
122fB.SetFitResult(result, iparB)
123fB.SetRange(rangeB().first, rangeB().second)
124fB.SetLineColor(ROOT.kBlue)
125hB.GetListOfFunctions().
Add(fB)
129fSB.SetFitResult(result, iparSB)
130fSB.SetRange(rangeSB().first, rangeSB().second)
131fSB.SetLineColor(ROOT.kRed)
132hSB.GetListOfFunctions().
Add(fSB)
135c1.SaveAs(
"combinedFit.png")
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
Chi2FCN class for binned fits using the least square methods.
class describing the range in the coordinates it supports multiple range in a coordinate.
Fitter class, entry point for performing all type of fits.
Documentation for class Functor class.
Class to Wrap a ROOT Function class (like TF1) in a IParamMultiFunction interface of multi-dimensions...
void FillData(BinData &dv, const TH1 *hist, TF1 *func=nullptr)
fill the data vector from a TH1.
TMatrixT< Element > & Add(TMatrixT< Element > &target, Element scalar, const TMatrixT< Element > &source)
Modify addition: target += scalar * source.
DataOptions : simple structure holding the options on how the data are filled.