1 |
import ROOT
|
2 |
import sys, re
|
3 |
sys.path.append("/afs/naf.desy.de/user/n/nowaf/UserCode/nowaf/PythonScripts/")
|
4 |
import definitions as Def
|
5 |
import styles as Style
|
6 |
import FakeHelper as FH
|
7 |
from array import array
|
8 |
|
9 |
if __name__ == "__main__":
|
10 |
|
11 |
Def.SetGlobalStyles()
|
12 |
|
13 |
sampleList = []
|
14 |
#sampleList.append( "ZJets" )
|
15 |
#sampleList.append( "WJets" )
|
16 |
#sampleList.append( "TTbar" )
|
17 |
sampleList.append( "QCDFlat" )
|
18 |
|
19 |
fileDict = {}
|
20 |
fileDict[ "ZJets" ] = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/ZJets50_TauTemplate_iii/ZJets_TauTemplate_iii.root"
|
21 |
fileDict[ "WJets" ] = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/WJets_TauTemplate_iii/WJets_TauTemplate_iii.root"
|
22 |
fileDict[ "TTbar" ] = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/TTbar_TauTemplate_iii/TTbar_TauTemplate_iii.root"
|
23 |
fileDict[ "QCDFlat" ] = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/QCDFlat_FakesOnSkim_xiv/QCDFlat_Fakes_xivPre.root"
|
24 |
|
25 |
dirList = []
|
26 |
dirList.append( "FakeRateDiJetsLoose/" )
|
27 |
dirList.append( "FakeRateAllLoose/" )
|
28 |
#dirList.append( "FakeRatePreLoose/" )
|
29 |
dirList.append( "FakeRateInvertMHTLoose/" )
|
30 |
|
31 |
fakeDict = {}
|
32 |
fakeDict[ "JetPt" ] = "JetTauPt"
|
33 |
fakeDict[ "JetEta" ] = "JetTauEta"
|
34 |
fakeDict[ "JetPtJPT" ] = "JetTauPtJPT"
|
35 |
fakeDict[ "JetEtaJPT" ] = "JetTauEtaJPT"
|
36 |
fakeDict[ "JetPteta1" ] = "JetTauPteta1"
|
37 |
fakeDict[ "JetPteta2" ] = "JetTauPteta2"
|
38 |
fakeDict[ "JetPteta25" ] = "JetTauPteta25"
|
39 |
fakeDict[ "JetEtaPt50" ] = "JetTauEtaPt50"
|
40 |
fakeDict[ "JetEtaPt100" ] = "JetTauEtaPt100"
|
41 |
fakeDict[ "JetEtaPt200" ] = "JetTauEtaPt200"
|
42 |
fakeDict[ "JetEtaPt500" ] = "JetTauEtaPt500"
|
43 |
fakeDict[ "JetEtaPtInf" ] = "JetTauEtaPtInf"
|
44 |
fakeDict[ "JetPtJPTeta1" ] = "JetTauPtJPTeta1"
|
45 |
fakeDict[ "JetPtJPTeta2" ] = "JetTauPtJPTeta2"
|
46 |
fakeDict[ "JetPtJPTeta25" ] = "JetTauPtJPTeta25"
|
47 |
fakeDict[ "JetEtaJPTPt20" ] = "JetTauEtaJPTPt20"
|
48 |
fakeDict[ "JetEtaJPTPt40" ] = "JetTauEtaJPTPt40"
|
49 |
fakeDict[ "JetEtaJPTPt60" ] = "JetTauEtaJPTPt60"
|
50 |
fakeDict[ "JetEtaJPTPt80" ] = "JetTauEtaJPTPt80"
|
51 |
fakeDict[ "JetEtaJPTPt100" ] = "JetTauEtaJPTPt100"
|
52 |
fakeDict[ "JetEtaJPTPt200" ] = "JetTauEtaJPTPt200"
|
53 |
fakeDict[ "JetEtaJPTPt500" ] = "JetTauEtaJPTPt500"
|
54 |
fakeDict[ "JetEtaJPTPtInf" ] = "JetTauEtaJPTPtInf"
|
55 |
fakeDict[ "JetIsoRel" ] = "JetTauIsoRel"
|
56 |
|
57 |
#fakeDict[ "JetIso" ] = "JetTauIso"
|
58 |
fakeDict[ "JetIsoReleta1" ] = "JetTauIsoReleta1"
|
59 |
fakeDict[ "JetIsoReleta2" ] = "JetTauIsoReleta2"
|
60 |
fakeDict[ "JetIsoReleta25" ] = "JetTauIsoReleta25"
|
61 |
fakeDict[ "JetIsoRelPt20" ] = "JetTauIsoRelPt20"
|
62 |
fakeDict[ "JetIsoRelPt40" ] = "JetTauIsoRelPt40"
|
63 |
fakeDict[ "JetIsoRelPt60" ] = "JetTauIsoRelPt60"
|
64 |
fakeDict[ "JetIsoRelPt80" ] = "JetTauIsoRelPt80"
|
65 |
fakeDict[ "JetIsoRelPt100" ] = "JetTauIsoRelPt100"
|
66 |
fakeDict[ "JetIsoRelPt200" ] = "JetTauIsoRelPt200"
|
67 |
fakeDict[ "JetIsoRelPt500" ] = "JetTauIsoRelPt500"
|
68 |
fakeDict[ "JetIsoRelPtInf" ] = "JetTauIsoRelPtInf"
|
69 |
|
70 |
histList = []
|
71 |
histList.append( "JetPteta1" )
|
72 |
histList.append( "JetPteta2" )
|
73 |
histList.append( "JetPteta25" )
|
74 |
for dir in dirList:
|
75 |
if dir == "FakeRatePreLoose/":
|
76 |
#if re.search( dir, "FakeRatePre" ):
|
77 |
continue
|
78 |
|
79 |
|
80 |
rebin = 1
|
81 |
|
82 |
|
83 |
histDict = {}
|
84 |
for hist in fakeDict.keys():
|
85 |
print "----- ", hist
|
86 |
histDict[ hist ] = {}
|
87 |
histDict[ fakeDict[ hist ] ] = {}
|
88 |
for file in sampleList:
|
89 |
rootfile = ROOT.TFile.Open( fileDict[ file ] )
|
90 |
#newrootfile = ROOT.TFile( "./" + file + "_TaNC_TauTemplate.root", "RECREATE" )
|
91 |
#print file
|
92 |
histDict[ hist ][ file ] = {}
|
93 |
histDict[ fakeDict[ hist ] ][ file ] = {}
|
94 |
for dir in dirList:
|
95 |
print dir
|
96 |
histDict[ hist ][ file ][ dir ] = rootfile.Get( dir + hist )
|
97 |
#histDict[ hist ][ file ][ dir ].SetDirectory( 0 )
|
98 |
histDict[ hist ][ file ][ dir ].UseCurrentStyle()
|
99 |
histDict[ hist ][ file ][ dir ].Rebin( rebin )
|
100 |
|
101 |
histDict[ fakeDict[ hist ] ][ file ][ dir ] = rootfile.Get( dir + fakeDict[ hist ] )
|
102 |
#histDict[ fakeDict[ hist ] ][ file ][ dir ].SetDirectory( 0 )
|
103 |
histDict[ fakeDict[ hist ] ][ file ][ dir ].UseCurrentStyle()
|
104 |
histDict[ fakeDict[ hist ] ][ file ][ dir ].Rebin( rebin )
|
105 |
|
106 |
|
107 |
lowerBinsHist = FH.getLowerBins( histDict[ hist ][ file ][ dir ] )
|
108 |
lowerBinsHist2 = FH.getLowerBins( histDict[ fakeDict[ hist ] ][ file ][ dir ] )
|
109 |
|
110 |
rebinList = FH.mergeList( [ lowerBinsHist, lowerBinsHist2 ] )
|
111 |
obj = array( 'd' )
|
112 |
for b in rebinList:
|
113 |
obj.append( b )
|
114 |
pass
|
115 |
histDict[ hist ][ file ][ dir ] = \
|
116 |
histDict[ hist ][ file ][ dir ].Rebin( len( rebinList ) -1 , hist , obj )
|
117 |
histDict[ fakeDict[ hist ] ][ file ][ dir ] = \
|
118 |
histDict[ fakeDict[ hist ] ][ file ][ dir ].Rebin( len( rebinList ) -1 , fakeDict[ hist ] , obj )
|
119 |
|
120 |
histDict[ hist ][ file ][ dir ].SetDirectory( 0 )
|
121 |
histDict[ fakeDict[ hist ] ][ file ][ dir ].SetDirectory( 0 )
|
122 |
pass
|
123 |
rootfile.Close()
|
124 |
pass
|
125 |
pass
|
126 |
|
127 |
for file in sampleList:
|
128 |
newrootfile = ROOT.TFile( "./" + file + "_fakes.root", "RECREATE" )
|
129 |
#thedir = newrootfile.GetDirectory( dir )
|
130 |
for dir in dirList:
|
131 |
newHist = {}
|
132 |
newrootfile.mkdir( dir.split( "/" )[ 0 ] )
|
133 |
thedir = newrootfile.GetDirectory( dir )
|
134 |
for hist in fakeDict.keys():
|
135 |
|
136 |
newHist[ hist ] = histDict[ fakeDict[ hist ] ][ file ][ dir ].Clone()
|
137 |
newHist[ hist ].SetName( histDict[ fakeDict[ hist ] ][ file ][ dir ].GetName() )
|
138 |
newHist[ hist ].SetDirectory( 0 )
|
139 |
newHist[ hist ].UseCurrentStyle()
|
140 |
newHist[ hist ].Divide( histDict[ hist ][ file ][ dir ] )
|
141 |
newHist[ hist ].SetDirectory( thedir )
|
142 |
pass
|
143 |
thedir.Write()
|
144 |
pass
|
145 |
newrootfile.Close()
|
146 |
pass
|
147 |
|