Skip to content

Commit

Permalink
Merge pull request #5 from steggema/htautau_cvs_updates
Browse files Browse the repository at this point in the history
Add latest CVS commits of CMGTools packages HTauTau, RootTools and Utilities
  • Loading branch information
cbernet authored and steggema committed Apr 2, 2014
1 parent 8708230 commit b497701
Show file tree
Hide file tree
Showing 52 changed files with 1,844 additions and 451 deletions.
102 changes: 72 additions & 30 deletions CMGTools/H2TauTau/Colin/plot_MuRm.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import math
import os
from CMGTools.RootTools.treeComparator import *
from CMGTools.H2TauTau.proto.plotter.categories_TauMu import *
from CMGTools.RootTools.ReWeighter import ReWeighter
from CMGTools.RootTools.statistics.Value import Value

canvas = None
pad = None
Expand All @@ -12,7 +8,8 @@

#TODO warning normalization
def drawWithRatio(var, cut, t1, t2, w1, w2, nbins, xmin=0, xmax=200, var2=None):
comp = draw(var, cut, t1, t2, w1=w1, w2=w2, normalize=-1, nbins=nbins,xmin=xmin, xmax=xmax, var2=var2)
comp = draw(var, cut, t1, t2, w1=w1, w2=w2, normalize=-1,
nbins=nbins,xmin=xmin, xmax=xmax, var2=var2)
return comp

def addWeight(iwstr, wfnam):
Expand All @@ -26,7 +23,7 @@ def addWeight(iwstr, wfnam):
def lowHighMTRatio(hist, lognam, msg, lowmax=None, highmin=None, highmax=None):
errlow = ROOT.Double()
lowmin = 1
if lowmax is None: lowmax = 4
if lowmax is None: lowmax = 3
low = hist.IntegralAndError(lowmin,lowmax,errlow)
errhigh = ROOT.Double()
if highmin is None: highmin = 8
Expand Down Expand Up @@ -65,48 +62,71 @@ def lowHighMTRatio(hist, lognam, msg, lowmax=None, highmin=None, highmax=None):
return vratio


def report( dirname, h1, h2, a1, a2, cut, highmin=None, highmax=None):
if dirname.find('Test')!=-1:
def report( dirname, comp, a1, a2, cut, highmin=None, highmax=None, force=False):
if force:
os.system('rm -r ' + dirname)
oldpwd = os.getcwd()
os.mkdir(dirname)
os.chdir(dirname)
r1 = lowHighMTRatio(h1, a1, cut, highmin=highmin, highmax=highmax)
r2 = lowHighMTRatio(h2, a2, cut, highmin=highmin, highmax=highmax)
r1 = lowHighMTRatio(comp.h1, a1, cut, highmin=highmin, highmax=highmax)
r2 = lowHighMTRatio(comp.h2, a2, cut, highmin=highmin, highmax=highmax)

slog = open('scaling.txt','w')
sstr = 'scaling : {val}\n'.format(val = r1/r2)
rFactor = r1/r2
sstr = 'scaling : {val}\n'.format(val = rFactor)
print sstr
slog.write( sstr )
slog.close()

can.SaveAs('plot.png')
comp.pad_main.cd()
latex = TLatex()
latex.SetNDC()
latex.DrawLatex(0.6, 0.6, 'R={val:3.2f} #pm {err:3.2f}'.format(val=rFactor.val, err=rFactor.err))
comp.can.SaveAs('plot.png')
os.chdir(oldpwd)


