Skip to content

Commit 9ff301b

Browse files
committed
Merge pull request BristolTopGroup#277 from kreczko/muon_2nd_control_region
Muon 2nd control region
2 parents 74fcf9d + 271c730 commit 9ff301b

File tree

5 files changed

+94
-12
lines changed

5 files changed

+94
-12
lines changed

config/cross_section_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def __fill_defaults__( self ):
357357

358358
self.tree_path_control_templates = {
359359
'electron' : 'TTbar_plus_X_analysis/EPlusJets/QCD non iso e+jets/FitVariables',
360-
'muon' : 'TTbar_plus_X_analysis/MuPlusJets/QCD non iso mu+jets/FitVariables'
360+
'muon' : 'TTbar_plus_X_analysis/MuPlusJets/QCD iso > 0.3/FitVariables'
361361
}
362362
self.variable_path_templates = {
363363
'MET' : 'TTbar_plus_X_analysis/{channel}/{selection}/FitVariables/MET',
@@ -380,8 +380,8 @@ def __fill_defaults__( self ):
380380
self.muon_control_region = 'QCD non iso mu+jets ge3j'
381381
self.muon_control_region_systematic = 'QCD non iso mu+jets ge3j' # no systematic yet
382382
if self.centre_of_mass_energy == 13:
383-
self.muon_control_region = 'QCD non iso mu+jets'
384-
self.muon_control_region_systematic = 'QCD non iso mu+jets'
383+
self.muon_control_region = 'QCD iso > 0.3'
384+
self.muon_control_region_systematic = 'QCD 0.12 < iso <= 0.3'
385385

386386
self.include_higgs = False
387387

experimental/add_control_region.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'''
2+
Created on 26 Aug 2015
3+
4+
@author: kreczko
5+
'''
6+
from rootpy.io.file import root_open, File
7+
from tools.ROOT_utils import root_mkdir
8+
import shutil
9+
import subprocess
10+
11+
input_folder = '/hdfs/TopQuarkGroup/run2/atOutput/13TeV/50ns/'
12+
output_folder = input_folder.replace('/hdfs', '')
13+
input_files = ['data_electron_tree.root', 'data_muon_tree.root',
14+
'SingleTop_tree.root', 'TTJets_PowhegPythia8_tree.root', 'VJets_tree.root', 'QCD_Muon_tree.root']
15+
16+
17+
def create_new_trees(input_file, suffix = ''):
18+
tree1_name = 'TTbar_plus_X_analysis/MuPlusJets/QCD non iso mu+jets/FitVariables' + suffix
19+
tree2_name = 'TTbar_plus_X_analysis/MuPlusJets/QCD non iso mu+jets/Muon/Muons' + suffix
20+
s_cr1 = 'relIso_04_deltaBeta <= 0.3 && relIso_04_deltaBeta > 0.12'
21+
s_cr2 = 'relIso_04_deltaBeta > 0.3'
22+
cr1 = 'TTbar_plus_X_analysis/MuPlusJets/QCD 0.12 < iso <= 0.3'
23+
cr2 = 'TTbar_plus_X_analysis/MuPlusJets/QCD iso > 0.3'
24+
25+
with root_open(input_file) as f:
26+
t1 = f.Get(tree1_name)
27+
t2 = f.Get(tree2_name)
28+
t1.AddFriend(t2)
29+
30+
# h1 = t1.Draw('MET', 'relIso_04_deltaBeta > 0.3')
31+
# h2 = t1.Draw(
32+
# 'MET', 'relIso_04_deltaBeta <= 0.3 && relIso_04_deltaBeta > 0.12')
33+
# h3 = t1.Draw('MET', 'relIso_04_deltaBeta > 0.12')
34+
# h4 = t2.Draw('relIso_04_deltaBeta', 'relIso_04_deltaBeta > 0.12')
35+
# print h1.integral()
36+
# print h2.integral()
37+
# print h3.integral(), h1.integral() + h2.integral()
38+
39+
output = File('test.root', 'recreate')
40+
output.mkdir(cr1, recurse=True)
41+
output.mkdir(cr2, recurse=True)
42+
output.cd(cr2)
43+
new_tree1 = t1.CopyTree(s_cr2)
44+
new_tree1.Write()
45+
output.cd(cr1)
46+
new_tree2 = t1.CopyTree(s_cr1)
47+
new_tree2.Write()
48+
output.close()
49+
50+
new_tree1 = None
51+
new_tree2 = None
52+
53+
f_out = File(input_file, 'update')
54+
root_mkdir(f_out, cr1)
55+
root_mkdir(f_out, cr2)
56+
with root_open('test.root') as f_in:
57+
f_out.cd(cr1)
58+
new_tree1 = f_in.Get(cr1 + '/FitVariables' + suffix).CloneTree()
59+
f_out.cd(cr2)
60+
new_tree2 = f_in.Get(cr2 + '/FitVariables' + suffix).CloneTree()
61+
62+
for f in input_files:
63+
shutil.copy(input_folder + f, f)
64+
for suffix in ['', '_JERDown', '_JERUp', '_JESDown', '_JESUp']:
65+
if 'data' in f and not suffix == '':
66+
continue
67+
create_new_trees(f, suffix=suffix)
68+
subprocess.call(['hadoop', 'fs', '-rm', output_folder + f])
69+
subprocess.call(['hadoop', 'fs', '-copyFromLocal', f, output_folder + f])

src/cross_section_measurement/create_measurement.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,25 @@ def create_measurement(com, category, variable, channel, phase_space, norm_metho
221221
m.addShapeForSample('QCD', m_qcd, False)
222222
norm_qcd = deepcopy(m_qcd)
223223
# we want QCD shape and normalisation to be separate
224-
if category == 'QCD_shape' and channel == 'electron':
224+
if category == 'QCD_shape':
225225
for sample in norm_qcd.samples.keys():
226226
tree = norm_qcd.samples[sample]['input'].tree_name
227-
tree = tree.replace(config.electron_control_region_systematic,
228-
config.electron_control_region)
227+
if channel == 'electron':
228+
tree = tree.replace(config.electron_control_region_systematic,
229+
config.electron_control_region)
230+
else:
231+
tree = tree.replace(config.muon_control_region_systematic,
232+
config.muon_control_region)
229233
norm_qcd.samples[sample]['input'].tree_name = tree
230-
if 'QCD_cross_section' in category and channel == 'electron':
234+
if 'QCD_cross_section' in category:
231235
for sample in norm_qcd.samples.keys():
232236
tree = norm_qcd.samples[sample]['input'].tree_name
233-
tree = tree.replace(config.electron_control_region,
234-
config.electron_control_region_systematic)
237+
if channel == 'electron':
238+
tree = tree.replace(config.electron_control_region,
239+
config.electron_control_region_systematic)
240+
else:
241+
tree = tree.replace(config.muon_control_region,
242+
config.muon_control_region_systematic)
235243
norm_qcd.samples[sample]['input'].tree_name = tree
236244

237245
m.addNormForSample('QCD', norm_qcd, False)

src/cross_section_measurement/make_control_plots_fromTrees.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def make_plot( channel, x_axis_title, y_axis_title,
8383
if normalise_to_fit:
8484
normalisation = normalisations_muon[norm_variable]
8585
if use_qcd_data_region:
86-
qcd_data_region = 'QCD non iso mu+jets'
86+
qcd_data_region = 'QCD iso > 0.3'
8787
if not 'QCD' in channel and not 'NPU' in branchName:
8888
weightBranchSignalRegion += ' * MuonEfficiencyCorrection'
8989

@@ -808,7 +808,8 @@ def make_plot( channel, x_axis_title, y_axis_title,
808808
for channel, label in {
809809
'electronQCDNonIso' : 'EPlusJets/QCD non iso e+jets',
810810
'electronQCDConversions' : 'EPlusJets/QCDConversions',
811-
'muonQCDNonIso' : 'MuPlusJets/QCD non iso mu+jets'
811+
'muonQCDNonIso' : 'MuPlusJets/QCD iso > 0.3',
812+
'muonQCDNonIso2' : 'MuPlusJets/QCD 0.12 < iso <= 0.3',
812813
}.iteritems() :
813814
b_tag_bin = '0btag'
814815

@@ -823,7 +824,10 @@ def make_plot( channel, x_axis_title, y_axis_title,
823824
if channel == 'electronQCDConversions':
824825
treeName = 'EPlusJets/QCDConversions'
825826
elif channel == 'muonQCDNonIso':
826-
treeName = 'MuPlusJets/QCD non iso mu+jets'
827+
treeName = 'MuPlusJets/QCD iso > 0.3'
828+
signalTreeName = 'MuPlusJets/Ref selection'
829+
elif channel == 'muonQCDNonIso2':
830+
treeName = 'MuPlusJets/QCD 0.12 < iso <= 0.3'
827831
signalTreeName = 'MuPlusJets/Ref selection'
828832

829833
###################################################

tools/measurement.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ def read_norm(self, sample):
257257
self.aux_info_norms[sample]['norm_factor'] = round(ratio, 2)
258258
self.aux_info_norms[sample]['n_mc_control'] = n_mc_control
259259
self.aux_info_norms[sample]['n_mc_signal_region'] = n_mc_signal_region
260+
self.aux_info_norms[sample]['n_data_control'] = n_data_control
260261
else:
261262
meas_log.warning(
262263
'No MC entry found for sample "{0}", using control region normalisation'.format(sample))

0 commit comments

Comments
 (0)