Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Luigi Dello Stritto committed Oct 30, 2024
1 parent 22f90b1 commit 349c530
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions machine_learning_hep/analysis/analyzerdhadrons_mult.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
# pylint: disable=too-many-lines
# pylint: disable=unused-wildcard-import, wildcard-import
import os
import itertools
from array import array
from pathlib import Path
import numpy as np
import itertools
# pylint: disable=import-error, no-name-in-module, unused-import, consider-using-f-string
from ROOT import TFile, TH1F, TH2F, TCanvas, TPad, TF1, TH1D
from ROOT import TFile, TH1, TH1F, TH2F, TCanvas, TPad, TF1, TH1D
from ROOT import gStyle, TLegend, TLine, TText, TPaveText, TArrow
from ROOT import gROOT, TDirectory, TPaveLabel
from ROOT import TStyle, kBlue, kCyan
Expand All @@ -37,6 +37,7 @@
from machine_learning_hep.hf_pt_spectrum import hf_pt_spectrum
from machine_learning_hep.utils.hist import (get_dim, project_hist)
# pylint: disable=too-few-public-methods, too-many-instance-attributes, too-many-statements, fixme
# pylint: disable=consider-using-enumerate, fixme
class AnalyzerDhadrons_mult(Analyzer): # pylint: disable=invalid-name
species = "analyzer"
def __init__(self, datap, case, typean, period):
Expand Down Expand Up @@ -261,7 +262,7 @@ def _fit_mass(self, hist, filename = None):
return (fit_res, func_sig, func_bkg)


# pylint: disable=too-many-branches,too-many-statements
# pylint: disable=too-many-branches,too-many-statements,too-many-nested-blocks
def fit(self):
self.logger.info("Fitting inclusive mass distributions")
gStyle.SetOptFit(1111)
Expand Down Expand Up @@ -309,7 +310,8 @@ def fit(self):
# Rebin
h_invmass.Rebin(self.p_rebin[ipt])
if h_invmass.GetEntries() < 100: # TODO: reconsider criterion
self.logger.error('Not enough entries to fit for %s, pt bin %d, mult bin %d', level, ipt, ibin2)
self.logger.error('Not enough entries to fit for %s, pt bin %d, mult bin %d', \
level, ipt, ibin2)
continue
ptrange = (self.bins_candpt[ipt], self.bins_candpt[ipt+1])
multrange = (self.lvar2_binmin[ibin2], self.lvar2_binmax[ibin2])
Expand All @@ -318,7 +320,8 @@ def fit(self):
fit_res, _, func_bkg = self._fit_mass(
h_invmass,
f'fit/'
f'h_mass_fitted_pthf-{ptrange[0]}-{ptrange[1]}_{self.v_var2_binning}-{multrange[0]}-{multrange[1]}_{level}.png')
f'h_mass_fitted_pthf-{ptrange[0]}-{ptrange[1]}_\
{self.v_var2_binning}-{multrange[0]}-{multrange[1]}_{level}.png')
if fit_res and fit_res.Get() and fit_res.IsValid():
self.fit_mean[level][ipt] = fit_res.Parameter(1)
self.fit_sigma[level][ipt] = fit_res.Parameter(2)
Expand All @@ -339,7 +342,7 @@ def fit(self):
self.logger.debug("Using fit config for %i: %s", ipt, fitcfg)
if datasel := fitcfg.get('datasel'):
h = rfile.Get(f'h_mass-pthf_{datasel}')
h_invmass = project_hist(h, [0], {1: (ipt+1, ipt+1)}) # TODO: under-/overflow for jets
h_invmass = project_hist(h, [0], {1: (ipt+1, ipt+1)})

for fixpar in fitcfg.get('fix_params', []):
if roows.var(fixpar):
Expand All @@ -354,7 +357,8 @@ def fit(self):
roo_res, roo_ws = self._roofit_mass(
level, h_invmass, ipt, self.p_pdfnames, self.p_param_names, fitcfg, roows,
f'roofit/mult_{multrange[0]}-{multrange[1]}/'
f'h_mass_fitted_pthf-{ptrange[0]}-{ptrange[1]}_{self.v_var2_binning}-{multrange[0]}-{multrange[1]}_{level}.png')
f'h_mass_fitted_pthf-{ptrange[0]}-{ptrange[1]}_\
{self.v_var2_binning}-{multrange[0]}-{multrange[1]}_{level}.png')
# if level == 'mc':
# roo_ws.Print()
self.roo_ws[level][ipt] = roo_ws
Expand Down Expand Up @@ -569,13 +573,8 @@ def plotter(self):
hcrossvsvar2[ipt].SetLineColor(ipt+1)
hcrossvsvar2[ipt].GetXaxis().SetTitle("%s" % self.p_latexbin2var)
hcrossvsvar2[ipt].GetYaxis().SetTitle(self.p_latexnhadron)
binmulrange = self.var2ranges[imult+1]-self.var2ranges[imult]
if self.p_dodoublecross is True:
hcrossvsvar2[ipt].SetBinContent(imult+1, listvalues[imult][ipt]/binmulrange)
hcrossvsvar2[ipt].SetBinError(imult+1, listvalueserr[imult][ipt]/binmulrange)
else:
hcrossvsvar2[ipt].SetBinContent(imult+1, listvalues[imult][ipt])
hcrossvsvar2[ipt].SetBinError(imult+1, listvalueserr[imult][ipt])
hcrossvsvar2[ipt].SetBinContent(imult+1, listvalues[imult][ipt])
hcrossvsvar2[ipt].SetBinError(imult+1, listvalueserr[imult][ipt])

hcrossvsvar2[ipt].GetYaxis().SetRangeUser(1e4, 1e10)
legvsvar2endstring = "%.1f < %s < %.1f GeV/#it{c}" % \
Expand Down

0 comments on commit 349c530

Please sign in to comment.