def systematicReport(basename):
os.mkdir(basename)
# Moriond categories
## cuts = {
## 'Inclusive':cat_Inc,
## '0jet_low':' && '.join( [cat_Inc, cat_J0, 'l1_pt<40'] ),
## '0jet_high':' && '.join( [cat_Inc, cat_J0, 'l1_pt>40'] ),
## '1jet_low':' && '.join( [cat_Inc, cat_J1, 'l1_pt<40'] ),
## '1jet_high':' && '.join( [cat_Inc, cat_J1, 'l1_pt>40'] ),
## '2jet':' && '.join( [cat_Inc, cat_J2] ),
## }
# Summer 13 categories
cuts = {
'Inclusive':cat_Inc,
'0jet_low':' && '.join( [cat_Inc, cat_J0, 'l1_pt<40'] ),
'0jet_high':' && '.join( [cat_Inc, cat_J0, 'l1_pt>40'] ),
'1jet_low':' && '.join( [cat_Inc, cat_J1, 'l1_pt<40'] ),
'1jet_high':' && '.join( [cat_Inc, cat_J1, 'l1_pt>40'] ),
'2jet':' && '.join( [cat_Inc, cat_J2] ),
'0jet_medium':' && '.join( [cat_Inc, cat_J0_medium, 'l1_pt>30'] ),
'0jet_high':' && '.join( [cat_Inc, cat_J0_high, 'l1_pt>30'] ),
'1jet_medium':' && '.join( [cat_Inc, cat_J1_medium, 'l1_pt>30'] ),
'1jet_high_lowhiggs':' && '.join( [cat_Inc, cat_J1_high_lowhiggs, 'l1_pt>30'] ),
'1jet_high_mediumhiggs':' && '.join( [cat_Inc, cat_J1_high_mediumhiggs, 'l1_pt>30'] ),
'1B':'&&'.join( [cat_Inc, cat_1BInclusive] ),
'0B':'&&'.join( [cat_Inc, cat_0B] )
# think about tau pT cut!!
# 'vbf_tight':' && '.join( [cat_Inc, cat_VBF_tight] ),
# 'vbf_loose':' && '.join( [cat_Inc, cat_VBF_loose] ),
}

for cut in cuts:
cuts[cut] = cuts[cut].replace('l1_looseMvaIso>0.5', 'l1_rawMvaIso>-0.5')
# cuts[cut] = cuts[cut].replace('l1_looseMvaIso>0.5', 'l1_rawMvaIso>-0.5')
cuts[cut] = cuts[cut].replace('l1_threeHitIso<1.5', 'l1_threeHitIso<10')
if a1.find('WJets')!=-1:
cuts[cut] += '&& (abs(genWnu_eta)<2. || genWnu_eta<-90)'

