231 |
|
Legend.SetFillStyle(0) |
232 |
|
|
233 |
|
|
234 |
– |
# outputFile.cd(pathToDir) |
235 |
– |
|
234 |
|
fittingIntegral = 0 |
235 |
|
scaleFactor = 1 |
236 |
|
|
367 |
|
sumOfWeights = 0.0 |
368 |
|
|
369 |
|
for i in range (0, len (HistogramsToFit)): |
370 |
< |
weight = 1.0 / (HistogramsToFit[i].GetBinError (xBin) * HistogramsToFit[i].GetBinError (xBin)) |
371 |
< |
sumOfWeights += weight |
372 |
< |
value += weight * par[i] * HistogramsToFit[i].GetBinContent (xBin) |
373 |
< |
value /= sumOfWeights |
370 |
> |
error = HistogramsToFit[i].GetBinError (xBin) |
371 |
> |
if error != 0.0: |
372 |
> |
weight = 1.0 / (error * error) |
373 |
> |
sumOfWeights += weight |
374 |
> |
value += weight * par[i] * HistogramsToFit[i].GetBinContent (xBin) |
375 |
> |
if sumOfWeights != 0.0: |
376 |
> |
value /= sumOfWeights |
377 |
> |
|
378 |
> |
return value |
379 |
> |
|
380 |
> |
|
381 |
> |
def fitf (x, par): |
382 |
> |
xBin = HistogramsToFit[0].FindBin (x[0]) |
383 |
> |
value = 0.0 |
384 |
> |
|
385 |
> |
for i in range (0, len (HistogramsToFit)): |
386 |
> |
value += par[i] * HistogramsToFit[i].GetBinContent (xBin) |
387 |
|
|
388 |
|
return value |
389 |
|
|
390 |
+ |
|
391 |
|
lowerLimit = Target.GetBinLowEdge (1) |
392 |
|
upperLimit = Target.GetBinLowEdge (Target.GetNbinsX ()) + Target.GetBinWidth (Target.GetNbinsX ()) |
393 |
|
if 'lowerLimit' in distribution: |
397 |
|
func = TF1 ("fit", fitf, lowerLimit, upperLimit, len (HistogramsToFit)) |
398 |
|
|
399 |
|
for i in range (0, len (HistogramsToFit)): |
400 |
< |
func.SetParameter (i, 1.0) |
400 |
> |
if 'fixed_datasets' in distribution and distribution['datasets'][i] in distribution['fixed_datasets']: |
401 |
> |
func.FixParameter (i, 1.0) |
402 |
> |
else: |
403 |
> |
func.SetParameter (i, 1.0) |
404 |
|
func.SetParName (i, labels[FittingHistogramDatasets[i]]) |
405 |
|
|
406 |
|
for i in range (0, distribution['iterations'] - 1): |
466 |
|
|
467 |
|
if i == 1: |
468 |
|
ratios = [] |
469 |
+ |
errors = [] |
470 |
|
for j in range (0, len (HistogramsToFit)): |
471 |
|
HistogramsToFit[j].Scale (func.GetParameter (j)) |
472 |
|
ratios.append(func.GetParameter (j)) |
473 |
< |
|
473 |
> |
errors.append(func.GetParError(j)) |
474 |
> |
|
475 |
|
for fittingHist in HistogramsToFit: |
476 |
|
if not arguments.noStack: |
477 |
|
Stack_list[i].Add(fittingHist) |
625 |
|
YieldsLabel.AddText ("MC yield: " + '%.1f' % mcYield) |
626 |
|
if i == 1: |
627 |
|
for j in range(0,len(FittingLegendEntries)): |
628 |
< |
RatiosLabel.AddText (FittingLegendEntries[j]+" ratio: " + '%.2f' % ratios[j]) |
628 |
> |
RatiosLabel.AddText (FittingLegendEntries[j]+" ratio: " + '%.2f' % ratios[j] + ' #pm %.2f' % errors[j]) |
629 |
|
YieldsLabel.Draw() |
630 |
|
RatiosLabel.Draw() |
631 |
|
|