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( "Data" )
|
15 |
|
16 |
fileDict = {}
|
17 |
fileDict[ "Data" ] = "/scratch/hh/lustre/cms/user/nowaf/2011Data/VersionII/Plots/Data_fakes_xiv/Data_Fakes_xiv.root"
|
18 |
|
19 |
|
20 |
fileName = "./" + "Data" + "_fakes.root"
|
21 |
|
22 |
rebin = 1
|
23 |
#rebin = 4
|
24 |
|
25 |
TrigList = []
|
26 |
#TrigList.append( 30 )
|
27 |
#TrigList.append( 60 )
|
28 |
#TrigList.append( 80 )
|
29 |
#TrigList.append( 110 )
|
30 |
#TrigList.append( 150 )
|
31 |
#TrigList.append( 190 )
|
32 |
#TrigList.append( 240 )
|
33 |
TrigList.append( 300 )
|
34 |
TrigList.append( 370 )
|
35 |
|
36 |
initialHistDict = {}
|
37 |
initialHistDict[ "JetTauPtJPT" ] = "JetPtJPT"
|
38 |
initialHistDict[ "JetTauEtaJPT" ] = "JetEtaJPT"
|
39 |
#initialHistDict[ "JetTauDist" ] = "JetDist"
|
40 |
#initialHistDict[ "JetTauIsoRel" ] = "JetIsoRel"
|
41 |
initialHistDict[ "JetTauEtaJPTPt20" ] = "JetEtaJPTPt20"
|
42 |
initialHistDict[ "JetTauEtaJPTPt40" ] = "JetEtaJPTPt40"
|
43 |
initialHistDict[ "JetTauEtaJPTPt60" ] = "JetEtaJPTPt60"
|
44 |
initialHistDict[ "JetTauEtaJPTPt80" ] = "JetEtaJPTPt80"
|
45 |
initialHistDict[ "JetTauEtaJPTPt100" ] = "JetEtaJPTPt100"
|
46 |
initialHistDict[ "JetTauEtaJPTPt200" ] = "JetEtaJPTPt200"
|
47 |
initialHistDict[ "JetTauEtaJPTPt500" ] = "JetEtaJPTPt500"
|
48 |
initialHistDict[ "JetTauEtaJPTPtInf" ] = "JetEtaJPTPtInf"
|
49 |
initialHistDict[ "JetTauPtJPTeta1" ] = "JetPtJPTeta1"
|
50 |
initialHistDict[ "JetTauPtJPTeta2" ] = "JetPtJPTeta2"
|
51 |
initialHistDict[ "JetTauPtJPTeta25" ] = "JetPtJPTeta25"
|
52 |
initialHistDict[ "JetTauIsoReleta1" ] = "JetIsoReleta1"
|
53 |
initialHistDict[ "JetTauIsoReleta2" ] = "JetIsoReleta2"
|
54 |
initialHistDict[ "JetTauIsoReleta25" ] = "JetIsoReleta25"
|
55 |
initialHistDict[ "JetTauIsoRelPt20" ] = "JetIsoRelPt20"
|
56 |
initialHistDict[ "JetTauIsoRelPt40" ] = "JetIsoRelPt40"
|
57 |
initialHistDict[ "JetTauIsoRelPt60" ] = "JetIsoRelPt60"
|
58 |
initialHistDict[ "JetTauIsoRelPt80" ] = "JetIsoRelPt80"
|
59 |
initialHistDict[ "JetTauIsoRelPt100" ] = "JetIsoRelPt100"
|
60 |
initialHistDict[ "JetTauIsoRelPt200" ] = "JetIsoRelPt200"
|
61 |
initialHistDict[ "JetTauIsoRelPt500" ] = "JetIsoRelPt500"
|
62 |
initialHistDict[ "JetTauIsoRelPtInf" ] = "JetIsoRelPtInf"
|
63 |
|
64 |
histDict = {}
|
65 |
graph = {}
|
66 |
Mean = {}
|
67 |
ErrUp = {}
|
68 |
ErrDwn = {}
|
69 |
for hist in initialHistDict:
|
70 |
print "----- ", hist
|
71 |
#histDict[ hist ] = {}
|
72 |
#graph[ hist ] = {}
|
73 |
#histDict[ initialHistDict[ hist ] ] = {}
|
74 |
#Mean[ hist ] = {}
|
75 |
#ErrUp[ hist ] = {}
|
76 |
#ErrDwn[ hist ] = {}
|
77 |
rootfile = ROOT.TFile.Open( fileDict[ "Data" ] )
|
78 |
for trig in TrigList:
|
79 |
dir = "FakeRateDiJetsLoose3Jet" + str( trig ) + "/"
|
80 |
#print dir + hist
|
81 |
h = rootfile.Get( dir + hist )
|
82 |
h.SetDirectory( 0 )
|
83 |
h.UseCurrentStyle()
|
84 |
h.Rebin( rebin )
|
85 |
if not hist in histDict.keys():
|
86 |
histDict[ hist ] = h.Clone()
|
87 |
else:
|
88 |
histDict[ hist ].Add( h.Clone() )
|
89 |
|
90 |
|
91 |
h = rootfile.Get( dir + initialHistDict[ hist ] )
|
92 |
h.SetDirectory( 0 )
|
93 |
h.UseCurrentStyle()
|
94 |
h.Rebin( rebin )
|
95 |
if not initialHistDict[ hist ] in histDict.keys():
|
96 |
histDict[ initialHistDict[ hist ] ] = h.Clone()
|
97 |
else:
|
98 |
histDict[ initialHistDict[ hist ] ].Add( h.Clone() )
|
99 |
pass
|
100 |
pass
|
101 |
pass
|
102 |
##### temporary
|
103 |
#for trig in TrigList:
|
104 |
histDict[ "JetEtaJPT" ] = histDict[ "JetEtaJPTPt20" ].Clone()
|
105 |
histDict[ "JetTauEtaJPT" ] = histDict[ "JetTauEtaJPTPt20" ].Clone()
|
106 |
for hist in [ "JetEtaJPTPt40", "JetEtaJPTPt60", "JetEtaJPTPt80", "JetEtaJPTPt100",
|
107 |
"JetEtaJPTPt200", "JetEtaJPTPt500", "JetEtaJPTPtInf"]:
|
108 |
histDict[ "JetEtaJPT" ].Add( histDict[ hist ] )
|
109 |
pass
|
110 |
for hist in [ "JetTauEtaJPTPt40", "JetTauEtaJPTPt60", "JetTauEtaJPTPt80", "JetTauEtaJPTPt100",
|
111 |
"JetTauEtaJPTPt200", "JetTauEtaJPTPt500", "JetTauEtaJPTPtInf"]:
|
112 |
histDict[ "JetTauEtaJPT" ].Add( histDict[ hist ] )
|
113 |
pass
|
114 |
|
115 |
for hist in initialHistDict:
|
116 |
#### make new, empty hists with same binning:
|
117 |
Mean[ hist ] = ROOT.TH1F( hist + "Mean", hist + "Mean",
|
118 |
histDict[ hist ].GetNbinsX(),
|
119 |
histDict[ hist ].GetXaxis().GetXmin(),
|
120 |
histDict[ hist ].GetXaxis().GetXmax() )
|
121 |
|
122 |
ErrUp[ hist ] = ROOT.TH1F( hist + "ErrUp", hist + "ErrUp",
|
123 |
histDict[ hist ].GetNbinsX(),
|
124 |
histDict[ hist ].GetXaxis().GetXmin(),
|
125 |
histDict[ hist ].GetXaxis().GetXmax() )
|
126 |
|
127 |
ErrDwn[ hist ] = ROOT.TH1F( hist + "ErrDwn", hist + "ErrDwn",
|
128 |
histDict[ hist ].GetNbinsX(),
|
129 |
histDict[ hist ].GetXaxis().GetXmin(),
|
130 |
histDict[ hist ].GetXaxis().GetXmax() )
|
131 |
|
132 |
Mean[ hist ].SetDirectory( 0 )
|
133 |
ErrUp[ hist ].SetDirectory( 0 )
|
134 |
ErrDwn[ hist ].SetDirectory( 0 )
|
135 |
|
136 |
#print type( Mean[ hist ][ file ][ dir ] )
|
137 |
|
138 |
lowerBinsHist = FH.getLowerBins( histDict[ hist ], nEntries = 5 )
|
139 |
lowerBinsHist2 = FH.getLowerBins( histDict[ initialHistDict[ hist ] ], nEntries = 5 )
|
140 |
|
141 |
rebinList = FH.mergeList( [ lowerBinsHist, lowerBinsHist2 ] )
|
142 |
obj = array( 'd' )
|
143 |
for b in rebinList:
|
144 |
obj.append( b )
|
145 |
pass
|
146 |
histDict[ hist ] = \
|
147 |
histDict[ hist ].Rebin( len( rebinList ) -1 , hist , obj )
|
148 |
histDict[ initialHistDict[ hist ] ] = \
|
149 |
histDict[ initialHistDict[ hist ] ].Rebin( len( rebinList ) -1 , hist , obj )
|
150 |
Mean[ hist ] = Mean[ hist ].Rebin( len( rebinList ) -1 , hist , obj )
|
151 |
ErrUp[ hist ] = ErrUp[ hist ].Rebin( len( rebinList ) -1 , hist , obj )
|
152 |
ErrDwn[ hist ] = ErrDwn[ hist ].Rebin( len( rebinList ) -1 , hist , obj )
|
153 |
|
154 |
Style.setHistStyle( Mean[ hist ],
|
155 |
status="Signal",
|
156 |
color=1,
|
157 |
xTitle="Tau P_{T} [GeV]", yTitle="eff" )
|
158 |
Style.setHistStyle( ErrUp[ hist ],
|
159 |
status="Signal",
|
160 |
color=9,
|
161 |
xTitle="Tau P_{T} [GeV]", yTitle="eff" )
|
162 |
Style.setHistStyle( ErrDwn[ hist ],
|
163 |
status="Signal",
|
164 |
color=9,
|
165 |
xTitle="Tau P_{T} [GeV]", yTitle="eff" )
|
166 |
|
167 |
#histDict[ hist ][ file ].Divide( histDict[ initialHistDict[ hist ] ][ file ] )
|
168 |
#### make a TGraph first:
|
169 |
graph[ hist ] = ROOT.TGraphAsymmErrors()
|
170 |
graph[ hist ].BayesDivide( histDict[ hist ],
|
171 |
histDict[ initialHistDict[ hist ] ] )
|
172 |
graph[ hist ].UseCurrentStyle()
|
173 |
|
174 |
#graph[ hist ][ file ].Draw( "AP" )
|
175 |
#Def.DontQuit()
|
176 |
#print type( Mean[ hist ][ file ][ dir ] )
|
177 |
|
178 |
### now get the mean, the err ups, and the err downs
|
179 |
### note: bins start at 1, points at 0!
|
180 |
for bin in range( 0, histDict[ hist ].GetNbinsX() ):
|
181 |
x = ROOT.Double( 0 )
|
182 |
y = ROOT.Double( 0 )
|
183 |
graph[ hist ].GetPoint( ( bin ) , x, y )
|
184 |
#print bin, " x=", x, " y=", y
|
185 |
errUp = graph[ hist ].GetErrorYhigh( bin )
|
186 |
errDwn = graph[ hist ].GetErrorYlow( bin )
|
187 |
Mean[ hist ].SetBinContent( bin + 1, y )
|
188 |
#print type( Mean[ hist ][ file ][ dir ] )
|
189 |
if not y == 0:
|
190 |
ErrUp[ hist ].SetBinContent( bin + 1, y + errUp )
|
191 |
ErrDwn[ hist ].SetBinContent( bin + 1, y - errDwn )
|
192 |
pass
|
193 |
else:
|
194 |
ErrUp[ hist ].SetBinContent( bin + 1, 0 )
|
195 |
ErrDwn[ hist ].SetBinContent( bin + 1, 0 )
|
196 |
pass
|
197 |
#rootfile.Close()
|
198 |
pass
|
199 |
pass
|
200 |
|
201 |
for file in sampleList:
|
202 |
newrootfile = ROOT.TFile( fileName, "RECREATE" )
|
203 |
#for dir in dirs:
|
204 |
newrootfile.mkdir( "FakeRateDiJetsLoose3Jet" )
|
205 |
thedir = newrootfile.GetDirectory( "FakeRateDiJetsLoose3Jet" )
|
206 |
for hist in initialHistDict.keys():
|
207 |
Mean[ hist ].SetName( hist )
|
208 |
ErrUp[ hist ].SetName( hist + "ErrUp" )
|
209 |
ErrDwn[ hist ].SetName( hist + "ErrDwn" )
|
210 |
Mean[ hist ].SetDirectory( thedir )
|
211 |
ErrUp[ hist ].SetDirectory( thedir )
|
212 |
ErrDwn[ hist ].SetDirectory( thedir )
|
213 |
pass
|
214 |
thedir.Write()
|
215 |
|
216 |
newrootfile.Close()
|