Skip to content

Commit f3a37a5

Browse files
author
Luigi Dello Stritto
committed
Updated DBs and analizer
1 parent e121fd6 commit f3a37a5

File tree

8 files changed

+1522
-276
lines changed

8 files changed

+1522
-276
lines changed

machine_learning_hep/analysis/analyzerdhadrons.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def fit(self):
304304
self.lpt_finbinmax[ipt],
305305
lpt_probcutfin[ipt],
306306
)
307-
h_invmass = rfile.Get("hmass" + suffix)
307+
h_invmass = rfile.Get("hmass_" + suffix)
308308
# Rebin
309309
h_invmass.Rebin(self.p_rebin[ipt])
310310
if h_invmass.GetEntries() < 100: # TODO: reconsider criterion
@@ -341,6 +341,7 @@ def fit(self):
341341
roows.var(fixpar).setConstant(True)
342342
if h_invmass.GetEntries() == 0:
343343
continue
344+
344345
roo_res, roo_ws = self._roofit_mass(
345346
level,
346347
h_invmass,
@@ -418,7 +419,7 @@ def efficiency(self):
418419
print(self.n_fileff)
419420
lfileeff = TFile.Open(self.n_fileff)
420421
lfileeff.ls()
421-
fileouteff = TFile.Open(f"{self.d_resultsallpmc}/{self.efficiency_filename}{self.case}{self.typean}.root", "recreate")
422+
fileouteff = TFile.Open(f"{self.d_resultsallpmc}/efficiencies{self.case}{self.typean}.root", "recreate")
422423
cEff = TCanvas("cEff", "The Fit Canvas")
423424
cEff.SetCanvasSize(1900, 1500)
424425
cEff.SetWindowSize(500, 500)
@@ -494,7 +495,7 @@ def makenormyields(self): # pylint: disable=import-outside-toplevel, too-many-b
494495
if not os.path.exists(yield_filename):
495496
self.logger.fatal("Yield file %s could not be found", yield_filename)
496497

497-
fileouteff = f"{self.d_resultsallpmc}/{self.efficiency_filename}{self.case}{self.typean}.root"
498+
fileouteff = f"{self.d_resultsallpmc}/efficiencies{self.case}{self.typean}.root"
498499
if not os.path.exists(fileouteff):
499500
self.logger.fatal("Efficiency file %s could not be found", fileouteff)
500501

@@ -506,12 +507,13 @@ def makenormyields(self): # pylint: disable=import-outside-toplevel, too-many-b
506507

507508
histonorm = TH1F("histonorm", "histonorm", 1, 0, 1)
508509

510+
filemass = TFile.Open(self.n_filemass)
511+
hevents = filemass.Get("all_events")
512+
hselevents = filemass.Get("sel_events")
513+
509514
if self.p_nevents is not None:
510515
selnorm = self.p_nevents
511516
else:
512-
filemass = TFile.Open(self.n_filemass)
513-
hevents = filemass.Get("all_events")
514-
hselevents = filemass.Get("sel_events")
515517
norm, selnorm = self.calculate_norm(self.logger, hevents, hselevents)
516518
histonorm.SetBinContent(1, selnorm)
517519
self.logger.warning("Number of events %d", norm)
@@ -554,9 +556,7 @@ def makenormyields(self): # pylint: disable=import-outside-toplevel, too-many-b
554556
f_fileoutcross = TFile.Open(fileoutcross)
555557
if f_fileoutcross:
556558
hcross = f_fileoutcross.Get("hptspectrum")
557-
hcrossbr = f_fileoutcross.Get("hptspectrum_wo_br")
558559
fileoutcrosstot.cd()
559560
hcross.Write()
560-
hcrossbr.Write()
561561
histonorm.Write()
562562
fileoutcrosstot.Close()

machine_learning_hep/analysis/analyzerdhadrons_mult.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
)
5151
from machine_learning_hep.hf_pt_spectrum import hf_pt_spectrum
5252
from machine_learning_hep.logger import get_logger
53-
from machine_learning_hep.utils.hist import get_dim, project_hist
53+
from machine_learning_hep.utils.hist import get_dim
5454

5555

5656
# pylint: disable=too-few-public-methods, too-many-instance-attributes, too-many-statements, fixme
@@ -320,7 +320,7 @@ def fit(self):
320320
for ipt in range(len(self.lpt_finbinmin)):
321321
lpt_probcutfin[ipt] = self.lpt_probcutfin_tmp[self.bin_matching[ipt]]
322322
self.logger.debug("fitting %s - %i - %i", level, ipt, ibin2)
323-
roows = self.roows.get(ipt)
323+
roows = self.roows.get((ibin2, ipt))
324324
if self.mltype == "MultiClassification":
325325
suffix = "%s%d_%d_%.2f%.2f%s_%.2f_%.2f" % (
326326
self.v_var_binning,
@@ -342,7 +342,7 @@ def fit(self):
342342
self.lvar2_binmin[ibin2],
343343
self.lvar2_binmax[ibin2],
344344
)
345-
h_invmass = rfile.Get("hmass" + suffix)
345+
h_invmass = rfile.Get("hmass_" + suffix)
346346
# Rebin
347347
h_invmass.Rebin(self.p_rebin[ipt])
348348
if h_invmass.GetEntries() < 100: # TODO: reconsider criterion
@@ -378,12 +378,14 @@ def fit(self):
378378
break
379379
self.logger.debug("Using fit config for %i: %s", ipt, fitcfg)
380380
if datasel := fitcfg.get("datasel"):
381-
h = rfile.Get(f"h_mass-pthf_{datasel}")
382-
h_invmass = project_hist(h, [0], {1: (ipt + 1, ipt + 1)})
381+
h_invmass = rfile.Get(f"hmass_{datasel}_{suffix}")
383382

384383
for fixpar in fitcfg.get("fix_params", []):
385384
if roows.var(fixpar):
386385
roows.var(fixpar).setConstant(True)
386+
for par in fitcfg.get("free_params", []):
387+
if roows.var(par):
388+
roows.var(par).setConstant(False)
387389
if h_invmass.GetEntries() == 0:
388390
continue
389391

@@ -405,8 +407,8 @@ def fit(self):
405407
)
406408
# if level == 'mc':
407409
# roo_ws.Print()
408-
self.roo_ws[level][ipt] = roo_ws
409-
self.roows[ipt] = roo_ws
410+
self.roows[(ibin2, ipt)] = roo_ws.Clone()
411+
self.roo_ws[(level, ibin2, ipt)] = roo_ws.Clone()
410412
if roo_res.status() == 0:
411413
if level in ("data", "mc_sig"):
412414
self.fit_mean[level][ipt] = roo_ws.var(self.p_param_names["gauss_mean"]).getValV()

0 commit comments

Comments
 (0)