# import pdb; pdb.set_trace()
for cutname, cut in cuts.iteritems():
highmin = 8
highmax = None
if cutname=='2jet':
if cutname.startswith('vbf'):
highmin = 7
highmax = 12
# import pdb; pdb.set_trace()
h1, h2, hr, leg = drawWithRatio(var, cut, trees[a1], trees[a2], w1=w1, w2=w2, nbins=20, xmin=0, xmax=200, var2=var2)
report('/'.join([basename, cutname]), h1, h2, a1, a2, cut,
# h1, h2, hr, leg = drawWithRatio(var, cut, trees[a1], trees[a2], w1=w1, w2=w2, nbins=20, xmin=0, xmax=200, var2=var2)
comp = drawWithRatio(var, cut, trees[a1], trees[a2], w1=w1, w2=w2, nbins=20, xmin=0, xmax=200, var2=var2)
report('/'.join([basename, cutname]), comp, a1, a2, cut,
highmin=highmin, highmax=highmax)

if __name__ == '__main__':
Expand All @@ -132,6 +152,19 @@ def systematicReport(basename):
(options,args) = parser.parse_args()
if len(args) !=3 :
print 'pattern1 pattern2 var'
sys.exit(1)

if options.report and os.path.isdir(options.report):
print options.report, ' already exists. quit'
sys.exit(2)

# importing after test of argument validity
# not to waste time loading fwlite.
from CMGTools.RootTools.treeComparator import *
from CMGTools.H2TauTau.proto.plotter.categories_TauMu import *
from CMGTools.RootTools.ReWeighter import ReWeighter
from CMGTools.RootTools.statistics.Value import Value
from ROOT import TLatex

p1 = args[0]
p2 = args[1]
Expand All @@ -144,17 +177,21 @@ def systematicReport(basename):
trees[a2].SetTitle( a2 )

# beware weight!
cut = cat_Inc + ' && ' + cat_J1
# cut = ' && '.join( [cat_Inc] )
cut = ' && '.join( [cat_Inc, cat_VBF_Rel_20, 'l1_pt>30'] )
# + '&&' + cat_0B
# cut = cat_Inc
if a1.find('WJets')!=-1:
cut += '&& (abs(genWnu_eta)<2.4 || genWnu_eta<-90)'
cut += '&& (abs(genWnu_eta)<2. || genWnu_eta<-90)'

# dr = 'sqrt((l1_eta-l2_eta)^2 + (l1_phi-l2_phi)^2)>2
cut = cut.replace('l1_threeHitIso<1.5', 'l1_threeHitIso<999')
cut = cut.replace('l1_threeHitIso<1.5', 'l1_threeHitIso<10')
# cut += ' && ' + dr
w1 = '1'
if a1.find('WJets') != -1:
w1 = 'weight'
w2 = 'weight'
if a1.find('WJets') != -1:
w1 = '1'
w2 = '1'

var = args[2]
var2 = options.var2
Expand All @@ -180,7 +217,8 @@ def systematicReport(basename):
w2 = addWeight( w2, wfnam )

comp = drawWithRatio(var, cut, trees[a1], trees[a2], w1=w1, w2=w2, nbins=20, xmin=0, xmax=200, var2=var2)

# report('Test', comp, a1, a2, cut, highmin=8)


if options.oweight:
weightFile = shelve.open( options.oweight )
Expand All @@ -190,4 +228,8 @@ def systematicReport(basename):


if options.report:
report(options.report, h1, h2, a1, a2, cut)
report(options.report, comp, a1, a2, cut, highmin=8)
else:
dir = 'Tmp_plot_MuRm'
report(dir, comp, a1, a2, cut, highmin=8, force=True)

17 changes: 13 additions & 4 deletions CMGTools/H2TauTau/Colin/tauEle_2012_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
syncntuple = True
doThePlot = True

puFileDir = os.environ['CMSSW_BASE'] + '/src/CMGTools/RootTools/data/Reweight/2012'

puFileMC = '/afs/cern.ch/user/a/agilbert/public/HTT_Pileup/12-06-13/MC_Summer12_PU_S10-600bins.root'
puFileData = '/afs/cern.ch/user/a/agilbert/public/HTT_Pileup/12-06-13/Data_Pileup_2012_ReReco-600bins.root'
puFileMC = '/afs/cern.ch/user/a/agilbert/public/HTT_Pileup/13-09-13/MC_Summer12_PU_S10-600bins.root'
puFileData = '/afs/cern.ch/user/a/agilbert/public/HTT_Pileup/13-09-13/Data_Pileup_2012_ReRecoPixel-600bins.root'

# vertexFileDir = os.environ['CMSSW_BASE'] + '/src/CMGTools/RootTools/data/Reweight/2012/Vertices'
# vertexFileData = '/'.join([vertexFileDir, 'vertices_data_2012A_2012B_start_195947.root'])
Expand Down Expand Up @@ -114,6 +112,10 @@
verbose = False,
)

tauFakeRateWeighter = cfg.Analyzer(
'TauFakeRateWeighter'
)

