Skip to content

Commit e121fd6

Browse files
authored
Small fixes to the cross section code (#963)
* First completed code for cross section. To be tested * Fixes for working hf_pt_spectrum * Database for Nb method * Add histogram for fractions * Back to dd config * Use configurable nevents for crosssec calculations * Fix nevents for Nb method. Fix input for dd method * Remove redundant hfraction. Add propagated statistical uncertainties to dd result. * Narrow range for low pt reproduction * Add dd_N method to calculate cross section from final corrected yields from cut variation * Configure proper merged input files for dd in database and analyser * Working cross section estimators. Only multiclass optimization remains * Defer opening of nevents files * Remove spurious lines * Exclude changes in database and submission files * Fixed next lines
1 parent dfaa500 commit e121fd6

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

machine_learning_hep/analysis/analyzerdhadrons.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def efficiency(self):
418418
print(self.n_fileff)
419419
lfileeff = TFile.Open(self.n_fileff)
420420
lfileeff.ls()
421-
fileouteff = TFile.Open(f"{self.d_resultsallpmc}/efficiencies{self.case}{self.typean}.root", "recreate")
421+
fileouteff = TFile.Open(f"{self.d_resultsallpmc}/{self.efficiency_filename}{self.case}{self.typean}.root", "recreate")
422422
cEff = TCanvas("cEff", "The Fit Canvas")
423423
cEff.SetCanvasSize(1900, 1500)
424424
cEff.SetWindowSize(500, 500)
@@ -494,7 +494,7 @@ def makenormyields(self): # pylint: disable=import-outside-toplevel, too-many-b
494494
if not os.path.exists(yield_filename):
495495
self.logger.fatal("Yield file %s could not be found", yield_filename)
496496

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

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

507507
histonorm = TH1F("histonorm", "histonorm", 1, 0, 1)
508508

509-
filemass = TFile.Open(self.n_filemass)
510-
hevents = filemass.Get("all_events")
511-
hselevents = filemass.Get("sel_events")
512-
513509
if self.p_nevents is not None:
514510
selnorm = self.p_nevents
515511
else:
512+
filemass = TFile.Open(self.n_filemass)
513+
hevents = filemass.Get("all_events")
514+
hselevents = filemass.Get("sel_events")
516515
norm, selnorm = self.calculate_norm(self.logger, hevents, hselevents)
517516
histonorm.SetBinContent(1, selnorm)
518517
self.logger.warning("Number of events %d", norm)
@@ -555,7 +554,9 @@ def makenormyields(self): # pylint: disable=import-outside-toplevel, too-many-b
555554
f_fileoutcross = TFile.Open(fileoutcross)
556555
if f_fileoutcross:
557556
hcross = f_fileoutcross.Get("hptspectrum")
557+
hcrossbr = f_fileoutcross.Get("hptspectrum_wo_br")
558558
fileoutcrosstot.cd()
559559
hcross.Write()
560+
hcrossbr.Write()
560561
histonorm.Write()
561562
fileoutcrosstot.Close()

machine_learning_hep/hf_analysis_utils.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,6 @@ def compute_fraction_dd(acc_eff_same, acc_eff_other, corryields_same, corryields
268268
yield_times_acceff_same = corryields_same * acc_eff_same
269269
yield_times_acceff_other = corryields_other * acc_eff_other
270270
frac_v = yield_times_acceff_same / (yield_times_acceff_same + yield_times_acceff_other)
271-
# print(f"same yield times acceff: {yield_times_acceff_same} " \
272-
# f"other {yield_times_acceff_other} final frac: {frac_v}")
273271

274272
denom = (yield_times_acceff_same + yield_times_acceff_other) ** 2
275273
der_same_same = (
@@ -279,8 +277,6 @@ def compute_fraction_dd(acc_eff_same, acc_eff_other, corryields_same, corryields
279277
unc = np.sqrt(
280278
der_same_same**2 * cov_same + der_same_other**2 * cov_other + 2 * der_same_same * der_same_other * cov_comb
281279
)
282-
# print(f"denom {denom} der_same_same {der_same_same} der_same_other {der_same_other} " \
283-
# f"cov same {cov_same} cov other {cov_other} cov comb {cov_comb} final unc {unc}")
284280

285281
return [frac_v, frac_v - unc, frac_v + unc]
286282

machine_learning_hep/hf_pt_spectrum.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,22 @@ def hf_pt_spectrum(
106106

107107
histos = {}
108108

109-
infile_pred = TFile.Open(input_fonll_or_fdd_pred)
110-
if frac_method in ("dd", "dd_N"):
111-
histos["corryields_fdd"] = [infile_pred.Get("hCorrYieldsPrompt"), infile_pred.Get("hCorrYieldsNonPrompt")]
112-
histos["covariances"] = [
113-
infile_pred.Get("hCovPromptPrompt"),
114-
infile_pred.Get("hCovNonPromptNonPrompt"),
115-
infile_pred.Get("hCovPromptNonPrompt"),
116-
]
117-
else:
118-
histos["FONLL"] = {"prompt": {}, "nonprompt": {}}
119-
for pred in ("central", "min", "max"):
120-
histos["FONLL"]["nonprompt"][pred] = infile_pred.Get(f"{fonll_hist_name[channel]}fromBpred_{pred}_corr")
121-
histos["FONLL"]["nonprompt"][pred].SetDirectory(0)
122-
if frac_method == "fc":
123-
histos["FONLL"]["prompt"][pred] = infile_pred.Get(f"{fonll_hist_name[channel]}pred_{pred}")
124-
histos["FONLL"]["prompt"][pred].SetDirectory(0)
125-
126-
infile_pred.Close()
109+
with TFile.Open(input_fonll_or_fdd_pred) as infile_pred:
110+
if frac_method in ("dd", "dd_N"):
111+
histos["corryields_fdd"] = [infile_pred.Get("hCorrYieldsPrompt"), infile_pred.Get("hCorrYieldsNonPrompt")]
112+
histos["covariances"] = [
113+
infile_pred.Get("hCovPromptPrompt"),
114+
infile_pred.Get("hCovNonPromptNonPrompt"),
115+
infile_pred.Get("hCovPromptNonPrompt"),
116+
]
117+
else:
118+
histos["FONLL"] = {"prompt": {}, "nonprompt": {}}
119+
for pred in ("central", "min", "max"):
120+
histos["FONLL"]["nonprompt"][pred] = infile_pred.Get(f"{fonll_hist_name[channel]}fromBpred_{pred}_corr")
121+
histos["FONLL"]["nonprompt"][pred].SetDirectory(0)
122+
if frac_method == "fc":
123+
histos["FONLL"]["prompt"][pred] = infile_pred.Get(f"{fonll_hist_name[channel]}pred_{pred}")
124+
histos["FONLL"]["prompt"][pred].SetDirectory(0)
127125

128126
infile_rawy = TFile.Open(yield_filename)
129127
histos["rawyields"] = infile_rawy.Get(yield_histoname)
@@ -235,10 +233,6 @@ def hf_pt_spectrum(
235233
histos["covariances"][1 - pnp_ind].GetBinContent(i_pt + 1),
236234
histos["covariances"][2].GetBinContent(i_pt + 1),
237235
)
238-
print("FRACTION HEREEEEEEEE: ")
239-
print(histos["corryields_fdd"][pnp_ind].GetBinContent(i_pt + 1))
240-
print(histos["corryields_fdd"][1 - pnp_ind].GetBinContent(i_pt + 1))
241-
print("FRACTION HEREEEEEEEE: ")
242236
elif frac_method == "dd_N":
243237
pnp_ind = 0 if crosssec_prompt else 1
244238
frac = [histos["corryields_fdd"][pnp_ind].GetBinContent(i_pt + 1)] * 3

0 commit comments

Comments
 (0)