66from dps .config .variable_binning import bin_edges_vis , reco_bin_edges_vis
77from dps .config .variableBranchNames import branchNames , genBranchNames_particle , genBranchNames_parton
88from dps .utils .file_utilities import make_folder_if_not_exists
9- from math import trunc
9+ from math import trunc , exp , sqrt
1010
1111from scaleFactors import *
1212
@@ -38,6 +38,14 @@ def calculateTopPtWeight( lepTopPt, hadTopPt, whichWayToWeight = 1 ):
3838 else :
3939 return 1
4040
41+ def calculateTopPtSystematicWeight ( lepTopPt , hadTopPt ):
42+ lepTopWeight = ptWeight ( lepTopPt )
43+ hadTopWeight = ptWeight ( hadTopPt )
44+ return sqrt ( lepTopWeight * hadTopWeight )
45+
46+ def ptWeight ( pt ):
47+ return exp ( 0.0615 - 0.0005 * pt )
48+
4149def getFileName ( com , sample , measurementConfig ) :
4250
4351 fileNames = {
@@ -47,10 +55,16 @@ def getFileName( com, sample, measurementConfig ) :
4755 'madgraph' : measurementConfig .ttbar_madgraph_category_templates_trees ,
4856 'powhegherwigpp' : measurementConfig .ttbar_powhegherwigpp_category_templates_trees ,
4957 'amcatnloherwigpp' : measurementConfig .ttbar_amcatnloherwigpp_category_templates_trees ,
50- 'scaleup' : measurementConfig .ttbar_scaleup_category_templates_trees ,
51- 'scaledown' : measurementConfig .ttbar_scaledown_category_templates_trees ,
5258 'massdown' : measurementConfig .ttbar_mtop1695_category_templates_trees ,
5359 'massup' : measurementConfig .ttbar_mtop1755_category_templates_trees ,
60+ 'topPtSystematic' : measurementConfig .ttbar_category_templates_trees ['central' ],
61+ 'fsrup' : measurementConfig .ttbar_fsrup_category_templates_trees ,
62+ 'fsrdown' : measurementConfig .ttbar_fsrdown_category_templates_trees ,
63+ 'isrup' : measurementConfig .ttbar_isrup_category_templates_trees ,
64+ 'isrdown' : measurementConfig .ttbar_isrdown_category_templates_trees ,
65+ 'ueup' : measurementConfig .ttbar_ueup_category_templates_trees ,
66+ 'uedown' : measurementConfig .ttbar_uedown_category_templates_trees ,
67+
5468 'jesdown' : measurementConfig .ttbar_jesdown_category_templates_trees ,
5569 'jesup' : measurementConfig .ttbar_jesup_category_templates_trees ,
5670 'jerdown' : measurementConfig .ttbar_jerdown_category_templates_trees ,
@@ -79,7 +93,7 @@ def getFileName( com, sample, measurementConfig ) :
7993 return fileNames [com ][sample ]
8094
8195channels = [
82- # channel( 'ePlusJets', 'rootTupleTreeEPlusJets', 'electron'),
96+ channel ( 'ePlusJets' , 'rootTupleTreeEPlusJets' , 'electron' ),
8397 channel ( 'muPlusJets' , 'rootTupleTreeMuPlusJets' , 'muon' )
8498 ]
8599
@@ -91,7 +105,6 @@ def main():
91105 parser .add_option ('-c' , '--centreOfMassEnergy' , dest = 'centreOfMassEnergy' , type = 'int' , default = 13 )
92106 parser .add_option ('--pdfWeight' , type = 'int' , dest = 'pdfWeight' , default = - 1 )
93107 parser .add_option ('--muFmuRWeight' , type = 'int' , dest = 'muFmuRWeight' , default = - 1 )
94- parser .add_option ('--alphaSWeight' , type = 'int' , dest = 'alphaSWeight' , default = - 1 )
95108 parser .add_option ('--nGeneratorWeights' , type = 'int' , dest = 'nGeneratorWeights' , default = 1 )
96109 parser .add_option ('-s' , '--sample' , dest = 'sample' , default = 'central' )
97110 parser .add_option ('-d' , '--debug' , action = 'store_true' , dest = 'debug' , default = False )
@@ -115,7 +128,6 @@ def main():
115128
116129 pdfWeight = options .pdfWeight
117130 muFmuRWeight = options .muFmuRWeight
118- alphaSWeight = options .alphaSWeight
119131
120132 # Output file name
121133 outputFileName = 'crap.root'
@@ -134,10 +146,6 @@ def main():
134146 outputFileName = outputFileDir + '/unfolding_TTJets_%s_asymmetric_withTopPtReweighting_up.root' % energySuffix
135147 elif options .applyTopPtReweighting == - 1 :
136148 outputFileName = outputFileDir + '/unfolding_TTJets_%s_asymmetric_withTopPtReweighting_down.root' % energySuffix
137- elif alphaSWeight == 0 :
138- outputFileName = outputFileDir + '/unfolding_TTJets_%s_asymmetric_alphaSDown.root' % ( energySuffix )
139- elif alphaSWeight == 1 :
140- outputFileName = outputFileDir + '/unfolding_TTJets_%s_asymmetric_alphaSUp.root' % ( energySuffix )
141149 elif muFmuRWeight == 1 :
142150 outputFileName = outputFileDir + '/unfolding_TTJets_%s_asymmetric_1muR2muF.root' % ( energySuffix )
143151 elif muFmuRWeight == 2 :
@@ -160,7 +168,7 @@ def main():
160168 outputFileName = outputFileDir + '/unfolding_TTJets_%s_asymmetric.root' % energySuffix
161169
162170 with root_open ( file_name , 'read' ) as f , root_open ( outputFileName , 'recreate' ) as out :
163-
171+
164172 # Get the tree
165173 treeName = "TTbar_plus_X_analysis/Unfolding/Unfolding"
166174 if options .sample == "jesup" :
@@ -325,7 +333,7 @@ def main():
325333 branch = event .__getattr__
326334 n += 1
327335 if not n % 100000 : print 'Processing event %.0f Progress : %.2g %%' % ( n , float (n )/ nEntries * 100 )
328- # if n == 10000 : break
336+ # if n == 100000 : break
329337 # # #
330338 # # # Weights and selection
331339 # # #
@@ -364,10 +372,16 @@ def main():
364372 elif options .sample == "lightjetdown" :
365373 bjetWeight = event .LightJetDownWeight
366374
375+ # Top pt systematic weight
376+ topPtSystematicWeight = 1
377+ if options .sample == 'topPtSystematic' :
378+ topPtSystematicWeight = calculateTopPtSystematicWeight ( branch ('lepTopPt_parton' ), branch ('hadTopPt_parton' ))
379+
367380 offlineWeight = event .EventWeight * measurement_config .luminosity_scale
368381 offlineWeight *= pileupWeight
369382 offlineWeight *= bjetWeight
370- offlineWeight *= leptonWeight
383+ # offlineWeight *= leptonWeight
384+ offlineWeight *= topPtSystematicWeight
371385
372386 # Generator weight
373387 # Scale up/down, pdf
@@ -376,15 +390,16 @@ def main():
376390 offlineWeight *= branch ('pdfWeight_%i' % pdfWeight )
377391 pass
378392
393+
379394 if muFmuRWeight >= 0 :
380395 genWeight *= branch ('muFmuRWeight_%i' % muFmuRWeight )
381396 offlineWeight *= branch ('muFmuRWeight_%i' % muFmuRWeight )
382397 pass
383398
384- if alphaSWeight > = 0 :
385- genWeight *= branch ('alphaSWeight_%i' % alphaSWeight )
386- offlineWeight *= branch ( 'alphaSWeight_%i' % alphaSWeight )
387- pass
399+ if options . applyTopPtReweighting ! = 0 :
400+ ptWeight = calculateTopPtWeight ( branch ('lepTopPt_parton' ), branch ( 'hadTopPt_parton' ), options . applyTopPtReweighting )
401+ offlineWeight *= ptWeight
402+ genWeight *= ptWeight
388403
389404 if options .applyTopPtReweighting != 0 :
390405 ptWeight = calculateTopPtWeight ( branch ('lepTopPt_parton' ), branch ('hadTopPt_parton' ), options .applyTopPtReweighting )
0 commit comments