tauWeighter = cfg.Analyzer(
'LeptonWeighter_tau',
effWeight = hlt_tauEffWeight,
Expand Down Expand Up @@ -246,6 +248,7 @@
pileUpAna,
embedWeighter,
tauDecayModeWeighter,
tauFakeRateWeighter,
tauWeighter,
eleWeighter,
treeProducer
Expand Down Expand Up @@ -276,6 +279,12 @@
# selectedComponents = [h for h in higgs if 'GGH' in h.name]
# selectedComponents = [DYJets, DY1Jets, DY2Jets, DY3Jets, DY4Jets]
selectedComponents = [W1Jets_ext, W2Jets_ext, W3Jets_ext,WJets, W1Jets, W2Jets, W3Jets, W4Jets]
# selectedComponents = mc_higgs_susy
# selectedComponents += higgs
# selectedComponents += [DYJets, DY1Jets, DY2Jets, DY3Jets, DY4Jets]
# selectedComponents = embed_list
# selectedComponents += [DYJets, DY1Jets, DY2Jets, DY3Jets, DY4Jets]
# selectedComponents = data_list


config = cfg.Config( components = selectedComponents,
Expand Down
11 changes: 6 additions & 5 deletions CMGTools/H2TauTau/Colin/tauEle_2012_down_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
syncntuple = True
doThePlot = True

puFileDir = os.environ['CMSSW_BASE'] + '/src/CMGTools/RootTools/data/Reweight/2012'

puFileMC = '/afs/cern.ch/user/a/agilbert/public/HTT_Pileup/12-06-13/MC_Summer12_PU_S10-600bins.root'
puFileData = '/afs/cern.ch/user/a/agilbert/public/HTT_Pileup/12-06-13/Data_Pileup_2012_ReReco-600bins.root'
puFileMC = '/afs/cern.ch/user/a/agilbert/public/HTT_Pileup/13-09-13/MC_Summer12_PU_S10-600bins.root'
puFileData = '/afs/cern.ch/user/a/agilbert/public/HTT_Pileup/13-09-13/Data_Pileup_2012_ReRecoPixel-600bins.root'

# vertexFileDir = os.environ['CMSSW_BASE'] + '/src/CMGTools/RootTools/data/Reweight/2012/Vertices'
# vertexFileData = '/'.join([vertexFileDir, 'vertices_data_2012A_2012B_start_195947.root'])
Expand Down Expand Up @@ -261,7 +259,10 @@
for comp in selectedComponents:
comp.splitFactor = 1
comp.files = comp.files[:3]

elif test==3:
# selectedComponents = mc_higgs_susy
# selectedComponents = [DYJets, DY1Jets, DY2Jets, DY3Jets, DY4Jets]
selectedComponents = [HiggsVBF125]

config = cfg.Config( components = selectedComponents,
sequence = sequence )
Expand Down
12 changes: 7 additions & 5 deletions CMGTools/H2TauTau/Colin/tauEle_2012_up_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
syncntuple = True
doThePlot = True

puFileDir = os.environ['CMSSW_BASE'] + '/src/CMGTools/RootTools/data/Reweight/2012'

puFileMC = '/afs/cern.ch/user/a/agilbert/public/HTT_Pileup/12-06-13/MC_Summer12_PU_S10-600bins.root'
puFileData = '/afs/cern.ch/user/a/agilbert/public/HTT_Pileup/12-06-13/Data_Pileup_2012_ReReco-600bins.root'
puFileMC = '/afs/cern.ch/user/a/agilbert/public/HTT_Pileup/13-09-13/MC_Summer12_PU_S10-600bins.root'
puFileData = '/afs/cern.ch/user/a/agilbert/public/HTT_Pileup/13-09-13/Data_Pileup_2012_ReRecoPixel-600bins.root'

# vertexFileDir = os.environ['CMSSW_BASE'] + '/src/CMGTools/RootTools/data/Reweight/2012/Vertices'
# vertexFileData = '/'.join([vertexFileDir, 'vertices_data_2012A_2012B_start_195947.root'])
Expand Down Expand Up @@ -257,7 +255,11 @@
for comp in selectedComponents:
comp.splitFactor = 1
comp.files = comp.files[:3]

elif test==3:
# selectedComponents = mc_higgs_susy
# selectedComponents = [DYJets, DY1Jets, DY2Jets, DY3Jets, DY4Jets]
selectedComponents = embed_list
selectedComponents += [DYJets, DY1Jets, DY2Jets, DY3Jets, DY4Jets]

config = cfg.Config( components = selectedComponents,
sequence = sequence )
Expand Down
Loading

0 comments on commit b497701

Please sign in to comment.