Skip to content

Commit b2b56c8

Browse files
committed
Merge pull request BristolTopGroup#284 from kreczko/more-stuff
More stuff
2 parents 9f993fb + 29b0b76 commit b2b56c8

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

src/cross_section_measurement/01_get_fit_results.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ def write_fit_results( channel, category, fit_results ):
579579
)
580580
write_fit_results_and_initial_values( 'electron', category, fit_results_electron, initial_values_electron, templates_electron )
581581
write_fit_results_and_initial_values( 'muon', category, fit_results_muon, initial_values_muon, templates_muon )
582-
# write_fit_results( 'combined', category, combine_complex_results( fit_results_electron, fit_results_muon ) )
582+
fit_results_combined = combine_complex_results( fit_results_electron, fit_results_muon )
583+
initial_values_combined = combine_complex_results( initial_values_electron, initial_values_muon)
584+
write_fit_results_and_initial_values( 'combined', category, fit_results_combined, initial_values_combined)
583585
last_systematic = category
584586

585587
# TTJet_file.Close()

src/cross_section_measurement/01_get_ttjet_normalisation.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import glob
3030
import tools.measurement
3131
from copy import deepcopy
32+
from tools.Calculation import combine_complex_results
3233

3334
# define logger for this module
3435
mylog = log["01b_get_ttjet_normalisation"]
@@ -196,6 +197,21 @@ def method_string(self):
196197

197198
return 'unknown_method'
198199

200+
@mylog.trace()
201+
def combine(self, other):
202+
if not self.have_normalisation or not other.have_normalisation:
203+
mylog.warn(
204+
'One of the TTJetNormalisations does not have a normalisation, aborting.')
205+
return
206+
207+
self.normalisation = combine_complex_results(
208+
self.normalisation, other.normalisation)
209+
self.initial_normalisation = combine_complex_results(
210+
self.initial_normalisation, other.initial_normalisation)
211+
self.templates = combine_complex_results(
212+
self.templates, other.templates)
213+
self.channel = 'combined'
214+
199215

200216
def parse_options():
201217
parser = OptionParser(__doc__)
@@ -244,6 +260,7 @@ def main():
244260
phase_space = 'FullPS'
245261
if options.visiblePS:
246262
phase_space = 'VisiblePS'
263+
results = {}
247264
for channel in ['electron', 'muon']:
248265
inputs = {
249266
'energy': options.CoM,
@@ -264,6 +281,16 @@ def main():
264281
)
265282
norm.calculate_normalisation()
266283
norm.save(output_path)
284+
r_name = f.replace(channel, '')
285+
if not results.has_key(r_name):
286+
results[r_name] = [norm]
287+
else:
288+
results[r_name].append(norm)
289+
for f, r_list in results.items():
290+
assert(len(r_list) == 2)
291+
n1, n2 = r_list
292+
n1.combine(n2)
293+
n1.save(output_path)
267294

268295

269296
def get_category_from_file(json_file):

src/cross_section_measurement/02_unfold_and_measure.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def get_unfolded_normalisation( TTJet_fit_results, category, channel, tau_value,
130130
visiblePS = visiblePS,
131131
)
132132

133-
# central_results = hist_to_value_error_tuplelist( h_truth )
133+
# central_results = hist_to_value_error_tuplelist( h_truth )
134134
TTJet_fit_results_unfolded = unfold_results( TTJet_fit_results,
135135
category,
136136
channel,
@@ -463,6 +463,7 @@ def calculate_normalised_xsections( normalisation, category, channel, normalise_
463463

464464
tau_value_electron = measurement_config.tau_values_electron[variable]
465465
tau_value_muon = measurement_config.tau_values_muon[variable]
466+
tau_value_combined = measurement_config.tau_values_combined[variable]
466467

467468
visiblePS = options.visiblePS
468469
phase_space = 'FullPS'
@@ -530,7 +531,6 @@ def calculate_normalised_xsections( normalisation, category, channel, normalise_
530531
# read fit results from JSON
531532
electron_file = path_to_JSON + '/' + category + '/normalisation_electron_' + met_type + '.txt'
532533
muon_file = path_to_JSON + '/' + category + '/normalisation_muon_' + met_type + '.txt'
533-
# combined_file = path_to_JSON + '/fit_results/' + category + '/fit_results_combined_' + met_type + '.txt'
534534

535535
# don't change fit input for ttbar generator/theory systematics and PDF weights
536536
if category in ttbar_generator_systematics or category in pdf_uncertainties:
@@ -569,10 +569,10 @@ def calculate_normalised_xsections( normalisation, category, channel, normalise_
569569
else:
570570
fit_results_electron = read_data_from_JSON( electron_file )
571571
fit_results_muon = read_data_from_JSON( muon_file )
572-
# fit_results_combined = read_data_from_JSON( combined_file )
572+
fit_results_combined = combine_complex_results(fit_results_electron, fit_results_muon)
573573
TTJet_fit_results_electron = fit_results_electron['TTJet']
574574
TTJet_fit_results_muon = fit_results_muon['TTJet']
575-
# TTJet_fit_results_combined = fit_results_combined['TTJet']
575+
TTJet_fit_results_combined = fit_results_combined['TTJet']
576576

577577
# # change back to original MET type for the unfolding
578578
met_type = translate_options[options.metType]
@@ -602,10 +602,14 @@ def calculate_normalised_xsections( normalisation, category, channel, normalise_
602602
calculate_normalised_xsections( unfolded_normalisation_muon, category, 'muon' )
603603
calculate_normalised_xsections( unfolded_normalisation_muon, category, 'muon' , True )
604604

605-
# # if combine_before_unfolding:
606-
# # unfolded_normalisation_combined = get_unfolded_normalisation( TTJet_fit_results_combined, category, 'combined', k_value_combined )
607-
# # else:
608-
unfolded_normalisation_combined = combine_complex_results( unfolded_normalisation_electron, unfolded_normalisation_muon )
605+
if combine_before_unfolding:
606+
unfolded_normalisation_combined = get_unfolded_normalisation(
607+
TTJet_fit_results_combined,
608+
category,'combined', tau_value=tau_value_combined,
609+
visiblePS=visiblePS,
610+
)
611+
else:
612+
unfolded_normalisation_combined = combine_complex_results( unfolded_normalisation_electron, unfolded_normalisation_muon )
609613

610614
filename = path_to_JSON + '/xsection_measurement_results/combined/%s/normalisation_%s.txt' % ( category, met_type )
611615
write_data_to_JSON( unfolded_normalisation_combined, filename )

tools/Calculation.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ def combine_complex_results(result1, result2):
9696
for sample in samples:
9797
results = []
9898
for entry1, entry2 in zip(result1[sample], result2[sample]):
99-
value1, error1 = entry1
100-
value2, error2 = entry2
101-
results.append( ( value1 + value2, sqrt( error1**2 + error2**2 ) ) )
99+
v1 = ufloat(entry1[0], entry1[1])
100+
v2 = ufloat(entry2[0], entry2[1])
101+
s = v1 + v2
102+
results.append( ( s.nominal_value, s.std_dev ) )
102103
combined_result[sample] = results
103104
return combined_result
104105

0 commit comments

Comments
 (0)